Move logic of teleporting players out of world from world manager
This commit is contained in:
parent
9ddfa59712
commit
ba93195671
|
@ -1,11 +1,14 @@
|
|||
package org.mvplugins.multiverse.core.commands;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import co.aikar.commands.MessageType;
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
import co.aikar.commands.annotation.CommandCompletion;
|
||||
import co.aikar.commands.annotation.CommandPermission;
|
||||
import co.aikar.commands.annotation.Conditions;
|
||||
import co.aikar.commands.annotation.Description;
|
||||
import co.aikar.commands.annotation.Optional;
|
||||
import co.aikar.commands.annotation.Single;
|
||||
import co.aikar.commands.annotation.Subcommand;
|
||||
import co.aikar.commands.annotation.Syntax;
|
||||
|
@ -17,48 +20,81 @@ import org.jvnet.hk2.annotations.Service;
|
|||
import org.mvplugins.multiverse.core.commandtools.MVCommandIssuer;
|
||||
import org.mvplugins.multiverse.core.commandtools.MVCommandManager;
|
||||
import org.mvplugins.multiverse.core.commandtools.MultiverseCommand;
|
||||
import org.mvplugins.multiverse.core.commandtools.flags.CommandFlag;
|
||||
import org.mvplugins.multiverse.core.commandtools.flags.ParsedCommandFlags;
|
||||
import org.mvplugins.multiverse.core.commandtools.queue.QueuedCommand;
|
||||
import org.mvplugins.multiverse.core.utils.MVCorei18n;
|
||||
import org.mvplugins.multiverse.core.worldnew.LoadedMultiverseWorld;
|
||||
import org.mvplugins.multiverse.core.worldnew.WorldManager;
|
||||
import org.mvplugins.multiverse.core.worldnew.helpers.PlayerWorldTeleporter;
|
||||
|
||||
@Service
|
||||
@CommandAlias("mv")
|
||||
class DeleteCommand extends MultiverseCommand {
|
||||
|
||||
private final WorldManager worldManager;
|
||||
private final PlayerWorldTeleporter playerWorldTeleporter;
|
||||
|
||||
private final CommandFlag REMOVE_PLAYERS_FLAG = flag(CommandFlag.builder("--remove-players")
|
||||
.addAlias("-r")
|
||||
.build());
|
||||
|
||||
@Inject
|
||||
DeleteCommand(@NotNull MVCommandManager commandManager, @NotNull WorldManager worldManager) {
|
||||
DeleteCommand(
|
||||
@NotNull MVCommandManager commandManager,
|
||||
@NotNull WorldManager worldManager,
|
||||
@NotNull PlayerWorldTeleporter playerWorldTeleporter) {
|
||||
super(commandManager);
|
||||
this.worldManager = worldManager;
|
||||
this.playerWorldTeleporter = playerWorldTeleporter;
|
||||
}
|
||||
|
||||
@Subcommand("delete")
|
||||
@CommandPermission("multiverse.core.delete")
|
||||
@CommandCompletion("@mvworlds:scope=both")
|
||||
@CommandCompletion("@mvworlds:scope=loaded @flags:groupName=mvdeletecommand")
|
||||
@Syntax("<world>")
|
||||
@Description("{@@mv-core.delete.description}")
|
||||
void onDeleteCommand(
|
||||
MVCommandIssuer issuer,
|
||||
|
||||
@Single
|
||||
@Conditions("worldname:scope=both")
|
||||
@Conditions("worldname:scope=loaded")
|
||||
@Syntax("<world>")
|
||||
@Description("The world you want to delete.")
|
||||
String worldName) {
|
||||
LoadedMultiverseWorld world,
|
||||
|
||||
@Optional
|
||||
@Syntax("[--remove-players]")
|
||||
@Description("")
|
||||
String[] flags) {
|
||||
ParsedCommandFlags parsedFlags = parseFlags(flags);
|
||||
|
||||
this.commandManager.getCommandQueueManager().addToQueue(new QueuedCommand(
|
||||
issuer.getIssuer(),
|
||||
() -> {
|
||||
issuer.sendInfo(MVCorei18n.DELETE_DELETING, "{world}", worldName);
|
||||
worldManager.deleteWorld(worldName)
|
||||
.onSuccess(deletedWorldName -> {
|
||||
Logging.fine("World delete success: " + deletedWorldName);
|
||||
issuer.sendInfo(MVCorei18n.DELETE_SUCCESS, "{world}", deletedWorldName);
|
||||
}).onFailure(failure -> {
|
||||
Logging.fine("World delete failure: " + failure);
|
||||
issuer.sendError(failure.getFailureMessage());
|
||||
});
|
||||
runDeleteCommand(issuer, world, parsedFlags);
|
||||
}, this.commandManager.formatMessage(
|
||||
issuer, MessageType.INFO, MVCorei18n.DELETE_PROMPT, "{world}", worldName)));
|
||||
issuer, MessageType.INFO, MVCorei18n.DELETE_PROMPT, "{world}", world.getName())));
|
||||
}
|
||||
|
||||
private void runDeleteCommand(MVCommandIssuer issuer, LoadedMultiverseWorld world, ParsedCommandFlags parsedFlags) {
|
||||
issuer.sendInfo(MVCorei18n.DELETE_DELETING, "{world}", world.getName());
|
||||
|
||||
CompletableFuture<Void> future = parsedFlags.hasFlag(REMOVE_PLAYERS_FLAG)
|
||||
? CompletableFuture.allOf(playerWorldTeleporter.removeFromWorld(world))
|
||||
: CompletableFuture.completedFuture(null);
|
||||
|
||||
future.thenRun(() -> doWorldDeleting(issuer, world));
|
||||
}
|
||||
|
||||
private void doWorldDeleting(MVCommandIssuer issuer, LoadedMultiverseWorld world) {
|
||||
worldManager.deleteWorld(world)
|
||||
.onSuccess(deletedWorldName -> {
|
||||
Logging.fine("World delete success: " + deletedWorldName);
|
||||
issuer.sendInfo(MVCorei18n.DELETE_SUCCESS, "{world}", deletedWorldName);
|
||||
}).onFailure(failure -> {
|
||||
Logging.fine("World delete failure: " + failure);
|
||||
issuer.sendError(failure.getFailureMessage());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
package org.mvplugins.multiverse.core.commands;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import co.aikar.commands.MessageType;
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
|
@ -13,6 +15,7 @@ import co.aikar.commands.annotation.Subcommand;
|
|||
import co.aikar.commands.annotation.Syntax;
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import jakarta.inject.Inject;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jvnet.hk2.annotations.Service;
|
||||
|
||||
|
@ -26,6 +29,7 @@ import org.mvplugins.multiverse.core.commandtools.queue.QueuedCommand;
|
|||
import org.mvplugins.multiverse.core.utils.MVCorei18n;
|
||||
import org.mvplugins.multiverse.core.worldnew.LoadedMultiverseWorld;
|
||||
import org.mvplugins.multiverse.core.worldnew.WorldManager;
|
||||
import org.mvplugins.multiverse.core.worldnew.helpers.PlayerWorldTeleporter;
|
||||
import org.mvplugins.multiverse.core.worldnew.options.RegenWorldOptions;
|
||||
|
||||
@Service
|
||||
|
@ -33,6 +37,7 @@ import org.mvplugins.multiverse.core.worldnew.options.RegenWorldOptions;
|
|||
class RegenCommand extends MultiverseCommand {
|
||||
|
||||
private final WorldManager worldManager;
|
||||
private final PlayerWorldTeleporter playerWorldTeleporter;
|
||||
|
||||
private final CommandValueFlag<String> SEED_FLAG = flag(CommandValueFlag.builder("--seed", String.class)
|
||||
.addAlias("-s")
|
||||
|
@ -51,10 +56,18 @@ class RegenCommand extends MultiverseCommand {
|
|||
.addAlias("-wb")
|
||||
.build());
|
||||
|
||||
private final CommandFlag REMOVE_PLAYERS_FLAG = flag(CommandFlag.builder("--remove-players")
|
||||
.addAlias("-r")
|
||||
.build());
|
||||
|
||||
@Inject
|
||||
RegenCommand(@NotNull MVCommandManager commandManager, @NotNull WorldManager worldManager) {
|
||||
RegenCommand(
|
||||
@NotNull MVCommandManager commandManager,
|
||||
@NotNull WorldManager worldManager,
|
||||
@NotNull PlayerWorldTeleporter playerWorldTeleporter) {
|
||||
super(commandManager);
|
||||
this.worldManager = worldManager;
|
||||
this.playerWorldTeleporter = playerWorldTeleporter;
|
||||
}
|
||||
|
||||
@Subcommand("regen")
|
||||
|
@ -77,23 +90,43 @@ class RegenCommand extends MultiverseCommand {
|
|||
|
||||
this.commandManager.getCommandQueueManager().addToQueue(new QueuedCommand(
|
||||
issuer.getIssuer(),
|
||||
() -> {
|
||||
issuer.sendInfo(MVCorei18n.REGEN_REGENERATING, "{world}", world.getName());
|
||||
worldManager.regenWorld(RegenWorldOptions.world(world)
|
||||
.randomSeed(parsedFlags.hasFlag(SEED_FLAG))
|
||||
.seed(parsedFlags.flagValue(SEED_FLAG))
|
||||
.keepWorldConfig(!parsedFlags.hasFlag(RESET_WORLD_CONFIG_FLAG))
|
||||
.keepGameRule(!parsedFlags.hasFlag(RESET_GAMERULES_FLAG))
|
||||
.keepWorldBorder(!parsedFlags.hasFlag(RESET_WORLD_BORDER_FLAG))
|
||||
).onSuccess(newWorld -> {
|
||||
Logging.fine("World regen success: " + newWorld);
|
||||
issuer.sendInfo(MVCorei18n.REGEN_SUCCESS, "{world}", newWorld.getName());
|
||||
}).onFailure(failure -> {
|
||||
Logging.fine("World regen failure: " + failure);
|
||||
issuer.sendError(failure.getFailureMessage());
|
||||
});
|
||||
},
|
||||
() -> runRegenCommand(issuer, world, parsedFlags),
|
||||
this.commandManager.formatMessage(
|
||||
issuer, MessageType.INFO, MVCorei18n.REGEN_PROMPT, "{world}", world.getName())));
|
||||
}
|
||||
|
||||
private void runRegenCommand(MVCommandIssuer issuer, LoadedMultiverseWorld world, ParsedCommandFlags parsedFlags) {
|
||||
issuer.sendInfo(MVCorei18n.REGEN_REGENERATING, "{world}", world.getName());
|
||||
List<Player> worldPlayers = world.getPlayers().getOrElse(Collections.emptyList());
|
||||
|
||||
CompletableFuture<Void> future = parsedFlags.hasFlag(REMOVE_PLAYERS_FLAG)
|
||||
? CompletableFuture.allOf(playerWorldTeleporter.removeFromWorld(world))
|
||||
: CompletableFuture.completedFuture(null);
|
||||
|
||||
future.thenRun(() -> doWorldRegening(issuer, world, parsedFlags, worldPlayers));
|
||||
}
|
||||
|
||||
private void doWorldRegening(
|
||||
MVCommandIssuer issuer,
|
||||
LoadedMultiverseWorld world,
|
||||
ParsedCommandFlags parsedFlags,
|
||||
List<Player> worldPlayers) {
|
||||
RegenWorldOptions regenWorldOptions = RegenWorldOptions.world(world)
|
||||
.randomSeed(parsedFlags.hasFlag(SEED_FLAG))
|
||||
.seed(parsedFlags.flagValue(SEED_FLAG))
|
||||
.keepWorldConfig(!parsedFlags.hasFlag(RESET_WORLD_CONFIG_FLAG))
|
||||
.keepGameRule(!parsedFlags.hasFlag(RESET_GAMERULES_FLAG))
|
||||
.keepWorldBorder(!parsedFlags.hasFlag(RESET_WORLD_BORDER_FLAG));
|
||||
|
||||
worldManager.regenWorld(regenWorldOptions).onSuccess(newWorld -> {
|
||||
Logging.fine("World regen success: " + newWorld);
|
||||
issuer.sendInfo(MVCorei18n.REGEN_SUCCESS, "{world}", newWorld.getName());
|
||||
if (parsedFlags.hasFlag(REMOVE_PLAYERS_FLAG)) {
|
||||
playerWorldTeleporter.teleportPlayersToWorld(worldPlayers, newWorld);
|
||||
}
|
||||
}).onFailure(failure -> {
|
||||
Logging.fine("World regen failure: " + failure);
|
||||
issuer.sendError(failure.getFailureMessage());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
package org.mvplugins.multiverse.core.commands;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
import co.aikar.commands.annotation.CommandCompletion;
|
||||
import co.aikar.commands.annotation.CommandPermission;
|
||||
import co.aikar.commands.annotation.Conditions;
|
||||
import co.aikar.commands.annotation.Description;
|
||||
import co.aikar.commands.annotation.Optional;
|
||||
import co.aikar.commands.annotation.Single;
|
||||
import co.aikar.commands.annotation.Subcommand;
|
||||
import co.aikar.commands.annotation.Syntax;
|
||||
|
@ -16,19 +19,31 @@ import org.jvnet.hk2.annotations.Service;
|
|||
import org.mvplugins.multiverse.core.commandtools.MVCommandIssuer;
|
||||
import org.mvplugins.multiverse.core.commandtools.MVCommandManager;
|
||||
import org.mvplugins.multiverse.core.commandtools.MultiverseCommand;
|
||||
import org.mvplugins.multiverse.core.commandtools.flags.CommandFlag;
|
||||
import org.mvplugins.multiverse.core.commandtools.flags.ParsedCommandFlags;
|
||||
import org.mvplugins.multiverse.core.utils.MVCorei18n;
|
||||
import org.mvplugins.multiverse.core.worldnew.WorldManager;
|
||||
import org.mvplugins.multiverse.core.worldnew.helpers.PlayerWorldTeleporter;
|
||||
|
||||
@Service
|
||||
@CommandAlias("mv")
|
||||
class RemoveCommand extends MultiverseCommand {
|
||||
|
||||
private final WorldManager worldManager;
|
||||
private final PlayerWorldTeleporter playerWorldTeleporter;
|
||||
|
||||
private final CommandFlag REMOVE_PLAYERS_FLAG = flag(CommandFlag.builder("--remove-players")
|
||||
.addAlias("-r")
|
||||
.build());
|
||||
|
||||
@Inject
|
||||
RemoveCommand(@NotNull MVCommandManager commandManager, @NotNull WorldManager worldManager) {
|
||||
RemoveCommand(
|
||||
@NotNull MVCommandManager commandManager,
|
||||
@NotNull WorldManager worldManager,
|
||||
@NotNull PlayerWorldTeleporter playerWorldTeleporter) {
|
||||
super(commandManager);
|
||||
this.worldManager = worldManager;
|
||||
this.playerWorldTeleporter = playerWorldTeleporter;
|
||||
}
|
||||
|
||||
@Subcommand("remove")
|
||||
|
@ -40,10 +55,27 @@ class RemoveCommand extends MultiverseCommand {
|
|||
MVCommandIssuer issuer,
|
||||
|
||||
@Single
|
||||
@Conditions("mvworlds:scope=both")
|
||||
@Conditions("mvworlds:scope=both @flags:groupName=mvremovecommand")
|
||||
@Syntax("<world>")
|
||||
@Description("{@@mv-core.remove.world.description}")
|
||||
String worldName) {
|
||||
String worldName,
|
||||
|
||||
@Optional
|
||||
@Syntax("[--remove-players]")
|
||||
@Description(/* TODO */"")
|
||||
String[] flags) {
|
||||
ParsedCommandFlags parsedFlags = parseFlags(flags);
|
||||
|
||||
CompletableFuture<Void> future = parsedFlags.hasFlag(REMOVE_PLAYERS_FLAG)
|
||||
? worldManager.getLoadedWorld(worldName)
|
||||
.map(world -> CompletableFuture.allOf(playerWorldTeleporter.removeFromWorld(world)))
|
||||
.getOrElse(CompletableFuture.completedFuture(null))
|
||||
: CompletableFuture.completedFuture(null);
|
||||
|
||||
future.thenRun(() -> doWorldRemoving(issuer, worldName));
|
||||
}
|
||||
|
||||
private void doWorldRemoving(MVCommandIssuer issuer, String worldName) {
|
||||
worldManager.removeWorld(worldName)
|
||||
.onSuccess(removedWorldName -> {
|
||||
Logging.fine("World remove success: " + removedWorldName);
|
||||
|
|
|
@ -72,10 +72,10 @@ class TeleportCommand extends MultiverseCommand {
|
|||
issuer.sendInfo(MVCorei18n.TELEPORT_SUCCESS,
|
||||
"{player}", playerName, "{destination}", destination.toString());
|
||||
|
||||
CompletableFuture.allOf(Arrays.stream(players)
|
||||
.map(player -> safetyTeleporter.teleportSafely(issuer.getIssuer(), player, destination))
|
||||
.toArray(CompletableFuture[]::new))
|
||||
.thenRun(() -> Logging.finer("Async teleport completed."));
|
||||
CompletableFuture
|
||||
.allOf(safetyTeleporter.teleportSafely(issuer.getIssuer(), Arrays.stream(players).toList(),
|
||||
destination))
|
||||
.thenAccept(result -> Logging.fine("Async teleport result: %s", result));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package org.mvplugins.multiverse.core.commands;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
import co.aikar.commands.annotation.CommandCompletion;
|
||||
import co.aikar.commands.annotation.CommandPermission;
|
||||
|
@ -20,6 +22,7 @@ import org.mvplugins.multiverse.core.commandtools.flags.ParsedCommandFlags;
|
|||
import org.mvplugins.multiverse.core.utils.MVCorei18n;
|
||||
import org.mvplugins.multiverse.core.worldnew.LoadedMultiverseWorld;
|
||||
import org.mvplugins.multiverse.core.worldnew.WorldManager;
|
||||
import org.mvplugins.multiverse.core.worldnew.helpers.PlayerWorldTeleporter;
|
||||
import org.mvplugins.multiverse.core.worldnew.options.UnloadWorldOptions;
|
||||
|
||||
@Service
|
||||
|
@ -27,6 +30,7 @@ import org.mvplugins.multiverse.core.worldnew.options.UnloadWorldOptions;
|
|||
class UnloadCommand extends MultiverseCommand {
|
||||
|
||||
private final WorldManager worldManager;
|
||||
private final PlayerWorldTeleporter playerWorldTeleporter;
|
||||
|
||||
private final CommandFlag REMOVE_PLAYERS_FLAG = flag(CommandFlag.builder("--remove-players")
|
||||
.addAlias("-r")
|
||||
|
@ -37,9 +41,13 @@ class UnloadCommand extends MultiverseCommand {
|
|||
.build());
|
||||
|
||||
@Inject
|
||||
UnloadCommand(@NotNull MVCommandManager commandManager, @NotNull WorldManager worldManager) {
|
||||
UnloadCommand(
|
||||
@NotNull MVCommandManager commandManager,
|
||||
@NotNull WorldManager worldManager,
|
||||
@NotNull PlayerWorldTeleporter playerWorldTeleporter) {
|
||||
super(commandManager);
|
||||
this.worldManager = worldManager;
|
||||
this.playerWorldTeleporter = playerWorldTeleporter;
|
||||
}
|
||||
|
||||
@Subcommand("unload")
|
||||
|
@ -61,8 +69,16 @@ class UnloadCommand extends MultiverseCommand {
|
|||
ParsedCommandFlags parsedFlags = parseFlags(flags);
|
||||
|
||||
issuer.sendInfo(MVCorei18n.UNLOAD_UNLOADING, "{world}", world.getAlias());
|
||||
|
||||
CompletableFuture<Void> future = parsedFlags.hasFlag(REMOVE_PLAYERS_FLAG)
|
||||
? CompletableFuture.allOf(playerWorldTeleporter.removeFromWorld(world))
|
||||
: CompletableFuture.completedFuture(null);
|
||||
|
||||
future.thenRun(() -> doWorldUnloading(issuer, world, parsedFlags));
|
||||
}
|
||||
|
||||
private void doWorldUnloading(MVCommandIssuer issuer, LoadedMultiverseWorld world, ParsedCommandFlags parsedFlags) {
|
||||
UnloadWorldOptions unloadWorldOptions = UnloadWorldOptions.world(world)
|
||||
.removePlayers(parsedFlags.hasFlag(REMOVE_PLAYERS_FLAG))
|
||||
.saveBukkitWorld(!parsedFlags.hasFlag(NO_SAVE_FLAG));
|
||||
worldManager.unloadWorld(unloadWorldOptions)
|
||||
.onSuccess(loadedWorld -> {
|
||||
|
|
|
@ -19,6 +19,7 @@ import org.mvplugins.multiverse.core.api.BlockSafety;
|
|||
import org.mvplugins.multiverse.core.destination.ParsedDestination;
|
||||
import org.mvplugins.multiverse.core.utils.result.Result;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Service
|
||||
public class AsyncSafetyTeleporter {
|
||||
private final BlockSafety blockSafety;
|
||||
|
@ -38,6 +39,15 @@ public class AsyncSafetyTeleporter {
|
|||
return teleportSafely(null, teleportee, destination);
|
||||
}
|
||||
|
||||
public <T extends Entity> CompletableFuture<Result<TeleportResult.Success, TeleportResult.Failure>>[] teleportSafely(
|
||||
@Nullable CommandSender teleporter,
|
||||
@NotNull List<T> teleportees,
|
||||
@Nullable ParsedDestination<?> destination) {
|
||||
return teleportees.stream()
|
||||
.map(teleportee -> teleportSafely(teleporter, teleportee, destination))
|
||||
.toArray(CompletableFuture[]::new);
|
||||
}
|
||||
|
||||
public CompletableFuture<Result<TeleportResult.Success, TeleportResult.Failure>> teleportSafely(
|
||||
@Nullable CommandSender teleporter,
|
||||
@NotNull Entity teleportee,
|
||||
|
@ -70,12 +80,12 @@ public class AsyncSafetyTeleporter {
|
|||
return teleport(teleporter, teleportee, safeLocation);
|
||||
}
|
||||
|
||||
public <T extends Entity> List<CompletableFuture<Result<TeleportResult.Success, TeleportResult.Failure>>> teleport(
|
||||
public <T extends Entity> CompletableFuture<Result<TeleportResult.Success, TeleportResult.Failure>>[] teleport(
|
||||
@NotNull List<T> teleportees,
|
||||
@Nullable ParsedDestination<?> destination) {
|
||||
return teleportees.stream()
|
||||
.map(teleportee -> teleport(teleportee, destination))
|
||||
.toList();
|
||||
.toArray(CompletableFuture[]::new);
|
||||
}
|
||||
|
||||
public CompletableFuture<Result<TeleportResult.Success, TeleportResult.Failure>> teleport(
|
||||
|
@ -94,12 +104,12 @@ public class AsyncSafetyTeleporter {
|
|||
return teleport(teleporter, teleportee, destination.getLocation(teleportee));
|
||||
}
|
||||
|
||||
public <T extends Entity> List<CompletableFuture<Result<TeleportResult.Success, TeleportResult.Failure>>> teleport(
|
||||
public <T extends Entity> CompletableFuture<Result<TeleportResult.Success, TeleportResult.Failure>>[] teleport(
|
||||
@NotNull List<T> teleportees,
|
||||
@Nullable Location location) {
|
||||
return teleportees.stream()
|
||||
.map(teleportee -> teleport(teleportee, location))
|
||||
.toList();
|
||||
.toArray(CompletableFuture[]::new);
|
||||
}
|
||||
|
||||
public CompletableFuture<Result<TeleportResult.Success, TeleportResult.Failure>> teleport(
|
||||
|
|
|
@ -371,10 +371,6 @@ public class WorldManager {
|
|||
return worldActionResult(UnloadFailureReason.WORLD_ALREADY_UNLOADING, world.getName());
|
||||
}
|
||||
|
||||
if (options.removePlayers()) {
|
||||
playerWorldActions.removeFromWorld(world);
|
||||
}
|
||||
|
||||
return unloadBukkitWorld(world.getBukkitWorld().getOrNull(), options.saveBukkitWorld()).fold(
|
||||
exception -> worldActionResult(UnloadFailureReason.BUKKIT_UNLOAD_FAILED,
|
||||
world.getName(), exception),
|
||||
|
@ -426,7 +422,7 @@ public class WorldManager {
|
|||
*/
|
||||
public Attempt<String, RemoveFailureReason> removeWorld(@NotNull LoadedMultiverseWorld loadedWorld) {
|
||||
// TODO: Config option on removePlayers
|
||||
return unloadWorld(UnloadWorldOptions.world(loadedWorld).removePlayers(true))
|
||||
return unloadWorld(UnloadWorldOptions.world(loadedWorld))
|
||||
.transform(RemoveFailureReason.UNLOAD_FAILED)
|
||||
.mapAttempt(this::removeWorldFromConfig);
|
||||
}
|
||||
|
@ -588,7 +584,6 @@ public class WorldManager {
|
|||
*/
|
||||
public Attempt<LoadedMultiverseWorld, RegenFailureReason> regenWorld(@NotNull RegenWorldOptions options) {
|
||||
LoadedMultiverseWorld world = options.world();
|
||||
List<Player> playersInWorld = world.getPlayers().getOrElse(Collections.emptyList());
|
||||
DataTransfer<LoadedMultiverseWorld> dataTransfer = transferData(options, world);
|
||||
boolean shouldKeepSpawnLocation = options.keepWorldConfig() && options.seed() == world.getSeed();
|
||||
Location spawnLocation = world.getSpawnLocation();
|
||||
|
@ -611,7 +606,6 @@ public class WorldManager {
|
|||
// different seed.
|
||||
newWorld.setSpawnLocation(spawnLocation);
|
||||
}
|
||||
playerWorldActions.teleportPlayersToWorld(playersInWorld, newWorld);
|
||||
saveWorldsConfig();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ public class PlayerWorldTeleporter {
|
|||
*
|
||||
* @param world The world to remove all players from.
|
||||
*/
|
||||
public List<CompletableFuture<Result<TeleportResult.Success, TeleportResult.Failure>>>
|
||||
public CompletableFuture<Result<TeleportResult.Success, TeleportResult.Failure>>[]
|
||||
removeFromWorld(@NotNull LoadedMultiverseWorld world) {
|
||||
// TODO: Better handling of fallback world
|
||||
World toWorld = Bukkit.getWorlds().get(0);
|
||||
|
@ -47,7 +47,7 @@ public class PlayerWorldTeleporter {
|
|||
* @param from The world to transfer players from.
|
||||
* @param to The location to transfer players to.
|
||||
*/
|
||||
public List<CompletableFuture<Result<TeleportResult.Success, TeleportResult.Failure>>>
|
||||
public CompletableFuture<Result<TeleportResult.Success, TeleportResult.Failure>>[]
|
||||
transferFromWorldTo(@NotNull LoadedMultiverseWorld from, @NotNull LoadedMultiverseWorld to) {
|
||||
return transferAllFromWorldToLocation(from, to.getSpawnLocation());
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ public class PlayerWorldTeleporter {
|
|||
* @param from The world to transfer players from.
|
||||
* @param to The world to transfer players to.
|
||||
*/
|
||||
public List<CompletableFuture<Result<TeleportResult.Success, TeleportResult.Failure>>>
|
||||
public CompletableFuture<Result<TeleportResult.Success, TeleportResult.Failure>>[]
|
||||
transferFromWorldTo(@NotNull LoadedMultiverseWorld from, @NotNull World to) {
|
||||
return transferAllFromWorldToLocation(from, to.getSpawnLocation());
|
||||
}
|
||||
|
@ -70,11 +70,11 @@ public class PlayerWorldTeleporter {
|
|||
* @param location The location to transfer players to.
|
||||
* @return A list of futures that represent the teleportation of each player.
|
||||
*/
|
||||
public List<CompletableFuture<Result<TeleportResult.Success, TeleportResult.Failure>>>
|
||||
public CompletableFuture<Result<TeleportResult.Success, TeleportResult.Failure>>[]
|
||||
transferAllFromWorldToLocation(@NotNull LoadedMultiverseWorld world, @NotNull Location location) {
|
||||
return world.getPlayers()
|
||||
.map(players -> safetyTeleporter.teleport(players, location))
|
||||
.getOrElse(Collections.emptyList());
|
||||
.getOrElse(new CompletableFuture[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -83,7 +83,7 @@ public class PlayerWorldTeleporter {
|
|||
* @param players The players to teleport.
|
||||
* @param world The world to teleport players to.
|
||||
*/
|
||||
public List<CompletableFuture<Result<TeleportResult.Success, TeleportResult.Failure>>>
|
||||
public CompletableFuture<Result<TeleportResult.Success, TeleportResult.Failure>>[]
|
||||
teleportPlayersToWorld(@NotNull List<Player> players, @NotNull LoadedMultiverseWorld world) {
|
||||
Location spawnLocation = world.getSpawnLocation();
|
||||
return safetyTeleporter.teleport(players, spawnLocation);
|
||||
|
|
|
@ -18,7 +18,6 @@ public class UnloadWorldOptions {
|
|||
}
|
||||
|
||||
private final LoadedMultiverseWorld world;
|
||||
private boolean removePlayers = false;
|
||||
private boolean saveBukkitWorld = true;
|
||||
|
||||
UnloadWorldOptions(LoadedMultiverseWorld world) {
|
||||
|
@ -34,26 +33,6 @@ public class UnloadWorldOptions {
|
|||
return world;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether to teleport the players out from the world before unloading.
|
||||
*
|
||||
* @param removePlayersInput Whether to remove players from the world before unloading.
|
||||
* @return This {@link UnloadWorldOptions} instance.
|
||||
*/
|
||||
public UnloadWorldOptions removePlayers(boolean removePlayersInput) {
|
||||
this.removePlayers = removePlayersInput;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether to teleport the players out from the world before unloading.
|
||||
*
|
||||
* @return Whether to remove players from the world before unloading.
|
||||
*/
|
||||
public boolean removePlayers() {
|
||||
return removePlayers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether to save the bukkit world before unloading.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue