From 3e8305a85ff83038e3466f89502b9ecdb6b173ce Mon Sep 17 00:00:00 2001 From: sekwah41 Date: Sun, 8 Dec 2013 19:59:55 +0000 Subject: [PATCH] Added a custom item to be used as the axe along with a few other edits --- Advanced Portals/src/Config.yml | 4 +++ .../AdvancedPortalsCommand.java | 19 +++++++++-- .../AdvancedPortalsPlugin.java | 2 -- .../com/sekwah/advancedportals/Listeners.java | 22 +++++++++++-- .../com/sekwah/advancedportals/Portals.java | 32 ------------------- .../portalcontrolls/Portal.java | 5 +-- 6 files changed, 44 insertions(+), 40 deletions(-) delete mode 100644 Advanced Portals/src/com/sekwah/advancedportals/Portals.java diff --git a/Advanced Portals/src/Config.yml b/Advanced Portals/src/Config.yml index 861e4a5..2a032a2 100644 --- a/Advanced Portals/src/Config.yml +++ b/Advanced Portals/src/Config.yml @@ -5,9 +5,13 @@ # Set to true if you want the normal axes to work normally but the ones gived with /portals selector or wand will still work though +# It can be usefull if people with permission want to use an iron axe on a survival server UseOnlyServerMadeAxe: false +# Preferably an item and not a block but it shouldnt matter +AxeItemId: IRON_AXE +# This must be a placeable block or it will not work and may even crash ShowSelectionBlockID: WOOL ShowSelectionBlockData: 14 diff --git a/Advanced Portals/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java b/Advanced Portals/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java index a7ef124..a4d66aa 100644 --- a/Advanced Portals/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java +++ b/Advanced Portals/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java @@ -2,6 +2,8 @@ package com.sekwah.advancedportals; import java.util.Arrays; +import net.minecraft.server.v1_7_R1.Item; + import org.bukkit.Material; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -33,10 +35,23 @@ public class AdvancedPortalsCommand implements CommandExecutor { if(sender.hasPermission("AdvancedPortals.CreatePortal")){ PlayerInventory inventory = player.getInventory(); - ItemStack regionselector = new ItemStack(Material.IRON_AXE); + String ItemID = config.getConfig().getString("AxeItemId"); + + Material WandMaterial; + + try + { + WandMaterial = Material.getMaterial(Integer.parseInt(ItemID)); + } + catch(Exception e) + { + WandMaterial = Material.getMaterial(ItemID); + } + + ItemStack regionselector = new ItemStack(WandMaterial); ItemMeta selectorname = regionselector.getItemMeta(); selectorname.setDisplayName("§ePortal Region Selector"); - selectorname.setLore(Arrays.asList("§rThis iron axe with has the power to help" + selectorname.setLore(Arrays.asList("§rThis wand with has the power to help" , "§r create portals bistowed upon it!")); regionselector.setItemMeta(selectorname); diff --git a/Advanced Portals/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java b/Advanced Portals/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java index a9e1e7c..88c328c 100644 --- a/Advanced Portals/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java +++ b/Advanced Portals/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java @@ -16,8 +16,6 @@ public class AdvancedPortalsPlugin extends JavaPlugin { ConfigAccessor config = new ConfigAccessor(this, "Config.yml"); config.saveDefaultConfig(); - // Loads the current portal data - new Portals(this); // Loads the portal and destination editors new Portal(this); diff --git a/Advanced Portals/src/com/sekwah/advancedportals/Listeners.java b/Advanced Portals/src/com/sekwah/advancedportals/Listeners.java index b2ca3bb..1cdf85d 100644 --- a/Advanced Portals/src/com/sekwah/advancedportals/Listeners.java +++ b/Advanced Portals/src/com/sekwah/advancedportals/Listeners.java @@ -10,6 +10,8 @@ import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.metadata.FixedMetadataValue; +import com.sekwah.advancedportals.portalcontrolls.Portal; + public class Listeners implements Listener { private final AdvancedPortalsPlugin plugin; @@ -17,6 +19,8 @@ public class Listeners implements Listener { // The needed config values will be stored so they are easier to access later // an example is in the interact event in this if statement if((!UseOnlyServerAxe || event.getItem().getItemMeta().getDisplayName().equals("§eP... private boolean UseOnlyServerAxe = false; + + private Material WandMaterial; public Listeners(AdvancedPortalsPlugin plugin) { this.plugin = plugin; @@ -24,13 +28,27 @@ public class Listeners implements Listener { ConfigAccessor config = new ConfigAccessor(plugin, "Config.yml"); this.UseOnlyServerAxe = config.getConfig().getBoolean("UseOnlyServerMadeAxe"); + String ItemID = config.getConfig().getString("AxeItemId"); + + try + { + WandMaterial = Material.getMaterial(Integer.parseInt(ItemID)); + } + catch(Exception e) + { + WandMaterial = Material.getMaterial(ItemID); + } + plugin.getServer().getPluginManager().registerEvents(this, plugin); } @EventHandler public void onMoveEvent(PlayerMoveEvent event) { // will check if the player is in the portal or not. - ConfigAccessor portalsconfig = new ConfigAccessor(plugin, "Portals.yml"); + Object[] portals = Portal.Portals; + for(Object portal : portals){ + System.out.println(portal.toString()); + } } @@ -45,7 +63,7 @@ public class Listeners implements Listener { // UseOnlyServerMadeAxe being set to true makes is so only the axe generated by the server can be used so other iron axes can be used normally, // by default its false but it is a nice feature in case the user wants to use the axe normally too, such as a admin playing survival or it being used // as a weapon. - if((!UseOnlyServerAxe || event.getItem().getItemMeta().getDisplayName().equals("§ePortal Region Selector")) && event.getPlayer().getItemInHand().getTypeId() == Material.IRON_AXE.getId()) { + if((!UseOnlyServerAxe || event.getItem().getItemMeta().getDisplayName().equals("§ePortal Region Selector")) && event.getPlayer().getItemInHand().getTypeId() == WandMaterial.getId()) { // This checks if the action was a left or right click and if it was directly effecting a block. if(event.getAction() == Action.LEFT_CLICK_BLOCK) { diff --git a/Advanced Portals/src/com/sekwah/advancedportals/Portals.java b/Advanced Portals/src/com/sekwah/advancedportals/Portals.java deleted file mode 100644 index c285713..0000000 --- a/Advanced Portals/src/com/sekwah/advancedportals/Portals.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.sekwah.advancedportals; - -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Level; - - - -public class Portals { - - private final AdvancedPortalsPlugin plugin; - - private List portals; - - - - public Portals(AdvancedPortalsPlugin plugin) { - this.plugin = plugin; - this.loadPortalData(); - } - - public void loadPortalData(){ - ConfigAccessor config = new ConfigAccessor(plugin, "Portals.yml"); - List portals = config.getConfig().getStringList("portals"); - if(portals.size() > 0){ - - } - else{ - plugin.getLogger().log(Level.INFO, "There are currently no portals!"); - } - } -} diff --git a/Advanced Portals/src/com/sekwah/advancedportals/portalcontrolls/Portal.java b/Advanced Portals/src/com/sekwah/advancedportals/portalcontrolls/Portal.java index 062189c..4798f4d 100644 --- a/Advanced Portals/src/com/sekwah/advancedportals/portalcontrolls/Portal.java +++ b/Advanced Portals/src/com/sekwah/advancedportals/portalcontrolls/Portal.java @@ -14,10 +14,11 @@ public class Portal { private static AdvancedPortalsPlugin plugin; - private static Object[] Portals; + public static Object[] Portals; public Portal(AdvancedPortalsPlugin plugin) { this.plugin = plugin; + this.loadPortals(); } /** @@ -29,7 +30,7 @@ public class Portal { * */ - public static void load(){ + public static void loadPortals(){ ConfigAccessor config = new ConfigAccessor(plugin, "Portals.yml"); Set PortalSet = config.getConfig().getKeys(false);