From b78941c0a0d965876816508c09ffb44413ef2a21 Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Tue, 12 Sep 2023 11:33:50 +0800 Subject: [PATCH] Refactor join-destination config and use async teleport --- .../multiverse/core/api/MVConfig.java | 32 +++++++++---------- .../multiverse/core/config/MVCoreConfig.java | 24 +++++++------- .../core/config/MVCoreConfigNodes.java | 6 ++-- .../core/listeners/MVPlayerListener.java | 18 ++++------- 4 files changed, 37 insertions(+), 43 deletions(-) diff --git a/src/main/java/org/mvplugins/multiverse/core/api/MVConfig.java b/src/main/java/org/mvplugins/multiverse/core/api/MVConfig.java index 3944b385..994d2747 100644 --- a/src/main/java/org/mvplugins/multiverse/core/api/MVConfig.java +++ b/src/main/java/org/mvplugins/multiverse/core/api/MVConfig.java @@ -127,29 +127,29 @@ public interface MVConfig { String getFirstSpawnLocation(); /** - * Sets alwaysSpawnDestination - * @param alwaysSpawnWorld The new value + * Sets whether join destination should be enabled. + * @param enableJoinDestination The new value */ - void setJoinDestination(String alwaysSpawnWorld); + void setEnableJoinDestination(boolean enableJoinDestination); /** - * Gets alwaysSpawnDestination + * Gets enableJoinDestination. + * @return enableJoinDestination + */ + boolean getEnableJoinDestination(); + + /** + * Sets alwaysSpawnDestination. + * @param alwaysSpawnDestination The new value + */ + void setJoinDestination(String alwaysSpawnDestination); + + /** + * Gets alwaysSpawnDestination. * @return alwaysSpawnLocation */ String getJoinDestination(); - /** - * Sets alwaysSpawnDestination - * @param enableAlwaysSpawnDestination The new value - */ - void setEnableJoinDestination(boolean enableAlwaysSpawnDestination); - - /** - * Gets enableAlwaysSpawnDestination - * @return enableAlwaysSpawnDestination - */ - boolean getEnableJoinDestination(); - /** * Sets whether or not to let Bukkit determine portal search radius on its own or if Multiverse should give input. * diff --git a/src/main/java/org/mvplugins/multiverse/core/config/MVCoreConfig.java b/src/main/java/org/mvplugins/multiverse/core/config/MVCoreConfig.java index ef346eab..576e482d 100644 --- a/src/main/java/org/mvplugins/multiverse/core/config/MVCoreConfig.java +++ b/src/main/java/org/mvplugins/multiverse/core/config/MVCoreConfig.java @@ -183,8 +183,18 @@ public class MVCoreConfig implements MVConfig { } @Override - public void setJoinDestination(String alwaysSpawnWorld) { - configHandle.set(configNodes.JOIN_DESTINATION, alwaysSpawnWorld); + public void setEnableJoinDestination(boolean enableJoinDestination) { + configHandle.set(configNodes.ENABLE_JOIN_DESTINATION, enableJoinDestination); + } + + @Override + public boolean getEnableJoinDestination() { + return configHandle.get(configNodes.ENABLE_JOIN_DESTINATION); + } + + @Override + public void setJoinDestination(String alwaysSpawnDestination) { + configHandle.set(configNodes.JOIN_DESTINATION, alwaysSpawnDestination); } @Override @@ -196,16 +206,6 @@ public class MVCoreConfig implements MVConfig { return configHandle.get(configNodes.JOIN_DESTINATION); } - @Override - public void setEnableJoinDestination(boolean enableJoinDestination) { - configHandle.set(configNodes.ENABLE_JOIN_DESTINATION, enableJoinDestination); - } - - @Override - public boolean getEnableJoinDestination() { - return configHandle.get(configNodes.ENABLE_JOIN_DESTINATION); - } - @Override public void setUseCustomPortalSearch(boolean useDefaultPortalSearch) { configHandle.set(configNodes.USE_CUSTOM_PORTAL_SEARCH, useDefaultPortalSearch); diff --git a/src/main/java/org/mvplugins/multiverse/core/config/MVCoreConfigNodes.java b/src/main/java/org/mvplugins/multiverse/core/config/MVCoreConfigNodes.java index f41b36f0..5f37ce7d 100644 --- a/src/main/java/org/mvplugins/multiverse/core/config/MVCoreConfigNodes.java +++ b/src/main/java/org/mvplugins/multiverse/core/config/MVCoreConfigNodes.java @@ -120,14 +120,14 @@ class MVCoreConfigNodes { .name("first-spawn-location") .build()); - public final ConfigNode ENABLE_JOIN_DESTINATION = node(ConfigNode.builder("spawn.enable-join-destination", Boolean.class) + final ConfigNode ENABLE_JOIN_DESTINATION = node(ConfigNode.builder("spawn.enable-join-destination", Boolean.class) .comment("") - .comment("Enables always-spawn-destination") + .comment("Enables join-destination below.") .defaultValue(false) .name("enable-join-destination") .build()); - public final ConfigNode JOIN_DESTINATION = node(ConfigNode.builder("spawn.join-destination", String.class) + final ConfigNode JOIN_DESTINATION = node(ConfigNode.builder("spawn.join-destination", String.class) .comment("") .comment("Sets the destination that Multiverse will use to spawn players on every login") .comment("Set the above enable-join-destination to false to disable") diff --git a/src/main/java/org/mvplugins/multiverse/core/listeners/MVPlayerListener.java b/src/main/java/org/mvplugins/multiverse/core/listeners/MVPlayerListener.java index ad4f336d..88e1074d 100644 --- a/src/main/java/org/mvplugins/multiverse/core/listeners/MVPlayerListener.java +++ b/src/main/java/org/mvplugins/multiverse/core/listeners/MVPlayerListener.java @@ -58,7 +58,7 @@ public class MVPlayerListener implements InjectableListener { private final Plugin plugin; private final MVCoreConfig config; private final Provider worldManagerProvider; - private final SafeTTeleporter safeTTeleporter; + private final SafeTTeleporter safetyTeleporter; private final Server server; private final TeleportQueue teleportQueue; private final MVEconomist economist; @@ -74,7 +74,7 @@ public class MVPlayerListener implements InjectableListener { MultiverseCore plugin, MVCoreConfig config, Provider worldManagerProvider, - SafeTTeleporter safeTTeleporter, + SafeTTeleporter safetyTeleporter, Server server, TeleportQueue teleportQueue, MVEconomist economist, @@ -85,7 +85,7 @@ public class MVPlayerListener implements InjectableListener { this.plugin = plugin; this.config = config; this.worldManagerProvider = worldManagerProvider; - this.safeTTeleporter = safeTTeleporter; + this.safetyTeleporter = safetyTeleporter; this.server = server; this.teleportQueue = teleportQueue; this.economist = economist; @@ -212,14 +212,8 @@ public class MVPlayerListener implements InjectableListener { return; } - Location joinDestinationLocation = joinDestination.getLocation(player); - if (joinDestinationLocation == null) { - Logging.finer("Not teleporting " + player.getName() + " because joinDestination is null"); - return; - } - // Finally, teleport the player - player.teleport(joinDestinationLocation); + safetyTeleporter.teleportAsync(getCommandManager().getCommandIssuer(player), player, joinDestination); } /** @@ -308,7 +302,7 @@ public class MVPlayerListener implements InjectableListener { // REMEMBER! getTo MAY be NULL HERE!!! // If the player was actually outside of the portal, adjust the from location if (event.getFrom().getWorld().getBlockAt(event.getFrom()).getType() != Material.NETHER_PORTAL) { - Location newloc = this.safeTTeleporter.findPortalBlockNextTo(event.getFrom()); + Location newloc = this.safetyTeleporter.findPortalBlockNextTo(event.getFrom()); // TODO: Fix this. Currently, we only check for PORTAL blocks. I'll have to figure out what // TODO: we want to do here. if (newloc != null) { @@ -360,7 +354,7 @@ public class MVPlayerListener implements InjectableListener { new Runnable() { @Override public void run() { - safeTTeleporter.safelyTeleportAsync(getCommandManager().getCommandIssuer(player), player, parsedDestination); + safetyTeleporter.safelyTeleportAsync(getCommandManager().getCommandIssuer(player), player, parsedDestination); } }, 1L); }