Compare commits

..

2 Commits

Author SHA1 Message Date
dordsor21
48a47be17d Adjust to always check econ before merge 2025-12-31 16:17:47 +00:00
dordsor21
79c7b5275a fix: fix a specific situation where a merge can fail but take money still 2025-12-31 16:17:47 +00:00
2 changed files with 89 additions and 72 deletions

View File

@@ -40,6 +40,7 @@ import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.UUID; import java.util.UUID;
import java.util.function.Supplier;
@CommandDeclaration(command = "merge", @CommandDeclaration(command = "merge",
aliases = "m", aliases = "m",
@@ -116,9 +117,11 @@ public class Merge extends SubCommand {
if (direction == null) { if (direction == null) {
player.sendMessage( player.sendMessage(
TranslatableCaption.of("commandconfig.command_syntax"), TranslatableCaption.of("commandconfig.command_syntax"),
TagResolver.resolver("value", Tag.inserting(Component.text( TagResolver.resolver(
"value", Tag.inserting(Component.text(
"/plot merge <" + StringMan.join(values, " | ") + "> [removeroads]" "/plot merge <" + StringMan.join(values, " | ") + "> [removeroads]"
))) ))
)
); );
player.sendMessage( player.sendMessage(
TranslatableCaption.of("help.direction"), TranslatableCaption.of("help.direction"),
@@ -154,7 +157,8 @@ public class Merge extends SubCommand {
UUID uuid = player.getUUID(); UUID uuid = player.getUUID();
if (!force && !plot.isOwner(uuid)) { if (!force) {
if (!plot.isOwner(uuid)) {
if (!player.hasPermission(Permission.PERMISSION_ADMIN_COMMAND_MERGE)) { if (!player.hasPermission(Permission.PERMISSION_ADMIN_COMMAND_MERGE)) {
player.sendMessage(TranslatableCaption.of("permission.no_plot_perms")); player.sendMessage(TranslatableCaption.of("permission.no_plot_perms"));
return false; return false;
@@ -162,6 +166,17 @@ public class Merge extends SubCommand {
uuid = plot.getOwnerAbs(); uuid = plot.getOwnerAbs();
} }
} }
if (this.econHandler.isEnabled(plotArea) && !player.hasPermission(Permission.PERMISSION_ADMIN_BYPASS_ECON) && price > 0d && this.econHandler.getMoney(
player) < price) {
player.sendMessage(
TranslatableCaption.of("economy.cannot_afford_merge"),
TagResolver.resolver("money", Tag.inserting(Component.text(this.econHandler.format(price))))
);
return false;
}
}
if (direction == Direction.ALL) { if (direction == Direction.ALL) {
boolean terrain = true; boolean terrain = true;
if (args.length == 2) { if (args.length == 2) {
@@ -178,7 +193,6 @@ public class Merge extends SubCommand {
return true; return true;
} }
if (plot.getPlotModificationManager().autoMerge(Direction.ALL, maxSize, uuid, player, terrain)) { if (plot.getPlotModificationManager().autoMerge(Direction.ALL, maxSize, uuid, player, terrain)) {
if (this.econHandler.isEnabled(plotArea) && !player.hasPermission(Permission.PERMISSION_ADMIN_BYPASS_ECON) && price > 0d) {
this.econHandler.withdrawMoney(player, price); this.econHandler.withdrawMoney(player, price);
player.sendMessage( player.sendMessage(
TranslatableCaption.of("economy.removed_balance"), TranslatableCaption.of("economy.removed_balance"),
@@ -188,7 +202,6 @@ public class Merge extends SubCommand {
Tag.inserting(Component.text(this.econHandler.format(this.econHandler.getMoney(player)))) Tag.inserting(Component.text(this.econHandler.format(this.econHandler.getMoney(player))))
) )
); );
}
player.sendMessage(TranslatableCaption.of("merge.success_merge")); player.sendMessage(TranslatableCaption.of("merge.success_merge"));
eventDispatcher.callPostMerge(player, plot); eventDispatcher.callPostMerge(player, plot);
return true; return true;
@@ -196,14 +209,6 @@ public class Merge extends SubCommand {
player.sendMessage(TranslatableCaption.of("merge.no_available_automerge")); player.sendMessage(TranslatableCaption.of("merge.no_available_automerge"));
return false; return false;
} }
if (!force && this.econHandler.isEnabled(plotArea) && !player.hasPermission(Permission.PERMISSION_ADMIN_BYPASS_ECON) && price > 0d && this.econHandler.getMoney(
player) < price) {
player.sendMessage(
TranslatableCaption.of("economy.cannot_afford_merge"),
TagResolver.resolver("money", Tag.inserting(Component.text(this.econHandler.format(price))))
);
return false;
}
final boolean terrain; final boolean terrain;
if (args.length == 2) { if (args.length == 2) {
terrain = "true".equalsIgnoreCase(args[1]); terrain = "true".equalsIgnoreCase(args[1]);
@@ -244,28 +249,32 @@ public class Merge extends SubCommand {
} }
java.util.Set<UUID> uuids = adjacent.getOwners(); java.util.Set<UUID> uuids = adjacent.getOwners();
boolean isOnline = false; boolean isOnline = false;
if (!force) {
for (final UUID owner : uuids) { for (final UUID owner : uuids) {
final PlotPlayer<?> accepter = PlotSquared.platform().playerManager().getPlayerIfExists(owner); final PlotPlayer<?> accepter = PlotSquared.platform().playerManager().getPlayerIfExists(owner);
if (!force && accepter == null) { if (accepter == null) {
continue; continue;
} }
isOnline = true; isOnline = true;
final Direction dir = direction; final Direction dir = direction;
Runnable run = () -> { Supplier<Boolean> run = () -> {
accepter.sendMessage(TranslatableCaption.of("merge.merge_accepted")); accepter.sendMessage(TranslatableCaption.of("merge.merge_accepted"));
plot.getPlotModificationManager().autoMerge(dir, maxSize - size, owner, player, terrain); if (plot.getPlotModificationManager().autoMerge(dir, maxSize - size, owner, player, terrain)) {
PlotPlayer<?> plotPlayer = PlotSquared.platform().playerManager().getPlayerIfExists(player.getUUID()); PlotPlayer<?> plotPlayer = PlotSquared.platform().playerManager().getPlayerIfExists(player.getUUID());
if (plotPlayer == null) { if (plotPlayer == null) {
accepter.sendMessage(TranslatableCaption.of("merge.merge_not_valid")); accepter.sendMessage(TranslatableCaption.of("merge.merge_not_valid"));
return; return false;
} }
if (this.econHandler.isEnabled(plotArea) && !player.hasPermission(Permission.PERMISSION_ADMIN_BYPASS_ECON) && price > 0d) { if (this.econHandler.isEnabled(plotArea) && !player.hasPermission(Permission.PERMISSION_ADMIN_BYPASS_ECON) && price > 0d) {
if (!force && this.econHandler.getMoney(player) < price) { if (this.econHandler.getMoney(player) < price) {
player.sendMessage( player.sendMessage(
TranslatableCaption.of("economy.cannot_afford_merge"), TranslatableCaption.of("economy.cannot_afford_merge"),
TagResolver.resolver("money", Tag.inserting(Component.text(this.econHandler.format(price)))) TagResolver.resolver(
"money",
Tag.inserting(Component.text(this.econHandler.format(price)))
)
); );
return; return false;
} }
this.econHandler.withdrawMoney(player, price); this.econHandler.withdrawMoney(player, price);
player.sendMessage( player.sendMessage(
@@ -275,9 +284,14 @@ public class Merge extends SubCommand {
} }
player.sendMessage(TranslatableCaption.of("merge.success_merge")); player.sendMessage(TranslatableCaption.of("merge.success_merge"));
eventDispatcher.callPostMerge(player, plot); eventDispatcher.callPostMerge(player, plot);
return true;
}
player.sendMessage(TranslatableCaption.of("merge.no_available_automerge"));
return false;
}; };
if (!force && hasConfirmation(player)) { if (hasConfirmation(player)) {
CmdConfirm.addPending(accepter, MINI_MESSAGE.serialize(MINI_MESSAGE CmdConfirm.addPending(
accepter, MINI_MESSAGE.serialize(MINI_MESSAGE
.deserialize( .deserialize(
TranslatableCaption.of("merge.merge_request_confirm").getComponent(player), TranslatableCaption.of("merge.merge_request_confirm").getComponent(player),
TagResolver.builder() TagResolver.builder()
@@ -288,10 +302,13 @@ public class Merge extends SubCommand {
) )
.build() .build()
)), )),
run run::get
); );
} else { } else {
run.run(); return run.get();
}
// find first
break;
} }
} }
if (force || !isOnline) { if (force || !isOnline) {

View File

@@ -12,7 +12,7 @@ adventure-bukkit = "4.4.1"
log4j = "2.19.0" log4j = "2.19.0"
# Plugins # Plugins
worldedit = "7.3.18" worldedit = "7.2.20"
fawe = "2.14.3" fawe = "2.14.3"
placeholderapi = "2.11.7" placeholderapi = "2.11.7"
luckperms = "5.5" luckperms = "5.5"