Added functionality for client side player list.
This commit is contained in:
parent
369792cc1e
commit
6a9d5c9acb
|
@ -51,8 +51,7 @@
|
||||||
-init-macrodef-junit: defines macro for junit execution
|
-init-macrodef-junit: defines macro for junit execution
|
||||||
-init-macrodef-debug: defines macro for class debugging
|
-init-macrodef-debug: defines macro for class debugging
|
||||||
-init-macrodef-java: defines macro for class execution
|
-init-macrodef-java: defines macro for class execution
|
||||||
-do-jar-with-manifest: JAR building (if you are using a manifest)
|
-do-jar: JAR building
|
||||||
-do-jar-without-manifest: JAR building (if you are not using a manifest)
|
|
||||||
run: execution of project
|
run: execution of project
|
||||||
-javadoc-build: Javadoc generation
|
-javadoc-build: Javadoc generation
|
||||||
test-report: JUnit report generation
|
test-report: JUnit report generation
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
build.xml.data.CRC32=ad7c8973
|
build.xml.data.CRC32=ad7c8973
|
||||||
build.xml.script.CRC32=a50ca8cc
|
build.xml.script.CRC32=48b261b8
|
||||||
build.xml.stylesheet.CRC32=28e38971@1.56.1.46
|
build.xml.stylesheet.CRC32=8064a381@1.74.2.48
|
||||||
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
|
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
|
||||||
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
|
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
|
||||||
nbproject/build-impl.xml.data.CRC32=ad7c8973
|
nbproject/build-impl.xml.data.CRC32=ad7c8973
|
||||||
|
|
|
@ -52,7 +52,7 @@ javac.classpath=\
|
||||||
${libs.Log4J-core.classpath}:\
|
${libs.Log4J-core.classpath}:\
|
||||||
${libs.Log4J-api.classpath}
|
${libs.Log4J-api.classpath}
|
||||||
# Space-separated list of extra javac options
|
# Space-separated list of extra javac options
|
||||||
javac.compilerargs=-Xlint:unchecked
|
javac.compilerargs=-Xlint:unchecked -Xlint:deprecation
|
||||||
javac.deprecation=false
|
javac.deprecation=false
|
||||||
javac.processorpath=\
|
javac.processorpath=\
|
||||||
${javac.classpath}
|
${javac.classpath}
|
||||||
|
|
|
@ -31,6 +31,7 @@ public class BukkitTelnet extends JavaPlugin
|
||||||
|
|
||||||
TelnetLogger.info(plugin.getName() + " v" + plugin.getDescription().getVersion() + " enabled");
|
TelnetLogger.info(plugin.getName() + " v" + plugin.getDescription().getVersion() + " enabled");
|
||||||
|
|
||||||
|
this.getServer().getPluginManager().registerEvents(new PlayerEventListener(), plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -0,0 +1,76 @@
|
||||||
|
package me.StevenLawson.BukkitTelnet;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
import org.bukkit.event.player.PlayerKickEvent;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
import org.json.simple.JSONArray;
|
||||||
|
import org.json.simple.JSONObject;
|
||||||
|
|
||||||
|
public class PlayerEventListener implements Listener
|
||||||
|
{
|
||||||
|
public PlayerEventListener()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
|
public void onPlayerJoin(PlayerJoinEvent event)
|
||||||
|
{
|
||||||
|
triggerPlayerListUpdates();
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
|
public void onPlayerKick(PlayerKickEvent event)
|
||||||
|
{
|
||||||
|
triggerPlayerListUpdates();
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
|
public void onPlayerQuit(PlayerQuitEvent event)
|
||||||
|
{
|
||||||
|
triggerPlayerListUpdates();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void triggerPlayerListUpdates()
|
||||||
|
{
|
||||||
|
new BukkitRunnable()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
final SocketListener socketListener = TelnetServer.getInstance().getSocketListener();
|
||||||
|
if (socketListener != null)
|
||||||
|
{
|
||||||
|
socketListener.triggerPlayerListUpdates(generatePlayerList());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.runTaskLater(BukkitTelnet.plugin, 20L);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private static String generatePlayerList()
|
||||||
|
{
|
||||||
|
final JSONArray players = new JSONArray();
|
||||||
|
|
||||||
|
for (final Player player : Bukkit.getServer().getOnlinePlayers())
|
||||||
|
{
|
||||||
|
final HashMap<String, String> info = new HashMap<String, String>();
|
||||||
|
|
||||||
|
info.put("name", player.getName());
|
||||||
|
info.put("ip", player.getAddress().getAddress().getHostAddress());
|
||||||
|
|
||||||
|
players.add(info);
|
||||||
|
}
|
||||||
|
|
||||||
|
final JSONObject response = new JSONObject();
|
||||||
|
response.put("players", players);
|
||||||
|
|
||||||
|
return response.toJSONString();
|
||||||
|
}
|
||||||
|
}
|
|
@ -50,7 +50,7 @@ public class SocketListener extends Thread
|
||||||
while (it.hasNext())
|
while (it.hasNext())
|
||||||
{
|
{
|
||||||
final ClientSession session = it.next();
|
final ClientSession session = it.next();
|
||||||
|
|
||||||
if (!session.syncIsConnected())
|
if (!session.syncIsConnected())
|
||||||
{
|
{
|
||||||
TelnetLogAppender.getInstance().removeSession(session);
|
TelnetLogAppender.getInstance().removeSession(session);
|
||||||
|
@ -59,6 +59,20 @@ public class SocketListener extends Thread
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void triggerPlayerListUpdates(final String playerListData)
|
||||||
|
{
|
||||||
|
final Iterator<ClientSession> it = clientSessions.iterator();
|
||||||
|
|
||||||
|
while (it.hasNext())
|
||||||
|
{
|
||||||
|
final ClientSession session = it.next();
|
||||||
|
if (session != null)
|
||||||
|
{
|
||||||
|
session.syncTriggerPlayerListUpdate(playerListData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void stopServer()
|
public void stopServer()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|
|
@ -81,6 +81,11 @@ public class TelnetServer
|
||||||
socketListener.stopServer();
|
socketListener.stopServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SocketListener getSocketListener()
|
||||||
|
{
|
||||||
|
return socketListener;
|
||||||
|
}
|
||||||
|
|
||||||
public static TelnetServer getInstance()
|
public static TelnetServer getInstance()
|
||||||
{
|
{
|
||||||
return TelnetServerHolder.INSTANCE;
|
return TelnetServerHolder.INSTANCE;
|
||||||
|
|
|
@ -37,6 +37,7 @@ public final class ClientSession extends Thread
|
||||||
private BufferedReader reader;
|
private BufferedReader reader;
|
||||||
private String username;
|
private String username;
|
||||||
private boolean hasTerminated;
|
private boolean hasTerminated;
|
||||||
|
private boolean enhancedMode = false;
|
||||||
|
|
||||||
public ClientSession(Socket clientSocket)
|
public ClientSession(Socket clientSocket)
|
||||||
{
|
{
|
||||||
|
@ -410,58 +411,77 @@ public final class ClientSession extends Thread
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void executeTelnetCommand(String command)
|
private void executeTelnetCommand(final String command)
|
||||||
{
|
{
|
||||||
if (command.equalsIgnoreCase("telnet.help"))
|
if ("telnet.help".equalsIgnoreCase(command))
|
||||||
{
|
{
|
||||||
println("--- Telnet commands ---");
|
println("--- Telnet commands ---");
|
||||||
println("telnet.help - See all of the telnet commands.");
|
println("telnet.help - See all of the telnet commands.");
|
||||||
println("telnet.stop - Shut the server down.");
|
println("telnet.stop - Shut the server down.");
|
||||||
println("telnet.log - Change your logging settings.");
|
println("telnet.log - Change your logging settings.");
|
||||||
println("telnet.exit - Quit the telnet session.");
|
println("telnet.exit - Quit the telnet session.");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
else if ("telnet.stop".equalsIgnoreCase(command))
|
||||||
if (command.equalsIgnoreCase("telnet.stop"))
|
|
||||||
{
|
{
|
||||||
println("Shutting down the server...");
|
println("Shutting down the server...");
|
||||||
TelnetLogger.warning(username + ": Shutting down the server...");
|
TelnetLogger.warning(username + ": Shutting down the server...");
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
else if ("telnet.log".equalsIgnoreCase(command))
|
||||||
if (command.equalsIgnoreCase("telnet.log"))
|
|
||||||
{
|
{
|
||||||
if (filterMode == FilterMode.FULL)
|
switch (filterMode)
|
||||||
{
|
{
|
||||||
filterMode = FilterMode.CHAT_ONLY;
|
case FULL:
|
||||||
println("Showing only chat logs.");
|
{
|
||||||
return;
|
filterMode = FilterMode.CHAT_ONLY;
|
||||||
|
println("Showing only chat logs.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case CHAT_ONLY:
|
||||||
|
{
|
||||||
|
filterMode = FilterMode.NONCHAT_ONLY;
|
||||||
|
println("Showing only non-chat logs.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case NONCHAT_ONLY:
|
||||||
|
{
|
||||||
|
filterMode = FilterMode.FULL;
|
||||||
|
println("Showing all logs.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filterMode == FilterMode.CHAT_ONLY)
|
|
||||||
{
|
|
||||||
filterMode = FilterMode.NONCHAT_ONLY;
|
|
||||||
println("Showing only non-chat logs.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (filterMode == FilterMode.NONCHAT_ONLY)
|
|
||||||
{
|
|
||||||
filterMode = FilterMode.FULL;
|
|
||||||
println("Showing all logs.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
else if ("telnet.exit".equalsIgnoreCase(command))
|
||||||
if (command.equalsIgnoreCase("telnet.exit"))
|
|
||||||
{
|
{
|
||||||
println("Goodbye <3");
|
println("Goodbye.");
|
||||||
syncTerminateSession();
|
syncTerminateSession();
|
||||||
}
|
}
|
||||||
|
else if ("telnet.enhanced".equalsIgnoreCase(command))
|
||||||
|
{
|
||||||
|
enhancedMode = !enhancedMode;
|
||||||
|
println((enhancedMode ? "A" : "Dea") + "ctivated enhanced mode.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
println("Invalid telnet command, use \"telnet.help\" to view help.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void syncTriggerPlayerListUpdate(String playerListData)
|
||||||
|
{
|
||||||
|
if (!enhancedMode)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
println("Invalid telnet command, use \"telnet.help\" to view help.");
|
synchronized (clientSocket)
|
||||||
|
{
|
||||||
|
if (clientSocket.isClosed())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
println("playerList~" + playerListData);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue