Replaced hard-coded registerCommands with general registerCommand from

Module
This commit is contained in:
alisolarflare 2016-11-03 15:44:03 -04:00
parent ae01b1d250
commit 70b2e89e10
10 changed files with 30 additions and 37 deletions

View file

@ -3,6 +3,7 @@ package alisolarflare;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import buttondevteam.lib.TBMCCoreAPI;
import buttondevteam.lib.chat.TBMCChatAPI; import buttondevteam.lib.chat.TBMCChatAPI;
import buttondevteam.lib.chat.TBMCCommandBase; import buttondevteam.lib.chat.TBMCCommandBase;
@ -37,11 +38,11 @@ public abstract class Module{
* @param label Name of the command in plugin.yml * @param label Name of the command in plugin.yml
* @param commandExecutor Custom coded CommandExecutor class * @param commandExecutor Custom coded CommandExecutor class
*/ */
protected <T extends TBMCCommandBase> void registerCommand(JavaPlugin plugin, String label, Class<T> commandExecutor){ protected void registerCommand(JavaPlugin plugin, TBMCCommandBase commandBase){
TBMCChatAPI.AddCommands(plugin, commandExecutor); TBMCChatAPI.AddCommand(plugin, commandBase);
} }
protected Listener registerListener(JavaPlugin plugin, Listener listener){ protected Listener registerListener(JavaPlugin plugin, Listener listener){
plugin.getServer().getPluginManager().registerEvents(listener, plugin); TBMCCoreAPI.RegisterEventsForExceptions(listener, plugin);
return listener; return listener;
} }
} }

View file

