From 025fde8b3abf7463e4c067f0092d0db6f7da9167 Mon Sep 17 00:00:00 2001 From: Llm Dl Date: Sun, 31 Oct 2021 10:01:01 -0500 Subject: [PATCH 1/3] Enhance Start and End Siege Events This PR adds more methods to the events thrown at start and end of sieges. It also adds a SiegeSide variable to Sieges: SiegeWinner. Closes #400. Whitespacing fixes. --- .../goosius/siegewar/SiegeController.java | 9 +++- .../siegewar/events/SiegeEndEvent.java | 48 ++++++++++++++++++- .../siegewar/events/SiegeWarStartEvent.java | 28 ++++++++++- .../gmail/goosius/siegewar/objects/Siege.java | 9 ++++ .../siegewar/timeractions/AttackerWin.java | 2 + .../siegewar/timeractions/DefenderWin.java | 2 + .../utils/SiegeWarSiegeCompletionUtil.java | 9 +++- 7 files changed, 102 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/gmail/goosius/siegewar/SiegeController.java b/src/main/java/com/gmail/goosius/siegewar/SiegeController.java index de62efda4..fe07212c5 100644 --- a/src/main/java/com/gmail/goosius/siegewar/SiegeController.java +++ b/src/main/java/com/gmail/goosius/siegewar/SiegeController.java @@ -485,8 +485,15 @@ public static void startSiege(Block bannerBlock, //Save to DB SiegeController.saveSiege(siege); + Nation nation = siege.getSiegeType().equals(SiegeType.REVOLT) ? TownOccupationController.getTownOccupier(targetTown) : (Nation)siege.getAttackingNationIfPossibleElseTown(); //Call event - Bukkit.getPluginManager().callEvent(new SiegeWarStartEvent(siege, townOfSiegeStarter, bannerBlock)); + Bukkit.getPluginManager().callEvent(new SiegeWarStartEvent( + siege, + siege.getSiegeType(), + siege.getTown(), + nation, + townOfSiegeStarter, + bannerBlock)); } private static void sendGlobalSiegeStartMessage(Siege siege) { diff --git a/src/main/java/com/gmail/goosius/siegewar/events/SiegeEndEvent.java b/src/main/java/com/gmail/goosius/siegewar/events/SiegeEndEvent.java index 8592cb039..02ddff523 100644 --- a/src/main/java/com/gmail/goosius/siegewar/events/SiegeEndEvent.java +++ b/src/main/java/com/gmail/goosius/siegewar/events/SiegeEndEvent.java @@ -22,12 +22,24 @@ public class SiegeEndEvent extends Event { private static final HandlerList handlers = new HandlerList(); private final Siege siege; + private final String siegeType; + private final String siegeWinner; + private final String attackerName; + private final String defenderName; private final String besiegedTownName; public SiegeEndEvent(Siege siege, + String siegeType, + String siegeWinner, + String attackerName, + String defenderName, String besiegedTownName) { super(!Bukkit.getServer().isPrimaryThread()); this.siege = siege; + this.siegeType = siegeType; + this.siegeWinner = siegeWinner; + this.attackerName = attackerName; + this.defenderName = defenderName; this.besiegedTownName = besiegedTownName; } @@ -41,11 +53,45 @@ public static HandlerList getHandlerList() { return handlers; } + /** + * @return Siege object + */ public Siege getSiege() { return siege; } - public String getBesiegedTownName() { + /** + * @return the siegeType as a String + */ + public String getSiegeType() { + return siegeType; + } + + /** + * @return the siegeWinner as a String + */ + public String getSiegeWinner() { + return siegeWinner; + } + + /** + * @return the attackerName + */ + public String getAttackerName() { + return attackerName; + } + + /** + * @return besiegedTownName; + */ + public String getBesiegedTownName() { return besiegedTownName; } + + /** + * @return the defenderName + */ + public String getDefenderName() { + return defenderName; + } } diff --git a/src/main/java/com/gmail/goosius/siegewar/events/SiegeWarStartEvent.java b/src/main/java/com/gmail/goosius/siegewar/events/SiegeWarStartEvent.java index 51b8ab35a..506dd608e 100644 --- a/src/main/java/com/gmail/goosius/siegewar/events/SiegeWarStartEvent.java +++ b/src/main/java/com/gmail/goosius/siegewar/events/SiegeWarStartEvent.java @@ -1,6 +1,8 @@ package com.gmail.goosius.siegewar.events; +import com.gmail.goosius.siegewar.enums.SiegeType; import com.gmail.goosius.siegewar.objects.Siege; +import com.palmergames.bukkit.towny.object.Nation; import com.palmergames.bukkit.towny.object.Town; import org.bukkit.block.Block; import org.bukkit.event.Event; @@ -10,13 +12,25 @@ public class SiegeWarStartEvent extends Event { private static final HandlerList handlers = new HandlerList(); + private final SiegeType siegeType; private final Siege siege; private final Town townOfSiegeStarter; + private final Nation nation; private final Block flag; + private final Town targetTown; - public SiegeWarStartEvent(Siege siege, Town townOfSiegeStarter, Block flag) { + public SiegeWarStartEvent( + Siege siege, + SiegeType siegeType, + Town targetTown, + Nation nation, + Town townOfSiegeStarter, + Block flag) { this.siege = siege; + this.siegeType = siegeType; + this.targetTown = targetTown; this.townOfSiegeStarter = townOfSiegeStarter; + this.nation = nation; this.flag = flag; } @@ -41,4 +55,16 @@ public Town getTownOfSiegeStarter() { public Block getFlag() { return flag; } + + public SiegeType getSiegeType() { + return siegeType; + } + + public Nation getNation() { + return nation; + } + + public Town getTargetTown() { + return targetTown; + } } diff --git a/src/main/java/com/gmail/goosius/siegewar/objects/Siege.java b/src/main/java/com/gmail/goosius/siegewar/objects/Siege.java index f42a1579c..a0308c826 100644 --- a/src/main/java/com/gmail/goosius/siegewar/objects/Siege.java +++ b/src/main/java/com/gmail/goosius/siegewar/objects/Siege.java @@ -56,6 +56,7 @@ public class Siege { private double warChestAmount; private List bannerControllingResidents; //Soldiers currently controlling the banner private SiegeSide bannerControllingSide; + private SiegeSide siegeWinner; //For when a siege is over, holds the winning side. private Map bannerControlSessions; private int timedBattlePointsEarnedFromCurrentBannerControl; private boolean attackerHasLowestPopulation; @@ -488,6 +489,14 @@ public int getTotalBattleSessions() { return result; } + public SiegeSide getSiegeWinner() { + return siegeWinner; + } + + public void setSiegeWinner(SiegeSide siegeWinner) { + this.siegeWinner = siegeWinner; + } + public String getAttackerName() { return attackerName; } diff --git a/src/main/java/com/gmail/goosius/siegewar/timeractions/AttackerWin.java b/src/main/java/com/gmail/goosius/siegewar/timeractions/AttackerWin.java index 2176fb257..e2f277798 100644 --- a/src/main/java/com/gmail/goosius/siegewar/timeractions/AttackerWin.java +++ b/src/main/java/com/gmail/goosius/siegewar/timeractions/AttackerWin.java @@ -1,6 +1,7 @@ package com.gmail.goosius.siegewar.timeractions; import com.gmail.goosius.siegewar.TownOccupationController; +import com.gmail.goosius.siegewar.enums.SiegeSide; import com.gmail.goosius.siegewar.enums.SiegeStatus; import com.gmail.goosius.siegewar.objects.Siege; import com.gmail.goosius.siegewar.utils.SiegeWarMoneyUtil; @@ -21,6 +22,7 @@ public class AttackerWin { * @param siegeStatus the siege status */ public static void attackerWin(Siege siege, SiegeStatus siegeStatus) { + siege.setSiegeWinner(SiegeSide.ATTACKERS); SiegeWarSiegeCompletionUtil.setCommonSiegeCompletionValues(siege, siegeStatus); switch(siege.getSiegeType()) { case CONQUEST: diff --git a/src/main/java/com/gmail/goosius/siegewar/timeractions/DefenderWin.java b/src/main/java/com/gmail/goosius/siegewar/timeractions/DefenderWin.java index 27a9fa1f3..7a24482c1 100644 --- a/src/main/java/com/gmail/goosius/siegewar/timeractions/DefenderWin.java +++ b/src/main/java/com/gmail/goosius/siegewar/timeractions/DefenderWin.java @@ -1,6 +1,7 @@ package com.gmail.goosius.siegewar.timeractions; import com.gmail.goosius.siegewar.TownOccupationController; +import com.gmail.goosius.siegewar.enums.SiegeSide; import com.gmail.goosius.siegewar.enums.SiegeStatus; import com.gmail.goosius.siegewar.objects.Siege; import com.gmail.goosius.siegewar.utils.SiegeWarMoneyUtil; @@ -21,6 +22,7 @@ public class DefenderWin * @param siegeStatus the siege status */ public static void defenderWin(Siege siege, SiegeStatus siegeStatus) { + siege.setSiegeWinner(SiegeSide.DEFENDERS); SiegeWarSiegeCompletionUtil.setCommonSiegeCompletionValues(siege, siegeStatus); switch(siege.getSiegeType()) { case CONQUEST: diff --git a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarSiegeCompletionUtil.java b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarSiegeCompletionUtil.java index ae5494ca0..3981160aa 100644 --- a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarSiegeCompletionUtil.java +++ b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarSiegeCompletionUtil.java @@ -51,7 +51,12 @@ public static void setCommonSiegeCompletionValues(Siege siege, SiegeController.saveSiege(siege); //Fire SiegeEnded event - SiegeEndEvent siegeEndEvent = new SiegeEndEvent(siege, siege.getTown().getName()); - Bukkit.getPluginManager().callEvent(siegeEndEvent); + Bukkit.getPluginManager().callEvent(new SiegeEndEvent( + siege, + siege.getSiegeType().getName(), + siege.getSiegeWinner().name(), + siege.getAttackerName(), + siege.getDefenderName(), + siege.getTown().getName())); } } From cb5766fc05fc570c742fa233bf80feb515de3630 Mon Sep 17 00:00:00 2001 From: Llm Dl Date: Sun, 31 Oct 2021 10:07:34 -0500 Subject: [PATCH 2/3] Use translated SiegeType name in the start event. --- .../java/com/gmail/goosius/siegewar/SiegeController.java | 2 +- .../gmail/goosius/siegewar/events/SiegeWarStartEvent.java | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/gmail/goosius/siegewar/SiegeController.java b/src/main/java/com/gmail/goosius/siegewar/SiegeController.java index fe07212c5..9165bad43 100644 --- a/src/main/java/com/gmail/goosius/siegewar/SiegeController.java +++ b/src/main/java/com/gmail/goosius/siegewar/SiegeController.java @@ -489,7 +489,7 @@ public static void startSiege(Block bannerBlock, //Call event Bukkit.getPluginManager().callEvent(new SiegeWarStartEvent( siege, - siege.getSiegeType(), + siege.getSiegeType().getName(), siege.getTown(), nation, townOfSiegeStarter, diff --git a/src/main/java/com/gmail/goosius/siegewar/events/SiegeWarStartEvent.java b/src/main/java/com/gmail/goosius/siegewar/events/SiegeWarStartEvent.java index 506dd608e..fbff43d0f 100644 --- a/src/main/java/com/gmail/goosius/siegewar/events/SiegeWarStartEvent.java +++ b/src/main/java/com/gmail/goosius/siegewar/events/SiegeWarStartEvent.java @@ -1,6 +1,5 @@ package com.gmail.goosius.siegewar.events; -import com.gmail.goosius.siegewar.enums.SiegeType; import com.gmail.goosius.siegewar.objects.Siege; import com.palmergames.bukkit.towny.object.Nation; import com.palmergames.bukkit.towny.object.Town; @@ -12,7 +11,7 @@ public class SiegeWarStartEvent extends Event { private static final HandlerList handlers = new HandlerList(); - private final SiegeType siegeType; + private final String siegeType; private final Siege siege; private final Town townOfSiegeStarter; private final Nation nation; @@ -21,7 +20,7 @@ public class SiegeWarStartEvent extends Event { public SiegeWarStartEvent( Siege siege, - SiegeType siegeType, + String siegeType, Town targetTown, Nation nation, Town townOfSiegeStarter, @@ -56,7 +55,7 @@ public Block getFlag() { return flag; } - public SiegeType getSiegeType() { + public String getSiegeType() { return siegeType; } From 1fef90437f6129bfa7d4971127061dd541cf9ed0 Mon Sep 17 00:00:00 2001 From: Llm Dl Date: Sun, 31 Oct 2021 11:14:19 -0500 Subject: [PATCH 3/3] Event variables set in contructor. --- .../goosius/siegewar/SiegeController.java | 9 +-------- .../goosius/siegewar/events/SiegeEndEvent.java | 17 ++++++----------- .../siegewar/events/SiegeWarStartEvent.java | 18 +++++++----------- .../utils/SiegeWarSiegeCompletionUtil.java | 8 +------- 4 files changed, 15 insertions(+), 37 deletions(-) diff --git a/src/main/java/com/gmail/goosius/siegewar/SiegeController.java b/src/main/java/com/gmail/goosius/siegewar/SiegeController.java index 9165bad43..8b446ddbe 100644 --- a/src/main/java/com/gmail/goosius/siegewar/SiegeController.java +++ b/src/main/java/com/gmail/goosius/siegewar/SiegeController.java @@ -485,15 +485,8 @@ public static void startSiege(Block bannerBlock, //Save to DB SiegeController.saveSiege(siege); - Nation nation = siege.getSiegeType().equals(SiegeType.REVOLT) ? TownOccupationController.getTownOccupier(targetTown) : (Nation)siege.getAttackingNationIfPossibleElseTown(); //Call event - Bukkit.getPluginManager().callEvent(new SiegeWarStartEvent( - siege, - siege.getSiegeType().getName(), - siege.getTown(), - nation, - townOfSiegeStarter, - bannerBlock)); + Bukkit.getPluginManager().callEvent(new SiegeWarStartEvent(siege, townOfSiegeStarter)); } private static void sendGlobalSiegeStartMessage(Siege siege) { diff --git a/src/main/java/com/gmail/goosius/siegewar/events/SiegeEndEvent.java b/src/main/java/com/gmail/goosius/siegewar/events/SiegeEndEvent.java index 02ddff523..431360a53 100644 --- a/src/main/java/com/gmail/goosius/siegewar/events/SiegeEndEvent.java +++ b/src/main/java/com/gmail/goosius/siegewar/events/SiegeEndEvent.java @@ -28,19 +28,14 @@ public class SiegeEndEvent extends Event { private final String defenderName; private final String besiegedTownName; - public SiegeEndEvent(Siege siege, - String siegeType, - String siegeWinner, - String attackerName, - String defenderName, - String besiegedTownName) { + public SiegeEndEvent(Siege siege) { super(!Bukkit.getServer().isPrimaryThread()); this.siege = siege; - this.siegeType = siegeType; - this.siegeWinner = siegeWinner; - this.attackerName = attackerName; - this.defenderName = defenderName; - this.besiegedTownName = besiegedTownName; + this.siegeType = siege.getSiegeType().getName(); + this.siegeWinner = siege.getSiegeWinner().name(); + this.attackerName = siege.getAttackerName(); + this.defenderName = siege.getDefenderName(); + this.besiegedTownName = siege.getTown().getName(); } @NotNull diff --git a/src/main/java/com/gmail/goosius/siegewar/events/SiegeWarStartEvent.java b/src/main/java/com/gmail/goosius/siegewar/events/SiegeWarStartEvent.java index fbff43d0f..7c6049cd2 100644 --- a/src/main/java/com/gmail/goosius/siegewar/events/SiegeWarStartEvent.java +++ b/src/main/java/com/gmail/goosius/siegewar/events/SiegeWarStartEvent.java @@ -1,6 +1,8 @@ package com.gmail.goosius.siegewar.events; +import com.gmail.goosius.siegewar.enums.SiegeType; import com.gmail.goosius.siegewar.objects.Siege; +import com.gmail.goosius.siegewar.TownOccupationController; import com.palmergames.bukkit.towny.object.Nation; import com.palmergames.bukkit.towny.object.Town; import org.bukkit.block.Block; @@ -18,19 +20,13 @@ public class SiegeWarStartEvent extends Event { private final Block flag; private final Town targetTown; - public SiegeWarStartEvent( - Siege siege, - String siegeType, - Town targetTown, - Nation nation, - Town townOfSiegeStarter, - Block flag) { + public SiegeWarStartEvent(Siege siege, Town townOfSiegeStarter) { this.siege = siege; - this.siegeType = siegeType; - this.targetTown = targetTown; + this.siegeType = siege.getSiegeType().getName(); + this.targetTown = siege.getTown(); this.townOfSiegeStarter = townOfSiegeStarter; - this.nation = nation; - this.flag = flag; + this.nation = siege.getSiegeType().equals(SiegeType.REVOLT) ? TownOccupationController.getTownOccupier(targetTown) : (Nation)siege.getAttackingNationIfPossibleElseTown(); + this.flag = siege.getFlagLocation().getBlock(); } @NotNull diff --git a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarSiegeCompletionUtil.java b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarSiegeCompletionUtil.java index 3981160aa..d70f25a88 100644 --- a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarSiegeCompletionUtil.java +++ b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarSiegeCompletionUtil.java @@ -51,12 +51,6 @@ public static void setCommonSiegeCompletionValues(Siege siege, SiegeController.saveSiege(siege); //Fire SiegeEnded event - Bukkit.getPluginManager().callEvent(new SiegeEndEvent( - siege, - siege.getSiegeType().getName(), - siege.getSiegeWinner().name(), - siege.getAttackerName(), - siege.getDefenderName(), - siege.getTown().getName())); + Bukkit.getPluginManager().callEvent(new SiegeEndEvent(siege)); } }