mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-11-26 12:35:39 +01:00
Implement JoinDestination and EnableJoinDestination config options
This commit is contained in:
parent
046840f0d9
commit
3b7a801a0c
@ -125,6 +125,30 @@ public interface MVConfig {
|
||||
*/
|
||||
String getFirstSpawnLocation();
|
||||
|
||||
/**
|
||||
* Sets alwaysSpawnDestination
|
||||
* @param alwaysSpawnWorld The new value
|
||||
*/
|
||||
void setJoinDestination(String alwaysSpawnWorld);
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
|
@ -3,6 +3,7 @@ package com.onarandombox.MultiverseCore.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 com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
@ -19,6 +20,7 @@ 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;
|
||||
|
||||
@Service
|
||||
@ -180,6 +182,30 @@ public class MVCoreConfig implements MVConfig {
|
||||
return configHandle.get(configNodes.FIRST_SPAWN_LOCATION);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setJoinDestination(String alwaysSpawnWorld) {
|
||||
configHandle.set(configNodes.JOIN_DESTINATION, alwaysSpawnWorld);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String getJoinDestination() {
|
||||
if (Objects.equals(configHandle.get(configNodes.JOIN_DESTINATION), "")) {
|
||||
return null;
|
||||
}
|
||||
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);
|
||||
|
@ -7,7 +7,6 @@ import com.onarandombox.MultiverseCore.configuration.node.Node;
|
||||
import com.onarandombox.MultiverseCore.configuration.node.NodeGroup;
|
||||
import com.onarandombox.MultiverseCore.event.MVDebugModeEvent;
|
||||
import com.onarandombox.MultiverseCore.exceptions.MultiverseException;
|
||||
import io.github.townyadvanced.commentedconfiguration.setting.CommentedNode;
|
||||
import io.vavr.control.Try;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
|
||||
@ -113,6 +112,21 @@ class MVCoreConfigNodes {
|
||||
.name("first-spawn-location")
|
||||
.build());
|
||||
|
||||
public final ConfigNode<String> JOIN_DESTINATION = node(ConfigNode.builder("spawn.always-spawn-destination", String.class)
|
||||
.comment("")
|
||||
.comment("Sets the destination that Multiverse will use to spawn players on every login")
|
||||
.comment("Set blank to disable")
|
||||
.defaultValue("")
|
||||
.name("always-spawn-destination")
|
||||
.build());
|
||||
|
||||
public final ConfigNode<Boolean> ENABLE_JOIN_DESTINATION = node(ConfigNode.builder("spawn.enable-always-spawn-destination", Boolean.class)
|
||||
.comment("")
|
||||
.comment("Enables always-spawn-destination")
|
||||
.defaultValue(false)
|
||||
.name("enable-always-spawn-destination")
|
||||
.build());
|
||||
|
||||
private final ConfigHeaderNode PORTAL_HEADER = node(ConfigHeaderNode.builder("portal")
|
||||
.comment("")
|
||||
.comment("")
|
||||
|
@ -85,7 +85,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];
|
||||
|
@ -18,6 +18,8 @@ import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import com.onarandombox.MultiverseCore.api.SafeTTeleporter;
|
||||
import com.onarandombox.MultiverseCore.commandtools.MVCommandManager;
|
||||
import com.onarandombox.MultiverseCore.config.MVCoreConfig;
|
||||
import com.onarandombox.MultiverseCore.destination.DestinationsProvider;
|
||||
import com.onarandombox.MultiverseCore.destination.ParsedDestination;
|
||||
import com.onarandombox.MultiverseCore.economy.MVEconomist;
|
||||
import com.onarandombox.MultiverseCore.event.MVRespawnEvent;
|
||||
import com.onarandombox.MultiverseCore.inject.InjectableListener;
|
||||
@ -43,6 +45,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;
|
||||
|
||||
/**
|
||||
@ -53,6 +56,7 @@ public class MVPlayerListener implements InjectableListener {
|
||||
private final Plugin plugin;
|
||||
private final MVCoreConfig config;
|
||||
private final Provider<MVWorldManager> worldManagerProvider;
|
||||
private final DestinationsProvider destinationsProvider;
|
||||
private final SafeTTeleporter safeTTeleporter;
|
||||
private final Server server;
|
||||
private final TeleportQueue teleportQueue;
|
||||
@ -68,6 +72,7 @@ public class MVPlayerListener implements InjectableListener {
|
||||
MultiverseCore plugin,
|
||||
MVCoreConfig config,
|
||||
Provider<MVWorldManager> worldManagerProvider,
|
||||
DestinationsProvider destinationsProvider,
|
||||
SafeTTeleporter safeTTeleporter,
|
||||
Server server,
|
||||
TeleportQueue teleportQueue,
|
||||
@ -79,6 +84,7 @@ public class MVPlayerListener implements InjectableListener {
|
||||
this.plugin = plugin;
|
||||
this.config = config;
|
||||
this.worldManagerProvider = worldManagerProvider;
|
||||
this.destinationsProvider = destinationsProvider;
|
||||
this.safeTTeleporter = safeTTeleporter;
|
||||
this.server = server;
|
||||
this.teleportQueue = teleportQueue;
|
||||
@ -154,26 +160,69 @@ public class MVPlayerListener implements InjectableListener {
|
||||
*/
|
||||
@EventHandler
|
||||
public void playerJoin(PlayerJoinEvent event) {
|
||||
Player p = event.getPlayer();
|
||||
if (!p.hasPlayedBefore()) {
|
||||
Player player = event.getPlayer();
|
||||
if (!player.hasPlayedBefore()) {
|
||||
Logging.finer("Player joined for the FIRST time!");
|
||||
if (config.getFirstSpawnOverride()) {
|
||||
Logging.fine("Moving NEW player to(firstspawnoverride): "
|
||||
+ getWorldManager().getFirstSpawnWorld().getSpawnLocation());
|
||||
this.sendPlayerToDefaultWorld(p);
|
||||
this.sendPlayerToDefaultWorld(player);
|
||||
}
|
||||
return;
|
||||
|
||||
} else {
|
||||
Logging.finer("Player joined AGAIN!");
|
||||
// Ensure the player still has permission to access the world they were in
|
||||
if (config.getEnforceAccess() // check this only if we're enforcing access!
|
||||
&& !permissionsChecker.hasWorldAccessPermission(p, getWorldManager().getFirstSpawnWorld())) {
|
||||
p.sendMessage("[MV] - Sorry you can't be in this world anymore!");
|
||||
this.sendPlayerToDefaultWorld(p);
|
||||
&& !permissionsChecker.hasWorldAccessPermission(player, getWorldManager().getFirstSpawnWorld())) {
|
||||
player.sendMessage("[MV] - Sorry you can't be in this world anymore!");
|
||||
this.sendPlayerToDefaultWorld(player);
|
||||
}
|
||||
|
||||
handleJoinDestination(player);
|
||||
}
|
||||
|
||||
// Handle the Players GameMode setting for the new world.
|
||||
this.handleGameModeAndFlight(event.getPlayer(), event.getPlayer().getWorld());
|
||||
playerWorld.put(p.getName(), p.getWorld().getName());
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user