use of de.dytanic.cloudnet.lib.player.PlayerExecutor 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