use of io.alerium.chocolate.object.PlayerData in project Chocolate by GiansCode.
the class ProxyIdCommand method perform.
@Override
public void perform(CommandSource commandSource, String[] args) {
if (!(commandSource instanceof Player)) {
sendMessage(commandSource, StringUtils.getInstance().colorize(Lang.GENERIC$MUST_BE_A_PLAYER.getString()));
return;
}
PlayerData playerData = this.chocolatePlugin.getCacheManager().getPlayerData(((Player) commandSource).getUniqueId());
sendMessage(commandSource, StringUtils.getInstance().replacePlaceholders(Lang.COMMAND$PROXY_ID$ID.getString(), "%proxyId%", playerData.getProxy()));
}
use of io.alerium.chocolate.object.PlayerData in project Chocolate by GiansCode.
the class LastSeenCommand method perform.
@Override
public void perform(CommandSource commandSource, String[] args) {
if (args.length == 0) {
sendUsageMessage(commandSource);
return;
}
PlayerData playerData = this.chocolatePlugin.getCacheManager().getPlayerData(args[0]);
if (playerData == null || playerData.getLastOnline() == null) {
sendMessage(commandSource, StringUtils.getInstance().replacePlaceholders(Lang.GENERIC$PLAYER_NOT_FOUND.getString(), "%player%", args[0]));
return;
}
String lastSeen = DurationFormatUtils.formatDurationWords(Instant.now().toEpochMilli() - playerData.getLastOnline(), true, true);
sendMessage(commandSource, StringUtils.getInstance().replacePlaceholders(Lang.COMMAND$LAST_SEEN$FOUND.getString(), "%player%", args[0], "%seen%", lastSeen));
}
use of io.alerium.chocolate.object.PlayerData in project Chocolate by GiansCode.
the class PluginMessageListener method onPluginMessage.
@Subscribe
public void onPluginMessage(PluginMessageEvent event) {
if (!event.getIdentifier().equals(LEGACY_CHANNEL) && !event.getIdentifier().equals(MODERN_CHANNEL))
return;
event.setResult(PluginMessageEvent.ForwardResult.handled());
if (!(event.getSource() instanceof ServerConnection))
return;
ServerConnection connection = (ServerConnection) event.getSource();
ByteArrayDataInput input = event.dataAsDataStream();
ByteArrayDataOutput output = ByteStreams.newDataOutput();
String subChannel = input.readUTF();
switch(subChannel.toUpperCase()) {
case "PLAYERLIST":
{
String server = input.readUTF();
Set<UUID> players = plugin.getCacheManager().getOnlinePlayersInServer(server.toLowerCase());
StringBuilder sb = new StringBuilder();
for (UUID uuid : players) sb.append(uuid).append(", ");
if (sb.length() != 0)
sb.setLength(sb.length() - 2);
output.writeUTF("PlayerList");
output.writeUTF(server);
output.writeUTF(sb.toString());
break;
}
case "PLAYERCOUNT":
{
String server = input.readUTF();
int players;
if (server.equalsIgnoreCase("ALL"))
players = plugin.getSyncManager().getOnlinePlayers();
else
players = plugin.getCacheManager().getOnlinePlayersInServer(server.toLowerCase()).size();
output.writeUTF("PlayerCount");
output.writeUTF(server);
output.writeInt(players);
break;
}
case "LASTONLINE":
{
String name = input.readUTF();
PlayerData data = plugin.getCacheManager().getPlayerData(name);
output.writeUTF("LastOnline");
output.writeUTF(name);
output.writeLong(data.getLastOnline());
break;
}
case "PROXY":
{
String uuidS = input.readUTF();
output.writeUTF("Proxy");
output.writeUTF(uuidS);
UUID uuid = UUID.fromString(uuidS);
if (plugin.getServer().getPlayer(uuid).isPresent())
output.writeUTF(plugin.getRedisManager().getProxyId());
else
output.writeUTF(plugin.getCacheManager().getPlayerData(uuid).getProxy());
break;
}
default:
return;
}
connection.sendPluginMessage(event.getIdentifier(), output.toByteArray());
}
use of io.alerium.chocolate.object.PlayerData in project Chocolate by GiansCode.
the class SyncManager method createPlayer.
/**
* Create a player his data, mostly used on player join.
*
* @param player The player you want to create the data from
*/
public void createPlayer(Player player) {
if (!player.getCurrentServer().isPresent())
throw new NullPointerException("Player must be in a server.");
PlayerData playerData = chocolatePlugin.getCacheManager().getPlayerData(player.getUniqueId());
if (playerData == null)
playerData = new PlayerData(player.getUniqueId());
playerData.setProxy(proxyId);
playerData.setIp(player.getRemoteAddress().getAddress().getHostAddress());
playerData.setServer(player.getCurrentServer().get().getServerInfo().getName());
playerData.setLastOnline(Instant.now().toEpochMilli());
redissonClient.getMap("online:playersData").put(player.getUniqueId(), playerData);
}
use of io.alerium.chocolate.object.PlayerData in project Chocolate by GiansCode.
the class SyncManager method setServer.
/**
* Change the server the player is on.
*
* @param uuid The UUID of the player where you want to change the server from
* @param server The server you want to change it to
*/
public void setServer(UUID uuid, String server) {
PlayerData playerData = chocolatePlugin.getCacheManager().getPlayerData(uuid);
if (playerData == null | server == null)
return;
playerData.setServer(server);
redissonClient.getMap("online:playersData").put(uuid, playerData);
}
Aggregations