Skip to content

Added an option to disable flight when an enemy player is in the town.#73

Open
connorwally wants to merge 10 commits into
TownyAdvanced:masterfrom
connorwally:master
Open

Added an option to disable flight when an enemy player is in the town.#73
connorwally wants to merge 10 commits into
TownyAdvanced:masterfrom
connorwally:master

Conversation

@connorwally
Copy link
Copy Markdown

Depending on the config option:

  • NONE - this feature will not be enabled
  • ALLY - all players except town members will disable flight
  • NEUTRAL - all players except town and ally will disable flight
  • ENEMY - only enemied players will disable flight

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.

Copy link
Copy Markdown
Member

@LlmDl LlmDl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An early review to keep you busy.

Comment on lines +147 to +148


Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unneeded diff

public TownyFlightAPI(TownyFlight plugin) {
TownyFlightAPI.plugin = plugin;
forceAllowFlight = new NamespacedKey(plugin, "force_allow_flight");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unneeded diff.

Comment on lines +60 to +61

//
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unneeded diff.

return true;

if (!Permission.has(player, "townyflight.command.tfly", silent)) return false;
if (!Permission.has(player, "townyflight.command.tfly", true)) return false;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method should accept a UUID instead of the whole Town.

Suggested change
public static boolean containsTown(Town town) {
public static boolean townHasEnemiesPresent(UUID uuid) {

Comment on lines +238 to +241
// If the player's town does not match the flight re-adding, dont add it.
if(TownyAPI.getInstance().getTown(player) != town) {
return;
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't be required any longer.

}

// If they can already fly, dont add it
if (player.getAllowFlight()) return;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename to something more descriptive, ie OutsidersInTownListener.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of the other methods should lose the Enemy naming as well, since this is not limited to just enemies.

Comment on lines +139 to +176
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;
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants