Skip to content

Commit

Permalink
Add BannerControlSessionStartedEvent & TownPlunderedEvent (#923)
Browse files Browse the repository at this point in the history
* add BannerControlSessionStartedEvent

* add TownPlunderedEvent

* Update src/main/java/com/gmail/goosius/siegewar/playeractions/PlaceBlock.java

---------

Co-authored-by: tlm920 <timo@timomcgrath.com>
Co-authored-by: LlmDl <LlmDlio@gmail.com>
  • Loading branch information
3 people authored Aug 25, 2024
1 parent 8777353 commit 1075945
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 1075945

Please sign in to comment.