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);
}
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);
}
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);
}
Aggregations