Protect placeStore. It's ugly and still needs work.

This commit is contained in:
GJ 2013-02-17 00:40:11 -05:00
parent f61aed9f6c
commit 1fe182babe
14 changed files with 90 additions and 46 deletions

View File

@ -65,17 +65,17 @@ public class BlockListener implements Listener {
Block futureEmptyBlock = event.getBlock().getRelative(direction); // Block that would be air after piston is finished Block futureEmptyBlock = event.getBlock().getRelative(direction); // Block that would be air after piston is finished
for (Block b : blocks) { for (Block b : blocks) {
if (mcMMO.placeStore.isTrue(b)) { if (mcMMO.p.isPlaced(b)) {
b.getRelative(direction).setMetadata("pistonTrack", new FixedMetadataValue(plugin, true)); b.getRelative(direction).setMetadata("pistonTrack", new FixedMetadataValue(plugin, true));
if (b.equals(futureEmptyBlock)) { if (b.equals(futureEmptyBlock)) {
mcMMO.placeStore.setFalse(b); mcMMO.p.setNotPlaced(b);
} }
} }
} }
for (Block b : blocks) { for (Block b : blocks) {
if (b.getRelative(direction).hasMetadata("pistonTrack")) { if (b.getRelative(direction).hasMetadata("pistonTrack")) {
mcMMO.placeStore.setTrue(b.getRelative(direction)); mcMMO.p.setIsPlaced(b.getRelative(direction));
b.getRelative(direction).removeMetadata("pistonTrack", plugin); b.getRelative(direction).removeMetadata("pistonTrack", plugin);
} }
} }
@ -111,7 +111,7 @@ public class BlockListener 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(block)) { if (BlockChecks.shouldBeWatched(block)) {
mcMMO.placeStore.setTrue(block); mcMMO.p.setIsPlaced(block);
} }
if (Repair.anvilMessagesEnabled) { if (Repair.anvilMessagesEnabled) {
@ -169,7 +169,7 @@ public class BlockListener implements Listener {
} }
/* MINING */ /* MINING */
else if (BlockChecks.canBeSuperBroken(block) && ItemChecks.isPickaxe(heldItem) && player.hasPermission("mcmmo.skills.mining") && !mcMMO.placeStore.isTrue(block)) { else if (BlockChecks.canBeSuperBroken(block) && ItemChecks.isPickaxe(heldItem) && player.hasPermission("mcmmo.skills.mining") && !mcMMO.p.isPlaced(block)) {
MiningManager miningManager = new MiningManager(mcMMOPlayer); MiningManager miningManager = new MiningManager(mcMMOPlayer);
miningManager.miningBlockCheck(block); miningManager.miningBlockCheck(block);
@ -179,7 +179,7 @@ public class BlockListener implements Listener {
} }
/* WOOD CUTTING */ /* WOOD CUTTING */
else if (BlockChecks.isLog(block) && player.hasPermission("mcmmo.skills.woodcutting") && !mcMMO.placeStore.isTrue(block)) { else if (BlockChecks.isLog(block) && player.hasPermission("mcmmo.skills.woodcutting") && !mcMMO.p.isPlaced(block)) {
if (profile.getAbilityMode(AbilityType.TREE_FELLER) && player.hasPermission("mcmmo.ability.woodcutting.treefeller") && ItemChecks.isAxe(heldItem)) { if (profile.getAbilityMode(AbilityType.TREE_FELLER) && player.hasPermission("mcmmo.ability.woodcutting.treefeller") && ItemChecks.isAxe(heldItem)) {
Woodcutting.beginTreeFeller(mcMMOPlayer, block); Woodcutting.beginTreeFeller(mcMMOPlayer, block);
} }
@ -196,7 +196,7 @@ public class BlockListener implements Listener {
} }
/* EXCAVATION */ /* EXCAVATION */
else if (BlockChecks.canBeGigaDrillBroken(block) && ItemChecks.isShovel(heldItem) && player.hasPermission("mcmmo.skills.excavation") && !mcMMO.placeStore.isTrue(block)) { else if (BlockChecks.canBeGigaDrillBroken(block) && ItemChecks.isShovel(heldItem) && player.hasPermission("mcmmo.skills.excavation") && !mcMMO.p.isPlaced(block)) {
Excavation.excavationProcCheck(block, mcMMOPlayer); Excavation.excavationProcCheck(block, mcMMOPlayer);
if (profile.getAbilityMode(AbilityType.GIGA_DRILL_BREAKER)) { if (profile.getAbilityMode(AbilityType.GIGA_DRILL_BREAKER)) {
@ -205,8 +205,8 @@ public class BlockListener implements Listener {
} }
/* Remove metadata from placed watched blocks */ /* Remove metadata from placed watched blocks */
if (BlockChecks.shouldBeWatched(block) && mcMMO.placeStore.isTrue(block)) { if (BlockChecks.shouldBeWatched(block) && mcMMO.p.isPlaced(block)) {
mcMMO.placeStore.setFalse(block); mcMMO.p.setNotPlaced(block);
} }
} }
@ -233,7 +233,7 @@ public class BlockListener implements Listener {
if (player.hasPermission("mcmmo.ability.herbalism.hylianluck") && ItemChecks.isSword(heldItem)) { if (player.hasPermission("mcmmo.ability.herbalism.hylianluck") && ItemChecks.isSword(heldItem)) {
Herbalism.hylianLuck(block, player, event); Herbalism.hylianLuck(block, player, event);
} }
else if (BlockChecks.canBeFluxMined(block) && ItemChecks.isPickaxe(heldItem) && !heldItem.containsEnchantment(Enchantment.SILK_TOUCH) && player.hasPermission("mcmmo.ability.smelting.fluxmining") && !mcMMO.placeStore.isTrue(block)) { else if (BlockChecks.canBeFluxMined(block) && ItemChecks.isPickaxe(heldItem) && !heldItem.containsEnchantment(Enchantment.SILK_TOUCH) && player.hasPermission("mcmmo.ability.smelting.fluxmining") && !mcMMO.p.isPlaced(block)) {
SmeltingManager smeltingManager = new SmeltingManager(Users.getPlayer(player)); SmeltingManager smeltingManager = new SmeltingManager(Users.getPlayer(player));
smeltingManager.fluxMining(event); smeltingManager.fluxMining(event);
} }

View File

@ -65,13 +65,13 @@ public class EntityListener implements Listener {
if (entity instanceof FallingBlock) { if (entity instanceof FallingBlock) {
Block block = event.getBlock(); Block block = event.getBlock();
if (mcMMO.placeStore.isTrue(block) && !mcMMO.placeStore.isSpawnedMob(entity)) { if (mcMMO.p.isPlaced(block) && !mcMMO.p.isSpawned(entity)) {
mcMMO.placeStore.setFalse(block); mcMMO.p.setNotPlaced(block);
mcMMO.placeStore.addSpawnedMob(entity); mcMMO.p.setIsSpawned(entity);
} }
else if (mcMMO.placeStore.isSpawnedMob(entity)) { else if (mcMMO.p.isSpawned(entity)) {
mcMMO.placeStore.setTrue(block); mcMMO.p.setIsPlaced(block);
mcMMO.placeStore.removeSpawnedMob(entity); mcMMO.p.setNotSpawned(entity);
} }
} }
} }
@ -208,7 +208,7 @@ public class EntityListener implements Listener {
entity.setFireTicks(0); entity.setFireTicks(0);
BleedTimer.remove(entity); BleedTimer.remove(entity);
Archery.arrowRetrievalCheck(entity); Archery.arrowRetrievalCheck(entity);
mcMMO.placeStore.removeSpawnedMob(entity); mcMMO.p.setNotSpawned(entity);
} }
/** /**
@ -225,7 +225,8 @@ public class EntityListener implements Listener {
SpawnReason reason = event.getSpawnReason(); SpawnReason reason = event.getSpawnReason();
if (reason == SpawnReason.SPAWNER || reason == SpawnReason.SPAWNER_EGG) { if (reason == SpawnReason.SPAWNER || reason == SpawnReason.SPAWNER_EGG) {
mcMMO.placeStore.addSpawnedMob(event.getEntity()); event.getEntity().setRemoveWhenFarAway(false);
mcMMO.p.setIsSpawned(event.getEntity());
} }
} }

View File

@ -38,9 +38,9 @@ public class WorldListener implements Listener {
return; return;
} }
if (mcMMO.placeStore.isTrue(event.getLocation().getBlock())) { if (mcMMO.p.isPlaced(event.getLocation().getBlock())) {
for (BlockState block : event.getBlocks()) { for (BlockState block : event.getBlocks()) {
mcMMO.placeStore.setFalse(block.getBlock()); mcMMO.p.setNotPlaced(block.getBlock());
} }
} }
} }
@ -73,7 +73,7 @@ public class WorldListener implements Listener {
*/ */
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onWorldUnload(WorldUnloadEvent event) { public void onWorldUnload(WorldUnloadEvent event) {
mcMMO.placeStore.unloadWorld(event.getWorld()); mcMMO.p.setUnloaded(event.getWorld());
} }
/** /**
@ -83,9 +83,7 @@ public class WorldListener implements Listener {
*/ */
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onChunkUnload(ChunkUnloadEvent event) { public void onChunkUnload(ChunkUnloadEvent event) {
Chunk chunk = event.getChunk(); mcMMO.p.setUnloaded(event.getChunk(), event.getWorld());
mcMMO.placeStore.chunkUnloaded(chunk.getX(), chunk.getZ(), event.getWorld());
} }
/** /**
@ -100,7 +98,7 @@ public class WorldListener implements Listener {
for (Entity entity : entities) { for (Entity entity : entities) {
if (entity instanceof LivingEntity || entity instanceof FallingBlock) { if (entity instanceof LivingEntity || entity instanceof FallingBlock) {
mcMMO.placeStore.loadChunk(chunk.getX(), chunk.getZ(), event.getWorld(), entities); mcMMO.p.setLoaded(chunk, event.getWorld(), entities);
return; return;
} }
} }

View File

@ -8,8 +8,11 @@ import java.util.List;
import net.shatteredlands.shatt.backup.ZipLibrary; import net.shatteredlands.shatt.backup.ZipLibrary;
import org.bukkit.Chunk;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
@ -63,7 +66,7 @@ public class mcMMO extends JavaPlugin {
public static mcMMO p; public static mcMMO p;
public static ChunkManager placeStore; private ChunkManager placeStore;
public static RepairManager repairManager; public static RepairManager repairManager;
// Jar Stuff // Jar Stuff
@ -419,4 +422,48 @@ public class mcMMO extends JavaPlugin {
public void toggleXpEventEnabled() { public void toggleXpEventEnabled() {
xpEventEnabled = !xpEventEnabled; xpEventEnabled = !xpEventEnabled;
} }
public boolean isPlaced(Block block) {
return placeStore.isTrue(block);
}
public void setNotPlaced(Block block) {
placeStore.setFalse(block);
}
public void setIsPlaced(Block block) {
placeStore.setTrue(block);
}
public boolean isSpawned(Entity entity) {
return placeStore.isSpawnedMob(entity);
}
public void setIsSpawned(Entity entity) {
placeStore.addSpawnedMob(entity);
}
public void setNotSpawned(Entity entity) {
placeStore.removeSpawnedMob(entity);
}
public void setUnloaded(World world) {
placeStore.unloadWorld(world);
}
public void setUnloaded(Chunk chunk, World world) {
placeStore.chunkUnloaded(chunk.getX(), chunk.getZ(), world);
}
public void setLoaded(Chunk chunk, World world, Entity[] entities) {
placeStore.loadChunk(chunk.getX(), chunk.getZ(), world, entities);
}
public void cleanMobLists() {
placeStore.cleanMobLists();
}
public ChunkManager getChunkStore() {
return placeStore;
}
} }

View File

@ -33,6 +33,6 @@ public class MobStoreCleaner implements Runnable {
@Override @Override
public void run() { public void run() {
mcMMO.placeStore.cleanMobLists(); mcMMO.p.cleanMobLists();
} }
} }

View File

@ -22,11 +22,11 @@ public class StickyPistonTracker implements Runnable {
return; return;
} }
if (!mcMMO.placeStore.isTrue(originalBlock)) { if (!mcMMO.p.isPlaced(originalBlock)) {
return; return;
} }
mcMMO.placeStore.setFalse(originalBlock); mcMMO.p.setNotPlaced(originalBlock);
mcMMO.placeStore.setTrue(newBlock); mcMMO.p.setIsPlaced(newBlock);
} }
} }

View File

@ -130,7 +130,7 @@ public class Herbalism {
for (int y = 0; y <= 2; y++) { for (int y = 0; y <= 2; y++) {
Block relativeBlock = block.getRelative(BlockFace.UP, y); Block relativeBlock = block.getRelative(BlockFace.UP, y);
if (relativeBlock.getType() == blockType && !mcMMO.placeStore.isTrue(relativeBlock)) { if (relativeBlock.getType() == blockType && !mcMMO.p.isPlaced(relativeBlock)) {
dropAmount++; dropAmount++;
} }
} }
@ -177,7 +177,7 @@ public class Herbalism {
greenThumbWheat(block, player, plugin); greenThumbWheat(block, player, plugin);
} }
else { else {
if (!mcMMO.placeStore.isTrue(block)) { if (!mcMMO.p.isPlaced(block)) {
dropItem = herbalismBlock.getDropItem(); dropItem = herbalismBlock.getDropItem();
xp = herbalismBlock.getXpGain(); xp = herbalismBlock.getXpGain();
} }
@ -332,8 +332,8 @@ public class Herbalism {
case RED_ROSE: case RED_ROSE:
case YELLOW_FLOWER: case YELLOW_FLOWER:
if (mcMMO.placeStore.isTrue(block)) { if (mcMMO.p.isPlaced(block)) {
mcMMO.placeStore.setFalse(block); mcMMO.p.setNotPlaced(block);
return; return;
} }

View File

@ -51,7 +51,7 @@ public class BlastMiningDropEventHandler {
McMMOPlayer mcMMOPlayer = manager.getMcMMOPlayer(); McMMOPlayer mcMMOPlayer = manager.getMcMMOPlayer();
for (Block block : droppedOres) { for (Block block : droppedOres) {
if (!mcMMO.placeStore.isTrue(block)) { if (!mcMMO.p.isPlaced(block)) {
Mining.miningXP(mcMMOPlayer, block, block.getType()); Mining.miningXP(mcMMOPlayer, block, block.getType());
} }
} }
@ -66,7 +66,7 @@ public class BlastMiningDropEventHandler {
droppedOres.add(block); droppedOres.add(block);
Mining.miningDrops(block, location, type); Mining.miningDrops(block, location, type);
if (!mcMMO.placeStore.isTrue(block)) { if (!mcMMO.p.isPlaced(block)) {
for (int i = 1 ; i < dropMultiplier ; i++) { for (int i = 1 ; i < dropMultiplier ; i++) {
droppedOres.add(block); droppedOres.add(block);
Mining.miningDrops(block, location, type); Mining.miningDrops(block, location, type);

View File

@ -67,7 +67,7 @@ public class CallOfTheWildEventHandler {
return; return;
LivingEntity entity = (LivingEntity) player.getWorld().spawnEntity(player.getLocation(), type); LivingEntity entity = (LivingEntity) player.getWorld().spawnEntity(player.getLocation(), type);
mcMMO.placeStore.addSpawnedPet(entity); mcMMO.p.setIsSpawned(entity);
((Tameable) entity).setOwner(player); ((Tameable) entity).setOwner(player);

View File

@ -27,7 +27,7 @@ public class TamingManager extends SkillManager {
* @param event The event to award XP for * @param event The event to award XP for
*/ */
public void awardTamingXP(EntityTameEvent event) { public void awardTamingXP(EntityTameEvent event) {
if (mcMMO.placeStore.isSpawnedMob(event.getEntity())) { if (mcMMO.p.isSpawned(event.getEntity())) {
return; return;
} }

View File

@ -459,8 +459,8 @@ public final class CombatTools {
baseXP = 20 * configInstance.getPlayerVersusPlayerXP(); baseXP = 20 * configInstance.getPlayerVersusPlayerXP();
} }
} }
else if (!mcMMO.placeStore.isSpawnedMob(target)) { else if (!mcMMO.p.isSpawned(target)) {
if (target instanceof Animals && !mcMMO.placeStore.isSpawnedPet(target)) { if (target instanceof Animals) {
if (ModChecks.isCustomEntity(target)) { if (ModChecks.isCustomEntity(target)) {
baseXP = ModChecks.getCustomEntity(target).getXpMultiplier(); baseXP = ModChecks.getCustomEntity(target).getXpMultiplier();
} }

View File

@ -112,7 +112,7 @@ public final class TreeFeller {
* @param treeFellerBlocks List of blocks to be removed * @param treeFellerBlocks List of blocks to be removed
*/ */
private static void handleBlock(Block block, List<Block> futureCenterBlocks, List<Block> treeFellerBlocks) { private static void handleBlock(Block block, List<Block> futureCenterBlocks, List<Block> treeFellerBlocks) {
if (!BlockChecks.treeFellerCompatible(block) || mcMMO.placeStore.isTrue(block) || treeFellerBlocks.contains(block)) { if (!BlockChecks.treeFellerCompatible(block) || mcMMO.p.isPlaced(block) || treeFellerBlocks.contains(block)) {
return; return;
} }

View File

@ -619,12 +619,10 @@ public class HashChunkManager implements ChunkManager {
List<Entity> tempSpawnedMobs = new ArrayList<Entity>(spawnedMobs); List<Entity> tempSpawnedMobs = new ArrayList<Entity>(spawnedMobs);
for (Entity entity : tempSpawnedMobs) { for (Entity entity : tempSpawnedMobs) {
if (entity.isDead()) if (entity.isDead() || !entity.isValid()) {
mobsToRemove.add(entity);
if (!entity.isValid())
mobsToRemove.add(entity); mobsToRemove.add(entity);
} }
}
spawnedMobs.removeAll(mobsToRemove); spawnedMobs.removeAll(mobsToRemove);
mobsToRemove.clear(); mobsToRemove.clear();

View File

@ -34,7 +34,7 @@ public class BlockStoreConversionZDirectory implements Runnable {
this.world = world; this.world = world;
this.scheduler = mcMMO.p.getServer().getScheduler(); this.scheduler = mcMMO.p.getServer().getScheduler();
this.manager = new HashChunkletManager(); this.manager = new HashChunkletManager();
this.newManager = (HashChunkManager) mcMMO.placeStore; this.newManager = (HashChunkManager) mcMMO.p.getChunkStore();
this.dataDir = dataDir; this.dataDir = dataDir;
this.xDir = xDir; this.xDir = xDir;