Added an option to disable flight when an enemy player is in the town.#73
Added an option to disable flight when an enemy player is in the town.#73connorwally wants to merge 10 commits into
Conversation
…light, fixed addFlightToPlayersInTown, fixed takeFlightFromPlayersInTown
…dded a cause to takeFlightFromPlayersInTown, rebuilt HashMap methods to use new UUID system
LlmDl
left a comment
There was a problem hiding this comment.
An early review to keep you busy.
|
|
||
|
|
| public TownyFlightAPI(TownyFlight plugin) { | ||
| TownyFlightAPI.plugin = plugin; | ||
| forceAllowFlight = new NamespacedKey(plugin, "force_allow_flight"); | ||
|
|
|
|
||
| // |
| return true; | ||
|
|
||
| if (!Permission.has(player, "townyflight.command.tfly", silent)) return false; | ||
| if (!Permission.has(player, "townyflight.command.tfly", true)) return false; |
There was a problem hiding this comment.
Probably an unneeded diff, we've also lost the silent permission test.
| } | ||
|
|
||
| // Returns true if the hashmap contains the supplied town and the value is >0. | ||
| public static boolean containsTown(Town town) { |
There was a problem hiding this comment.
This method should accept a UUID instead of the whole Town.
| public static boolean containsTown(Town town) { | |
| public static boolean townHasEnemiesPresent(UUID uuid) { | |
| // If the player's town does not match the flight re-adding, dont add it. | ||
| if(TownyAPI.getInstance().getTown(player) != town) { | ||
| return; | ||
| } |
| } | ||
|
|
||
| // If they can already fly, dont add it | ||
| if (player.getAllowFlight()) return; |
There was a problem hiding this comment.
| if (player.getAllowFlight()) return; | |
| if (player.getAllowFlight()) continue; | |
| "# Number of seconds after leaving an allowed flight area before flight is taken away.", "# Set to 0 to take flight away immediately."); | ||
| "# Number of seconds after leaving an allowed flight area before flight is taken away.", "# Set to 0 to take flight away immediately."), | ||
| OPTIONS_DISABLE_BY( | ||
| "options.flight_Disable_By", |
There was a problem hiding this comment.
This should be renamed to something like flight_Disabled_By_Outsider
| import org.bukkit.event.player.PlayerQuitEvent; | ||
| import org.bukkit.event.player.PlayerTeleportEvent; | ||
|
|
||
| public class EnemyEnterTownListener implements Listener { |
There was a problem hiding this comment.
Rename to something more descriptive, ie OutsidersInTownListener.
There was a problem hiding this comment.
All of the other methods should lose the Enemy naming as well, since this is not limited to just enemies.
| public boolean playerDisablesFlight(Town town, Resident resident){ | ||
| if (Settings.flightDisableBy.equals("ALLY")){ | ||
|
|
||
| // If they don't belong to a town, treated as a NEUTRAL player | ||
| if(TownyAPI.getInstance().getResidentTownOrNull(resident) == null){ | ||
| return true; | ||
| } | ||
|
|
||
| if (!CombatUtil.isSameTown(town, TownyAPI.getInstance().getResidentTownOrNull(resident))) { | ||
| return true; | ||
| } | ||
|
|
||
| } | ||
| if(Settings.flightDisableBy.equals("NEUTRAL")){ | ||
|
|
||
| // If they don't belong to a town, treated as a NEUTRAL player | ||
| if(TownyAPI.getInstance().getResidentTownOrNull(resident) == null){ | ||
| return true; | ||
| } | ||
|
|
||
| if (!CombatUtil.isSameTown(town, TownyAPI.getInstance().getResidentTownOrNull(resident)) && !CombatUtil.isAlly(town, TownyAPI.getInstance().getResidentTownOrNull(resident))) { | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| if(Settings.flightDisableBy.equals("ENEMY")) { | ||
|
|
||
| // If they don't belong to a town, treated as a NEUTRAL player | ||
| if(TownyAPI.getInstance().getResidentTownOrNull(resident) == null){ | ||
| return false; | ||
| } | ||
| if (CombatUtil.isEnemy(town, TownyAPI.getInstance().getResidentTownOrNull(resident)) || CombatUtil.isEnemy(TownyAPI.getInstance().getResidentTownOrNull(resident), town)) { | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| return false; | ||
| } |
There was a problem hiding this comment.
| public boolean playerDisablesFlight(Town town, Resident resident){ | |
| if (Settings.flightDisableBy.equals("ALLY")){ | |
| // If they don't belong to a town, treated as a NEUTRAL player | |
| if(TownyAPI.getInstance().getResidentTownOrNull(resident) == null){ | |
| return true; | |
| } | |
| if (!CombatUtil.isSameTown(town, TownyAPI.getInstance().getResidentTownOrNull(resident))) { | |
| return true; | |
| } | |
| } | |
| if(Settings.flightDisableBy.equals("NEUTRAL")){ | |
| // If they don't belong to a town, treated as a NEUTRAL player | |
| if(TownyAPI.getInstance().getResidentTownOrNull(resident) == null){ | |
| return true; | |
| } | |
| if (!CombatUtil.isSameTown(town, TownyAPI.getInstance().getResidentTownOrNull(resident)) && !CombatUtil.isAlly(town, TownyAPI.getInstance().getResidentTownOrNull(resident))) { | |
| return true; | |
| } | |
| } | |
| if(Settings.flightDisableBy.equals("ENEMY")) { | |
| // If they don't belong to a town, treated as a NEUTRAL player | |
| if(TownyAPI.getInstance().getResidentTownOrNull(resident) == null){ | |
| return false; | |
| } | |
| if (CombatUtil.isEnemy(town, TownyAPI.getInstance().getResidentTownOrNull(resident)) || CombatUtil.isEnemy(TownyAPI.getInstance().getResidentTownOrNull(resident), town)) { | |
| return true; | |
| } | |
| } | |
| return false; | |
| } | |
| public boolean playerDisablesFlight(Town town, Resident resident){ | |
| if (!resident.hasTown()) { | |
| return Settings.flightDisableBy.equals("NEUTRAL"); | |
| } | |
| Town outsiderTown = resident.getTownOrNull(); | |
| if (Settings.flightDisableBy.equals("ALLY")){ | |
| return CombatUtil.isAlly(town, outsiderTown); | |
| } | |
| if(Settings.flightDisableBy.equals("ENEMY")) { | |
| return CombatUtil.isEnemy(town, outsiderTown); | |
| } | |
| return false; | |
| } |
I believe this will achieve what you want.
Depending on the config option:
A hashmap, enemiesInTown, is used to track towns with active enemies inside them.
If they do have active enemies inside the town, there is a new condition in, canFly, which will return false.
Town flight will automatically be disabled on an enemy entering, and re-enabled when the enemy leaves.
I tried to touch as little existing code as possible.
I have tested a reasonable amount on a private server with 2 accounts.