From 45b88354e59daa5377919e0f1d227f42ca8efaee Mon Sep 17 00:00:00 2001 From: alisolarflare Date: Sun, 6 Nov 2016 16:44:56 -0500 Subject: [PATCH 1/2] 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; + } + +} -- 2.30.2 From bbacdc3529485d4e1db7ba765b03ca0072aa9b33 Mon Sep 17 00:00:00 2001 From: alisolarflare Date: Sun, 6 Nov 2016 17:12:24 -0500 Subject: [PATCH 2/2] Tried to fix up powerup --- plugin.yml | 2 ++ .../components/flairdoor/FlairDoorModule.java | 1 - .../flairdoor/commands/FlairMe.java | 3 +- .../flairdoor/listeners/PortalListener.java | 29 +++++++------------ .../components/gpowers/GPowerMemory.java | 5 ++++ .../components/gpowers/commands/PowerUp.java | 1 + .../uhc/intro/IntroductionCutscene.java | 5 ++++ src/alisolarflare/uhc/memory/UHCMatch.java | 4 +++ 8 files changed, 29 insertions(+), 21 deletions(-) create mode 100644 src/alisolarflare/uhc/intro/IntroductionCutscene.java diff --git a/plugin.yml b/plugin.yml index bc68779..2bf7be2 100644 --- a/plugin.yml +++ b/plugin.yml @@ -29,6 +29,8 @@ commands: description: List all fighters currently in a button minigame setcolourspawn: description: sets the spawn points for each colour in a button minigame + setmatchstate: + description: sets the current state of the ultrahardcore game. addtouhc: description: Adds a player to the UltraHardcore match joinuhc: diff --git a/src/alisolarflare/components/flairdoor/FlairDoorModule.java b/src/alisolarflare/components/flairdoor/FlairDoorModule.java index c7e266a..1c5cddb 100644 --- a/src/alisolarflare/components/flairdoor/FlairDoorModule.java +++ b/src/alisolarflare/components/flairdoor/FlairDoorModule.java @@ -10,7 +10,6 @@ public class FlairDoorModule extends Module { @Override public void register(JavaPlugin plugin) { registerCommand(plugin, new FlairMe()); - registerListener(plugin, new PortalListener(plugin)); } } diff --git a/src/alisolarflare/components/flairdoor/commands/FlairMe.java b/src/alisolarflare/components/flairdoor/commands/FlairMe.java index 548fe9a..963da82 100644 --- a/src/alisolarflare/components/flairdoor/commands/FlairMe.java +++ b/src/alisolarflare/components/flairdoor/commands/FlairMe.java @@ -9,9 +9,8 @@ public class FlairMe extends TBMCCommandBase { @Override public boolean OnCommand(CommandSender sender, String label, String[] args) { - sender.sendMessage("Flairing..." + sender.getName()); PortalListener.playersToBeFlaired.add(sender.getName()); - sender.sendMessage("Finished Preparation! Walk through a portal to get your flair"); + sender.sendMessage("Setup Successful! Walk through a portal to get your flair"); return false; } diff --git a/src/alisolarflare/components/flairdoor/listeners/PortalListener.java b/src/alisolarflare/components/flairdoor/listeners/PortalListener.java index 82d186d..4ce684a 100644 --- a/src/alisolarflare/components/flairdoor/listeners/PortalListener.java +++ b/src/alisolarflare/components/flairdoor/listeners/PortalListener.java @@ -57,19 +57,15 @@ public class PortalListener implements Listener{ //RECOLOUR PLAYER if(HigherBlock.getType() == Material.STONE){ - player.sendMessage("STONE DETECTED"); recolourPlayer(player, DyeColor.GRAY); //TOP BLOCK IS WOOL? }else if(HigherBlock.getType() == Material.WOOL){ - player.sendMessage("WOOL DETECTED T"); Wool wool = (Wool) HigherBlock.getState().getData(); recolourPlayer(player, wool.getColor()); //MIDDLE BLOCK IS WOOL? }else if(MiddleBlock.getType() == Material.WOOL){ - - player.sendMessage("WOOL DETECTED M"); MaterialData mData = MiddleBlock.getState().getData(); Wool wool = (Wool) mData; @@ -77,7 +73,6 @@ public class PortalListener implements Listener{ //BOTTOM BLOCK IS WOOL? }else if (BottomBlock.getType() == Material.WOOL){ - player.sendMessage("WOOL DETECTED B"); Wool wool = (Wool) BottomBlock.getState().getData(); recolourPlayer(player, wool.getColor()); } @@ -86,60 +81,58 @@ public class PortalListener implements Listener{ public void recolourPlayer(Player player, DyeColor dyecolour){ User user = essentials.getUser(player); - player.sendMessage("Recolouring Player as..." + dyecolour.toString()); String name = user._getNickname(); - player.sendMessage("name:" + name); String tempName = ""; for(int i = 0; i < name.length(); i++){ - player.sendMessage("|"+name.charAt(i)+"|"); if (name.charAt(i) != '§'){ - tempName += name.charAt(i); }else{ i++; } } name = tempName; - player.sendMessage("Adjusted Name: " + name); switch(dyecolour){ case GRAY: - player.sendMessage("Adding GRAY"); + player.sendMessage("Adding §7GRAY!§f"); name = "§7" + name; break; case RED: - player.sendMessage("Adding RED"); + player.sendMessage("Adding §4RED!§f"); name = "§4" + name; break; case ORANGE: - player.sendMessage("Adding ORANGE"); + player.sendMessage("Adding §6ORANGE!§f"); name = "§6" + name; break; case YELLOW: - player.sendMessage("Adding YELLOW"); + player.sendMessage("Adding §eYELLOW!§f"); name = "§e" + name; break; case LIME: case GREEN: - player.sendMessage("Adding GREEN"); + player.sendMessage("Adding §aGREEN!§f"); name = "§a" + name; break; case CYAN: case LIGHT_BLUE: case BLUE: - player.sendMessage("Adding BLUE"); + player.sendMessage("Adding §9BLUE!§f"); name = "§9" + name; break; case PURPLE: - player.sendMessage("Adding PURPLE"); + player.sendMessage("Adding §5PURPLE!§f"); name = "§5" + name; break; + case WHITE: + player.sendMessage("Adding §fWHITE!§f"); + name = "§f" + name; default: player.sendMessage("ERROR, PORTAL HAS INVALID UNDER-BLOCK"); break; } user.setNickname(name); - player.sendMessage("Your name is now: " + user.getNickname() +"! Removing you from playersToBeFlaired..."); + player.sendMessage("Your name is now: " + user.getNickname() +"!"); playersToBeFlaired.remove(player.getName()); } } diff --git a/src/alisolarflare/components/gpowers/GPowerMemory.java b/src/alisolarflare/components/gpowers/GPowerMemory.java index 0dda7b9..44e0089 100644 --- a/src/alisolarflare/components/gpowers/GPowerMemory.java +++ b/src/alisolarflare/components/gpowers/GPowerMemory.java @@ -13,17 +13,22 @@ public class GPowerMemory{ poweredPlayerList.put(player.getUniqueId(), new poweredPlayer(player.getUniqueId(), colour, true)); } public void PowerUpPlayer(Player player){ + player.sendMessage("Powering up!"); if(poweredPlayerList.containsKey(player.getUniqueId())){ poweredPlayerList.get(player.getUniqueId()).isPowersActive = true; + player.sendMessage("Powered up!"); }else{ player.sendMessage("You must instantiate your power settings using /GPower"); } } public void PowerDownPlayer(Player player){ + player.sendMessage("Powering down!"); if (poweredPlayerList.containsKey(player.getUniqueId())){ + player.sendMessage("Powered down!"); poweredPlayerList.get(player.getUniqueId()).isPowersActive = false; }else{ + player.sendMessage("P down!"); return; } diff --git a/src/alisolarflare/components/gpowers/commands/PowerUp.java b/src/alisolarflare/components/gpowers/commands/PowerUp.java index 2e50db8..84670f3 100644 --- a/src/alisolarflare/components/gpowers/commands/PowerUp.java +++ b/src/alisolarflare/components/gpowers/commands/PowerUp.java @@ -18,6 +18,7 @@ public class PowerUp extends TBMCCommandBase { public boolean OnCommand(CommandSender sender, String label, String[] args) { if (!(sender instanceof Player)) sender.sendMessage("You must be a player to use this command! Contact a dev/ali if you think this is wrong"); + Player player = (Player) sender; gPowerMemory.PowerUpPlayer(player); return false; diff --git a/src/alisolarflare/uhc/intro/IntroductionCutscene.java b/src/alisolarflare/uhc/intro/IntroductionCutscene.java new file mode 100644 index 0000000..6ff7ce5 --- /dev/null +++ b/src/alisolarflare/uhc/intro/IntroductionCutscene.java @@ -0,0 +1,5 @@ +package alisolarflare.uhc.intro; + +public class IntroductionCutscene { + //TODO: Teleport all players to the area. +} diff --git a/src/alisolarflare/uhc/memory/UHCMatch.java b/src/alisolarflare/uhc/memory/UHCMatch.java index 42b0484..4c4049a 100644 --- a/src/alisolarflare/uhc/memory/UHCMatch.java +++ b/src/alisolarflare/uhc/memory/UHCMatch.java @@ -23,6 +23,10 @@ public class UHCMatch { public void setMatchState(MatchState newMS){ matchState = newMS; fileConfiguration.set("UHCMatchState", newMS.toString()); + switch(newMS){ + default: + break; + } } } -- 2.30.2