From 254a0cdf105bbf1e398532b79b93831d90e16cf4 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Thu, 3 Nov 2016 17:38:20 +0100 Subject: [PATCH 1/2] Fixed command adding --- .../components/links/AliLinkModule.java | 3 +- .../components/shulker/AliShulkerModule.java | 2 +- src/alisolarflare/events/uhc/UHCModule.java | 4 +- src/alisolarflare/magic/MagicModule.java | 3 -- .../freeforall/FreeForAllModule.java | 2 +- .../minigames/lobby/LobbyModule.java | 7 ++-- .../minigames/lobby/commands/ButtonFight.java | 41 +++++++++++-------- .../minigames/lobby/commands/ButtonLeave.java | 37 ++++++++++------- .../lobby/commands/ListFighters.java | 29 ++++++++++--- 9 files changed, 82 insertions(+), 46 deletions(-) diff --git a/src/alisolarflare/components/links/AliLinkModule.java b/src/alisolarflare/components/links/AliLinkModule.java index 5760d93..73b39de 100644 --- a/src/alisolarflare/components/links/AliLinkModule.java +++ b/src/alisolarflare/components/links/AliLinkModule.java @@ -16,7 +16,8 @@ public class AliLinkModule extends Module { @Override public void register(JavaPlugin plugin) { setAliLink = new SetAliLink(plugin); - TBMCChatAPI.AddCommands(plugin, PressAliLink.class); + TBMCChatAPI.AddCommand(plugin, new PressAliLink(plugin, setAliLink)); + TBMCChatAPI.AddCommand(plugin, setAliLink); } diff --git a/src/alisolarflare/components/shulker/AliShulkerModule.java b/src/alisolarflare/components/shulker/AliShulkerModule.java index ffccad4..1ba2fbc 100644 --- a/src/alisolarflare/components/shulker/AliShulkerModule.java +++ b/src/alisolarflare/components/shulker/AliShulkerModule.java @@ -10,7 +10,7 @@ public class AliShulkerModule extends Module { @Override public void register(JavaPlugin plugin) { - TBMCChatAPI.AddCommands(plugin, AliShulker.class); + TBMCChatAPI.AddCommand(plugin, AliShulker.class); } } diff --git a/src/alisolarflare/events/uhc/UHCModule.java b/src/alisolarflare/events/uhc/UHCModule.java index 4e27b57..0b0dd41 100644 --- a/src/alisolarflare/events/uhc/UHCModule.java +++ b/src/alisolarflare/events/uhc/UHCModule.java @@ -4,6 +4,7 @@ import org.bukkit.plugin.java.JavaPlugin; import alisolarflare.Module; import alisolarflare.events.uhc.commands.AddToUHC; +import alisolarflare.events.uhc.commands.StartMatch; import alisolarflare.events.uhc.memory.UHCMatch; import buttondevteam.lib.chat.TBMCChatAPI; @@ -20,7 +21,8 @@ public class UHCModule extends Module { } private void registerCommands(JavaPlugin plugin) { - TBMCChatAPI.AddCommands(plugin, AddToUHC.class); + TBMCChatAPI.AddCommand(plugin, AddToUHC.class, match); + TBMCChatAPI.AddCommand(plugin, new StartMatch(match)); } private void registerMemoryUnits(JavaPlugin plugin) { diff --git a/src/alisolarflare/magic/MagicModule.java b/src/alisolarflare/magic/MagicModule.java index 628bef8..96ff14f 100644 --- a/src/alisolarflare/magic/MagicModule.java +++ b/src/alisolarflare/magic/MagicModule.java @@ -3,11 +3,9 @@ package alisolarflare.magic; import org.bukkit.plugin.java.JavaPlugin; import alisolarflare.Module; -import alisolarflare.events.uhc.commands.AddToUHC; import alisolarflare.magic.aliarrow.AliArrowListener; import alisolarflare.magic.boombow.BoomBowListener; import buttondevteam.lib.TBMCCoreAPI; -import buttondevteam.lib.chat.TBMCChatAPI; public class MagicModule extends Module{ @@ -15,7 +13,6 @@ public class MagicModule extends Module{ public void register(JavaPlugin plugin) { TBMCCoreAPI.RegisterEventsForExceptions(new AliArrowListener(plugin), plugin); TBMCCoreAPI.RegisterEventsForExceptions(new BoomBowListener(), plugin); - TBMCChatAPI.AddCommands(plugin, AddToUHC.class); } diff --git a/src/alisolarflare/minigames/freeforall/FreeForAllModule.java b/src/alisolarflare/minigames/freeforall/FreeForAllModule.java index 070ccf9..78828e5 100644 --- a/src/alisolarflare/minigames/freeforall/FreeForAllModule.java +++ b/src/alisolarflare/minigames/freeforall/FreeForAllModule.java @@ -22,7 +22,7 @@ public class FreeForAllModule extends Module{ } private void registerCommands(JavaPlugin plugin) { - TBMCChatAPI.AddCommands(plugin, SetFFAS.class); + TBMCChatAPI.AddCommand(plugin, SetFFAS.class, spawnSet); } private void registerMemory() { this.spawnSet = new SpawnSet(); diff --git a/src/alisolarflare/minigames/lobby/LobbyModule.java b/src/alisolarflare/minigames/lobby/LobbyModule.java index 27416bf..2793307 100644 --- a/src/alisolarflare/minigames/lobby/LobbyModule.java +++ b/src/alisolarflare/minigames/lobby/LobbyModule.java @@ -8,6 +8,7 @@ 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; @@ -20,8 +21,8 @@ public class LobbyModule extends Module{ } private void registerCommands(JavaPlugin plugin) { - plugin.getCommand("buttonfight").setExecutor(new ButtonFight(this)); - plugin.getCommand("buttonleave").setExecutor(new ButtonLeave(this)); - plugin.getCommand("listfighters").setExecutor(new ListFighters(this)); + TBMCChatAPI.AddCommand(plugin, new ButtonFight(this)); + TBMCChatAPI.AddCommand(plugin, new ButtonLeave(this)); + TBMCChatAPI.AddCommand(plugin, new ListFighters(this)); } } diff --git a/src/alisolarflare/minigames/lobby/commands/ButtonFight.java b/src/alisolarflare/minigames/lobby/commands/ButtonFight.java index 373af3e..25fdb44 100644 --- a/src/alisolarflare/minigames/lobby/commands/ButtonFight.java +++ b/src/alisolarflare/minigames/lobby/commands/ButtonFight.java @@ -1,13 +1,12 @@ package alisolarflare.minigames.lobby.commands; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import alisolarflare.minigames.lobby.LobbyModule; +import buttondevteam.lib.chat.TBMCCommandBase; -public class ButtonFight implements CommandExecutor{ +public class ButtonFight extends TBMCCommandBase { private LobbyModule lobby; public ButtonFight(LobbyModule lobby) { @@ -15,28 +14,38 @@ public class ButtonFight implements CommandExecutor{ } @Override - public boolean onCommand(CommandSender sender, Command arg1, String arg2, String[] arg3) { - - if(!(sender instanceof Player)){ - sender.sendMessage("You must be a player to be using this command!"); - return false; - } - + public boolean OnCommand(CommandSender sender, String arg2, String[] arg3) { Player player = (Player) sender; player.sendMessage(player.toString()); String name = player.getName(); - if(lobby.fighters.contains(name)){ + if (lobby.fighters.contains(name)) { player.sendMessage("You are already in the button fight!"); return false; } - + lobby.fighters.add(name); - - if(lobby.fighters.contains(name)){ + + if (lobby.fighters.contains(name)) { player.sendMessage("You have joined the fighters category!"); - } + } return false; } - + + @Override + public String[] GetHelpText(String alias) { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean GetPlayerOnly() { + return true; + } + + @Override + public boolean GetModOnly() { + return false; + } + } diff --git a/src/alisolarflare/minigames/lobby/commands/ButtonLeave.java b/src/alisolarflare/minigames/lobby/commands/ButtonLeave.java index 5ff3f59..2882075 100644 --- a/src/alisolarflare/minigames/lobby/commands/ButtonLeave.java +++ b/src/alisolarflare/minigames/lobby/commands/ButtonLeave.java @@ -1,15 +1,13 @@ package alisolarflare.minigames.lobby.commands; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import alisolarflare.minigames.lobby.LobbyModule; +import buttondevteam.lib.chat.TBMCCommandBase; + +public class ButtonLeave extends TBMCCommandBase { -public class ButtonLeave implements CommandExecutor{ - - private LobbyModule lobby; public ButtonLeave(LobbyModule lobby) { @@ -17,23 +15,34 @@ public class ButtonLeave implements CommandExecutor{ } @Override - public boolean onCommand(CommandSender sender, Command arg1, String arg2, String[] arg3) { - if(!(sender instanceof Player)){ - sender.sendMessage("You must be a player to be using this command!"); - return false; - } - + public boolean OnCommand(CommandSender sender, String arg2, String[] arg3) { Player player = (Player) sender; String name = player.getName(); - if (!(lobby.fighters.contains(name))){ + if (!(lobby.fighters.contains(name))) { player.sendMessage("You are not fighting!"); return false; } lobby.fighters.remove(name); - if(!(lobby.fighters.contains(name))){ + if (!(lobby.fighters.contains(name))) { player.sendMessage("You have left the fighters category!"); } return false; } - + + @Override + public String[] GetHelpText(String alias) { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean GetPlayerOnly() { + return true; + } + + @Override + public boolean GetModOnly() { + return false; + } + } diff --git a/src/alisolarflare/minigames/lobby/commands/ListFighters.java b/src/alisolarflare/minigames/lobby/commands/ListFighters.java index 3931d13..8024727 100644 --- a/src/alisolarflare/minigames/lobby/commands/ListFighters.java +++ b/src/alisolarflare/minigames/lobby/commands/ListFighters.java @@ -1,12 +1,13 @@ package alisolarflare.minigames.lobby.commands; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; +import java.util.stream.Collectors; + import org.bukkit.command.CommandSender; import alisolarflare.minigames.lobby.LobbyModule; +import buttondevteam.lib.chat.TBMCCommandBase; -public class ListFighters implements CommandExecutor{ +public class ListFighters extends TBMCCommandBase { private LobbyModule lobby; public ListFighters(LobbyModule lobby) { @@ -14,9 +15,25 @@ public class ListFighters implements CommandExecutor{ } @Override - public boolean onCommand(CommandSender sender, Command arg1, String arg2, String[] arg3) { - sender.sendMessage(lobby.fighters.toString()); + public boolean OnCommand(CommandSender sender, String arg2, String[] arg3) { + sender.sendMessage(lobby.fighters.stream().map(Object::toString).collect(Collectors.joining(", "))); return false; } - + + @Override + public String[] GetHelpText(String alias) { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean GetPlayerOnly() { + return false; + } + + @Override + public boolean GetModOnly() { + return false; + } + } From f24d9ad9ac03482594311cb5a471c2d15545ad30 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Thu, 3 Nov 2016 18:05:40 +0100 Subject: [PATCH 2/2] Fixed NPE --- src/alisolarflare/events/uhc/UHCModule.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/alisolarflare/events/uhc/UHCModule.java b/src/alisolarflare/events/uhc/UHCModule.java index 0b0dd41..7d3b750 100644 --- a/src/alisolarflare/events/uhc/UHCModule.java +++ b/src/alisolarflare/events/uhc/UHCModule.java @@ -12,9 +12,9 @@ public class UHCModule extends Module { public UHCMatch match; public void register(JavaPlugin plugin) { + registerMemoryUnits(plugin); registerCommands(plugin); registerListeners(plugin); - registerMemoryUnits(plugin); } private void registerListeners(JavaPlugin plugin) {