diff --git a/src/com/redstoner/modules/seen/Seen.java b/src/com/redstoner/modules/seen/Seen.java index 78721e1..6c3e8b1 100644 --- a/src/com/redstoner/modules/seen/Seen.java +++ b/src/com/redstoner/modules/seen/Seen.java @@ -31,7 +31,7 @@ import com.redstoner.modules.datamanager.DataManager; @AutoRegisterListener @Commands(CommandHolderType.File) -@Version(major = 4, minor = 0, revision = 0, compatible = 4) +@Version(major = 4, minor = 0, revision = 1, compatible = 4) public class Seen implements Module, Listener { HashMap names = new HashMap<>(); @@ -41,12 +41,13 @@ public class Seen implements Module, Listener public void postEnable() { Module.super.postEnable(); - + for (Player player : Bukkit.getOnlinePlayers()) + loadData(player); } @SuppressWarnings("deprecation") - @Command(hook = "seen", async = AsyncType.ALWAYS) - public boolean seen(CommandSender sender, String player) + @Command(hook = "seen2", async = AsyncType.ALWAYS) + public boolean seen(CommandSender sender, String player, boolean show_ips) { ArrayList message = new ArrayList<>(); OfflinePlayer p = Bukkit.getPlayer(player); @@ -56,7 +57,7 @@ public class Seen implements Module, Listener if (p != null) p = Bukkit.getOfflinePlayer(p.getUniqueId()); } - if (p == null || !p.hasPlayedBefore()) + if (p == null || (!p.isOnline() && !p.hasPlayedBefore())) { getLogger().message(sender, true, "That player has never joined the server!"); return true; @@ -77,15 +78,17 @@ public class Seen implements Module, Listener timestamp = (long) DataManager.getOrDefault(p.getUniqueId().toString(), "lastquit", p.getLastPlayed()); } String time = DateUtil.formatDateDiff(timestamp); - message.add("The player &e" + p.getName() + " &7has been " + state + " &7since " + time + "&7."); + message.add("The player &e" + p.getName() + " &7has been " + state + " &7since &e" + time + "&7."); JSONArray _names; if (online) { if (DataManager.getState((Player) p, "afk")) - message.add("This player is currently &eAFK"); - String reason = (String) DataManager.getOrDefault(p.getUniqueId().toString(), "AFK", "afk_reason", ""); - if (reason.length() >= 1) - message.add(" &5- " + reason); + { + message.add("This player is currently &eAFK&7:"); + String reason = (String) DataManager.getOrDefault(p.getUniqueId().toString(), "AFK", "afk_reason", ""); + if (reason.length() >= 1) + message.add(" &5- " + reason); + } if (DataManager.getState((Player) p, "vanished")) message.add("This player is currently &evanished&7!"); _names = names.get(p.getUniqueId()); @@ -99,14 +102,19 @@ public class Seen implements Module, Listener + _names.toJSONString().replaceAll("[\"\\[\\]]", "").replace(",", "&7, &e")); if (sender.hasPermission("utils.seen.ip")) { - JSONArray _ips; - if (online) - _ips = ips.get(p.getUniqueId()); - else - _ips = loadIPs(p.getUniqueId()); - if (_names != null && _names.size() > 0) - message.add("This player has joined with the following IPs: &e" - + _ips.toJSONString().replaceAll("[\"\\[\\]]", "").replace(",", "&7, &e")); + if (show_ips) + { + JSONArray _ips; + if (online) + _ips = ips.get(p.getUniqueId()); + else + _ips = loadIPs(p.getUniqueId()); + if (_ips != null && _ips.size() > 0) + message.add("This player has joined with the following IPs: &e" + + _ips.toJSONString().replaceAll("[\"\\[\\]]", "").replace(",", "&7, &e")); + } + message.add("This players current IP is: &a" + + DataManager.getOrDefault(p.getUniqueId().toString(), "ip", "unknown")); } getLogger().message(sender, message.toArray(new String[] {})); return true; @@ -116,7 +124,7 @@ public class Seen implements Module, Listener public void onPlayerJoin(PlayerJoinEvent event) { DataManager.setData(event.getPlayer(), "lastjoined", System.currentTimeMillis()); - DataManager.setData(event.getPlayer(), "ip", event.getPlayer().getAddress().getHostName()); + DataManager.setData(event.getPlayer(), "ip", event.getPlayer().getAddress().getHostString()); loadData(event.getPlayer()); } @@ -130,33 +138,47 @@ public class Seen implements Module, Listener @SuppressWarnings("unchecked") public void loadData(Player player) { - File jsonfile = new File(Main.plugin.getDataFolder(), "/seen/" + Utils.getID(player)); - JSONObject json = JsonManager.getObject(jsonfile); - if (json == null) + Thread t = new Thread(new Runnable() { - json = new JSONObject(); - json.put("names", new JSONArray()); - json.put("ips", new JSONArray()); - } - JSONArray names = (JSONArray) json.get("names"); - if (!names.contains(player.getName())) - names.add(player.getName()); - json.put("names", names); - - JSONArray ips = (JSONArray) json.get("ips"); - String ip = player.getAddress().getHostName(); - if (!ips.contains(ip)) - ips.add(ip); - json.put("ips", ips); - - this.names.put(player.getUniqueId(), names); - this.ips.put(player.getUniqueId(), ips); - JsonManager.save(json, jsonfile); + + @Override + public void run() + { + File jsonfile = new File(Main.plugin.getDataFolder(), "/seen/" + Utils.getID(player) + ".json"); + JSONObject json = JsonManager.getObject(jsonfile); + if (json == null) + { + json = new JSONObject(); + json.put("names", new JSONArray()); + json.put("ips", new JSONArray()); + } + JSONArray lnames = (JSONArray) json.get("names"); + if (!lnames.contains(player.getName())) + lnames.add(player.getName()); + json.put("names", names); + + JSONArray lips = (JSONArray) json.get("ips"); + String ip = player.getAddress().getHostString(); + if (!lips.contains(ip)) + lips.add(ip); + json.put("ips", ips); + + names.put(player.getUniqueId(), lnames); + ips.put(player.getUniqueId(), lips); + JsonManager.save(json, jsonfile); + } + }); + t.start(); + } + + public void unloadData(Player player) + { + this.names.remove(player.getUniqueId()); } public JSONArray loadNames(UUID uuid) { - File jsonfile = new File(Main.plugin.getDataFolder(), "/seen/" + uuid); + File jsonfile = new File(Main.plugin.getDataFolder(), "/seen/" + uuid + ".json"); JSONObject json = JsonManager.getObject(jsonfile); if (json == null) return null; @@ -166,16 +188,11 @@ public class Seen implements Module, Listener public JSONArray loadIPs(UUID uuid) { - File jsonfile = new File(Main.plugin.getDataFolder(), "/seen/" + uuid); + File jsonfile = new File(Main.plugin.getDataFolder(), "/seen/" + uuid + ".json"); JSONObject json = JsonManager.getObject(jsonfile); if (json == null) return null; else return (JSONArray) json.get("ips"); } - - public void unloadData(Player player) - { - this.names.remove(player.getUniqueId()); - } }