Utils Converters - Simplix-Softworks/SimplixCore GitHub Wiki
Converters
Modules
The converters are located in the simplixcore-common-api.
Dependencies required:
All classes of the Converter system are located in the simplixcore-common-api module.
No other dependencies than described in getting started are required.
Usage
import dev.simplix.core.common.converter.Converter;
import dev.simplix.core.common.converter.Converters;
import java.util.UUID;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.connection.ProxiedPlayer;
public class ConvertablesExample {
public void registerConvertables() {
Converters.register(UUID.class, ProxiedPlayer.class, new Converter<UUID, ProxiedPlayer>() {
@Override
public ProxiedPlayer convert(UUID src) {
final ProxiedPlayer out = ProxyServer.getInstance().getPlayer(src);
if (out == null) {
throw new IllegalStateException("No player found for '" + src + "'");
}
return out;
}
});
}
public void exampleUsage(UUID uuid) {
final ProxiedPlayer player = Converters.convert(uuid, ProxiedPlayer.class);
}
}