mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2025-01-25 09:41:23 +01:00
Merge pull request #2991 from zax71/MV5-always-spawn-location
Implement JoinDestination and EnableJoinDestination config options
This commit is contained in:
commit
80dba5068c
@ -126,6 +126,30 @@ public interface MVConfig {
|
||||
*/
|
||||
String getFirstSpawnLocation();
|
||||
|
||||
/**
|
||||
* Sets whether join destination should be enabled.
|
||||
* @param enableJoinDestination The new value
|
||||
*/
|
||||
void setEnableJoinDestination(boolean enableJoinDestination);
|
||||
|
||||
/**
|
||||
* Gets enableJoinDestination.
|
||||
* @return enableJoinDestination
|
||||
*/
|
||||
boolean getEnableJoinDestination();
|
||||
|
||||
/**
|
||||
* Sets alwaysSpawnDestination.
|
||||
* @param alwaysSpawnDestination The new value
|
||||
*/
|
||||
void setJoinDestination(String alwaysSpawnDestination);
|
||||
|
||||
/**
|
||||
* Gets alwaysSpawnDestination.
|
||||
* @return alwaysSpawnLocation
|
||||
*/
|
||||
String getJoinDestination();
|
||||
|
||||
/**
|
||||
* Sets whether or not to let Bukkit determine portal search radius on its own or if Multiverse should give input.
|
||||
*
|
||||
|
@ -3,12 +3,14 @@ package org.mvplugins.multiverse.core.config;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Objects;
|
||||
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import io.vavr.control.Try;
|
||||
import jakarta.inject.Inject;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jvnet.hk2.annotations.Service;
|
||||
|
||||
import org.mvplugins.multiverse.core.MultiverseCore;
|
||||
@ -180,6 +182,30 @@ public class MVCoreConfig implements MVConfig {
|
||||
return configHandle.get(configNodes.FIRST_SPAWN_LOCATION);
|
||||
}
|
||||
|
||||
@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 setJoinDestination(String alwaysSpawnDestination) {
|
||||
configHandle.set(configNodes.JOIN_DESTINATION, alwaysSpawnDestination);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String getJoinDestination() {
|
||||
if (Objects.equals(configHandle.get(configNodes.JOIN_DESTINATION), "")) {
|
||||
return null;
|
||||
}
|
||||
return configHandle.get(configNodes.JOIN_DESTINATION);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUseCustomPortalSearch(boolean useDefaultPortalSearch) {
|
||||
configHandle.set(configNodes.USE_CUSTOM_PORTAL_SEARCH, useDefaultPortalSearch);
|
||||
|
@ -120,6 +120,21 @@ class MVCoreConfigNodes {
|
||||
.name("first-spawn-location")
|
||||
.build());
|
||||
|
||||
final ConfigNode<Boolean> ENABLE_JOIN_DESTINATION = node(ConfigNode.builder("spawn.enable-join-destination", Boolean.class)
|
||||
.comment("")
|
||||
.comment("Enables join-destination below.")
|
||||
.defaultValue(false)
|
||||
.name("enable-join-destination")
|
||||
.build());
|
||||
|
||||
final ConfigNode<String> 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")
|
||||
.defaultValue("")
|
||||
.name("join-destination")
|
||||
.build());
|
||||
|
||||
private final ConfigHeaderNode PORTAL_HEADER = node(ConfigHeaderNode.builder("portal")
|
||||
.comment("")
|
||||
.comment("")
|
||||
|
@ -83,7 +83,8 @@ public class DestinationsProvider {
|
||||
* @param destinationString The destination string.
|
||||
* @return The destination object, or null if invalid format.
|
||||
*/
|
||||
public ParsedDestination<?> parseDestination(String destinationString) {
|
||||
@Nullable
|
||||
public ParsedDestination<?> parseDestination(@NotNull String destinationString) {
|
||||
String[] items = destinationString.split(SEPARATOR, 2);
|
||||
|
||||
String idString = items[0];
|
||||
|
@ -30,6 +30,7 @@ import org.bukkit.event.player.PlayerPortalEvent;
|
||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jvnet.hk2.annotations.Service;
|
||||
|
||||
import org.mvplugins.multiverse.core.MultiverseCore;
|
||||
@ -57,7 +58,7 @@ public class MVPlayerListener implements InjectableListener {
|
||||
private final Plugin plugin;
|
||||
private final MVCoreConfig config;
|
||||
private final Provider<WorldManager> worldManagerProvider;
|
||||
private final SafeTTeleporter safeTTeleporter;
|
||||
private final SafeTTeleporter safetyTeleporter;
|
||||
private final Server server;
|
||||
private final TeleportQueue teleportQueue;
|
||||
private final MVEconomist economist;
|
||||
@ -73,7 +74,7 @@ public class MVPlayerListener implements InjectableListener {
|
||||
MultiverseCore plugin,
|
||||
MVCoreConfig config,
|
||||
Provider<WorldManager> worldManagerProvider,
|
||||
SafeTTeleporter safeTTeleporter,
|
||||
SafeTTeleporter safetyTeleporter,
|
||||
Server server,
|
||||
TeleportQueue teleportQueue,
|
||||
MVEconomist economist,
|
||||
@ -84,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;
|
||||
@ -178,13 +179,8 @@ public class MVPlayerListener implements InjectableListener {
|
||||
Logging.fine("Moving NEW player to(firstspawnoverride): %s", config.getFirstSpawnLocation());
|
||||
this.sendPlayerToDefaultWorld(player, parsedDestination);
|
||||
}
|
||||
} else {
|
||||
Logging.finer("Player joined AGAIN!");
|
||||
if (worldEntryCheckerProvider.forSender(player).canAccessWorld(world).isFailure()) {
|
||||
player.sendMessage("[MV] - Sorry you can't be in this world anymore!");
|
||||
this.sendPlayerToDefaultWorld(player, parsedDestination);
|
||||
}
|
||||
}
|
||||
handleJoinDestination(player);
|
||||
});
|
||||
|
||||
// Handle the Players GameMode setting for the new world.
|
||||
@ -192,6 +188,34 @@ public class MVPlayerListener implements InjectableListener {
|
||||
playerWorld.put(player.getName(), player.getWorld().getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Will teleport the player to the destination specified in config
|
||||
* @param player The {@link Player} to teleport
|
||||
*/
|
||||
private void handleJoinDestination(@NotNull Player player) {
|
||||
if (!config.getEnableJoinDestination()) {
|
||||
Logging.finer("JoinDestination is disabled");
|
||||
// User has disabled the feature in config
|
||||
return;
|
||||
}
|
||||
|
||||
if (config.getJoinDestination() == null) {
|
||||
Logging.warning("Joindestination is enabled but no destination has been specified in config!");
|
||||
return;
|
||||
}
|
||||
|
||||
Logging.finer("JoinDestination is " + config.getJoinDestination());
|
||||
ParsedDestination<?> joinDestination = destinationsProvider.parseDestination(config.getJoinDestination());
|
||||
|
||||
if (joinDestination == null) {
|
||||
Logging.warning("The destination in JoinDestination in config is invalid");
|
||||
return;
|
||||
}
|
||||
|
||||
// Finally, teleport the player
|
||||
safetyTeleporter.teleportAsync(getCommandManager().getCommandIssuer(player), player, joinDestination);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when a player changes worlds.
|
||||
* @param event The Event that was fired.
|
||||
@ -278,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) {
|
||||
@ -330,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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user