fabric: tweak perm defaults, #require() perms for aliases

This commit is contained in:
William committed 2023-04-13 20:16:41 +01:00
1 parent 4fddd1e8dc
commit fd3697d49d
3 files changed
+13 -7

No files matched your search

@@ -158,8 +158,10 @@ public abstract class OnlineUser extends User implements Teleportable, CommandUs
public final void playSound(@Subst(Key.MINECRAFT_NAMESPACE + "block.note_block.banjo")
@NotNull String soundEffect) throws IllegalArgumentException {
try {
getAudience().playSound(Sound.sound(Key.key(soundEffect), Sound.Source.PLAYER,
1.0f, 1.0f), Sound.Emitter.self());
getAudience().playSound(
Sound.sound(Key.key(soundEffect), Sound.Source.PLAYER, 1.0f, 1.0f),
Sound.Emitter.self()
);
} catch (InvalidKeyException e) {
throw new IllegalArgumentException("Invalid sound effect name: " + soundEffect);
}
@@ -34,6 +34,7 @@ import net.william278.huskhomes.user.FabricUser;
import org.jetbrains.annotations.NotNull;
import java.util.Map;
import java.util.function.Predicate;
import static com.mojang.brigadier.arguments.StringArgumentType.greedyString;
import static net.minecraft.server.command.CommandManager.argument;
@@ -51,9 +52,10 @@ public class FabricCommand {
public void register(@NotNull CommandDispatcher<ServerCommandSource> dispatcher) {
// Register brigadier command
final Predicate<ServerCommandSource> predicate = Permissions
.require(command.getPermission(), command.isOperatorCommand() ? 3 : 0);
final LiteralArgumentBuilder<ServerCommandSource> builder = literal(command.getName())
.requires(Permissions.require(command.getPermission(), command.isOperatorCommand() ? 3 : 0))
.executes(getBrigadierExecutor());
.requires(predicate).executes(getBrigadierExecutor());
plugin.getPermissions().put(command.getPermission(), command.isOperatorCommand());
if (!command.getRawUsage().isBlank()) {
builder.then(argument(command.getRawUsage().replaceAll("[<>\\[\\]]", ""), greedyString())
@@ -73,8 +75,10 @@ public class FabricCommand {
// Register aliases
final LiteralCommandNode<ServerCommandSource> node = dispatcher.register(builder);
dispatcher.register(literal("huskhomes:" + command.getName()).executes(getBrigadierExecutor()).redirect(node));
command.getAliases().forEach(alias -> dispatcher.register(literal(alias).executes(getBrigadierExecutor()).redirect(node)));
dispatcher.register(literal("huskhomes:" + command.getName()).executes(getBrigadierExecutor())
.requires(predicate).redirect(node));
command.getAliases().forEach(alias -> dispatcher.register(literal(alias).executes(getBrigadierExecutor())
.requires(predicate).redirect(node)));
}
private com.mojang.brigadier.Command<ServerCommandSource> getBrigadierExecutor() {
@@ -90,7 +90,7 @@ public class FabricUser extends OnlineUser {
@Override
public boolean hasPermission(@NotNull String node) {
final boolean requiresOp = Boolean.TRUE.equals(plugin.getPermissions().computeIfPresent(node, (key, isOp) -> isOp));
final boolean requiresOp = Boolean.TRUE.equals(plugin.getPermissions().getOrDefault(node, true));
return Permissions.check(player, node, !requiresOp || player.hasPermissionLevel(3));
}