From 70b2e89e10dfd1d6c389cbe61ea36d5f05277249 Mon Sep 17 00:00:00 2001 From: alisolarflare Date: Thu, 3 Nov 2016 15:44:03 -0400 Subject: [PATCH] Replaced hard-coded registerCommands with general registerCommand from Module --- src/alisolarflare/Module.java | 7 ++++--- .../components/flairdoor/FlairDoorModule.java | 3 +-- .../components/gpowers/GPowerModule.java | 3 +-- .../components/links/AliLinkModule.java | 5 ++--- .../components/shulker/AliShulkerModule.java | 3 +-- src/alisolarflare/events/uhc/UHCModule.java | 21 +++++++++---------- .../events/uhc/commands/StartMatch.java | 1 - src/alisolarflare/magic/MagicModule.java | 5 ++--- .../freeforall/FreeForAllModule.java | 12 +++++------ .../minigames/lobby/LobbyModule.java | 7 +++---- 10 files changed, 30 insertions(+), 37 deletions(-) diff --git a/src/alisolarflare/Module.java b/src/alisolarflare/Module.java index 986bb00..ad674d1 100644 --- a/src/alisolarflare/Module.java +++ b/src/alisolarflare/Module.java @@ -3,6 +3,7 @@ package alisolarflare; import org.bukkit.event.Listener; import org.bukkit.plugin.java.JavaPlugin; +import buttondevteam.lib.TBMCCoreAPI; import buttondevteam.lib.chat.TBMCChatAPI; import buttondevteam.lib.chat.TBMCCommandBase; @@ -37,11 +38,11 @@ public abstract class Module{ * @param label Name of the command in plugin.yml * @param commandExecutor Custom coded CommandExecutor class */ - protected void registerCommand(JavaPlugin plugin, String label, Class commandExecutor){ - TBMCChatAPI.AddCommands(plugin, commandExecutor); + protected void registerCommand(JavaPlugin plugin, TBMCCommandBase commandBase){ + TBMCChatAPI.AddCommand(plugin, commandBase); } protected Listener registerListener(JavaPlugin plugin, Listener listener){ - plugin.getServer().getPluginManager().registerEvents(listener, plugin); + TBMCCoreAPI.RegisterEventsForExceptions(listener, plugin); return listener; } } diff --git a/src/alisolarflare/components/flairdoor/FlairDoorModule.java b/src/alisolarflare/components/flairdoor/FlairDoorModule.java index 981abdd..0368634 100644 --- a/src/alisolarflare/components/flairdoor/FlairDoorModule.java +++ b/src/alisolarflare/components/flairdoor/FlairDoorModule.java @@ -6,12 +6,11 @@ import alisolarflare.Module; import alisolarflare.components.flairdoor.commands.FlairMe; import alisolarflare.components.flairdoor.listeners.PortalListener; import buttondevteam.lib.TBMCCoreAPI; -import buttondevteam.lib.chat.TBMCChatAPI; public class FlairDoorModule extends Module { @Override public void register(JavaPlugin plugin) { - TBMCChatAPI.AddCommands(plugin, FlairMe.class); + registerCommand(plugin, new FlairMe()); TBMCCoreAPI.RegisterEventsForExceptions(new PortalListener(plugin), plugin); } diff --git a/src/alisolarflare/components/gpowers/GPowerModule.java b/src/alisolarflare/components/gpowers/GPowerModule.java index a73e81e..8eb4287 100644 --- a/src/alisolarflare/components/gpowers/GPowerModule.java +++ b/src/alisolarflare/components/gpowers/GPowerModule.java @@ -6,13 +6,12 @@ import alisolarflare.Module; import alisolarflare.components.gpowers.commands.gPowerCommand; import alisolarflare.components.gpowers.listeners.gPowerListener; import buttondevteam.lib.TBMCCoreAPI; -import buttondevteam.lib.chat.TBMCChatAPI; public class GPowerModule extends Module { @Override public void register(JavaPlugin plugin) { - TBMCChatAPI.AddCommands(plugin, gPowerCommand.class); + registerCommand(plugin, new gPowerCommand()); TBMCCoreAPI.RegisterEventsForExceptions(new gPowerListener(plugin), plugin); } diff --git a/src/alisolarflare/components/links/AliLinkModule.java b/src/alisolarflare/components/links/AliLinkModule.java index c076791..1ef6c46 100644 --- a/src/alisolarflare/components/links/AliLinkModule.java +++ b/src/alisolarflare/components/links/AliLinkModule.java @@ -8,7 +8,6 @@ import alisolarflare.Module; import alisolarflare.components.links.commands.PressAliLink; import alisolarflare.components.links.commands.SetAliLink; import alisolarflare.components.links.entities.Link; -import buttondevteam.lib.chat.TBMCChatAPI; public class AliLinkModule extends Module { private SetAliLink setAliLink; @@ -16,8 +15,8 @@ public class AliLinkModule extends Module { @Override public void register(JavaPlugin plugin) { setAliLink = new SetAliLink(plugin); - TBMCChatAPI.AddCommands(plugin, PressAliLink.class); - TBMCChatAPI.AddCommands(plugin, SetAliLink.class); + registerCommand(plugin, new PressAliLink(plugin, setAliLink)); + registerCommand(plugin, setAliLink); } diff --git a/src/alisolarflare/components/shulker/AliShulkerModule.java b/src/alisolarflare/components/shulker/AliShulkerModule.java index ffccad4..7cfaac3 100644 --- a/src/alisolarflare/components/shulker/AliShulkerModule.java +++ b/src/alisolarflare/components/shulker/AliShulkerModule.java @@ -4,13 +4,12 @@ import org.bukkit.plugin.java.JavaPlugin; import alisolarflare.Module; import alisolarflare.components.shulker.commands.AliShulker; -import buttondevteam.lib.chat.TBMCChatAPI; public class AliShulkerModule extends Module { @Override public void register(JavaPlugin plugin) { - TBMCChatAPI.AddCommands(plugin, AliShulker.class); + registerCommand(plugin, new AliShulker()); } } diff --git a/src/alisolarflare/events/uhc/UHCModule.java b/src/alisolarflare/events/uhc/UHCModule.java index 98881b4..ddb9bdb 100644 --- a/src/alisolarflare/events/uhc/UHCModule.java +++ b/src/alisolarflare/events/uhc/UHCModule.java @@ -4,10 +4,9 @@ import org.bukkit.plugin.java.JavaPlugin; import alisolarflare.Module; import alisolarflare.events.uhc.commands.AddToUHC; -import alisolarflare.events.uhc.memory.MatchState; import alisolarflare.events.uhc.commands.StartMatch; +import alisolarflare.events.uhc.memory.MatchState; import alisolarflare.events.uhc.memory.UHCMatch; -import buttondevteam.lib.chat.TBMCChatAPI; public class UHCModule extends Module { public UHCMatch match; @@ -17,15 +16,6 @@ public class UHCModule extends Module { registerCommands(plugin); registerListeners(plugin); } - - private void registerListeners(JavaPlugin plugin) { - } - - private void registerCommands(JavaPlugin plugin) { - TBMCChatAPI.AddCommand(plugin, AddToUHC.class, match); - TBMCChatAPI.AddCommand(plugin, new StartMatch(match)); - } - private void registerMemoryUnits(JavaPlugin plugin) { if (plugin.getConfig().contains("UHCMatchState")){ match = new UHCMatch(plugin.getConfig(), MatchState.valueOf(plugin.getConfig().getString("UHCMatchState"))); @@ -33,4 +23,13 @@ public class UHCModule extends Module { match = new UHCMatch(plugin.getConfig(), MatchState.IDLE); } } + private void registerListeners(JavaPlugin plugin) { + } + + private void registerCommands(JavaPlugin plugin) { + registerCommand(plugin, new AddToUHC(match)); + registerCommand(plugin, new StartMatch(match)); + } + + } diff --git a/src/alisolarflare/events/uhc/commands/StartMatch.java b/src/alisolarflare/events/uhc/commands/StartMatch.java index bee51bb..29f8a54 100644 --- a/src/alisolarflare/events/uhc/commands/StartMatch.java +++ b/src/alisolarflare/events/uhc/commands/StartMatch.java @@ -2,7 +2,6 @@ package alisolarflare.events.uhc.commands; import org.bukkit.command.CommandSender; -import alisolarflare.events.uhc.memory.MatchState; import alisolarflare.events.uhc.memory.UHCMatch; import buttondevteam.lib.chat.TBMCCommandBase; diff --git a/src/alisolarflare/magic/MagicModule.java b/src/alisolarflare/magic/MagicModule.java index 96ff14f..4da9fc3 100644 --- a/src/alisolarflare/magic/MagicModule.java +++ b/src/alisolarflare/magic/MagicModule.java @@ -5,14 +5,13 @@ import org.bukkit.plugin.java.JavaPlugin; import alisolarflare.Module; import alisolarflare.magic.aliarrow.AliArrowListener; import alisolarflare.magic.boombow.BoomBowListener; -import buttondevteam.lib.TBMCCoreAPI; public class MagicModule extends Module{ @Override public void register(JavaPlugin plugin) { - TBMCCoreAPI.RegisterEventsForExceptions(new AliArrowListener(plugin), plugin); - TBMCCoreAPI.RegisterEventsForExceptions(new BoomBowListener(), plugin); + registerListener(plugin, new AliArrowListener(plugin)); + registerListener(plugin, new BoomBowListener()); } diff --git a/src/alisolarflare/minigames/freeforall/FreeForAllModule.java b/src/alisolarflare/minigames/freeforall/FreeForAllModule.java index 5f6dd13..181562f 100644 --- a/src/alisolarflare/minigames/freeforall/FreeForAllModule.java +++ b/src/alisolarflare/minigames/freeforall/FreeForAllModule.java @@ -5,7 +5,6 @@ import org.bukkit.plugin.java.JavaPlugin; import alisolarflare.Module; import alisolarflare.minigames.freeforall.commands.SetFFAS; import alisolarflare.minigames.freeforall.data.SpawnSet; -import buttondevteam.lib.chat.TBMCChatAPI; public class FreeForAllModule extends Module{ public SpawnSet spawnSet; @@ -13,20 +12,21 @@ public class FreeForAllModule extends Module{ @Override public void register(JavaPlugin plugin) { + registerMemory(); registerEvents(); registerCommands(plugin); - registerMemory(); + } + private void registerMemory() { + this.spawnSet = new SpawnSet(); } private void registerEvents() { } private void registerCommands(JavaPlugin plugin) { - TBMCChatAPI.AddCommands(plugin, SetFFAS.class); - } - private void registerMemory() { - this.spawnSet = new SpawnSet(); + registerCommand(plugin, new SetFFAS(spawnSet)); } + public int getGameState() {return GameState;} public void setGameState(int gameState) {GameState = gameState;} diff --git a/src/alisolarflare/minigames/lobby/LobbyModule.java b/src/alisolarflare/minigames/lobby/LobbyModule.java index 86227cd..640b91a 100644 --- a/src/alisolarflare/minigames/lobby/LobbyModule.java +++ b/src/alisolarflare/minigames/lobby/LobbyModule.java @@ -8,7 +8,6 @@ import alisolarflare.Module; import alisolarflare.minigames.lobby.commands.ButtonFight; import alisolarflare.minigames.lobby.commands.ButtonLeave; import alisolarflare.minigames.lobby.commands.ListFighters; -import buttondevteam.lib.chat.TBMCChatAPI; public class LobbyModule extends Module{ public List fighters; @@ -21,8 +20,8 @@ public class LobbyModule extends Module{ } private void registerCommands(JavaPlugin plugin) { - TBMCChatAPI.AddCommands(plugin, ButtonFight.class); - TBMCChatAPI.AddCommands(plugin, ButtonLeave.class); - TBMCChatAPI.AddCommands(plugin, ListFighters.class); + registerCommand(plugin, new ButtonFight(this)); + registerCommand(plugin, new ButtonLeave(this)); + registerCommand(plugin, new ListFighters(this)); } }