|
40 | 40 | import org.checkerframework.checker.nullness.qual.NonNull; |
41 | 41 |
|
42 | 42 | import java.util.UUID; |
| 43 | +import java.util.function.Supplier; |
43 | 44 |
|
44 | 45 | @CommandDeclaration(command = "merge", |
45 | 46 | aliases = "m", |
@@ -116,9 +117,11 @@ public boolean onCommand(final PlotPlayer<?> player, String[] args) { |
116 | 117 | if (direction == null) { |
117 | 118 | player.sendMessage( |
118 | 119 | TranslatableCaption.of("commandconfig.command_syntax"), |
119 | | - TagResolver.resolver("value", Tag.inserting(Component.text( |
120 | | - "/plot merge <" + StringMan.join(values, " | ") + "> [removeroads]" |
121 | | - ))) |
| 120 | + TagResolver.resolver( |
| 121 | + "value", Tag.inserting(Component.text( |
| 122 | + "/plot merge <" + StringMan.join(values, " | ") + "> [removeroads]" |
| 123 | + )) |
| 124 | + ) |
122 | 125 | ); |
123 | 126 | player.sendMessage( |
124 | 127 | TranslatableCaption.of("help.direction"), |
@@ -244,54 +247,66 @@ public boolean onCommand(final PlotPlayer<?> player, String[] args) { |
244 | 247 | } |
245 | 248 | java.util.Set<UUID> uuids = adjacent.getOwners(); |
246 | 249 | boolean isOnline = false; |
247 | | - for (final UUID owner : uuids) { |
248 | | - final PlotPlayer<?> accepter = PlotSquared.platform().playerManager().getPlayerIfExists(owner); |
249 | | - if (!force && accepter == null) { |
250 | | - continue; |
251 | | - } |
252 | | - isOnline = true; |
253 | | - final Direction dir = direction; |
254 | | - Runnable run = () -> { |
255 | | - accepter.sendMessage(TranslatableCaption.of("merge.merge_accepted")); |
256 | | - plot.getPlotModificationManager().autoMerge(dir, maxSize - size, owner, player, terrain); |
257 | | - PlotPlayer<?> plotPlayer = PlotSquared.platform().playerManager().getPlayerIfExists(player.getUUID()); |
258 | | - if (plotPlayer == null) { |
259 | | - accepter.sendMessage(TranslatableCaption.of("merge.merge_not_valid")); |
260 | | - return; |
| 250 | + if (!force) { |
| 251 | + for (final UUID owner : uuids) { |
| 252 | + final PlotPlayer<?> accepter = PlotSquared.platform().playerManager().getPlayerIfExists(owner); |
| 253 | + if (accepter == null) { |
| 254 | + continue; |
261 | 255 | } |
262 | | - if (this.econHandler.isEnabled(plotArea) && !player.hasPermission(Permission.PERMISSION_ADMIN_BYPASS_ECON) && price > 0d) { |
263 | | - if (!force && this.econHandler.getMoney(player) < price) { |
264 | | - player.sendMessage( |
265 | | - TranslatableCaption.of("economy.cannot_afford_merge"), |
266 | | - TagResolver.resolver("money", Tag.inserting(Component.text(this.econHandler.format(price)))) |
267 | | - ); |
268 | | - return; |
| 256 | + isOnline = true; |
| 257 | + final Direction dir = direction; |
| 258 | + Supplier<Boolean> run = () -> { |
| 259 | + accepter.sendMessage(TranslatableCaption.of("merge.merge_accepted")); |
| 260 | + if (plot.getPlotModificationManager().autoMerge(dir, maxSize - size, owner, player, terrain)) { |
| 261 | + PlotPlayer<?> plotPlayer = PlotSquared.platform().playerManager().getPlayerIfExists(player.getUUID()); |
| 262 | + if (plotPlayer == null) { |
| 263 | + accepter.sendMessage(TranslatableCaption.of("merge.merge_not_valid")); |
| 264 | + return false; |
| 265 | + } |
| 266 | + if (this.econHandler.isEnabled(plotArea) && !player.hasPermission(Permission.PERMISSION_ADMIN_BYPASS_ECON) && price > 0d) { |
| 267 | + if (this.econHandler.getMoney(player) < price) { |
| 268 | + player.sendMessage( |
| 269 | + TranslatableCaption.of("economy.cannot_afford_merge"), |
| 270 | + TagResolver.resolver( |
| 271 | + "money", |
| 272 | + Tag.inserting(Component.text(this.econHandler.format(price))) |
| 273 | + ) |
| 274 | + ); |
| 275 | + return false; |
| 276 | + } |
| 277 | + this.econHandler.withdrawMoney(player, price); |
| 278 | + player.sendMessage( |
| 279 | + TranslatableCaption.of("economy.removed_balance"), |
| 280 | + TagResolver.resolver("money", Tag.inserting(Component.text(this.econHandler.format(price)))) |
| 281 | + ); |
| 282 | + } |
| 283 | + player.sendMessage(TranslatableCaption.of("merge.success_merge")); |
| 284 | + eventDispatcher.callPostMerge(player, plot); |
| 285 | + return true; |
269 | 286 | } |
270 | | - this.econHandler.withdrawMoney(player, price); |
271 | | - player.sendMessage( |
272 | | - TranslatableCaption.of("economy.removed_balance"), |
273 | | - TagResolver.resolver("money", Tag.inserting(Component.text(this.econHandler.format(price)))) |
| 287 | + player.sendMessage(TranslatableCaption.of("merge.no_available_automerge")); |
| 288 | + return false; |
| 289 | + }; |
| 290 | + if (hasConfirmation(player)) { |
| 291 | + CmdConfirm.addPending( |
| 292 | + accepter, MINI_MESSAGE.serialize(MINI_MESSAGE |
| 293 | + .deserialize( |
| 294 | + TranslatableCaption.of("merge.merge_request_confirm").getComponent(player), |
| 295 | + TagResolver.builder() |
| 296 | + .tag("player", Tag.inserting(Component.text(player.getName()))) |
| 297 | + .tag( |
| 298 | + "location", |
| 299 | + Tag.inserting(Component.text(plot.getWorldName() + " " + plot.getId())) |
| 300 | + ) |
| 301 | + .build() |
| 302 | + )), |
| 303 | + run::get |
274 | 304 | ); |
| 305 | + } else { |
| 306 | + return run.get(); |
275 | 307 | } |
276 | | - player.sendMessage(TranslatableCaption.of("merge.success_merge")); |
277 | | - eventDispatcher.callPostMerge(player, plot); |
278 | | - }; |
279 | | - if (!force && hasConfirmation(player)) { |
280 | | - CmdConfirm.addPending(accepter, MINI_MESSAGE.serialize(MINI_MESSAGE |
281 | | - .deserialize( |
282 | | - TranslatableCaption.of("merge.merge_request_confirm").getComponent(player), |
283 | | - TagResolver.builder() |
284 | | - .tag("player", Tag.inserting(Component.text(player.getName()))) |
285 | | - .tag( |
286 | | - "location", |
287 | | - Tag.inserting(Component.text(plot.getWorldName() + " " + plot.getId())) |
288 | | - ) |
289 | | - .build() |
290 | | - )), |
291 | | - run |
292 | | - ); |
293 | | - } else { |
294 | | - run.run(); |
| 308 | + // find first |
| 309 | + break; |
295 | 310 | } |
296 | 311 | } |
297 | 312 | if (force || !isOnline) { |
|
0 commit comments