From 5e3b99d201a66508feaba5e442d681feeea2fc33 Mon Sep 17 00:00:00 2001 From: Rhythmic Date: Thu, 5 Mar 2026 20:21:45 -0600 Subject: [PATCH] feat: migrate commands to Paper Brigadier and update to 1.21.5 - bump Java to 21 and paper-api to 1.21.5 - switch `/back` and `/backreload` from CommandExecutor to lifecycle Brigadier registration - add command exception types for localized error/cooldown feedback - rename `Message` -> `LocaleMessage` and `Permissions` -> `BackPermission` - register permissions in code and remove command/permission blocks from plugin.yml - add new locale keys for invalid/missing player arguments --- pom.xml | 4 +- .../simplexity/simpleback/SimpleBack.java | 24 +++-- .../simplexity/simpleback/commands/Back.java | 91 +++++++++++++------ .../simpleback/commands/BackReload.java | 31 ++++--- .../simpleback/commands/Exceptions.java | 43 +++++++++ .../simpleback/config/LocaleHandler.java | 14 +-- .../{Message.java => LocaleMessage.java} | 6 +- .../simpleback/handlers/BackPermission.java | 30 ++++++ .../simpleback/handlers/CooldownHandler.java | 5 +- .../simpleback/handlers/MessageHandler.java | 24 ++--- .../simpleback/handlers/Permissions.java | 10 -- .../simpleback/handlers/TeleportHandler.java | 14 +-- src/main/resources/paper-plugin.yml | 5 + src/main/resources/plugin.yml | 38 -------- 14 files changed, 208 insertions(+), 131 deletions(-) create mode 100644 src/main/java/simplexity/simpleback/commands/Exceptions.java rename src/main/java/simplexity/simpleback/config/{Message.java => LocaleMessage.java} (85%) create mode 100644 src/main/java/simplexity/simpleback/handlers/BackPermission.java delete mode 100644 src/main/java/simplexity/simpleback/handlers/Permissions.java create mode 100644 src/main/resources/paper-plugin.yml delete mode 100644 src/main/resources/plugin.yml diff --git a/pom.xml b/pom.xml index 5c788db..0f1de56 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ SimpleBack - 17 + 21 UTF-8 @@ -65,7 +65,7 @@ io.papermc.paper paper-api - 1.20.4-R0.1-SNAPSHOT + 1.21.5-R0.1-SNAPSHOT provided diff --git a/src/main/java/simplexity/simpleback/SimpleBack.java b/src/main/java/simplexity/simpleback/SimpleBack.java index bf9f73e..c31afe1 100644 --- a/src/main/java/simplexity/simpleback/SimpleBack.java +++ b/src/main/java/simplexity/simpleback/SimpleBack.java @@ -1,20 +1,19 @@ package simplexity.simpleback; +import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents; import net.kyori.adventure.text.minimessage.MiniMessage; import org.bukkit.Location; import org.bukkit.plugin.java.JavaPlugin; import simplexity.simpleback.commands.Back; import simplexity.simpleback.commands.BackReload; import simplexity.simpleback.config.ConfigHandler; -import simplexity.simpleback.listeners.DeathListener; -import simplexity.simpleback.listeners.JoinListener; -import simplexity.simpleback.listeners.LeaveListener; -import simplexity.simpleback.listeners.MovementListener; -import simplexity.simpleback.listeners.TeleportListener; +import simplexity.simpleback.handlers.BackPermission; +import simplexity.simpleback.listeners.*; import java.util.HashMap; import java.util.UUID; +@SuppressWarnings("UnstableApiUsage") public final class SimpleBack extends JavaPlugin { private final HashMap backLocations = new HashMap<>(); private static final MiniMessage miniMessage = MiniMessage.miniMessage(); @@ -27,17 +26,22 @@ public void onEnable() { getConfig().options().copyDefaults(true); saveConfig(); ConfigHandler.getInstance().loadConfigValues(); + registerPermissions(); this.getServer().getPluginManager().registerEvents(new TeleportListener(), this); this.getServer().getPluginManager().registerEvents(new MovementListener(), this); this.getServer().getPluginManager().registerEvents(new JoinListener(), this); this.getServer().getPluginManager().registerEvents(new LeaveListener(), this); this.getServer().getPluginManager().registerEvents(new DeathListener(), this); - //noinspection DataFlowIssue - this.getCommand("back").setExecutor(new Back()); - //noinspection DataFlowIssue - this.getCommand("backreload").setExecutor(new BackReload()); - // Plugin startup logic + this.getLifecycleManager().registerEventHandler(LifecycleEvents.COMMANDS, commands -> { + commands.registrar().register(Back.createCommand().build()); + commands.registrar().register(BackReload.createCommand().build()); + }); + } + private void registerPermissions(){ + for (BackPermission permission : BackPermission.values()) { + this.getServer().getPluginManager().addPermission(permission.getPermission()); + } } public HashMap getBackLocations() { diff --git a/src/main/java/simplexity/simpleback/commands/Back.java b/src/main/java/simplexity/simpleback/commands/Back.java index 57a2ef6..10d990e 100644 --- a/src/main/java/simplexity/simpleback/commands/Back.java +++ b/src/main/java/simplexity/simpleback/commands/Back.java @@ -1,42 +1,77 @@ package simplexity.simpleback.commands; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; +import com.mojang.brigadier.Command; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import io.papermc.paper.command.brigadier.CommandSourceStack; +import io.papermc.paper.command.brigadier.Commands; +import io.papermc.paper.command.brigadier.argument.ArgumentTypes; +import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver; import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; -import simplexity.simpleback.config.ConfigHandler; -import simplexity.simpleback.config.Message; import simplexity.simpleback.SimpleBack; +import simplexity.simpleback.config.ConfigHandler; import simplexity.simpleback.handlers.CooldownHandler; -import simplexity.simpleback.handlers.MessageHandler; +import simplexity.simpleback.handlers.BackPermission; import simplexity.simpleback.handlers.TeleportHandler; -public class Back implements CommandExecutor { - @Override - public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) { - if (!(sender instanceof Player player)) { - sender.sendRichMessage(Message.ERROR_MUST_BE_PLAYER.getMessage()); - return true; - } - if (!SimpleBack.getInstance().getBackLocations().containsKey(player.getUniqueId())) { - player.sendRichMessage(Message.ERROR_NO_BACK_LOCATIONS.getMessage()); - return true; - } - if (!CooldownHandler.cooldownExpired(player)) { - player.sendMessage(MessageHandler.getParsedTimeMessage(Message.ERROR_COOLDOWN, - CooldownHandler.getLeftoverCooldownTime(player.getUniqueId()))); - return false; - } - if (TeleportHandler.blacklistedWorld(player)) { - player.sendRichMessage(Message.ERROR_BLACKLISTED_WORLD.getMessage()); - return false; +import java.util.List; + +@SuppressWarnings({"UnstableApiUsage", "SameReturnValue"}) +public class Back { + + public static LiteralArgumentBuilder createCommand() { + return Commands.literal("back") + .requires(Back::canExecute) + .executes(Back::execute) + .then(Commands.argument("player", ArgumentTypes.player()) + .requires(Back::canExecuteWithArg) + .executes(Back::executeWithArg)); + } + + + private static int execute(CommandContext ctx) throws CommandSyntaxException { + if (!(ctx.getSource().getSender() instanceof Player player)) throw Exceptions.MUST_PROVIDE_PLAYER.create(); + if (!SimpleBack.getInstance().getBackLocations().containsKey(player.getUniqueId())) + throw Exceptions.NO_BACK_LOCATIONS.create(); + if (!CooldownHandler.cooldownExpired(player)) + throw Exceptions.COOLDOWN_NOT_FINISHED.create(CooldownHandler.getLeftoverCooldownTime(player.getUniqueId())); + if (TeleportHandler.blacklistedWorld(player)) throw Exceptions.BLACKLISTED_WORLD.create(); + if (ConfigHandler.getInstance().isTeleportDelay()) { + TeleportHandler.delayTeleport(player); + return Command.SINGLE_SUCCESS; } + TeleportHandler.teleport(player); + return Command.SINGLE_SUCCESS; + } + + private static int executeWithArg(CommandContext ctx) throws CommandSyntaxException { + PlayerSelectorArgumentResolver argResolver = ctx.getArgument("player", PlayerSelectorArgumentResolver.class); + List playerList = argResolver.resolve(ctx.getSource()); + if (playerList.isEmpty()) throw Exceptions.PLAYER_NOT_FOUND.create(); + Player player = playerList.getFirst(); + if (!SimpleBack.getInstance().getBackLocations().containsKey(player.getUniqueId())) + throw Exceptions.NO_BACK_LOCATIONS.create(); + if (!CooldownHandler.cooldownExpired(player)) + throw Exceptions.COOLDOWN_NOT_FINISHED.create(CooldownHandler.getLeftoverCooldownTime(player.getUniqueId())); + if (TeleportHandler.blacklistedWorld(player)) throw Exceptions.BLACKLISTED_WORLD.create(); if (ConfigHandler.getInstance().isTeleportDelay()) { TeleportHandler.delayTeleport(player); - return true; + return Command.SINGLE_SUCCESS; } TeleportHandler.teleport(player); - return true; + return Command.SINGLE_SUCCESS; + } + + private static boolean canExecute(CommandSourceStack css) { + if (css.getSender() instanceof Player player) { + return player.hasPermission(BackPermission.BACK_USE.getPermission()); + } + return css.getSender().hasPermission(BackPermission.FORCE_BACK.getPermission()); + } + + private static boolean canExecuteWithArg(CommandSourceStack css) { + if (css.getSender() instanceof Player) return false; + return css.getSender().hasPermission(BackPermission.FORCE_BACK.getPermission()); } } diff --git a/src/main/java/simplexity/simpleback/commands/BackReload.java b/src/main/java/simplexity/simpleback/commands/BackReload.java index cca34c0..0315c1d 100644 --- a/src/main/java/simplexity/simpleback/commands/BackReload.java +++ b/src/main/java/simplexity/simpleback/commands/BackReload.java @@ -1,19 +1,24 @@ package simplexity.simpleback.commands; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.jetbrains.annotations.NotNull; +import com.mojang.brigadier.Command; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import io.papermc.paper.command.brigadier.CommandSourceStack; +import io.papermc.paper.command.brigadier.Commands; import simplexity.simpleback.config.ConfigHandler; -import simplexity.simpleback.config.Message; -import simplexity.simpleback.handlers.CacheHandler; +import simplexity.simpleback.config.LocaleMessage; +import simplexity.simpleback.handlers.BackPermission; -public class BackReload implements CommandExecutor { - @Override - public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String s, @NotNull String[] args) { - CacheHandler.clearCache(); - ConfigHandler.getInstance().loadConfigValues(); - sender.sendRichMessage(Message.PLUGIN_RELOADED.getMessage()); - return true; +@SuppressWarnings("UnstableApiUsage") +public class BackReload { + + public static LiteralArgumentBuilder createCommand() { + return Commands.literal("backreload") + .requires(css -> css.getSender().hasPermission(BackPermission.BACK_RELOAD.getPermission())) + .executes(css -> { + ConfigHandler.getInstance().loadConfigValues(); + css.getSource().getSender().sendRichMessage(LocaleMessage.PLUGIN_RELOADED.getMessage()); + return Command.SINGLE_SUCCESS; + }); } + } diff --git a/src/main/java/simplexity/simpleback/commands/Exceptions.java b/src/main/java/simplexity/simpleback/commands/Exceptions.java new file mode 100644 index 0000000..71492db --- /dev/null +++ b/src/main/java/simplexity/simpleback/commands/Exceptions.java @@ -0,0 +1,43 @@ +package simplexity.simpleback.commands; + +import com.mojang.brigadier.Message; +import com.mojang.brigadier.exceptions.DynamicCommandExceptionType; +import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; +import io.papermc.paper.command.brigadier.MessageComponentSerializer; +import net.kyori.adventure.text.minimessage.MiniMessage; +import simplexity.simpleback.SimpleBack; +import simplexity.simpleback.config.LocaleMessage; +import simplexity.simpleback.handlers.MessageHandler; + +@SuppressWarnings("UnstableApiUsage") +public class Exceptions { + private static final MiniMessage miniMessage = SimpleBack.getMiniMessage(); + + public static final SimpleCommandExceptionType NO_BACK_LOCATIONS = new SimpleCommandExceptionType( + parseMessage(LocaleMessage.ERROR_NO_BACK_LOCATIONS) + ); + + public static final SimpleCommandExceptionType BLACKLISTED_WORLD = new SimpleCommandExceptionType( + parseMessage(LocaleMessage.ERROR_BLACKLISTED_WORLD) + ); + + public static final SimpleCommandExceptionType PLAYER_NOT_FOUND = new SimpleCommandExceptionType( + parseMessage(LocaleMessage.ERROR_PLAYER_INVALID) + ); + + public static final SimpleCommandExceptionType MUST_PROVIDE_PLAYER = new SimpleCommandExceptionType( + parseMessage(LocaleMessage.ERROR_MUST_PROVIDE_PLAYER) + ); + + public static final DynamicCommandExceptionType COOLDOWN_NOT_FINISHED = new DynamicCommandExceptionType(time -> { + return MessageComponentSerializer.message().serialize( + MessageHandler.getParsedTimeMessage(LocaleMessage.ERROR_COOLDOWN, (long) time) + ); + }); + + private static Message parseMessage(LocaleMessage message){ + return MessageComponentSerializer.message().serialize( + miniMessage.deserialize(message.getMessage()) + ); + } +} diff --git a/src/main/java/simplexity/simpleback/config/LocaleHandler.java b/src/main/java/simplexity/simpleback/config/LocaleHandler.java index 5bc4d5d..8a454d2 100644 --- a/src/main/java/simplexity/simpleback/config/LocaleHandler.java +++ b/src/main/java/simplexity/simpleback/config/LocaleHandler.java @@ -51,16 +51,16 @@ public void reloadLocale() { private void populateLocale() { - Set missing = new HashSet<>(Arrays.asList(Message.values())); - for (Message message : Message.values()) { - if (locale.contains(message.getPath())) { - message.setMessage(locale.getString(message.getPath())); - missing.remove(message); + Set missing = new HashSet<>(Arrays.asList(LocaleMessage.values())); + for (LocaleMessage localeMessage : LocaleMessage.values()) { + if (locale.contains(localeMessage.getPath())) { + localeMessage.setMessage(locale.getString(localeMessage.getPath())); + missing.remove(localeMessage); } } - for (Message message : missing) { - locale.set(message.getPath(), message.getMessage()); + for (LocaleMessage localeMessage : missing) { + locale.set(localeMessage.getPath(), localeMessage.getMessage()); } diff --git a/src/main/java/simplexity/simpleback/config/Message.java b/src/main/java/simplexity/simpleback/config/LocaleMessage.java similarity index 85% rename from src/main/java/simplexity/simpleback/config/Message.java rename to src/main/java/simplexity/simpleback/config/LocaleMessage.java index 8cde67b..3ab0b3e 100644 --- a/src/main/java/simplexity/simpleback/config/Message.java +++ b/src/main/java/simplexity/simpleback/config/LocaleMessage.java @@ -1,6 +1,6 @@ package simplexity.simpleback.config; -public enum Message { +public enum LocaleMessage { TELEPORT_PLEASE_WAIT("message.teleport-delay", "Teleporting! Please wait seconds!"), TELEPORT_SUCCESSFUL("message.teleport-successful", "Successfully teleported to , , in !"), TELEPORT_CANCELLED("message.teleport-cancelled", "Teleport Cancelled"), @@ -12,6 +12,8 @@ public enum Message { INSERT_MINUTE("insert.minute", "m "), INSERT_SECOND("insert.second", "s"), ERROR_MUST_BE_PLAYER("error.must-be-player", "Sorry, you must be a player to run this command!"), + ERROR_MUST_PROVIDE_PLAYER("error.must-provide-player", "You must provide a valid player for this command!"), + ERROR_PLAYER_INVALID("error.player-invalid", "Player not found"), ERROR_NO_BACK_LOCATIONS("error.no-back-locations", "No back locations found!"), ERROR_COOLDOWN("error.command-cooldown", "Sorry, that command is on cooldown for: []!"), ERROR_BLACKLISTED_WORLD("error.blacklisted-world", "Sorry, the world you are trying to return to is blacklisted!"), @@ -19,7 +21,7 @@ public enum Message { private final String path; private String message; - Message(String path, String message) { + LocaleMessage(String path, String message) { this.path = path; this.message = message; } diff --git a/src/main/java/simplexity/simpleback/handlers/BackPermission.java b/src/main/java/simplexity/simpleback/handlers/BackPermission.java new file mode 100644 index 0000000..81bd9a3 --- /dev/null +++ b/src/main/java/simplexity/simpleback/handlers/BackPermission.java @@ -0,0 +1,30 @@ +package simplexity.simpleback.handlers; + +import org.bukkit.permissions.Permission; +import org.bukkit.permissions.PermissionDefault; + +public enum BackPermission { + // Declaration order so I don't keep having to look and forget + // Permission(@NotNull String name, + // @Nullable String description, + // @Nullable PermissionDefault defaultValue, + // @Nullable Map children) + + BACK_USE(new Permission("back.use", "Allows the player to use the back command", PermissionDefault.TRUE)), + FORCE_BACK(new Permission("back.force", "Runs /back for another player", PermissionDefault.OP)), + BACK_RELOAD(new Permission("back.reload", "Allows the player to reload the SimpleBack config", PermissionDefault.OP)), + DELAY_BYPASS(new Permission("back.bypass.delay", "Bypass the teleport delay completely", PermissionDefault.OP)), + MOVEMENT_BYPASS(new Permission("back.bypass.movement", "Bypass the 'no movement' requirement of the teleport delay", PermissionDefault.OP)), + WORLD_BYPASS(new Permission("back.bypass.worlds", "Bypass the worlds blacklist for /back", PermissionDefault.OP)), + COOLDOWN_BYPASS(new Permission("back.bypass.cooldown", "Bypass the cooldown on /back", PermissionDefault.OP)); + + private final Permission permission; + + BackPermission(Permission permission) { + this.permission = permission; + } + + public Permission getPermission() { + return permission; + } +} diff --git a/src/main/java/simplexity/simpleback/handlers/CooldownHandler.java b/src/main/java/simplexity/simpleback/handlers/CooldownHandler.java index 4d000a5..1f32f8a 100644 --- a/src/main/java/simplexity/simpleback/handlers/CooldownHandler.java +++ b/src/main/java/simplexity/simpleback/handlers/CooldownHandler.java @@ -7,12 +7,13 @@ import java.util.HashMap; import java.util.UUID; +@SuppressWarnings("BooleanMethodIsAlwaysInverted") public class CooldownHandler { public static final HashMap cooldownTime = new HashMap<>(); static void addToCooldown(@NotNull Player player) { if (!ConfigHandler.getInstance().isTeleportCooldown()) return; - if (player.hasPermission(Permissions.COOLDOWN_BYPASS)) return; + if (player.hasPermission(BackPermission.COOLDOWN_BYPASS.getPermission())) return; UUID uuid = player.getUniqueId(); Long cooldownTimeMilli = System.currentTimeMillis() + (ConfigHandler.getInstance().getCooldownInSeconds() * 1000L); cooldownTime.put(uuid, cooldownTimeMilli); @@ -21,7 +22,7 @@ static void addToCooldown(@NotNull Player player) { public static boolean cooldownExpired(@NotNull Player player) { UUID uuid = player.getUniqueId(); if (!cooldownTime.containsKey(uuid)) return true; - if (player.hasPermission(Permissions.COOLDOWN_BYPASS)) return true; + if (player.hasPermission(BackPermission.COOLDOWN_BYPASS.getPermission())) return true; long leftoverTime = getLeftoverCooldownTime(uuid); return leftoverTime <= 0; } diff --git a/src/main/java/simplexity/simpleback/handlers/MessageHandler.java b/src/main/java/simplexity/simpleback/handlers/MessageHandler.java index 2780f2c..819c9a0 100644 --- a/src/main/java/simplexity/simpleback/handlers/MessageHandler.java +++ b/src/main/java/simplexity/simpleback/handlers/MessageHandler.java @@ -5,29 +5,29 @@ import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import org.bukkit.Location; import simplexity.simpleback.SimpleBack; -import simplexity.simpleback.config.Message; +import simplexity.simpleback.config.LocaleMessage; public class MessageHandler { private static final MiniMessage miniMessage = SimpleBack.getMiniMessage(); - public static Component getParsedLocationMessage(Message message, Location location) { - Component xLocation = miniMessage.deserialize(Message.INSERT_X_LOC.getMessage(), + public static Component getParsedLocationMessage(LocaleMessage localeMessage, Location location) { + Component xLocation = miniMessage.deserialize(LocaleMessage.INSERT_X_LOC.getMessage(), Placeholder.unparsed("value", String.valueOf(location.getBlockX()))); - Component yLocation = miniMessage.deserialize(Message.INSERT_Y_LOC.getMessage(), + Component yLocation = miniMessage.deserialize(LocaleMessage.INSERT_Y_LOC.getMessage(), Placeholder.unparsed("value", String.valueOf(location.getBlockY()))); - Component zLocation = miniMessage.deserialize(Message.INSERT_Z_LOC.getMessage(), + Component zLocation = miniMessage.deserialize(LocaleMessage.INSERT_Z_LOC.getMessage(), Placeholder.unparsed("value", String.valueOf(location.getBlockZ()))); - Component worldName = miniMessage.deserialize(Message.INSERT_WORLD.getMessage(), + Component worldName = miniMessage.deserialize(LocaleMessage.INSERT_WORLD.getMessage(), Placeholder.unparsed("value", location.getWorld().getName())); - return miniMessage.deserialize(message.getMessage(), + return miniMessage.deserialize(localeMessage.getMessage(), Placeholder.component("x-loc", xLocation), Placeholder.component("y-loc", yLocation), Placeholder.component("z-loc", zLocation), Placeholder.component("world", worldName)); } - public static Component getParsedTimeMessage(Message message, long millis) { + public static Component getParsedTimeMessage(LocaleMessage localeMessage, long millis) { long seconds = (millis / 1000) % 60; long minutes = (millis / (1000 * 60)) % 60; long hours = millis / (1000 * 60 * 60); @@ -35,15 +35,15 @@ public static Component getParsedTimeMessage(Message message, long millis) { Component minutesComponent = Component.empty(); Component secondsComponent = Component.empty(); if (hours > 0) hoursComponent = miniMessage.deserialize( - Message.INSERT_HOUR.getMessage(), + LocaleMessage.INSERT_HOUR.getMessage(), Placeholder.unparsed("hour", String.valueOf(hours))); if (minutes > 0) minutesComponent = miniMessage.deserialize( - Message.INSERT_MINUTE.getMessage(), + LocaleMessage.INSERT_MINUTE.getMessage(), Placeholder.unparsed("minute", String.valueOf(minutes))); if (seconds > 0) secondsComponent = miniMessage.deserialize( - Message.INSERT_SECOND.getMessage(), + LocaleMessage.INSERT_SECOND.getMessage(), Placeholder.unparsed("second", String.valueOf(seconds))); - return miniMessage.deserialize(message.getMessage(), + return miniMessage.deserialize(localeMessage.getMessage(), Placeholder.component("hour", hoursComponent), Placeholder.component("minute", minutesComponent), Placeholder.component("second", secondsComponent)); diff --git a/src/main/java/simplexity/simpleback/handlers/Permissions.java b/src/main/java/simplexity/simpleback/handlers/Permissions.java deleted file mode 100644 index 08549b7..0000000 --- a/src/main/java/simplexity/simpleback/handlers/Permissions.java +++ /dev/null @@ -1,10 +0,0 @@ -package simplexity.simpleback.handlers; - -import org.bukkit.permissions.Permission; - -public class Permissions { - public static final Permission DELAY_BYPASS = new Permission("back.bypass.delay"); - public static final Permission MOVEMENT_BYPASS = new Permission("back.bypass.movement"); - public static final Permission WORLD_BYPASS = new Permission("back.bypass.worlds"); - public static final Permission COOLDOWN_BYPASS = new Permission("back.bypass.cooldown"); -} diff --git a/src/main/java/simplexity/simpleback/handlers/TeleportHandler.java b/src/main/java/simplexity/simpleback/handlers/TeleportHandler.java index b10914f..697fc6f 100644 --- a/src/main/java/simplexity/simpleback/handlers/TeleportHandler.java +++ b/src/main/java/simplexity/simpleback/handlers/TeleportHandler.java @@ -8,7 +8,7 @@ import org.jetbrains.annotations.NotNull; import simplexity.simpleback.SimpleBack; import simplexity.simpleback.config.ConfigHandler; -import simplexity.simpleback.config.Message; +import simplexity.simpleback.config.LocaleMessage; import java.util.HashMap; import java.util.UUID; @@ -18,16 +18,16 @@ public class TeleportHandler { public static final HashMap startingLocations = new HashMap<>(); public static void delayTeleport(@NotNull Player player) { - if (player.hasPermission(Permissions.DELAY_BYPASS)) { + if (player.hasPermission(BackPermission.DELAY_BYPASS.getPermission())) { teleport(player); return; } - if (!player.hasPermission(Permissions.MOVEMENT_BYPASS)) { + if (!player.hasPermission(BackPermission.MOVEMENT_BYPASS.getPermission())) { startingLocations.put(player.getUniqueId(), player.getLocation()); } UUID uuid = player.getUniqueId(); int delay = ConfigHandler.getInstance().getDelayInSeconds(); - player.sendRichMessage(Message.TELEPORT_PLEASE_WAIT.getMessage(), + player.sendRichMessage(LocaleMessage.TELEPORT_PLEASE_WAIT.getMessage(), Placeholder.unparsed("value", String.valueOf(delay))); BukkitTask task = Bukkit.getScheduler().runTaskLater(SimpleBack.getInstance(), () -> { teleport(player); @@ -37,7 +37,7 @@ public static void delayTeleport(@NotNull Player player) { public static void teleport(@NotNull Player player) { Location location = SimpleBack.getInstance().getBackLocations().get(player.getUniqueId()); - player.sendMessage(MessageHandler.getParsedLocationMessage(Message.TELEPORT_SUCCESSFUL, location)); + player.sendMessage(MessageHandler.getParsedLocationMessage(LocaleMessage.TELEPORT_SUCCESSFUL, location)); player.teleportAsync(location); CooldownHandler.addToCooldown(player); UUID uuid = player.getUniqueId(); @@ -49,12 +49,12 @@ public static void cancelTeleport(@NotNull Player player) { UUID uuid = player.getUniqueId(); currentTasks.get(uuid).cancel(); startingLocations.remove(uuid); - player.sendRichMessage(Message.TELEPORT_CANCELLED.getMessage()); + player.sendRichMessage(LocaleMessage.TELEPORT_CANCELLED.getMessage()); } public static boolean blacklistedWorld(@NotNull Player player) { UUID uuid = player.getUniqueId(); - if (player.hasPermission(Permissions.WORLD_BYPASS)) return false; + if (player.hasPermission(BackPermission.WORLD_BYPASS.getPermission())) return false; Location location = SimpleBack.getInstance().getBackLocations().get(uuid); if (location == null) return false; UUID worldUUID = location.getWorld().getUID(); diff --git a/src/main/resources/paper-plugin.yml b/src/main/resources/paper-plugin.yml new file mode 100644 index 0000000..0797f2b --- /dev/null +++ b/src/main/resources/paper-plugin.yml @@ -0,0 +1,5 @@ +name: SimpleBack +version: '${project.version}' +main: simplexity.simpleback.SimpleBack +api-version: '1.21.5' +website: "https://github.com/Simplexity-Development/SimpleBack" \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml deleted file mode 100644 index 75f7e40..0000000 --- a/src/main/resources/plugin.yml +++ /dev/null @@ -1,38 +0,0 @@ -name: SimpleBack -version: '${project.version}' -main: simplexity.simpleback.SimpleBack -api-version: '1.20' -commands: - back: - permission: back.use - description: teleport back to the last location you teleported to - backreload: - permission: back.reload - description: reload the config -permissions: - back.use: - default: true - description: use the back command - back.bypass: - default: op - description: Bypass any restrictions set in the config - children: - back.bypass.delay: true - back.bypass.movement: true - back.bypass.worlds: true - back.bypass.cooldown: true - back.bypass.delay: - default: op - description: Bypass the teleport delay completely - back.bypass.movement: - default: op - description: Bypass the 'no movement' requirement of the teleport delay - back.bypass.worlds: - default: op - description: Bypass the worlds blacklist for /back - back.bypass.cooldown: - default: op - description: Bypass the cooldown on /back - back.reload: - default: op - description: reload the config \ No newline at end of file