diff --git a/bukkit/src/main/java/net/william278/uniform/bukkit/BukkitCommand.java b/bukkit/src/main/java/net/william278/uniform/bukkit/BukkitCommand.java index 57c5b48..b014cd4 100644 --- a/bukkit/src/main/java/net/william278/uniform/bukkit/BukkitCommand.java +++ b/bukkit/src/main/java/net/william278/uniform/bukkit/BukkitCommand.java @@ -30,10 +30,12 @@ import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import net.william278.uniform.BaseCommand; import net.william278.uniform.Command; +import net.william278.uniform.Permission; import net.william278.uniform.Uniform; import org.bukkit.command.CommandException; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.List; @@ -41,9 +43,11 @@ import java.util.List; public class BukkitCommand extends BaseCommand { private BukkitAudiences audiences; + private @Nullable Permission permission; public BukkitCommand(@NotNull Command command) { super(command); + this.permission = command.getPermission().orElse(null); } public BukkitCommand(@NotNull String name, @NotNull String description, @NotNull List aliases) { @@ -64,12 +68,19 @@ public class BukkitCommand extends BaseCommand { private static final int COMMAND_SUCCESS = com.mojang.brigadier.Command.SINGLE_SUCCESS; private final CommandDispatcher dispatcher = new CommandDispatcher<>(); + private final @Nullable Permission permission; public Impl(@NotNull Uniform uniform, @NotNull BukkitCommand command) { super(command.getName()); this.dispatcher.register(command.createBuilder()); + this.permission = command.permission; + + // Setup command properties this.setDescription(command.getDescription()); this.setAliases(command.getAliases()); + if (permission != null) { + this.setPermission(permission.node()); + } } @SuppressWarnings("deprecation") @@ -105,6 +116,14 @@ public class BukkitCommand extends BaseCommand { .join(); } + @Override + public boolean testPermissionSilent(@NotNull CommandSender target) { + if (permission == null || permission.node().isBlank()) { + return true; + } + return new BukkitCommandUser(target).checkPermission(permission); + } + @NotNull private Audience getAudience(@NotNull CommandSender sender) { return BukkitUniform.getAudiences().sender(sender); diff --git a/common/src/main/java/net/william278/uniform/BaseCommand.java b/common/src/main/java/net/william278/uniform/BaseCommand.java index 0254655..14ceae5 100644 --- a/common/src/main/java/net/william278/uniform/BaseCommand.java +++ b/common/src/main/java/net/william278/uniform/BaseCommand.java @@ -79,16 +79,16 @@ public abstract class BaseCommand { this.condition = condition; } - public final void setPermission(@NotNull Permission permission) { + public void setPermission(@NotNull Permission permission) { this.setCondition(this.createPermission(permission)); } public final void setPermission(@NotNull String permission) { - this.setCondition(this.createPermission(new Permission(permission))); + this.setPermission(new Permission(permission)); } public final void setPermission(@NotNull String permission, @NotNull Permission.Default permissionDefault) { - this.setCondition(this.createPermission(new Permission(permission, permissionDefault))); + this.setPermission(new Permission(permission, permissionDefault)); } public final void setDefaultExecutor(@NotNull CommandExecutor executor) { diff --git a/example-plugin/build.gradle b/example-plugin/build.gradle index 624e554..dca4d45 100644 --- a/example-plugin/build.gradle +++ b/example-plugin/build.gradle @@ -11,6 +11,10 @@ dependencies { tasks { runServer { - minecraftVersion("1.20.6") + minecraftVersion("1.20.4") + + downloadPlugins { + url('https://download.luckperms.net/1549/bukkit/loader/LuckPerms-Bukkit-5.4.134.jar') + } } } \ No newline at end of file diff --git a/example-plugin/src/main/java/net/william278/uniform/ExampleCommand.java b/example-plugin/src/main/java/net/william278/uniform/ExampleCommand.java index 3278479..fa80a75 100644 --- a/example-plugin/src/main/java/net/william278/uniform/ExampleCommand.java +++ b/example-plugin/src/main/java/net/william278/uniform/ExampleCommand.java @@ -38,6 +38,7 @@ public class ExampleCommand extends Command { super("example"); setDescription("An example command for Uniform"); setAliases(List.of("helloworld")); + setPermission(Permission.defaultIfOp("uniform.example")); } @Override diff --git a/gradle.properties b/gradle.properties index eb2e130..8c6a95c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,6 +3,6 @@ javaVersion=17 org.gradle.jvmargs='-Dfile.encoding=UTF-8' org.gradle.daemon=true -library_version=1.1.5 +library_version=1.1.6 library_archive=uniform library_description=Cross-platform wrapper for making Brigadier commands, based on BrigadierWrapper by Tofaa2, itself inspired by emortalmcs command system. \ No newline at end of file diff --git a/paper/src/main/java/net/william278/uniform/paper/LegacyPaperCommand.java b/paper/src/main/java/net/william278/uniform/paper/LegacyPaperCommand.java index 6b31e00..d39f55c 100644 --- a/paper/src/main/java/net/william278/uniform/paper/LegacyPaperCommand.java +++ b/paper/src/main/java/net/william278/uniform/paper/LegacyPaperCommand.java @@ -26,13 +26,11 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.suggestion.Suggestion; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; -import net.william278.uniform.BaseCommand; -import net.william278.uniform.Command; -import net.william278.uniform.CommandUser; -import net.william278.uniform.Uniform; +import net.william278.uniform.*; import org.bukkit.command.CommandException; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.List; import java.util.function.Function; @@ -40,12 +38,15 @@ import java.util.function.Function; @SuppressWarnings("unused") public class LegacyPaperCommand extends BaseCommand { + private @Nullable Permission permission; + static final Function USER_SUPPLIER = (user) -> new LegacyPaperCommandUser( (CommandSender) user ); public LegacyPaperCommand(@NotNull Command command) { super(command); + this.permission = command.getPermission().orElse(null); } public LegacyPaperCommand(@NotNull String name, @NotNull String description, @NotNull List aliases) { @@ -61,17 +62,30 @@ public class LegacyPaperCommand extends BaseCommand { return new Impl(uniform, this); } + @Override + public void setPermission(@NotNull Permission permission) { + this.permission = permission; + super.setPermission(permission); + } + static final class Impl extends org.bukkit.command.Command { private static final int COMMAND_SUCCESS = com.mojang.brigadier.Command.SINGLE_SUCCESS; private final CommandDispatcher dispatcher = new CommandDispatcher<>(); + private final @Nullable Permission permission; public Impl(@NotNull Uniform uniform, @NotNull LegacyPaperCommand command) { super(command.getName()); this.dispatcher.register(command.createBuilder()); + this.permission = command.permission; + + // Setup command properties this.setDescription(command.getDescription()); this.setAliases(command.getAliases()); + if (permission != null) { + this.setPermission(permission.node()); + } } @SuppressWarnings("deprecation") @@ -107,6 +121,14 @@ public class LegacyPaperCommand extends BaseCommand { .join(); } + @Override + public boolean testPermissionSilent(@NotNull CommandSender target) { + if (permission == null || permission.node().isBlank()) { + return true; + } + return new LegacyPaperCommandUser(target).checkPermission(permission); + } + @NotNull private String getInput(@NotNull String[] args) { return args.length == 0 ? getName() : "%s %s".formatted(getName(), String.join(" ", args));