Skip to content

Commit

Permalink
Count PISTON_HEAD and MOVING_PISTON
Browse files Browse the repository at this point in the history
  • Loading branch information
YellowZaki committed Oct 28, 2020
1 parent eb3efc0 commit 88879f5
Showing 1 changed file with 37 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.type.TechnicalPiston;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
Expand Down Expand Up @@ -282,26 +283,44 @@ private int process(Block b, boolean add) {
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
public Material fixMaterial(Object b) {
Material mat;
if (b instanceof Block) {
mat = ((Block) b).getType();
}
else {
mat = (Material) b;
}

if (mat == Material.REDSTONE_WALL_TORCH) {
return Material.REDSTONE_TORCH;
} else if (b == Material.WALL_TORCH) {
} else if (mat == Material.WALL_TORCH) {
return Material.TORCH;
} else if (b == Material.ZOMBIE_WALL_HEAD) {
} else if (mat == Material.ZOMBIE_WALL_HEAD) {
return Material.ZOMBIE_HEAD;
} else if (b == Material.CREEPER_WALL_HEAD) {
} else if (mat == Material.CREEPER_WALL_HEAD) {
return Material.CREEPER_HEAD;
} else if (b == Material.PLAYER_WALL_HEAD) {
} else if (mat == Material.PLAYER_WALL_HEAD) {
return Material.PLAYER_HEAD;
} else if (b == Material.DRAGON_WALL_HEAD) {
} else if (mat == Material.DRAGON_WALL_HEAD) {
return Material.DRAGON_HEAD;
} else if (b != null && b == Material.getMaterial("BAMBOO_SAPLING")) {
} 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 b;
}

return mat;
}
/**
* Check if a block can be
*
Expand All @@ -311,7 +330,7 @@ public Material fixMaterial(Material b) {
* @return limit amount if over limit, or -1 if no limitation
*/
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;
}
// Check if on island
Expand All @@ -325,24 +344,24 @@ private int process(Block b, boolean add, Material changeTo) {
islandCountMap.putIfAbsent(id, new IslandBlockCount(id, gameMode));
if (add) {
// Check limit
int limit = checkLimit(b.getWorld(), fixMaterial(b.getType()), id);
int limit = checkLimit(b.getWorld(), fixMaterial(b), id);
if (limit > -1) {
return limit;
}
islandCountMap.get(id).add(fixMaterial(b.getType()));
islandCountMap.get(id).add(fixMaterial(b));
} else {
if (islandCountMap.containsKey(id)) {
// Check for changes
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
int limit = checkLimit(b.getWorld(), fixed, id);
if (limit > -1) {
return limit;
}
islandCountMap.get(id).add(fixed);
}
islandCountMap.get(id).remove(fixMaterial(b.getType()));
islandCountMap.get(id).remove(fixMaterial(b));
}
}
updateSaveMap(id);
Expand All @@ -363,7 +382,7 @@ public void removeBlock(Block b) {
// Invalid world
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);
});
}
Expand Down

0 comments on commit 88879f5

Please sign in to comment.