Changed placed block tracking to use metadata!

This commit is contained in:
GJ 2012-03-14 23:31:56 -04:00
parent 43ff0fa41a
commit 058cc3aac9
11 changed files with 28 additions and 113 deletions

View File

@ -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 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 Call of the Wild to summon animals already tamed.
! Changed mob spawner tracking to use new Metadata API ! Changed mob spawner tracking to use new Metadata API
! Changed block watch list to use new Metadata API
Version 1.3.02 Version 1.3.02
+ Added in game guides for Mining, Excavation, and Acrobatics. Simply type /skillname ? to access them + Added in game guides for Mining, Excavation, and Acrobatics. Simply type /skillname ? to access them

View File

@ -1,7 +1,6 @@
package com.gmail.nossr50; package com.gmail.nossr50;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block;
import com.gmail.nossr50.config.LoadProperties; import com.gmail.nossr50.config.LoadProperties;
@ -117,45 +116,4 @@ public class BlockChecks {
return false; 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);
}
} }

View File

@ -2,9 +2,7 @@ package com.gmail.nossr50.config;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -15,7 +13,6 @@ public class Misc
{ {
String location = "mcmmo.properties"; String location = "mcmmo.properties";
public HashSet<Block> blockWatchList = new HashSet<Block>();
public HashMap<Entity, Integer> arrowTracker = new HashMap<Entity, Integer>(); public HashMap<Entity, Integer> arrowTracker = new HashMap<Entity, Integer>();
public ArrayList<LivingEntity> bleedTracker = new ArrayList<LivingEntity>(); public ArrayList<LivingEntity> bleedTracker = new ArrayList<LivingEntity>();
public HashMap<Integer, Player> tntTracker = new HashMap<Integer, Player>(); public HashMap<Integer, Player> tntTracker = new HashMap<Integer, Player>();

View File

@ -30,6 +30,7 @@ import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.player.PlayerAnimationEvent; import org.bukkit.event.player.PlayerAnimationEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.metadata.FixedMetadataValue;
import org.getspout.spoutapi.SpoutManager; import org.getspout.spoutapi.SpoutManager;
import org.getspout.spoutapi.player.SpoutPlayer; import org.getspout.spoutapi.player.SpoutPlayer;
@ -74,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.setData((byte) 0x5); newLocation.setMetadata("placedBlock", new FixedMetadataValue(plugin, true));
break; 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 */ /* 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)) {
BlockChecks.watchBlock(mat, block, plugin); block.setMetadata("placedBlock", new FixedMetadataValue(plugin, true));
} }
if (id == LoadProperties.anvilID && LoadProperties.anvilmessages) { 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 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); Herbalism.herbalismProcCheck(block, player, event, plugin);
} }
@ -175,7 +176,7 @@ public class mcBlockListener implements Listener {
* EXCAVATION * 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)) { if (LoadProperties.excavationRequiresShovel && ItemChecks.isShovel(inhand)) {
Excavation.excavationProcCheck(block, player); Excavation.excavationProcCheck(block, player);
} }
@ -184,12 +185,9 @@ public class mcBlockListener implements Listener {
} }
} }
//Change the byte back when broken //Remove metadata when broken
if (block.getData() == (byte) 0x5 && BlockChecks.shouldBeWatched(mat)) { if (block.hasMetadata("placedBlock") && BlockChecks.shouldBeWatched(mat)) {
block.setData((byte) 0x0); block.removeMetadata("placedBlock", plugin);
}
else if(plugin.misc.blockWatchList.contains(block)) {
plugin.misc.blockWatchList.remove(block);
} }
} }

View File

@ -59,8 +59,6 @@ public class mcMMO extends JavaPlugin {
private Runnable mcMMO_Timer = new mcTimer(this); //BLEED AND REGENERATION private Runnable mcMMO_Timer = new mcTimer(this); //BLEED AND REGENERATION
private Runnable mcMMO_SaveTimer = new mcSaveTimer(this); //Periodic saving of Player Data 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 //Alias - Command
public HashMap<String, String> aliasMap = new HashMap<String, String>(); public HashMap<String, String> aliasMap = new HashMap<String, String>();
@ -152,10 +150,6 @@ public class mcMMO extends JavaPlugin {
//Bleed & Regen timer (Runs every 20 seconds) //Bleed & Regen timer (Runs every 20 seconds)
Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, mcMMO_Timer, 0, 20); 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(); registerCommands();
//Spout Stuff //Spout Stuff

View File

@ -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<Block> queue;
public ChangeDataValueTimer(ArrayDeque<Block> 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);
}
}
}

View File

@ -48,7 +48,7 @@ public class BlastMining {
blocksDropped.add(temp); blocksDropped.add(temp);
Mining.miningDrops(temp); Mining.miningDrops(temp);
if (temp.getData() != (byte) 0x5 && !plugin.misc.blockWatchList.contains(temp)) { if (!temp.hasMetadata("placedBlock")) {
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.getData() != (byte)5 && !plugin.misc.blockWatchList.contains(block)) { if (!block.hasMetadata("placedBlock")) {
Mining.miningXP(player, block); Mining.miningXP(player, block);
} }
} }

View File

@ -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.getData() != (byte) 0x5) { if (!block.hasMetadata("placedBlock")) {
PlayerAnimationEvent armswing = new PlayerAnimationEvent(player); PlayerAnimationEvent armswing = new PlayerAnimationEvent(player);
Bukkit.getPluginManager().callEvent(armswing); Bukkit.getPluginManager().callEvent(armswing);

View File

@ -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 (!plugin.misc.blockWatchList.contains(b)) { if (!b.hasMetadata("placedBlock")) {
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 (data != (byte) 0x5) { if (!block.hasMetadata("placedBlock")) {
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 (!plugin.misc.blockWatchList.contains(block)) { if (!block.hasMetadata("placedBlock")) {
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 (!plugin.misc.blockWatchList.contains(block)) { if (!block.hasMetadata("placedBlock")) {
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 (!plugin.misc.blockWatchList.contains(b)) { if (!b.hasMetadata("placedBlock")) {
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 (!plugin.misc.blockWatchList.contains(block)) { if (!block.hasMetadata("placedBlock")) {
mat = type; mat = type;
xp = LoadProperties.mvines; xp = LoadProperties.mvines;
} }
break; break;
case WATER_LILY: case WATER_LILY:
if (data != (byte) 0x5) { if (!block.hasMetadata("placedBlock")) {
mat = type; mat = type;
xp = LoadProperties.mlilypad; xp = LoadProperties.mlilypad;
} }

View File

@ -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 (plugin.misc.blockWatchList.contains(block) || block.getData() == (byte) 5) { if (block.hasMetadata("placedBlock")) {
return; return;
} }
@ -251,7 +251,7 @@ public class Mining
case NETHERRACK: case NETHERRACK:
case SANDSTONE: case SANDSTONE:
case STONE: case STONE:
if ((block.getData() == (byte) 5) || plugin.misc.blockWatchList.contains(block)) { if (!block.hasMetadata("placedBlock")) {
return; return;
} }

View File

@ -97,9 +97,7 @@ public class WoodCutting
break; break;
} }
//ItemStack item = new ItemStack(x.getType(), 1, (byte)0, type); if(!x.hasMetadata("placedBlock"))
if(!plugin.misc.blockWatchList.contains(x))
{ {
WoodCutting.woodCuttingProcCheck(player, x); WoodCutting.woodCuttingProcCheck(player, x);
@ -166,16 +164,16 @@ public class WoodCutting
Block zPositive = world.getBlockAt(x, y, z+1); Block zPositive = world.getBlockAt(x, y, z+1);
Block zNegative = 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)) !isTooAgressive(isAirOrLeaves, xPositive) && treeFellerCompatible(xPositive) && !toBeFelled.contains(xPositive))
processTreeFelling(xPositive, world, toBeFelled, plugin); processTreeFelling(xPositive, world, toBeFelled, plugin);
if(!plugin.misc.blockWatchList.contains(currentBlock) && if(!currentBlock.hasMetadata("placedBlock") &&
!isTooAgressive(isAirOrLeaves, xNegative) && treeFellerCompatible(xNegative) && !toBeFelled.contains(xNegative)) !isTooAgressive(isAirOrLeaves, xNegative) && treeFellerCompatible(xNegative) && !toBeFelled.contains(xNegative))
processTreeFelling(xNegative, world, toBeFelled, plugin); processTreeFelling(xNegative, world, toBeFelled, plugin);
if(!plugin.misc.blockWatchList.contains(currentBlock) && if(!currentBlock.hasMetadata("placedBlock") &&
!isTooAgressive(isAirOrLeaves, zPositive) && treeFellerCompatible(zPositive) && !toBeFelled.contains(zPositive)) !isTooAgressive(isAirOrLeaves, zPositive) && treeFellerCompatible(zPositive) && !toBeFelled.contains(zPositive))
processTreeFelling(zPositive, world, toBeFelled, plugin); processTreeFelling(zPositive, world, toBeFelled, plugin);
if(!plugin.misc.blockWatchList.contains(currentBlock) && if(!currentBlock.hasMetadata("placedBlock") &&
!isTooAgressive(isAirOrLeaves, zNegative) && treeFellerCompatible(zNegative) && !toBeFelled.contains(zNegative)) !isTooAgressive(isAirOrLeaves, zNegative) && treeFellerCompatible(zNegative) && !toBeFelled.contains(zNegative))
processTreeFelling(zNegative, world, toBeFelled, plugin); processTreeFelling(zNegative, world, toBeFelled, plugin);
@ -184,7 +182,7 @@ public class WoodCutting
if(treeFellerCompatible(yPositive)) if(treeFellerCompatible(yPositive))
{ {
if(!plugin.misc.blockWatchList.contains(currentBlock) && !toBeFelled.contains(yPositive)) if(!currentBlock.hasMetadata("placedBlock") && !toBeFelled.contains(yPositive))
{ {
processTreeFelling(yPositive, world, toBeFelled, plugin); processTreeFelling(yPositive, world, toBeFelled, plugin);
} }
@ -217,7 +215,7 @@ public class WoodCutting
int xp = 0; int xp = 0;
byte data = block.getData(); byte data = block.getData();
if(plugin.misc.blockWatchList.contains(block)) if(block.hasMetadata("placedBlock"))
return; return;
switch(data) switch(data)