From c4320edb2d2c56b0d18713537a325de3eae2f3b8 Mon Sep 17 00:00:00 2001 From: William Date: Thu, 23 Mar 2023 23:26:30 +0000 Subject: [PATCH] Tweak permission registration --- .../huskhomes/api/HuskHomesAPI.java | 2 +- .../net/william278/huskhomes/HuskHomes.java | 9 +- .../william278/huskhomes/command/Command.java | 17 +- .../huskhomes/command/EditHomeCommand.java | 6 +- .../huskhomes/command/EditWarpCommand.java | 3 + .../huskhomes/command/HuskHomesCommand.java | 16 +- .../command/PrivateHomeListCommand.java | 2 + .../huskhomes/command/RtpCommand.java | 7 +- .../command/SavedPositionCommand.java | 8 +- .../huskhomes/command/SpawnCommand.java | 2 + .../huskhomes/command/TpCommand.java | 10 +- .../huskhomes/database/Database.java | 5 +- .../huskhomes/database/SqLiteDatabase.java | 5 +- .../huskhomes/hook/EconomyHook.java | 2 + .../huskhomes/listener/EventListener.java | 16 +- .../huskhomes/teleport/Teleport.java | 9 +- .../huskhomes/teleport/TimedTeleport.java | 4 +- .../william278/huskhomes/util/Permission.java | 209 ------------------ .../huskhomes/config/LocalesTests.java | 5 +- 19 files changed, 84 insertions(+), 253 deletions(-) delete mode 100644 common/src/main/java/net/william278/huskhomes/util/Permission.java diff --git a/bukkit/src/main/java/net/william278/huskhomes/api/HuskHomesAPI.java b/bukkit/src/main/java/net/william278/huskhomes/api/HuskHomesAPI.java index 95d6153a..317c246e 100644 --- a/bukkit/src/main/java/net/william278/huskhomes/api/HuskHomesAPI.java +++ b/bukkit/src/main/java/net/william278/huskhomes/api/HuskHomesAPI.java @@ -1,9 +1,9 @@ package net.william278.huskhomes.api; import net.william278.huskhomes.BukkitHuskHomes; +import net.william278.huskhomes.config.Server; import net.william278.huskhomes.position.Location; import net.william278.huskhomes.position.Position; -import net.william278.huskhomes.config.Server; import net.william278.huskhomes.user.BukkitUser; import net.william278.huskhomes.user.OnlineUser; import net.william278.huskhomes.user.User; diff --git a/common/src/main/java/net/william278/huskhomes/HuskHomes.java b/common/src/main/java/net/william278/huskhomes/HuskHomes.java index 7b2eec4b..87abd6dc 100644 --- a/common/src/main/java/net/william278/huskhomes/HuskHomes.java +++ b/common/src/main/java/net/william278/huskhomes/HuskHomes.java @@ -7,23 +7,22 @@ import net.william278.desertwell.UpdateChecker; import net.william278.desertwell.Version; import net.william278.huskhomes.command.Command; import net.william278.huskhomes.config.Locales; +import net.william278.huskhomes.config.Server; import net.william278.huskhomes.config.Settings; import net.william278.huskhomes.config.Spawn; import net.william278.huskhomes.database.Database; import net.william278.huskhomes.event.EventDispatcher; import net.william278.huskhomes.hook.EconomyHook; -import net.william278.huskhomes.hook.MapHook; import net.william278.huskhomes.hook.Hook; +import net.william278.huskhomes.hook.MapHook; import net.william278.huskhomes.manager.Manager; import net.william278.huskhomes.network.Broker; import net.william278.huskhomes.position.Location; import net.william278.huskhomes.position.Position; -import net.william278.huskhomes.config.Server; import net.william278.huskhomes.position.World; import net.william278.huskhomes.random.RandomTeleportEngine; import net.william278.huskhomes.user.ConsoleUser; import net.william278.huskhomes.user.OnlineUser; -import net.william278.huskhomes.util.Permission; import net.william278.huskhomes.util.TaskRunner; import net.william278.huskhomes.util.Validator; import org.intellij.lang.annotations.Subst; @@ -193,7 +192,7 @@ public interface HuskHomes extends TaskRunner, EventDispatcher { @SuppressWarnings("BooleanMethodIsAlwaysInverted") default boolean validateEconomyCheck(@NotNull OnlineUser player, @NotNull EconomyHook.Action action) { final Optional cost = getSettings().getEconomyCost(action).map(Math::abs); - if (cost.isPresent() && !player.hasPermission(Permission.BYPASS_ECONOMY_CHECKS.node)) { + if (cost.isPresent() && !player.hasPermission(EconomyHook.BYPASS_PERMISSION)) { final Optional hook = getEconomyHook(); if (hook.isPresent()) { if (cost.get() > hook.get().getPlayerBalance(player)) { @@ -216,7 +215,7 @@ public interface HuskHomes extends TaskRunner, EventDispatcher { if (!getSettings().doEconomy()) return; final Optional cost = getSettings().getEconomyCost(action).map(Math::abs); - if (cost.isPresent() && !player.hasPermission(Permission.BYPASS_ECONOMY_CHECKS.node)) { + if (cost.isPresent() && !player.hasPermission(EconomyHook.BYPASS_PERMISSION)) { final Optional hook = getEconomyHook(); if (hook.isPresent()) { hook.get().changePlayerBalance(player, -cost.get()); diff --git a/common/src/main/java/net/william278/huskhomes/command/Command.java b/common/src/main/java/net/william278/huskhomes/command/Command.java index 4082636b..9d1c7abe 100644 --- a/common/src/main/java/net/william278/huskhomes/command/Command.java +++ b/common/src/main/java/net/william278/huskhomes/command/Command.java @@ -4,16 +4,19 @@ import net.william278.huskhomes.HuskHomes; import net.william278.huskhomes.user.CommandUser; import org.jetbrains.annotations.NotNull; +import java.util.HashMap; import java.util.List; import java.util.Map; public abstract class Command extends Node { private final String usage; + private final Map additionalPermissions; protected Command(@NotNull String name, @NotNull List aliases, @NotNull String usage, @NotNull HuskHomes plugin) { super(name, aliases, plugin); this.usage = usage; + this.additionalPermissions = new HashMap<>(); } @Override @@ -40,6 +43,15 @@ public abstract class Command extends Node { return "/" + getName() + " " + usage; } + public final void addAdditionalPermissions(@NotNull Map additionalPermissions) { + additionalPermissions.forEach((permission, value) -> this.additionalPermissions.put(getPermission(permission), value)); + } + + @NotNull + public final Map getAdditionalPermissions() { + return additionalPermissions; + } + @NotNull public String getDescription() { return plugin.getLocales().getRawLocale(getName() + "_command_description") @@ -47,11 +59,6 @@ public abstract class Command extends Node { .orElse(getUsage()); } - @NotNull - public Map getAdditionalPermissions() { - return Map.of(); - } - @NotNull public final HuskHomes getPlugin() { return plugin; diff --git a/common/src/main/java/net/william278/huskhomes/command/EditHomeCommand.java b/common/src/main/java/net/william278/huskhomes/command/EditHomeCommand.java index 69c505af..dcd66cb3 100644 --- a/common/src/main/java/net/william278/huskhomes/command/EditHomeCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/EditHomeCommand.java @@ -12,15 +12,15 @@ import org.jetbrains.annotations.NotNull; import java.time.ZoneId; import java.time.format.DateTimeFormatter; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; +import java.util.*; import java.util.regex.Pattern; public class EditHomeCommand extends SavedPositionCommand { public EditHomeCommand(@NotNull HuskHomes plugin) { super("edithome", List.of(), Home.class, List.of("rename", "description", "relocate", "privacy"), plugin); + addAdditionalPermissions(arguments.stream() + .collect(HashMap::new, (m, e) -> m.put(getPermission(e), false), HashMap::putAll)); } @Override diff --git a/common/src/main/java/net/william278/huskhomes/command/EditWarpCommand.java b/common/src/main/java/net/william278/huskhomes/command/EditWarpCommand.java index b0c167aa..d55ab551 100644 --- a/common/src/main/java/net/william278/huskhomes/command/EditWarpCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/EditWarpCommand.java @@ -11,6 +11,7 @@ import org.jetbrains.annotations.NotNull; import java.time.ZoneId; import java.time.format.DateTimeFormatter; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Optional; import java.util.regex.Pattern; @@ -19,6 +20,8 @@ public class EditWarpCommand extends SavedPositionCommand { public EditWarpCommand(@NotNull HuskHomes plugin) { super("editwarp", List.of(), Warp.class, List.of("rename", "description", "relocate"), plugin); + addAdditionalPermissions(arguments.stream() + .collect(HashMap::new, (m, e) -> m.put(getPermission(e), false), HashMap::putAll)); } @Override diff --git a/common/src/main/java/net/william278/huskhomes/command/HuskHomesCommand.java b/common/src/main/java/net/william278/huskhomes/command/HuskHomesCommand.java index 51622b4b..667e867b 100644 --- a/common/src/main/java/net/william278/huskhomes/command/HuskHomesCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/HuskHomesCommand.java @@ -10,18 +10,24 @@ import net.william278.paginedown.PaginatedList; import org.jetbrains.annotations.NotNull; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; public class HuskHomesCommand extends Command implements TabProvider { - private static final List SUB_COMMANDS = List.of("about", "help", "reload", "update"); + private static final Map SUB_COMMANDS = Map.of( + "about", false, + "help", false, + "reload", true, + "update", true + ); private final UpdateChecker updateChecker; private final AboutMenu aboutMenu; protected HuskHomesCommand(@NotNull HuskHomes plugin) { - super("huskhomes", List.of(), "[" + String.join("|", SUB_COMMANDS) + "]", plugin); - setOperatorCommand(true); + super("huskhomes", List.of(), "[" + String.join("|", SUB_COMMANDS.keySet()) + "]", plugin); + addAdditionalPermissions(SUB_COMMANDS); this.updateChecker = plugin.getUpdateChecker(); this.aboutMenu = AboutMenu.create("HuskHomes") @@ -52,7 +58,7 @@ public class HuskHomesCommand extends Command implements TabProvider { @Override public void execute(@NotNull CommandUser executor, @NotNull String[] args) { final String action = parseStringArg(args, 0).orElse("about"); - if (SUB_COMMANDS.contains(action) && !executor.hasPermission(getPermission(action))) { + if (SUB_COMMANDS.containsKey(action) && !executor.hasPermission(getPermission(action))) { plugin.getLocales().getLocale("error_no_permission") .ifPresent(executor::sendMessage); return; @@ -105,7 +111,7 @@ public class HuskHomesCommand extends Command implements TabProvider { @Override @NotNull public List suggest(@NotNull CommandUser user, @NotNull String[] args) { - return args.length < 2 ? SUB_COMMANDS : List.of(); + return args.length < 2 ? SUB_COMMANDS.keySet().stream().sorted().toList() : List.of(); } } diff --git a/common/src/main/java/net/william278/huskhomes/command/PrivateHomeListCommand.java b/common/src/main/java/net/william278/huskhomes/command/PrivateHomeListCommand.java index 9bfd7ee3..0f88d759 100644 --- a/common/src/main/java/net/william278/huskhomes/command/PrivateHomeListCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/PrivateHomeListCommand.java @@ -11,6 +11,7 @@ import net.william278.paginedown.PaginatedList; import org.jetbrains.annotations.NotNull; import java.util.List; +import java.util.Map; import java.util.Optional; import java.util.stream.Collectors; @@ -18,6 +19,7 @@ public class PrivateHomeListCommand extends ListCommand { protected PrivateHomeListCommand(@NotNull HuskHomes plugin) { super("homelist", List.of("homes"), "[player] [page]", plugin); + addAdditionalPermissions(Map.of("other", true)); } @Override diff --git a/common/src/main/java/net/william278/huskhomes/command/RtpCommand.java b/common/src/main/java/net/william278/huskhomes/command/RtpCommand.java index dd4dae68..716d82c6 100644 --- a/common/src/main/java/net/william278/huskhomes/command/RtpCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/RtpCommand.java @@ -14,12 +14,17 @@ import org.jetbrains.annotations.NotNull; import java.time.Instant; import java.time.temporal.ChronoUnit; import java.util.List; +import java.util.Map; import java.util.Optional; public class RtpCommand extends Command { protected RtpCommand(@NotNull HuskHomes plugin) { super("rtp", List.of(), "[player]", plugin); + addAdditionalPermissions(Map.of( + "other", true, + "bypass_cooldown", true + )); } @Override @@ -64,7 +69,7 @@ public class RtpCommand extends Command { .orElseThrow(() -> new IllegalStateException("No user data found for " + teleporter.getUsername())); final Instant currentTime = Instant.now(); if (executor.equals(teleporter) && !currentTime.isAfter(user.getRtpCooldown()) && - !executor.hasPermission(getPermission("bypass_cooldown"))) { + !executor.hasPermission(getPermission("bypass_cooldown"))) { plugin.getLocales().getLocale("error_rtp_cooldown", Long.toString(currentTime.until(user.getRtpCooldown(), ChronoUnit.MINUTES) + 1)) .ifPresent(executor::sendMessage); diff --git a/common/src/main/java/net/william278/huskhomes/command/SavedPositionCommand.java b/common/src/main/java/net/william278/huskhomes/command/SavedPositionCommand.java index 28b12224..7b0eb227 100644 --- a/common/src/main/java/net/william278/huskhomes/command/SavedPositionCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/SavedPositionCommand.java @@ -25,6 +25,8 @@ public abstract class SavedPositionCommand extends Comm super(name, aliases, "" + ((arguments.size() > 0) ? " [" + String.join("|", arguments) + "]" : ""), plugin); this.positionType = positionType; this.arguments = arguments; + + addAdditionalPermissions(Map.of("other", false)); } @NotNull @@ -114,12 +116,6 @@ public abstract class SavedPositionCommand extends Comm .execute(); } - @Override - @NotNull - public Map getAdditionalPermissions() { - return Map.of(getOtherPermission(), true); - } - @Override @NotNull public List suggest(@NotNull CommandUser executor, @NotNull String[] args) { diff --git a/common/src/main/java/net/william278/huskhomes/command/SpawnCommand.java b/common/src/main/java/net/william278/huskhomes/command/SpawnCommand.java index c8e8ee9c..32e3219c 100644 --- a/common/src/main/java/net/william278/huskhomes/command/SpawnCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/SpawnCommand.java @@ -10,12 +10,14 @@ import net.william278.huskhomes.user.CommandUser; import org.jetbrains.annotations.NotNull; import java.util.List; +import java.util.Map; import java.util.Optional; public class SpawnCommand extends Command { protected SpawnCommand(@NotNull HuskHomes plugin) { super("spawn", List.of(), "[player]", plugin); + addAdditionalPermissions(Map.of("other", true)); } @Override diff --git a/common/src/main/java/net/william278/huskhomes/command/TpCommand.java b/common/src/main/java/net/william278/huskhomes/command/TpCommand.java index 990ca681..6672c6ec 100644 --- a/common/src/main/java/net/william278/huskhomes/command/TpCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/TpCommand.java @@ -9,6 +9,7 @@ import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.Optional; import java.util.stream.Collectors; @@ -16,6 +17,7 @@ public class TpCommand extends Command implements TabProvider { protected TpCommand(@NotNull HuskHomes plugin) { super("tp", List.of("tpo"), "[] [target]", plugin); + addAdditionalPermissions(Map.of("coordinates", true)); setOperatorCommand(true); } @@ -31,10 +33,11 @@ public class TpCommand extends Command implements TabProvider { this.execute(executor, user, Target.username(args[0]), args); } - case 2 -> execute(executor, Teleportable.username(args[0]), Target.username(args[1]), args); + case 2 -> this.execute(executor, Teleportable.username(args[0]), Target.username(args[1]), args); default -> { final Position basePosition = getBasePosition(executor); - Optional target = parsePositionArgs(basePosition, args, 0); + Optional target = executor.hasPermission(getPermission("coordinates")) + ? parsePositionArgs(basePosition, args, 0) : Optional.empty(); if (target.isPresent()) { if (!(executor instanceof OnlineUser user)) { plugin.getLocales().getLocale("error_in_game_only") @@ -46,7 +49,8 @@ public class TpCommand extends Command implements TabProvider { return; } - target = parsePositionArgs(basePosition, args, 1); + target = executor.hasPermission(getPermission("coordinates")) + ? parsePositionArgs(basePosition, args, 0) : Optional.empty(); if (target.isPresent() && args.length >= 1) { this.execute(executor, Teleportable.username(args[0]), target.get(), args); return; diff --git a/common/src/main/java/net/william278/huskhomes/database/Database.java b/common/src/main/java/net/william278/huskhomes/database/Database.java index 39c04096..eda76a2e 100644 --- a/common/src/main/java/net/william278/huskhomes/database/Database.java +++ b/common/src/main/java/net/william278/huskhomes/database/Database.java @@ -2,7 +2,10 @@ package net.william278.huskhomes.database; import net.william278.huskhomes.HuskHomes; import net.william278.huskhomes.config.Server; -import net.william278.huskhomes.position.*; +import net.william278.huskhomes.position.Home; +import net.william278.huskhomes.position.Position; +import net.william278.huskhomes.position.SavedPosition; +import net.william278.huskhomes.position.Warp; import net.william278.huskhomes.teleport.Teleport; import net.william278.huskhomes.user.OnlineUser; import net.william278.huskhomes.user.SavedUser; diff --git a/common/src/main/java/net/william278/huskhomes/database/SqLiteDatabase.java b/common/src/main/java/net/william278/huskhomes/database/SqLiteDatabase.java index be9b34d8..1fd50bb2 100644 --- a/common/src/main/java/net/william278/huskhomes/database/SqLiteDatabase.java +++ b/common/src/main/java/net/william278/huskhomes/database/SqLiteDatabase.java @@ -13,7 +13,10 @@ import org.sqlite.SQLiteConfig; import java.io.File; import java.io.IOException; import java.sql.*; -import java.util.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import java.util.UUID; import java.util.logging.Level; /** diff --git a/common/src/main/java/net/william278/huskhomes/hook/EconomyHook.java b/common/src/main/java/net/william278/huskhomes/hook/EconomyHook.java index 45cd4041..73155133 100644 --- a/common/src/main/java/net/william278/huskhomes/hook/EconomyHook.java +++ b/common/src/main/java/net/william278/huskhomes/hook/EconomyHook.java @@ -9,6 +9,8 @@ import org.jetbrains.annotations.NotNull; */ public abstract class EconomyHook extends Hook { + public static final String BYPASS_PERMISSION = "huskhomes.bypass_economy_checks"; + protected EconomyHook(@NotNull HuskHomes plugin, @NotNull String hookName) { super(plugin, hookName); } diff --git a/common/src/main/java/net/william278/huskhomes/listener/EventListener.java b/common/src/main/java/net/william278/huskhomes/listener/EventListener.java index 83256354..a601d315 100644 --- a/common/src/main/java/net/william278/huskhomes/listener/EventListener.java +++ b/common/src/main/java/net/william278/huskhomes/listener/EventListener.java @@ -2,12 +2,13 @@ package net.william278.huskhomes.listener; import de.themoep.minedown.adventure.MineDown; import net.william278.huskhomes.HuskHomes; +import net.william278.huskhomes.command.BackCommand; +import net.william278.huskhomes.command.Command; import net.william278.huskhomes.network.Message; import net.william278.huskhomes.network.Payload; import net.william278.huskhomes.position.Position; import net.william278.huskhomes.teleport.Teleport; import net.william278.huskhomes.user.OnlineUser; -import net.william278.huskhomes.util.Permission; import org.jetbrains.annotations.NotNull; import java.util.Optional; @@ -148,9 +149,8 @@ public class EventListener { * @param onlineUser the {@link OnlineUser} who died */ protected final void handlePlayerDeath(@NotNull OnlineUser onlineUser) { - // Set the player's last position to where they died - if (plugin.getSettings().isBackCommandReturnByDeath() - && onlineUser.hasPermission(Permission.COMMAND_BACK_RETURN_BY_DEATH.node)) { + if (plugin.getSettings().isBackCommandReturnByDeath() && plugin.getCommand(BackCommand.class) + .map(Command::getPermission).map(onlineUser::hasPermission).orElse(false)) { plugin.getDatabase().setLastPosition(onlineUser, onlineUser.getPosition()); } } @@ -163,9 +163,11 @@ public class EventListener { protected final void handlePlayerRespawn(@NotNull OnlineUser onlineUser) { plugin.runAsync(() -> { // Display the return by death via /back notification - if (plugin.getSettings().isBackCommandReturnByDeath() - && onlineUser.hasPermission(Permission.COMMAND_BACK.node) - && onlineUser.hasPermission(Permission.COMMAND_BACK_RETURN_BY_DEATH.node)) { + final boolean canReturnByDeath = plugin.getCommand(BackCommand.class) + .map(command -> onlineUser.hasPermission(command.getPermission()) + && onlineUser.hasPermission(command.getPermission("death"))) + .orElse(false); + if (plugin.getSettings().isBackCommandReturnByDeath() && canReturnByDeath) { plugin.getLocales().getLocale("return_by_death_notification") .ifPresent(onlineUser::sendMessage); } diff --git a/common/src/main/java/net/william278/huskhomes/teleport/Teleport.java b/common/src/main/java/net/william278/huskhomes/teleport/Teleport.java index 24f92d70..4a2e06c0 100644 --- a/common/src/main/java/net/william278/huskhomes/teleport/Teleport.java +++ b/common/src/main/java/net/william278/huskhomes/teleport/Teleport.java @@ -1,6 +1,7 @@ package net.william278.huskhomes.teleport; import net.william278.huskhomes.HuskHomes; +import net.william278.huskhomes.command.BackCommand; import net.william278.huskhomes.config.Settings; import net.william278.huskhomes.event.ITeleportEvent; import net.william278.huskhomes.hook.EconomyHook; @@ -22,21 +23,23 @@ public class Teleport { protected final Teleportable teleporter; protected final Target target; protected final Type type; - protected final boolean updateLastPosition; protected final List economyActions; private final boolean async; + protected final boolean updateLastPosition; protected Teleport(@NotNull OnlineUser executor, @NotNull Teleportable teleporter, @NotNull Target target, @NotNull Type type, boolean updateLastPosition, @NotNull List actions, @NotNull HuskHomes plugin) { + this.plugin = plugin; this.executor = executor; this.teleporter = teleporter; this.target = target; this.type = type; - this.updateLastPosition = updateLastPosition; this.economyActions = actions; this.async = plugin.getSettings().isAsynchronousTeleports(); - this.plugin = plugin; + this.updateLastPosition = updateLastPosition && plugin.getCommand(BackCommand.class) + .map(command -> executor.hasPermission(command.getPermission())) + .orElse(false); } @NotNull diff --git a/common/src/main/java/net/william278/huskhomes/teleport/TimedTeleport.java b/common/src/main/java/net/william278/huskhomes/teleport/TimedTeleport.java index 37866137..8a3ec721 100644 --- a/common/src/main/java/net/william278/huskhomes/teleport/TimedTeleport.java +++ b/common/src/main/java/net/william278/huskhomes/teleport/TimedTeleport.java @@ -6,7 +6,6 @@ import net.william278.huskhomes.config.Settings; import net.william278.huskhomes.hook.EconomyHook; import net.william278.huskhomes.position.Position; import net.william278.huskhomes.user.OnlineUser; -import net.william278.huskhomes.util.Permission; import org.jetbrains.annotations.NotNull; import java.util.List; @@ -14,6 +13,7 @@ import java.util.concurrent.atomic.AtomicInteger; public class TimedTeleport extends Teleport { + public static final String BYPASS_PERMISSION = "huskhomes.bypass_teleport_warmup"; private final OnlineUser teleporter; private final Position startLocation; private final double startHealth; @@ -32,7 +32,7 @@ public class TimedTeleport extends Teleport { @Override public void execute() throws TeleportationException { // Check if the teleporter can bypass warmup - if (timeLeft == 0 || teleporter.hasPermission(Permission.BYPASS_TELEPORT_WARMUP.node)) { + if (timeLeft == 0 || teleporter.hasPermission(BYPASS_PERMISSION)) { super.execute(); return; } diff --git a/common/src/main/java/net/william278/huskhomes/util/Permission.java b/common/src/main/java/net/william278/huskhomes/util/Permission.java deleted file mode 100644 index 901e424e..00000000 --- a/common/src/main/java/net/william278/huskhomes/util/Permission.java +++ /dev/null @@ -1,209 +0,0 @@ -package net.william278.huskhomes.util; - -import org.intellij.lang.annotations.Pattern; -import org.intellij.lang.annotations.Subst; -import org.jetbrains.annotations.NotNull; - -/** - * Static plugin permission nodes required to perform actions or execute commands - */ -public enum Permission { - - /* - * Bypass permission nodes - */ - - /** - * Lets the user bypass the warmup time when a player must stand still before teleportation - */ - BYPASS_TELEPORT_WARMUP("huskhomes.bypass.teleport_warmup", DefaultAccess.NOBODY), - /** - * Lets the user bypass the cooldown on the {@code /rtp} command - */ - BYPASS_RTP_COOLDOWN("huskhomes.bypass.rtp_cooldown", DefaultAccess.NOBODY), - /** - * Lets the user bypass economy costs when teleporting - */ - BYPASS_ECONOMY_CHECKS("huskhomes.bypass.economy", DefaultAccess.NOBODY), - - /* - * Command permission nodes - */ - /** - * Lets the user view the "disabled command" message for disabled commands - */ - COMMAND_DISABLED_MESSAGE("huskhomes.disabled_command_message", DefaultAccess.EVERYONE), - /** - * Lets the user teleport to their homes ({@code /home [home_name]}) - */ - COMMAND_HOME("huskhomes.command.home", DefaultAccess.EVERYONE), - /** - * Lets the user teleport to other users' homes ({@code /home [player_name.home_name]}) - */ - COMMAND_HOME_OTHER("huskhomes.command.home.other", DefaultAccess.OPERATORS), - /** - * Lets the user set a home ({@code /sethome [home_name]}) - */ - COMMAND_SET_HOME("huskhomes.command.sethome", DefaultAccess.EVERYONE), - /** - * Lets the user delete a home ({@code /delhome [home_name]}) - */ - COMMAND_DELETE_HOME("huskhomes.command.delhome", DefaultAccess.EVERYONE), - /** - * Lets the user delete other users' homes ({@code /delhome [player_name.home_name]}) - */ - COMMAND_DELETE_HOME_OTHER("huskhomes.command.delhome.other", DefaultAccess.OPERATORS), - /** - * Lets the user edit their homes ({@code /edithome [home_name]}) - */ - COMMAND_EDIT_HOME("huskhomes.command.edithome", DefaultAccess.EVERYONE), - /** - * Lets the user edit other users' homes ({@code /edithome [player_name.home_name]}) - */ - COMMAND_EDIT_HOME_OTHER("huskhomes.command.edithome.other", DefaultAccess.OPERATORS), - /** - * Lets the user edit the privacy of their home ({@code /edithome [home_name] [public/private]}) - */ - COMMAND_EDIT_HOME_PRIVACY("huskhomes.command.edithome.privacy", DefaultAccess.EVERYONE), - /** - * Lets the user teleport to a public home ({@code /phome [player_name.home_name]}) - */ - COMMAND_PUBLIC_HOME("huskhomes.command.phome", DefaultAccess.EVERYONE), - /** - * Lets the user teleport to a warp ({@code /warp [warp_name]}) - */ - COMMAND_WARP("huskhomes.command.warp", DefaultAccess.EVERYONE), - /** - * Lets the user set a warp ({@code /setwarp [warp_name]}) - */ - COMMAND_SET_WARP("huskhomes.command.setwarp", DefaultAccess.OPERATORS), - /** - * Lets the user delete a warp ({@code /delwarp [warp_name]}) - */ - COMMAND_DELETE_WARP("huskhomes.command.delwarp", DefaultAccess.OPERATORS), - /** - * Lets the user edit a warp ({@code /editwarp [warp_name]}) - */ - COMMAND_EDIT_WARP("huskhomes.command.editwarp", DefaultAccess.OPERATORS), - /** - * Lets the user instantly tp to another player ({@code /tp [player_name]}) - */ - COMMAND_TP("huskhomes.command.tp", DefaultAccess.OPERATORS), - /** - * Lets the user instantly tp to a set of coordinates ({@code /tp [x] [y] [z] [world] [server]}) - */ - COMMAND_TP_TO_COORDINATES("huskhomes.command.tp.coordinates", DefaultAccess.OPERATORS), - /** - * Lets the user instantly tp another user to a player (and, if they have the {@link Permission#COMMAND_TP_TO_COORDINATES} - * permission, to a set of coordinates) ({@code /tp [player_to_teleport] [target]}) - */ - COMMAND_TP_OTHER("huskhomes.command.tp.other", DefaultAccess.OPERATORS), - /** - * Lets the user instantly tp another player to them ({@code /tphere [player_name]}) - */ - COMMAND_TPHERE("huskhomes.command.tphere", DefaultAccess.OPERATORS), - /** - * Lets the user request to tp to another player ({@code /tpa [player_name]}) - */ - COMMAND_TPA("huskhomes.command.tpa", DefaultAccess.EVERYONE), - /** - * Lets the user request another player to tp to them ({@code /tpahere [player_name]}) - */ - COMMAND_TPAHERE("huskhomes.command.tpahere", DefaultAccess.EVERYONE), - /** - * Lets the user accept a tp request ({@code /tpaccept}) - */ - COMMAND_TPACCEPT("huskhomes.command.tpaccept", DefaultAccess.EVERYONE), - /** - * Lets the user deny a tp request ({@code /tpdeny}) - */ - COMMAND_TPDECLINE("huskhomes.command.tpdecline", DefaultAccess.EVERYONE), - /** - * Lets the user ignore incoming tp requests ({@code /tpignore}) - */ - COMMAND_TPIGNORE("huskhomes.command.tpignore", DefaultAccess.EVERYONE), - /** - * Lets the user tp to where a user logged out ({@code /tpoffline [player_name]}) - */ - COMMAND_TPOFFLINE("huskhomes.command.tpoffline", DefaultAccess.OPERATORS), - /** - * Lets the user teleport everyone to their position ({@code /tpall}) - */ - COMMAND_TPALL("huskhomes.command.tpall", DefaultAccess.OPERATORS), - /** - * Lets the user send a teleport request asking everyone to teleport to them ({@code /tpaall}) - */ - COMMAND_TPA_ALL("huskhomes.command.tpaall", DefaultAccess.OPERATORS), - /** - * Lets the user randomly teleport in the world they are in ({@code /rtp}) - */ - COMMAND_RTP("huskhomes.command.rtp", DefaultAccess.EVERYONE), - COMMAND_RTP_OTHER("huskhomes.command.rtp.other", DefaultAccess.OPERATORS), - /** - * Lets the user teleport to the defined spawn position ({@code /spawn}) - */ - COMMAND_SPAWN("huskhomes.command.spawn", DefaultAccess.EVERYONE), - /** - * Lets the user set the spawn position ({@code /setspawn}) - */ - COMMAND_SET_SPAWN("huskhomes.command.setspawn", DefaultAccess.OPERATORS), - /** - * Lets the user return to where they last teleported from ({@code /back}) - */ - COMMAND_BACK("huskhomes.command.back", DefaultAccess.EVERYONE), - /** - * Lets the user use {@code /back} to return to where they died - */ - COMMAND_BACK_RETURN_BY_DEATH("huskhomes.command.back.death", DefaultAccess.EVERYONE), - /** - * Lets the user access /huskhomes subcommands - */ - COMMAND_HUSKHOMES("huskhomes.command.huskhomes", DefaultAccess.EVERYONE), - /** - * Lets the user view the command list - */ - COMMAND_HUSKHOMES_HELP("huskhomes.command.huskhomes.help", DefaultAccess.EVERYONE), - /** - * Lets the user view plugin information - */ - COMMAND_HUSKHOMES_ABOUT("huskhomes.command.huskhomes.about", DefaultAccess.EVERYONE), - /** - * Lets the user reload the plugin config and message files - */ - COMMAND_HUSKHOMES_RELOAD("huskhomes.command.huskhomes.reload", DefaultAccess.OPERATORS), - /** - * Lets the user check for plugin updates - */ - COMMAND_HUSKHOMES_UPDATE("huskhomes.command.huskhomes.update", DefaultAccess.OPERATORS); - - public static final String PERMISSION_PATTERN = "(huskhomes\\.)?[a-z0-9_\\-*.]+"; - - @Pattern(Permission.PERMISSION_PATTERN) - @NotNull - public final String node; - @NotNull - public final DefaultAccess defaultAccess; - - Permission(@Subst("huskhomes.*") @NotNull String node, @NotNull DefaultAccess defaultAccess) { - this.node = node; - this.defaultAccess = defaultAccess; - } - - /** - * Identifies who gets what permissions by default - */ - public enum DefaultAccess { - /** - * Everyone gets this permission node by default - */ - EVERYONE, - /** - * Nobody gets this permission node by default - */ - NOBODY, - /** - * Server operators ({@code /op}) get this permission node by default - */ - OPERATORS - } -} diff --git a/common/src/test/java/net/william278/huskhomes/config/LocalesTests.java b/common/src/test/java/net/william278/huskhomes/config/LocalesTests.java index b80c3260..87436770 100644 --- a/common/src/test/java/net/william278/huskhomes/config/LocalesTests.java +++ b/common/src/test/java/net/william278/huskhomes/config/LocalesTests.java @@ -2,7 +2,10 @@ package net.william278.huskhomes.config; import net.william278.annotaml.Annotaml; import org.jetbrains.annotations.NotNull; -import org.junit.jupiter.api.*; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource;