Merge pull request #207 from tmantti/bungee-destifix

Fix timing issues with bungeecord destination warps
This commit is contained in:
Sekwah 2020-07-16 23:48:41 +01:00 committed by GitHub
commit 5718d789d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 10 deletions

View File

@ -12,6 +12,8 @@ import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.HashMap;
public class AdvancedPortalsPlugin extends JavaPlugin {
//public CraftBukkit compat = null;
@ -21,7 +23,7 @@ public class AdvancedPortalsPlugin extends JavaPlugin {
public boolean registeredBungeeChannels = false;
// public HashMap<OfflinePlayer, String> PlayerDestiMap = new HashMap<>();
public HashMap<String, String> PlayerDestiMap = new HashMap<>();
public void onEnable() {

View File

@ -89,7 +89,20 @@ public class Listeners implements Listener {
@EventHandler
public void onJoinEvent(PlayerJoinEvent event) {
Portal.joinCooldown.put(event.getPlayer().getName(), System.currentTimeMillis());
Player player = event.getPlayer();
Portal.joinCooldown.put(player.getName(), System.currentTimeMillis());
String uuid = player.getUniqueId().toString();
if (plugin.PlayerDestiMap.containsKey(uuid)) {
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> {
Destination.warp(player, plugin.PlayerDestiMap.get(uuid), false, true);
plugin.PlayerDestiMap.remove(uuid);
}, 1L);
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)

View File

@ -31,20 +31,24 @@ public class PluginMessageReceiver implements PluginMessageListener {
if (subchannel.equals(BungeeMessages.SERVER_DESTI)) {
String targetDestination = in.readUTF();
UUID bungeeUUID = UUID.fromString(in.readUTF());
Player targetPlayer = this.plugin.getServer().getPlayer(bungeeUUID);
String bungeeUUID = in.readUTF();
Player targetPlayer = this.plugin.getServer().getPlayer(UUID.fromString(bungeeUUID));
if (targetPlayer != null) {
Player finalTargetPlayer = targetPlayer;
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin,
() -> Destination.warp(finalTargetPlayer, targetDestination, false, true),
20L
);
Destination.warp(finalTargetPlayer, targetDestination, false, true);
}
else {
plugin.getLogger().warning("Could not find player to teleport to destination");
plugin.PlayerDestiMap.put(bungeeUUID, targetDestination);
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () ->
plugin.PlayerDestiMap.remove(bungeeUUID),
20L*10
);
}
}
}