mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-25 22:56:45 +01:00
Protect placeStore. It's ugly and still needs work.
This commit is contained in:
parent
f61aed9f6c
commit
1fe182babe
@ -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);
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,6 @@ public class MobStoreCleaner implements Runnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
mcMMO.placeStore.cleanMobLists();
|
||||
mcMMO.p.cleanMobLists();
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -112,7 +112,7 @@ public final class TreeFeller {
|
||||
* @param treeFellerBlocks List of blocks to be removed
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -619,12 +619,10 @@ public class HashChunkManager implements ChunkManager {
|
||||
|
||||
List<Entity> tempSpawnedMobs = new ArrayList<Entity>(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);
|
||||
mobsToRemove.clear();
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user