Search in sources :

Example 1 with EventManager

use of cloud.timo.TimoCloud.api.implementations.managers.EventManager in project TimoCloud by TimoCloud.

the class CordStringHandler method handleMessage.

@Override
public void handleMessage(Message message, String originalMessage, Channel channel) {
    String type = (String) message.get("type");
    Object data = message.get("data");
    switch(type) {
        case "HANDSHAKE_SUCCESS":
            TimoCloudCord.getInstance().onHandshakeSuccess();
            break;
        case "API_DATA":
            {
                ((TimoCloudUniversalAPICordImplementation) 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: ");
                TimoCloudCord.getInstance().severe(e);
            }
            break;
        case "PLUGIN_MESSAGE":
            {
                AddressedPluginMessage addressedPluginMessage = PluginMessageSerializer.deserialize((Map) data);
                ((TimoCloudMessageAPIBasicImplementation) TimoCloudAPI.getMessageAPI()).onMessage(addressedPluginMessage);
                break;
            }
        default:
            TimoCloudCord.getInstance().severe("Could not categorize json message: " + originalMessage);
    }
}
Also used : EventManager(cloud.timo.TimoCloud.api.implementations.managers.EventManager) EventType(cloud.timo.TimoCloud.api.events.EventType) TimoCloudUniversalAPIBasicImplementation(cloud.timo.TimoCloud.api.implementations.TimoCloudUniversalAPIBasicImplementation) Map(java.util.Map) AddressedPluginMessage(cloud.timo.TimoCloud.api.messages.objects.AddressedPluginMessage)

Example 2 with EventManager

use of cloud.timo.TimoCloud.api.implementations.managers.EventManager in project TimoCloud by TimoCloud.

the class BungeeStringHandler method handleMessage.

@Override
public void handleMessage(Message message, String originalMessage, Channel channel) {
    if (message == null) {
        TimoCloudBungee.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:
            TimoCloudBungee.getInstance().onHandshakeSuccess();
            break;
        case API_DATA:
            ((TimoCloudUniversalAPIBungeeImplementation) 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: ");
                TimoCloudBungee.getInstance().severe(e);
            }
            break;
        case CORE_SEND_MESSAGE_TO_COMMAND_SENDER:
            {
                TimoCloudBungee.getInstance().getTimoCloudCommand().sendMessage((String) message.get("sender"), (String) data);
            }
        case PROXY_EXECUTE_COMMAND:
            TimoCloudBungee.getInstance().getProxy().getPluginManager().dispatchCommand(TimoCloudBungee.getInstance().getProxy().getConsole(), (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");
                ProxiedPlayer proxiedPlayer = TimoCloudBungee.getInstance().getProxy().getPlayer(UUID.fromString(playerUUID));
                if (Objects.isNull(proxiedPlayer))
                    return;
                proxiedPlayer.connect(TimoCloudBungee.getInstance().getProxy().getServerInfo(serverObject));
                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");
            ProxiedPlayer proxiedPlayer = TimoCloudBungee.getInstance().getProxy().getPlayer(UUID.fromString(playerUUID));
            if (Objects.isNull(proxiedPlayer))
                return;
            try {
                proxiedPlayer.sendMessage(ComponentSerializer.parse(chatMessage));
            } catch (Exception e) {
                proxiedPlayer.sendMessage(TextComponent.fromLegacyText(chatMessage));
            }
            break;
        case PROXY_ADD_SERVER:
            TimoCloudBungee.getInstance().getProxy().getServers().put(server, TimoCloudBungee.getInstance().getProxy().constructServerInfo(server, new InetSocketAddress((String) message.get("address"), ((Number) message.get("port")).intValue()), "", false));
            break;
        case PROXY_REMOVE_SERVER:
            TimoCloudBungee.getInstance().getProxy().getServers().remove(server);
            break;
        case CORD_SET_IP:
            try {
                TimoCloudBungee.getInstance().getIpManager().setAddresses(InetAddressUtil.getSocketAddressByName((String) message.get("CHANNEL_ADDRESS")), InetAddressUtil.getSocketAddressByName((String) message.get("CLIENT_ADDRESS")));
            } catch (Exception e) {
                TimoCloudBungee.getInstance().severe("Error while parsing IP addresses (" + message.get("CHANNEL_ADDRESS") + ", " + message.get("CLIENT_ADDRESS") + "): ");
                TimoCloudBungee.getInstance().severe(e);
            }
            break;
        case ON_PLUGIN_MESSAGE:
            {
                AddressedPluginMessage addressedPluginMessage = PluginMessageSerializer.deserialize((Map) data);
                ((TimoCloudMessageAPIBasicImplementation) TimoCloudAPI.getMessageAPI()).onMessage(addressedPluginMessage);
                break;
            }
        case PROXY_STOP:
            {
                TimoCloudBungee.getInstance().stop();
                break;
            }
        default:
            TimoCloudBungee.getInstance().severe("Could not categorize json message: " + message);
    }
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) EventManager(cloud.timo.TimoCloud.api.implementations.managers.EventManager) EventType(cloud.timo.TimoCloud.api.events.EventType) InetSocketAddress(java.net.InetSocketAddress) TimoCloudUniversalAPIBungeeImplementation(cloud.timo.TimoCloud.bungeecord.api.TimoCloudUniversalAPIBungeeImplementation) AddressedPluginMessage(cloud.timo.TimoCloud.api.messages.objects.AddressedPluginMessage) TimoCloudUniversalAPIBasicImplementation(cloud.timo.TimoCloud.api.implementations.TimoCloudUniversalAPIBasicImplementation) Map(java.util.Map) MessageType(cloud.timo.TimoCloud.common.protocol.MessageType)

Example 3 with EventManager

use of cloud.timo.TimoCloud.api.implementations.managers.EventManager in project TimoCloud by TimoCloud.

the class TimoCloudCord method makeInstances.

private void makeInstances() throws Exception {
    instance = this;
    fileManager = new CordFileManager();
    proxyManager = new ProxyManager();
    socketClient = new CordSocketClient();
    socketClientHandler = new CordSocketClientHandler();
    socketMessageManager = new CordSocketMessageManager();
    socketServer = new CordSocketServer();
    minecraftDecoder = new MinecraftDecoder();
    stringHandler = new CordStringHandler();
    scheduler = Executors.newScheduledThreadPool(1);
    workerGroup = new NioEventLoopGroup();
    APIInstanceUtil.setInternalMessageInstance(new TimoCloudInternalMessageAPICordImplementation());
    APIInstanceUtil.setEventInstance(new EventManager());
    APIInstanceUtil.setUniversalInstance(new TimoCloudUniversalAPICordImplementation());
    APIInstanceUtil.setMessageInstance(new TimoCloudMessageAPICordImplementation());
    APIInstanceUtil.setInternalImplementationAPIInstance(new TimoCloudInternalImplementationAPIBasicImplementation());
    TimoCloudAPI.getMessageAPI().registerMessageListener(new APIResponseManager(), "TIMOCLOUD_API_RESPONSE");
}
Also used : EventManager(cloud.timo.TimoCloud.api.implementations.managers.EventManager) TimoCloudInternalImplementationAPIBasicImplementation(cloud.timo.TimoCloud.api.implementations.internal.TimoCloudInternalImplementationAPIBasicImplementation) CordFileManager(cloud.timo.TimoCloud.cord.managers.CordFileManager) TimoCloudMessageAPICordImplementation(cloud.timo.TimoCloud.cord.api.TimoCloudMessageAPICordImplementation) ProxyManager(cloud.timo.TimoCloud.cord.managers.ProxyManager) APIResponseManager(cloud.timo.TimoCloud.api.implementations.managers.APIResponseManager) TimoCloudInternalMessageAPICordImplementation(cloud.timo.TimoCloud.cord.api.TimoCloudInternalMessageAPICordImplementation) TimoCloudUniversalAPICordImplementation(cloud.timo.TimoCloud.cord.api.TimoCloudUniversalAPICordImplementation) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup)

Example 4 with EventManager

use of cloud.timo.TimoCloud.api.implementations.managers.EventManager 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");
}
Also used : TimoCloudUniversalAPIVelocityImplementation(cloud.timo.TimoCloud.velocity.api.TimoCloudUniversalAPIVelocityImplementation) VelocitySocketClientHandler(cloud.timo.TimoCloud.velocity.sockets.VelocitySocketClientHandler) EventManager(cloud.timo.TimoCloud.api.implementations.managers.EventManager) VelocityStringHandler(cloud.timo.TimoCloud.velocity.sockets.VelocityStringHandler) TimoCloudInternalImplementationAPIBasicImplementation(cloud.timo.TimoCloud.api.implementations.internal.TimoCloudInternalImplementationAPIBasicImplementation) TimoCloudInternalMessageAPIVelocityImplementation(cloud.timo.TimoCloud.velocity.api.TimoCloudInternalMessageAPIVelocityImplementation) TimoCloudCommand(cloud.timo.TimoCloud.velocity.commands.TimoCloudCommand) IpManager(cloud.timo.TimoCloud.velocity.managers.IpManager) VelocityFileManager(cloud.timo.TimoCloud.velocity.managers.VelocityFileManager) LobbyManager(cloud.timo.TimoCloud.common.manager.LobbyManager) APIResponseManager(cloud.timo.TimoCloud.api.implementations.managers.APIResponseManager) TimoCloudBungeeAPIImplementation(cloud.timo.TimoCloud.api.implementations.TimoCloudBungeeAPIImplementation) VelocitySocketClient(cloud.timo.TimoCloud.velocity.sockets.VelocitySocketClient) VelocitySocketMessageManager(cloud.timo.TimoCloud.velocity.sockets.VelocitySocketMessageManager) TimoCloudMessageAPIVelocityImplementation(cloud.timo.TimoCloud.velocity.api.TimoCloudMessageAPIVelocityImplementation)

Example 5 with EventManager

use of cloud.timo.TimoCloud.api.implementations.managers.EventManager 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)

