fix: problems with permissions on Bukkit/legacy Paper

dependabot/gradle/org.projectlombok-lombok-1.18.34 1.1.6
William 5 months ago
parent d399788b9f
commit d1b946f14a
No known key found for this signature in database

@ -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<CommandSender> {
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<String> aliases) {
@ -64,12 +68,19 @@ public class BukkitCommand extends BaseCommand<CommandSender> {
private static final int COMMAND_SUCCESS = com.mojang.brigadier.Command.SINGLE_SUCCESS;
private final CommandDispatcher<CommandSender> 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<CommandSender> {
.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);

@ -79,16 +79,16 @@ public abstract class BaseCommand<S> {
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<S> executor) {

@ -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')
}
}
}

@ -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

@ -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.

@ -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<CommandSender> {
private @Nullable Permission permission;
static final Function<Object, CommandUser> 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<String> aliases) {
@ -61,17 +62,30 @@ public class LegacyPaperCommand extends BaseCommand<CommandSender> {
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<CommandSender> 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<CommandSender> {
.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));

Loading…
Cancel
Save