feat: Added configurable proxy teleport delay

This commit is contained in:
Sekwah 2021-05-13 00:33:28 +01:00
parent e8cbb403c5
commit a1121adc10
No known key found for this signature in database
GPG Key ID: C3BE2E6C861A461A
3 changed files with 37 additions and 14 deletions

View File

@ -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);
}
}
}

View File

@ -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,20 +39,31 @@ public class PluginMessageReceiver implements PluginMessageListener {
Player targetPlayer = this.plugin.getServer().getPlayer(UUID.fromString(bungeeUUID));
if (targetPlayer != null) {
Destination.warp(targetPlayer, targetDestination, false, true);
if(teleportDelay <= 0) {
teleportPlayerToDesti(targetPlayer, targetDestination, bungeeUUID);
} else {
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () ->
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, targetDestination);
plugin.getPlayerDestiMap().put(bungeeUUID, desti);
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () ->
plugin.getPlayerDestiMap().remove(bungeeUUID),
20L * 10
);
}
}
}
/**

View File

@ -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