Skip to content

Commit

Permalink
Improve event handling
Browse files Browse the repository at this point in the history
added priorities to all events, set them to ignore cancelled
  • Loading branch information
drfiveminusmint committed May 26, 2024
1 parent 47a62ae commit 51f30fc
Showing 1 changed file with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@


public class SiegeLeaderListener implements Listener {
@EventHandler(priority = EventPriority.NORMAL)
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onCraftMovement(CraftPreTranslateEvent event) {
Craft leaderCraft = event.getCraft();
if (!(leaderCraft instanceof PlayerCraft && Config.SiegeEnable && !event.isCancelled())) return;
if (!(leaderCraft instanceof PlayerCraft) || !Config.SiegeEnable) return;
Player player = ((PlayerCraft)leaderCraft).getPilot();
Siege currentSiege = getSiegeByLeader(player);
if (currentSiege == null) return;
Expand All @@ -49,10 +49,10 @@ public void onCraftMovement(CraftPreTranslateEvent event) {
event.setCancelled(processCraftMovement(leaderCraft,player,currentSiege,newMaxLocation,newMinLocation));
}

@EventHandler
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onCraftRotation(CraftRotateEvent event) {
Craft leaderCraft = event.getCraft();
if (!(leaderCraft instanceof PlayerCraft && Config.SiegeEnable && !event.isCancelled())) return;
if (!(leaderCraft instanceof PlayerCraft) || !Config.SiegeEnable) return;
Player player = ((PlayerCraft)leaderCraft).getPilot();
Siege currentSiege = getSiegeByLeader(player);
if (currentSiege == null) return;
Expand All @@ -73,13 +73,13 @@ public void onCraftSink (CraftSinkEvent event) {
processCraftRemoval(event.getCraft());
}

@EventHandler
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onCraftRelease (CraftReleaseEvent event) {
processCraftRemoval(event.getCraft());
}

private void processCraftRemoval(Craft leaderCraft) {
if (!(leaderCraft instanceof PlayerCraft && Config.SiegeEnable)) return;
if (!(leaderCraft instanceof PlayerCraft) || Config.SiegeEnable) return;
Player player = ((PlayerCraft)leaderCraft).getPilot();
Siege currentSiege = getSiegeByLeader(player);
if (currentSiege == null) return;
Expand Down Expand Up @@ -146,5 +146,4 @@ private Siege getSiegeByLeader (@NotNull Player leader) {
}
return null;
}

}

0 comments on commit 51f30fc

Please sign in to comment.