diff --git a/plugin.yml b/plugin.yml index 0e55209..d70a25d 100755 --- a/plugin.yml +++ b/plugin.yml @@ -1,6 +1,6 @@ name: ServerlistMOTD author: Strumswell -version: X-FIRESTORM +version: X-2018-10-20 description: Change your Serverlist Motd! load: POSTWORLD depend: [ProtocolLib] diff --git a/src/cloud/bolte/serverlistmotd/Main.java b/src/cloud/bolte/serverlistmotd/Main.java index 8cc70cc..460a2d1 100644 --- a/src/cloud/bolte/serverlistmotd/Main.java +++ b/src/cloud/bolte/serverlistmotd/Main.java @@ -7,7 +7,6 @@ import java.util.UUID; import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; import org.bukkit.event.Listener; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitScheduler; @@ -17,7 +16,6 @@ import cloud.bolte.serverlistmotd.events.Ping; import cloud.bolte.serverlistmotd.events.ProtocolLibImplementation; import cloud.bolte.serverlistmotd.events.RestrictedModeJoin; -import cloud.bolte.serverlistmotd.motd.MotdState; import cloud.bolte.serverlistmotd.util.IO; import cloud.bolte.serverlistmotd.util.VaultIntegration; @@ -34,7 +32,7 @@ public class Main extends JavaPlugin implements Listener { public static Map IP_UUID = new HashMap(); - + @Override public void onDisable() { //Prepare HashMap and save it to disk diff --git a/src/cloud/bolte/serverlistmotd/motd/BanManagerMotd.java b/src/cloud/bolte/serverlistmotd/motd/BanManagerMotd.java index 813cc7e..8f32cda 100644 --- a/src/cloud/bolte/serverlistmotd/motd/BanManagerMotd.java +++ b/src/cloud/bolte/serverlistmotd/motd/BanManagerMotd.java @@ -45,6 +45,10 @@ public String formatMotd(String motd, InetAddress ip) { .replace("%time%", TimeVariable.getTime()); String playerName = Bukkit.getOfflinePlayer(Main.IP_UUID.get(ip)).getName(); + + if(playerName.equals(null)) { + playerName = "Strumswell"; + } BanInterface ban = new BanManager(); Date timestampconv = new Date((long) ban.expires(playerName) * 1000); diff --git a/src/cloud/bolte/serverlistmotd/motd/BanMotd.java b/src/cloud/bolte/serverlistmotd/motd/BanMotd.java index 0d7ced4..2f0ab45 100644 --- a/src/cloud/bolte/serverlistmotd/motd/BanMotd.java +++ b/src/cloud/bolte/serverlistmotd/motd/BanMotd.java @@ -77,8 +77,10 @@ public String formatMotd(String motd, InetAddress ip) { public void setBanMotd(ServerListPingEvent e, InetAddress ip) { if (Main.IP_UUID.containsKey(ip)) { OfflinePlayer p = Bukkit.getOfflinePlayer(Main.IP_UUID.get(ip)); - if (p.isBanned()) { - e.setMotd(formatMotd(getMOTD(ip), ip)); + if (p.hasPlayedBefore()) { + if (p.isBanned()) { + e.setMotd(formatMotd(getMOTD(ip), ip)); + } } } } diff --git a/src/cloud/bolte/serverlistmotd/motd/MaxBansMotd.java b/src/cloud/bolte/serverlistmotd/motd/MaxBansMotd.java index c3181ef..ac8cc3c 100644 --- a/src/cloud/bolte/serverlistmotd/motd/MaxBansMotd.java +++ b/src/cloud/bolte/serverlistmotd/motd/MaxBansMotd.java @@ -4,6 +4,7 @@ import org.bukkit.Bukkit; import org.bukkit.ChatColor; +import org.bukkit.OfflinePlayer; import org.bukkit.event.server.ServerListPingEvent; import org.maxgamer.maxbans.MaxBans; import org.maxgamer.maxbans.banmanager.TempBan; @@ -78,9 +79,11 @@ public String formatMotd(String motd, InetAddress ip) { */ public void setBanMotd(ServerListPingEvent e, InetAddress ip) { //Check if player is known and set motd - if (Main.IP_UUID.containsKey(ip) && MaxBans.instance.getBanManager() - .getBan(Bukkit.getOfflinePlayer(Main.IP_UUID.get(ip)).getName()) != null) { + OfflinePlayer p = Bukkit.getOfflinePlayer(Main.IP_UUID.get(ip)); + if (p.hasPlayedBefore()) { + if (Main.IP_UUID.containsKey(ip) && MaxBans.instance.getBanManager().getBan(p.getName()) != null) { e.setMotd(formatMotd(getMOTD(ip), ip)); + } } } } diff --git a/src/cloud/bolte/serverlistmotd/variables/MoneyVariable.java b/src/cloud/bolte/serverlistmotd/variables/MoneyVariable.java index 9cfa138..d66198e 100644 --- a/src/cloud/bolte/serverlistmotd/variables/MoneyVariable.java +++ b/src/cloud/bolte/serverlistmotd/variables/MoneyVariable.java @@ -3,6 +3,7 @@ import java.net.InetAddress; import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; import cloud.bolte.serverlistmotd.Main; import cloud.bolte.serverlistmotd.util.VaultIntegration; @@ -25,8 +26,14 @@ public class MoneyVariable { */ public static Double getMoney(InetAddress ip) { try { - return VaultIntegration.getEcononomy().getBalance - (Bukkit.getOfflinePlayer(Main.IP_UUID.get(ip))); + OfflinePlayer p = Bukkit.getOfflinePlayer(Main.IP_UUID.get(ip)); + if (p.hasPlayedBefore()) { + return VaultIntegration.getEcononomy().getBalance(p); + }else { + //User is uncached by Spigot + //p is null + return 0d; + } } catch (NullPointerException npe) { return -1d; } catch (NoClassDefFoundError nc) { diff --git a/src/cloud/bolte/serverlistmotd/variables/PlayerVariable.java b/src/cloud/bolte/serverlistmotd/variables/PlayerVariable.java index 146fbc1..30a5ebf 100644 --- a/src/cloud/bolte/serverlistmotd/variables/PlayerVariable.java +++ b/src/cloud/bolte/serverlistmotd/variables/PlayerVariable.java @@ -36,7 +36,13 @@ public static boolean isKnownPlayer(InetAddress ip) { */ public static String getNameFromIP(InetAddress ip) { OfflinePlayer p = Bukkit.getOfflinePlayer(Main.IP_UUID.get(ip)); - return p.getName(); + if (p.hasPlayedBefore()) { + return p.getName(); + }else { + //User is uncached by Spigot + //p is null + return ""; + } } } diff --git a/src/cloud/bolte/serverlistmotd/variables/RandomPlayerVariable.java b/src/cloud/bolte/serverlistmotd/variables/RandomPlayerVariable.java index d26c244..5375f34 100644 --- a/src/cloud/bolte/serverlistmotd/variables/RandomPlayerVariable.java +++ b/src/cloud/bolte/serverlistmotd/variables/RandomPlayerVariable.java @@ -5,6 +5,7 @@ import java.util.UUID; import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; import cloud.bolte.serverlistmotd.Main; @@ -47,9 +48,18 @@ private static String getRandomOfflinePlayer() { if (SpigotConfig.randomPlayerVariableUseTextEnabled()) { return SpigotConfig.getRandomPlayerVariableText(); } else { - return Bukkit.getOfflinePlayer(values.get(index)).getName(); + OfflinePlayer p = Bukkit.getOfflinePlayer(values.get(index)); + if (p.hasPlayedBefore()) { + return p.getName(); + }else { + //User is uncached by Spigot + //p is null + return ""; + } } } else { + //No player joined before + //Just returning my name ;-) return "Strumswell"; } }