From 3bc317e7b27f2852a1e102a3ca55d17d99f33db0 Mon Sep 17 00:00:00 2001 From: GJ Date: Sun, 4 Mar 2012 03:54:26 -0500 Subject: [PATCH] Enum more things, fixed some durability issues with abilities. --- .../nossr50/listeners/mcBlockListener.java | 46 ++---- .../nossr50/listeners/mcPlayerListener.java | 2 +- .../com/gmail/nossr50/skills/Excavation.java | 12 +- .../java/com/gmail/nossr50/skills/Mining.java | 142 ++++++------------ .../java/com/gmail/nossr50/skills/Skills.java | 15 ++ .../com/gmail/nossr50/skills/WoodCutting.java | 24 +-- 6 files changed, 78 insertions(+), 163 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/listeners/mcBlockListener.java b/src/main/java/com/gmail/nossr50/listeners/mcBlockListener.java index da870510b..8accaa84f 100644 --- a/src/main/java/com/gmail/nossr50/listeners/mcBlockListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/mcBlockListener.java @@ -27,7 +27,6 @@ import com.gmail.nossr50.datatypes.SkillType; import org.bukkit.Material; import org.bukkit.block.Block; -import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -63,7 +62,7 @@ public class mcBlockListener implements Listener Player player = event.getPlayer(); //When blocks are placed on snow this event reports the wrong block. - if (event.getBlockReplacedState() != null && event.getBlockReplacedState().getTypeId() == 78) + if (event.getBlockReplacedState() != null && event.getBlockReplacedState().getType().equals(Material.SNOW)) block = event.getBlockAgainst(); else block = event.getBlock(); @@ -72,7 +71,7 @@ public class mcBlockListener implements Listener Material mat = block.getType(); //TNT placement checks - needed for Blast Mining - if(id == 46 && mcPermissions.getInstance().blastMining(player)) + if(mat.equals(Material.TNT) && mcPermissions.getInstance().blastMining(player)) plugin.misc.tntTracker.put(block.getLocation(), player); //Check if the blocks placed should be monitored so they do not give out XP in the future @@ -199,9 +198,7 @@ public class mcBlockListener implements Listener { block.setData((byte) 0); if(plugin.misc.blockWatchList.contains(block)) - { plugin.misc.blockWatchList.remove(block); - } } } @@ -213,6 +210,7 @@ public class mcBlockListener implements Listener ItemStack inhand = player.getItemInHand(); Block block = event.getBlock(); int id = block.getTypeId(); + Material mat = block.getType(); /* * ABILITY PREPARATION CHECKS @@ -221,7 +219,7 @@ public class mcBlockListener implements Listener { if(PP.getHoePreparationMode() && Herbalism.canBeGreenTerra(block)) Skills.abilityCheck(player, SkillType.HERBALISM); - if(PP.getAxePreparationMode() && id == 17 && mcPermissions.getInstance().woodCuttingAbility(player)) + if(PP.getAxePreparationMode() && mat.equals(Material.LOG) && mcPermissions.getInstance().woodCuttingAbility(player)) Skills.abilityCheck(player, SkillType.WOODCUTTING); if(PP.getPickaxePreparationMode() && Mining.canBeSuperBroken(block)) Skills.abilityCheck(player, SkillType.MINING); @@ -229,13 +227,13 @@ public class mcBlockListener implements Listener Skills.abilityCheck(player, SkillType.EXCAVATION); } - if(PP.getFistsPreparationMode() && (Excavation.canBeGigaDrillBroken(block) || id == 78)) + if(PP.getFistsPreparationMode() && (Excavation.canBeGigaDrillBroken(block) || mat.equals(Material.SNOW))) Skills.abilityCheck(player, SkillType.UNARMED); /* * TREE FELLER STUFF */ - if(LoadProperties.spoutEnabled && id == 17 && PP.getTreeFellerMode()) + if(LoadProperties.spoutEnabled && mat.equals(Material.LOG) && PP.getTreeFellerMode()) SpoutStuff.playSoundForPlayer(SoundEffect.FIZZ, player, block.getLocation()); /* @@ -251,21 +249,11 @@ public class mcBlockListener implements Listener { if(LoadProperties.excavationRequiresShovel && m.isShovel(inhand)) { - event.setInstaBreak(true); - Excavation.gigaDrillBreaker(player, block); - } - else if(!LoadProperties.excavationRequiresShovel){ - - if(LoadProperties.toolsLoseDurabilityFromAbilities) - { - if(!inhand.containsEnchantment(Enchantment.DURABILITY)) - { - short durability = inhand.getDurability(); - durability += (LoadProperties.abilityDurabilityLoss); - inhand.setDurability(durability); - } - } - + event.setInstaBreak(true); + Excavation.gigaDrillBreaker(player, block); + } + else if(!LoadProperties.excavationRequiresShovel) + { event.setInstaBreak(true); Excavation.gigaDrillBreaker(player, block); } @@ -297,16 +285,6 @@ public class mcBlockListener implements Listener { if(m.isMiningPick(inhand)){ - if(LoadProperties.toolsLoseDurabilityFromAbilities) - { - if(!inhand.containsEnchantment(Enchantment.DURABILITY)) - { - short durability = inhand.getDurability(); - durability += (LoadProperties.abilityDurabilityLoss); - inhand.setDurability(durability); - } - } - event.setInstaBreak(true); Mining.SuperBreakerBlockCheck(player, block, plugin); } @@ -347,8 +325,6 @@ public class mcBlockListener implements Listener Block blockFrom = event.getBlock(); Block blockTo = event.getToBlock(); if(m.shouldBeWatched(blockFrom.getType()) && blockFrom.getData() == (byte)5) - { blockTo.setData((byte)5); - } } } diff --git a/src/main/java/com/gmail/nossr50/listeners/mcPlayerListener.java b/src/main/java/com/gmail/nossr50/listeners/mcPlayerListener.java index c61433001..5da217b59 100644 --- a/src/main/java/com/gmail/nossr50/listeners/mcPlayerListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/mcPlayerListener.java @@ -99,7 +99,7 @@ public class mcPlayerListener implements Listener { State state = event.getState(); Entity caught = event.getCaught(); - if(state== State.CAUGHT_FISH) + if(state == State.CAUGHT_FISH) { if(caught instanceof org.bukkit.entity.Item) Fishing.processResults(event); diff --git a/src/main/java/com/gmail/nossr50/skills/Excavation.java b/src/main/java/com/gmail/nossr50/skills/Excavation.java index 57240f12a..7fbbfc0f0 100644 --- a/src/main/java/com/gmail/nossr50/skills/Excavation.java +++ b/src/main/java/com/gmail/nossr50/skills/Excavation.java @@ -24,7 +24,6 @@ import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -import org.bukkit.enchantments.Enchantment; import org.bukkit.event.player.PlayerAnimationEvent; import com.gmail.nossr50.spout.SpoutStuff; @@ -174,16 +173,7 @@ public class Excavation public static void gigaDrillBreaker(Player player, Block block) { - if(LoadProperties.toolsLoseDurabilityFromAbilities) - { - if(!player.getItemInHand().containsEnchantment(Enchantment.DURABILITY)) - { - short durability = player.getItemInHand().getDurability(); - durability += LoadProperties.abilityDurabilityLoss; - player.getItemInHand().setDurability(durability); - } - } - + Skills.abilityDurabilityLoss(player.getItemInHand()); if(block.getData() != (byte)5) { PlayerAnimationEvent armswing = new PlayerAnimationEvent(player); diff --git a/src/main/java/com/gmail/nossr50/skills/Mining.java b/src/main/java/com/gmail/nossr50/skills/Mining.java index 8c4cd3000..fd52f42e9 100644 --- a/src/main/java/com/gmail/nossr50/skills/Mining.java +++ b/src/main/java/com/gmail/nossr50/skills/Mining.java @@ -18,6 +18,7 @@ package com.gmail.nossr50.skills; import org.bukkit.Bukkit; import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -40,8 +41,8 @@ public class Mining public static void blockProcSimulate(Block block, Player player) { Location loc = block.getLocation(); - int id = block.getTypeId(); - ItemStack item = new ItemStack(id, 1); + Material type = block.getType(); + ItemStack item = new ItemStack(type, 1); //Drop natural block with Silk Touch if(player.getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)){ @@ -49,43 +50,33 @@ public class Mining return; } - switch (id){ - //GLOWSTONE - case 89: - item = new ItemStack(348, 1); + switch (type){ + case GLOWSTONE: + item = new ItemStack(Material.GLOWSTONE_DUST, 1); m.mcDropItems(loc, item, 2); m.mcRandomDropItems(loc, item, 50, 2); break; - //REDSTONE - case 73: - item = new ItemStack(331, 1); + case GLOWING_REDSTONE_ORE: + case REDSTONE_ORE: + item = new ItemStack(Material.REDSTONE, 1); m.mcDropItems(loc, item, 4); m.mcRandomDropItem(loc, item, 50); break; - case 74: - item = new ItemStack(331, 1); - m.mcDropItems(loc, item, 4); - m.mcRandomDropItem(loc, item, 50); - break; - //LAPIS - case 21: - item = new ItemStack(351, 1, (byte)0,(byte)0x4); + case LAPIS_ORE: + item = new ItemStack(Material.INK_SACK, 1, (byte)0, (byte)0x4); m.mcDropItems(loc, item, 4); m.mcRandomDropItems(loc, item, 50, 4); break; - //DIAMOND - case 56: - item = new ItemStack(264, 1); + case DIAMOND_ORE: + item = new ItemStack(Material.DIAMOND, 1); m.mcDropItem(loc, item); break; - //STONE - case 1: - item = new ItemStack(4, 1); + case STONE: + item = new ItemStack(Material.COBBLESTONE, 1); m.mcDropItem(loc, item); break; - //COAL - case 16: - item = new ItemStack(263, 1); + case COAL_ORE: + item = new ItemStack(Material.COAL, 1, (byte)0, (byte)0x0); m.mcDropItem(loc, item); break; default: @@ -108,66 +99,50 @@ public class Mining if(plugin.misc.blockWatchList.contains(block) || block.getData() == (byte) 5) return; int xp = 0; - int id = block.getTypeId(); + Material type = block.getType(); - switch (id) { - //STONE - case 1: + switch (type) { + case STONE: xp += LoadProperties.mstone; break; - //SANDSTONE - case 24: + case SANDSTONE: xp += LoadProperties.msandstone; break; - //OBSIDIAN - case 49: + case OBSIDIAN: xp += LoadProperties.mobsidian; break; - //NETHERRACK - case 87: + case NETHERRACK: xp += LoadProperties.mnetherrack; break; - //GLOWSTONE - case 89: + case GLOWSTONE: xp += LoadProperties.mglowstone; break; - //COAL - case 16: + case COAL_ORE: xp += LoadProperties.mcoal; break; - //GOLD - case 14: + case GOLD_ORE: xp += LoadProperties.mgold; break; - //DIAMOND - case 56: + case DIAMOND_ORE: xp += LoadProperties.mdiamond; break; - //IRON - case 15: + case IRON_ORE: xp += LoadProperties.miron; break; - //REDSTONE - case 73: + case GLOWING_REDSTONE_ORE: + case REDSTONE_ORE: xp += LoadProperties.mredstone; break; - case 74: - xp += LoadProperties.mredstone; - break; - //LAPIS - case 21: + case LAPIS_ORE: xp += LoadProperties.mlapis; break; - //END STONE - case 121: + case ENDER_STONE: xp += LoadProperties.mendstone; break; - //MOSS STONE - case 48: + case MOSSY_COBBLESTONE: xp += LoadProperties.mmossstone; break; } - if(canBeSuperBroken(block)) blockProcCheck(block, player); PP.addXP(SkillType.MINING, xp, player); @@ -202,119 +177,98 @@ public class Mining public static void SuperBreakerBlockCheck(Player player, Block block, mcMMO plugin) { PlayerProfile PP = Users.getProfile(player); - if(LoadProperties.toolsLoseDurabilityFromAbilities) - { - if(!player.getItemInHand().containsEnchantment(Enchantment.DURABILITY)) - { - short durability = player.getItemInHand().getDurability(); - durability += LoadProperties.abilityDurabilityLoss; - player.getItemInHand().setDurability(durability); - } - } + Skills.abilityDurabilityLoss(player.getItemInHand()); //Pre-processing - int id = block.getTypeId(); + Material type = block.getType(); int xp = 0; PlayerAnimationEvent armswing = new PlayerAnimationEvent(player); - //STONE - if(id == 1 && block.getData() != (byte) 5) + if(type.equals(Material.STONE) && block.getData() != (byte) 5) { Bukkit.getPluginManager().callEvent(armswing); xp += LoadProperties.mstone; blockProcCheck(block, player); blockProcCheck(block, player); } - //SANDSTONE - else if(id == 24 && block.getData() != (byte) 5) + else if(type.equals(Material.SANDSTONE) && block.getData() != (byte) 5) { Bukkit.getPluginManager().callEvent(armswing); xp += LoadProperties.msandstone; blockProcCheck(block, player); blockProcCheck(block, player); } - //NETHERRACK - else if(id == 87 && block.getData() != (byte) 5) + else if(type.equals(Material.NETHERRACK) && block.getData() != (byte) 5) { Bukkit.getPluginManager().callEvent(armswing); xp += LoadProperties.mnetherrack; blockProcCheck(block, player); blockProcCheck(block, player); } - //GLOWSTONE - else if(id == 89 && block.getData() != (byte) 5) + else if(type.equals(Material.GLOWSTONE) && block.getData() != (byte) 5) { Bukkit.getPluginManager().callEvent(armswing); xp += LoadProperties.mglowstone; blockProcCheck(block, player); blockProcCheck(block, player); } - //COAL - else if(id == 16 && block.getData() != (byte) 5) + else if(type.equals(Material.COAL_ORE) && block.getData() != (byte) 5) { Bukkit.getPluginManager().callEvent(armswing); xp += LoadProperties.mcoal; blockProcCheck(block, player); blockProcCheck(block, player); } - //GOLD - else if(id == 14 && m.getTier(player) >= 3 && block.getData() != (byte) 5) + else if(type.equals(Material.GOLD_ORE) && m.getTier(player) >= 3 && block.getData() != (byte) 5) { Bukkit.getPluginManager().callEvent(armswing); xp += LoadProperties.mgold; blockProcCheck(block, player); blockProcCheck(block, player); } - //OBSIDIAN - else if(id == 49 && m.getTier(player) >= 4 && block.getData() != (byte) 5) + else if(type.equals(Material.OBSIDIAN) && m.getTier(player) >= 4 && block.getData() != (byte) 5) { Bukkit.getPluginManager().callEvent(armswing); xp += LoadProperties.mobsidian; blockProcCheck(block, player); blockProcCheck(block, player); } - //DIAMOND - else if(id == 56 && m.getTier(player) >= 3 && block.getData() != (byte) 5) + else if(type.equals(Material.DIAMOND_ORE) && m.getTier(player) >= 3 && block.getData() != (byte) 5) { Bukkit.getPluginManager().callEvent(armswing); xp += LoadProperties.mdiamond; blockProcCheck(block, player); blockProcCheck(block, player); } - //IRON - else if(id == 15 && m.getTier(player) >= 2 && block.getData() != (byte) 5) + else if(type.equals(Material.IRON_ORE) && m.getTier(player) >= 2 && block.getData() != (byte) 5) { Bukkit.getPluginManager().callEvent(armswing); xp += LoadProperties.miron; blockProcCheck(block, player); blockProcCheck(block, player); } - //REDSTONE - else if((id == 73 || id == 74) && m.getTier(player) >= 3 && !plugin.misc.blockWatchList.contains(block)) + else if((type.equals(Material.GLOWING_REDSTONE_ORE) || type.equals(Material.REDSTONE_ORE)) && m.getTier(player) >= 3 && !plugin.misc.blockWatchList.contains(block)) { Bukkit.getPluginManager().callEvent(armswing); xp += LoadProperties.mredstone; blockProcCheck(block, player); blockProcCheck(block, player); } - //LAPIS - else if(id == 21 && m.getTier(player) >= 3 && block.getData() != (byte) 5) + else if(type.equals(Material.LAPIS_ORE) && m.getTier(player) >= 3 && block.getData() != (byte) 5) { Bukkit.getPluginManager().callEvent(armswing); xp += LoadProperties.mlapis; blockProcCheck(block, player); blockProcCheck(block, player); } - //END STONE - else if(id == 121 && block.getData() != (byte) 5) + else if(type.equals(Material.ENDER_STONE) && block.getData() != (byte) 5) { Bukkit.getPluginManager().callEvent(armswing); xp += LoadProperties.mendstone; blockProcCheck(block, player); blockProcCheck(block, player); } - //MOSS STONE - else if(id == 48 && block.getData() != (byte) 5) + else if(type.equals(Material.MOSSY_COBBLESTONE) && block.getData() != (byte) 5) { Bukkit.getPluginManager().callEvent(armswing); xp += LoadProperties.mmossstone; diff --git a/src/main/java/com/gmail/nossr50/skills/Skills.java b/src/main/java/com/gmail/nossr50/skills/Skills.java index f9bdde49c..6c4498580 100644 --- a/src/main/java/com/gmail/nossr50/skills/Skills.java +++ b/src/main/java/com/gmail/nossr50/skills/Skills.java @@ -20,7 +20,9 @@ import java.util.logging.Logger; import org.bukkit.Bukkit; import org.bukkit.ChatColor; +import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; import org.getspout.spoutapi.SpoutManager; import org.getspout.spoutapi.player.SpoutPlayer; @@ -269,6 +271,19 @@ public class Skills return false; } + public static void abilityDurabilityLoss(ItemStack inhand) + { + if(LoadProperties.toolsLoseDurabilityFromAbilities) + { + if(!inhand.containsEnchantment(Enchantment.DURABILITY)) + { + short durability = inhand.getDurability(); + durability += (LoadProperties.abilityDurabilityLoss); + inhand.setDurability(durability); + } + } + } + /** * Check to see if an ability can be activated. * diff --git a/src/main/java/com/gmail/nossr50/skills/WoodCutting.java b/src/main/java/com/gmail/nossr50/skills/WoodCutting.java index 337861de5..85acd0d98 100644 --- a/src/main/java/com/gmail/nossr50/skills/WoodCutting.java +++ b/src/main/java/com/gmail/nossr50/skills/WoodCutting.java @@ -23,7 +23,6 @@ import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -import org.bukkit.enchantments.Enchantment; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.player.PlayerAnimationEvent; import org.bukkit.Bukkit; @@ -161,16 +160,7 @@ public class WoodCutting PP.addXP(SkillType.WOODCUTTING, xp, player); //Tree Feller gives nerf'd XP Skills.XpCheckSkill(SkillType.WOODCUTTING, player); - - if(LoadProperties.toolsLoseDurabilityFromAbilities) - { - if(!player.getItemInHand().containsEnchantment(Enchantment.DURABILITY)) - { - short durability = player.getItemInHand().getDurability(); - durability += (LoadProperties.abilityDurabilityLoss * durabilityLoss); - player.getItemInHand().setDurability(durability); - } - } + Skills.abilityDurabilityLoss(player.getItemInHand()); } private static boolean treeFellerCompatible(Block block) @@ -275,17 +265,7 @@ public class WoodCutting PlayerAnimationEvent armswing = new PlayerAnimationEvent(player); Bukkit.getPluginManager().callEvent(armswing); - - if(LoadProperties.toolsLoseDurabilityFromAbilities) - { - if(!player.getItemInHand().containsEnchantment(Enchantment.DURABILITY)) - { - short durability = player.getItemInHand().getDurability(); - durability += LoadProperties.abilityDurabilityLoss; - player.getItemInHand().setDurability(durability); - } - } - + Skills.abilityDurabilityLoss(player.getItemInHand()); if(LoadProperties.spoutEnabled) SpoutStuff.playSoundForPlayer(SoundEffect.POP, player, block.getLocation()); }