From 29559b83c44f0c150c7135ede158032feb337ca9 Mon Sep 17 00:00:00 2001 From: Len <40720638+destro174@users.noreply.github.com> Date: Thu, 15 Aug 2024 17:41:17 +0200 Subject: [PATCH] Add SetSpawnCommand.java --- .../commands/admin/SetSpawnCommand.java | 45 +++++++++++++++++++ .../alttd/essentia/configuration/Config.java | 2 +- 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 plugin/src/main/java/com/alttd/essentia/commands/admin/SetSpawnCommand.java diff --git a/plugin/src/main/java/com/alttd/essentia/commands/admin/SetSpawnCommand.java b/plugin/src/main/java/com/alttd/essentia/commands/admin/SetSpawnCommand.java new file mode 100644 index 0000000..3220c9a --- /dev/null +++ b/plugin/src/main/java/com/alttd/essentia/commands/admin/SetSpawnCommand.java @@ -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 command() { + final LiteralArgumentBuilder 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(); + } + +} diff --git a/plugin/src/main/java/com/alttd/essentia/configuration/Config.java b/plugin/src/main/java/com/alttd/essentia/configuration/Config.java index c270677..3038b6e 100755 --- a/plugin/src/main/java/com/alttd/essentia/configuration/Config.java +++ b/plugin/src/main/java/com/alttd/essentia/configuration/Config.java @@ -66,7 +66,7 @@ public class Config { saveConfig(); } - static void saveConfig() { + public static void saveConfig() { try { config.save(CONFIG_FILE); } catch (IOException ex) {