diff --git a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java index 94bc51825..84f1fd2ca 100644 --- a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java @@ -65,17 +65,17 @@ public class BlockListener implements Listener { Block futureEmptyBlock = event.getBlock().getRelative(direction); // Block that would be air after piston is finished for (Block b : blocks) { - if (mcMMO.placeStore.isTrue(b)) { + if (mcMMO.p.isPlaced(b)) { b.getRelative(direction).setMetadata("pistonTrack", new FixedMetadataValue(plugin, true)); if (b.equals(futureEmptyBlock)) { - mcMMO.placeStore.setFalse(b); + mcMMO.p.setNotPlaced(b); } } } for (Block b : blocks) { if (b.getRelative(direction).hasMetadata("pistonTrack")) { - mcMMO.placeStore.setTrue(b.getRelative(direction)); + mcMMO.p.setIsPlaced(b.getRelative(direction)); 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 */ if (BlockChecks.shouldBeWatched(block)) { - mcMMO.placeStore.setTrue(block); + mcMMO.p.setIsPlaced(block); } if (Repair.anvilMessagesEnabled) { @@ -169,7 +169,7 @@ public class BlockListener implements Listener { } /* 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.miningBlockCheck(block); @@ -179,7 +179,7 @@ public class BlockListener implements Listener { } /* 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)) { Woodcutting.beginTreeFeller(mcMMOPlayer, block); } @@ -196,7 +196,7 @@ public class BlockListener implements Listener { } /* 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); if (profile.getAbilityMode(AbilityType.GIGA_DRILL_BREAKER)) { @@ -205,8 +205,8 @@ public class BlockListener implements Listener { } /* Remove metadata from placed watched blocks */ - if (BlockChecks.shouldBeWatched(block) && mcMMO.placeStore.isTrue(block)) { - mcMMO.placeStore.setFalse(block); + if (BlockChecks.shouldBeWatched(block) && mcMMO.p.isPlaced(block)) { + mcMMO.p.setNotPlaced(block); } } @@ -233,7 +233,7 @@ public class BlockListener implements Listener { if (player.hasPermission("mcmmo.ability.herbalism.hylianluck") && ItemChecks.isSword(heldItem)) { 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.fluxMining(event); } diff --git a/src/main/java/com/gmail/nossr50/listeners/EntityListener.java b/src/main/java/com/gmail/nossr50/listeners/EntityListener.java index d313d8a18..09b70a1a2 100644 --- a/src/main/java/com/gmail/nossr50/listeners/EntityListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/EntityListener.java @@ -65,13 +65,13 @@ public class EntityListener implements Listener { if (entity instanceof FallingBlock) { Block block = event.getBlock(); - if (mcMMO.placeStore.isTrue(block) && !mcMMO.placeStore.isSpawnedMob(entity)) { - mcMMO.placeStore.setFalse(block); - mcMMO.placeStore.addSpawnedMob(entity); + if (mcMMO.p.isPlaced(block) && !mcMMO.p.isSpawned(entity)) { + mcMMO.p.setNotPlaced(block); + mcMMO.p.setIsSpawned(entity); } - else if (mcMMO.placeStore.isSpawnedMob(entity)) { - mcMMO.placeStore.setTrue(block); - mcMMO.placeStore.removeSpawnedMob(entity); + else if (mcMMO.p.isSpawned(entity)) { + mcMMO.p.setIsPlaced(block); + mcMMO.p.setNotSpawned(entity); } } } @@ -208,7 +208,7 @@ public class EntityListener implements Listener { entity.setFireTicks(0); BleedTimer.remove(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(); if (reason == SpawnReason.SPAWNER || reason == SpawnReason.SPAWNER_EGG) { - mcMMO.placeStore.addSpawnedMob(event.getEntity()); + event.getEntity().setRemoveWhenFarAway(false); + mcMMO.p.setIsSpawned(event.getEntity()); } } diff --git a/src/main/java/com/gmail/nossr50/listeners/WorldListener.java b/src/main/java/com/gmail/nossr50/listeners/WorldListener.java index 508ff7b5f..8c135b1eb 100644 --- a/src/main/java/com/gmail/nossr50/listeners/WorldListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/WorldListener.java @@ -38,9 +38,9 @@ public class WorldListener implements Listener { return; } - if (mcMMO.placeStore.isTrue(event.getLocation().getBlock())) { + if (mcMMO.p.isPlaced(event.getLocation().getBlock())) { 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) 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) public void onChunkUnload(ChunkUnloadEvent event) { - Chunk chunk = event.getChunk(); - - mcMMO.placeStore.chunkUnloaded(chunk.getX(), chunk.getZ(), event.getWorld()); + mcMMO.p.setUnloaded(event.getChunk(), event.getWorld()); } /** @@ -100,7 +98,7 @@ public class WorldListener implements Listener { for (Entity entity : entities) { 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; } } diff --git a/src/main/java/com/gmail/nossr50/mcMMO.java b/src/main/java/com/gmail/nossr50/mcMMO.java index bc1c7e6ab..d0424701f 100644 --- a/src/main/java/com/gmail/nossr50/mcMMO.java +++ b/src/main/java/com/gmail/nossr50/mcMMO.java @@ -8,8 +8,11 @@ import java.util.List; import net.shatteredlands.shatt.backup.ZipLibrary; +import org.bukkit.Chunk; import org.bukkit.OfflinePlayer; +import org.bukkit.World; import org.bukkit.block.Block; +import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; @@ -63,7 +66,7 @@ public class mcMMO extends JavaPlugin { public static mcMMO p; - public static ChunkManager placeStore; + private ChunkManager placeStore; public static RepairManager repairManager; // Jar Stuff @@ -419,4 +422,48 @@ public class mcMMO extends JavaPlugin { public void toggleXpEventEnabled() { 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; + } } diff --git a/src/main/java/com/gmail/nossr50/runnables/MobStoreCleaner.java b/src/main/java/com/gmail/nossr50/runnables/MobStoreCleaner.java index 4261f1d5d..021989e0a 100755 --- a/src/main/java/com/gmail/nossr50/runnables/MobStoreCleaner.java +++ b/src/main/java/com/gmail/nossr50/runnables/MobStoreCleaner.java @@ -33,6 +33,6 @@ public class MobStoreCleaner implements Runnable { @Override public void run() { - mcMMO.placeStore.cleanMobLists(); + mcMMO.p.cleanMobLists(); } } \ No newline at end of file diff --git a/src/main/java/com/gmail/nossr50/runnables/StickyPistonTracker.java b/src/main/java/com/gmail/nossr50/runnables/StickyPistonTracker.java index c2d325505..e83f693a4 100644 --- a/src/main/java/com/gmail/nossr50/runnables/StickyPistonTracker.java +++ b/src/main/java/com/gmail/nossr50/runnables/StickyPistonTracker.java @@ -22,11 +22,11 @@ public class StickyPistonTracker implements Runnable { return; } - if (!mcMMO.placeStore.isTrue(originalBlock)) { + if (!mcMMO.p.isPlaced(originalBlock)) { return; } - mcMMO.placeStore.setFalse(originalBlock); - mcMMO.placeStore.setTrue(newBlock); + mcMMO.p.setNotPlaced(originalBlock); + mcMMO.p.setIsPlaced(newBlock); } } diff --git a/src/main/java/com/gmail/nossr50/skills/herbalism/Herbalism.java b/src/main/java/com/gmail/nossr50/skills/herbalism/Herbalism.java index 87351af5e..fd4c86fe0 100644 --- a/src/main/java/com/gmail/nossr50/skills/herbalism/Herbalism.java +++ b/src/main/java/com/gmail/nossr50/skills/herbalism/Herbalism.java @@ -130,7 +130,7 @@ public class Herbalism { for (int y = 0; y <= 2; 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++; } } @@ -177,7 +177,7 @@ public class Herbalism { greenThumbWheat(block, player, plugin); } else { - if (!mcMMO.placeStore.isTrue(block)) { + if (!mcMMO.p.isPlaced(block)) { dropItem = herbalismBlock.getDropItem(); xp = herbalismBlock.getXpGain(); } @@ -332,8 +332,8 @@ public class Herbalism { case RED_ROSE: case YELLOW_FLOWER: - if (mcMMO.placeStore.isTrue(block)) { - mcMMO.placeStore.setFalse(block); + if (mcMMO.p.isPlaced(block)) { + mcMMO.p.setNotPlaced(block); return; } diff --git a/src/main/java/com/gmail/nossr50/skills/mining/BlastMiningDropEventHandler.java b/src/main/java/com/gmail/nossr50/skills/mining/BlastMiningDropEventHandler.java index dd5f9055d..7dd957209 100644 --- a/src/main/java/com/gmail/nossr50/skills/mining/BlastMiningDropEventHandler.java +++ b/src/main/java/com/gmail/nossr50/skills/mining/BlastMiningDropEventHandler.java @@ -51,7 +51,7 @@ public class BlastMiningDropEventHandler { McMMOPlayer mcMMOPlayer = manager.getMcMMOPlayer(); for (Block block : droppedOres) { - if (!mcMMO.placeStore.isTrue(block)) { + if (!mcMMO.p.isPlaced(block)) { Mining.miningXP(mcMMOPlayer, block, block.getType()); } } @@ -66,7 +66,7 @@ public class BlastMiningDropEventHandler { droppedOres.add(block); Mining.miningDrops(block, location, type); - if (!mcMMO.placeStore.isTrue(block)) { + if (!mcMMO.p.isPlaced(block)) { for (int i = 1 ; i < dropMultiplier ; i++) { droppedOres.add(block); Mining.miningDrops(block, location, type); diff --git a/src/main/java/com/gmail/nossr50/skills/taming/CallOfTheWildEventHandler.java b/src/main/java/com/gmail/nossr50/skills/taming/CallOfTheWildEventHandler.java index c6de8e203..37a0b0298 100644 --- a/src/main/java/com/gmail/nossr50/skills/taming/CallOfTheWildEventHandler.java +++ b/src/main/java/com/gmail/nossr50/skills/taming/CallOfTheWildEventHandler.java @@ -67,7 +67,7 @@ public class CallOfTheWildEventHandler { return; LivingEntity entity = (LivingEntity) player.getWorld().spawnEntity(player.getLocation(), type); - mcMMO.placeStore.addSpawnedPet(entity); + mcMMO.p.setIsSpawned(entity); ((Tameable) entity).setOwner(player); diff --git a/src/main/java/com/gmail/nossr50/skills/taming/TamingManager.java b/src/main/java/com/gmail/nossr50/skills/taming/TamingManager.java index 3bd2651a7..891ce8fb7 100644 --- a/src/main/java/com/gmail/nossr50/skills/taming/TamingManager.java +++ b/src/main/java/com/gmail/nossr50/skills/taming/TamingManager.java @@ -27,7 +27,7 @@ public class TamingManager extends SkillManager { * @param event The event to award XP for */ public void awardTamingXP(EntityTameEvent event) { - if (mcMMO.placeStore.isSpawnedMob(event.getEntity())) { + if (mcMMO.p.isSpawned(event.getEntity())) { return; } diff --git a/src/main/java/com/gmail/nossr50/skills/utilities/CombatTools.java b/src/main/java/com/gmail/nossr50/skills/utilities/CombatTools.java index 21559cff1..b93dce198 100644 --- a/src/main/java/com/gmail/nossr50/skills/utilities/CombatTools.java +++ b/src/main/java/com/gmail/nossr50/skills/utilities/CombatTools.java @@ -459,8 +459,8 @@ public final class CombatTools { baseXP = 20 * configInstance.getPlayerVersusPlayerXP(); } } - else if (!mcMMO.placeStore.isSpawnedMob(target)) { - if (target instanceof Animals && !mcMMO.placeStore.isSpawnedPet(target)) { + else if (!mcMMO.p.isSpawned(target)) { + if (target instanceof Animals) { if (ModChecks.isCustomEntity(target)) { baseXP = ModChecks.getCustomEntity(target).getXpMultiplier(); } diff --git a/src/main/java/com/gmail/nossr50/skills/woodcutting/TreeFeller.java b/src/main/java/com/gmail/nossr50/skills/woodcutting/TreeFeller.java index d173b2dc2..90b875099 100644 --- a/src/main/java/com/gmail/nossr50/skills/woodcutting/TreeFeller.java +++ b/src/main/java/com/gmail/nossr50/skills/woodcutting/TreeFeller.java @@ -112,7 +112,7 @@ public final class TreeFeller { * @param treeFellerBlocks List of blocks to be removed */ private static void handleBlock(Block block, List futureCenterBlocks, List treeFellerBlocks) { - if (!BlockChecks.treeFellerCompatible(block) || mcMMO.placeStore.isTrue(block) || treeFellerBlocks.contains(block)) { + if (!BlockChecks.treeFellerCompatible(block) || mcMMO.p.isPlaced(block) || treeFellerBlocks.contains(block)) { return; } diff --git a/src/main/java/com/gmail/nossr50/util/blockmeta/chunkmeta/HashChunkManager.java b/src/main/java/com/gmail/nossr50/util/blockmeta/chunkmeta/HashChunkManager.java index e11936b44..4029960bc 100755 --- a/src/main/java/com/gmail/nossr50/util/blockmeta/chunkmeta/HashChunkManager.java +++ b/src/main/java/com/gmail/nossr50/util/blockmeta/chunkmeta/HashChunkManager.java @@ -619,11 +619,9 @@ public class HashChunkManager implements ChunkManager { List tempSpawnedMobs = new ArrayList(spawnedMobs); for (Entity entity : tempSpawnedMobs) { - if (entity.isDead()) - mobsToRemove.add(entity); - - if (!entity.isValid()) + if (entity.isDead() || !entity.isValid()) { mobsToRemove.add(entity); + } } spawnedMobs.removeAll(mobsToRemove); diff --git a/src/main/java/com/gmail/nossr50/util/blockmeta/conversion/BlockStoreConversionZDirectory.java b/src/main/java/com/gmail/nossr50/util/blockmeta/conversion/BlockStoreConversionZDirectory.java index 91f018246..d8a93cb49 100755 --- a/src/main/java/com/gmail/nossr50/util/blockmeta/conversion/BlockStoreConversionZDirectory.java +++ b/src/main/java/com/gmail/nossr50/util/blockmeta/conversion/BlockStoreConversionZDirectory.java @@ -34,7 +34,7 @@ public class BlockStoreConversionZDirectory implements Runnable { this.world = world; this.scheduler = mcMMO.p.getServer().getScheduler(); this.manager = new HashChunkletManager(); - this.newManager = (HashChunkManager) mcMMO.placeStore; + this.newManager = (HashChunkManager) mcMMO.p.getChunkStore(); this.dataDir = dataDir; this.xDir = xDir;