Search in sources :

Example 1 with PlayerConnection

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

the class ProxiedListener method handleLogin.

@EventHandler(priority = EventPriority.LOWEST)
public void handleLogin(LoginEvent e) {
    PlayerConnection playerConnection = new PlayerConnection(e.getConnection().getUniqueId(), e.getConnection().getName(), e.getConnection().getVersion(), e.getConnection().getAddress().getAddress().getHostAddress(), e.getConnection().getAddress().getPort(), e.getConnection().isOnlineMode(), e.getConnection().isLegacy());
    CloudPlayer cloudPlayer = CloudAPI.getInstance().getNetworkConnection().getPacketManager().sendQuery(new PacketOutPlayerLoginRequest(playerConnection), CloudAPI.getInstance().getNetworkConnection()).getResult().getObject("player", new TypeToken<CloudPlayer>() {
    }.getType());
    if (cloudPlayer == null) {
        e.setCancelReason(TextComponent.fromLegacyText("§cYou are already on the network!"));
        e.setCancelled(true);
    }
    CommandSender cloudCommandSender = new CloudPlayerCommandSender(cloudPlayer);
    if (CloudProxy.getInstance().getProxyGroup() != null) {
        ProxyConfig proxyConfig = CloudProxy.getInstance().getProxyGroup().getProxyConfig();
        if ((proxyConfig.isEnabled() && proxyConfig.isMaintenance())) {
            PermissionCheckEvent permissionCheckEvent = new PermissionCheckEvent(cloudCommandSender, "cloudnet.maintenance", false);
            if (!proxyConfig.getWhitelist().contains(e.getConnection().getName()) && !ProxyServer.getInstance().getPluginManager().callEvent(permissionCheckEvent).hasPermission()) {
                e.setCancelled(true);
                e.setCancelReason(ChatColor.translateAlternateColorCodes('&', CloudAPI.getInstance().getCloudNetwork().getMessages().getString("kick-maintenance")));
                return;
            }
        }
    }
    ProxyGroup proxyGroup = CloudProxy.getInstance().getProxyGroup();
    if (proxyGroup.getProxyConfig().isEnabled())
        if (CloudAPI.getInstance().getOnlineCount() >= CloudProxy.getInstance().getProxyGroup().getProxyConfig().getMaxPlayers()) {
            PermissionCheckEvent permissionCheckEvent = new PermissionCheckEvent(cloudCommandSender, "cloudnet.fulljoin", false);
            if (!ProxyServer.getInstance().getPluginManager().callEvent(permissionCheckEvent).hasPermission()) {
                e.setCancelled(true);
                e.setCancelReason(ChatColor.translateAlternateColorCodes('&', CloudAPI.getInstance().getCloudNetwork().getMessages().getString("full-join")));
                return;
            }
        }
    CloudProxy.getInstance().getCloudPlayers().put(cloudPlayer.getUniqueId(), cloudPlayer);
}
Also used : CloudPlayerCommandSender(de.dytanic.cloudnet.bridge.internal.util.CloudPlayerCommandSender) ProxyGroup(de.dytanic.cloudnet.lib.server.ProxyGroup) TypeToken(com.google.gson.reflect.TypeToken) CloudPlayer(de.dytanic.cloudnet.lib.player.CloudPlayer) CommandSender(net.md_5.bungee.api.CommandSender) CloudPlayerCommandSender(de.dytanic.cloudnet.bridge.internal.util.CloudPlayerCommandSender) ProxyConfig(de.dytanic.cloudnet.lib.proxylayout.ProxyConfig) PlayerConnection(de.dytanic.cloudnet.lib.player.PlayerConnection) EventHandler(net.md_5.bungee.event.EventHandler)

Example 2 with PlayerConnection

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

the class PacketInPlayerLoginRequest method handleInput.

@Override
public void handleInput(Document data, PacketSender packetSender) {
    if (!(packetSender instanceof ProxyServer) && packetUniqueId != null)
        return;
    PlayerConnection playerConnection = data.getObject("playerConnection", new TypeToken<PlayerConnection>() {
    }.getType());
    CloudNet.getInstance().getNetworkManager().handlePlayerLoginRequest(((ProxyServer) packetSender), playerConnection, packetUniqueId);
}
Also used : TypeToken(com.google.gson.reflect.TypeToken) PlayerConnection(de.dytanic.cloudnet.lib.player.PlayerConnection) ProxyServer(de.dytanic.cloudnetcore.network.components.ProxyServer)

Example 3 with PlayerConnection

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

the class PlayerExample method examplePlayer.

