FlagWar icon indicating copy to clipboard operation
FlagWar copied to clipboard

Suggestion: debug messages for flag depth

Open ADM8 opened this issue 10 months ago • 1 comments

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.

ADM8 avatar Feb 22 '25 00:02 ADM8

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"));
            }
        }
    }

LlmDl avatar Mar 05 '25 13:03 LlmDl