mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-01 14:38:53 +00:00
Add /setspawn and /spawn
This commit is contained in:
1 parent
560d701113
commit
8adbc49a61
10 files changed
+198
-17
No files matched your search
@@ -0,0 +1,38 @@
|
||||
package net.william278.huskhomes.command;
|
||||
|
||||
import net.william278.huskhomes.HuskHomes;
|
||||
import net.william278.huskhomes.player.OnlineUser;
|
||||
import net.william278.huskhomes.position.Position;
|
||||
import net.william278.huskhomes.util.Permission;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class SpawnCommand extends CommandBase {
|
||||
|
||||
protected SpawnCommand(@NotNull HuskHomes implementor) {
|
||||
super("spawn", Permission.COMMAND_SPAWN, implementor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExecute(@NotNull OnlineUser onlineUser, @NotNull String[] args) {
|
||||
if (args.length > 0) {
|
||||
plugin.getLocales().getLocale("error_invalid_syntax", "/spawn")
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
CompletableFuture.runAsync(() -> {
|
||||
final Optional<? extends Position> position = (plugin.getSettings().crossServer && plugin.getSettings().globalSpawn
|
||||
? plugin.getDatabase().getWarp(plugin.getSettings().globalSpawnName).join()
|
||||
: plugin.getSpawn().flatMap(spawn -> spawn.getLocation(plugin.getServer(onlineUser).join())));
|
||||
if (position.isEmpty()) {
|
||||
plugin.getLocales().getLocale("error_spawn_not_set").ifPresent(onlineUser::sendMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.getTeleportManager().timedTeleport(onlineUser, position.get()).join();
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user