TownyAdvanced / TownyFlight

Flight plugin for Towny servers.
https://townyadvanced.github.io/
Other
23 stars 17 forks source link

Config option for tempfly restrictions #81

Closed KermX closed 3 months ago

KermX commented 3 months ago

It would be awesome to be able to decide where players are able to use tempfly, rather than it being inside their town only. I'm sure a better system to configure this idea could be devised, but a possible solution below:

options:
  tempfly_Areas:
    - alltowns
    - wilderness

This would mean that temp fly isn't removed in the wilderness or in any town.

LlmDl commented 3 months ago

At the moment, I don't see how we restrict anyone using tempflight using the permission nodes.

If they receive tempflight and they have the node to allow flight in the wilderness, they should be able to use /tfly.

Are you seeing something different?

KermX commented 3 months ago

It would be useful to not need to assign permissions when also granting temp fly. If I activate temp fly for a user who has no permissions they are still able to fly in their own town currently. Ideally I would like to be able to control that behavior without also needing to assign permissions

LlmDl commented 3 months ago

That would be counter-intuitive to how we test if someone can fly at a location, the code of which is used by the tempflight and all the other "can they fly here?" tests.

KermX commented 3 months ago

how so? A user granted tempfly with the /tfly tempfly command is currently able to fly in their own town while having no permissions at all

LlmDl commented 3 months ago

This is the area where tempflight bypasses the permission test:

    /**
     * Returns true if a player can fly according to TownyFlight's rules.
     * 
     * @param player {@link Player} to test for flight allowance.
     * @param silent true will show messages to player.
     * @return true if the {@link Player} is allowed to fly.
     **/
    public boolean canFly(Player player, boolean silent) {
        if (player.hasPermission("townyflight.bypass") 
            || player.getGameMode().equals(GameMode.SPECTATOR) 
            || player.getGameMode().equals(GameMode.CREATIVE)
            || getForceAllowFlight(player))
            return true;

        if (!hasTempFlight(player) && !Permission.has(player, "townyflight.command.tfly", silent)) return false;

        Resident resident = TownyUniverse.getInstance().getResident(player.getUniqueId());
        if (resident == null) return false;

        if (warPrevents(player.getLocation(), resident)) {
            if (!silent) Message.of("notDuringWar").to(player);
            return false;
        }

        if (!allowedLocation(player, player.getLocation(), resident)) {
            if (!silent) Message.of("notInTownMsg").to(player);
            return false;
        }
        return true;
    }

I am not sure why I made it so that tempflight users dont need the command node, but its probably so that someone can get tempflight without any other requirements.

The wilderness test is done in if (!allowedLocation(player, player.getLocation(), resident)) { where we do test the player for the various permission nodes we use to determine if they can fly in those locations.

Are you unable to give everyone the townyflight.wilderness node? As in you want people with tempflight to be able to fly in places normal /tfly users can not?

KermX commented 3 months ago

I could give them the wilderness node, but if I have to assign permissions why wouldn't I just assign a temp permission instead of using townyflights tempfly system at all?

LlmDl commented 3 months ago

Good point, something will likely need to get refactored. Not a ton of work though.