From 14b4f4bb0a32c6d050150d68a5aee231a66f5b01 Mon Sep 17 00:00:00 2001 From: tlm920 Date: Wed, 14 Aug 2024 09:21:00 -0400 Subject: [PATCH 1/3] add BannerControlSessionStartedEvent --- .../BannerControlSessionStartedEvent.java | 38 +++++++++++++++++++ .../utils/SiegeWarBannerControlUtil.java | 3 ++ 2 files changed, 41 insertions(+) create mode 100644 src/main/java/com/gmail/goosius/siegewar/events/BannerControlSessionStartedEvent.java diff --git a/src/main/java/com/gmail/goosius/siegewar/events/BannerControlSessionStartedEvent.java b/src/main/java/com/gmail/goosius/siegewar/events/BannerControlSessionStartedEvent.java new file mode 100644 index 000000000..38d401cf6 --- /dev/null +++ b/src/main/java/com/gmail/goosius/siegewar/events/BannerControlSessionStartedEvent.java @@ -0,0 +1,38 @@ +package com.gmail.goosius.siegewar.events; + +import com.gmail.goosius.siegewar.objects.BannerControlSession; +import com.gmail.goosius.siegewar.objects.Siege; +import org.bukkit.Bukkit; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.NotNull; + +public class BannerControlSessionStartedEvent extends Event { + private static final HandlerList handlers = new HandlerList(); + private final Siege siege; + private final BannerControlSession bannerControlSession; + + public BannerControlSessionStartedEvent(Siege siege, BannerControlSession bannerControlSession) { + super(!Bukkit.getServer().isPrimaryThread()); + this.siege = siege; + this.bannerControlSession = bannerControlSession; + } + + @NotNull + @Override + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } + + public Siege getSiege() { + return siege; + } + + public BannerControlSession getBannerControlSession() { + return bannerControlSession; + } +} diff --git a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarBannerControlUtil.java b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarBannerControlUtil.java index 3989c32b4..8d28157f8 100644 --- a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarBannerControlUtil.java +++ b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarBannerControlUtil.java @@ -6,6 +6,7 @@ import com.gmail.goosius.siegewar.enums.SiegeSide; import com.gmail.goosius.siegewar.enums.SiegeStatus; import com.gmail.goosius.siegewar.events.BannerControlSessionEndedEvent; +import com.gmail.goosius.siegewar.events.BannerControlSessionStartedEvent; import com.gmail.goosius.siegewar.objects.BannerControlSession; import com.gmail.goosius.siegewar.objects.BattleSession; import com.gmail.goosius.siegewar.objects.Siege; @@ -135,6 +136,8 @@ private static void addNewBannerControlSession(Siege siege, final Player player, SiegeWarNotificationUtil.informSiegeParticipants(siege, message); } } + + Bukkit.getPluginManager().callEvent(new BannerControlSessionStartedEvent(siege, bannerControlSession)); } private static boolean doesPlayerMeetBasicSessionRequirements(Siege siege, Player player, Resident resident) throws Exception { From 8f4991a43caa04f2cd6b6dbc85b670c2c7fdd95d Mon Sep 17 00:00:00 2001 From: tlm920 Date: Wed, 14 Aug 2024 10:03:28 -0400 Subject: [PATCH 2/3] add TownPlunderedEvent --- .../siegewar/events/TownPlunderedEvent.java | 43 +++++++++++++++++++ .../siegewar/playeractions/PlaceBlock.java | 14 +++++- 2 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/gmail/goosius/siegewar/events/TownPlunderedEvent.java diff --git a/src/main/java/com/gmail/goosius/siegewar/events/TownPlunderedEvent.java b/src/main/java/com/gmail/goosius/siegewar/events/TownPlunderedEvent.java new file mode 100644 index 000000000..1ab721e44 --- /dev/null +++ b/src/main/java/com/gmail/goosius/siegewar/events/TownPlunderedEvent.java @@ -0,0 +1,43 @@ +package com.gmail.goosius.siegewar.events; + +import com.gmail.goosius.siegewar.objects.Siege; +import com.palmergames.bukkit.towny.object.Town; +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class TownPlunderedEvent extends Event { + private static final HandlerList handlers = new HandlerList(); + private final Siege siege; + private final Player player; + + public TownPlunderedEvent(Siege siege, Player player) { + this.siege = siege; + this.player = player; + } + + @NotNull + @Override + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } + + public Siege getSiege() { + return siege; + } + + @Nullable + public Town getTown() { + return siege.getTown(); + } + + public Player getPlayer() { + return player; + } +} diff --git a/src/main/java/com/gmail/goosius/siegewar/playeractions/PlaceBlock.java b/src/main/java/com/gmail/goosius/siegewar/playeractions/PlaceBlock.java index c1f2a59a6..b1f9d3e00 100644 --- a/src/main/java/com/gmail/goosius/siegewar/playeractions/PlaceBlock.java +++ b/src/main/java/com/gmail/goosius/siegewar/playeractions/PlaceBlock.java @@ -4,6 +4,7 @@ import com.gmail.goosius.siegewar.SiegeController; import com.gmail.goosius.siegewar.TownOccupationController; import com.gmail.goosius.siegewar.enums.SiegeStatus; +import com.gmail.goosius.siegewar.events.TownPlunderedEvent; import com.gmail.goosius.siegewar.objects.Siege; import com.gmail.goosius.siegewar.settings.SiegeWarSettings; import com.gmail.goosius.siegewar.utils.SiegeWarBlockProtectionUtil; @@ -24,6 +25,7 @@ import com.palmergames.bukkit.towny.object.Translatable; import com.palmergames.bukkit.towny.object.Translator; +import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.Tag; import org.bukkit.block.Banner; @@ -355,8 +357,16 @@ private static void evaluatePlaceChest(Player player, Block block) throws TownyE if(adjacentSieges.size() > 1) throw new TownyException(translator.of("msg_err_siege_war_too_many_adjacent_towns")); - //Attempt plunder. - PlunderTown.processPlunderTownRequest(player, adjacentSieges.iterator().next()); + Siege adjacentSiege = adjacentSieges.iterator().next(); + + //Attempt plunder. Call TownPlunderedEvent if the plunder doesn't throw an exception. + try { + PlunderTown.processPlunderTownRequest(player, adjacentSiege); + } catch (TownyException e) { + return; + } + + Bukkit.getPluginManager().callEvent(new TownPlunderedEvent(adjacentSiege, player)); } private static boolean isWhiteBanner(Block block) { From 8d5e1273a84514fbcf79f52960b3e2377178193d Mon Sep 17 00:00:00 2001 From: LlmDl Date: Sun, 25 Aug 2024 07:57:27 -0500 Subject: [PATCH 3/3] Update src/main/java/com/gmail/goosius/siegewar/playeractions/PlaceBlock.java --- .../goosius/siegewar/playeractions/PlaceBlock.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/gmail/goosius/siegewar/playeractions/PlaceBlock.java b/src/main/java/com/gmail/goosius/siegewar/playeractions/PlaceBlock.java index b1f9d3e00..bc78a8f09 100644 --- a/src/main/java/com/gmail/goosius/siegewar/playeractions/PlaceBlock.java +++ b/src/main/java/com/gmail/goosius/siegewar/playeractions/PlaceBlock.java @@ -357,15 +357,10 @@ private static void evaluatePlaceChest(Player player, Block block) throws TownyE if(adjacentSieges.size() > 1) throw new TownyException(translator.of("msg_err_siege_war_too_many_adjacent_towns")); - Siege adjacentSiege = adjacentSieges.iterator().next(); - - //Attempt plunder. Call TownPlunderedEvent if the plunder doesn't throw an exception. - try { - PlunderTown.processPlunderTownRequest(player, adjacentSiege); - } catch (TownyException e) { - return; - } + //Attempt plunder. + PlunderTown.processPlunderTownRequest(player, adjacentSieges.iterator().next()); + //Call TownPlunderedEvent if the plunder doesn't throw an exception. Bukkit.getPluginManager().callEvent(new TownPlunderedEvent(adjacentSiege, player)); }