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.kyori.adventure.text.format.NamedTextColor;
import net.william278.uniform.BaseCommand; import net.william278.uniform.BaseCommand;
import net.william278.uniform.Command; import net.william278.uniform.Command;
import net.william278.uniform.Permission;
import net.william278.uniform.Uniform; import net.william278.uniform.Uniform;
import org.bukkit.command.CommandException; import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List; import java.util.List;
@ -41,9 +43,11 @@ import java.util.List;
public class BukkitCommand extends BaseCommand<CommandSender> { public class BukkitCommand extends BaseCommand<CommandSender> {
private BukkitAudiences audiences; private BukkitAudiences audiences;
private @Nullable Permission permission;
public BukkitCommand(@NotNull Command command) { public BukkitCommand(@NotNull Command command) {
super(command); super(command);
this.permission = command.getPermission().orElse(null);
} }
public BukkitCommand(@NotNull String name, @NotNull String description, @NotNull List<String> aliases) { 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 static final int COMMAND_SUCCESS = com.mojang.brigadier.Command.SINGLE_SUCCESS;
private final CommandDispatcher<CommandSender> dispatcher = new CommandDispatcher<>(); private final CommandDispatcher<CommandSender> dispatcher = new CommandDispatcher<>();
private final @Nullable Permission permission;
public Impl(@NotNull Uniform uniform, @NotNull BukkitCommand command) { public Impl(@NotNull Uniform uniform, @NotNull BukkitCommand command) {
super(command.getName()); super(command.getName());
this.dispatcher.register(command.createBuilder()); this.dispatcher.register(command.createBuilder());
this.permission = command.permission;
// Setup command properties
this.setDescription(command.getDescription()); this.setDescription(command.getDescription());
this.setAliases(command.getAliases()); this.setAliases(command.getAliases());
if (permission != null) {
this.setPermission(permission.node());
}
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@ -105,6 +116,14 @@ public class BukkitCommand extends BaseCommand<CommandSender> {
.join(); .join();
} }
@Override
public boolean testPermissionSilent(@NotNull CommandSender target) {
if (permission == null || permission.node().isBlank()) {
return true;
}
return new BukkitCommandUser(target).checkPermission(permission);
}
@NotNull @NotNull
private Audience getAudience(@NotNull CommandSender sender) { private Audience getAudience(@NotNull CommandSender sender) {
return BukkitUniform.getAudiences().sender(sender); return BukkitUniform.getAudiences().sender(sender);

@ -79,16 +79,16 @@ public abstract class BaseCommand<S> {
this.condition = condition; this.condition = condition;
} }
public final void setPermission(@NotNull Permission permission) { public void setPermission(@NotNull Permission permission) {
this.setCondition(this.createPermission(permission)); this.setCondition(this.createPermission(permission));
} }
public final void setPermission(@NotNull String 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) { 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) { public final void setDefaultExecutor(@NotNull CommandExecutor<S> executor) {

@ -11,6 +11,10 @@ dependencies {
tasks { tasks {
runServer { 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"); super("example");
setDescription("An example command for Uniform"); setDescription("An example command for Uniform");
setAliases(List.of("helloworld")); setAliases(List.of("helloworld"));
setPermission(Permission.defaultIfOp("uniform.example"));
} }
@Override @Override

@ -3,6 +3,6 @@ javaVersion=17
org.gradle.jvmargs='-Dfile.encoding=UTF-8' org.gradle.jvmargs='-Dfile.encoding=UTF-8'
org.gradle.daemon=true org.gradle.daemon=true
library_version=1.1.5 library_version=1.1.6
library_archive=uniform library_archive=uniform
library_description=Cross-platform wrapper for making Brigadier commands, based on BrigadierWrapper by Tofaa2, itself inspired by emortalmcs command system. 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 com.mojang.brigadier.suggestion.Suggestion;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
import net.william278.uniform.BaseCommand; import net.william278.uniform.*;
import net.william278.uniform.Command;
import net.william278.uniform.CommandUser;
import net.william278.uniform.Uniform;
import org.bukkit.command.CommandException; import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List; import java.util.List;
import java.util.function.Function; import java.util.function.Function;
@ -40,12 +38,15 @@ import java.util.function.Function;
@SuppressWarnings("unused") @SuppressWarnings("unused")
public class LegacyPaperCommand extends BaseCommand<CommandSender> { public class LegacyPaperCommand extends BaseCommand<CommandSender> {
private @Nullable Permission permission;
static final Function<Object, CommandUser> USER_SUPPLIER = (user) -> new LegacyPaperCommandUser( static final Function<Object, CommandUser> USER_SUPPLIER = (user) -> new LegacyPaperCommandUser(
(CommandSender) user (CommandSender) user
); );
public LegacyPaperCommand(@NotNull Command command) { public LegacyPaperCommand(@NotNull Command command) {
super(command); super(command);
this.permission = command.getPermission().orElse(null);
} }
public LegacyPaperCommand(@NotNull String name, @NotNull String description, @NotNull List<String> aliases) { 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); 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 { static final class Impl extends org.bukkit.command.Command {
private static final int COMMAND_SUCCESS = com.mojang.brigadier.Command.SINGLE_SUCCESS; private static final int COMMAND_SUCCESS = com.mojang.brigadier.Command.SINGLE_SUCCESS;
private final CommandDispatcher<CommandSender> dispatcher = new CommandDispatcher<>(); private final CommandDispatcher<CommandSender> dispatcher = new CommandDispatcher<>();
private final @Nullable Permission permission;
public Impl(@NotNull Uniform uniform, @NotNull LegacyPaperCommand command) { public Impl(@NotNull Uniform uniform, @NotNull LegacyPaperCommand command) {
super(command.getName()); super(command.getName());
this.dispatcher.register(command.createBuilder()); this.dispatcher.register(command.createBuilder());
this.permission = command.permission;
// Setup command properties
this.setDescription(command.getDescription()); this.setDescription(command.getDescription());
this.setAliases(command.getAliases()); this.setAliases(command.getAliases());
if (permission != null) {
this.setPermission(permission.node());
}
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@ -107,6 +121,14 @@ public class LegacyPaperCommand extends BaseCommand<CommandSender> {
.join(); .join();
} }
@Override
public boolean testPermissionSilent(@NotNull CommandSender target) {
if (permission == null || permission.node().isBlank()) {
return true;
}
return new LegacyPaperCommandUser(target).checkPermission(permission);
}
@NotNull @NotNull
private String getInput(@NotNull String[] args) { private String getInput(@NotNull String[] args) {
return args.length == 0 ? getName() : "%s %s".formatted(getName(), String.join(" ", args)); return args.length == 0 ? getName() : "%s %s".formatted(getName(), String.join(" ", args));

Loading…
Cancel
Save