mirror of
https://github.com/BentoBoxWorld/Limits.git
synced 2024-09-27 14:12:57 +02:00
Count PISTON_HEAD and MOVING_PISTON
This commit is contained in:
parent
eb3efc03b4
commit
88879f5638
@ -15,6 +15,7 @@ import org.bukkit.Material;
|
|||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
|
import org.bukkit.block.data.type.TechnicalPiston;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
@ -282,24 +283,42 @@ public class BlockLimitsListener implements Listener {
|
|||||||
return process(b, add, b.getType());
|
return process(b, add, b.getType());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return equivalents.
|
|
||||||
public Material fixMaterial(Material b) {
|
|
||||||
if (b == Material.REDSTONE_WALL_TORCH) {
|
// Return equivalents. b can be Block/Material
|
||||||
return Material.REDSTONE_TORCH;
|
public Material fixMaterial(Object b) {
|
||||||
} else if (b == Material.WALL_TORCH) {
|
Material mat;
|
||||||
return Material.TORCH;
|
if (b instanceof Block) {
|
||||||
} else if (b == Material.ZOMBIE_WALL_HEAD) {
|
mat = ((Block) b).getType();
|
||||||
return Material.ZOMBIE_HEAD;
|
|
||||||
} else if (b == Material.CREEPER_WALL_HEAD) {
|
|
||||||
return Material.CREEPER_HEAD;
|
|
||||||
} else if (b == Material.PLAYER_WALL_HEAD) {
|
|
||||||
return Material.PLAYER_HEAD;
|
|
||||||
} else if (b == Material.DRAGON_WALL_HEAD) {
|
|
||||||
return Material.DRAGON_HEAD;
|
|
||||||
} else if (b != null && b == Material.getMaterial("BAMBOO_SAPLING")) {
|
|
||||||
return Material.getMaterial("BAMBOO");
|
|
||||||
}
|
}
|
||||||
return b;
|
else {
|
||||||
|
mat = (Material) b;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mat == Material.REDSTONE_WALL_TORCH) {
|
||||||
|
return Material.REDSTONE_TORCH;
|
||||||
|
} else if (mat == Material.WALL_TORCH) {
|
||||||
|
return Material.TORCH;
|
||||||
|
} else if (mat == Material.ZOMBIE_WALL_HEAD) {
|
||||||
|
return Material.ZOMBIE_HEAD;
|
||||||
|
} else if (mat == Material.CREEPER_WALL_HEAD) {
|
||||||
|
return Material.CREEPER_HEAD;
|
||||||
|
} else if (mat == Material.PLAYER_WALL_HEAD) {
|
||||||
|
return Material.PLAYER_HEAD;
|
||||||
|
} else if (mat == Material.DRAGON_WALL_HEAD) {
|
||||||
|
return Material.DRAGON_HEAD;
|
||||||
|
} else if (mat != null && mat == Material.getMaterial("BAMBOO_SAPLING")) {
|
||||||
|
return Material.getMaterial("BAMBOO");
|
||||||
|
} else if (mat == Material.PISTON_HEAD || mat == Material.MOVING_PISTON) {
|
||||||
|
Block block = ((Block) b);
|
||||||
|
TechnicalPiston tp = (TechnicalPiston) block.getBlockData();
|
||||||
|
if (tp.getType() == TechnicalPiston.Type.NORMAL) {
|
||||||
|
return Material.PISTON;
|
||||||
|
} else {
|
||||||
|
return Material.STICKY_PISTON;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return mat;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -311,7 +330,7 @@ public class BlockLimitsListener implements Listener {
|
|||||||
* @return limit amount if over limit, or -1 if no limitation
|
* @return limit amount if over limit, or -1 if no limitation
|
||||||
*/
|
*/
|
||||||
private int process(Block b, boolean add, Material changeTo) {
|
private int process(Block b, boolean add, Material changeTo) {
|
||||||
if (DO_NOT_COUNT.contains(fixMaterial(b.getType())) || !addon.inGameModeWorld(b.getWorld())) {
|
if (DO_NOT_COUNT.contains(fixMaterial(b)) || !addon.inGameModeWorld(b.getWorld())) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
// Check if on island
|
// Check if on island
|
||||||
@ -325,16 +344,16 @@ public class BlockLimitsListener implements Listener {
|
|||||||
islandCountMap.putIfAbsent(id, new IslandBlockCount(id, gameMode));
|
islandCountMap.putIfAbsent(id, new IslandBlockCount(id, gameMode));
|
||||||
if (add) {
|
if (add) {
|
||||||
// Check limit
|
// Check limit
|
||||||
int limit = checkLimit(b.getWorld(), fixMaterial(b.getType()), id);
|
int limit = checkLimit(b.getWorld(), fixMaterial(b), id);
|
||||||
if (limit > -1) {
|
if (limit > -1) {
|
||||||
return limit;
|
return limit;
|
||||||
}
|
}
|
||||||
islandCountMap.get(id).add(fixMaterial(b.getType()));
|
islandCountMap.get(id).add(fixMaterial(b));
|
||||||
} else {
|
} else {
|
||||||
if (islandCountMap.containsKey(id)) {
|
if (islandCountMap.containsKey(id)) {
|
||||||
// Check for changes
|
// Check for changes
|
||||||
Material fixed = fixMaterial(changeTo);
|
Material fixed = fixMaterial(changeTo);
|
||||||
if (!fixed.equals(fixMaterial(b.getType())) && fixed.isBlock() && !DO_NOT_COUNT.contains(fixed)) {
|
if (!fixed.equals(fixMaterial(b)) && fixed.isBlock() && !DO_NOT_COUNT.contains(fixed)) {
|
||||||
// Check limit
|
// Check limit
|
||||||
int limit = checkLimit(b.getWorld(), fixed, id);
|
int limit = checkLimit(b.getWorld(), fixed, id);
|
||||||
if (limit > -1) {
|
if (limit > -1) {
|
||||||
@ -342,7 +361,7 @@ public class BlockLimitsListener implements Listener {
|
|||||||
}
|
}
|
||||||
islandCountMap.get(id).add(fixed);
|
islandCountMap.get(id).add(fixed);
|
||||||
}
|
}
|
||||||
islandCountMap.get(id).remove(fixMaterial(b.getType()));
|
islandCountMap.get(id).remove(fixMaterial(b));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
updateSaveMap(id);
|
updateSaveMap(id);
|
||||||
@ -363,7 +382,7 @@ public class BlockLimitsListener implements Listener {
|
|||||||
// Invalid world
|
// Invalid world
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
islandCountMap.computeIfAbsent(id, k -> new IslandBlockCount(id, gameMode)).remove(fixMaterial(b.getType()));
|
islandCountMap.computeIfAbsent(id, k -> new IslandBlockCount(id, gameMode)).remove(fixMaterial(b));
|
||||||
updateSaveMap(id);
|
updateSaveMap(id);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user