Add option to show bungee online player count
This commit is contained in:
parent
cb6e714617
commit
2555add7a9
13
pom.xml
13
pom.xml
|
|
@ -35,6 +35,13 @@
|
||||||
</resources>
|
</resources>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>placeholderapi</id>
|
||||||
|
<url>http://repo.extendedclip.com/content/repositories/placeholderapi/</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.destroystokyo.paper</groupId>
|
<groupId>com.destroystokyo.paper</groupId>
|
||||||
|
|
@ -42,6 +49,12 @@
|
||||||
<version>1.16.3-R0.1-SNAPSHOT</version>
|
<version>1.16.3-R0.1-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>me.clip</groupId>
|
||||||
|
<artifactId>placeholderapi</artifactId>
|
||||||
|
<version>2.10.9</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.alttd.destro174.custommotd.commands.custommotdCommand;
|
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.listener.PingListener;
|
||||||
import com.alttd.destro174.custommotd.storage.MOTDConfig;
|
import com.alttd.destro174.custommotd.storage.MOTDConfig;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
|
@ -23,6 +24,7 @@ public class CustomMOTD extends JavaPlugin {
|
||||||
public int counter;
|
public int counter;
|
||||||
public static List<String> motd;
|
public static List<String> motd;
|
||||||
public static CachedServerIcon icon;
|
public static CachedServerIcon icon;
|
||||||
|
public boolean useproxyonlinecount;
|
||||||
|
|
||||||
|
|
||||||
public List<String> colorList(List<String> list){
|
public List<String> colorList(List<String> list){
|
||||||
|
|
@ -79,6 +81,7 @@ public class CustomMOTD extends JavaPlugin {
|
||||||
Options += line + " ";
|
Options += line + " ";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
useproxyonlinecount = motdfile.getBoolean("useproxyonline", false);
|
||||||
//getLogger().info(Options);
|
//getLogger().info(Options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -97,6 +100,7 @@ public class CustomMOTD extends JavaPlugin {
|
||||||
for(String line : this.getConfig().getKeys(false)) {
|
for(String line : this.getConfig().getKeys(false)) {
|
||||||
Options += line + " ";
|
Options += line + " ";
|
||||||
}
|
}
|
||||||
|
useproxyonlinecount = motdfile.getBoolean("useproxyonline", false);
|
||||||
}
|
}
|
||||||
catch (Throwable t) {
|
catch (Throwable t) {
|
||||||
getLogger().severe("MOTD - An error has occured!");
|
getLogger().severe("MOTD - An error has occured!");
|
||||||
|
|
@ -209,7 +213,15 @@ public class CustomMOTD extends JavaPlugin {
|
||||||
// TODO add all events
|
// TODO add all events
|
||||||
PluginManager pm = getServer().getPluginManager();
|
PluginManager pm = getServer().getPluginManager();
|
||||||
pm.registerEvents(new PingListener(), this);
|
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() {
|
private void registerCommands() {
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -12,7 +12,7 @@ public class PingListener implements Listener {
|
||||||
public CustomMOTD instance = CustomMOTD.getInstance();
|
public CustomMOTD instance = CustomMOTD.getInstance();
|
||||||
|
|
||||||
@EventHandler
|
@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));
|
event.setMotd(CustomMOTD.motd.get(0) + "\n" + CustomMOTD.motd.get(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,3 @@
|
||||||
MOTD:
|
MOTD:
|
||||||
default
|
default
|
||||||
|
useproxyonline: false
|
||||||
|
|
@ -2,6 +2,7 @@ name: CustomMOTD
|
||||||
main: com.alttd.destro174.custommotd.CustomMOTD
|
main: com.alttd.destro174.custommotd.CustomMOTD
|
||||||
version: 1.0
|
version: 1.0
|
||||||
author: destro174
|
author: destro174
|
||||||
|
softdepend: [PlaceholderAPI]
|
||||||
commands:
|
commands:
|
||||||
custommotd:
|
custommotd:
|
||||||
aliases: [cmotd]
|
aliases: [cmotd]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user