mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-11-22 02:25:41 +01:00
Remove one tick delay in teleport and gamemode check.
This commit is contained in:
parent
89fd700e32
commit
d5c65e6bc9
@ -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...
|
player.teleport(plugin.getMVWorldManager().getFirstSpawnWorld().getSpawnLocation());
|
||||||
this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin,
|
|
||||||
new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
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,42 +339,34 @@ 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
|
if (!MVPlayerListener.this.pt.playerCanIgnoreGameModeRestriction(world, player)) {
|
||||||
// destination world, otherwise we'd be changing the player mode if they havent moved anywhere.
|
// Check that the player is in the new world and they haven't been teleported elsewhere or the event cancelled.
|
||||||
this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin,
|
if (player.getWorld() == world.getCBWorld()) {
|
||||||
new Runnable() {
|
Logging.fine("Handling gamemode for player: %s, Changing to %s", player.getName(), world.getGameMode().toString());
|
||||||
@Override
|
Logging.finest("From World: %s", player.getWorld());
|
||||||
public void run() {
|
Logging.finest("To World: %s", world);
|
||||||
if (!MVPlayerListener.this.pt.playerCanIgnoreGameModeRestriction(world, player)) {
|
player.setGameMode(world.getGameMode());
|
||||||
// Check that the player is in the new world and they haven't been teleported elsewhere or the event cancelled.
|
// Check if their flight mode should change
|
||||||
if (player.getWorld() == world.getCBWorld()) {
|
// TODO need a override permission for this
|
||||||
Logging.fine("Handling gamemode for player: %s, Changing to %s", player.getName(), world.getGameMode().toString());
|
if (player.getAllowFlight() && !world.getAllowFlight() && player.getGameMode() != GameMode.CREATIVE) {
|
||||||
Logging.finest("From World: %s", player.getWorld());
|
player.setAllowFlight(false);
|
||||||
Logging.finest("To World: %s", world);
|
if (player.isFlying()) {
|
||||||
player.setGameMode(world.getGameMode());
|
player.setFlying(false);
|
||||||
// Check if their flight mode should change
|
|
||||||
// TODO need a override permission for this
|
|
||||||
if (player.getAllowFlight() && !world.getAllowFlight() && player.getGameMode() != GameMode.CREATIVE) {
|
|
||||||
player.setAllowFlight(false);
|
|
||||||
if (player.isFlying()) {
|
|
||||||
player.setFlying(false);
|
|
||||||
}
|
|
||||||
} else if (world.getAllowFlight()) {
|
|
||||||
if (player.getGameMode() == GameMode.CREATIVE) {
|
|
||||||
player.setAllowFlight(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Logging.fine("The gamemode/allowfly was NOT changed for player '%s' because he is now in world '%s' instead of world '%s'",
|
|
||||||
player.getName(), player.getWorld().getName(), world.getName());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Logging.fine("Player: " + player.getName() + " is IMMUNE to gamemode changes!");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}, 1L);
|
} else if (world.getAllowFlight()) {
|
||||||
|
if (player.getGameMode() == GameMode.CREATIVE) {
|
||||||
|
player.setAllowFlight(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Logging.fine("The gamemode/allowfly was NOT changed for player '%s' because he is now in world '%s' instead of world '%s'",
|
||||||
|
player.getName(), player.getWorld().getName(), world.getName());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Logging.fine("Player: " + player.getName() + " is IMMUNE to gamemode changes!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user