From 39e1f134a6999355fb7854320e56348ad89ea21b Mon Sep 17 00:00:00 2001 From: Steffion Date: Sat, 3 Aug 2013 14:23:22 +0200 Subject: [PATCH] Added join command. --- .../Steffion/BlockHunt/Commands/CMDjoin.java | 66 +++++++++++++++++++ .../Steffion/BlockHunt/Managers/CommandC.java | 8 +++ .../Steffion/BlockHunt/Managers/ConfigC.java | 13 ++-- .../Steffion/BlockHunt/Managers/PlayerM.java | 3 +- 4 files changed, 85 insertions(+), 5 deletions(-) create mode 100644 src/nl/Steffion/BlockHunt/Commands/CMDjoin.java diff --git a/src/nl/Steffion/BlockHunt/Commands/CMDjoin.java b/src/nl/Steffion/BlockHunt/Commands/CMDjoin.java new file mode 100644 index 0000000..5489d95 --- /dev/null +++ b/src/nl/Steffion/BlockHunt/Commands/CMDjoin.java @@ -0,0 +1,66 @@ +package nl.Steffion.BlockHunt.Commands; + +import nl.Steffion.BlockHunt.Arena; +import nl.Steffion.BlockHunt.ArenaHandler; +import nl.Steffion.BlockHunt.W; +import nl.Steffion.BlockHunt.Managers.CommandC; +import nl.Steffion.BlockHunt.Managers.ConfigC; +import nl.Steffion.BlockHunt.Managers.MessageM; +import nl.Steffion.BlockHunt.Managers.PlayerM; +import nl.Steffion.BlockHunt.Managers.PlayerM.PermsC; + +import org.bukkit.command.Command; +import org.bukkit.entity.Player; + +public class CMDjoin extends DefaultCMD { + + @Override + public boolean exectue(Player player, Command cmd, String label, + String[] args) { + if (PlayerM.hasPerm(player, PermsC.join, true)) { + if (player != null) { + if (args.length <= 1) { + MessageM.sendFMessage(player, + ConfigC.error_notEnoughArguments, true, "syntax-" + + CommandC.JOIN.usage); + } else { + boolean found = false; + boolean alreadyJoined = false; + for (Arena arena : W.arenaList) { + if (arena.playersInArena != null) { + if (arena.playersInArena.contains(player)) { + alreadyJoined = true; + } + } + } + + if (!alreadyJoined) { + for (Arena arena : W.arenaList) { + if (arena.arenaName.equalsIgnoreCase(args[1])) { + found = true; + arena.playersInArena.add(player); + ArenaHandler.sendFMessage(arena, + ConfigC.normal_joinJoinedArena, true, + "playername-" + player.getName(), "1-" + + arena.playersInArena.size(), + "2-" + arena.maxPlayers); + } + } + } else { + MessageM.sendFMessage(player, + ConfigC.error_joinAlreadyJoined, true); + return true; + } + + if (!found) { + MessageM.sendFMessage(player, ConfigC.error_noArena, + true, "name-" + args[1]); + } + } + } else { + MessageM.sendFMessage(player, ConfigC.error_onlyIngame, true); + } + } + return true; + } +} diff --git a/src/nl/Steffion/BlockHunt/Managers/CommandC.java b/src/nl/Steffion/BlockHunt/Managers/CommandC.java index c2b22dd..005a044 100644 --- a/src/nl/Steffion/BlockHunt/Managers/CommandC.java +++ b/src/nl/Steffion/BlockHunt/Managers/CommandC.java @@ -42,6 +42,14 @@ public enum CommandC { ConfigC.help_reload, 1, W.pluginName + " "), + JOIN ("BlockHunt%join_", + "BlockHunt%j_", + new CMDjoin(), + ConfigC.commandEnabled_join, + PermsC.join, + ConfigC.help_join, + 1, + W.pluginName + " "), WAND ("BlockHunt%wand_", "BlockHunt%w_", new CMDwand(), diff --git a/src/nl/Steffion/BlockHunt/Managers/ConfigC.java b/src/nl/Steffion/BlockHunt/Managers/ConfigC.java index de22dfb..11ebce2 100644 --- a/src/nl/Steffion/BlockHunt/Managers/ConfigC.java +++ b/src/nl/Steffion/BlockHunt/Managers/ConfigC.java @@ -18,6 +18,7 @@ public enum ConfigC { commandEnabled_info (true, W.config), commandEnabled_help (true, W.config), commandEnabled_reload (true, W.config), + commandEnabled_join (true, W.config), commandEnabled_wand (true, W.config), commandEnabled_create (true, W.config), commandEnabled_set (true, W.config), @@ -39,6 +40,7 @@ public enum ConfigC { help_info ("%NDisplays the plugin's info.", W.messages), help_help ("%NShows a list of commands.", W.messages), help_reload ("%NReloads all configs.", W.messages), + help_join ("%NJoins a " + W.pluginName + " game.", W.messages), help_wand ("%NGives you the wand selection tool.", W.messages), help_create ("%NCreates an arena from your selection.", W.messages), help_set ("%NOpens a panel to set settings.", W.messages), @@ -50,6 +52,8 @@ public enum ConfigC { button_remove2 ("Remove", W.messages), normal_reloadedConfigs ("&aReloaded all configs!", W.messages), + normal_joinJoinedArena ("%A%playername%%N joined your arena. (%A%1%%N/%A%2%%N)", + W.messages), normal_wandGaveWand ("%NHere you go ;)! &o(Use the %A&o%type%%N&o!)", W.messages), normal_wandSetPosition ("%NSet position %A#%number%%N to location: %pos%.", @@ -66,18 +70,19 @@ public enum ConfigC { W.messages), error_noArena ("%ENo arena found with the name '%A%name%%E'.", W.messages), error_onlyIngame ("%EThis is an only in-game command!", W.messages), + error_joinAlreadyJoined ("%EYou've already joined an arena!", W.messages), error_createSelectionFirst ("%EMake a selection first. Use the wand command: %A/" + W.pluginName + " %E.", W.messages), error_createNotSameWorld ("%EMake your selection points in the same world!", W.messages), - error_tooHighNumber ("%EThat amount is too high! Max amount is: %A%max%%E.", + error_setTooHighNumber ("%EThat amount is too high! Max amount is: %A%max%%E.", W.messages), - error_tooLowNumber ("%EThat amount is too low! Minimal amount is: %A%min%%E.", + error_setTooLowNumber ("%EThat amount is too low! Minimal amount is: %A%min%%E.", W.messages); - Object value; - ConfigM config; + public Object value; + public ConfigM config; private ConfigC (Object value, ConfigM config) { this.value = value; diff --git a/src/nl/Steffion/BlockHunt/Managers/PlayerM.java b/src/nl/Steffion/BlockHunt/Managers/PlayerM.java index cbb1c4e..461725c 100644 --- a/src/nl/Steffion/BlockHunt/Managers/PlayerM.java +++ b/src/nl/Steffion/BlockHunt/Managers/PlayerM.java @@ -20,7 +20,8 @@ public class PlayerM { help (main + "help", PType.ALL), reload (main + "reload", PType.MODERATOR), create (main + "create", PType.ADMIN), - set (main + "set", PType.MODERATOR); + set (main + "set", PType.MODERATOR), + join (main + "join", PType.PLAYER); public String perm; public PType type;