diff --git a/src/me/StevenLawson/BukkitTelnet/BT_ClientSession.java b/src/me/StevenLawson/BukkitTelnet/BT_ClientSession.java index 7c07133..b203f20 100644 --- a/src/me/StevenLawson/BukkitTelnet/BT_ClientSession.java +++ b/src/me/StevenLawson/BukkitTelnet/BT_ClientSession.java @@ -121,9 +121,9 @@ public final class BT_ClientSession extends Thread } } - public void sendBukkitCommand(final String _command) + public void sendBukkitCommand(final String command) { - final CommandSender commandSender = getCommandSender(); + final CommandSender sender = getCommandSender(); try { @@ -133,15 +133,23 @@ public final class BT_ClientSession extends Thread public void run() { final Server server = Bukkit.getServer(); - if (server != null) + + final TelnetCommandEvent telnetEvent = new TelnetCommandEvent(sender, command); + server.getPluginManager().callEvent(telnetEvent); + + if (telnetEvent.isCancelled()) { - final RemoteServerCommandEvent event = new RemoteServerCommandEvent(commandSender, _command); - server.getPluginManager().callEvent(event); - String command = event.getCommand(); - if (command != null && !command.isEmpty()) - { - server.dispatchCommand(commandSender, command); - } + return; + } + + // Deprecated + final RemoteServerCommandEvent serverEvent = new RemoteServerCommandEvent(telnetEvent.getSender(), telnetEvent.getCommand()); + server.getPluginManager().callEvent(serverEvent); + + final String command = serverEvent.getCommand(); + if (command != null && !command.isEmpty()) + { + server.dispatchCommand(sender, command); } } }.runTask(BukkitTelnet.getPlugin()); diff --git a/src/me/StevenLawson/BukkitTelnet/BT_TelnetServer.java b/src/me/StevenLawson/BukkitTelnet/BT_TelnetServer.java index 294aa55..1302a9a 100644 --- a/src/me/StevenLawson/BukkitTelnet/BT_TelnetServer.java +++ b/src/me/StevenLawson/BukkitTelnet/BT_TelnetServer.java @@ -8,7 +8,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; -import java.util.logging.Level; public class BT_TelnetServer { @@ -56,11 +55,11 @@ public class BT_TelnetServer { if (hostAddress == null) { - serverSocket = new java.net.ServerSocket(port); + serverSocket = new ServerSocket(port); } else { - serverSocket = new java.net.ServerSocket(port, 50, hostAddress); + serverSocket = new ServerSocket(port, 50, hostAddress); } String hostIP = serverSocket.getInetAddress().getHostAddress(); @@ -73,7 +72,8 @@ public class BT_TelnetServer } catch (IOException ex) { - BT_Log.getLogger().log(Level.SEVERE, "Cant bind to " + (hostAddress == null ? "*" : hostAddress) + ":" + port, ex); + BT_Log.severe("Cant bind to " + (hostAddress == null ? "*" : hostAddress) + ":" + port); + BT_Log.severe(ex); } if (serverSocket != null) diff --git a/src/me/StevenLawson/BukkitTelnet/BukkitTelnet.java b/src/me/StevenLawson/BukkitTelnet/BukkitTelnet.java index 9a18ba3..0d842a3 100644 --- a/src/me/StevenLawson/BukkitTelnet/BukkitTelnet.java +++ b/src/me/StevenLawson/BukkitTelnet/BukkitTelnet.java @@ -15,19 +15,20 @@ public class BukkitTelnet extends JavaPlugin @Override public void onEnable() { - BT_Log.info("Plugin enabled."); - BT_Config.getInstance().load(); BT_TelnetServer.getInstance().startServer(); + + BT_Log.info(plugin.getName() + " v" + plugin.getDescription().getVersion() + " enabled"); + } @Override public void onDisable() { - BT_Log.info("Plugin disabled."); - BT_TelnetServer.getInstance().stopServer(); + + BT_Log.info("Plugin disabled"); } public static BukkitTelnet getPlugin() throws PluginNotLoadedException diff --git a/src/me/StevenLawson/BukkitTelnet/TelnetCommandEvent.java b/src/me/StevenLawson/BukkitTelnet/TelnetCommandEvent.java new file mode 100644 index 0000000..695b2cc --- /dev/null +++ b/src/me/StevenLawson/BukkitTelnet/TelnetCommandEvent.java @@ -0,0 +1,54 @@ +package me.StevenLawson.BukkitTelnet; + +import org.bukkit.command.CommandSender; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +public class TelnetCommandEvent extends Event implements Cancellable +{ + private static final HandlerList handlers = new HandlerList(); + private boolean cancelled = false; + // + private CommandSender sender; + private String command; + + public TelnetCommandEvent(CommandSender sender, String command) { + this.sender = sender; + this.command = command; + } + + @Override + public HandlerList getHandlers() + { + return handlers; + } + + @Override + public boolean isCancelled() + { + return cancelled; + } + + @Override + public void setCancelled(boolean cancel) + { + cancelled = cancel; + } + + public CommandSender getSender() { + return sender; + } + + public void setSender(CommandSender sender) { + this.sender = sender; + } + + public String getCommand() { + return command; + } + + public void setCommand(String command) { + this.command = command; + } +} diff --git a/src/me/StevenLawson/BukkitTelnet/TelnetPreLoginEvent.java b/src/me/StevenLawson/BukkitTelnet/TelnetPreLoginEvent.java index ab342fb..a440791 100644 --- a/src/me/StevenLawson/BukkitTelnet/TelnetPreLoginEvent.java +++ b/src/me/StevenLawson/BukkitTelnet/TelnetPreLoginEvent.java @@ -7,11 +7,11 @@ import org.bukkit.event.HandlerList; public class TelnetPreLoginEvent extends Event implements Cancellable { private static final HandlerList handlers = new HandlerList(); + private boolean cancelled = false; // - private final String ip; private String name = null; + private final String ip; private boolean bypassPassword; - private boolean cancelled; public TelnetPreLoginEvent(String ip, String name, boolean bypassPassword) { diff --git a/src/plugin.yml b/src/plugin.yml index 6c54610..25a792a 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -2,4 +2,4 @@ name: BukkitTelnet main: me.StevenLawson.BukkitTelnet.BukkitTelnet version: 3.0 description: Telnet console access plugin. -author: bekvon, Madgeek1450 / StevenLawson +authors: [bekvon, Madgeek1450]