Call new TelnetCommandEvent when a telnet user tries to run a command

Some cleanup
This commit is contained in:
unknown 2013-12-17 16:00:53 +01:00
parent 30b42f485d
commit 7707093231
6 changed files with 84 additions and 21 deletions

View file

@ -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());

View file

@ -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)

View file

@ -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

View file

@ -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;
}
}

View file

@ -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)
{

View file

@ -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]