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 an isOverClaim property to TownClaimEvent and TownUnclaimEvent #7165

Merged
merged 3 commits into from
Jan 7, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Expand Up @@ -3801,7 +3801,7 @@ private void parseTownTakeoverClaimCommand(Player player) throws TownyException
double cost = TownySettings.getTakeoverClaimPrice();
String costSlug = !TownyEconomyHandler.isActive() || cost <= 0 ? Translatable.of("msg_spawn_cost_free").forLocale(player) : prettyMoney(cost);
String townName = overclaimedTown.getName();
Confirmation.runOnAccept(() -> Bukkit.getScheduler().runTask(plugin, new TownClaim(plugin, player, town, Arrays.asList(wc), false, true, false)))
Confirmation.runOnAccept(() -> Bukkit.getScheduler().runTask(plugin, new TownClaim(plugin, player, town, Arrays.asList(wc), false, true, false, true)))
.setTitle(Translatable.of("confirmation_you_are_about_to_take_over_a_claim", townName, costSlug))
.setCost(new ConfirmationTransaction(() -> cost, town, "Takeover Claim (" + wc.toString() + ") from " + townName + "."))
.sendTo(player);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ public void removeTownBlock(TownBlock townBlock) {
TownyRegenAPI.addToRegenQueueList(townBlock.getWorldCoord(), true);

// Raise an event to signal the unclaim
BukkitTools.fireEvent(new TownUnclaimEvent(town, townBlock.getWorldCoord()));
BukkitTools.fireEvent(new TownUnclaimEvent(town, townBlock.getWorldCoord(), false));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class TownClaimEvent extends Event {

private final TownBlock townBlock;
private Resident resident;
private boolean isOverClaim;

@Override
public HandlerList getHandlers() {
Expand All @@ -28,13 +29,22 @@ public static HandlerList getHandlerList() {
return handlers;
}

public TownClaimEvent(TownBlock townBlock, Player player) {
public TownClaimEvent(TownBlock townBlock, Player player, boolean isOverClaim) {
super(!Bukkit.getServer().isPrimaryThread());
this.townBlock = townBlock;
this.resident = TownyUniverse.getInstance().getResident(player.getUniqueId());
this.isOverClaim = isOverClaim;
}

/**
/**
* Whether the claim has resulted from takeoverclaim.
* @return true if the claim resulted from /t takeoverclaim.
*/
public boolean isOverClaim() {
return isOverClaim;
}

/**
*
* @return the new TownBlock.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ public class TownUnclaimEvent extends Event {
private static final HandlerList handlers = new HandlerList();
private final Town town;
private final WorldCoord worldCoord;
private boolean isOverClaim;

public TownUnclaimEvent(Town town, WorldCoord worldCoord) {
public TownUnclaimEvent(Town town, WorldCoord worldCoord, boolean isOverClaim) {
super(!Bukkit.getServer().isPrimaryThread());
this.town = town;
this.worldCoord = worldCoord;
this.isOverClaim = isOverClaim;
}

@NotNull
Expand All @@ -34,7 +36,15 @@ public static HandlerList getHandlerList() {
return handlers;
}

/**
/**
* Whether the unclaim has resulted from takeoverclaim.
* @return true if the unclaim resulted from /t takeoverclaim.
*/
public boolean isOverClaim() {
return isOverClaim;
}

/**
* @return {@link Town} which is unclaiming land.
*/
@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class TownClaim implements Runnable {
private double runningRefund = 0.0;
private double insufficientFunds = 0.0;
private boolean successfulRun = false;
private boolean isOverClaim = false;

/**
* @param plugin reference to towny
Expand All @@ -69,6 +70,20 @@ public TownClaim(Towny plugin, Player player, Town town, List<WorldCoord> select
this.runningRefund = 0.0;
}

public TownClaim(Towny plugin, Player player, Town town, List<WorldCoord> selection, boolean isOutpost, boolean claim, boolean forced, boolean isOverClaim) {
this.plugin = plugin;
this.player = player;
if (this.player != null)
this.outpostLocation = player.getLocation();
this.town = town;
this.selection = selection;
this.outpost = isOutpost;
this.claim = claim;
this.forced = forced;
this.runningRefund = 0.0;
this.isOverClaim = isOverClaim;
}

@Override
public void run() {
lock.lock();
Expand Down Expand Up @@ -193,7 +208,7 @@ private void townClaim(WorldCoord worldCoord) throws TownyException {
Town oldTown = worldCoord.getTownOrNull();

// Fire an event for other plugins.
BukkitTools.fireEvent(new TownUnclaimEvent(oldTown, worldCoord));
BukkitTools.fireEvent(new TownUnclaimEvent(oldTown, worldCoord, isOverClaim));

if (townBlock.hasResident())
townBlock.setResident(null, false);
Expand Down Expand Up @@ -226,7 +241,7 @@ private void townClaim(WorldCoord worldCoord) throws TownyException {
townBlock.save();

// Raise an event for the claim
BukkitTools.fireEvent(new TownClaimEvent(townBlock, player));
BukkitTools.fireEvent(new TownClaimEvent(townBlock, player, isOverClaim));
}

private void handleRevertOnUnclaimPossiblities(WorldCoord worldCoord, TownBlock townBlock) {
Expand Down