From cd68ccf261e9753fa7225bf6df11edd7423dcbc5 Mon Sep 17 00:00:00 2001 From: Steffion Date: Tue, 30 Jul 2013 20:43:06 +0200 Subject: [PATCH] Create wand command, and make it work. --- src/nl/Steffion/BlockHunt/BlockHunt.java | 6 +- .../Steffion/BlockHunt/Commands/CMDwand.java | 54 +++++++++++++++ .../BlockHunt/Listeners/PlayerListener.java | 67 +++++++++++++++++++ .../Steffion/BlockHunt/Managers/CommandC.java | 8 +++ .../Steffion/BlockHunt/Managers/ConfigC.java | 18 ++++- .../Steffion/BlockHunt/Managers/PlayerM.java | 3 +- src/nl/Steffion/BlockHunt/W.java | 6 ++ 7 files changed, 156 insertions(+), 6 deletions(-) create mode 100644 src/nl/Steffion/BlockHunt/Commands/CMDwand.java diff --git a/src/nl/Steffion/BlockHunt/BlockHunt.java b/src/nl/Steffion/BlockHunt/BlockHunt.java index ea4b1da..b97243e 100644 --- a/src/nl/Steffion/BlockHunt/BlockHunt.java +++ b/src/nl/Steffion/BlockHunt/BlockHunt.java @@ -1,5 +1,6 @@ package nl.Steffion.BlockHunt; +import nl.Steffion.BlockHunt.Listeners.PlayerListener; import nl.Steffion.BlockHunt.Managers.CommandC; import nl.Steffion.BlockHunt.Managers.ConfigC; import nl.Steffion.BlockHunt.Managers.MessageM; @@ -18,9 +19,8 @@ public class BlockHunt extends JavaPlugin implements Listener { public void onEnable() { W.newFiles(); getServer().getPluginManager().registerEvents(this, this); - // getServer().getPluginManager().registerEvents(new - // PlayerListener(this), - // this); + getServer().getPluginManager().registerEvents(new PlayerListener(), + this); MessageM.sendFMessage(null, ConfigC.log_Enabled, true, "name-" + W.pluginName, "version-" + W.pluginVersion, "autors-" + W.pluginAutors); diff --git a/src/nl/Steffion/BlockHunt/Commands/CMDwand.java b/src/nl/Steffion/BlockHunt/Commands/CMDwand.java new file mode 100644 index 0000000..12f0738 --- /dev/null +++ b/src/nl/Steffion/BlockHunt/Commands/CMDwand.java @@ -0,0 +1,54 @@ +package nl.Steffion.BlockHunt.Commands; + +import java.util.ArrayList; +import java.util.List; + +import nl.Steffion.BlockHunt.W; +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.Material; +import org.bukkit.Sound; +import org.bukkit.command.Command; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +public class CMDwand extends DefaultCMD { + + @Override + public boolean exectue(Player player, Command cmd, String label, + String[] args) { + if (PlayerM.hasPerm(player, PermsC.create, true)) { + if (player != null) { + ItemStack wand = new ItemStack( + Material.getMaterial((Integer) W.config + .get(ConfigC.wandID))); + ItemMeta im = wand.getItemMeta(); + im.setDisplayName(MessageM.replaceAll((String) W.config + .get(ConfigC.wandName))); + W.config.load(); + List lores = W.config.getFile().getStringList( + ConfigC.wandDescription.getLocation()); + List lores2 = new ArrayList(); + for (String lore : lores) { + lores2.add(MessageM.replaceAll(lore)); + } + + im.setLore(lores2); + wand.setItemMeta(im); + player.getInventory().addItem(wand); + player.playSound(player.getLocation(), Sound.ORB_PICKUP, 5, 0); + MessageM.sendFMessage(player, ConfigC.normal_gaveWand, true, + "type-" + + wand.getType().toString() + .replaceAll("_", " ").toLowerCase()); + } else { + MessageM.sendFMessage(player, ConfigC.error_onlyIngame, true); + } + } + return true; + } +} diff --git a/src/nl/Steffion/BlockHunt/Listeners/PlayerListener.java b/src/nl/Steffion/BlockHunt/Listeners/PlayerListener.java index 581a4fa..4069ef0 100644 --- a/src/nl/Steffion/BlockHunt/Listeners/PlayerListener.java +++ b/src/nl/Steffion/BlockHunt/Listeners/PlayerListener.java @@ -1,6 +1,20 @@ package nl.Steffion.BlockHunt.Listeners; +import nl.Steffion.BlockHunt.W; +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 nl.Steffion.BlockHunt.Serializables.LocationSerializable; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; public class PlayerListener implements Listener { @@ -10,6 +24,59 @@ public class PlayerListener implements Listener { // this.plugin = plugin; // } + @EventHandler(priority = EventPriority.NORMAL) + public void onPlayerInteractEvent(PlayerInteractEvent event) { + Player player = event.getPlayer(); + if (PlayerM.hasPerm(player, PermsC.create, false)) { + ItemStack item = player.getItemInHand(); + + if (item.getItemMeta().hasDisplayName()) { + ItemMeta im = item.getItemMeta(); + if (im.getDisplayName().equals( + MessageM.replaceAll((String) W.config + .get(ConfigC.wandName)))) { + Action action = event.getAction(); + if (event.hasBlock()) { + LocationSerializable location = new LocationSerializable( + event.getClickedBlock().getLocation()); + if (action.equals(Action.LEFT_CLICK_BLOCK)) { + event.setCancelled(true); + if (W.pos1.get(player) == null + || !W.pos1.get(player).equals(location)) { + MessageM.sendFMessage( + player, + ConfigC.normal_setPosition, + true, + "number-1", + "pos-%N(%A" + location.getBlockX() + + "%N, %A" + + location.getBlockY() + + "%N, %A" + + location.getBlockZ() + "%N)"); + W.pos1.put(player, location); + } + } else if (action.equals(Action.RIGHT_CLICK_BLOCK)) { + event.setCancelled(true); + if (W.pos2.get(player) == null + || !W.pos2.get(player).equals(location)) { + MessageM.sendFMessage( + player, + ConfigC.normal_setPosition, + true, + "number-2", + "pos-%N(%A" + location.getBlockX() + + "%N, %A" + + location.getBlockY() + + "%N, %A" + + location.getBlockZ() + "%N)"); + W.pos2.put(player, location); + } + } + } + } + } + } + } // @EventHandler(priority = EventPriority.MONITOR) // public void onPlayerTeleportEvent(final PlayerTeleportEvent event) { // final Player player = event.getPlayer(); diff --git a/src/nl/Steffion/BlockHunt/Managers/CommandC.java b/src/nl/Steffion/BlockHunt/Managers/CommandC.java index 7d44a5b..dca4a77 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 + " "), + WAND ("BlockHunt%wand_", + "BlockHunt%w_", + new CMDwand(), + ConfigC.commandEnabled_wand, + PermsC.create, + ConfigC.help_wand, + 1, + W.pluginName + " "), NOT_FOUND ("%_", "%_", new CMDnotfound(), diff --git a/src/nl/Steffion/BlockHunt/Managers/ConfigC.java b/src/nl/Steffion/BlockHunt/Managers/ConfigC.java index 6858e31..6ae05e7 100644 --- a/src/nl/Steffion/BlockHunt/Managers/ConfigC.java +++ b/src/nl/Steffion/BlockHunt/Managers/ConfigC.java @@ -18,6 +18,16 @@ public enum ConfigC { commandEnabled_info (true, W.config), commandEnabled_help (true, W.config), commandEnabled_reload (true, W.config), + commandEnabled_wand (true, W.config), + + wandID (280, W.config), + wandName ("%A&l" + W.pluginName + "%N's selection wand", W.config), + wandDescription (new String[] { + "%NUse this item to select an arena for your arena.", + "%ALeft-Click%N to select point #1.", + "%ARight-Click%N to select point #2.", + "%NUse the create command to define your arena.", + "%A/" + W.pluginName + " " }, W.config), log_Enabled ("%N%name%&a&k + %N%version% is now Enabled. Made by %A%autors%%N.", W.messages), @@ -27,8 +37,13 @@ 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_wand ("%NGives you the wand selection tool.", W.messages), normal_reloadedConfigs ("&aReloaded all configs!", W.messages), + normal_gaveWand ("%NHere you go ;)! &o(Use the %A&o%type%%N&o!)", + W.messages), + normal_setPosition ("%NSet position %A#%number%%N to location: %pos%.", + W.messages), error_noPermission ("%EYou don't have the permissions to do that!", W.messages), @@ -37,7 +52,8 @@ public enum ConfigC { + W.pluginName + " help %Efor more info.", W.messages), error_notEnoughArguments ("%EYou're missing arguments, correct syntax: %A/%syntax%", W.messages), - error_noArena ("%ENo arena found with the name '%A%name%%E'.", 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); Object value; ConfigM config; diff --git a/src/nl/Steffion/BlockHunt/Managers/PlayerM.java b/src/nl/Steffion/BlockHunt/Managers/PlayerM.java index 283f223..bc91417 100644 --- a/src/nl/Steffion/BlockHunt/Managers/PlayerM.java +++ b/src/nl/Steffion/BlockHunt/Managers/PlayerM.java @@ -19,8 +19,7 @@ public class PlayerM { info (main + "info", PType.ALL), help (main + "help", PType.ALL), reload (main + "reload", PType.MODERATOR), - list (main + "list", PType.MODERATOR), - preview (main + "preview", PType.ADMIN); + create (main + "create", PType.ADMIN); public String perm; public PType type; diff --git a/src/nl/Steffion/BlockHunt/W.java b/src/nl/Steffion/BlockHunt/W.java index fac9d2b..0d7a384 100644 --- a/src/nl/Steffion/BlockHunt/W.java +++ b/src/nl/Steffion/BlockHunt/W.java @@ -1,9 +1,13 @@ package nl.Steffion.BlockHunt; import java.util.ArrayList; +import java.util.HashMap; + +import org.bukkit.entity.Player; import nl.Steffion.BlockHunt.Managers.ConfigM; import nl.Steffion.BlockHunt.Managers.MessageM; +import nl.Steffion.BlockHunt.Serializables.LocationSerializable; public class W { /* @@ -17,6 +21,8 @@ public class W { public static String pluginMainPermission = pluginName + "."; public static ArrayList newFiles = new ArrayList(); + public static HashMap pos1 = new HashMap(); + public static HashMap pos2 = new HashMap(); public static ConfigM config = new ConfigM("config", ""); public static ConfigM messages = new ConfigM("messages", "");