Browse Source

Updates to metadata, change to use block.getRelative in Woodcutting.java

GJ 13 years ago
parent
commit
bb5d003430

+ 2 - 2
src/main/java/com/gmail/nossr50/Combat.java

@@ -395,8 +395,8 @@ public class Combat {
                 baseXP = 20 * LoadProperties.pvpxprewardmodifier;
                 baseXP = 20 * LoadProperties.pvpxprewardmodifier;
             }
             }
         }
         }
-        else if (!target.hasMetadata("fromMobSpawner")) {
-            if (target instanceof Animals && !target.hasMetadata("summoned")) {
+        else if (!target.hasMetadata("mcmmoFromMobSpawner")) {
+            if (target instanceof Animals && !target.hasMetadata("mcmmoSummoned")) {
                 baseXP = LoadProperties.animalXP;
                 baseXP = LoadProperties.animalXP;
             }
             }
             else {
             else {

+ 5 - 5
src/main/java/com/gmail/nossr50/listeners/mcBlockListener.java

@@ -75,7 +75,7 @@ public class mcBlockListener implements Listener {
                 }
                 }
                 else {
                 else {
                     Block newLocation = block.getRelative(0, y+1, 0);
                     Block newLocation = block.getRelative(0, y+1, 0);
-                    newLocation.setMetadata("placedBlock", new FixedMetadataValue(plugin, true));
+                    newLocation.setMetadata("mcmmoPlacedBlock", new FixedMetadataValue(plugin, true));
                     break;
                     break;
                 }
                 }
             }
             }
@@ -83,7 +83,7 @@ public class mcBlockListener implements Listener {
 
 
         /* Check if the blocks placed should be monitored so they do not give out XP in the future */
         /* Check if the blocks placed should be monitored so they do not give out XP in the future */
         if (BlockChecks.shouldBeWatched(mat)) {
         if (BlockChecks.shouldBeWatched(mat)) {
-            block.setMetadata("placedBlock", new FixedMetadataValue(plugin, true));
+            block.setMetadata("mcmmoPlacedBlock", new FixedMetadataValue(plugin, true));
         }
         }
 
 
         if (id == LoadProperties.anvilID && LoadProperties.anvilmessages) {
         if (id == LoadProperties.anvilID && LoadProperties.anvilmessages) {
@@ -176,7 +176,7 @@ public class mcBlockListener implements Listener {
          * EXCAVATION
          * EXCAVATION
          */
          */
 
 
-        if (Excavation.canBeGigaDrillBroken(mat) && mcPermissions.getInstance().excavation(player) && !block.hasMetadata("placedBlock")) {
+        if (Excavation.canBeGigaDrillBroken(mat) && mcPermissions.getInstance().excavation(player) && !block.hasMetadata("mcmmoPlacedBlock")) {
             if (LoadProperties.excavationRequiresShovel && ItemChecks.isShovel(inhand)) {
             if (LoadProperties.excavationRequiresShovel && ItemChecks.isShovel(inhand)) {
                 Excavation.excavationProcCheck(block, player);
                 Excavation.excavationProcCheck(block, player);
             }
             }
@@ -186,8 +186,8 @@ public class mcBlockListener implements Listener {
         }
         }
 
 
         //Remove metadata when broken
         //Remove metadata when broken
-        if (block.hasMetadata("placedBlock") && BlockChecks.shouldBeWatched(mat)) {
-            block.removeMetadata("placedBlock", plugin);
+        if (block.hasMetadata("mcmmoPlacedBlock") && BlockChecks.shouldBeWatched(mat)) {
+            block.removeMetadata("mcmmoPlacedBlock", plugin);
         }
         }
     }
     }
 
 

+ 2 - 2
src/main/java/com/gmail/nossr50/listeners/mcEntityListener.java

@@ -165,7 +165,7 @@ public class mcEntityListener implements Listener {
     @EventHandler (priority = EventPriority.MONITOR)
     @EventHandler (priority = EventPriority.MONITOR)
     public void onCreatureSpawn(CreatureSpawnEvent event) {
     public void onCreatureSpawn(CreatureSpawnEvent event) {
         if (event.getSpawnReason().equals(SpawnReason.SPAWNER) && !LoadProperties.xpGainsMobSpawners) {
         if (event.getSpawnReason().equals(SpawnReason.SPAWNER) && !LoadProperties.xpGainsMobSpawners) {
-            event.getEntity().setMetadata("fromMobSpawner", new FixedMetadataValue(plugin, true));
+            event.getEntity().setMetadata("mcmmoFromMobSpawner", new FixedMetadataValue(plugin, true));
         }
         }
     }
     }
 
 
@@ -287,7 +287,7 @@ public class mcEntityListener implements Listener {
     public void onEntityTame(EntityTameEvent event) {
     public void onEntityTame(EntityTameEvent event) {
         Player player = (Player) event.getOwner();
         Player player = (Player) event.getOwner();
 
 
-        if (mcPermissions.getInstance().taming(player) && !event.getEntity().hasMetadata("summoned")) {
+        if (mcPermissions.getInstance().taming(player) && !event.getEntity().hasMetadata("mcmmoSummoned")) {
             PlayerProfile PP = Users.getProfile(player);
             PlayerProfile PP = Users.getProfile(player);
             EntityType type = event.getEntityType();
             EntityType type = event.getEntityType();
             int xp = 0;
             int xp = 0;

+ 2 - 2
src/main/java/com/gmail/nossr50/skills/BlastMining.java

@@ -48,7 +48,7 @@ public class BlastMining {
                 blocksDropped.add(temp);
                 blocksDropped.add(temp);
                 Mining.miningDrops(temp);
                 Mining.miningDrops(temp);
 
 
-                if (!temp.hasMetadata("placedBlock")) {
+                if (!temp.hasMetadata("mcmmoPlacedBlock")) {
                     if (extraDrops == 2) {
                     if (extraDrops == 2) {
                         blocksDropped.add(temp);
                         blocksDropped.add(temp);
                         Mining.miningDrops(temp);
                         Mining.miningDrops(temp);
@@ -160,7 +160,7 @@ public class BlastMining {
         }
         }
 
 
         for (Block block : xp) {
         for (Block block : xp) {
-            if (!block.hasMetadata("placedBlock")) {
+            if (!block.hasMetadata("mcmmoPlacedBlock")) {
                 Mining.miningXP(player, block);
                 Mining.miningXP(player, block);
             }
             }
         }
         }

+ 1 - 1
src/main/java/com/gmail/nossr50/skills/Excavation.java

@@ -126,7 +126,7 @@ public class Excavation {
     public static void gigaDrillBreaker(Player player, Block block) {
     public static void gigaDrillBreaker(Player player, Block block) {
         Skills.abilityDurabilityLoss(player.getItemInHand(), LoadProperties.abilityDurabilityLoss);
         Skills.abilityDurabilityLoss(player.getItemInHand(), LoadProperties.abilityDurabilityLoss);
 
 
-        if (!block.hasMetadata("placedBlock")) {
+        if (!block.hasMetadata("mcmmoPlacedBlock")) {
             PlayerAnimationEvent armswing = new PlayerAnimationEvent(player);
             PlayerAnimationEvent armswing = new PlayerAnimationEvent(player);
             Bukkit.getPluginManager().callEvent(armswing);
             Bukkit.getPluginManager().callEvent(armswing);
 
 

+ 7 - 7
src/main/java/com/gmail/nossr50/skills/Herbalism.java

@@ -135,7 +135,7 @@ public class Herbalism {
                 Block b = block.getRelative(0, y, 0);
                 Block b = block.getRelative(0, y, 0);
                 if (b.getType().equals(Material.CACTUS)) {
                 if (b.getType().equals(Material.CACTUS)) {
                     mat = Material.CACTUS;
                     mat = Material.CACTUS;
-                    if (!b.hasMetadata("placedBlock")) {
+                    if (!b.hasMetadata("mcmmoPlacedBlock")) {
                         if(herbLevel > MAX_BONUS_LEVEL || (Math.random() * 1000 <= herbLevel)) {
                         if(herbLevel > MAX_BONUS_LEVEL || (Math.random() * 1000 <= herbLevel)) {
                             catciDrops++;
                             catciDrops++;
                         }
                         }
@@ -154,7 +154,7 @@ public class Herbalism {
             break;
             break;
 
 
         case MELON_BLOCK:
         case MELON_BLOCK:
-            if (!block.hasMetadata("placedBlock")) {
+            if (!block.hasMetadata("mcmmoPlacedBlock")) {
                 mat = Material.MELON;
                 mat = Material.MELON;
                 xp = LoadProperties.mmelon;
                 xp = LoadProperties.mmelon;
             }
             }
@@ -169,7 +169,7 @@ public class Herbalism {
 
 
         case PUMPKIN:
         case PUMPKIN:
         case JACK_O_LANTERN:
         case JACK_O_LANTERN:
-            if (!block.hasMetadata("placedBlock")) {
+            if (!block.hasMetadata("mcmmoPlacedBlock")) {
                 mat = Material.getMaterial(id);
                 mat = Material.getMaterial(id);
                 xp = LoadProperties.mpumpkin;
                 xp = LoadProperties.mpumpkin;
             }
             }
@@ -177,7 +177,7 @@ public class Herbalism {
 
 
         case RED_ROSE:
         case RED_ROSE:
         case YELLOW_FLOWER:
         case YELLOW_FLOWER:
-            if (!block.hasMetadata("placedBlock")) {
+            if (!block.hasMetadata("mcmmoPlacedBlock")) {
                 mat = Material.getMaterial(id);
                 mat = Material.getMaterial(id);
                 xp = LoadProperties.mflower;
                 xp = LoadProperties.mflower;
             }
             }
@@ -188,7 +188,7 @@ public class Herbalism {
                 Block b = block.getRelative(0, y, 0);
                 Block b = block.getRelative(0, y, 0);
                 if (b.getType().equals(Material.SUGAR_CANE_BLOCK)) {
                 if (b.getType().equals(Material.SUGAR_CANE_BLOCK)) {
                     mat = Material.SUGAR_CANE;
                     mat = Material.SUGAR_CANE;
-                    if (!b.hasMetadata("placedBlock")) {
+                    if (!b.hasMetadata("mcmmoPlacedBlock")) {
                         if(herbLevel > MAX_BONUS_LEVEL || (Math.random() * 1000 <= herbLevel)) {
                         if(herbLevel > MAX_BONUS_LEVEL || (Math.random() * 1000 <= herbLevel)) {
                             caneDrops++;
                             caneDrops++;
                         }
                         }
@@ -199,14 +199,14 @@ public class Herbalism {
             break;
             break;
 
 
         case VINE:
         case VINE:
-            if (!block.hasMetadata("placedBlock")) {
+            if (!block.hasMetadata("mcmmoPlacedBlock")) {
                 mat = type;
                 mat = type;
                 xp = LoadProperties.mvines;
                 xp = LoadProperties.mvines;
             }
             }
             break;
             break;
 
 
         case WATER_LILY:
         case WATER_LILY:
-            if (!block.hasMetadata("placedBlock")) {
+            if (!block.hasMetadata("mcmmoPlacedBlock")) {
                 mat = type;
                 mat = type;
                 xp = LoadProperties.mlilypad;
                 xp = LoadProperties.mlilypad;
             }
             }

+ 2 - 2
src/main/java/com/gmail/nossr50/skills/Mining.java

@@ -156,7 +156,7 @@ public class Mining
      * @param plugin mcMMO plugin instance
      * @param plugin mcMMO plugin instance
      */
      */
     public static void miningBlockCheck(Player player, Block block, mcMMO plugin) {
     public static void miningBlockCheck(Player player, Block block, mcMMO plugin) {
-        if (block.hasMetadata("placedBlock")) {
+        if (block.hasMetadata("mcmmoPlacedBlock")) {
             return;
             return;
         }
         }
 
 
@@ -251,7 +251,7 @@ public class Mining
         case NETHERRACK:
         case NETHERRACK:
         case SANDSTONE:
         case SANDSTONE:
         case STONE:
         case STONE:
-            if (!block.hasMetadata("placedBlock")) {
+            if (!block.hasMetadata("mcmmoPlacedBlock")) {
                 return;
                 return;
             }
             }
 
 

+ 1 - 1
src/main/java/com/gmail/nossr50/skills/Taming.java

@@ -215,7 +215,7 @@ public class Taming {
                 }
                 }
             }
             }
             LivingEntity entity = player.getWorld().spawnCreature(player.getLocation(), type);
             LivingEntity entity = player.getWorld().spawnCreature(player.getLocation(), type);
-            entity.setMetadata("summoned", new FixedMetadataValue(plugin, true));
+            entity.setMetadata("mcmmoSummoned", new FixedMetadataValue(plugin, true));
             ((Tameable) entity).setOwner(player);
             ((Tameable) entity).setOwner(player);
 
 
             player.setItemInHand(new ItemStack(summonItem, item.getAmount() - summonAmount));
             player.setItemInHand(new ItemStack(summonItem, item.getAmount() - summonAmount));

+ 18 - 21
src/main/java/com/gmail/nossr50/skills/WoodCutting.java

@@ -3,7 +3,6 @@ package com.gmail.nossr50.skills;
 import java.util.ArrayList;
 import java.util.ArrayList;
 
 
 import org.bukkit.Material;
 import org.bukkit.Material;
-import org.bukkit.World;
 import org.bukkit.block.Block;
 import org.bukkit.block.Block;
 import org.bukkit.entity.Player;
 import org.bukkit.entity.Player;
 import org.bukkit.inventory.ItemStack;
 import org.bukkit.inventory.ItemStack;
@@ -32,13 +31,12 @@ public class WoodCutting
         Player player = event.getPlayer();
         Player player = event.getPlayer();
         Block firstBlock = event.getBlock();
         Block firstBlock = event.getBlock();
         PlayerProfile PP = Users.getProfile(player);
         PlayerProfile PP = Users.getProfile(player);
-        World world = firstBlock.getWorld();
         
         
         //Prepare array
         //Prepare array
         ArrayList<Block> toBeFelled = new ArrayList<Block>();
         ArrayList<Block> toBeFelled = new ArrayList<Block>();
         
         
         //NOTE: Tree Feller will cut upwards like how you actually fell trees
         //NOTE: Tree Feller will cut upwards like how you actually fell trees
-        processTreeFelling(firstBlock, world, toBeFelled, plugin);
+        processTreeFelling(firstBlock, toBeFelled, plugin);
         removeBlocks(toBeFelled, player, PP, plugin);
         removeBlocks(toBeFelled, player, PP, plugin);
     }
     }
     
     
@@ -97,7 +95,7 @@ public class WoodCutting
                         break;
                         break;
                     }
                     }
                     
                     
-                    if(!x.hasMetadata("placedBlock"))
+                    if(!x.hasMetadata("mcmmoPlacedBlock"))
                     {
                     {
                         WoodCutting.woodCuttingProcCheck(player, x);
                         WoodCutting.woodCuttingProcCheck(player, x);
                             
                             
@@ -149,9 +147,8 @@ public class WoodCutting
         return block.getType() == Material.LOG || block.getType() == Material.LEAVES || block.getType() == Material.AIR;
         return block.getType() == Material.LOG || block.getType() == Material.LEAVES || block.getType() == Material.AIR;
     }
     }
     
     
-    private static void processTreeFelling(Block currentBlock, World world, ArrayList<Block> toBeFelled, mcMMO plugin)
+    private static void processTreeFelling(Block currentBlock, ArrayList<Block> toBeFelled, mcMMO plugin)
     {
     {
-        int x = currentBlock.getX(), y = currentBlock.getY(), z = currentBlock.getZ();
         
         
         if(currentBlock.getType() == Material.LOG || currentBlock.getType() == Material.LEAVES)
         if(currentBlock.getType() == Material.LOG || currentBlock.getType() == Material.LEAVES)
             toBeFelled.add(currentBlock);
             toBeFelled.add(currentBlock);
@@ -159,32 +156,32 @@ public class WoodCutting
         //These 2 are to make sure that Tree Feller isn't so aggressive
         //These 2 are to make sure that Tree Feller isn't so aggressive
         boolean isAirOrLeaves = currentBlock.getType() == Material.LEAVES || currentBlock.getType() == Material.AIR;
         boolean isAirOrLeaves = currentBlock.getType() == Material.LEAVES || currentBlock.getType() == Material.AIR;
         
         
-        Block xPositive = world.getBlockAt(x+1, y, z);
-        Block xNegative = world.getBlockAt(x-1, y, z);
-        Block zPositive = world.getBlockAt(x, y, z+1);
-        Block zNegative = world.getBlockAt(x, y, z-1);
+        Block xPositive = currentBlock.getRelative(1, 0, 0);
+        Block xNegative = currentBlock.getRelative(-1, 0, 0);
+        Block zPositive = currentBlock.getRelative(0, 0, 1);
+        Block zNegative = currentBlock.getRelative(0, 0, -1);
         
         
-        if(!currentBlock.hasMetadata("placedBlock") &&
+        if(!currentBlock.hasMetadata("mcmmoPlacedBlock") &&
                 !isTooAgressive(isAirOrLeaves, xPositive) && treeFellerCompatible(xPositive) && !toBeFelled.contains(xPositive))
                 !isTooAgressive(isAirOrLeaves, xPositive) && treeFellerCompatible(xPositive) && !toBeFelled.contains(xPositive))
-            processTreeFelling(xPositive, world, toBeFelled, plugin);
-        if(!currentBlock.hasMetadata("placedBlock") &&
+            processTreeFelling(xPositive, toBeFelled, plugin);
+        if(!currentBlock.hasMetadata("mcmmoPlacedBlock") &&
                 !isTooAgressive(isAirOrLeaves, xNegative) && treeFellerCompatible(xNegative) && !toBeFelled.contains(xNegative))
                 !isTooAgressive(isAirOrLeaves, xNegative) && treeFellerCompatible(xNegative) && !toBeFelled.contains(xNegative))
-            processTreeFelling(xNegative, world, toBeFelled, plugin);
-        if(!currentBlock.hasMetadata("placedBlock") &&
+            processTreeFelling(xNegative, toBeFelled, plugin);
+        if(!currentBlock.hasMetadata("mcmmoPlacedBlock") &&
                 !isTooAgressive(isAirOrLeaves, zPositive) && treeFellerCompatible(zPositive) && !toBeFelled.contains(zPositive))
                 !isTooAgressive(isAirOrLeaves, zPositive) && treeFellerCompatible(zPositive) && !toBeFelled.contains(zPositive))
-            processTreeFelling(zPositive, world, toBeFelled, plugin);
-        if(!currentBlock.hasMetadata("placedBlock") &&
+            processTreeFelling(zPositive, toBeFelled, plugin);
+        if(!currentBlock.hasMetadata("mcmmoPlacedBlock") &&
                 !isTooAgressive(isAirOrLeaves, zNegative) && treeFellerCompatible(zNegative) && !toBeFelled.contains(zNegative))
                 !isTooAgressive(isAirOrLeaves, zNegative) && treeFellerCompatible(zNegative) && !toBeFelled.contains(zNegative))
-            processTreeFelling(zNegative, world, toBeFelled, plugin);
+            processTreeFelling(zNegative, toBeFelled, plugin);
         
         
         //Finally go Y+
         //Finally go Y+
-        Block yPositive = world.getBlockAt(x, y+1, z);
+        Block yPositive = currentBlock.getRelative(0, 1, 0);
         
         
         if(treeFellerCompatible(yPositive))
         if(treeFellerCompatible(yPositive))
         {
         {
-            if(!currentBlock.hasMetadata("placedBlock") && !toBeFelled.contains(yPositive))
+            if(!currentBlock.hasMetadata("mcmmoPlacedBlock") && !toBeFelled.contains(yPositive))
             {
             {
-                processTreeFelling(yPositive, world, toBeFelled, plugin);
+                processTreeFelling(yPositive, toBeFelled, plugin);
             }
             }
         }
         }
     }
     }