use of cloud.timo.TimoCloud.velocity.api.TimoCloudUniversalAPIVelocityImplementation in project TimoCloud by TimoCloud.
the class TimoCloudVelocity method makeInstances.
private void makeInstances() throws Exception {
TimoCloudLogger.setLogger(this);
fileManager = new VelocityFileManager();
lobbyManager = new LobbyManager(getFileManager().getConfig().getString("fallbackGroup"), getFileManager().getConfig().getString("LobbyChooseStrategy"), getFileManager().getConfig().getString("emergencyFallback"));
ipManager = new IpManager();
socketClient = new VelocitySocketClient();
socketClientHandler = new VelocitySocketClientHandler();
socketMessageManager = new VelocitySocketMessageManager();
velocityStringHandler = new VelocityStringHandler();
timoCloudCommand = new TimoCloudCommand();
APIInstanceUtil.setInternalMessageInstance(new TimoCloudInternalMessageAPIVelocityImplementation());
APIInstanceUtil.setEventInstance(new EventManager());
APIInstanceUtil.setUniversalInstance(new TimoCloudUniversalAPIVelocityImplementation());
APIInstanceUtil.setBungeeInstance(new TimoCloudBungeeAPIImplementation(getProxyName()));
APIInstanceUtil.setMessageInstance(new TimoCloudMessageAPIVelocityImplementation());
APIInstanceUtil.setInternalImplementationAPIInstance(new TimoCloudInternalImplementationAPIBasicImplementation());
TimoCloudAPI.getMessageAPI().registerMessageListener(new APIResponseManager(), "TIMOCLOUD_API_RESPONSE");
}
use of cloud.timo.TimoCloud.velocity.api.TimoCloudUniversalAPIVelocityImplementation in project TimoCloud by TimoCloud.
the class VelocityStringHandler method handleMessage.
@Override
public void handleMessage(Message message, String originalMessage, Channel channel) {
if (message == null) {
TimoCloudVelocity.getInstance().severe("Error while parsing json (json is null): " + originalMessage);
return;
}
String server = (String) message.get("name");
MessageType type = message.getType();
Object data = message.getData();
switch(type) {
case PROXY_HANDSHAKE_SUCCESS:
TimoCloudVelocity.getInstance().onHandshakeSuccess();
break;
case API_DATA:
((TimoCloudUniversalAPIVelocityImplementation) TimoCloudAPI.getUniversalAPI()).setData((Map<String, Object>) data);
break;
case EVENT_FIRED:
try {
EventType eventType = EnumUtil.valueOf(EventType.class, (String) message.get("eT"));
((EventManager) TimoCloudAPI.getEventAPI()).callEvent(((TimoCloudUniversalAPIBasicImplementation) TimoCloudAPI.getUniversalAPI()).getObjectMapper().readValue((String) data, EventUtil.getClassByEventType(eventType)));
} catch (Exception e) {
System.err.println("Error while parsing event from json: ");
TimoCloudVelocity.getInstance().severe(e);
}
break;
case CORE_SEND_MESSAGE_TO_COMMAND_SENDER:
{
TimoCloudVelocity.getInstance().getTimoCloudCommand().sendMessage((String) message.get("sender"), (String) data);
}
case PROXY_EXECUTE_COMMAND:
TimoCloudVelocity.getInstance().getServer().getCommandManager().executeImmediatelyAsync(TimoCloudVelocity.getInstance().getServer().getConsoleCommandSource(), (String) data);
break;
case PROXY_SEND_PLAYER:
{
Map<String, Object> information = (Map<String, Object>) data;
String playerUUID = (String) information.get("playerUUID");
String serverObject = (String) information.get("serverObject");
Optional<Player> player = TimoCloudVelocity.getInstance().getServer().getPlayer(UUID.fromString(playerUUID));
player.ifPresent(it -> it.createConnectionRequest(TimoCloudVelocity.getInstance().getServer().getServer(serverObject).get()).fireAndForget());
break;
}
case PROXY_SEND_MESSAGE:
Map<String, Object> information = (Map<String, Object>) data;
String playerUUID = (String) information.get("playerUUID");
String chatMessage = (String) information.get("chatMessage");
Optional<Player> player = TimoCloudVelocity.getInstance().getServer().getPlayer(UUID.fromString(playerUUID));
player.ifPresent(it -> it.sendMessage(Component.text(chatMessage)));
break;
case PROXY_ADD_SERVER:
TimoCloudVelocity.getInstance().getServer().registerServer(new ServerInfo(server, new InetSocketAddress((String) message.get("address"), ((Number) message.get("port")).intValue())));
break;
case PROXY_REMOVE_SERVER:
TimoCloudVelocity.getInstance().getServer().unregisterServer(TimoCloudVelocity.getInstance().getServer().getServer(server).get().getServerInfo());
break;
case CORD_SET_IP:
try {
TimoCloudVelocity.getInstance().getIpManager().setAddresses(InetAddressUtil.getSocketAddressByName((String) message.get("CHANNEL_ADDRESS")), InetAddressUtil.getSocketAddressByName((String) message.get("CLIENT_ADDRESS")));
} catch (Exception e) {
TimoCloudVelocity.getInstance().severe("Error while parsing IP addresses (" + message.get("CHANNEL_ADDRESS") + ", " + message.get("CLIENT_ADDRESS") + "): ");
TimoCloudVelocity.getInstance().severe(e);
}
break;
case ON_PLUGIN_MESSAGE:
{
AddressedPluginMessage addressedPluginMessage = PluginMessageSerializer.deserialize((Map) data);
((TimoCloudMessageAPIBasicImplementation) TimoCloudAPI.getMessageAPI()).onMessage(addressedPluginMessage);
break;
}
case PROXY_STOP:
{
TimoCloudVelocity.getInstance().stop();
break;
}
default:
TimoCloudVelocity.getInstance().severe("Could not categorize json message: " + message);
}
}
Aggregations