mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 06:28:49 +00:00
Spawn: Simplify getting method, refactoring, add way of getting via API
This commit is contained in:
1 parent
f94f9e82db
commit
4db869abf1
6 files changed
+36
-20
No files matched your search
@@ -14,10 +14,7 @@ import net.william278.huskhomes.hook.PluginHook;
|
||||
import net.william278.huskhomes.messenger.NetworkMessenger;
|
||||
import net.william278.huskhomes.migrator.Migrator;
|
||||
import net.william278.huskhomes.player.OnlineUser;
|
||||
import net.william278.huskhomes.position.Location;
|
||||
import net.william278.huskhomes.position.SavedPositionManager;
|
||||
import net.william278.huskhomes.position.Server;
|
||||
import net.william278.huskhomes.position.World;
|
||||
import net.william278.huskhomes.position.*;
|
||||
import net.william278.huskhomes.random.RandomTeleportEngine;
|
||||
import net.william278.huskhomes.request.RequestManager;
|
||||
import net.william278.huskhomes.teleport.TeleportManager;
|
||||
@@ -165,11 +162,23 @@ public interface HuskHomes {
|
||||
List<Migrator> getMigrators();
|
||||
|
||||
/**
|
||||
* The {@link CachedSpawn} location of this server
|
||||
* The local {@link CachedSpawn} location of this server, as cached to disk
|
||||
*
|
||||
* @return the {@link CachedSpawn} location data
|
||||
* @see #getSpawn() for the canonical spawn point to use
|
||||
*/
|
||||
Optional<CachedSpawn> getServerSpawn();
|
||||
Optional<CachedSpawn> getLocalCachedSpawn();
|
||||
|
||||
/**
|
||||
* The canonical spawn {@link Position} of this server, if it has been set
|
||||
*
|
||||
* @return the {@link Position} of the spawn, or an empty {@link Optional} if it has not been set
|
||||
*/
|
||||
default Optional<? extends Position> getSpawn() {
|
||||
return getSettings().crossServer && getSettings().globalSpawn
|
||||
? getDatabase().getWarp(getSettings().globalSpawnName).join()
|
||||
: getLocalCachedSpawn().flatMap(spawn -> spawn.getPosition(getPluginServer()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a future returning the latest plugin {@link Version} if the plugin is out-of-date
|
||||
|
||||
@@ -196,6 +196,16 @@ public abstract class BaseHuskHomesAPI {
|
||||
return plugin.getDatabase().getWarp(warpUuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the canonical {@link Position} of the spawn point. Note that if cross-server and global spawn
|
||||
* are enabled in the config, this may not return a position on this server.
|
||||
*
|
||||
* @return A {@link CompletableFuture} that will complete with the {@link Position} of the spawn point
|
||||
*/
|
||||
public final CompletableFuture<Optional<? extends Position>> getSpawn() {
|
||||
return CompletableFuture.supplyAsync(plugin::getSpawn);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the {@link PositionMeta} of a {@link Home}
|
||||
*
|
||||
|
||||
@@ -21,16 +21,13 @@ public class SpawnCommand extends CommandBase {
|
||||
return;
|
||||
}
|
||||
|
||||
CompletableFuture.supplyAsync(() -> plugin.getSettings().crossServer && plugin.getSettings().globalSpawn
|
||||
? plugin.getDatabase().getWarp(plugin.getSettings().globalSpawnName).join()
|
||||
: plugin.getServerSpawn().flatMap(spawn -> spawn.getLocation(plugin.getPluginServer())))
|
||||
.thenAccept(position -> {
|
||||
if (position.isEmpty()) {
|
||||
plugin.getLocales().getLocale("error_spawn_not_set")
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
return;
|
||||
}
|
||||
plugin.getTeleportManager().timedTeleport(onlineUser, position.get());
|
||||
});
|
||||
CompletableFuture.supplyAsync(plugin::getSpawn).thenAccept(position -> {
|
||||
if (position.isEmpty()) {
|
||||
plugin.getLocales().getLocale("error_spawn_not_set")
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
return;
|
||||
}
|
||||
plugin.getTeleportManager().timedTeleport(onlineUser, position.get());
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -33,7 +33,7 @@ public class CachedSpawn {
|
||||
*
|
||||
* @return The {@link Position} of the spawn
|
||||
*/
|
||||
public Optional<Position> getLocation(@NotNull Server server) {
|
||||
public Optional<Position> getPosition(@NotNull Server server) {
|
||||
try {
|
||||
return Optional.of(new Position(x, y, z, yaw, pitch,
|
||||
new World(worldName, UUID.fromString(worldUuid)), server));
|
||||
|
||||
@@ -52,7 +52,7 @@ public class EventListener {
|
||||
if (activeTeleport.type == TeleportType.RESPAWN) {
|
||||
final Optional<Position> bedPosition = onlineUser.getBedSpawnPosition();
|
||||
if (bedPosition.isEmpty()) {
|
||||
plugin.getServerSpawn().flatMap(spawn -> spawn.getLocation(plugin.getPluginServer()))
|
||||
plugin.getLocalCachedSpawn().flatMap(spawn -> spawn.getPosition(plugin.getPluginServer()))
|
||||
.ifPresent(position -> onlineUser.teleport(position, plugin.getSettings().asynchronousTeleports));
|
||||
onlineUser.sendMinecraftMessage("block.minecraft.spawn.not_valid");
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user