|
7 | 7 |
|
8 | 8 | package org.mvplugins.multiverse.core.listeners; |
9 | 9 |
|
10 | | -import java.util.Map; |
11 | 10 | import java.util.Objects; |
12 | | -import java.util.concurrent.ConcurrentHashMap; |
13 | 11 |
|
14 | 12 | import com.dumptruckman.minecraft.util.Logging; |
15 | 13 | import io.vavr.control.Option; |
@@ -402,21 +400,31 @@ void playerPortal(PlayerPortalEvent event) { |
402 | 400 | } |
403 | 401 |
|
404 | 402 | /** |
405 | | - * Handles the gamemode for the specified {@link Player}. |
| 403 | + * Handles the gamemode for the specified {@link Player}. Delays the enforcement if configured to do so |
| 404 | + * to ensure multiverse has final say over other plugins changing gamemodes. |
406 | 405 | * |
407 | 406 | * @param player The {@link Player}. |
408 | 407 | * @param world The {@link World} the player is supposed to be in. |
409 | 408 | */ |
410 | 409 | private void handleGameModeAndFlight(final Player player, World world) { |
411 | | - // We perform this task one tick later to MAKE SURE that the player actually reaches the |
412 | | - // destination world, otherwise we'd be changing the player mode if they havent moved anywhere. |
413 | | - this.server.getScheduler().runTaskLater(this.plugin, () -> { |
414 | | - if (!player.isOnline() || !player.getWorld().equals(world)) { |
415 | | - return; |
416 | | - } |
417 | | - Logging.finer("Handling gamemode and flight for player %s in world '%s'", player.getName(), world.getName()); |
418 | | - enforcementHandler.handleFlightEnforcement(player); |
419 | | - enforcementHandler.handleGameModeEnforcement(player); |
420 | | - }, 1L); |
| 410 | + if (config.getGamemodeAndFlightEnforceDelay() <= 0) { |
| 411 | + doGameModeAndFlightEnforcement(player, world); |
| 412 | + return; |
| 413 | + } |
| 414 | + server.getScheduler().runTaskLater( |
| 415 | + this.plugin, |
| 416 | + () -> doGameModeAndFlightEnforcement(player, world), |
| 417 | + config.getGamemodeAndFlightEnforceDelay() |
| 418 | + ); |
| 419 | + } |
| 420 | + |
| 421 | + private void doGameModeAndFlightEnforcement(Player player, World world) { |
| 422 | + if (!player.isOnline() || !player.getWorld().equals(world)) { |
| 423 | + Logging.finer("Player %s is no longer online or not in the expected world '%s'", player.getName(), world.getName()); |
| 424 | + return; |
| 425 | + } |
| 426 | + Logging.finer("Handling gamemode and flight for player %s in world '%s'", player.getName(), world.getName()); |
| 427 | + enforcementHandler.handleFlightEnforcement(player); |
| 428 | + enforcementHandler.handleGameModeEnforcement(player); |
421 | 429 | } |
422 | 430 | } |
0 commit comments