mirror of
https://github.com/TotalFreedomMC/BukkitTelnet.git
synced 2024-12-27 18:44:20 +00:00
ZTC stuff
This commit is contained in:
parent
66124908d9
commit
541e9fdb84
5 changed files with 143 additions and 8 deletions
14
pom.xml
14
pom.xml
|
@ -39,10 +39,9 @@
|
|||
<id>spigot</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
|
||||
</repository>
|
||||
|
||||
<repository>
|
||||
<id>maven-central</id>
|
||||
<url>https://repo1.maven.org/maven2/</url>
|
||||
<id>ess-repo</id>
|
||||
<url>https://ci.ender.zone/plugin/repository/everything/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
|
@ -50,7 +49,7 @@
|
|||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.15.2-R0.1-SNAPSHOT</version>
|
||||
<version>1.15-R0.1-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
|
@ -69,9 +68,10 @@
|
|||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.googlecode.json-simple</groupId>
|
||||
<artifactId>json-simple</artifactId>
|
||||
<version>1.1.1</version>
|
||||
<groupId>net.ess3</groupId>
|
||||
<artifactId>EssentialsX</artifactId>
|
||||
<version>2.16.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
package me.totalfreedom.bukkittelnet;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import me.totalfreedom.bukkittelnet.api.TelnetRequestDataTagsEvent;
|
||||
import me.totalfreedom.bukkittelnet.api.TelnetRequestUsageEvent;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -12,14 +15,18 @@ import org.bukkit.event.EventPriority;
|
|||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import com.earth2me.essentials.Essentials;
|
||||
|
||||
public class PlayerEventListener implements Listener
|
||||
{
|
||||
|
||||
private static Essentials essentials = null;
|
||||
|
||||
private final BukkitTelnet plugin;
|
||||
|
||||
public PlayerEventListener(BukkitTelnet plugin)
|
||||
|
@ -39,6 +46,18 @@ public class PlayerEventListener implements Listener
|
|||
triggerPlayerListUpdates();
|
||||
}
|
||||
|
||||
public static Essentials getEssentials()
|
||||
{
|
||||
Plugin ess = Bukkit.getPluginManager().getPlugin("Essentials");
|
||||
if (ess instanceof Essentials)
|
||||
{
|
||||
essentials = (Essentials)ess;
|
||||
return essentials;
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
private static BukkitTask updateTask = null;
|
||||
|
||||
public void triggerPlayerListUpdates()
|
||||
|
@ -99,4 +118,58 @@ public class PlayerEventListener implements Listener
|
|||
|
||||
return response.toJSONString();
|
||||
}
|
||||
|
||||
private static BukkitTask usageUpdateTask = null;
|
||||
|
||||
// Just putting this stuff here
|
||||
public void triggerUsageUpdates()
|
||||
{
|
||||
if (usageUpdateTask != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
usageUpdateTask= new BukkitRunnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
final SocketListener socketListener = plugin.telnet.getSocketListener();
|
||||
if (socketListener != null)
|
||||
{
|
||||
final TelnetRequestUsageEvent event = new TelnetRequestUsageEvent();
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
socketListener.triggerDataUsageUpdates(generateUsageStats());
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(plugin, 100L, 100L); // every 5 seconds
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static String generateUsageStats()
|
||||
{
|
||||
if (essentials == null)
|
||||
{
|
||||
essentials = getEssentials();
|
||||
}
|
||||
|
||||
final HashMap<String, String> info = new HashMap<>();
|
||||
|
||||
String cpuUsage = null;
|
||||
String ramUsage = null;
|
||||
String tps = null;
|
||||
|
||||
if (essentials != null)
|
||||
{
|
||||
tps = String.valueOf(String.valueOf(new BigDecimal(essentials.getTimer().getAverageTPS()).setScale(1, RoundingMode.CEILING)));
|
||||
}
|
||||
|
||||
info.put("tps", tps);
|
||||
|
||||
final JSONObject data = new JSONObject();
|
||||
data.putAll(info);
|
||||
|
||||
return data.toJSONString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -131,6 +131,20 @@ public class SocketListener extends Thread
|
|||
}
|
||||
}
|
||||
|
||||
public void triggerDataUsageUpdates(final String usageData)
|
||||
{
|
||||
final Iterator<ClientSession> it = clientSessions.iterator();
|
||||
|
||||
while (it.hasNext())
|
||||
{
|
||||
final ClientSession session = it.next();
|
||||
if (session != null)
|
||||
{
|
||||
session.syncUsageUpdate(usageData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void stopServer()
|
||||
{
|
||||
try
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
package me.totalfreedom.bukkittelnet.api;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
public class TelnetRequestUsageEvent extends Event
|
||||
{
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
public TelnetRequestUsageEvent()
|
||||
{
|
||||
super(!Bukkit.getServer().isPrimaryThread());
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers()
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
}
|
|
@ -39,7 +39,8 @@ public final class ClientSession extends Thread
|
|||
private String username = "";
|
||||
private volatile boolean terminated = false;
|
||||
private volatile boolean authenticated = false;
|
||||
private volatile boolean enhancedMode = false;
|
||||
private boolean enhancedMode = false;
|
||||
private boolean enhancedPlusMode = false;
|
||||
|
||||
public ClientSession(TelnetServer telnet, Socket clientSocket)
|
||||
{
|
||||
|
@ -84,6 +85,8 @@ public final class ClientSession extends Thread
|
|||
mainLoop();
|
||||
|
||||
syncTerminateSession();
|
||||
|
||||
telnet.getPlugin().listener.triggerUsageUpdates();
|
||||
}
|
||||
|
||||
public boolean syncIsAuthenticated()
|
||||
|
@ -472,6 +475,11 @@ public final class ClientSession extends Thread
|
|||
telnet.getPlugin().listener.triggerPlayerListUpdates();
|
||||
}
|
||||
}
|
||||
else if ("telnet.enhancedplus".equalsIgnoreCase(command))
|
||||
{
|
||||
enhancedPlusMode = !enhancedPlusMode;
|
||||
writeLine((enhancedPlusMode ? "A" : "Dea") + "ctivated enhanced+ mode.");
|
||||
}
|
||||
else
|
||||
{
|
||||
writeLine("Invalid telnet command, use \"telnet.help\" to view help.");
|
||||
|
@ -495,4 +503,22 @@ public final class ClientSession extends Thread
|
|||
writeLine("playerList~" + playerListData);
|
||||
}
|
||||
}
|
||||
|
||||
public void syncUsageUpdate(String usageData)
|
||||
{
|
||||
if (!enhancedPlusMode)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
synchronized (clientSocket)
|
||||
{
|
||||
if (clientSocket.isClosed())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
writeLine("usage~" + usageData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue