mirror of
https://github.com/TotalFreedomMC/BukkitTelnet.git
synced 2025-08-06 12:33:24 +00:00
Call new TelnetCommandEvent when a telnet user tries to run a command
Some cleanup
This commit is contained in:
parent
30b42f485d
commit
7707093231
6 changed files with 84 additions and 21 deletions
|
@ -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
|
try
|
||||||
{
|
{
|
||||||
|
@ -133,15 +133,23 @@ public final class BT_ClientSession extends Thread
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
final Server server = Bukkit.getServer();
|
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);
|
return;
|
||||||
server.getPluginManager().callEvent(event);
|
}
|
||||||
String command = event.getCommand();
|
|
||||||
|
// Deprecated
|
||||||
|
final RemoteServerCommandEvent serverEvent = new RemoteServerCommandEvent(telnetEvent.getSender(), telnetEvent.getCommand());
|
||||||
|
server.getPluginManager().callEvent(serverEvent);
|
||||||
|
|
||||||
|
final String command = serverEvent.getCommand();
|
||||||
if (command != null && !command.isEmpty())
|
if (command != null && !command.isEmpty())
|
||||||
{
|
{
|
||||||
server.dispatchCommand(commandSender, command);
|
server.dispatchCommand(sender, command);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.runTask(BukkitTelnet.getPlugin());
|
}.runTask(BukkitTelnet.getPlugin());
|
||||||
|
|
|
@ -8,7 +8,6 @@ import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
public class BT_TelnetServer
|
public class BT_TelnetServer
|
||||||
{
|
{
|
||||||
|
@ -56,11 +55,11 @@ public class BT_TelnetServer
|
||||||
{
|
{
|
||||||
if (hostAddress == null)
|
if (hostAddress == null)
|
||||||
{
|
{
|
||||||
serverSocket = new java.net.ServerSocket(port);
|
serverSocket = new ServerSocket(port);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
serverSocket = new java.net.ServerSocket(port, 50, hostAddress);
|
serverSocket = new ServerSocket(port, 50, hostAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
String hostIP = serverSocket.getInetAddress().getHostAddress();
|
String hostIP = serverSocket.getInetAddress().getHostAddress();
|
||||||
|
@ -73,7 +72,8 @@ public class BT_TelnetServer
|
||||||
}
|
}
|
||||||
catch (IOException ex)
|
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)
|
if (serverSocket != null)
|
||||||
|
|
|
@ -15,19 +15,20 @@ public class BukkitTelnet extends JavaPlugin
|
||||||
@Override
|
@Override
|
||||||
public void onEnable()
|
public void onEnable()
|
||||||
{
|
{
|
||||||
BT_Log.info("Plugin enabled.");
|
|
||||||
|
|
||||||
BT_Config.getInstance().load();
|
BT_Config.getInstance().load();
|
||||||
|
|
||||||
BT_TelnetServer.getInstance().startServer();
|
BT_TelnetServer.getInstance().startServer();
|
||||||
|
|
||||||
|
BT_Log.info(plugin.getName() + " v" + plugin.getDescription().getVersion() + " enabled");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable()
|
public void onDisable()
|
||||||
{
|
{
|
||||||
BT_Log.info("Plugin disabled.");
|
|
||||||
|
|
||||||
BT_TelnetServer.getInstance().stopServer();
|
BT_TelnetServer.getInstance().stopServer();
|
||||||
|
|
||||||
|
BT_Log.info("Plugin disabled");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BukkitTelnet getPlugin() throws PluginNotLoadedException
|
public static BukkitTelnet getPlugin() throws PluginNotLoadedException
|
||||||
|
|
54
src/me/StevenLawson/BukkitTelnet/TelnetCommandEvent.java
Normal file
54
src/me/StevenLawson/BukkitTelnet/TelnetCommandEvent.java
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,11 +7,11 @@ import org.bukkit.event.HandlerList;
|
||||||
public class TelnetPreLoginEvent extends Event implements Cancellable
|
public class TelnetPreLoginEvent extends Event implements Cancellable
|
||||||
{
|
{
|
||||||
private static final HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
private boolean cancelled = false;
|
||||||
//
|
//
|
||||||
private final String ip;
|
|
||||||
private String name = null;
|
private String name = null;
|
||||||
|
private final String ip;
|
||||||
private boolean bypassPassword;
|
private boolean bypassPassword;
|
||||||
private boolean cancelled;
|
|
||||||
|
|
||||||
public TelnetPreLoginEvent(String ip, String name, boolean bypassPassword)
|
public TelnetPreLoginEvent(String ip, String name, boolean bypassPassword)
|
||||||
{
|
{
|
||||||
|
|
|
@ -2,4 +2,4 @@ name: BukkitTelnet
|
||||||
main: me.StevenLawson.BukkitTelnet.BukkitTelnet
|
main: me.StevenLawson.BukkitTelnet.BukkitTelnet
|
||||||
version: 3.0
|
version: 3.0
|
||||||
description: Telnet console access plugin.
|
description: Telnet console access plugin.
|
||||||
author: bekvon, Madgeek1450 / StevenLawson
|
authors: [bekvon, Madgeek1450]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue