diff --git a/src/main/java/net/aufdemrand/denizen/Denizen.java b/src/main/java/net/aufdemrand/denizen/Denizen.java index d83c9c1da6..b295e73c6f 100644 --- a/src/main/java/net/aufdemrand/denizen/Denizen.java +++ b/src/main/java/net/aufdemrand/denizen/Denizen.java @@ -13,6 +13,7 @@ import net.aufdemrand.denizen.events.bukkit.SavesReloadEvent; import net.aufdemrand.denizen.events.bukkit.ScriptReloadEvent; import net.aufdemrand.denizen.flags.FlagManager; +import net.aufdemrand.denizen.scripts.commands.BukkitCommandRegistry; import net.aufdemrand.denizen.utilities.*; import net.aufdemrand.denizencore.interfaces.dExternal; import net.aufdemrand.denizen.listeners.ListenerRegistry; @@ -23,7 +24,6 @@ import net.aufdemrand.denizen.objects.notable.NotableManager; import net.aufdemrand.denizen.objects.properties.PropertyParser; import net.aufdemrand.denizen.scripts.*; -import net.aufdemrand.denizen.scripts.commands.CommandRegistry; import net.aufdemrand.denizen.scripts.containers.core.*; import net.aufdemrand.denizen.scripts.queues.ScriptEngine; import net.aufdemrand.denizen.scripts.queues.core.InstantQueue; @@ -80,14 +80,14 @@ public ScriptEngine getScriptEngine() { /* * Denizen Registries */ - private CommandRegistry commandRegistry = new CommandRegistry(this); + private BukkitCommandRegistry commandRegistry = new BukkitCommandRegistry(); private TriggerRegistry triggerRegistry = new TriggerRegistry(); private RequirementRegistry requirementRegistry = new RequirementRegistry(this); private ListenerRegistry listenerRegistry = new ListenerRegistry(); private dNPCRegistry dNPCRegistry; - public CommandRegistry getCommandRegistry() { + public BukkitCommandRegistry getCommandRegistry() { return commandRegistry; } @@ -226,6 +226,7 @@ public void onEnable() { } try { + DenizenCore.setCommandRegistry(getCommandRegistry()); getCommandRegistry().registerCoreMembers(); } catch (Exception e) { @@ -686,7 +687,7 @@ public void debugMessage(String message) { } @Override - public void debugException(Exception ex) { + public void debugException(Throwable ex) { dB.echoError(ex); } diff --git a/src/main/java/net/aufdemrand/denizen/scripts/ScriptEntry.java b/src/main/java/net/aufdemrand/denizen/scripts/ScriptEntry.java index 6870a22815..04429e302a 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/ScriptEntry.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/ScriptEntry.java @@ -114,7 +114,7 @@ else if (command.charAt(0) == '~') { dB.echoError(null, "The command '" + this.command + "' cannot be waited for!"); } } - actualCommand = DenizenAPI.getCurrentInstance().getCommandRegistry().get(this.command); + actualCommand = (AbstractCommand)DenizenAPI.getCurrentInstance().getCommandRegistry().get(this.command); } else { actualCommand = null; diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/AbstractCommand.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/AbstractCommand.java index 524fdbe618..6296705439 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/AbstractCommand.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/AbstractCommand.java @@ -4,25 +4,10 @@ import net.aufdemrand.denizencore.exceptions.InvalidArgumentsException; import net.aufdemrand.denizen.scripts.ScriptEntry; -import net.aufdemrand.denizen.utilities.DenizenAPI; import net.aufdemrand.denizencore.scripts.commands.BaseAbstractCommand; public abstract class AbstractCommand extends BaseAbstractCommand { - @Override - public AbstractCommand activate() { - return this; - } - - @Override - public AbstractCommand as(String commandName) { - // Register command with Registry with a Name - name = commandName.toUpperCase(); - DenizenAPI.getCurrentInstance().getCommandRegistry().register(this.name, this); - onEnable(); - return this; - } - public abstract void execute(ScriptEntry scriptEntry) throws CommandExecutionException; /** diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/CommandRegistry.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/BukkitCommandRegistry.java similarity index 93% rename from src/main/java/net/aufdemrand/denizen/scripts/commands/CommandRegistry.java rename to src/main/java/net/aufdemrand/denizen/scripts/commands/BukkitCommandRegistry.java index e3826dec86..0427a46116 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/CommandRegistry.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/BukkitCommandRegistry.java @@ -1,11 +1,5 @@ package net.aufdemrand.denizen.scripts.commands; -import java.util.HashMap; -import java.util.Map; - -import net.aufdemrand.denizen.Denizen; -import net.aufdemrand.denizencore.interfaces.RegistrationableInstance; -import net.aufdemrand.denizencore.interfaces.dRegistry; import net.aufdemrand.denizen.scripts.commands.core.*; import net.aufdemrand.denizen.scripts.commands.entity.*; import net.aufdemrand.denizen.scripts.commands.item.*; @@ -15,88 +9,15 @@ import net.aufdemrand.denizen.scripts.commands.world.*; import net.aufdemrand.denizen.utilities.debugging.dB; import net.aufdemrand.denizen.utilities.depends.Depends; +import net.aufdemrand.denizencore.scripts.commands.CommandRegistry; -public class CommandRegistry implements dRegistry { - - public Denizen denizen; - - public CommandRegistry(Denizen denizen) { - this.denizen = denizen; - } - - private final Map instances = new HashMap(); - private final Map, String> classes = new HashMap, String>(); - - @Override - public boolean register(String commandName, RegistrationableInstance commandInstance) { - this.instances.put(commandName.toUpperCase(), (AbstractCommand) commandInstance); - this.classes.put(((AbstractCommand) commandInstance).getClass(), commandName.toUpperCase()); - return true; - } - - @Override - public Map list() { - return instances; - } - - @Override - public AbstractCommand get(String commandName) { - return instances.get(commandName.toUpperCase()); - } - - @Override - public T get(Class clazz) { - String command = classes.get(clazz); - if (command != null) return clazz.cast(instances.get(command)); - else return null; - } - - // <--[language] - // @Name Command Syntax - // @group Script Command System - // @Description - // Almost every Denizen command and requirement has arguments after the command itself. - // These arguments are just snippets of text showing what exactly the command should do, - // like what the chat command should say, or where the look command should point. - // But how do you know what to put in the arguments? - // - // You merely need to look at the command's usage/syntax info. - // Let's take for example: - // - // - animatechest [] ({open}/close) (sound:{true}/false) - // - // Obviously, the command is 'animatechest'... but what does the rest of it mean? - // - // Anything in [brackets] is required... you MUST put it there. - // Anything in (parenthesis) is optional... you only need to put it there if you want to. - // Anything in {braces} is default... the command will just assume this if no argument is actually typed. - // Anything in <> is non-literal... you must change what is inside of it. - // Anything outside of <> is literal... you must put it exactly as-is. - // <#> represents a number without a decimal, and <#.#> represents a number with a decimal - // Lastly, input that ends with "|..." (EG, [|...] ) can take a list of the input indicated before it (In that example, a list of entities) - // - // A few examples: - // [] is required and non-literal... you might fill it with 'l@1,2,3,world' which is a valid location object. - // (sound:{true}/false) is optional and has a default value of true... you can put sound:false to prevent sound, or leave it blank to allow sound. - // (repeats:<#>) is optional, has no clear default, and is a number. You can put repeats:3 to repeat three times, or leave it blank to not repeat. - // Note: Optional arguments without a default usually have a secret default... EG, the (repeats:<#>) above has a secret default of '0'. - // - // Also, you should never directly type in [], (), {}, or <> even though they are in the syntax info. - // The only exception is in a replaceable tag (EG: ]> will take as a valid actual usage) - // - // Highly specific note: means a block of commands wrapped in braces... EG: - // - // - repeat 3 { - // - narrate "%value%" - // - narrate "everything between the {and} symbols (including them) are for the input!" - // } - // - // - // --> +public class BukkitCommandRegistry extends CommandRegistry { @Override public void registerCoreMembers() { + registerCoreCommands(); + // <--[command] // @Name Action // @Syntax Action [|...] (|...) (context:||...) @@ -2935,27 +2856,4 @@ public void registerCoreMembers() { dB.echoApproval("Loaded core commands: " + instances.keySet().toString()); } - - private void registerCoreMember(Class cmd, String names, String hint, int args) { - for (String name : names.split(", ")) { - - try { - cmd.newInstance().activate().as(name).withOptions(hint, args); - } catch(Throwable e) { - dB.echoError("Could not register command " + name + ": " + e.getMessage()); - dB.echoError(e); - } - } - } - - @Override - public void disableCoreMembers() { - for (RegistrationableInstance member : instances.values()) - try { - member.onDisable(); - } catch (Exception e) { - dB.echoError("Unable to disable '" + member.getClass().getName() + "'!"); - dB.echoError(e); - } - } } diff --git a/src/main/java/net/aufdemrand/denizen/scripts/commands/CommandExecuter.java b/src/main/java/net/aufdemrand/denizen/scripts/commands/CommandExecuter.java index 10cdf7f38d..28e3c4a799 100644 --- a/src/main/java/net/aufdemrand/denizen/scripts/commands/CommandExecuter.java +++ b/src/main/java/net/aufdemrand/denizen/scripts/commands/CommandExecuter.java @@ -66,7 +66,7 @@ public boolean execute(ScriptEntry scriptEntry) { // Get the command instance ready for the execution of the scriptEntry AbstractCommand command = scriptEntry.getCommand(); if (command == null) { - command = DenizenAPI.getCurrentInstance().getCommandRegistry().get(scriptEntry.getCommandName()); + command = (AbstractCommand)DenizenAPI.getCurrentInstance().getCommandRegistry().get(scriptEntry.getCommandName()); } if (command == null) { diff --git a/src/main/java/net/aufdemrand/denizen/utilities/DenizenAPI.java b/src/main/java/net/aufdemrand/denizen/utilities/DenizenAPI.java index e3f2e5b708..0d6e0d05e8 100644 --- a/src/main/java/net/aufdemrand/denizen/utilities/DenizenAPI.java +++ b/src/main/java/net/aufdemrand/denizen/utilities/DenizenAPI.java @@ -3,8 +3,8 @@ import net.aufdemrand.denizen.Denizen; import net.aufdemrand.denizen.npc.dNPCRegistry; import net.aufdemrand.denizen.objects.dNPC; +import net.aufdemrand.denizen.scripts.commands.BukkitCommandRegistry; import net.aufdemrand.denizen.scripts.queues.ScriptEngine; -import net.aufdemrand.denizen.scripts.commands.CommandRegistry; import net.citizensnpcs.api.npc.NPC; import org.bukkit.Bukkit; import org.bukkit.configuration.file.FileConfiguration; @@ -52,7 +52,7 @@ public static Denizen getCurrentInstance() { return (Denizen) Bukkit.getPluginManager().getPlugin("Denizen"); } - public static CommandRegistry _commandRegistry() { + public static BukkitCommandRegistry _commandRegistry() { return getCurrentInstance().getCommandRegistry(); }