Aggregations

EventManager (cloud.timo.TimoCloud.api.implementations.managers.EventManager)10 TimoCloudInternalImplementationAPIBasicImplementation (cloud.timo.TimoCloud.api.implementations.internal.TimoCloudInternalImplementationAPIBasicImplementation)5 APIResponseManager (cloud.timo.TimoCloud.api.implementations.managers.APIResponseManager)5 EventType (cloud.timo.TimoCloud.api.events.EventType)4 TimoCloudUniversalAPIBasicImplementation (cloud.timo.TimoCloud.api.implementations.TimoCloudUniversalAPIBasicImplementation)4 AddressedPluginMessage (cloud.timo.TimoCloud.api.messages.objects.AddressedPluginMessage)4 Map (java.util.Map)4 MessageType (cloud.timo.TimoCloud.common.protocol.MessageType)3 TimoCloudBungeeAPIImplementation (cloud.timo.TimoCloud.api.implementations.TimoCloudBungeeAPIImplementation)2 TimoCloudUniversalAPIBukkitImplementation (cloud.timo.TimoCloud.bukkit.api.TimoCloudUniversalAPIBukkitImplementation)2 LobbyManager (cloud.timo.TimoCloud.common.manager.LobbyManager)2 Message (cloud.timo.TimoCloud.common.protocol.Message)2 TimoCloudAPI (cloud.timo.TimoCloud.api.TimoCloudAPI)1 TimoCloudMessageAPIBasicImplementation (cloud.timo.TimoCloud.api.implementations.TimoCloudMessageAPIBasicImplementation)1 EventUtil (cloud.timo.TimoCloud.api.utils.EventUtil)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