Skip to content

Commit

Permalink
feat: Added configurable proxy teleport delay
Browse files Browse the repository at this point in the history
  • Loading branch information
Sekwah committed May 12, 2021
1 parent e8cbb40 commit a1121ad
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

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;

Expand All @@ -22,7 +24,7 @@ public ConfigHelper(FileConfiguration config) {
* 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");
Expand All @@ -35,6 +37,7 @@ public void update() {
} 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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
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;
Expand All @@ -13,9 +15,12 @@
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
Expand All @@ -34,22 +39,33 @@ public void onPluginMessageReceived(String channel, Player player, byte[] messag

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.
*
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit a1121ad

Please sign in to comment.