-
-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #395 from Mindgamesnl/feature/wait-until-teleporta…
…tion-finished [fix] wait until teleportation went through before re-updating player…
- Loading branch information
Showing
2 changed files
with
19 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 19 additions & 10 deletions
29
...m/craftmend/openaudiomc/spigot/modules/players/listeners/PlayerTeleportationListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,35 @@ | ||
package com.craftmend.openaudiomc.spigot.modules.players.listeners; | ||
|
||
import com.craftmend.openaudiomc.OpenAudioMc; | ||
import com.craftmend.openaudiomc.spigot.OpenAudioMcSpigot; | ||
import com.craftmend.openaudiomc.spigot.modules.players.SpigotPlayerService; | ||
import com.craftmend.openaudiomc.spigot.modules.players.objects.SpigotConnection; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.EventPriority; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.player.PlayerTeleportEvent; | ||
|
||
public class PlayerTeleportationListener implements Listener { | ||
|
||
@EventHandler | ||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) | ||
public void onTp(PlayerTeleportEvent event) { | ||
// this event might be called before the player is registered, as some plugins use | ||
// the teleport event to warp them to spawn, instead of the player spawn event | ||
if (!OpenAudioMc.getService(SpigotPlayerService.class).hasClient(event.getPlayer())) return; | ||
|
||
SpigotConnection spigotConnection = OpenAudioMc.getService(SpigotPlayerService.class).getClient(event.getPlayer()); | ||
if (spigotConnection == null) return; | ||
if (spigotConnection.getRegionHandler() != null) { | ||
spigotConnection.getRegionHandler().tick(); | ||
} | ||
spigotConnection.getSpeakerHandler().tick(); | ||
// run a tick later, to run post teleport if the player actually moved | ||
Bukkit.getScheduler().runTaskLater(OpenAudioMcSpigot.getInstance(), () -> { | ||
if (event.isCancelled()) return; | ||
|
||
// this event might be called before the player is registered, as some plugins use | ||
// the teleport event to warp them to spawn, instead of the player spawn event | ||
if (!OpenAudioMc.getService(SpigotPlayerService.class).hasClient(event.getPlayer())) return; | ||
|
||
SpigotConnection spigotConnection = OpenAudioMc.getService(SpigotPlayerService.class).getClient(event.getPlayer()); | ||
if (spigotConnection == null) return; | ||
if (spigotConnection.getRegionHandler() != null) { | ||
spigotConnection.getRegionHandler().tick(); | ||
} | ||
spigotConnection.getSpeakerHandler().tick(); | ||
}, 1); | ||
} | ||
|
||
} |