Search in sources :

Example 1 with TimoCloudUniversalAPIBukkitImplementation

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);
    }
}
Also used : EventManager(cloud.timo.TimoCloud.api.implementations.managers.EventManager) EventType(cloud.timo.TimoCloud.api.events.EventType) TimoCloudUniversalAPIBasicImplementation(cloud.timo.TimoCloud.api.implementations.TimoCloudUniversalAPIBasicImplementation) TimoCloudUniversalAPIBukkitImplementation(cloud.timo.TimoCloud.bukkit.api.TimoCloudUniversalAPIBukkitImplementation) Map(java.util.Map) MessageType(cloud.timo.TimoCloud.common.protocol.MessageType) AddressedPluginMessage(cloud.timo.TimoCloud.api.messages.objects.AddressedPluginMessage)

Example 2 with TimoCloudUniversalAPIBukkitImplementation

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");
}
Also used : SignManager(cloud.timo.TimoCloud.bukkit.managers.SignManager) StateByEventManager(cloud.timo.TimoCloud.bukkit.managers.StateByEventManager) EventManager(cloud.timo.TimoCloud.api.implementations.managers.EventManager) BukkitSocketClientHandler(cloud.timo.TimoCloud.bukkit.sockets.BukkitSocketClientHandler) TimoCloudInternalImplementationAPIBasicImplementation(cloud.timo.TimoCloud.api.implementations.internal.TimoCloudInternalImplementationAPIBasicImplementation) BukkitFileManager(cloud.timo.TimoCloud.bukkit.managers.BukkitFileManager) StateByEventManager(cloud.timo.TimoCloud.bukkit.managers.StateByEventManager) TimoCloudUniversalAPIBukkitImplementation(cloud.timo.TimoCloud.bukkit.api.TimoCloudUniversalAPIBukkitImplementation) TimoCloudMessageAPIBukkitImplementation(cloud.timo.TimoCloud.bukkit.api.TimoCloudMessageAPIBukkitImplementation) BukkitSocketMessageManager(cloud.timo.TimoCloud.bukkit.sockets.BukkitSocketMessageManager) APIResponseManager(cloud.timo.TimoCloud.api.implementations.managers.APIResponseManager) TimoCloudInternalMessageAPIBukkitImplementation(cloud.timo.TimoCloud.bukkit.api.TimoCloudInternalMessageAPIBukkitImplementation) TimoCloudBukkitAPIImplementation(cloud.timo.TimoCloud.bukkit.api.TimoCloudBukkitAPIImplementation) BukkitStringHandler(cloud.timo.TimoCloud.bukkit.sockets.BukkitStringHandler)

Aggregations

EventManager (cloud.timo.TimoCloud.api.implementations.managers.EventManager)2 TimoCloudUniversalAPIBukkitImplementation (cloud.timo.TimoCloud.bukkit.api.TimoCloudUniversalAPIBukkitImplementation)2 EventType (cloud.timo.TimoCloud.api.events.EventType)1 TimoCloudUniversalAPIBasicImplementation (cloud.timo.TimoCloud.api.implementations.TimoCloudUniversalAPIBasicImplementation)1 TimoCloudInternalImplementationAPIBasicImplementation (cloud.timo.TimoCloud.api.implementations.internal.TimoCloudInternalImplementationAPIBasicImplementation)1 APIResponseManager (cloud.timo.TimoCloud.api.implementations.managers.APIResponseManager)1 AddressedPluginMessage (cloud.timo.TimoCloud.api.messages.objects.AddressedPluginMessage)1 TimoCloudBukkitAPIImplementation (cloud.timo.TimoCloud.bukkit.api.TimoCloudBukkitAPIImplementation)1 TimoCloudInternalMessageAPIBukkitImplementation (cloud.timo.TimoCloud.bukkit.api.TimoCloudInternalMessageAPIBukkitImplementation)1 TimoCloudMessageAPIBukkitImplementation (cloud.timo.TimoCloud.bukkit.api.TimoCloudMessageAPIBukkitImplementation)1 BukkitFileManager (cloud.timo.TimoCloud.bukkit.managers.BukkitFileManager)1 SignManager (cloud.timo.TimoCloud.bukkit.managers.SignManager)1 StateByEventManager (cloud.timo.TimoCloud.bukkit.managers.StateByEventManager)1 BukkitSocketClientHandler (cloud.timo.TimoCloud.bukkit.sockets.BukkitSocketClientHandler)1 BukkitSocketMessageManager (cloud.timo.TimoCloud.bukkit.sockets.BukkitSocketMessageManager)1 BukkitStringHandler (cloud.timo.TimoCloud.bukkit.sockets.BukkitStringHandler)1 MessageType (cloud.timo.TimoCloud.common.protocol.MessageType)1 Map (java.util.Map)1