diff --git a/fml/common/cpw/mods/fml/common/FMLModContainer.java b/fml/common/cpw/mods/fml/common/FMLModContainer.java index 25b10cce9..609dd35c0 100644 --- a/fml/common/cpw/mods/fml/common/FMLModContainer.java +++ b/fml/common/cpw/mods/fml/common/FMLModContainer.java @@ -261,4 +261,24 @@ public class FMLModContainer implements ModContainer // TODO Auto-generated method stub return false; } + + /* (non-Javadoc) + * @see cpw.mods.fml.common.ModContainer#wantsConsoleCommands() + */ + @Override + public boolean wantsConsoleCommands() + { + // TODO Auto-generated method stub + return false; + } + + /* (non-Javadoc) + * @see cpw.mods.fml.common.ModContainer#getConsoleHandler() + */ + @Override + public IConsoleHandler getConsoleHandler() + { + // TODO Auto-generated method stub + return null; + } } diff --git a/fml/common/cpw/mods/fml/common/IConsoleHandler.java b/fml/common/cpw/mods/fml/common/IConsoleHandler.java new file mode 100644 index 000000000..8f2d05343 --- /dev/null +++ b/fml/common/cpw/mods/fml/common/IConsoleHandler.java @@ -0,0 +1,24 @@ +/* + * The FML Forge Mod Loader suite. + * Copyright (C) 2012 cpw + * + * This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 2.1 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +package cpw.mods.fml.common; + +/** + * @author cpw + * + */ +public interface IConsoleHandler +{ + public boolean handleCommand(String command); +} diff --git a/fml/common/cpw/mods/fml/common/ModContainer.java b/fml/common/cpw/mods/fml/common/ModContainer.java index ba8cf1c28..1a9b0ddc3 100644 --- a/fml/common/cpw/mods/fml/common/ModContainer.java +++ b/fml/common/cpw/mods/fml/common/ModContainer.java @@ -156,4 +156,12 @@ public interface ModContainer * @return */ boolean ownsNetworkChannel(String channel); + + /** + * Does this mod want commands from the console? + * @return + */ + boolean wantsConsoleCommands(); + + IConsoleHandler getConsoleHandler(); } diff --git a/fml/patches/minecraft_server/net/minecraft/src/ConsoleCommandHandler.java.patch b/fml/patches/minecraft_server/net/minecraft/src/ConsoleCommandHandler.java.patch new file mode 100644 index 000000000..2170d88df --- /dev/null +++ b/fml/patches/minecraft_server/net/minecraft/src/ConsoleCommandHandler.java.patch @@ -0,0 +1,20 @@ +--- ../src-base/minecraft_server/net/minecraft/src/ConsoleCommandHandler.java 0000-00-00 00:00:00.000000000 -0000 ++++ ../src-work/minecraft_server/net/minecraft/src/ConsoleCommandHandler.java 0000-00-00 00:00:00.000000000 -0000 +@@ -3,6 +3,8 @@ + import java.util.Iterator; + import java.util.Set; + import java.util.logging.Logger; ++ ++import cpw.mods.fml.server.FMLServerHandler; + import net.minecraft.server.MinecraftServer; + + public class ConsoleCommandHandler +@@ -397,7 +399,7 @@ + var6.func_2_b("Ban list:" + this.func_40648_a(this.field_22116_b.func_40025_r(), ", ")); + } + } +- else ++ else if (!FMLServerHandler.instance().handleServerCommand(var2)) + { + field_22117_a.info("Unknown console command. Type \"help\" for help."); + } diff --git a/fml/server/cpw/mods/fml/server/FMLServerHandler.java b/fml/server/cpw/mods/fml/server/FMLServerHandler.java index e12cd4891..f42ba6d00 100644 --- a/fml/server/cpw/mods/fml/server/FMLServerHandler.java +++ b/fml/server/cpw/mods/fml/server/FMLServerHandler.java @@ -440,4 +440,18 @@ public class FMLServerHandler implements IFMLSidedHandler return new File("."); } } + + /** + * @param var2 + * @return + */ + public boolean handleServerCommand(String command) + { + for (ModContainer mod : Loader.getModList()) { + if (mod.wantsConsoleCommands() && mod.getConsoleHandler().handleCommand(command)) { + return true; + } + } + return false; + } } diff --git a/fml/server/cpw/mods/fml/server/ModLoaderModContainer.java b/fml/server/cpw/mods/fml/server/ModLoaderModContainer.java index 792763b74..986ee53c4 100644 --- a/fml/server/cpw/mods/fml/server/ModLoaderModContainer.java +++ b/fml/server/cpw/mods/fml/server/ModLoaderModContainer.java @@ -27,6 +27,7 @@ import java.util.StringTokenizer; import net.minecraft.src.BaseMod; import net.minecraft.src.MLProp; import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.common.IConsoleHandler; import cpw.mods.fml.common.ICraftingHandler; import cpw.mods.fml.common.IDispenseHandler; import cpw.mods.fml.common.INetworkHandler; @@ -492,4 +493,16 @@ public class ModLoaderModContainer implements ModContainer { return FMLCommonHandler.instance().getChannelListFor(this).contains(channel); } + + @Override + public boolean wantsConsoleCommands() + { + return true; + } + + @Override + public IConsoleHandler getConsoleHandler() + { + return mod; + } } diff --git a/fml/server/net/minecraft/src/BaseMod.java b/fml/server/net/minecraft/src/BaseMod.java index 0aa1d3cac..e1f54cbf1 100644 --- a/fml/server/net/minecraft/src/BaseMod.java +++ b/fml/server/net/minecraft/src/BaseMod.java @@ -15,13 +15,14 @@ package net.minecraft.src; import java.util.Random; import net.minecraft.server.MinecraftServer; +import cpw.mods.fml.common.IConsoleHandler; import cpw.mods.fml.common.ICraftingHandler; import cpw.mods.fml.common.IDispenseHandler; import cpw.mods.fml.common.INetworkHandler; import cpw.mods.fml.common.IPickupNotifier; import cpw.mods.fml.common.IWorldGenerator; -public abstract class BaseMod implements IWorldGenerator, IPickupNotifier, IDispenseHandler, ICraftingHandler, INetworkHandler +public abstract class BaseMod implements IWorldGenerator, IPickupNotifier, IDispenseHandler, ICraftingHandler, INetworkHandler, IConsoleHandler { // CALLBACK MECHANISMS @Override @@ -82,6 +83,20 @@ public abstract class BaseMod implements IWorldGenerator, IPickupNotifier, IDisp } } + @Override + public final boolean handleCommand(String command) + { + return onServerCommand(command); + } + /** + * @param command + * @return + */ + private boolean onServerCommand(String command) + { + return false; + } + // BASEMOD API /** * Override if you wish to provide a fuel item for the furnace and return the fuel value of the item