diff --git a/pom.xml b/pom.xml index 611fc8d..e3d7bbf 100644 --- a/pom.xml +++ b/pom.xml @@ -35,6 +35,13 @@ + + + placeholderapi + http://repo.extendedclip.com/content/repositories/placeholderapi/ + + + com.destroystokyo.paper @@ -42,6 +49,12 @@ 1.16.3-R0.1-SNAPSHOT provided + + me.clip + placeholderapi + 2.10.9 + provided + \ No newline at end of file diff --git a/src/main/java/com/alttd/destro174/custommotd/CustomMOTD.java b/src/main/java/com/alttd/destro174/custommotd/CustomMOTD.java index 415b672..2148492 100644 --- a/src/main/java/com/alttd/destro174/custommotd/CustomMOTD.java +++ b/src/main/java/com/alttd/destro174/custommotd/CustomMOTD.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.List; import com.alttd.destro174.custommotd.commands.custommotdCommand; +import com.alttd.destro174.custommotd.listener.PapiPingListener; import com.alttd.destro174.custommotd.listener.PingListener; import com.alttd.destro174.custommotd.storage.MOTDConfig; import org.bukkit.Bukkit; @@ -23,6 +24,7 @@ public class CustomMOTD extends JavaPlugin { public int counter; public static List motd; public static CachedServerIcon icon; + public boolean useproxyonlinecount; public List colorList(List list){ @@ -79,6 +81,7 @@ public class CustomMOTD extends JavaPlugin { Options += line + " "; } } + useproxyonlinecount = motdfile.getBoolean("useproxyonline", false); //getLogger().info(Options); } @@ -97,6 +100,7 @@ public class CustomMOTD extends JavaPlugin { for(String line : this.getConfig().getKeys(false)) { Options += line + " "; } + useproxyonlinecount = motdfile.getBoolean("useproxyonline", false); } catch (Throwable t) { getLogger().severe("MOTD - An error has occured!"); @@ -209,7 +213,15 @@ public class CustomMOTD extends JavaPlugin { // TODO add all events PluginManager pm = getServer().getPluginManager(); pm.registerEvents(new PingListener(), this); - //pm.registerEvents(blockListener, this); + if(useproxyonlinecount) { + if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) { + Bukkit.getPluginManager().registerEvents(new PapiPingListener(), this); + } else { + getLogger().warning("Could not find PlaceholderAPI! This plugin is required."); + Bukkit.getPluginManager().disablePlugin(this); + } + } + } private void registerCommands() { diff --git a/src/main/java/com/alttd/destro174/custommotd/listener/PapiPingListener.java b/src/main/java/com/alttd/destro174/custommotd/listener/PapiPingListener.java new file mode 100644 index 0000000..4cd88a4 --- /dev/null +++ b/src/main/java/com/alttd/destro174/custommotd/listener/PapiPingListener.java @@ -0,0 +1,26 @@ +package com.alttd.destro174.custommotd.listener; + +import com.alttd.destro174.custommotd.CustomMOTD; +import com.destroystokyo.paper.event.server.PaperServerListPingEvent; +import me.clip.placeholderapi.PlaceholderAPI; +import org.bukkit.Bukkit; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; + +public class PapiPingListener implements Listener { + + public CustomMOTD instance = CustomMOTD.getInstance(); + + @EventHandler + public void onPing(PaperServerListPingEvent event) { + String bungeeonline = PlaceholderAPI.setPlaceholders(Bukkit.getPlayer("test"), "%bungee_total%"); + int count = 0; + try { + count = Integer.parseInt(bungeeonline); + } catch (NumberFormatException ex) { + count = 0; + } + event.setNumPlayers(count); + } + +} \ No newline at end of file diff --git a/src/main/java/com/alttd/destro174/custommotd/listener/PingListener.java b/src/main/java/com/alttd/destro174/custommotd/listener/PingListener.java index 76403bb..b3f56f9 100644 --- a/src/main/java/com/alttd/destro174/custommotd/listener/PingListener.java +++ b/src/main/java/com/alttd/destro174/custommotd/listener/PingListener.java @@ -12,7 +12,7 @@ public class PingListener implements Listener { public CustomMOTD instance = CustomMOTD.getInstance(); @EventHandler - public void onPing(ServerListPingEvent event) throws IllegalArgumentException, UnsupportedOperationException, Exception { + public void onPing(ServerListPingEvent event) { event.setMotd(CustomMOTD.motd.get(0) + "\n" + CustomMOTD.motd.get(1)); } diff --git a/src/main/resources/MOTD.yml b/src/main/resources/MOTD.yml index 40698f9..771c5d4 100644 --- a/src/main/resources/MOTD.yml +++ b/src/main/resources/MOTD.yml @@ -1,2 +1,3 @@ MOTD: - default \ No newline at end of file + default +useproxyonline: false \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 341438e..da7b6f3 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -2,6 +2,7 @@ name: CustomMOTD main: com.alttd.destro174.custommotd.CustomMOTD version: 1.0 author: destro174 +softdepend: [PlaceholderAPI] commands: custommotd: aliases: [cmotd]