From 058cc3aac9a4c333898e8c2bcd28ff7d5291971d Mon Sep 17 00:00:00 2001 From: GJ Date: Wed, 14 Mar 2012 23:31:56 -0400 Subject: [PATCH] Changed placed block tracking to use metadata! --- Changelog.txt | 1 + .../java/com/gmail/nossr50/BlockChecks.java | 42 ------------------- .../java/com/gmail/nossr50/config/Misc.java | 3 -- .../nossr50/listeners/mcBlockListener.java | 18 ++++---- src/main/java/com/gmail/nossr50/mcMMO.java | 6 --- .../runnables/ChangeDataValueTimer.java | 31 -------------- .../com/gmail/nossr50/skills/BlastMining.java | 4 +- .../com/gmail/nossr50/skills/Excavation.java | 2 +- .../com/gmail/nossr50/skills/Herbalism.java | 14 +++---- .../java/com/gmail/nossr50/skills/Mining.java | 4 +- .../com/gmail/nossr50/skills/WoodCutting.java | 16 ++++--- 11 files changed, 28 insertions(+), 113 deletions(-) delete mode 100644 src/main/java/com/gmail/nossr50/runnables/ChangeDataValueTimer.java diff --git a/Changelog.txt b/Changelog.txt index b4b7b9ac8..9a73cecf6 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -36,6 +36,7 @@ Version 2.0.00-dev ! Changed parties so that a player will leave their existing party if they enter a world where they don't have party permissions. ! Changed Call of the Wild to summon animals already tamed. ! Changed mob spawner tracking to use new Metadata API + ! Changed block watch list to use new Metadata API Version 1.3.02 + Added in game guides for Mining, Excavation, and Acrobatics. Simply type /skillname ? to access them diff --git a/src/main/java/com/gmail/nossr50/BlockChecks.java b/src/main/java/com/gmail/nossr50/BlockChecks.java index 460ff7a29..a58c8c5ab 100644 --- a/src/main/java/com/gmail/nossr50/BlockChecks.java +++ b/src/main/java/com/gmail/nossr50/BlockChecks.java @@ -1,7 +1,6 @@ package com.gmail.nossr50; import org.bukkit.Material; -import org.bukkit.block.Block; import com.gmail.nossr50.config.LoadProperties; @@ -117,45 +116,4 @@ public class BlockChecks { return false; } } - - /** - * Adds the block the the appropriate watchlist. - * - * @param material the type of Block to watch - * @param block the Block to watch - * @param plugin mcMMO plugin instance - */ - public static void watchBlock(Material material, Block block, mcMMO plugin) { - - boolean addToChangeQueue = true; - - switch (material) { - case CACTUS: - case GLOWING_REDSTONE_ORE: - case JACK_O_LANTERN: - case LOG: - case PUMPKIN: - case REDSTONE_ORE: - case SUGAR_CANE_BLOCK: - case VINE: - addToChangeQueue = false; //We don't want these added to changeQueue - these use their data - plugin.misc.blockWatchList.add(block); - break; - - case BROWN_MUSHROOM: - case RED_MUSHROOM: - case RED_ROSE: - case YELLOW_FLOWER: - case WATER_LILY: - addToChangeQueue = false; //We don't want these added to changeQueue - they're already being added to the fast queue - plugin.fastChangeQueue.push(block); - break; - - default: - break; - } - - if(addToChangeQueue) - plugin.changeQueue.push(block); - } } diff --git a/src/main/java/com/gmail/nossr50/config/Misc.java b/src/main/java/com/gmail/nossr50/config/Misc.java index 433508d65..0557315c3 100644 --- a/src/main/java/com/gmail/nossr50/config/Misc.java +++ b/src/main/java/com/gmail/nossr50/config/Misc.java @@ -2,9 +2,7 @@ package com.gmail.nossr50.config; import java.util.ArrayList; import java.util.HashMap; -import java.util.HashSet; -import org.bukkit.block.Block; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; @@ -15,7 +13,6 @@ public class Misc { String location = "mcmmo.properties"; - public HashSet blockWatchList = new HashSet(); public HashMap arrowTracker = new HashMap(); public ArrayList bleedTracker = new ArrayList(); public HashMap tntTracker = new HashMap(); diff --git a/src/main/java/com/gmail/nossr50/listeners/mcBlockListener.java b/src/main/java/com/gmail/nossr50/listeners/mcBlockListener.java index fa777cff6..68ad897fc 100644 --- a/src/main/java/com/gmail/nossr50/listeners/mcBlockListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/mcBlockListener.java @@ -30,6 +30,7 @@ import org.bukkit.event.block.BlockDamageEvent; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.player.PlayerAnimationEvent; import org.bukkit.inventory.ItemStack; +import org.bukkit.metadata.FixedMetadataValue; import org.getspout.spoutapi.SpoutManager; import org.getspout.spoutapi.player.SpoutPlayer; @@ -74,7 +75,7 @@ public class mcBlockListener implements Listener { } else { Block newLocation = block.getRelative(0, y+1, 0); - newLocation.setData((byte) 0x5); + newLocation.setMetadata("placedBlock", new FixedMetadataValue(plugin, true)); break; } } @@ -82,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 */ if (BlockChecks.shouldBeWatched(mat)) { - BlockChecks.watchBlock(mat, block, plugin); + block.setMetadata("placedBlock", new FixedMetadataValue(plugin, true)); } if (id == LoadProperties.anvilID && LoadProperties.anvilmessages) { @@ -137,7 +138,7 @@ public class mcBlockListener implements Listener { Herbalism.herbalismProcCheck(block, player, event, plugin); //Called twice for triple drop functionality } - if (mcPermissions.getInstance().herbalism(player) && block.getData() != (byte) 0x5 && Herbalism.canBeGreenTerra(mat)) { + if (mcPermissions.getInstance().herbalism(player) && Herbalism.canBeGreenTerra(mat)) { Herbalism.herbalismProcCheck(block, player, event, plugin); } @@ -175,7 +176,7 @@ public class mcBlockListener implements Listener { * EXCAVATION */ - if (Excavation.canBeGigaDrillBroken(mat) && mcPermissions.getInstance().excavation(player) && block.getData() != (byte) 0x5) { + if (Excavation.canBeGigaDrillBroken(mat) && mcPermissions.getInstance().excavation(player) && !block.hasMetadata("placedBlock")) { if (LoadProperties.excavationRequiresShovel && ItemChecks.isShovel(inhand)) { Excavation.excavationProcCheck(block, player); } @@ -184,12 +185,9 @@ public class mcBlockListener implements Listener { } } - //Change the byte back when broken - if (block.getData() == (byte) 0x5 && BlockChecks.shouldBeWatched(mat)) { - block.setData((byte) 0x0); - } - else if(plugin.misc.blockWatchList.contains(block)) { - plugin.misc.blockWatchList.remove(block); + //Remove metadata when broken + if (block.hasMetadata("placedBlock") && BlockChecks.shouldBeWatched(mat)) { + block.removeMetadata("placedBlock", plugin); } } diff --git a/src/main/java/com/gmail/nossr50/mcMMO.java b/src/main/java/com/gmail/nossr50/mcMMO.java index eb76b4e6a..414352039 100644 --- a/src/main/java/com/gmail/nossr50/mcMMO.java +++ b/src/main/java/com/gmail/nossr50/mcMMO.java @@ -59,8 +59,6 @@ public class mcMMO extends JavaPlugin { private Runnable mcMMO_Timer = new mcTimer(this); //BLEED AND REGENERATION private Runnable mcMMO_SaveTimer = new mcSaveTimer(this); //Periodic saving of Player Data - private Runnable ChangeDataValueTimer = new ChangeDataValueTimer(changeQueue); //R2 block place workaround - private Runnable FastChangeDataValueTimer = new ChangeDataValueTimer(fastChangeQueue); //R2 block place workaround for instant-break stuff //Alias - Command public HashMap aliasMap = new HashMap(); @@ -152,10 +150,6 @@ public class mcMMO extends JavaPlugin { //Bleed & Regen timer (Runs every 20 seconds) Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, mcMMO_Timer, 0, 20); - //R2+ block place fix - Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, ChangeDataValueTimer, 0, 10); - Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, FastChangeDataValueTimer, 0, 1); - registerCommands(); //Spout Stuff diff --git a/src/main/java/com/gmail/nossr50/runnables/ChangeDataValueTimer.java b/src/main/java/com/gmail/nossr50/runnables/ChangeDataValueTimer.java deleted file mode 100644 index 666874a54..000000000 --- a/src/main/java/com/gmail/nossr50/runnables/ChangeDataValueTimer.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.gmail.nossr50.runnables; - -import java.util.ArrayDeque; - -import org.bukkit.block.Block; - -/* - * This file was created for a breakage introduced in 1.1-R2 - * It should be removed afterwards if the breakage is removed. - */ -public class ChangeDataValueTimer implements Runnable { - private ArrayDeque queue; - - public ChangeDataValueTimer(ArrayDeque queue) { - this.queue = queue; - } - - public void run() { - int size = queue.size(); - if(size == 0) return; - if(size > 25) { - size = (int) Math.floor(size / 10); - } - - for(int i = 0; i < size; i++) { - Block change = queue.poll(); - if(change == null) continue; - change.setData((byte) 5); - } - } -} diff --git a/src/main/java/com/gmail/nossr50/skills/BlastMining.java b/src/main/java/com/gmail/nossr50/skills/BlastMining.java index d0730500b..4c8a92a30 100644 --- a/src/main/java/com/gmail/nossr50/skills/BlastMining.java +++ b/src/main/java/com/gmail/nossr50/skills/BlastMining.java @@ -48,7 +48,7 @@ public class BlastMining { blocksDropped.add(temp); Mining.miningDrops(temp); - if (temp.getData() != (byte) 0x5 && !plugin.misc.blockWatchList.contains(temp)) { + if (!temp.hasMetadata("placedBlock")) { if (extraDrops == 2) { blocksDropped.add(temp); Mining.miningDrops(temp); @@ -160,7 +160,7 @@ public class BlastMining { } for (Block block : xp) { - if (block.getData() != (byte)5 && !plugin.misc.blockWatchList.contains(block)) { + if (!block.hasMetadata("placedBlock")) { Mining.miningXP(player, block); } } diff --git a/src/main/java/com/gmail/nossr50/skills/Excavation.java b/src/main/java/com/gmail/nossr50/skills/Excavation.java index 01bbf512d..b4259f991 100644 --- a/src/main/java/com/gmail/nossr50/skills/Excavation.java +++ b/src/main/java/com/gmail/nossr50/skills/Excavation.java @@ -126,7 +126,7 @@ public class Excavation { public static void gigaDrillBreaker(Player player, Block block) { Skills.abilityDurabilityLoss(player.getItemInHand(), LoadProperties.abilityDurabilityLoss); - if (block.getData() != (byte) 0x5) { + if (!block.hasMetadata("placedBlock")) { PlayerAnimationEvent armswing = new PlayerAnimationEvent(player); Bukkit.getPluginManager().callEvent(armswing); diff --git a/src/main/java/com/gmail/nossr50/skills/Herbalism.java b/src/main/java/com/gmail/nossr50/skills/Herbalism.java index ce57b7faf..eda4c05a8 100644 --- a/src/main/java/com/gmail/nossr50/skills/Herbalism.java +++ b/src/main/java/com/gmail/nossr50/skills/Herbalism.java @@ -135,7 +135,7 @@ public class Herbalism { Block b = block.getRelative(0, y, 0); if (b.getType().equals(Material.CACTUS)) { mat = Material.CACTUS; - if (!plugin.misc.blockWatchList.contains(b)) { + if (!b.hasMetadata("placedBlock")) { if(herbLevel > MAX_BONUS_LEVEL || (Math.random() * 1000 <= herbLevel)) { catciDrops++; } @@ -154,7 +154,7 @@ public class Herbalism { break; case MELON_BLOCK: - if (data != (byte) 0x5) { + if (!block.hasMetadata("placedBlock")) { mat = Material.MELON; xp = LoadProperties.mmelon; } @@ -169,7 +169,7 @@ public class Herbalism { case PUMPKIN: case JACK_O_LANTERN: - if (!plugin.misc.blockWatchList.contains(block)) { + if (!block.hasMetadata("placedBlock")) { mat = Material.getMaterial(id); xp = LoadProperties.mpumpkin; } @@ -177,7 +177,7 @@ public class Herbalism { case RED_ROSE: case YELLOW_FLOWER: - if (!plugin.misc.blockWatchList.contains(block)) { + if (!block.hasMetadata("placedBlock")) { mat = Material.getMaterial(id); xp = LoadProperties.mflower; } @@ -188,7 +188,7 @@ public class Herbalism { Block b = block.getRelative(0, y, 0); if (b.getType().equals(Material.SUGAR_CANE_BLOCK)) { mat = Material.SUGAR_CANE; - if (!plugin.misc.blockWatchList.contains(b)) { + if (!b.hasMetadata("placedBlock")) { if(herbLevel > MAX_BONUS_LEVEL || (Math.random() * 1000 <= herbLevel)) { caneDrops++; } @@ -199,14 +199,14 @@ public class Herbalism { break; case VINE: - if (!plugin.misc.blockWatchList.contains(block)) { + if (!block.hasMetadata("placedBlock")) { mat = type; xp = LoadProperties.mvines; } break; case WATER_LILY: - if (data != (byte) 0x5) { + if (!block.hasMetadata("placedBlock")) { mat = type; xp = LoadProperties.mlilypad; } diff --git a/src/main/java/com/gmail/nossr50/skills/Mining.java b/src/main/java/com/gmail/nossr50/skills/Mining.java index 4cac6fb76..ba3ca4625 100644 --- a/src/main/java/com/gmail/nossr50/skills/Mining.java +++ b/src/main/java/com/gmail/nossr50/skills/Mining.java @@ -156,7 +156,7 @@ public class Mining * @param plugin mcMMO plugin instance */ public static void miningBlockCheck(Player player, Block block, mcMMO plugin) { - if (plugin.misc.blockWatchList.contains(block) || block.getData() == (byte) 5) { + if (block.hasMetadata("placedBlock")) { return; } @@ -251,7 +251,7 @@ public class Mining case NETHERRACK: case SANDSTONE: case STONE: - if ((block.getData() == (byte) 5) || plugin.misc.blockWatchList.contains(block)) { + if (!block.hasMetadata("placedBlock")) { return; } diff --git a/src/main/java/com/gmail/nossr50/skills/WoodCutting.java b/src/main/java/com/gmail/nossr50/skills/WoodCutting.java index 0d0dc92f2..f57540fcd 100644 --- a/src/main/java/com/gmail/nossr50/skills/WoodCutting.java +++ b/src/main/java/com/gmail/nossr50/skills/WoodCutting.java @@ -97,9 +97,7 @@ public class WoodCutting break; } - //ItemStack item = new ItemStack(x.getType(), 1, (byte)0, type); - - if(!plugin.misc.blockWatchList.contains(x)) + if(!x.hasMetadata("placedBlock")) { WoodCutting.woodCuttingProcCheck(player, x); @@ -166,16 +164,16 @@ public class WoodCutting Block zPositive = world.getBlockAt(x, y, z+1); Block zNegative = world.getBlockAt(x, y, z-1); - if(!plugin.misc.blockWatchList.contains(currentBlock) && + if(!currentBlock.hasMetadata("placedBlock") && !isTooAgressive(isAirOrLeaves, xPositive) && treeFellerCompatible(xPositive) && !toBeFelled.contains(xPositive)) processTreeFelling(xPositive, world, toBeFelled, plugin); - if(!plugin.misc.blockWatchList.contains(currentBlock) && + if(!currentBlock.hasMetadata("placedBlock") && !isTooAgressive(isAirOrLeaves, xNegative) && treeFellerCompatible(xNegative) && !toBeFelled.contains(xNegative)) processTreeFelling(xNegative, world, toBeFelled, plugin); - if(!plugin.misc.blockWatchList.contains(currentBlock) && + if(!currentBlock.hasMetadata("placedBlock") && !isTooAgressive(isAirOrLeaves, zPositive) && treeFellerCompatible(zPositive) && !toBeFelled.contains(zPositive)) processTreeFelling(zPositive, world, toBeFelled, plugin); - if(!plugin.misc.blockWatchList.contains(currentBlock) && + if(!currentBlock.hasMetadata("placedBlock") && !isTooAgressive(isAirOrLeaves, zNegative) && treeFellerCompatible(zNegative) && !toBeFelled.contains(zNegative)) processTreeFelling(zNegative, world, toBeFelled, plugin); @@ -184,7 +182,7 @@ public class WoodCutting if(treeFellerCompatible(yPositive)) { - if(!plugin.misc.blockWatchList.contains(currentBlock) && !toBeFelled.contains(yPositive)) + if(!currentBlock.hasMetadata("placedBlock") && !toBeFelled.contains(yPositive)) { processTreeFelling(yPositive, world, toBeFelled, plugin); } @@ -217,7 +215,7 @@ public class WoodCutting int xp = 0; byte data = block.getData(); - if(plugin.misc.blockWatchList.contains(block)) + if(block.hasMetadata("placedBlock")) return; switch(data)