Add SetSpawnCommand.java
This commit is contained in:
parent
be8b7e20df
commit
29559b83c4
|
|
@ -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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -66,7 +66,7 @@ public class Config {
|
||||||
saveConfig();
|
saveConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void saveConfig() {
|
public static void saveConfig() {
|
||||||
try {
|
try {
|
||||||
config.save(CONFIG_FILE);
|
config.save(CONFIG_FILE);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user