feat: spawn command & fix version (2.1.1)
This commit is contained in:
parent
f9bf400c8e
commit
d0e6f470c8
3 changed files with 84 additions and 1 deletions
|
@ -1,5 +1,5 @@
|
|||
group = "rip.iwakura"
|
||||
version = "0.1.0"
|
||||
version = "2.1.1"
|
||||
|
||||
plugins {
|
||||
java
|
||||
|
|
|
@ -5,6 +5,7 @@ import java.util.ArrayList;
|
|||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
|
@ -21,6 +22,7 @@ import net.kyori.adventure.text.format.TextDecoration;
|
|||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import rip.iwakura.civil.events.ChatHandler;
|
||||
import rip.iwakura.civil.events.TeamChatHandler;
|
||||
import rip.iwakura.civil.commands.Spawn;
|
||||
import rip.iwakura.civil.commands.Team;
|
||||
import rip.iwakura.civil.events.JoinHandler;
|
||||
import rip.iwakura.civil.types.CivilPlayer;
|
||||
|
@ -71,6 +73,13 @@ public class Core extends JavaPlugin {
|
|||
}
|
||||
}
|
||||
|
||||
public Location getSpawn() {
|
||||
return new Location(Bukkit.getWorld(getConfig().getString("spawn.world")),
|
||||
getConfig().getDouble("spawn.x"), getConfig().getDouble("spawn.y"),
|
||||
getConfig().getDouble("spawn.z"), (float) getConfig().getDouble("spawn.yaw"),
|
||||
(float) getConfig().getDouble("spawn.pitch"));
|
||||
};
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
getLogger().info("Hello world! We are booting up...");
|
||||
|
@ -90,9 +99,11 @@ public class Core extends JavaPlugin {
|
|||
discord.connect(getConfig().getString("discord.token"));
|
||||
|
||||
Team teamCommand = new Team(this);
|
||||
Spawn spawnCommand = new Spawn(this);
|
||||
|
||||
this.getLifecycleManager().registerEventHandler(LifecycleEvents.COMMANDS, commands -> {
|
||||
commands.registrar().register(teamCommand.getCommand());
|
||||
commands.registrar().register(spawnCommand.getCommand());
|
||||
});
|
||||
|
||||
getServer().getPluginManager().registerEvents(new JoinHandler(database), this);
|
||||
|
|
72
src/main/java/rip/iwakura/civil/commands/Spawn.java
Normal file
72
src/main/java/rip/iwakura/civil/commands/Spawn.java
Normal file
|
@ -0,0 +1,72 @@
|
|||
package rip.iwakura.civil.commands;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.text.Format;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.checkerframework.common.reflection.qual.GetConstructor;
|
||||
|
||||
import com.mojang.brigadier.Command;
|
||||
import com.mojang.brigadier.arguments.LongArgumentType;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
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 net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.translation.MiniMessageTranslator;
|
||||
import rip.iwakura.civil.Core;
|
||||
import rip.iwakura.civil.Database;
|
||||
import rip.iwakura.civil.exceptions.InvalidChannelException;
|
||||
import rip.iwakura.civil.types.*;
|
||||
|
||||
public class Spawn {
|
||||
private Core core;
|
||||
|
||||
public Spawn(Core core) {
|
||||
this.core = core;
|
||||
}
|
||||
|
||||
public LiteralCommandNode<CommandSourceStack> getCommand() {
|
||||
return Commands.literal("spawn")
|
||||
.requires(ctx -> ctx.getSender() instanceof Player)
|
||||
.executes(ctx -> {
|
||||
Player p = (Player) ctx.getSource().getSender();
|
||||
|
||||
if (!core.getConfig().contains("spawn")) {
|
||||
p.sendMessage(MiniMessage.miniMessage().deserialize("<red>The spawn has not been set yet."));
|
||||
return 0;
|
||||
}
|
||||
|
||||
p.teleport(core.getSpawn());
|
||||
|
||||
return Command.SINGLE_SUCCESS;
|
||||
})
|
||||
.then(Commands.literal("set").requires(
|
||||
ctx -> ctx.getSender() instanceof Player && ctx.getSender().hasPermission("civil.spawn.set"))
|
||||
.executes(ctx -> {
|
||||
Player p = (Player) ctx.getSource().getSender();
|
||||
Location loc = p.getLocation();
|
||||
|
||||
core.getConfig().set("spawn.world", loc.getWorld().getName());
|
||||
core.getConfig().set("spawn.x", loc.x());
|
||||
core.getConfig().set("spawn.y", loc.y());
|
||||
core.getConfig().set("spawn.z", loc.z());
|
||||
core.getConfig().set("spawn.yaw", loc.getYaw());
|
||||
core.getConfig().set("spawn.pitch", loc.getPitch());
|
||||
|
||||
p.sendMessage(MiniMessage.miniMessage().deserialize("<green>Set the server spawn to your current position."));
|
||||
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}))
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue