Skip to content

Commit

Permalink
- API: Add TownPreReclaimEvent.
Browse files Browse the repository at this point in the history
    - A cancellable event thrown before a player can reclaim a town.
  • Loading branch information
LlmDl committed Jun 4, 2024
1 parent 5127d26 commit afb725e
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.palmergames.bukkit.towny.event.town;

import com.palmergames.bukkit.towny.event.CancellableTownyEvent;
import com.palmergames.bukkit.towny.object.Resident;
import com.palmergames.bukkit.towny.object.Town;

import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class TownPreReclaimEvent extends CancellableTownyEvent {
private static final HandlerList HANDLER_LIST = new HandlerList();

private final Player player;
private final Resident resident;
private final Town town;

/**
* Event thrown prior to a {@link Town} being reclaimed by a {@link Resident}.
*
* @param town The Town being reclaimed.
* @param resident The resident who would become mayor.
* @param player The Player who would become mayor.
*/
public TownPreReclaimEvent(Town town, Resident resident, Player player) {
this.town = town;
this.resident = resident;
this.player = player;
}

/**
* @return the {@link Town} which will be reclaimed.
*/
@Nullable
public Town getTown() {
return town;
}

/**
* @return the resident who will become mayor.
*/
public Resident getResident() {
return resident;
}

/**
* @return the player who will become mayor.
*/
public Player getPlayer() {
return player;
}

public static HandlerList getHandlerList() {
return HANDLER_LIST;
}

@NotNull
@Override
public HandlerList getHandlers() {
return HANDLER_LIST;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.palmergames.bukkit.towny.confirmations.Confirmation;
import com.palmergames.bukkit.towny.confirmations.ConfirmationTransaction;
import com.palmergames.bukkit.towny.event.DeleteTownEvent;
import com.palmergames.bukkit.towny.event.town.TownPreReclaimEvent;
import com.palmergames.bukkit.towny.event.town.TownReclaimedEvent;
import com.palmergames.bukkit.towny.event.town.TownRuinedEvent;
import com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException;
Expand Down Expand Up @@ -165,6 +166,7 @@ public static void processRuinedTownReclaimRequest(Player player) {
Confirmation.runOnAccept(() -> reclaimTown(resident, town))
.setCost(new ConfirmationTransaction(() -> townReclaimCost, resident, "Cost of town reclaim.", Translatable.of("msg_insuf_funds")))
.setTitle(Translatable.of("msg_confirm_purchase", TownyEconomyHandler.getFormattedBalance(townReclaimCost)))
.setCancellableEvent(new TownPreReclaimEvent(town, resident, player))
.sendTo(player);
} catch (TownyException e) {
TownyMessaging.sendErrorMsg(player, e.getMessage(player));
Expand Down
4 changes: 3 additions & 1 deletion Towny/src/main/resources/ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9799,4 +9799,6 @@ v0.92.0.11:
- Bump me.clip:placeholderapi from 2.11.5 to 2.11.6.
0.100.2.13:
- Improve a couple SQL operations, courtesy of xyzeva with PR #7438. (First-Time Contributor!)
- Fix the relational placeholder that showed conquered status not being used for the player which are conquered.
- Fix the relational placeholder that showed conquered status not being used for the player which are conquered.
- API: Add TownPreReclaimEvent.
- A cancellable event thrown before a player can reclaim a town.

0 comments on commit afb725e

Please sign in to comment.