FlagWar
FlagWar copied to clipboard
Suggestion: debug messages for flag depth
add some indicator that you are placing flags below depth. I thought flagwar was broken on my server because the world im using is naturally low and at some spots flagwar is below the default depth. This took me longer than id like to admit to find out. A simple console or in game message when placing flags below depth would have made this so much easier to notice.
It is currently a small mystery as to why this code did not result in a message being sent about the depth being the issue:
private static void flagPlacementChecks(final Block block) throws TownyException {
int seaLevel = block.getWorld().getSeaLevel();
int yLoc = block.getY();
int allowedDepth = FlagWarConfig.getDepthAllowance();
if (yLoc < seaLevel - allowedDepth) { // ensure flag is at or above sea-level - potentially configurable.
if (allowedDepth > 0) {
throw new TownyException(Translate.fromPrefixed("error.flag.below-sea-level-allowance", allowedDepth));
} else {
throw new TownyException(Translate.fromPrefixed("error.flag.below-sea-level"));
}
}
// Check 3 blocks up, ensure they valid blocks to overwrite.
final byte checkHeight = 5;
for (byte i = 1; i < checkHeight; i++) {
Block iBlock = block.getWorld().getBlockAt(block.getX(), block.getY() + i, block.getZ());
if (iBlock.isLiquid()) { // Submersion Check
throw new TownyException(Translate.fromPrefixed("error.flag.avoid-liquid"));
} else if (!iBlock.isEmpty()) { // General Space Check
throw new TownyException(Translate.fromPrefixed("error.flag.need-space-above"));
}
}
if (!block.getWorld().hasCeiling()) { // Ignore if natural ceiling for world
Block highestBlock = block.getWorld().getHighestBlockAt(block.getLocation());
if (highestBlock.getY() > block.getWorld().getMaxHeight() - checkHeight
&& yLoc < highestBlock.getY() - 1) { // Traditional check
throw new TownyException(Translate.fromPrefixed("error.flag.need-above-ground"));
}
}
}