diff --git a/src/main/java/com/sekwah/advancedportals/bukkit/config/ConfigHelper.java b/src/main/java/com/sekwah/advancedportals/bukkit/config/ConfigHelper.java index d7a66b4..8c7162e 100644 --- a/src/main/java/com/sekwah/advancedportals/bukkit/config/ConfigHelper.java +++ b/src/main/java/com/sekwah/advancedportals/bukkit/config/ConfigHelper.java @@ -4,13 +4,15 @@ import org.bukkit.configuration.file.FileConfiguration; public class ConfigHelper { - public static String CONFIG_VERSION = "ConfigVersion"; + public static final String CONFIG_VERSION = "ConfigVersion"; - public static String COMMAND_LOGS = "CommandLogs"; + public static final String COMMAND_LOGS = "CommandLogs"; - public static String FORCE_ENABLE_PROXY_SUPPORT = "ForceEnableProxySupport"; + public static final String FORCE_ENABLE_PROXY_SUPPORT = "ForceEnableProxySupport"; - public static String DISABLE_GATEWAY_BEAM = "DisableGatewayBeam"; + public static final String PROXY_TELEPORT_DELAY = "ProxyTeleportDelay"; + + public static final String DISABLE_GATEWAY_BEAM = "DisableGatewayBeam"; private final FileConfiguration config; @@ -22,7 +24,7 @@ public class ConfigHelper { * Recursively for each time there is a future update */ public void update() { - String configVersion = config.getString("ConfigVersion"); + String configVersion = config.getString(CONFIG_VERSION); // Added in 0.5.4 if(configVersion == null || configVersion.equals("true") || configVersion.equals("0.5.3")) { config.set(ConfigHelper.CONFIG_VERSION, "0.5.4"); @@ -35,6 +37,7 @@ public class ConfigHelper { } else if(configVersion.equals("0.5.10") || configVersion.equals("0.5.11")) { config.set(ConfigHelper.CONFIG_VERSION, "0.5.13"); config.set(ConfigHelper.FORCE_ENABLE_PROXY_SUPPORT, false); + config.set(ConfigHelper.PROXY_TELEPORT_DELAY, 0); } } } diff --git a/src/main/java/com/sekwah/advancedportals/bukkit/listeners/PluginMessageReceiver.java b/src/main/java/com/sekwah/advancedportals/bukkit/listeners/PluginMessageReceiver.java index 640982d..693462d 100644 --- a/src/main/java/com/sekwah/advancedportals/bukkit/listeners/PluginMessageReceiver.java +++ b/src/main/java/com/sekwah/advancedportals/bukkit/listeners/PluginMessageReceiver.java @@ -3,6 +3,8 @@ package com.sekwah.advancedportals.bukkit.listeners; import com.google.common.io.ByteArrayDataInput; import com.google.common.io.ByteStreams; import com.sekwah.advancedportals.bukkit.AdvancedPortalsPlugin; +import com.sekwah.advancedportals.bukkit.config.ConfigAccessor; +import com.sekwah.advancedportals.bukkit.config.ConfigHelper; import com.sekwah.advancedportals.bukkit.destinations.Destination; import com.sekwah.advancedportals.bungee.BungeeMessages; import org.bukkit.entity.Player; @@ -13,9 +15,12 @@ import java.util.UUID; public class PluginMessageReceiver implements PluginMessageListener { private final AdvancedPortalsPlugin plugin; + private final int teleportDelay; public PluginMessageReceiver(AdvancedPortalsPlugin plugin) { this.plugin = plugin; + ConfigAccessor config = new ConfigAccessor(plugin, "config.yml"); + teleportDelay = config.getConfig().getInt(ConfigHelper.PROXY_TELEPORT_DELAY, 0); } @Override @@ -34,22 +39,33 @@ public class PluginMessageReceiver implements PluginMessageListener { Player targetPlayer = this.plugin.getServer().getPlayer(UUID.fromString(bungeeUUID)); - if (targetPlayer != null) { - Destination.warp(targetPlayer, targetDestination, false, true); - - } - else { - plugin.getPlayerDestiMap().put(bungeeUUID, targetDestination); - + if(teleportDelay <= 0) { + teleportPlayerToDesti(targetPlayer, targetDestination, bungeeUUID); + } else { plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> - plugin.getPlayerDestiMap().remove(bungeeUUID), - 20L * 10 + teleportPlayerToDesti(targetPlayer, targetDestination, bungeeUUID), + 20L * teleportDelay ); } } } + public void teleportPlayerToDesti(Player player, String desti, String bungeeUUID) { + if (player != null) { + Destination.warp(player, desti, false, true); + + } + else { + plugin.getPlayerDestiMap().put(bungeeUUID, desti); + + plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () -> + plugin.getPlayerDestiMap().remove(bungeeUUID), + 20L * 10 + ); + } + } + /** * Example forward packet. * diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 9bf16db..849668b 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -91,3 +91,7 @@ CommandLogs: true # If you want to use bungee or velocity and it is not automatically detected (make sure you have advanced portals on the proxy, especially with velocity) ForceEnableProxySupport: false + +# How many seconds after the proxy event fires should the player be teleported (should help with on spawn plugins and such) +# 0 is disabled and anything higher causes a delay. +ProxyTeleportDelay: 0