mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2025-01-10 18:28:28 +01:00
Split PlayerWorldAction to PlayerWorldTeleporter and EnforcementHandler
This commit is contained in:
parent
a45849799d
commit
f9bd7f136d
@ -47,7 +47,8 @@ import org.mvplugins.multiverse.core.worldnew.LoadedMultiverseWorld;
|
|||||||
import org.mvplugins.multiverse.core.worldnew.WorldManager;
|
import org.mvplugins.multiverse.core.worldnew.WorldManager;
|
||||||
import org.mvplugins.multiverse.core.worldnew.entrycheck.EntryFeeResult;
|
import org.mvplugins.multiverse.core.worldnew.entrycheck.EntryFeeResult;
|
||||||
import org.mvplugins.multiverse.core.worldnew.entrycheck.WorldEntryCheckerProvider;
|
import org.mvplugins.multiverse.core.worldnew.entrycheck.WorldEntryCheckerProvider;
|
||||||
import org.mvplugins.multiverse.core.worldnew.helpers.PlayerWorldActions;
|
import org.mvplugins.multiverse.core.worldnew.helpers.EnforcementHandler;
|
||||||
|
import org.mvplugins.multiverse.core.worldnew.helpers.PlayerWorldTeleporter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Multiverse's Listener for players.
|
* Multiverse's Listener for players.
|
||||||
@ -63,9 +64,8 @@ public class MVPlayerListener implements InjectableListener {
|
|||||||
private final MVEconomist economist;
|
private final MVEconomist economist;
|
||||||
private final WorldEntryCheckerProvider worldEntryCheckerProvider;
|
private final WorldEntryCheckerProvider worldEntryCheckerProvider;
|
||||||
private final Provider<MVCommandManager> commandManagerProvider;
|
private final Provider<MVCommandManager> commandManagerProvider;
|
||||||
private final CorePermissionsChecker permissionsChecker;
|
|
||||||
private final DestinationsProvider destinationsProvider;
|
private final DestinationsProvider destinationsProvider;
|
||||||
private final PlayerWorldActions playerWorldActions;
|
private final EnforcementHandler enforcementHandler;
|
||||||
|
|
||||||
private final Map<String, String> playerWorld = new ConcurrentHashMap<String, String>();
|
private final Map<String, String> playerWorld = new ConcurrentHashMap<String, String>();
|
||||||
|
|
||||||
@ -80,9 +80,8 @@ public class MVPlayerListener implements InjectableListener {
|
|||||||
MVEconomist economist,
|
MVEconomist economist,
|
||||||
WorldEntryCheckerProvider worldEntryCheckerProvider,
|
WorldEntryCheckerProvider worldEntryCheckerProvider,
|
||||||
Provider<MVCommandManager> commandManagerProvider,
|
Provider<MVCommandManager> commandManagerProvider,
|
||||||
CorePermissionsChecker permissionsChecker,
|
|
||||||
DestinationsProvider destinationsProvider,
|
DestinationsProvider destinationsProvider,
|
||||||
PlayerWorldActions playerWorldActions) {
|
EnforcementHandler enforcementHandler) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.worldManagerProvider = worldManagerProvider;
|
this.worldManagerProvider = worldManagerProvider;
|
||||||
@ -92,9 +91,8 @@ public class MVPlayerListener implements InjectableListener {
|
|||||||
this.economist = economist;
|
this.economist = economist;
|
||||||
this.worldEntryCheckerProvider = worldEntryCheckerProvider;
|
this.worldEntryCheckerProvider = worldEntryCheckerProvider;
|
||||||
this.commandManagerProvider = commandManagerProvider;
|
this.commandManagerProvider = commandManagerProvider;
|
||||||
this.permissionsChecker = permissionsChecker;
|
|
||||||
this.destinationsProvider = destinationsProvider;
|
this.destinationsProvider = destinationsProvider;
|
||||||
this.playerWorldActions = playerWorldActions;
|
this.enforcementHandler = enforcementHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
private WorldManager getWorldManager() {
|
private WorldManager getWorldManager() {
|
||||||
@ -374,8 +372,8 @@ public class MVPlayerListener implements InjectableListener {
|
|||||||
if (!player.isOnline() || !player.getWorld().equals(world)) {
|
if (!player.isOnline() || !player.getWorld().equals(world)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
playerWorldActions.handleFlightEnforcement(player);
|
enforcementHandler.handleFlightEnforcement(player);
|
||||||
playerWorldActions.handleGameModeEnforcement(player);
|
enforcementHandler.handleGameModeEnforcement(player);
|
||||||
}, 1L);
|
}, 1L);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ import org.mvplugins.multiverse.core.worldnew.generators.GeneratorProvider;
|
|||||||
import org.mvplugins.multiverse.core.worldnew.helpers.DataStore.GameRulesStore;
|
import org.mvplugins.multiverse.core.worldnew.helpers.DataStore.GameRulesStore;
|
||||||
import org.mvplugins.multiverse.core.worldnew.helpers.DataTransfer;
|
import org.mvplugins.multiverse.core.worldnew.helpers.DataTransfer;
|
||||||
import org.mvplugins.multiverse.core.worldnew.helpers.FilesManipulator;
|
import org.mvplugins.multiverse.core.worldnew.helpers.FilesManipulator;
|
||||||
import org.mvplugins.multiverse.core.worldnew.helpers.PlayerWorldActions;
|
import org.mvplugins.multiverse.core.worldnew.helpers.PlayerWorldTeleporter;
|
||||||
import org.mvplugins.multiverse.core.worldnew.options.CloneWorldOptions;
|
import org.mvplugins.multiverse.core.worldnew.options.CloneWorldOptions;
|
||||||
import org.mvplugins.multiverse.core.worldnew.options.CreateWorldOptions;
|
import org.mvplugins.multiverse.core.worldnew.options.CreateWorldOptions;
|
||||||
import org.mvplugins.multiverse.core.worldnew.options.ImportWorldOptions;
|
import org.mvplugins.multiverse.core.worldnew.options.ImportWorldOptions;
|
||||||
@ -72,7 +72,7 @@ public class WorldManager {
|
|||||||
private final WorldsConfigManager worldsConfigManager;
|
private final WorldsConfigManager worldsConfigManager;
|
||||||
private final WorldNameChecker worldNameChecker;
|
private final WorldNameChecker worldNameChecker;
|
||||||
private final GeneratorProvider generatorProvider;
|
private final GeneratorProvider generatorProvider;
|
||||||
private final PlayerWorldActions playerWorldActions;
|
private final PlayerWorldTeleporter playerWorldActions;
|
||||||
private final FilesManipulator filesManipulator;
|
private final FilesManipulator filesManipulator;
|
||||||
private final BlockSafety blockSafety;
|
private final BlockSafety blockSafety;
|
||||||
private final SafeTTeleporter safetyTeleporter;
|
private final SafeTTeleporter safetyTeleporter;
|
||||||
@ -83,7 +83,7 @@ public class WorldManager {
|
|||||||
@NotNull WorldsConfigManager worldsConfigManager,
|
@NotNull WorldsConfigManager worldsConfigManager,
|
||||||
@NotNull WorldNameChecker worldNameChecker,
|
@NotNull WorldNameChecker worldNameChecker,
|
||||||
@NotNull GeneratorProvider generatorProvider,
|
@NotNull GeneratorProvider generatorProvider,
|
||||||
@NotNull PlayerWorldActions playerWorldActions,
|
@NotNull PlayerWorldTeleporter playerWorldActions,
|
||||||
@NotNull FilesManipulator filesManipulator,
|
@NotNull FilesManipulator filesManipulator,
|
||||||
@NotNull BlockSafety blockSafety,
|
@NotNull BlockSafety blockSafety,
|
||||||
@NotNull SafeTTeleporter safetyTeleporter,
|
@NotNull SafeTTeleporter safetyTeleporter,
|
||||||
|
@ -24,26 +24,23 @@ import org.mvplugins.multiverse.core.configuration.migration.NullStringMigratorA
|
|||||||
import org.mvplugins.multiverse.core.configuration.migration.VersionMigrator;
|
import org.mvplugins.multiverse.core.configuration.migration.VersionMigrator;
|
||||||
import org.mvplugins.multiverse.core.world.configuration.AllowedPortalType;
|
import org.mvplugins.multiverse.core.world.configuration.AllowedPortalType;
|
||||||
import org.mvplugins.multiverse.core.worldnew.LoadedMultiverseWorld;
|
import org.mvplugins.multiverse.core.worldnew.LoadedMultiverseWorld;
|
||||||
import org.mvplugins.multiverse.core.worldnew.helpers.PlayerWorldActions;
|
import org.mvplugins.multiverse.core.worldnew.helpers.EnforcementHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a world configuration.
|
* Represents a world configuration.
|
||||||
*/
|
*/
|
||||||
public final class WorldConfig {
|
public final class WorldConfig {
|
||||||
|
|
||||||
private final PlayerWorldActions playerWorldActions;
|
|
||||||
private final String worldName;
|
private final String worldName;
|
||||||
private final WorldConfigNodes configNodes;
|
private final WorldConfigNodes configNodes;
|
||||||
private final ConfigurationSectionHandle configHandle;
|
private final ConfigurationSectionHandle configHandle;
|
||||||
|
|
||||||
WorldConfig(
|
WorldConfig(
|
||||||
@NotNull PlayerWorldActions playerWorldActions,
|
|
||||||
@NotNull String worldName,
|
@NotNull String worldName,
|
||||||
@NotNull ConfigurationSection configSection) {
|
@NotNull ConfigurationSection configSection,
|
||||||
this.playerWorldActions = playerWorldActions;
|
@NotNull EnforcementHandler enforcementHandler) {
|
||||||
|
|
||||||
this.worldName = worldName;
|
this.worldName = worldName;
|
||||||
this.configNodes = new WorldConfigNodes(playerWorldActions);
|
this.configNodes = new WorldConfigNodes(enforcementHandler);
|
||||||
this.configHandle = ConfigurationSectionHandle.builder(configSection)
|
this.configHandle = ConfigurationSectionHandle.builder(configSection)
|
||||||
.logger(Logging.getLogger())
|
.logger(Logging.getLogger())
|
||||||
.nodes(configNodes.getNodes())
|
.nodes(configNodes.getNodes())
|
||||||
|
@ -15,7 +15,7 @@ import org.mvplugins.multiverse.core.configuration.node.Node;
|
|||||||
import org.mvplugins.multiverse.core.configuration.node.NodeGroup;
|
import org.mvplugins.multiverse.core.configuration.node.NodeGroup;
|
||||||
import org.mvplugins.multiverse.core.world.configuration.AllowedPortalType;
|
import org.mvplugins.multiverse.core.world.configuration.AllowedPortalType;
|
||||||
import org.mvplugins.multiverse.core.worldnew.LoadedMultiverseWorld;
|
import org.mvplugins.multiverse.core.worldnew.LoadedMultiverseWorld;
|
||||||
import org.mvplugins.multiverse.core.worldnew.helpers.PlayerWorldActions;
|
import org.mvplugins.multiverse.core.worldnew.helpers.EnforcementHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents nodes in a world configuration.
|
* Represents nodes in a world configuration.
|
||||||
@ -24,11 +24,11 @@ public class WorldConfigNodes {
|
|||||||
private static final double CONFIG_VERSION = 1.0;
|
private static final double CONFIG_VERSION = 1.0;
|
||||||
|
|
||||||
private final NodeGroup nodes = new NodeGroup();
|
private final NodeGroup nodes = new NodeGroup();
|
||||||
private PlayerWorldActions playerWorldActions;
|
private EnforcementHandler enforcementHandler;
|
||||||
private LoadedMultiverseWorld world = null;
|
private LoadedMultiverseWorld world = null;
|
||||||
|
|
||||||
WorldConfigNodes(@NotNull PlayerWorldActions playerWorldActions) {
|
WorldConfigNodes(@NotNull EnforcementHandler enforcementHandler) {
|
||||||
this.playerWorldActions = playerWorldActions;
|
this.enforcementHandler = enforcementHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
LoadedMultiverseWorld getWorld() {
|
LoadedMultiverseWorld getWorld() {
|
||||||
@ -65,7 +65,7 @@ public class WorldConfigNodes {
|
|||||||
.defaultValue(false)
|
.defaultValue(false)
|
||||||
.onSetValue((oldValue, newValue) -> {
|
.onSetValue((oldValue, newValue) -> {
|
||||||
if (world == null) return;
|
if (world == null) return;
|
||||||
playerWorldActions.handleAllFlightEnforcement(world);
|
enforcementHandler.handleAllFlightEnforcement(world);
|
||||||
})
|
})
|
||||||
.build());
|
.build());
|
||||||
|
|
||||||
@ -123,7 +123,7 @@ public class WorldConfigNodes {
|
|||||||
.defaultValue(GameMode.SURVIVAL)
|
.defaultValue(GameMode.SURVIVAL)
|
||||||
.onSetValue((oldValue, newValue) -> {
|
.onSetValue((oldValue, newValue) -> {
|
||||||
if (world == null) return;
|
if (world == null) return;
|
||||||
playerWorldActions.handleAllGameModeEnforcement(world);
|
enforcementHandler.handleAllGameModeEnforcement(world);
|
||||||
})
|
})
|
||||||
.build());
|
.build());
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jvnet.hk2.annotations.Service;
|
import org.jvnet.hk2.annotations.Service;
|
||||||
|
|
||||||
import org.mvplugins.multiverse.core.MultiverseCore;
|
import org.mvplugins.multiverse.core.MultiverseCore;
|
||||||
import org.mvplugins.multiverse.core.worldnew.helpers.PlayerWorldActions;
|
import org.mvplugins.multiverse.core.worldnew.helpers.EnforcementHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manages the worlds.yml file.
|
* Manages the worlds.yml file.
|
||||||
@ -35,14 +35,14 @@ public final class WorldsConfigManager {
|
|||||||
private final File worldConfigFile;
|
private final File worldConfigFile;
|
||||||
private YamlConfiguration worldsConfig;
|
private YamlConfiguration worldsConfig;
|
||||||
|
|
||||||
private final PlayerWorldActions playerWorldActions;
|
private final EnforcementHandler enforcementHandler;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
WorldsConfigManager(@NotNull MultiverseCore core, @NotNull PlayerWorldActions playerWorldActions) {
|
WorldsConfigManager(@NotNull MultiverseCore core, @NotNull EnforcementHandler enforcementHandler) {
|
||||||
worldConfigMap = new HashMap<>();
|
worldConfigMap = new HashMap<>();
|
||||||
worldConfigFile = core.getDataFolder().toPath().resolve(CONFIG_FILENAME).toFile();
|
worldConfigFile = core.getDataFolder().toPath().resolve(CONFIG_FILENAME).toFile();
|
||||||
|
|
||||||
this.playerWorldActions = playerWorldActions;
|
this.enforcementHandler = enforcementHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -126,9 +126,9 @@ public final class WorldsConfigManager {
|
|||||||
.peek(config -> config.load(getWorldConfigSection(worldName)))
|
.peek(config -> config.load(getWorldConfigSection(worldName)))
|
||||||
.onEmpty(() -> {
|
.onEmpty(() -> {
|
||||||
WorldConfig newWorldConfig = new WorldConfig(
|
WorldConfig newWorldConfig = new WorldConfig(
|
||||||
playerWorldActions,
|
|
||||||
worldName,
|
worldName,
|
||||||
getWorldConfigSection(worldName));
|
getWorldConfigSection(worldName),
|
||||||
|
enforcementHandler);
|
||||||
worldConfigMap.put(worldName, newWorldConfig);
|
worldConfigMap.put(worldName, newWorldConfig);
|
||||||
newWorldsAdded.add(newWorldConfig);
|
newWorldsAdded.add(newWorldConfig);
|
||||||
});
|
});
|
||||||
@ -183,7 +183,7 @@ public final class WorldsConfigManager {
|
|||||||
if (worldConfigMap.containsKey(worldName)) {
|
if (worldConfigMap.containsKey(worldName)) {
|
||||||
throw new IllegalArgumentException("WorldConfig for world " + worldName + " already exists.");
|
throw new IllegalArgumentException("WorldConfig for world " + worldName + " already exists.");
|
||||||
}
|
}
|
||||||
WorldConfig worldConfig = new WorldConfig(playerWorldActions, worldName, getWorldConfigSection(worldName));
|
WorldConfig worldConfig = new WorldConfig(worldName, getWorldConfigSection(worldName), enforcementHandler);
|
||||||
worldConfigMap.put(worldName, worldConfig);
|
worldConfigMap.put(worldName, worldConfig);
|
||||||
return worldConfig;
|
return worldConfig;
|
||||||
}
|
}
|
||||||
|
@ -1,104 +1,29 @@
|
|||||||
package org.mvplugins.multiverse.core.worldnew.helpers;
|
package org.mvplugins.multiverse.core.worldnew.helpers;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.dumptruckman.minecraft.util.Logging;
|
import com.dumptruckman.minecraft.util.Logging;
|
||||||
import jakarta.inject.Inject;
|
import jakarta.inject.Inject;
|
||||||
import jakarta.inject.Provider;
|
import jakarta.inject.Provider;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jvnet.hk2.annotations.Service;
|
import org.jvnet.hk2.annotations.Service;
|
||||||
|
|
||||||
import org.mvplugins.multiverse.core.api.SafeTTeleporter;
|
|
||||||
import org.mvplugins.multiverse.core.permissions.CorePermissionsChecker;
|
import org.mvplugins.multiverse.core.permissions.CorePermissionsChecker;
|
||||||
import org.mvplugins.multiverse.core.worldnew.LoadedMultiverseWorld;
|
import org.mvplugins.multiverse.core.worldnew.LoadedMultiverseWorld;
|
||||||
import org.mvplugins.multiverse.core.worldnew.WorldManager;
|
import org.mvplugins.multiverse.core.worldnew.WorldManager;
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles all player actions that need to be done when a change in world related activity occurs.
|
|
||||||
*/
|
|
||||||
@Service
|
@Service
|
||||||
public class PlayerWorldActions {
|
public class EnforcementHandler {
|
||||||
|
|
||||||
private final CorePermissionsChecker permissionsChecker;
|
private final CorePermissionsChecker permissionsChecker;
|
||||||
private final SafeTTeleporter safetyTeleporter;
|
|
||||||
private final Provider<WorldManager> worldManagerProvider;
|
private final Provider<WorldManager> worldManagerProvider;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
PlayerWorldActions(
|
EnforcementHandler(CorePermissionsChecker permissionsChecker, Provider<WorldManager> worldManagerProvider) {
|
||||||
@NotNull CorePermissionsChecker permissionsChecker,
|
|
||||||
@NotNull SafeTTeleporter safetyTeleporter,
|
|
||||||
@NotNull Provider<WorldManager> worldManagerProvider) {
|
|
||||||
this.permissionsChecker = permissionsChecker;
|
this.permissionsChecker = permissionsChecker;
|
||||||
this.safetyTeleporter = safetyTeleporter;
|
|
||||||
this.worldManagerProvider = worldManagerProvider;
|
this.worldManagerProvider = worldManagerProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes all players from the given world.
|
|
||||||
*
|
|
||||||
* @param world The world to remove all players from.
|
|
||||||
*/
|
|
||||||
public void removeFromWorld(@NotNull LoadedMultiverseWorld world) {
|
|
||||||
// TODO: Better handling of fallback world
|
|
||||||
World toWorld = Bukkit.getWorlds().get(0);
|
|
||||||
transferFromWorldTo(world, toWorld);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Transfers all players from the given world to another world's spawn location.
|
|
||||||
*
|
|
||||||
* @param from The world to transfer players from.
|
|
||||||
* @param to The location to transfer players to.
|
|
||||||
*/
|
|
||||||
public void transferFromWorldTo(@NotNull LoadedMultiverseWorld from, @NotNull LoadedMultiverseWorld to) {
|
|
||||||
transferAllFromWorldToLocation(from, to.getSpawnLocation());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Transfers all players from the given world to another world's spawn location.
|
|
||||||
*
|
|
||||||
* @param from The world to transfer players from.
|
|
||||||
* @param to The world to transfer players to.
|
|
||||||
*/
|
|
||||||
public void transferFromWorldTo(@NotNull LoadedMultiverseWorld from, @NotNull World to) {
|
|
||||||
transferAllFromWorldToLocation(from, to.getSpawnLocation());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Transfers all players from the given world to the given location.
|
|
||||||
*
|
|
||||||
* @param world The world to transfer players from.
|
|
||||||
* @param location The location to transfer players to.
|
|
||||||
*/
|
|
||||||
public void transferAllFromWorldToLocation(@NotNull LoadedMultiverseWorld world, @NotNull Location location) {
|
|
||||||
world.getPlayers().peek(players -> players.forEach(player -> {
|
|
||||||
if (player.isOnline()) {
|
|
||||||
Logging.fine("Teleporting player '%s' to world spawn: %s", player.getName(), location);
|
|
||||||
safetyTeleporter.safelyTeleport(null, player, location, true);
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Teleports all players to the given world's spawn location.
|
|
||||||
*
|
|
||||||
* @param players The players to teleport.
|
|
||||||
* @param world The world to teleport players to.
|
|
||||||
*/
|
|
||||||
public void teleportPlayersToWorld(@NotNull List<Player> players, @NotNull LoadedMultiverseWorld world) {
|
|
||||||
players.forEach(player -> {
|
|
||||||
Location spawnLocation = world.getSpawnLocation();
|
|
||||||
if (player.isOnline()) {
|
|
||||||
safetyTeleporter.safelyTeleport(null, player, spawnLocation, true);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Teleports all players to the given location.
|
* Teleports all players to the given location.
|
||||||
*
|
*
|
@ -0,0 +1,89 @@
|
|||||||
|
package org.mvplugins.multiverse.core.worldnew.helpers;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.dumptruckman.minecraft.util.Logging;
|
||||||
|
import jakarta.inject.Inject;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jvnet.hk2.annotations.Service;
|
||||||
|
|
||||||
|
import org.mvplugins.multiverse.core.api.SafeTTeleporter;
|
||||||
|
import org.mvplugins.multiverse.core.worldnew.LoadedMultiverseWorld;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles all player actions that need to be done when a change in world related activity occurs.
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class PlayerWorldTeleporter {
|
||||||
|
private final SafeTTeleporter safetyTeleporter;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
PlayerWorldTeleporter(@NotNull SafeTTeleporter safetyTeleporter) {
|
||||||
|
this.safetyTeleporter = safetyTeleporter;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes all players from the given world.
|
||||||
|
*
|
||||||
|
* @param world The world to remove all players from.
|
||||||
|
*/
|
||||||
|
public void removeFromWorld(@NotNull LoadedMultiverseWorld world) {
|
||||||
|
// TODO: Better handling of fallback world
|
||||||
|
World toWorld = Bukkit.getWorlds().get(0);
|
||||||
|
transferFromWorldTo(world, toWorld);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transfers all players from the given world to another world's spawn location.
|
||||||
|
*
|
||||||
|
* @param from The world to transfer players from.
|
||||||
|
* @param to The location to transfer players to.
|
||||||
|
*/
|
||||||
|
public void transferFromWorldTo(@NotNull LoadedMultiverseWorld from, @NotNull LoadedMultiverseWorld to) {
|
||||||
|
transferAllFromWorldToLocation(from, to.getSpawnLocation());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transfers all players from the given world to another world's spawn location.
|
||||||
|
*
|
||||||
|
* @param from The world to transfer players from.
|
||||||
|
* @param to The world to transfer players to.
|
||||||
|
*/
|
||||||
|
public void transferFromWorldTo(@NotNull LoadedMultiverseWorld from, @NotNull World to) {
|
||||||
|
transferAllFromWorldToLocation(from, to.getSpawnLocation());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transfers all players from the given world to the given location.
|
||||||
|
*
|
||||||
|
* @param world The world to transfer players from.
|
||||||
|
* @param location The location to transfer players to.
|
||||||
|
*/
|
||||||
|
public void transferAllFromWorldToLocation(@NotNull LoadedMultiverseWorld world, @NotNull Location location) {
|
||||||
|
world.getPlayers().peek(players -> players.forEach(player -> {
|
||||||
|
if (player.isOnline()) {
|
||||||
|
Logging.fine("Teleporting player '%s' to world spawn: %s", player.getName(), location);
|
||||||
|
safetyTeleporter.safelyTeleport(null, player, location, true);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Teleports all players to the given world's spawn location.
|
||||||
|
*
|
||||||
|
* @param players The players to teleport.
|
||||||
|
* @param world The world to teleport players to.
|
||||||
|
*/
|
||||||
|
public void teleportPlayersToWorld(@NotNull List<Player> players, @NotNull LoadedMultiverseWorld world) {
|
||||||
|
players.forEach(player -> {
|
||||||
|
Location spawnLocation = world.getSpawnLocation();
|
||||||
|
if (player.isOnline()) {
|
||||||
|
safetyTeleporter.safelyTeleport(null, player, spawnLocation, true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user