Remove one tick delay in teleport and gamemode check.

This commit is contained in:
benwoo1110 2021-02-18 13:22:10 +08:00
parent 89fd700e32
commit d5c65e6bc9

View File

@ -136,7 +136,6 @@ public class MVPlayerListener implements Listener {
*/ */
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void playerChangedWorld(PlayerChangedWorldEvent event) { public void playerChangedWorld(PlayerChangedWorldEvent event) {
// Permissions now determine whether or not to handle a gamemode.
this.handleGameModeAndFlight(event.getPlayer(), event.getPlayer().getWorld()); this.handleGameModeAndFlight(event.getPlayer(), event.getPlayer().getWorld());
playerWorld.put(event.getPlayer().getName(), event.getPlayer().getWorld().getName()); playerWorld.put(event.getPlayer().getName(), event.getPlayer().getWorld().getName());
} }
@ -265,6 +264,7 @@ public class MVPlayerListener implements Listener {
return; return;
} }
} }
/** /**
* This method is called when a player actually portals via a vanilla style portal. * This method is called when a player actually portals via a vanilla style portal.
* @param event The Event that was fired. * @param event The Event that was fired.
@ -318,19 +318,15 @@ public class MVPlayerListener implements Listener {
} }
private void sendPlayerToDefaultWorld(final Player player) { private void sendPlayerToDefaultWorld(final Player player) {
// Remove the player 1 tick after the login. I'm sure there's GOT to be a better way to do this...
this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin,
new Runnable() {
@Override
public void run() {
player.teleport(plugin.getMVWorldManager().getFirstSpawnWorld().getSpawnLocation()); player.teleport(plugin.getMVWorldManager().getFirstSpawnWorld().getSpawnLocation());
} }
}, 1L);
}
// FOLLOWING 2 Methods and Private class handle Per Player GameModes. /**
* Handles the gamemode for the specified {@link Player}.
* @param player The {@link Player}.
* @param world The world the player is in.
*/
private void handleGameModeAndFlight(Player player, World world) { private void handleGameModeAndFlight(Player player, World world) {
MultiverseWorld mvWorld = this.worldManager.getMVWorld(world.getName()); MultiverseWorld mvWorld = this.worldManager.getMVWorld(world.getName());
if (mvWorld != null) { if (mvWorld != null) {
this.handleGameModeAndFlight(player, mvWorld); this.handleGameModeAndFlight(player, mvWorld);
@ -343,15 +339,9 @@ public class MVPlayerListener implements Listener {
/** /**
* Handles the gamemode for the specified {@link Player}. * Handles the gamemode for the specified {@link Player}.
* @param player The {@link Player}. * @param player The {@link Player}.
* @param world The world the player is in. * @param world The MVWorld the player is in.
*/ */
public void handleGameModeAndFlight(final Player player, final MultiverseWorld world) { public void handleGameModeAndFlight(final Player player, final MultiverseWorld world) {
// We perform this task one tick later to MAKE SURE that the player actually reaches the
// destination world, otherwise we'd be changing the player mode if they havent moved anywhere.
this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin,
new Runnable() {
@Override
public void run() {
if (!MVPlayerListener.this.pt.playerCanIgnoreGameModeRestriction(world, player)) { if (!MVPlayerListener.this.pt.playerCanIgnoreGameModeRestriction(world, player)) {
// Check that the player is in the new world and they haven't been teleported elsewhere or the event cancelled. // Check that the player is in the new world and they haven't been teleported elsewhere or the event cancelled.
if (player.getWorld() == world.getCBWorld()) { if (player.getWorld() == world.getCBWorld()) {
@ -379,6 +369,4 @@ public class MVPlayerListener implements Listener {
Logging.fine("Player: " + player.getName() + " is IMMUNE to gamemode changes!"); Logging.fine("Player: " + player.getName() + " is IMMUNE to gamemode changes!");
} }
} }
}, 1L);
}
} }