use of cloud.timo.TimoCloud.bukkit.api.TimoCloudUniversalAPIBukkitImplementation in project TimoCloud by TimoCloud.
the class BukkitStringHandler method handleMessage.
@Override
public void handleMessage(Message message, String originalMessage, Channel channel) {
if (message == null) {
TimoCloudBukkit.getInstance().severe("Error while parsing json (json is null): " + originalMessage);
return;
}
MessageType type = message.getType();
Object data = message.getData();
switch(type) {
case SERVER_HANDSHAKE_SUCCESS:
TimoCloudBukkit.getInstance().onHandshakeSuccess();
break;
case API_DATA:
((TimoCloudUniversalAPIBukkitImplementation) 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: ");
TimoCloudBukkit.getInstance().severe(e);
}
break;
case SERVER_EXECUTE_COMMAND:
Bukkit.getScheduler().runTask(TimoCloudBukkit.getInstance(), () -> TimoCloudBukkit.getInstance().getServer().dispatchCommand(TimoCloudBukkit.getInstance().getServer().getConsoleSender(), (String) data));
break;
case ON_PLUGIN_MESSAGE:
{
AddressedPluginMessage addressedPluginMessage = PluginMessageSerializer.deserialize((Map) data);
((TimoCloudMessageAPIBasicImplementation) TimoCloudAPI.getMessageAPI()).onMessage(addressedPluginMessage);
break;
}
case SERVER_STOP:
{
TimoCloudBukkit.getInstance().stop();
break;
}
default:
TimoCloudBukkit.getInstance().severe("Error: Could not categorize json message: " + message);
}
}
use of cloud.timo.TimoCloud.bukkit.api.TimoCloudUniversalAPIBukkitImplementation in project TimoCloud by TimoCloud.
the class TimoCloudBukkit method makeInstances.
private void makeInstances() throws Exception {
instance = this;
TimoCloudLogger.setLogger(this);
fileManager = new BukkitFileManager();
socketClientHandler = new BukkitSocketClientHandler();
socketMessageManager = new BukkitSocketMessageManager();
stringHandler = new BukkitStringHandler();
signManager = new SignManager();
stateByEventManager = new StateByEventManager();
APIInstanceUtil.setInternalMessageInstance(new TimoCloudInternalMessageAPIBukkitImplementation());
APIInstanceUtil.setEventInstance(new EventManager());
APIInstanceUtil.setUniversalInstance(new TimoCloudUniversalAPIBukkitImplementation());
APIInstanceUtil.setBukkitInstance(new TimoCloudBukkitAPIImplementation());
APIInstanceUtil.setMessageInstance(new TimoCloudMessageAPIBukkitImplementation());
APIInstanceUtil.setInternalImplementationAPIInstance(new TimoCloudInternalImplementationAPIBasicImplementation());
TimoCloudAPI.getMessageAPI().registerMessageListener(new APIResponseManager(), "TIMOCLOUD_API_RESPONSE");
}
Aggregations