Add SetSpawnCommand.java

This commit is contained in:
Len 2024-08-15 17:41:17 +02:00
parent be8b7e20df
commit 29559b83c4
2 changed files with 46 additions and 1 deletions

View File

@ -0,0 +1,45 @@
package com.alttd.essentia.commands.admin;
import com.alttd.essentia.commands.EssentiaCommand;
import com.alttd.essentia.configuration.Config;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.tree.LiteralCommandNode;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import io.papermc.paper.command.brigadier.Commands;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class SetSpawnCommand implements EssentiaCommand {
static String commandName = "setspawn";
@Override
public @NotNull LiteralCommandNode<CommandSourceStack> command() {
final LiteralArgumentBuilder<CommandSourceStack> builder =
Commands.literal(commandName)
.requires(
commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName) &&
commandSourceStack.getSender() instanceof Player
)
.executes((source) -> {
if (source.getSource().getSender() instanceof Player player)
execute(player, player);
return 1;
});
return builder.build();
}
public void execute(CommandSender sender, Player target) {
// Todo - output messages
World world = target.getWorld();
world.setSpawnLocation(target.getLocation());
// TODO -- method in config to update & save
Config.config.set("spawn-world", world.getName());
Config.SPAWN_WORLD = world.getName();
Config.saveConfig();
}
}

View File

@ -66,7 +66,7 @@ public class Config {
saveConfig();
}
static void saveConfig() {
public static void saveConfig() {
try {
config.save(CONFIG_FILE);
} catch (IOException ex) {