diff --git a/lang b/lang index 17e04cd6e..e48361dc0 160000 --- a/lang +++ b/lang @@ -1 +1 @@ -Subproject commit 17e04cd6e567da581b3ca05d93c2fcb6381f9149 +Subproject commit e48361dc007b560de05664d7d6ad4fb22a0f9794 diff --git a/src/main/java/forestry/core/CommandForestry.java b/src/main/java/forestry/core/CommandForestry.java deleted file mode 100755 index 5ac8572eb..000000000 --- a/src/main/java/forestry/core/CommandForestry.java +++ /dev/null @@ -1,171 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011-2014 SirSengir. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser Public License v3 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/lgpl-3.0.txt - * - * Various Contributors including, but not limited to: - * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges - ******************************************************************************/ -package forestry.core; - -import java.util.List; - -import forestry.core.utils.StringUtil; -import net.minecraft.command.CommandException; -import net.minecraft.command.ICommand; -import net.minecraft.command.ICommandSender; -import net.minecraft.command.WrongUsageException; -import net.minecraft.entity.player.EntityPlayer; - -import forestry.plugins.Plugin; -import forestry.core.config.Version; -import forestry.core.proxy.Proxies; -import forestry.core.utils.CommandMC; -import forestry.plugins.ForestryPlugin; -import forestry.plugins.PluginManager; -import net.minecraft.util.StatCollector; - -public class CommandForestry extends CommandMC { - - @Override - public int compareTo(Object arg0) { - return this.getCommandName().compareTo(((ICommand) arg0).getCommandName()); - } - - @Override - public String getCommandName() { - return "forestry"; - } - - @Override - public String getCommandUsage(ICommandSender sender) { - return "/" + this.getCommandName() + " help"; - } - - @SuppressWarnings("rawtypes") - @Override - public List getCommandAliases() { - return null; - } - - @Override - public void processCommand(ICommandSender sender, String[] arguments) { - - if (arguments.length <= 0) - throw new WrongUsageException(StringUtil.localizeAndFormat("chat.help", this.getCommandUsage(sender))); - - if (arguments[0].matches("version")) { - commandVersion(sender, arguments); - return; - } else if (arguments[0].matches("plugins")) { - commandPlugins(sender, arguments); - return; - } else if (arguments[0].matches("help")) { - sendChatMessage(sender, StringUtil.localizeAndFormat("chat.command.help.0", this.getCommandName())); - sendChatMessage(sender, StringUtil.localize("chat.command.help.1")); - sendChatMessage(sender, StringUtil.localize("chat.command.help.2")); - sendChatMessage(sender, StringUtil.localize("chat.command.help.3")); - sendChatMessage(sender, StringUtil.localize("chat.command.help.4")); - return; - } - - throw new WrongUsageException(this.getCommandUsage(sender)); - } - - private void commandVersion(ICommandSender sender, String[] arguments) { - String colour = Version.isOutdated() ? "\u00A7c" : "\u00A7a"; - - sendChatMessage(sender, String.format(colour + StringUtil.localize("chat.version"), Version.getVersion(), - Proxies.common.getMinecraftVersion(), Version.getRecommendedVersion())); - if (Version.isOutdated()) - for (String updateLine : Version.getChangelog()) - sendChatMessage(sender, "\u00A79" + updateLine); - } - - private void commandPlugins(ICommandSender sender, String[] arguments) { - - if (arguments.length <= 1) - listPluginsForSender(sender); - else if (arguments[1].matches("info")) - listPluginInfoForSender(sender, arguments); - - } - - private void listPluginsForSender(ICommandSender sender) { - - String pluginList = ""; - - for (PluginManager.Module pluginModule : PluginManager.getLoadedModules()) { - if (!pluginList.isEmpty()) - pluginList += ", "; - pluginList += makeListEntry(pluginModule.instance()); - } - - sendChatMessage(sender, pluginList); - } - - private void listPluginInfoForSender(ICommandSender sender, String[] arguments) { - - if (arguments.length < 3) - throw new WrongUsageException("/" + getCommandName() + " plugins info "); - - ForestryPlugin found = null; - for (PluginManager.Module pluginModule : PluginManager.getLoadedModules()) { - Plugin info = pluginModule.instance().getClass().getAnnotation(Plugin.class); - if (info == null) - continue; - - if ((info.pluginID().equalsIgnoreCase(arguments[2]) || info.name().equalsIgnoreCase(arguments[2]))) { - found = pluginModule.instance(); - break; - } - } - - if (found == null) - throw new CommandException(StringUtil.localizeAndFormat("chat.plugins.error", arguments[2])); - - String entry = "\u00A7c"; - if (found.isAvailable()) - entry = "\u00A7a"; - Plugin info = found.getClass().getAnnotation(Plugin.class); - if (info != null) { - sendChatMessage(sender, entry + "Plugin: " + info.name()); - if (!info.version().isEmpty()) - sendChatMessage(sender, "\u00A79Version: " + info.version()); - if (!info.author().isEmpty()) - sendChatMessage(sender, "\u00A79Author(s): " + info.author()); - if (!info.url().isEmpty()) - sendChatMessage(sender, "\u00A79URL: " + info.url()); - if (!info.unlocalizedDescription().isEmpty()) - sendChatMessage(sender, StatCollector.translateToLocal(info.unlocalizedDescription())); - } - - } - - private String makeListEntry(ForestryPlugin plugin) { - String entry = "\u00A7c"; - if (plugin.isAvailable()) - entry = "\u00A7a"; - - Plugin info = plugin.getClass().getAnnotation(Plugin.class); - if (info != null) { - entry += info.pluginID(); - if (!info.version().isEmpty()) - entry += " (" + info.version() + ")"; - } else - entry += "???"; - - return entry; - } - - @Override - public boolean canCommandSenderUseCommand(ICommandSender sender) { - if (sender instanceof EntityPlayer) - return Proxies.common.isOp((EntityPlayer) sender); - else - return sender.canCommandSenderUseCommand(4, getCommandName()); - } - -} diff --git a/src/main/java/forestry/core/commands/CommandHelpers.java b/src/main/java/forestry/core/commands/CommandHelpers.java new file mode 100644 index 000000000..b1c979200 --- /dev/null +++ b/src/main/java/forestry/core/commands/CommandHelpers.java @@ -0,0 +1,112 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.core.commands; + +import forestry.core.utils.StringUtil; +import net.minecraft.command.ICommandSender; +import net.minecraft.command.WrongUsageException; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.server.MinecraftServer; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.ChatComponentTranslation; +import net.minecraft.world.World; + +/** + * + * @author CovertJaguar + */ +public class CommandHelpers { + + public static World getWorld(ICommandSender sender, IForestryCommand command, String[] args, int worldArgIndex) { + + // Handle passed in world argument + if (worldArgIndex < args.length) + try { + int dim = Integer.parseInt(args[worldArgIndex]); + World world = MinecraftServer.getServer().worldServerForDimension(dim); + if (world != null) + return world; + } catch (Exception ex) { + throwWrongUsage(sender, command); + } + + if (sender instanceof EntityPlayer) { + EntityPlayer player = (EntityPlayer) sender; + return player.worldObj; + } else + return MinecraftServer.getServer().worldServerForDimension(0); + + } + + public static String[] getPlayers() { + return MinecraftServer.getServer().getAllUsernames(); + } + + public static void sendLocalizedChatMessage(ICommandSender sender, String locTag, Object... args) { + sender.addChatMessage(new ChatComponentTranslation(locTag, args)); + } + + public static void sendChatMessage(ICommandSender sender, String message) { + sender.addChatMessage(new ChatComponentText(message)); + } + + public static void throwWrongUsage(ICommandSender sender, IForestryCommand command) throws WrongUsageException { + throw new WrongUsageException(StringUtil.localizeAndFormat("chat.help", command.getCommandUsage(sender))); + } + + public static void processChildCommand(ICommandSender sender, SubCommand child, String[] args) { + if (!sender.canCommandSenderUseCommand(child.getRequiredPermissionLevel(), child.getFullCommandString())) + throw new WrongUsageException(StringUtil.localize("chat.command.noperms")); + String[] newargs = new String[args.length - 1]; + System.arraycopy(args, 1, newargs, 0, newargs.length); + child.processCommand(sender, newargs); + } + + public static void printHelp(ICommandSender sender, IForestryCommand command) { + sendLocalizedChatMessage(sender, "for.chat.command.format", command.getCommandFormat(sender)); + sendLocalizedChatMessage(sender, "for.chat.command.aliases", command.getCommandAliases().toString().replace("[", "").replace("]", "")); + sendLocalizedChatMessage(sender, "for.chat.command.permlevel", command.getRequiredPermissionLevel()); + sendLocalizedChatMessage(sender, "for.chat.command." + command.getFullCommandString().replace(" ", ".") + ".help"); + if (!command.getChildren().isEmpty()) { + sendLocalizedChatMessage(sender, "for.chat.command.list"); + for (SubCommand child : command.getChildren()) { + sendLocalizedChatMessage(sender, "for.chat.command." + child.getFullCommandString().replace(" ", ".") + ".desc", child.getCommandName()); + } + } + } + + public static boolean processStandardCommands(ICommandSender sender, IForestryCommand command, String[] args) { + if (args.length >= 1) { + if (args[0].equals("help")) { + command.printHelp(sender); + return true; + } + for (SubCommand child : command.getChildren()) { + if (matches(args[0], child)) { + processChildCommand(sender, child, args); + return true; + } + } + } + return false; + } + + public static boolean matches(String commandName, IForestryCommand command) { + if (commandName.equals(command.getCommandName())) + return true; + else if (command.getCommandAliases() != null) + for (String alias : command.getCommandAliases()) { + if (commandName.equals(alias)) + return true; + } + return false; + } +} diff --git a/src/main/java/forestry/core/commands/CommandPlugins.java b/src/main/java/forestry/core/commands/CommandPlugins.java new file mode 100644 index 000000000..3ab8cfbb4 --- /dev/null +++ b/src/main/java/forestry/core/commands/CommandPlugins.java @@ -0,0 +1,126 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.core.commands; + +import forestry.core.utils.StringUtil; +import forestry.plugins.ForestryPlugin; +import forestry.plugins.Plugin; +import forestry.plugins.PluginManager; +import net.minecraft.command.CommandException; +import net.minecraft.command.ICommandSender; +import net.minecraft.util.StatCollector; + +/** + * + * @author CovertJaguar + */ +public class CommandPlugins extends SubCommand { + + public CommandPlugins() { + addChildCommand(new CommandPluginsInfo()); + } + + @Override + public String getCommandName() { + return "plugins"; + } + + @Override + public String getCommandFormat(ICommandSender sender) { + return "/" + getFullCommandString() + " [info ]"; + } + + @Override + public void processSubCommand(ICommandSender sender, String[] args) { + if (args.length == 0) + listPluginsForSender(sender); + else + CommandHelpers.throwWrongUsage(sender, this); + } + + private void listPluginsForSender(ICommandSender sender) { + String pluginList = ""; + for (PluginManager.Module pluginModule : PluginManager.getLoadedModules()) { + if (!pluginList.isEmpty()) + pluginList += ", "; + pluginList += makeListEntry(pluginModule.instance()); + } + CommandHelpers.sendChatMessage(sender, pluginList); + } + + private String makeListEntry(ForestryPlugin plugin) { + String entry = "\u00A7c"; + if (plugin.isAvailable()) + entry = "\u00A7a"; + + Plugin info = plugin.getClass().getAnnotation(Plugin.class); + if (info != null) { + entry += info.pluginID(); + if (!info.version().isEmpty()) + entry += " (" + info.version() + ")"; + } else + entry += "???"; + + return entry; + } + + public static class CommandPluginsInfo extends SubCommand { + + @Override + public String getCommandName() { + return "info"; + } + + @Override + public void processSubCommand(ICommandSender sender, String[] args) { + if (args.length == 1) + listPluginInfoForSender(sender, args[0]); + else + CommandHelpers.throwWrongUsage(sender, this); + } + + private void listPluginInfoForSender(ICommandSender sender, String plugin) { + ForestryPlugin found = null; + for (PluginManager.Module pluginModule : PluginManager.getLoadedModules()) { + Plugin info = pluginModule.instance().getClass().getAnnotation(Plugin.class); + if (info == null) + continue; + + if ((info.pluginID().equalsIgnoreCase(plugin) || info.name().equalsIgnoreCase(plugin))) { + found = pluginModule.instance(); + break; + } + } + + if (found == null) + throw new CommandException(StringUtil.localizeAndFormat("chat.plugins.error", plugin)); + + String entry = "\u00A7c"; + if (found.isAvailable()) + entry = "\u00A7a"; + Plugin info = found.getClass().getAnnotation(Plugin.class); + if (info != null) { + CommandHelpers.sendChatMessage(sender, entry + "Plugin: " + info.name()); + if (!info.version().isEmpty()) + CommandHelpers.sendChatMessage(sender, "\u00A79Version: " + info.version()); + if (!info.author().isEmpty()) + CommandHelpers.sendChatMessage(sender, "\u00A79Author(s): " + info.author()); + if (!info.url().isEmpty()) + CommandHelpers.sendChatMessage(sender, "\u00A79URL: " + info.url()); + if (!info.unlocalizedDescription().isEmpty()) + CommandHelpers.sendChatMessage(sender, StatCollector.translateToLocal(info.unlocalizedDescription())); + } + + } + + } + +} diff --git a/src/main/java/forestry/core/commands/CommandVersion.java b/src/main/java/forestry/core/commands/CommandVersion.java new file mode 100644 index 000000000..6a3529838 --- /dev/null +++ b/src/main/java/forestry/core/commands/CommandVersion.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.core.commands; + +import net.minecraft.command.ICommandSender; +import forestry.core.config.Version; +import forestry.core.proxy.Proxies; +import forestry.core.utils.StringUtil; + +/** + * + * @author CovertJaguar + */ +public class CommandVersion extends SubCommand { + + @Override + public String getCommandName() { + return "version"; + } + + @Override + public String getCommandFormat(ICommandSender sender) { + return "/" + getFullCommandString(); + } + + @Override + public void processSubCommand(ICommandSender sender, String[] args) { + String colour = Version.isOutdated() ? "\u00A7c" : "\u00A7a"; + + CommandHelpers.sendChatMessage(sender, String.format(colour + StringUtil.localize("chat.version"), Version.getVersion(), Proxies.common.getMinecraftVersion(), Version.getRecommendedVersion())); + if (Version.isOutdated()) + for (String updateLine : Version.getChangelog()) { + CommandHelpers.sendChatMessage(sender, "\u00A79" + updateLine); + } + } + +} diff --git a/src/main/java/forestry/core/commands/IForestryCommand.java b/src/main/java/forestry/core/commands/IForestryCommand.java new file mode 100644 index 000000000..c4c3631e8 --- /dev/null +++ b/src/main/java/forestry/core/commands/IForestryCommand.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.core.commands; + +import java.util.List; +import java.util.SortedSet; +import net.minecraft.command.ICommand; +import net.minecraft.command.ICommandSender; + +/** + * + * @author CovertJaguar + */ +public interface IForestryCommand extends ICommand { + + String getFullCommandString(); + + @Override + List getCommandAliases(); + + int getRequiredPermissionLevel(); + + SortedSet getChildren(); + + String getCommandFormat(ICommandSender sender); + + void printHelp(ICommandSender sender); +} diff --git a/src/main/java/forestry/core/commands/RootCommand.java b/src/main/java/forestry/core/commands/RootCommand.java new file mode 100644 index 000000000..38d6d6958 --- /dev/null +++ b/src/main/java/forestry/core/commands/RootCommand.java @@ -0,0 +1,91 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.core.commands; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; +import java.util.SortedSet; +import java.util.TreeSet; +import net.minecraft.command.CommandBase; +import net.minecraft.command.ICommandSender; + +/** + * + * @author CovertJaguar + */ +public class RootCommand extends CommandBase implements IForestryCommand { + + public static final String ROOT_COMMAND_NAME = "forestry"; + public static final String ROOT_COMMAND_ALIAS = "for"; + + private final SortedSet children = new TreeSet(new Comparator() { + + @Override + public int compare(SubCommand o1, SubCommand o2) { + return o1.compareTo(o2); + } + }); + + public void addChildCommand(SubCommand child) { + child.setParent(this); + children.add(child); + } + + @Override + public SortedSet getChildren() { + return children; + } + + @Override + public String getCommandName() { + return ROOT_COMMAND_NAME; + } + + @Override + public int getRequiredPermissionLevel() { + return 0; + } + + @Override + public List getCommandAliases() { + List aliases = new ArrayList(); + aliases.add(ROOT_COMMAND_ALIAS); + return aliases; + } + + @Override + public String getCommandUsage(ICommandSender sender) { + return "/" + this.getCommandName() + " help"; + } + + @Override + public void processCommand(ICommandSender sender, String[] args) { + if (!CommandHelpers.processStandardCommands(sender, this, args)) + CommandHelpers.throwWrongUsage(sender, this); + } + + @Override + public String getCommandFormat(ICommandSender sender) { + return "/" + getFullCommandString() + " "; + } + + @Override + public String getFullCommandString() { + return getCommandName(); + } + + @Override + public void printHelp(ICommandSender sender) { + CommandHelpers.printHelp(sender, this); + } + +} diff --git a/src/main/java/forestry/core/commands/SubCommand.java b/src/main/java/forestry/core/commands/SubCommand.java new file mode 100644 index 000000000..1beb895d2 --- /dev/null +++ b/src/main/java/forestry/core/commands/SubCommand.java @@ -0,0 +1,120 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.core.commands; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; +import java.util.SortedSet; +import java.util.TreeSet; +import net.minecraft.command.ICommand; +import net.minecraft.command.ICommandSender; + +/** + * + * @author CovertJaguar + */ +public abstract class SubCommand implements IForestryCommand { + + private final List aliases = new ArrayList(); + private IForestryCommand parent; + private final SortedSet children = new TreeSet(new Comparator() { + + @Override + public int compare(SubCommand o1, SubCommand o2) { + return o1.compareTo(o2); + } + }); + + public void addChildCommand(SubCommand child) { + child.setParent(this); + children.add(child); + } + + void setParent(IForestryCommand parent) { + this.parent = parent; + } + + @Override + public SortedSet getChildren() { + return children; + } + + public void addAlias(String alias) { + aliases.add(alias); + } + + @Override + public List getCommandAliases() { + return aliases; + } + + @Override + public List addTabCompletionOptions(ICommandSender p_71516_1_, String[] p_71516_2_) { + return null; + } + + @Override + public final void processCommand(ICommandSender sender, String[] args) { + if (!CommandHelpers.processStandardCommands(sender, this, args)) + processSubCommand(sender, args); + + } + + public void processSubCommand(ICommandSender sender, String[] args) { + CommandHelpers.throwWrongUsage(sender, this); + } + + @Override + public int getRequiredPermissionLevel() { + return 0; + } + + @Override + public boolean canCommandSenderUseCommand(ICommandSender sender) { + return sender.canCommandSenderUseCommand(getRequiredPermissionLevel(), getCommandName()); + } + + @Override + public boolean isUsernameIndex(String[] args, int index) { + return false; + } + + @Override + public String getCommandUsage(ICommandSender sender) { + return "/" + getFullCommandString() + " help"; + } + + @Override + public String getCommandFormat(ICommandSender sender) { + return "/" + getFullCommandString() + " "; + } + + @Override + public void printHelp(ICommandSender sender) { + CommandHelpers.printHelp(sender, this); + } + + @Override + public String getFullCommandString() { + return parent.getFullCommandString() + " " + getCommandName(); + } + + public int compareTo(ICommand command) { + return this.getCommandName().compareTo(command.getCommandName()); + } + + @Override + public int compareTo(Object command) { + return this.compareTo((ICommand) command); + } + +} diff --git a/src/main/java/forestry/core/utils/CommandMC.java b/src/main/java/forestry/core/utils/CommandMC.java index 92113bb3a..138fb83c0 100755 --- a/src/main/java/forestry/core/utils/CommandMC.java +++ b/src/main/java/forestry/core/utils/CommandMC.java @@ -18,6 +18,7 @@ import net.minecraft.server.MinecraftServer; import net.minecraft.util.ChatComponentText; import net.minecraft.world.World; +@Deprecated public abstract class CommandMC extends CommandBase { protected World getWorld(ICommandSender sender, String[] arguments) { diff --git a/src/main/java/forestry/lepidopterology/commands/CommandButterfly.java b/src/main/java/forestry/lepidopterology/commands/CommandButterfly.java new file mode 100644 index 000000000..98cba4d27 --- /dev/null +++ b/src/main/java/forestry/lepidopterology/commands/CommandButterfly.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.lepidopterology.commands; + +import forestry.core.commands.*; +import forestry.lepidopterology.entities.EntityButterfly; +import net.minecraft.command.ICommandSender; +import net.minecraft.world.World; + +/** + * + * @author CovertJaguar + */ +public class CommandButterfly extends SubCommand { + + public CommandButterfly() { + addAlias("bfly"); + addChildCommand(new CommandButterflyKill()); + } + + @Override + public String getCommandName() { + return "butterfly"; + } + + @Override + public String getCommandFormat(ICommandSender sender) { + return "/" + getFullCommandString() + " "; + } + + public static class CommandButterflyKill extends SubCommand { + + public CommandButterflyKill() { + addAlias("killall"); + } + + @Override + public String getCommandName() { + return "kill"; + } + + @Override + public int getRequiredPermissionLevel() { + return 2; + } + + @Override + public String getCommandFormat(ICommandSender sender) { + return "/" + getFullCommandString() + " []"; + } + + @Override + public void processSubCommand(ICommandSender sender, String[] args) { + if (args.length > 1) + CommandHelpers.throwWrongUsage(sender, this); + + World world = CommandHelpers.getWorld(sender, this, args, 0); + if (world == null) + CommandHelpers.throwWrongUsage(sender, this); + else + for (Object entity : world.loadedEntityList) { + if (entity instanceof EntityButterfly) + ((EntityButterfly) entity).setDead(); + } + } + + } + +} diff --git a/src/main/java/forestry/plugins/PluginCore.java b/src/main/java/forestry/plugins/PluginCore.java index 4c9f1c925..297042964 100755 --- a/src/main/java/forestry/plugins/PluginCore.java +++ b/src/main/java/forestry/plugins/PluginCore.java @@ -23,7 +23,6 @@ import cpw.mods.fml.common.network.IGuiHandler; import forestry.api.circuits.ChipsetManager; import forestry.api.core.Tabs; import forestry.api.genetics.AlleleManager; -import forestry.core.CommandForestry; import forestry.core.CreativeTabForestry; import forestry.core.GameMode; import forestry.core.PickupHandlerCore; @@ -31,6 +30,9 @@ import forestry.core.SaveEventHandlerCore; import forestry.core.circuits.CircuitRegistry; import forestry.core.circuits.ItemCircuitBoard; import forestry.core.circuits.ItemSolderingIron; +import forestry.core.commands.CommandPlugins; +import forestry.core.commands.CommandVersion; +import forestry.core.commands.RootCommand; import forestry.core.config.Config; import forestry.core.config.Defaults; import forestry.core.config.ForestryBlock; @@ -74,11 +76,15 @@ public class PluginCore extends ForestryPlugin { public static MachineDefinition definitionEscritoire; // ICrashCallable for highlighting certain mods during crashes. public static ForestryModEnvWarningCallable crashCallable; + public static RootCommand rootCommand = new RootCommand(); @Override public void preInit() { super.preInit(); + rootCommand.addChildCommand(new CommandVersion()); + rootCommand.addChildCommand(new CommandPlugins()); + ChipsetManager.solderManager = new ItemSolderingIron.SolderManager(); CircuitRegistry circuitRegistry = new CircuitRegistry(); @@ -109,7 +115,7 @@ public class PluginCore extends ForestryPlugin { OreDictionary.registerOre("oreApatite", ForestryBlock.resources.getItemStack(1, 0)); OreDictionary.registerOre("oreCopper", ForestryBlock.resources.getItemStack(1, 1)); OreDictionary.registerOre("oreTin", ForestryBlock.resources.getItemStack(1, 2)); - + ForestryBlock.resourceStorage.registerBlock(new BlockResourceStorageBlock(), ItemForestryBlock.class, "resourceStorage"); ForestryBlock.resourceStorage.block().setHarvestLevel("pickaxe", 0, 0); ForestryBlock.resourceStorage.block().setHarvestLevel("pickaxe", 0, 1); @@ -435,17 +441,17 @@ public class PluginCore extends ForestryPlugin { // / Pipette Proxies.common.addRecipe(ForestryItem.pipette.getItemStack(), " #", " X ", "X ", 'X', Blocks.glass_pane, '#', new ItemStack(Blocks.wool, 1, Defaults.WILDCARD)); - + // Storage Blocks Proxies.common.addRecipe(ForestryBlock.resourceStorage.getItemStack(1, 0), "###", "###", "###", '#', "gemApatite"); Proxies.common.addShapelessRecipe(ForestryItem.apatite.getItemStack(9), "blockApatite"); Proxies.common.addRecipe(ForestryBlock.resourceStorage.getItemStack(1, 1), "###", "###", "###", '#', "ingotCopper"); Proxies.common.addShapelessRecipe(ForestryItem.ingotCopper.getItemStack(9), "blockCopper"); - + Proxies.common.addRecipe(ForestryBlock.resourceStorage.getItemStack(1, 2), "###", "###", "###", '#', "ingotTin"); Proxies.common.addShapelessRecipe(ForestryItem.ingotTin.getItemStack(9), "blockTin"); - + Proxies.common.addRecipe(ForestryBlock.resourceStorage.getItemStack(1, 3), "###", "###", "###", '#', "ingotBronze"); Proxies.common.addShapelessRecipe(ForestryItem.ingotBronze.getItemStack(9), "blockBronze"); } @@ -457,7 +463,7 @@ public class PluginCore extends ForestryPlugin { @Override public ICommand[] getConsoleCommands() { - return new ICommand[]{new CommandForestry()}; + return new ICommand[]{rootCommand}; } @Override diff --git a/src/main/java/forestry/plugins/PluginLepidopterology.java b/src/main/java/forestry/plugins/PluginLepidopterology.java index 4b97b7602..0efb4c37e 100755 --- a/src/main/java/forestry/plugins/PluginLepidopterology.java +++ b/src/main/java/forestry/plugins/PluginLepidopterology.java @@ -48,6 +48,7 @@ import forestry.core.utils.Utils; import forestry.lepidopterology.ButterflySpawner; import forestry.lepidopterology.GuiHandlerLepidopterology; import forestry.lepidopterology.MatingRecipe; +import forestry.lepidopterology.commands.CommandButterfly; import forestry.lepidopterology.entities.EntityButterfly; import forestry.lepidopterology.gadgets.TileLepidopteristChest; import forestry.lepidopterology.genetics.AlleleButterflySpecies; @@ -110,6 +111,8 @@ public class PluginLepidopterology extends ForestryPlugin { config.save(); + PluginCore.rootCommand.addChildCommand(new CommandButterfly()); + Utils.registerEntity(EntityButterfly.class, "butterflyGE", 0, 0x000000, 0xffffff, 50, 1, true); proxy.initializeRendering(); registerTemplates();