@Override protected void run(Player p, SLPlayer slp, Command cmd, String[] args) { p.sendMessage( ChatColor.DARK_GRAY + "[ " + ChatColor.GRAY + "============ " + ChatColor.DARK_AQUA + "Spawns" + ChatColor.GRAY + " ============" + ChatColor.DARK_GRAY + " ]"); ModifiableFinal<Integer> current = new ModifiableFinal<>(1); SpleefLeague.getInstance() .getSpawnManager() .getAll() .forEach( (SpawnManager.SpawnLocation spawnLocation) -> { ComponentBuilder componentBuilder = new ComponentBuilder("#" + current.getValue()) .color(ChatColor.RED.asBungee()) .append(" | ") .color(ChatColor.DARK_GRAY.asBungee()) .append("CLICK TO TELEPORT") .color(ChatColor.GRAY.asBungee()) .event( new ClickEvent( ClickEvent.Action.RUN_COMMAND, "/tppos " + spawnLocation.getLocation().getBlockX() + " " + spawnLocation.getLocation().getBlockY() + ' ' + spawnLocation.getLocation().getBlockZ())) .append(" | ") .color(ChatColor.DARK_GRAY.asBungee()) .append(spawnLocation.getPlayersInRadius() + " players") .color(ChatColor.GRAY.asBungee()); slp.spigot().sendMessage(componentBuilder.create()); current.setValue(current.getValue() + 1); }); p.sendMessage( ChatColor.RED + "All spawns were cached " + TimeUtil.dateToString( new Date(SpleefLeague.getInstance().getSpawnManager().getLastCached()), false) + " ago."); }
public String getState() { if (!slp.isOnline()) { Document dbo = SpleefLeague.getInstance() .getPluginDB() .getCollection("ActiveInfractions") .find(new Document("uuid", slp.getUniqueId().toString())) .first(); if (dbo != null) { Infraction inf = EntityBuilder.load(dbo, Infraction.class); if (inf.getType() == InfractionType.BAN) { return ChatColor.DARK_RED + "BANNED"; } else if (inf.getType() == InfractionType.TEMPBAN) { if (inf.getTime() + inf.getDuration() > System.currentTimeMillis()) { return ChatColor.RED + "TEMPBANNED" + ChatColor.GRAY + " (for " + TimeUtil.dateToString(new Date(inf.getTime() + inf.getDuration()), true) + ")"; } } } return ChatColor.GRAY + "OFFLINE"; } else { return ChatColor.GREEN + StringUtil.upperCaseFirst(slp.getState().toString()); } }
static { Bukkit.getScheduler() .scheduleSyncRepeatingTask( SpleefLeague.getInstance(), () -> AFFECTED_PLAYERS.forEach((p, i) -> i.sendToPlayer(p)), INTERVAL, INTERVAL); }
public String getSharedAccounts() { String playerUUID = slp.getUniqueId().toString(); Set<String> sharedUUIDs = new HashSet<>(); Collection<String> ips = new HashSet<>(); MongoCollection<Document> col = SpleefLeague.getInstance().getPluginDB().getCollection("PlayerConnections"); Date lastOnline = null; for (Document doc : col.find(new Document("uuid", playerUUID))) { ips.add(doc.get("ip", String.class)); if (lastOnline == null) { lastOnline = doc.get("date", Date.class); } else { Date d = doc.get("date", Date.class); if (lastOnline.before(d)) { lastOnline = d; } } } lastSeen = lastOnline != null ? TimeUtil.dateToString(lastOnline, false) + " ago" : "Unknown"; Set<Document> orQuerry = new HashSet<>(); for (String ip : ips) { orQuerry.add(new Document("ip", ip)); Thread.currentThread().getStackTrace(); } if (!orQuerry.isEmpty()) { for (Document doc : col.find(new Document("$or", orQuerry))) { String uuid = doc.get("uuid", String.class); if (!uuid.equals(playerUUID)) { sharedUUIDs.add(uuid); } } } col = SpleefLeague.getInstance().getPluginDB().getCollection("Players"); String sharedUsernames = null; for (String uuid : sharedUUIDs) { if (sharedUsernames == null) { sharedUsernames = col.find(new Document("uuid", uuid)).first().get("username", String.class); } else { sharedUsernames += ", " + col.find(new Document("uuid", uuid)).first().get("username", String.class); } } return sharedUsernames; }
@Override protected void run(Player p, SLPlayer slp, Command cmd, String[] args) { if (args.length < 2) { String targetName = (args.length == 0) ? p.getName() : args[0]; Player targetPlayer = Bukkit.getPlayer(targetName); Bukkit.getScheduler() .runTaskAsynchronously( SpleefLeague.getInstance(), () -> { SLPlayer target; if (targetPlayer != null) { target = SpleefLeague.getInstance().getPlayerManager().get(targetPlayer); } else { target = SpleefLeague.getInstance().getPlayerManager().loadFake(targetName); if (target == null) { error(p, targetName + " does not exist."); return; } } JSONObject request = new JSONObject(); request.put("uuid", target.getUniqueId().toString()); request.put("action", "GET_PLAYER"); new ConnectionResponseHandler("sessions", request, 40) { @Override protected void response(JSONObject jsonObject) { PlayerData data = new PlayerData(target); p.sendMessage( ChatColor.DARK_GRAY + "[========== " + ChatColor.GRAY + targetName + "'s data " + ChatColor.DARK_GRAY + "==========]"); p.sendMessage(ChatColor.DARK_GRAY + "Name: " + ChatColor.GRAY + data.getName()); TextComponent uuidFirst = new TextComponent("UUID: "); uuidFirst.setColor(ChatColor.DARK_GRAY); TextComponent uuidSecond = new TextComponent(data.getUUID()); uuidSecond.setColor(ChatColor.GRAY); uuidSecond.setHoverEvent( new HoverEvent( HoverEvent.Action.SHOW_TEXT, new BaseComponent[] {new TextComponent("Click to put in chatbox")})); uuidSecond.setClickEvent( new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, data.getUUID())); uuidFirst.addExtra(uuidSecond); p.spigot().sendMessage(uuidFirst); p.sendMessage(ChatColor.DARK_GRAY + "Rank: " + ChatColor.GRAY + data.getRank()); if (data.getState().equalsIgnoreCase("OFFLINE") && jsonObject != null && !jsonObject.get("playerServer").toString().equalsIgnoreCase("OFFLINE")) { p.sendMessage(ChatColor.DARK_GRAY + "State: ONLINE"); } else { p.sendMessage(ChatColor.DARK_GRAY + "State: " + data.getState()); } if (target.isOnline()) { p.sendMessage(ChatColor.DARK_GRAY + "IP: " + ChatColor.GRAY + data.getIP()); } else { p.sendMessage( ChatColor.DARK_GRAY + "Last seen: " + ChatColor.GRAY + data.getLastSeen()); } p.sendMessage( ChatColor.DARK_GRAY + "Server: " + ChatColor.GRAY + (jsonObject == null ? "NONE (OFFLINE)" : jsonObject.get("playerServer").toString())); String sharedAccounts = data.getSharedAccounts(); if (sharedAccounts != null) { p.sendMessage( ChatColor.DARK_GRAY + "Shared accounts: " + ChatColor.GRAY + sharedAccounts); } } }; }); } else { sendUsage(p); } }