Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add BannerControlSessionStartedEvent & TownPlunderedEvent #923

Merged
merged 3 commits into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

im pretty sure the plunder can remove the town so i think this is 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 @@ -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;
}

LlmDl marked this conversation as resolved.
Show resolved Hide resolved
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