Fixed lag on player join, fixed format, added "ips" flag
This commit is contained in:
@@ -31,7 +31,7 @@ import com.redstoner.modules.datamanager.DataManager;
|
|||||||
|
|
||||||
@AutoRegisterListener
|
@AutoRegisterListener
|
||||||
@Commands(CommandHolderType.File)
|
@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
|
public class Seen implements Module, Listener
|
||||||
{
|
{
|
||||||
HashMap<UUID, JSONArray> names = new HashMap<>();
|
HashMap<UUID, JSONArray> names = new HashMap<>();
|
||||||
@@ -41,12 +41,13 @@ public class Seen implements Module, Listener
|
|||||||
public void postEnable()
|
public void postEnable()
|
||||||
{
|
{
|
||||||
Module.super.postEnable();
|
Module.super.postEnable();
|
||||||
|
for (Player player : Bukkit.getOnlinePlayers())
|
||||||
|
loadData(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
@Command(hook = "seen", async = AsyncType.ALWAYS)
|
@Command(hook = "seen2", async = AsyncType.ALWAYS)
|
||||||
public boolean seen(CommandSender sender, String player)
|
public boolean seen(CommandSender sender, String player, boolean show_ips)
|
||||||
{
|
{
|
||||||
ArrayList<String> message = new ArrayList<>();
|
ArrayList<String> message = new ArrayList<>();
|
||||||
OfflinePlayer p = Bukkit.getPlayer(player);
|
OfflinePlayer p = Bukkit.getPlayer(player);
|
||||||
@@ -56,7 +57,7 @@ public class Seen implements Module, Listener
|
|||||||
if (p != null)
|
if (p != null)
|
||||||
p = Bukkit.getOfflinePlayer(p.getUniqueId());
|
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!");
|
getLogger().message(sender, true, "That player has never joined the server!");
|
||||||
return true;
|
return true;
|
||||||
@@ -77,15 +78,17 @@ public class Seen implements Module, Listener
|
|||||||
timestamp = (long) DataManager.getOrDefault(p.getUniqueId().toString(), "lastquit", p.getLastPlayed());
|
timestamp = (long) DataManager.getOrDefault(p.getUniqueId().toString(), "lastquit", p.getLastPlayed());
|
||||||
}
|
}
|
||||||
String time = DateUtil.formatDateDiff(timestamp);
|
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;
|
JSONArray _names;
|
||||||
if (online)
|
if (online)
|
||||||
{
|
{
|
||||||
if (DataManager.getState((Player) p, "afk"))
|
if (DataManager.getState((Player) p, "afk"))
|
||||||
message.add("This player is currently &eAFK");
|
{
|
||||||
|
message.add("This player is currently &eAFK&7:");
|
||||||
String reason = (String) DataManager.getOrDefault(p.getUniqueId().toString(), "AFK", "afk_reason", "");
|
String reason = (String) DataManager.getOrDefault(p.getUniqueId().toString(), "AFK", "afk_reason", "");
|
||||||
if (reason.length() >= 1)
|
if (reason.length() >= 1)
|
||||||
message.add(" &5- " + reason);
|
message.add(" &5- " + reason);
|
||||||
|
}
|
||||||
if (DataManager.getState((Player) p, "vanished"))
|
if (DataManager.getState((Player) p, "vanished"))
|
||||||
message.add("This player is currently &evanished&7!");
|
message.add("This player is currently &evanished&7!");
|
||||||
_names = names.get(p.getUniqueId());
|
_names = names.get(p.getUniqueId());
|
||||||
@@ -98,16 +101,21 @@ public class Seen implements Module, Listener
|
|||||||
message.add("This player has also been known as: &e"
|
message.add("This player has also been known as: &e"
|
||||||
+ _names.toJSONString().replaceAll("[\"\\[\\]]", "").replace(",", "&7, &e"));
|
+ _names.toJSONString().replaceAll("[\"\\[\\]]", "").replace(",", "&7, &e"));
|
||||||
if (sender.hasPermission("utils.seen.ip"))
|
if (sender.hasPermission("utils.seen.ip"))
|
||||||
|
{
|
||||||
|
if (show_ips)
|
||||||
{
|
{
|
||||||
JSONArray _ips;
|
JSONArray _ips;
|
||||||
if (online)
|
if (online)
|
||||||
_ips = ips.get(p.getUniqueId());
|
_ips = ips.get(p.getUniqueId());
|
||||||
else
|
else
|
||||||
_ips = loadIPs(p.getUniqueId());
|
_ips = loadIPs(p.getUniqueId());
|
||||||
if (_names != null && _names.size() > 0)
|
if (_ips != null && _ips.size() > 0)
|
||||||
message.add("This player has joined with the following IPs: &e"
|
message.add("This player has joined with the following IPs: &e"
|
||||||
+ _ips.toJSONString().replaceAll("[\"\\[\\]]", "").replace(",", "&7, &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[] {}));
|
getLogger().message(sender, message.toArray(new String[] {}));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -116,7 +124,7 @@ public class Seen implements Module, Listener
|
|||||||
public void onPlayerJoin(PlayerJoinEvent event)
|
public void onPlayerJoin(PlayerJoinEvent event)
|
||||||
{
|
{
|
||||||
DataManager.setData(event.getPlayer(), "lastjoined", System.currentTimeMillis());
|
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());
|
loadData(event.getPlayer());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,7 +138,13 @@ public class Seen implements Module, Listener
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void loadData(Player player)
|
public void loadData(Player player)
|
||||||
{
|
{
|
||||||
File jsonfile = new File(Main.plugin.getDataFolder(), "/seen/" + Utils.getID(player));
|
Thread t = new Thread(new Runnable()
|
||||||
|
{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
File jsonfile = new File(Main.plugin.getDataFolder(), "/seen/" + Utils.getID(player) + ".json");
|
||||||
JSONObject json = JsonManager.getObject(jsonfile);
|
JSONObject json = JsonManager.getObject(jsonfile);
|
||||||
if (json == null)
|
if (json == null)
|
||||||
{
|
{
|
||||||
@@ -138,25 +152,33 @@ public class Seen implements Module, Listener
|
|||||||
json.put("names", new JSONArray());
|
json.put("names", new JSONArray());
|
||||||
json.put("ips", new JSONArray());
|
json.put("ips", new JSONArray());
|
||||||
}
|
}
|
||||||
JSONArray names = (JSONArray) json.get("names");
|
JSONArray lnames = (JSONArray) json.get("names");
|
||||||
if (!names.contains(player.getName()))
|
if (!lnames.contains(player.getName()))
|
||||||
names.add(player.getName());
|
lnames.add(player.getName());
|
||||||
json.put("names", names);
|
json.put("names", names);
|
||||||
|
|
||||||
JSONArray ips = (JSONArray) json.get("ips");
|
JSONArray lips = (JSONArray) json.get("ips");
|
||||||
String ip = player.getAddress().getHostName();
|
String ip = player.getAddress().getHostString();
|
||||||
if (!ips.contains(ip))
|
if (!lips.contains(ip))
|
||||||
ips.add(ip);
|
lips.add(ip);
|
||||||
json.put("ips", ips);
|
json.put("ips", ips);
|
||||||
|
|
||||||
this.names.put(player.getUniqueId(), names);
|
names.put(player.getUniqueId(), lnames);
|
||||||
this.ips.put(player.getUniqueId(), ips);
|
ips.put(player.getUniqueId(), lips);
|
||||||
JsonManager.save(json, jsonfile);
|
JsonManager.save(json, jsonfile);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
t.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unloadData(Player player)
|
||||||
|
{
|
||||||
|
this.names.remove(player.getUniqueId());
|
||||||
|
}
|
||||||
|
|
||||||
public JSONArray loadNames(UUID uuid)
|
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);
|
JSONObject json = JsonManager.getObject(jsonfile);
|
||||||
if (json == null)
|
if (json == null)
|
||||||
return null;
|
return null;
|
||||||
@@ -166,16 +188,11 @@ public class Seen implements Module, Listener
|
|||||||
|
|
||||||
public JSONArray loadIPs(UUID uuid)
|
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);
|
JSONObject json = JsonManager.getObject(jsonfile);
|
||||||
if (json == null)
|
if (json == null)
|
||||||
return null;
|
return null;
|
||||||
else
|
else
|
||||||
return (JSONArray) json.get("ips");
|
return (JSONArray) json.get("ips");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unloadData(Player player)
|
|
||||||
{
|
|
||||||
this.names.remove(player.getUniqueId());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user