diff --git a/src/main/java/com/gmail/goosius/siegewar/SiegeController.java b/src/main/java/com/gmail/goosius/siegewar/SiegeController.java index de62efda4..8b446ddbe 100644 --- a/src/main/java/com/gmail/goosius/siegewar/SiegeController.java +++ b/src/main/java/com/gmail/goosius/siegewar/SiegeController.java @@ -486,7 +486,7 @@ public static void startSiege(Block bannerBlock, SiegeController.saveSiege(siege); //Call event - Bukkit.getPluginManager().callEvent(new SiegeWarStartEvent(siege, 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 8592cb039..431360a53 100644 --- a/src/main/java/com/gmail/goosius/siegewar/events/SiegeEndEvent.java +++ b/src/main/java/com/gmail/goosius/siegewar/events/SiegeEndEvent.java @@ -22,13 +22,20 @@ 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 besiegedTownName) { + public SiegeEndEvent(Siege siege) { super(!Bukkit.getServer().isPrimaryThread()); this.siege = siege; - 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 @@ -41,11 +48,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..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,9 @@ 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; import org.bukkit.event.Event; @@ -10,14 +13,20 @@ public class SiegeWarStartEvent extends Event { private static final HandlerList handlers = new HandlerList(); + private final String 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, Town townOfSiegeStarter) { this.siege = siege; + this.siegeType = siege.getSiegeType().getName(); + this.targetTown = siege.getTown(); this.townOfSiegeStarter = townOfSiegeStarter; - this.flag = flag; + this.nation = siege.getSiegeType().equals(SiegeType.REVOLT) ? TownOccupationController.getTownOccupier(targetTown) : (Nation)siege.getAttackingNationIfPossibleElseTown(); + this.flag = siege.getFlagLocation().getBlock(); } @NotNull @@ -41,4 +50,16 @@ public Town getTownOfSiegeStarter() { public Block getFlag() { return flag; } + + public String 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..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,7 +51,6 @@ 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)); } }