Search in sources :

Example 1 with DefaultType

use of de.dytanic.cloudnet.lib.DefaultType in project CloudNet by Dytanic.

the class PacketInServerDispatchCommand method handleInput.

@Override
public void handleInput(Document data, PacketSender packetSender) {
    DefaultType defaultType = data.getObject("defaultType", new TypeToken<DefaultType>() {
    }.getType());
    String serverId = data.getString("serverId");
    String commandLine = data.getString("commandLine");
    if (defaultType == DefaultType.BUKKIT) {
        MinecraftServer minecraftServer = CloudNet.getInstance().getServer(serverId);
        if (minecraftServer != null) {
            minecraftServer.getWrapper().writeServerCommand(commandLine, minecraftServer.getServerInfo());
        }
        CloudServer cloudServer = CloudNet.getInstance().getCloudGameServer(serverId);
        if (cloudServer != null) {
            cloudServer.getWrapper().writeServerCommand(commandLine, minecraftServer.getServerInfo());
        }
    } else {
        ProxyServer proxyServer = CloudNet.getInstance().getProxy(serverId);
        if (proxyServer != null) {
            proxyServer.getWrapper().writeProxyCommand(commandLine, proxyServer.getProxyInfo());
        }
    }
}
Also used : DefaultType(de.dytanic.cloudnet.lib.DefaultType) TypeToken(com.google.gson.reflect.TypeToken) CloudServer(de.dytanic.cloudnetcore.network.components.CloudServer) MinecraftServer(de.dytanic.cloudnetcore.network.components.MinecraftServer) ProxyServer(de.dytanic.cloudnetcore.network.components.ProxyServer)

Example 2 with DefaultType

use of de.dytanic.cloudnet.lib.DefaultType in project CloudNet by Dytanic.

the class PacketInCustomSubChannelMessage method handleInput.

@Override
public void handleInput(Document data, PacketSender packetSender) {
    DefaultType defaultType = data.getObject("defaultType", DefaultType.class);
    String channel = data.getString("channel");
    String message = data.getString("message");
    Document document = data.getDocument("value");
    if (defaultType.equals(DefaultType.BUKKIT)) {
        if (data.contains("serverId")) {
            MinecraftServer minecraftServer = CloudNet.getInstance().getServer(data.getString("serverId"));
            if (minecraftServer != null) {
                minecraftServer.sendPacket(new PacketOutCustomSubChannelMessage(channel, message, document));
                return;
            }
            CloudServer cloudServer = CloudNet.getInstance().getCloudGameServer(data.getString("serverId"));
            if (cloudServer != null) {
                cloudServer.sendPacket(new PacketOutCustomSubChannelMessage(channel, message, document));
            }
        } else {
            CloudNet.getInstance().getNetworkManager().sendAll(new PacketOutCustomSubChannelMessage(channel, message, document), new ChannelFilter() {

                @Override
                public boolean accept(INetworkComponent networkComponent) {
                    return networkComponent instanceof MinecraftServer || networkComponent instanceof CloudServer;
                }
            });
        }
    } else {
        if (data.contains("serverId")) {
            ProxyServer proxyServer = CloudNet.getInstance().getProxy(data.getString("serverId"));
            if (proxyServer != null) {
                proxyServer.sendPacket(new PacketOutCustomSubChannelMessage(channel, message, document));
            }
        } else {
            CloudNet.getInstance().getNetworkManager().sendToProxy(new PacketOutCustomSubChannelMessage(channel, message, document));
        }
    }
}
Also used : ChannelFilter(de.dytanic.cloudnetcore.network.components.util.ChannelFilter) PacketOutCustomSubChannelMessage(de.dytanic.cloudnetcore.network.packet.out.PacketOutCustomSubChannelMessage) INetworkComponent(de.dytanic.cloudnetcore.network.components.INetworkComponent) DefaultType(de.dytanic.cloudnet.lib.DefaultType) CloudServer(de.dytanic.cloudnetcore.network.components.CloudServer) Document(de.dytanic.cloudnet.lib.utility.document.Document) MinecraftServer(de.dytanic.cloudnetcore.network.components.MinecraftServer) ProxyServer(de.dytanic.cloudnetcore.network.components.ProxyServer)

Aggregations

DefaultType (de.dytanic.cloudnet.lib.DefaultType)2 CloudServer (de.dytanic.cloudnetcore.network.components.CloudServer)2 MinecraftServer (de.dytanic.cloudnetcore.network.components.MinecraftServer)2 ProxyServer (de.dytanic.cloudnetcore.network.components.ProxyServer)2 TypeToken (com.google.gson.reflect.TypeToken)1 Document (de.dytanic.cloudnet.lib.utility.document.Document)1 INetworkComponent (de.dytanic.cloudnetcore.network.components.INetworkComponent)1 ChannelFilter (de.dytanic.cloudnetcore.network.components.util.ChannelFilter)1 PacketOutCustomSubChannelMessage (de.dytanic.cloudnetcore.network.packet.out.PacketOutCustomSubChannelMessage)1