From 45b88354e59daa5377919e0f1d227f42ca8efaee Mon Sep 17 00:00:00 2001 From: alisolarflare Date: Sun, 6 Nov 2016 16:44:56 -0500 Subject: [PATCH] Pretty much the command equivalent to hard coding --- src/alisolarflare/AliPresents.java | 3 +- src/alisolarflare/Module.java | 26 ++++--- .../CreativeBoundariesModule.java | 4 +- .../listeners/ItemRestrictionListener.java | 26 +++++++ .../{ => listeners}/PlotChangeListener.java | 4 +- .../magic/tricks/BoomBowDeathListener.java | 2 +- src/alisolarflare/uhc/UHCModule.java | 3 + .../uhc/controller/SetMatchState.java | 76 +++++++++++++++++++ 8 files changed, 128 insertions(+), 16 deletions(-) create mode 100644 src/alisolarflare/creativeboundaries/listeners/ItemRestrictionListener.java rename src/alisolarflare/creativeboundaries/{ => listeners}/PlotChangeListener.java (91%) create mode 100644 src/alisolarflare/uhc/controller/SetMatchState.java diff --git a/src/alisolarflare/AliPresents.java b/src/alisolarflare/AliPresents.java index b86142c..947c41b 100644 --- a/src/alisolarflare/AliPresents.java +++ b/src/alisolarflare/AliPresents.java @@ -18,10 +18,10 @@ public class AliPresents extends JavaPlugin{ public void onEnable(){ PluginDescriptionFile pdfFile = getDescription(); - Logger logger = getLogger(); logger.info(pdfFile.getName() + " has been started (V." + pdfFile.getVersion()+ ")."); + new FlairDoorModule().register(this); new GPowerModule().register(this); new AliLinkModule().register(this); @@ -30,6 +30,7 @@ public class AliPresents extends JavaPlugin{ new MinigameModule().register(this); new CreativeBoundariesModule().register(this); + logger.info(pdfFile.getName() + " has fully registered (V." + pdfFile.getVersion()+ ")."); diff --git a/src/alisolarflare/Module.java b/src/alisolarflare/Module.java index ad674d1..3fe900b 100644 --- a/src/alisolarflare/Module.java +++ b/src/alisolarflare/Module.java @@ -8,10 +8,10 @@ import buttondevteam.lib.chat.TBMCChatAPI; import buttondevteam.lib.chat.TBMCCommandBase; /** - * A Module class is a helper class that allows the compacting of projects into one single package. - * Each feature, whether game, arrow trail listener, or command tool, can have its command and listener - * registration coded into the Module class, as well as any other pointers to memory units, or other - * classes in the package. + * A Module class allows the compacting of projects into one single package. + * + * Each feature can have its commands and listeners coded into the Module class, + * as well as any other pointers to memory units, or other classes in the package. * * This package can then be moved from eclipse project to eclipse project smoothly, * as long as the destination project has the Module abstract class, and as long as all dependencies are either @@ -21,19 +21,14 @@ import buttondevteam.lib.chat.TBMCCommandBase; */ public abstract class Module{ /** - * Registers the project, when called by the Main JavaPlugin class that handles - * the main plugin. + * Registers the module, when called by the JavaPlugin class. Call + * registerCommand() and registerListener() within this method. * - * To register a command, call plugin.getCommand(//label).setExecutor(//commandExecutor); where - * label is a string containing the name of the command in plugin.yml, and where commandExecutor - * is a class implementing command executor - * - * To register a listener, * @param plugin Plugin class called to register commands and listeners */ public abstract void register(JavaPlugin plugin); /** - * Lazy route to type plugin.getCommand("label").setExecutor + * Registers a TBMCCommand to the plugin * @param plugin Main plugin responsible for stuff * @param label Name of the command in plugin.yml * @param commandExecutor Custom coded CommandExecutor class @@ -41,8 +36,15 @@ public abstract class Module{ protected void registerCommand(JavaPlugin plugin, TBMCCommandBase commandBase){ TBMCChatAPI.AddCommand(plugin, commandBase); } + /** + * Registers a Listener to this plugin + * @param plugin Main plugin responsible for stuff + * @param label Name of the command in plugin.yml + * @param commandExecutor Custom coded CommandExecutor class + */ protected Listener registerListener(JavaPlugin plugin, Listener listener){ TBMCCoreAPI.RegisterEventsForExceptions(listener, plugin); return listener; } + } diff --git a/src/alisolarflare/creativeboundaries/CreativeBoundariesModule.java b/src/alisolarflare/creativeboundaries/CreativeBoundariesModule.java index 6de650f..39dac19 100644 --- a/src/alisolarflare/creativeboundaries/CreativeBoundariesModule.java +++ b/src/alisolarflare/creativeboundaries/CreativeBoundariesModule.java @@ -10,6 +10,8 @@ import alisolarflare.Module; import alisolarflare.creativeboundaries.commands.Cbgm0; import alisolarflare.creativeboundaries.commands.Cbgm1; import alisolarflare.creativeboundaries.commands.SetDickmode; +import alisolarflare.creativeboundaries.listeners.ItemRestrictionListener; +import alisolarflare.creativeboundaries.listeners.PlotChangeListener; public class CreativeBoundariesModule extends Module{ @@ -21,8 +23,8 @@ public class CreativeBoundariesModule extends Module{ registerCommand(plugin, new Cbgm0(this)); registerCommand(plugin, new SetDickmode(this)); - registerListener(plugin, new PlotChangeListener(this)); + //registerListener(plugin, new ItemRestrictionListener(this)); } } diff --git a/src/alisolarflare/creativeboundaries/listeners/ItemRestrictionListener.java b/src/alisolarflare/creativeboundaries/listeners/ItemRestrictionListener.java new file mode 100644 index 0000000..9023755 --- /dev/null +++ b/src/alisolarflare/creativeboundaries/listeners/ItemRestrictionListener.java @@ -0,0 +1,26 @@ +package alisolarflare.creativeboundaries.listeners; + +import java.util.List; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryCreativeEvent; + +import alisolarflare.creativeboundaries.CreativeBoundariesModule; + +public class ItemRestrictionListener implements Listener { + + private CreativeBoundariesModule module; + + public ItemRestrictionListener(CreativeBoundariesModule module) { + this.module = module; + } + + @EventHandler + public void onItemTake(InventoryCreativeEvent event){ + List cbCreatives = module.cbCreatives; + + } + +} diff --git a/src/alisolarflare/creativeboundaries/PlotChangeListener.java b/src/alisolarflare/creativeboundaries/listeners/PlotChangeListener.java similarity index 91% rename from src/alisolarflare/creativeboundaries/PlotChangeListener.java rename to src/alisolarflare/creativeboundaries/listeners/PlotChangeListener.java index ddd69b4..e911b98 100644 --- a/src/alisolarflare/creativeboundaries/PlotChangeListener.java +++ b/src/alisolarflare/creativeboundaries/listeners/PlotChangeListener.java @@ -1,4 +1,4 @@ -package alisolarflare.creativeboundaries; +package alisolarflare.creativeboundaries.listeners; import org.bukkit.GameMode; import org.bukkit.entity.Player; @@ -12,6 +12,8 @@ import com.palmergames.bukkit.towny.object.Town; import com.palmergames.bukkit.towny.object.TownBlock; import com.palmergames.bukkit.towny.object.TownyUniverse; +import alisolarflare.creativeboundaries.CreativeBoundariesModule; + public class PlotChangeListener implements Listener{ public CreativeBoundariesModule module; public PlotChangeListener(CreativeBoundariesModule module){ diff --git a/src/alisolarflare/magic/tricks/BoomBowDeathListener.java b/src/alisolarflare/magic/tricks/BoomBowDeathListener.java index 4380414..427537e 100644 --- a/src/alisolarflare/magic/tricks/BoomBowDeathListener.java +++ b/src/alisolarflare/magic/tricks/BoomBowDeathListener.java @@ -12,7 +12,7 @@ public class BoomBowDeathListener implements Listener{ if (player.getLastDamage() > 7.42420 && player.getLastDamage() < 7.42429){ player.sendMessage("42!"); - event.setDeathMessage(player.getName() + "got trigger happy with the Boom Bow"); + event.setDeathMessage(player.getName() + " got trigger happy with the [Boom Bow]"); } } } diff --git a/src/alisolarflare/uhc/UHCModule.java b/src/alisolarflare/uhc/UHCModule.java index a27aa14..eebbb43 100644 --- a/src/alisolarflare/uhc/UHCModule.java +++ b/src/alisolarflare/uhc/UHCModule.java @@ -3,6 +3,7 @@ package alisolarflare.uhc; import org.bukkit.plugin.java.JavaPlugin; import alisolarflare.Module; +import alisolarflare.uhc.controller.SetMatchState; import alisolarflare.uhc.idle.AddToUHC; import alisolarflare.uhc.idle.JoinUHC; import alisolarflare.uhc.intro.ConfigureMatch; @@ -23,6 +24,8 @@ public class UHCModule extends Module { match = new UHCMatch(plugin.getConfig(), MatchState.IDLE); } + + registerCommand(plugin, new SetMatchState(match)); registerCommand(plugin, new AddToUHC(match)); registerCommand(plugin, new JoinUHC(match)); registerCommand(plugin, new StartMatch(match)); diff --git a/src/alisolarflare/uhc/controller/SetMatchState.java b/src/alisolarflare/uhc/controller/SetMatchState.java new file mode 100644 index 0000000..f646b50 --- /dev/null +++ b/src/alisolarflare/uhc/controller/SetMatchState.java @@ -0,0 +1,76 @@ +package alisolarflare.uhc.controller; + +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import alisolarflare.uhc.memory.MatchState; +import alisolarflare.uhc.memory.UHCMatch; +import buttondevteam.lib.chat.TBMCCommandBase; + +public class SetMatchState extends TBMCCommandBase{ + + UHCMatch match; + public SetMatchState(UHCMatch match) { + this.match = match; + } + + @Override + public String[] GetHelpText(String alias) { + return null; + } + + @Override + public boolean OnCommand(CommandSender sender, String alias, String[] args) { + if (!(sender instanceof Player)){ + sender.sendMessage("You must be a player to use this command!"); + return false; + } + + Player player = (Player) sender; + + if (player.getName().equalsIgnoreCase("alisolarflare") && player.getName().equalsIgnoreCase("Arsen_Derby_FTW")){ + sender.sendMessage("You must be either Ali or Arsen to use this command!"); + return false; + } + + + if(args.length < 1 ){ + player.sendMessage("Usage: /setMatchState [stateToBeSet]"); + player.sendMessage("States: IDLE, WAITING, SETUP, INTRO, PEACE, POWER, TENSION, END"); + return false; + } + + String inputState = args[0]; + boolean inputIsValidState = false; + for (MatchState defaultMatchState : MatchState.values()){ + if(inputState.equalsIgnoreCase(defaultMatchState.toString())){ + inputIsValidState = true; + } + } + + if (inputIsValidState){ + match.setMatchState(MatchState.valueOf(inputState)); + player.sendMessage("Match State set to: " + match.getMatchState().toString() + "!"); + }else{ + player.sendMessage("Error, could not parse state."); + player.sendMessage("Valid States: IDLE, WAITING, SETUP, INTRO, PEACE, POWER, TENSION, END"); + return false; + } + + + return false; + } + + @Override + public boolean GetPlayerOnly() { + // TODO Auto-generated method stub + return true; + } + + @Override + public boolean GetModOnly() { + // TODO Auto-generated method stub + return false; + } + +}