@ -6,12 +6,11 @@ import alisolarflare.Module;
import alisolarflare.components.flairdoor.commands.FlairMe; import alisolarflare.components.flairdoor.commands.FlairMe;
import alisolarflare.components.flairdoor.listeners.PortalListener; import alisolarflare.components.flairdoor.listeners.PortalListener;
import buttondevteam.lib.TBMCCoreAPI; import buttondevteam.lib.TBMCCoreAPI;
import buttondevteam.lib.chat.TBMCChatAPI;
public class FlairDoorModule extends Module { public class FlairDoorModule extends Module {
@Override @Override
public void register(JavaPlugin plugin) { public void register(JavaPlugin plugin) {
TBMCChatAPI.AddCommands(plugin, FlairMe.class); registerCommand(plugin, new FlairMe());
TBMCCoreAPI.RegisterEventsForExceptions(new PortalListener(plugin), plugin); TBMCCoreAPI.RegisterEventsForExceptions(new PortalListener(plugin), plugin);
} }

View file

@ -6,13 +6,12 @@ import alisolarflare.Module;
import alisolarflare.components.gpowers.commands.gPowerCommand; import alisolarflare.components.gpowers.commands.gPowerCommand;
import alisolarflare.components.gpowers.listeners.gPowerListener; import alisolarflare.components.gpowers.listeners.gPowerListener;
import buttondevteam.lib.TBMCCoreAPI; import buttondevteam.lib.TBMCCoreAPI;
import buttondevteam.lib.chat.TBMCChatAPI;
public class GPowerModule extends Module { public class GPowerModule extends Module {
@Override @Override
public void register(JavaPlugin plugin) { public void register(JavaPlugin plugin) {
TBMCChatAPI.AddCommands(plugin, gPowerCommand.class); registerCommand(plugin, new gPowerCommand());
TBMCCoreAPI.RegisterEventsForExceptions(new gPowerListener(plugin), plugin); TBMCCoreAPI.RegisterEventsForExceptions(new gPowerListener(plugin), plugin);
} }

View file

@ -8,7 +8,6 @@ import alisolarflare.Module;
import alisolarflare.components.links.commands.PressAliLink; import alisolarflare.components.links.commands.PressAliLink;
import alisolarflare.components.links.commands.SetAliLink; import alisolarflare.components.links.commands.SetAliLink;
import alisolarflare.components.links.entities.Link; import alisolarflare.components.links.entities.Link;
import buttondevteam.lib.chat.TBMCChatAPI;
public class AliLinkModule extends Module { public class AliLinkModule extends Module {
private SetAliLink setAliLink; private SetAliLink setAliLink;
@ -16,8 +15,8 @@ public class AliLinkModule extends Module {
@Override @Override
public void register(JavaPlugin plugin) { public void register(JavaPlugin plugin) {
setAliLink = new SetAliLink(plugin); setAliLink = new SetAliLink(plugin);
TBMCChatAPI.AddCommands(plugin, PressAliLink.class); registerCommand(plugin, new PressAliLink(plugin, setAliLink));
TBMCChatAPI.AddCommands(plugin, SetAliLink.class); registerCommand(plugin, setAliLink);
} }

View file

@ -4,13 +4,12 @@ import org.bukkit.plugin.java.JavaPlugin;
import alisolarflare.Module; import alisolarflare.Module;
import alisolarflare.components.shulker.commands.AliShulker; import alisolarflare.components.shulker.commands.AliShulker;
import buttondevteam.lib.chat.TBMCChatAPI;
public class AliShulkerModule extends Module { public class AliShulkerModule extends Module {
@Override @Override
public void register(JavaPlugin plugin) { public void register(JavaPlugin plugin) {
TBMCChatAPI.AddCommands(plugin, AliShulker.class); registerCommand(plugin, new AliShulker());
} }
} }

View file

@ -4,10 +4,9 @@ import org.bukkit.plugin.java.JavaPlugin;
import alisolarflare.Module; import alisolarflare.Module;
import alisolarflare.events.uhc.commands.AddToUHC; import alisolarflare.events.uhc.commands.AddToUHC;
import alisolarflare.events.uhc.memory.MatchState;
import alisolarflare.events.uhc.commands.StartMatch; import alisolarflare.events.uhc.commands.StartMatch;
import alisolarflare.events.uhc.memory.MatchState;
import alisolarflare.events.uhc.memory.UHCMatch; import alisolarflare.events.uhc.memory.UHCMatch;
import buttondevteam.lib.chat.TBMCChatAPI;
public class UHCModule extends Module { public class UHCModule extends Module {
public UHCMatch match; public UHCMatch match;
@ -17,15 +16,6 @@ public class UHCModule extends Module {
registerCommands(plugin); registerCommands(plugin);
registerListeners(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) { private void registerMemoryUnits(JavaPlugin plugin) {
if (plugin.getConfig().contains("UHCMatchState")){ if (plugin.getConfig().contains("UHCMatchState")){
match = new UHCMatch(plugin.getConfig(), MatchState.valueOf(plugin.getConfig().getString("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); 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));
}
} }

View file

@ -2,7 +2,6 @@ package alisolarflare.events.uhc.commands;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import alisolarflare.events.uhc.memory.MatchState;
import alisolarflare.events.uhc.memory.UHCMatch; import alisolarflare.events.uhc.memory.UHCMatch;
import buttondevteam.lib.chat.TBMCCommandBase; import buttondevteam.lib.chat.TBMCCommandBase;

View file

@ -5,14 +5,13 @@ import org.bukkit.plugin.java.JavaPlugin;
import alisolarflare.Module; import alisolarflare.Module;
import alisolarflare.magic.aliarrow.AliArrowListener; import alisolarflare.magic.aliarrow.AliArrowListener;
import alisolarflare.magic.boombow.BoomBowListener; import alisolarflare.magic.boombow.BoomBowListener;
import buttondevteam.lib.TBMCCoreAPI;
public class MagicModule extends Module{ public class MagicModule extends Module{
@Override @Override
public void register(JavaPlugin plugin) { public void register(JavaPlugin plugin) {
TBMCCoreAPI.RegisterEventsForExceptions(new AliArrowListener(plugin), plugin); registerListener(plugin, new AliArrowListener(plugin));
TBMCCoreAPI.RegisterEventsForExceptions(new BoomBowListener(), plugin); registerListener(plugin, new BoomBowListener());
} }

View file

@ -5,7 +5,6 @@ import org.bukkit.plugin.java.JavaPlugin;
import alisolarflare.Module; import alisolarflare.Module;
import alisolarflare.minigames.freeforall.commands.SetFFAS; import alisolarflare.minigames.freeforall.commands.SetFFAS;
import alisolarflare.minigames.freeforall.data.SpawnSet; import alisolarflare.minigames.freeforall.data.SpawnSet;
import buttondevteam.lib.chat.TBMCChatAPI;
public class FreeForAllModule extends Module{ public class FreeForAllModule extends Module{
public SpawnSet spawnSet; public SpawnSet spawnSet;
@ -13,20 +12,21 @@ public class FreeForAllModule extends Module{
@Override @Override
public void register(JavaPlugin plugin) { public void register(JavaPlugin plugin) {
registerMemory();
registerEvents(); registerEvents();
registerCommands(plugin); registerCommands(plugin);
registerMemory(); }
private void registerMemory() {
this.spawnSet = new SpawnSet();
} }
private void registerEvents() { private void registerEvents() {
} }
private void registerCommands(JavaPlugin plugin) { private void registerCommands(JavaPlugin plugin) {
TBMCChatAPI.AddCommands(plugin, SetFFAS.class); registerCommand(plugin, new SetFFAS(spawnSet));
}
private void registerMemory() {
this.spawnSet = new SpawnSet();
} }
public int getGameState() {return GameState;} public int getGameState() {return GameState;}
public void setGameState(int gameState) {GameState = gameState;} public void setGameState(int gameState) {GameState = gameState;}

View file

@ -8,7 +8,6 @@ import alisolarflare.Module;
import alisolarflare.minigames.lobby.commands.ButtonFight; import alisolarflare.minigames.lobby.commands.ButtonFight;
import alisolarflare.minigames.lobby.commands.ButtonLeave; import alisolarflare.minigames.lobby.commands.ButtonLeave;
import alisolarflare.minigames.lobby.commands.ListFighters; import alisolarflare.minigames.lobby.commands.ListFighters;
import buttondevteam.lib.chat.TBMCChatAPI;
public class LobbyModule extends Module{ public class LobbyModule extends Module{
public List<String> fighters; public List<String> fighters;
@ -21,8 +20,8 @@ public class LobbyModule extends Module{
} }
private void registerCommands(JavaPlugin plugin) { private void registerCommands(JavaPlugin plugin) {
TBMCChatAPI.AddCommands(plugin, ButtonFight.class); registerCommand(plugin, new ButtonFight(this));
TBMCChatAPI.AddCommands(plugin, ButtonLeave.class); registerCommand(plugin, new ButtonLeave(this));
TBMCChatAPI.AddCommands(plugin, ListFighters.class); registerCommand(plugin, new ListFighters(this));
} }
} }