Initial commit (Forge 1291).
This commit is contained in:
74
patches/net/minecraft/command/CommandHandler.java.patch
Normal file
74
patches/net/minecraft/command/CommandHandler.java.patch
Normal file
@ -0,0 +1,74 @@
|
||||
--- ../src-base/minecraft/net/minecraft/command/CommandHandler.java
|
||||
+++ ../src-work/minecraft/net/minecraft/command/CommandHandler.java
|
||||
@@ -16,6 +16,11 @@
|
||||
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.CommandEvent;
|
||||
+// Cauldron start
|
||||
+import org.bukkit.craftbukkit.command.CraftSimpleCommandMap;
|
||||
+import org.bukkit.craftbukkit.command.ModCustomCommand;
|
||||
+import cpw.mods.fml.common.FMLCommonHandler;
|
||||
+// Cauldron end
|
||||
|
||||
public class CommandHandler implements ICommandManager
|
||||
{
|
||||
@@ -48,7 +53,7 @@
|
||||
throw new CommandNotFoundException();
|
||||
}
|
||||
|
||||
- if (icommand.canCommandSenderUseCommand(p_71556_1_))
|
||||
+ if (true || icommand.canCommandSenderUseCommand(p_71556_1_)) // Cauldron start - disable check for permissions since we handle it on Bukkit side
|
||||
{
|
||||
CommandEvent event = new CommandEvent(icommand, p_71556_1_, astring);
|
||||
if (MinecraftForge.EVENT_BUS.post(event))
|
||||
@@ -134,11 +139,30 @@
|
||||
|
||||
public ICommand registerCommand(ICommand p_71560_1_)
|
||||
{
|
||||
- List list = p_71560_1_.getCommandAliases();
|
||||
- this.commandMap.put(p_71560_1_.getCommandName(), p_71560_1_);
|
||||
- this.commandSet.add(p_71560_1_);
|
||||
+ // Cauldron start - register commands with permission nodes, defaulting to class name
|
||||
+ return registerCommand(p_71560_1_, p_71560_1_.getClass().getName());
|
||||
+ }
|
||||
|
||||
+ public ICommand registerCommand(String permissionGroup, ICommand par1ICommand)
|
||||
+ {
|
||||
+ return registerCommand(par1ICommand, permissionGroup + "." + par1ICommand.getCommandName());
|
||||
+ }
|
||||
+
|
||||
+ public ICommand registerCommand(ICommand par1ICommand, String permissionNode)
|
||||
+ {
|
||||
+ List list = par1ICommand.getCommandAliases();
|
||||
+ this.commandMap.put(par1ICommand.getCommandName(), par1ICommand);
|
||||
+ this.commandSet.add(par1ICommand);
|
||||
+ // register vanilla commands with Bukkit to support permissions.
|
||||
+ CraftSimpleCommandMap commandMap = FMLCommonHandler.instance().getMinecraftServerInstance().server.getCraftCommandMap();
|
||||
+ ModCustomCommand customCommand = new ModCustomCommand(par1ICommand.getCommandName());
|
||||
+ customCommand.setPermission(permissionNode);
|
||||
if (list != null)
|
||||
+ customCommand.setAliases(list);
|
||||
+ commandMap.register(par1ICommand.getCommandName(), customCommand);
|
||||
+ LogManager.getLogger().info("Registered command " + par1ICommand.getCommandName() + " with permission node " + permissionNode);
|
||||
+
|
||||
+ if (list != null)
|
||||
{
|
||||
Iterator iterator = list.iterator();
|
||||
|
||||
@@ -149,13 +173,14 @@
|
||||
|
||||
if (icommand1 == null || !icommand1.getCommandName().equals(s))
|
||||
{
|
||||
- this.commandMap.put(s, p_71560_1_);
|
||||
+ this.commandMap.put(s, par1ICommand);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- return p_71560_1_;
|
||||
+ return par1ICommand;
|
||||
}
|
||||
+ // Cauldron end
|
||||
|
||||
private static String[] dropFirstString(String[] p_71559_0_)
|
||||
{
|
24
patches/net/minecraft/command/PlayerSelector.java.patch
Normal file
24
patches/net/minecraft/command/PlayerSelector.java.patch
Normal file
@ -0,0 +1,24 @@
|
||||
--- ../src-base/minecraft/net/minecraft/command/PlayerSelector.java
|
||||
+++ ../src-work/minecraft/net/minecraft/command/PlayerSelector.java
|
||||
@@ -7,6 +7,7 @@
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
+import net.minecraft.command.server.CommandBlockLogic;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.ChunkCoordinates;
|
||||
@@ -51,6 +52,13 @@
|
||||
|
||||
public static EntityPlayerMP[] matchPlayers(ICommandSender p_82380_0_, String p_82380_1_)
|
||||
{
|
||||
+ // CraftBukkit start
|
||||
+ if (!(p_82380_0_ instanceof CommandBlockLogic))
|
||||
+ {
|
||||
+ return null;
|
||||
+ }
|
||||
+
|
||||
+ // CraftBukkit end
|
||||
Matcher matcher = tokenPattern.matcher(p_82380_1_);
|
||||
|
||||
if (matcher.matches())
|
@ -0,0 +1,76 @@
|
||||
--- ../src-base/minecraft/net/minecraft/command/ServerCommandManager.java
|
||||
+++ ../src-work/minecraft/net/minecraft/command/ServerCommandManager.java
|
||||
@@ -39,8 +39,16 @@
|
||||
{
|
||||
private static final String __OBFID = "CL_00000922";
|
||||
|
||||
+ // Cauldron start - moved commands to it's own method to be executed further in server startup + changed to registerVanillaCommand
|
||||
public ServerCommandManager()
|
||||
{
|
||||
+ CommandBase.setAdminCommander(this);
|
||||
+ }
|
||||
+
|
||||
+ public void registerVanillaCommands()
|
||||
+ {
|
||||
+ // Cauldron - do not register vanilla commands replaced by Bukkit
|
||||
+ /*
|
||||
this.registerCommand(new CommandTime());
|
||||
this.registerCommand(new CommandGameMode());
|
||||
this.registerCommand(new CommandDifficulty());
|
||||
@@ -56,7 +64,6 @@
|
||||
this.registerCommand(new CommandEmote());
|
||||
this.registerCommand(new CommandShowSeed());
|
||||
this.registerCommand(new CommandHelp());
|
||||
- this.registerCommand(new CommandDebug());
|
||||
this.registerCommand(new CommandMessage());
|
||||
this.registerCommand(new CommandBroadcast());
|
||||
this.registerCommand(new CommandSetSpawnpoint());
|
||||
@@ -64,17 +71,23 @@
|
||||
this.registerCommand(new CommandGameRule());
|
||||
this.registerCommand(new CommandClearInventory());
|
||||
this.registerCommand(new CommandTestFor());
|
||||
- this.registerCommand(new CommandSpreadPlayers());
|
||||
- this.registerCommand(new CommandPlaySound());
|
||||
- this.registerCommand(new CommandScoreboard());
|
||||
- this.registerCommand(new CommandAchievement());
|
||||
- this.registerCommand(new CommandSummon());
|
||||
- this.registerCommand(new CommandSetBlock());
|
||||
- this.registerCommand(new CommandTestForBlock());
|
||||
- this.registerCommand(new CommandMessageRaw());
|
||||
+ */
|
||||
+ // Cauldron start - add permission nodes for rest of vanilla commands
|
||||
+ this.registerCommand("vanilla.command", new CommandDebug());
|
||||
+ this.registerCommand("vanilla.command", new CommandSpreadPlayers());
|
||||
+ this.registerCommand("vanilla.command", new CommandPlaySound());
|
||||
+ this.registerCommand("vanilla.command", new CommandScoreboard());
|
||||
+ this.registerCommand("vanilla.command", new CommandAchievement());
|
||||
+ this.registerCommand("vanilla.command", new CommandSummon());
|
||||
+ this.registerCommand("vanilla.command", new CommandSetBlock());
|
||||
+ this.registerCommand("vanilla.command", new CommandTestForBlock());
|
||||
+ this.registerCommand("vanilla.command", new CommandMessageRaw());
|
||||
+ this.registerCommand("vanilla.command", new CommandNetstat());
|
||||
+ // Cauldron end
|
||||
|
||||
if (MinecraftServer.getServer().isDedicatedServer())
|
||||
{
|
||||
+ /*
|
||||
this.registerCommand(new CommandOp());
|
||||
this.registerCommand(new CommandDeOp());
|
||||
this.registerCommand(new CommandStop());
|
||||
@@ -90,7 +103,7 @@
|
||||
this.registerCommand(new CommandListPlayers());
|
||||
this.registerCommand(new CommandWhitelist());
|
||||
this.registerCommand(new CommandSetPlayerTimeout());
|
||||
- this.registerCommand(new CommandNetstat());
|
||||
+ */
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -98,6 +111,7 @@
|
||||
}
|
||||
|
||||
CommandBase.setAdminCommander(this);
|
||||
+ // Cauldron end
|
||||
}
|
||||
|
||||
public void func_152372_a(ICommandSender p_152372_1_, ICommand p_152372_2_, int p_152372_3_, String p_152372_4_, Object ... p_152372_5_)
|
@ -0,0 +1,212 @@
|
||||
--- ../src-base/minecraft/net/minecraft/command/server/CommandBlockLogic.java
|
||||
+++ ../src-work/minecraft/net/minecraft/command/server/CommandBlockLogic.java
|
||||
@@ -9,18 +9,30 @@
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
+import net.minecraft.tileentity.TileEntityCommandBlockListener;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraft.util.IChatComponent;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
+// CraftBukkit start
|
||||
+import java.util.ArrayList;
|
||||
+import org.apache.logging.log4j.Level;
|
||||
+import org.bukkit.craftbukkit.command.VanillaCommandWrapper;
|
||||
+import com.google.common.base.Joiner;
|
||||
+import net.minecraft.command.PlayerSelector;
|
||||
+import net.minecraft.entity.EntityMinecartCommandBlockListener;
|
||||
+import net.minecraft.entity.player.EntityPlayerMP;
|
||||
+// CraftBukkit end
|
||||
+
|
||||
public abstract class CommandBlockLogic implements ICommandSender
|
||||
{
|
||||
private static final SimpleDateFormat field_145766_a = new SimpleDateFormat("HH:mm:ss");
|
||||
private int field_145764_b;
|
||||
private boolean field_145765_c = true;
|
||||
private IChatComponent field_145762_d = null;
|
||||
- private String field_145763_e = "";
|
||||
+ public String field_145763_e = ""; // CraftBukkit - private -> public
|
||||
private String field_145761_f = "@";
|
||||
+ protected org.bukkit.command.CommandSender sender; // CraftBukkit - add sender;
|
||||
private static final String __OBFID = "CL_00000128";
|
||||
|
||||
public int func_145760_g()
|
||||
@@ -94,8 +106,143 @@
|
||||
|
||||
if (minecraftserver != null && minecraftserver.isCommandBlockEnabled())
|
||||
{
|
||||
- ICommandManager icommandmanager = minecraftserver.getCommandManager();
|
||||
- this.field_145764_b = icommandmanager.executeCommand(this, this.field_145763_e);
|
||||
+ // CraftBukkit start - Handle command block commands using Bukkit dispatcher
|
||||
+ org.bukkit.command.SimpleCommandMap commandMap = minecraftserver.server.getCommandMap();
|
||||
+ Joiner joiner = Joiner.on(" ");
|
||||
+ String command = this.field_145763_e;
|
||||
+
|
||||
+ if (this.field_145763_e.startsWith("/"))
|
||||
+ {
|
||||
+ command = this.field_145763_e.substring(1);
|
||||
+ }
|
||||
+
|
||||
+ String[] args = command.split(" ");
|
||||
+ ArrayList<String[]> commands = new ArrayList<String[]>();
|
||||
+
|
||||
+ // Block disallowed commands
|
||||
+ if (args[0].equalsIgnoreCase("stop") || args[0].equalsIgnoreCase("kick") || args[0].equalsIgnoreCase("op") ||
|
||||
+ args[0].equalsIgnoreCase("deop") || args[0].equalsIgnoreCase("ban") || args[0].equalsIgnoreCase("ban-ip") ||
|
||||
+ args[0].equalsIgnoreCase("pardon") || args[0].equalsIgnoreCase("pardon-ip") || args[0].equalsIgnoreCase("reload"))
|
||||
+ {
|
||||
+ this.field_145764_b = 0;
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ // If the world has no players don't run
|
||||
+ if (this.getEntityWorld().playerEntities.isEmpty())
|
||||
+ {
|
||||
+ this.field_145764_b = 0;
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ // Handle vanilla commands;
|
||||
+ if (minecraftserver.server.getCommandBlockOverride(args[0]))
|
||||
+ {
|
||||
+ org.bukkit.command.Command commandBlockCommand = commandMap.getCommand("minecraft:" + args[0]);
|
||||
+
|
||||
+ if (commandBlockCommand instanceof VanillaCommandWrapper)
|
||||
+ {
|
||||
+ this.field_145764_b = ((VanillaCommandWrapper) commandBlockCommand).dispatchVanillaCommandBlock(this, this.field_145763_e);
|
||||
+ return;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ // Make sure this is a valid command
|
||||
+ if (commandMap.getCommand(args[0]) == null)
|
||||
+ {
|
||||
+ // Cauldron start - execute command using the vanilla command manager if it isn't in the bukkit command map
|
||||
+ net.minecraft.command.ICommandManager icommandmanager = minecraftserver.getCommandManager();
|
||||
+ icommandmanager.executeCommand(this, this.field_145763_e);
|
||||
+ return;
|
||||
+ // Cauldron end
|
||||
+ }
|
||||
+
|
||||
+ // testfor command requires special handling
|
||||
+ if (args[0].equalsIgnoreCase("testfor"))
|
||||
+ {
|
||||
+ if (args.length < 2)
|
||||
+ {
|
||||
+ this.field_145764_b = 0;
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ EntityPlayerMP[] players = PlayerSelector.matchPlayers(this, args[1]);
|
||||
+
|
||||
+ if (players != null && players.length > 0)
|
||||
+ {
|
||||
+ this.field_145764_b = players.length;
|
||||
+ return;
|
||||
+ }
|
||||
+ else
|
||||
+ {
|
||||
+ EntityPlayerMP player = MinecraftServer.getServer().getConfigurationManager().func_152612_a(args[1]);
|
||||
+
|
||||
+ if (player == null)
|
||||
+ {
|
||||
+ this.field_145764_b = 0;
|
||||
+ return;
|
||||
+ }
|
||||
+ else
|
||||
+ {
|
||||
+ this.field_145764_b = 1;
|
||||
+ return;
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ commands.add(args);
|
||||
+ // Find positions of command block syntax, if any
|
||||
+ ArrayList<String[]> newCommands = new ArrayList<String[]>();
|
||||
+
|
||||
+ for (int i = 0; i < args.length; i++)
|
||||
+ {
|
||||
+ if (PlayerSelector.hasArguments(args[i]))
|
||||
+ {
|
||||
+ for (int j = 0; j < commands.size(); j++)
|
||||
+ {
|
||||
+ newCommands.addAll(this.buildCommands(commands.get(j), i));
|
||||
+ }
|
||||
+
|
||||
+ ArrayList<String[]> temp = commands;
|
||||
+ commands = newCommands;
|
||||
+ newCommands = temp;
|
||||
+ newCommands.clear();
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ int completed = 0;
|
||||
+
|
||||
+ // Now dispatch all of the commands we ended up with
|
||||
+ for (int i = 0; i < commands.size(); i++)
|
||||
+ {
|
||||
+ try
|
||||
+ {
|
||||
+ if (commandMap.dispatch(sender, joiner.join(java.util.Arrays.asList(commands.get(i)))))
|
||||
+ {
|
||||
+ completed++;
|
||||
+ }
|
||||
+ }
|
||||
+ catch (Throwable exception)
|
||||
+ {
|
||||
+ if (this instanceof TileEntityCommandBlockListener)
|
||||
+ {
|
||||
+ TileEntityCommandBlockListener listener = (TileEntityCommandBlockListener) this;
|
||||
+ MinecraftServer.getLogger().log(Level.WARN, String.format("CommandBlock at (%d,%d,%d) failed to handle command", listener.getPlayerCoordinates().posX, listener.getPlayerCoordinates().posY, listener.getPlayerCoordinates().posZ), exception);
|
||||
+ }
|
||||
+ else if (this instanceof EntityMinecartCommandBlockListener)
|
||||
+ {
|
||||
+ EntityMinecartCommandBlockListener listener = (EntityMinecartCommandBlockListener) this;
|
||||
+ MinecraftServer.getLogger().log(Level.WARN, String.format("MinecartCommandBlock at (%d,%d,%d) failed to handle command", listener.getPlayerCoordinates().posX, listener.getPlayerCoordinates().posY, listener.getPlayerCoordinates().posZ), exception);
|
||||
+ }
|
||||
+ else
|
||||
+ {
|
||||
+ MinecraftServer.getLogger().log(Level.WARN, String.format("Unknown CommandBlock failed to handle command"), exception);
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ this.field_145764_b = completed;
|
||||
+ // CraftBukkit end
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -103,6 +250,31 @@
|
||||
}
|
||||
}
|
||||
|
||||
+ // CraftBukkit start
|
||||
+ private ArrayList<String[]> buildCommands(String[] args, int pos)
|
||||
+ {
|
||||
+ ArrayList<String[]> commands = new ArrayList<String[]>();
|
||||
+ EntityPlayerMP[] players = PlayerSelector.matchPlayers(this, args[pos]);
|
||||
+
|
||||
+ if (players != null)
|
||||
+ {
|
||||
+ for (EntityPlayerMP player : players)
|
||||
+ {
|
||||
+ if (player.worldObj != this.getEntityWorld())
|
||||
+ {
|
||||
+ continue;
|
||||
+ }
|
||||
+
|
||||
+ String[] command = args.clone();
|
||||
+ command[pos] = player.getCommandSenderName();
|
||||
+ commands.add(command);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ return commands;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
+
|
||||
public String getCommandSenderName()
|
||||
{
|
||||
return this.field_145761_f;
|
Reference in New Issue
Block a user