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/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..bc78a8f09 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; @@ -357,6 +359,9 @@ private static void evaluatePlaceChest(Player player, Block block) throws TownyE //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)); } private static boolean isWhiteBanner(Block block) { 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 {