Methods, BlockCache: BlockCache now considers ability names

This commit is contained in:
nathank33 2015-01-31 21:30:59 -08:00
parent aaa4e59505
commit 85c9c86743

View file

@ -46,6 +46,7 @@ import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState; import org.bukkit.block.BlockState;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.FallingBlock; import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.FallingSand; import org.bukkit.entity.FallingSand;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
@ -1456,15 +1457,22 @@ public class Methods {
ConcurrentHashMap<Block, BlockCacheElement> blockMap = blockProtectionCache.get(player.getName()); ConcurrentHashMap<Block, BlockCacheElement> blockMap = blockProtectionCache.get(player.getName());
Block block = loc.getBlock(); Block block = loc.getBlock();
if(blockMap.containsKey(block)) if(blockMap.containsKey(block)) {
return blockMap.get(block).isAllowed(); BlockCacheElement elem = blockMap.get(block);
// both abilities must be equal to each other to use the cache
if((ability == null && elem.getAbility() == null)
|| (ability != null && elem.getAbility() != null && elem.getAbility().equals(ability))) {
return elem.isAllowed();
}
}
boolean value = isRegionProtectedFromBuildPostCache(player, ability, loc); boolean value = isRegionProtectedFromBuildPostCache(player, ability, loc);
blockMap.put(block, new BlockCacheElement(player, block, value, System.currentTimeMillis())); blockMap.put(block, new BlockCacheElement(player, block, ability, value, System.currentTimeMillis()));
return value; return value;
} }
private static boolean isRegionProtectedFromBuildPostCache(Player player, String ability, Location loc) { public static boolean isRegionProtectedFromBuildPostCache(Player player, String ability, Location loc) {
boolean allowharmless = plugin.getConfig().getBoolean("Properties.RegionProtection.AllowHarmlessAbilities"); boolean allowharmless = plugin.getConfig().getBoolean("Properties.RegionProtection.AllowHarmlessAbilities");
boolean respectWorldGuard = plugin.getConfig().getBoolean("Properties.RegionProtection.RespectWorldGuard"); boolean respectWorldGuard = plugin.getConfig().getBoolean("Properties.RegionProtection.RespectWorldGuard");
@ -2668,12 +2676,14 @@ public class Methods {
public static class BlockCacheElement { public static class BlockCacheElement {
private Player player; private Player player;
private Block block; private Block block;
private String ability;
private boolean allowed; private boolean allowed;
private long time; private long time;
public BlockCacheElement(Player player, Block block, boolean allowed, long time) { public BlockCacheElement(Player player, Block block, String ability, boolean allowed, long time) {
this.player = player; this.player = player;
this.block = block; this.block = block;
this.ability = ability;
this.allowed = allowed; this.allowed = allowed;
this.time = time; this.time = time;
} }
@ -2710,6 +2720,14 @@ public class Methods {
this.allowed = allowed; this.allowed = allowed;
} }
public String getAbility() {
return ability;
}
public void setAbility(String ability) {
this.ability = ability;
}
} }
public static void startCacheCleaner(final double period) { public static void startCacheCleaner(final double period) {
@ -2729,5 +2747,22 @@ public class Methods {
}.runTaskTimer(ProjectKorra.plugin, 0, (long) (period / 20)); }.runTaskTimer(ProjectKorra.plugin, 0, (long) (period / 20));
} }
/** Checks if an entity is Undead **/
public static boolean isUndead(Entity entity) {
if (entity == null) return false;
if (entity.getType() == EntityType.ZOMBIE
|| entity.getType() == EntityType.BLAZE
|| entity.getType() == EntityType.GIANT
|| entity.getType() == EntityType.IRON_GOLEM
|| entity.getType() == EntityType.MAGMA_CUBE
|| entity.getType() == EntityType.PIG_ZOMBIE
|| entity.getType() == EntityType.SKELETON
|| entity.getType() == EntityType.SLIME
|| entity.getType() == EntityType.SNOWMAN
|| entity.getType() == EntityType.ZOMBIE) {
return true;
}
return false;
}
} }