diff options
author | Andrew Ardill <andrew.ardill@gmail.com> | 2011-12-07 17:01:05 +1100 |
---|---|---|
committer | Andrew Ardill <andrew.ardill@gmail.com> | 2011-12-07 17:45:50 +1100 |
commit | 93a4a9ba8ce37179bd903283c73c453c8abcc208 (patch) | |
tree | eca53bf707df8fd791c5eda336627ba0209f5e50 | |
parent | e4a839cbbc057fce7ed614b01abdb5d59382f0f8 (diff) | |
download | craftbukkit-93a4a9ba8ce37179bd903283c73c453c8abcc208.tar craftbukkit-93a4a9ba8ce37179bd903283c73c453c8abcc208.tar.gz craftbukkit-93a4a9ba8ce37179bd903283c73c453c8abcc208.tar.lz craftbukkit-93a4a9ba8ce37179bd903283c73c453c8abcc208.tar.xz craftbukkit-93a4a9ba8ce37179bd903283c73c453c8abcc208.zip |
Teach MinecraftServer how to handle Remote Console commands.
This fixes BUKKIT-220. Thanks for the help bawoodruff!
3 files changed, 110 insertions, 2 deletions
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java index cea2ffb2..91ea00d4 100644 --- a/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/src/main/java/net/minecraft/server/MinecraftServer.java @@ -20,10 +20,13 @@ import jline.ConsoleReader; import joptsimple.OptionSet; import org.bukkit.World.Environment; import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.command.RemoteConsoleCommandSender; +import org.bukkit.craftbukkit.command.CraftRemoteConsoleCommandSender; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.LoggerOutputStream; import org.bukkit.craftbukkit.scheduler.CraftScheduler; import org.bukkit.craftbukkit.util.ServerShutdownThread; +import org.bukkit.event.Event; import org.bukkit.event.server.ServerCommandEvent; import org.bukkit.event.world.WorldInitEvent; import org.bukkit.event.world.WorldLoadEvent; @@ -67,6 +70,7 @@ public class MinecraftServer implements Runnable, ICommandListener, IMinecraftSe public CraftServer server; public OptionSet options; public ConsoleCommandSender console; + public RemoteConsoleCommandSender remoteConsole; public ConsoleReader reader; public static int currentTick; // CraftBukkit end @@ -176,6 +180,7 @@ public class MinecraftServer implements Runnable, ICommandListener, IMinecraftSe log.info("Starting remote control listener"); this.z = new RemoteControlListener(this); this.z.a(); + this.remoteConsole = new CraftRemoteConsoleCommandSender(); } // CraftBukkit start @@ -544,7 +549,7 @@ public class MinecraftServer implements Runnable, ICommandListener, IMinecraftSe ServerCommand servercommand = (ServerCommand) this.x.remove(0); // CraftBukkit start - ServerCommand for preprocessing - ServerCommandEvent event = new ServerCommandEvent(this.console, servercommand.command); + ServerCommandEvent event = new ServerCommandEvent(Event.Type.SERVER_COMMAND, this.console, servercommand.command); this.server.getPluginManager().callEvent(event); servercommand = new ServerCommand(event.getCommand(), servercommand.b); // CraftBukkit end @@ -689,7 +694,13 @@ public class MinecraftServer implements Runnable, ICommandListener, IMinecraftSe public String d(String s) { RemoteControlCommandListener.a.a(); - this.consoleCommandHandler.handle(new ServerCommand(s, RemoteControlCommandListener.a)); + // CraftBukkt start + ServerCommandEvent event = new ServerCommandEvent(Event.Type.REMOTE_COMMAND, this.remoteConsole, s); + this.server.getPluginManager().callEvent(event); + ServerCommand servercommand = new ServerCommand(event.getCommand(), RemoteControlCommandListener.a); + // this.consoleCommandHandler.handle(new ServerCommand(s, RemoteControlCommandListener.a)); // CraftBukkit - removed + this.server.dispatchCommand(this.remoteConsole, servercommand); // CraftBukkit + // CraftBukkit end return RemoteControlCommandListener.a.b(); } diff --git a/src/main/java/org/bukkit/craftbukkit/command/CraftRemoteConsoleCommandSender.java b/src/main/java/org/bukkit/craftbukkit/command/CraftRemoteConsoleCommandSender.java new file mode 100644 index 00000000..68acced1 --- /dev/null +++ b/src/main/java/org/bukkit/craftbukkit/command/CraftRemoteConsoleCommandSender.java @@ -0,0 +1,26 @@ +package org.bukkit.craftbukkit.command; + +import net.minecraft.server.RemoteControlCommandListener; +import org.bukkit.command.RemoteConsoleCommandSender; + +public class CraftRemoteConsoleCommandSender extends ServerCommandSender implements RemoteConsoleCommandSender { + public CraftRemoteConsoleCommandSender() { + super(); + } + + public void sendMessage(String message) { + RemoteControlCommandListener.a.sendMessage(message); + } + + public String getName() { + return "Rcon"; + } + + public boolean isOp() { + return true; + } + + public void setOp(boolean value) { + throw new UnsupportedOperationException("Cannot change operator status of remote controller."); + } +} diff --git a/src/main/java/org/bukkit/craftbukkit/command/ServerCommandSender.java b/src/main/java/org/bukkit/craftbukkit/command/ServerCommandSender.java new file mode 100644 index 00000000..1314c744 --- /dev/null +++ b/src/main/java/org/bukkit/craftbukkit/command/ServerCommandSender.java @@ -0,0 +1,71 @@ +package org.bukkit.craftbukkit.command; + +import org.bukkit.Bukkit; +import org.bukkit.Server; +import org.bukkit.command.CommandSender; +import org.bukkit.permissions.PermissibleBase; +import org.bukkit.permissions.Permission; +import org.bukkit.permissions.PermissionAttachment; +import org.bukkit.permissions.PermissionAttachmentInfo; +import org.bukkit.plugin.Plugin; + +import java.util.Set; + +public abstract class ServerCommandSender implements CommandSender { + private final PermissibleBase perm = new PermissibleBase(this); + + public ServerCommandSender() { + } + + public boolean isPermissionSet(String name) { + return perm.isPermissionSet(name); + } + + public boolean isPermissionSet(Permission perm) { + return this.perm.isPermissionSet(perm); + } + + public boolean hasPermission(String name) { + return perm.hasPermission(name); + } + + public boolean hasPermission(Permission perm) { + return this.perm.hasPermission(perm); + } + + public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value) { + return perm.addAttachment(plugin, name, value); + } + + public PermissionAttachment addAttachment(Plugin plugin) { + return perm.addAttachment(plugin); + } + + public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value, int ticks) { + return perm.addAttachment(plugin, name, value, ticks); + } + + public PermissionAttachment addAttachment(Plugin plugin, int ticks) { + return perm.addAttachment(plugin, ticks); + } + + public void removeAttachment(PermissionAttachment attachment) { + perm.removeAttachment(attachment); + } + + public void recalculatePermissions() { + perm.recalculatePermissions(); + } + + public Set<PermissionAttachmentInfo> getEffectivePermissions() { + return perm.getEffectivePermissions(); + } + + public boolean isPlayer() { + return false; + } + + public Server getServer() { + return Bukkit.getServer(); + } +} |