public void examplePlayer() {
    // Returns the CloudPlayer if the play is online or null if isn't online
    CloudPlayer cloudPlayer = CloudAPI.getInstance().getOnlinePlayer(UUID.fromString("e71d69dd-058f-4319-9ae9-8c8f0a7a61f5"));
    {
        // Returns the online player connection metadata
        PlayerConnection playerConnection = cloudPlayer.getPlayerConnection();
        // Returns the IP
        playerConnection.getHost();
        // Returns the port of the last connection
        playerConnection.getPort();
        // Returns the UUID of the connection
        playerConnection.getUniqueId();
        // Returns the legacy version
        playerConnection.getVersion();
        // Returns if the player was in onlinemode
        playerConnection.isOnlineMode();
    }
    System.out.println("The player " + cloudPlayer.getName() + " is on " + cloudPlayer.getProxy() + NetworkUtils.SLASH_STRING + cloudPlayer.getServer() + " and connected at " + cloudPlayer.getLoginTimeStamp().getTime());
    // Returns a util Class for some network methods
    PlayerExecutor playerExecutor = cloudPlayer.getPlayerExecutor();
    // writes a message to the player if the player is online
    playerExecutor.sendMessage(cloudPlayer, "Hello world!");
    // send a player to a some server
    playerExecutor.sendPlayer(cloudPlayer, "Lobby-2");
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            // Kick a player from the network
            playerExecutor.kickPlayer(cloudPlayer, "you are a cool guy for the network");
        }
    }).start();
    OfflinePlayer offlinePlayer = CloudAPI.getInstance().getOfflinePlayer("Dytanic");
    if (// If the player is registered
    offlinePlayer != null) {
        // Returns the permissionentity for manage some permission systems
        PermissionEntity permissionEntity = offlinePlayer.getPermissionEntity();
        // add a permission group with the delay of 30 days
        permissionEntity.getGroups().add(new GroupEntityData("VIP", System.currentTimeMillis() + TimeUnit.DAYS.toMillis(30)));
        // add a permission for this player
        permissionEntity.getPermissions().put("minecraft.command.tp", true);
        if (permissionEntity.isInGroup("VIP")) {
            System.out.println("The player " + offlinePlayer.getUniqueId() + NetworkUtils.SLASH_STRING + offlinePlayer.getName() + " is in the group VIP");
        }
        PlayerConnection playerConnection = offlinePlayer.getLastPlayerConnection();
        // Returns the IP
        playerConnection.getHost();
        // Returns the port of the last connection
        playerConnection.getPort();
        // Returns the UUID of the connection
        playerConnection.getUniqueId();
        // Returns the legacy version
        playerConnection.getVersion();
        // Returns if the player was in onlinemode
        playerConnection.isOnlineMode();
    }
    // update the player
    // cloudplayer update
    CloudAPI.getInstance().updatePlayer(cloudPlayer);
    // update the offline player
    CloudAPI.getInstance().updatePlayer(offlinePlayer);
}
Also used : PlayerExecutor(de.dytanic.cloudnet.lib.player.PlayerExecutor) CloudPlayer(de.dytanic.cloudnet.lib.player.CloudPlayer) OfflinePlayer(de.dytanic.cloudnet.lib.player.OfflinePlayer) PermissionEntity(de.dytanic.cloudnet.lib.player.permission.PermissionEntity) PlayerConnection(de.dytanic.cloudnet.lib.player.PlayerConnection) GroupEntityData(de.dytanic.cloudnet.lib.player.permission.GroupEntityData)

Aggregations

PlayerConnection (de.dytanic.cloudnet.lib.player.PlayerConnection)3 TypeToken (com.google.gson.reflect.TypeToken)2 CloudPlayer (de.dytanic.cloudnet.lib.player.CloudPlayer)2 CloudPlayerCommandSender (de.dytanic.cloudnet.bridge.internal.util.CloudPlayerCommandSender)1 OfflinePlayer (de.dytanic.cloudnet.lib.player.OfflinePlayer)1 PlayerExecutor (de.dytanic.cloudnet.lib.player.PlayerExecutor)1 GroupEntityData (de.dytanic.cloudnet.lib.player.permission.GroupEntityData)1 PermissionEntity (de.dytanic.cloudnet.lib.player.permission.PermissionEntity)1 ProxyConfig (de.dytanic.cloudnet.lib.proxylayout.ProxyConfig)1 ProxyGroup (de.dytanic.cloudnet.lib.server.ProxyGroup)1 ProxyServer (de.dytanic.cloudnetcore.network.components.ProxyServer)1 CommandSender (net.md_5.bungee.api.CommandSender)1 EventHandler (net.md_5.bungee.event.EventHandler)1