Skip to content

Commit

Permalink
minecraft: Update to cloud 1.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
zml2008 committed Jan 18, 2021
1 parent b418ab8 commit a65c81a
Show file tree
Hide file tree
Showing 23 changed files with 80 additions and 568 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ adventurePlatformVersion=4.0.0-SNAPSHOT
antlrVersion=4.9.1
autoServiceVersion=1.0-rc7
checkerVersion=3.9.1
cloudVersion=1.3.0
cloudVersion=1.4.0
configurateVersion=4.0.0
errorproneVersion=2.5.1
immutablesVersion=2.8.8
Expand Down
2 changes: 1 addition & 1 deletion impl-blocks/minecraft/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ dependencies {
compileOnlyApi("org.immutables:gson:$immutablesVersion")
runtimeOnly(project(":datastore:sql"))
api("cloud.commandframework:cloud-core:$cloudVersion")
implementation("cloud.commandframework:cloud-minecraft-extras:$cloudVersion")
api("cloud.commandframework:cloud-minecraft-extras:$cloudVersion")
compileOnly("cloud.commandframework:cloud-brigadier:$cloudVersion")
compileOnly("com.mojang:brigadier:1.0.17")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
package ca.stellardrift.permissionsex.minecraft.command;

import ca.stellardrift.permissionsex.subject.SubjectRef;
import cloud.commandframework.keys.CloudKey;
import cloud.commandframework.keys.SimpleCloudKey;
import cloud.commandframework.permission.CommandPermission;
import cloud.commandframework.permission.PredicatePermission;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
Expand All @@ -36,7 +39,7 @@
* [default] is the value to resolve this permission to when unset
*/
@Value.Immutable(builder = false)
public abstract class Permission implements CommandPermission {
public abstract class Permission implements PredicatePermission<Commander> {

public static Permission of(final String permission) {
return of(permission, Component.empty(), 0);
Expand Down Expand Up @@ -99,6 +102,16 @@ public final Permission then(final String other) {
return this.value(this.value() + '.' + other);
}

@Override
public final @NonNull CloudKey<Void> getKey() {
return SimpleCloudKey.of(this.value());
}

@Override
public final boolean hasPermission(final Commander sender) {
return sender.hasPermission(this);
}

@Override
public final @NonNull Collection<@NonNull CommandPermission> getPermissions() {
return Collections.singleton(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import ca.stellardrift.permissionsex.subject.SubjectRef;
import ca.stellardrift.permissionsex.util.TranslatableProvider;
import cloud.commandframework.Command;
import cloud.commandframework.meta.CommandMeta;
import cloud.commandframework.minecraft.extras.MinecraftExtrasMetaKeys;
import net.kyori.adventure.text.BuildableComponent;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.ComponentBuilder;
Expand All @@ -54,7 +54,7 @@ static Command.Builder<Commander> register(final Command.Builder<Commander> buil
final Permission perm = Permission.pex("info");
return builder
.permission(perm)
.meta(CommandMeta.DESCRIPTION, Messages.INFO_DESCRIPTION.key()) // TODO
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, Messages.INFO_DESCRIPTION.tr()) // TODO
.handler(handler((source, engine, ctx) -> {
final CalculatedSubject subject = subjectProvider.provideCalculated(ctx, perm);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
import ca.stellardrift.permissionsex.minecraft.command.Permission;
import ca.stellardrift.permissionsex.subject.SubjectRef;
import cloud.commandframework.Command;
import cloud.commandframework.Description;
import cloud.commandframework.arguments.CommandArgument;
import cloud.commandframework.arguments.standard.StringArgument;
import cloud.commandframework.minecraft.extras.RichDescription;
import org.checkerframework.checker.nullness.qual.Nullable;

import java.util.ArrayList;
Expand All @@ -43,11 +43,12 @@ static Command.Builder<Commander> register(final Command.Builder<Commander> buil
final CommandArgument<Commander, String> optionArg = StringArgument.<Commander>newBuilder("option").single()
.withSuggestionsProvider(engineCompletions((engine, input) -> new ArrayList<>(((PermissionsEx<?>) engine).getRecordingNotifier().getKnownOptions())))
.build();
// TODO: Use custom parser that stops at a word starting with `-` (start of flags)
final CommandArgument<Commander, String> optionValueArg = StringArgument.optional("value", StringArgument.StringMode.GREEDY);

return builder
.permission(permission)
.argument(optionArg, Description.of("any option, suggesting from those that have already been checked"))
.argument(optionArg, RichDescription.of(Messages.OPTION_ARG_OPTION_DESCRIPTION))
.argument(optionValueArg)
.handler(ctx -> {
final SubjectRef.ToData<?> subject = subjectProvider.provideData(ctx, permission);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import cloud.commandframework.arguments.flags.CommandFlag;
import cloud.commandframework.arguments.standard.StringArgument;
import cloud.commandframework.meta.CommandMeta;
import cloud.commandframework.minecraft.extras.MinecraftExtrasMetaKeys;
import cloud.commandframework.minecraft.extras.MinecraftHelp;
import io.leangen.geantyref.TypeToken;
import net.kyori.adventure.text.Component;
Expand All @@ -47,7 +48,6 @@

import java.util.Locale;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static ca.stellardrift.permissionsex.minecraft.command.Elements.*;
Expand Down Expand Up @@ -133,7 +133,7 @@ public static void register(final CommandRegistrationContext regCtx) {
private static Command.Builder<Commander> help(final Command.Builder<Commander> base, final CommandManager<Commander> mgr, final MessageFormatter formatter) {
final CommandArgument<Commander, String> query = StringArgument.optional("query", StringArgument.StringMode.GREEDY);
final Command.Builder<Commander> helpCommand = base
.meta(CommandMeta.DESCRIPTION, "Get help for PermissionsEx")
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, Messages.PEX_HELP_DESCRIPTION.tr())
.argument(query)
.permission(Permission.pex("help"));

Expand Down Expand Up @@ -196,7 +196,7 @@ private static Command.Builder<Commander> commandImport(final Command.Builder<Co
.build();

return base
.meta(CommandMeta.DESCRIPTION, "Import data from another store")
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, Messages.PEX_IMPORT_DESCRIPTION.tr())
.argument(dataStoreArg)
.permission(Permission.pex("import"))
.handler(ctx -> {
Expand Down Expand Up @@ -242,7 +242,7 @@ private static Command.Builder<Commander> commandImport(final Command.Builder<Co

private static Command.Builder<Commander> reload(final Command.Builder<Commander> base) {
return base
.meta(CommandMeta.DESCRIPTION, "Reload PermissionsEx")
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, Messages.RELOAD_DESCRIPTION.tr())
.permission(Permission.pex("reload"))
.handler(ctx -> {
ctx.getSender().sendMessage(Messages.RELOAD_ACTION_BEGIN.tr());
Expand All @@ -254,7 +254,7 @@ private static Command.Builder<Commander> reload(final Command.Builder<Commander
private static Command.Builder<Commander> version(final Command.Builder<Commander> base) {
final CommandFlag<Void> verboseFlag = CommandFlag.newBuilder("verbose").withAliases("v").build();
return base
.meta(CommandMeta.DESCRIPTION, "Get details about the currently running PermissionsEx version")
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, Messages.VERSION_DESCRIPTION.tr())
.permission(Permission.pex("version"))
.flag(verboseFlag)
.handler(ctx -> {
Expand All @@ -268,7 +268,7 @@ private static Command.Builder<Commander> list(final Command.Builder<Commander>
final CommandArgument<Commander, String> filterArg = StringArgument.optional("filter");
final Permission basePerm = Permission.pex("list");
return base
.meta(CommandMeta.DESCRIPTION, "List all subjects of a certain type")
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, Messages.PEX_LIST_DESCRIPTION.tr())
// .permission(basePerm) // TODO: Allow prefix permissions
.argument(filterArg)
.flag(Elements.FLAG_TRANSIENT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import cloud.commandframework.Command;
import cloud.commandframework.arguments.CommandArgument;
import cloud.commandframework.arguments.standard.StringArgument;
import cloud.commandframework.meta.CommandMeta;
import cloud.commandframework.minecraft.extras.MinecraftExtrasMetaKeys;

import java.util.ArrayList;
import java.util.Set;
Expand All @@ -54,7 +54,7 @@ static Command.Builder<Commander> permission(final Command.Builder<Commander> bu
final CommandArgument<Commander, Integer> permissionValueArg = permissionValueArgument();

return builder
.meta(CommandMeta.DESCRIPTION, "Set a permission for a subject")
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, Messages.PERMISSION_DESCRIPTION.tr())
.argument(permissionArg)
.argument(permissionValueArg)
.permission(cmdPerm)
Expand All @@ -77,7 +77,7 @@ static Command.Builder<Commander> permissionDefault(final Command.Builder<Comman
final Permission cmdPerm = Permission.pex("permission.set-default");
final CommandArgument<Commander, Integer> permissionValueArg = permissionValueArgument();
return builder
.meta(CommandMeta.DESCRIPTION, "Set the fallback permission for a subject")
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, Messages.PERMISSION_DEFAULT_DESCRIPTION.tr())
.argument(permissionValueArg)
.permission(cmdPerm)
.handler(ctx -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import cloud.commandframework.arguments.flags.CommandFlag;
import cloud.commandframework.arguments.standard.IntegerArgument;
import cloud.commandframework.meta.CommandMeta;
import cloud.commandframework.minecraft.extras.MinecraftExtrasMetaKeys;
import cloud.commandframework.minecraft.extras.RichDescription;
import io.leangen.geantyref.TypeToken;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.Nullable;
Expand Down Expand Up @@ -63,7 +65,7 @@ private static CommandArgument<Commander, RankLadder> ladderArgument(final boole

// Only for subcommands that modify
private static final CommandFlag<Void> FLAG_RELATIVE = CommandFlag.newBuilder("relative")
.withDescription(Description.of("Whether the <index> argument should be relative to the current position of the rank"))
.withDescription(RichDescription.of(Messages.RANK_ARG_RELATIVE_DESCRIPTION))
.withAliases("r")
.build();

Expand All @@ -72,7 +74,7 @@ private RankingCommands() {

static void register(final CommandRegistrationContext ctx) {
// ctx.register(RankingCommands::list, "")
ctx.push(ctx.head().argument(LADDER_ARG, Description.of("the rank ladder to work on")), child -> {
ctx.push(ctx.head().argument(LADDER_ARG, RichDescription.of(Messages.RANK_ARG_LADDER_DESCRIPTION)), child -> {
ctx.register(list(ctx.head()));
ctx.register(RankingCommands::add, "add", "+");
ctx.register(RankingCommands::remove, "remove", "rem", "delete", "del", "-");
Expand All @@ -82,7 +84,7 @@ static void register(final CommandRegistrationContext ctx) {
static Command.Builder<Commander> list(final Command.Builder<Commander> builder) {
final Permission listPerm = Permission.pex("ranking.list");
return builder
.meta(CommandMeta.DESCRIPTION, "List information about existing rank ladders")
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, Messages.RANK_LIST_DESCRIPTION.tr())
.permission(listPerm)
.handler(ctx -> {
final Commander source = ctx.getSender();
Expand Down Expand Up @@ -212,7 +214,7 @@ static Command.Builder<Commander> add(final Command.Builder<Commander> builder)
.argument(rankIdentifierArg)
.argument(positionArg)
.permission(perm)
.meta(CommandMeta.DESCRIPTION, "Add a rank to a ladder")
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, Messages.RANK_ADD_DESCRIPTION.tr())
.handler(handler((source, engine, ctx) -> {
final RankLadder ladder = ctx.get(LADDER_ARG);
source.checkPermission(perm.then(ladder.name()));
Expand Down Expand Up @@ -255,7 +257,7 @@ static Command.Builder<Commander> remove(final Command.Builder<Commander> builde
.argument(rankTypeArg)
.argument(rankIdentifierArg)
.permission(perm)
.meta(CommandMeta.DESCRIPTION, "Remove a rank from a ladder")
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, Messages.RANK_REMOVE_DESCRIPTION.tr())
.handler(handler((source, engine, ctx) -> {
final RankLadder ladder = ctx.get(LADDER_ARG);
source.checkPermission(perm.then(ladder.name()));
Expand Down Expand Up @@ -290,7 +292,7 @@ public static Command.Builder<Commander> promote(final Command.Builder<Commander
.argument(rankTypeArg)
.argument(rankIdentifierArg)
.argument(ladderArg)
.meta(CommandMeta.DESCRIPTION, "Promote a subject along a rank ladder")
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, Messages.RANK_PROMOTE_DESCRIPTION.tr())
.permission(promote)
.handler(handler((source, engine, ctx) -> {
final RankLadder ladder = ctx.get(ladderArg);
Expand Down Expand Up @@ -324,7 +326,7 @@ public static Command.Builder<Commander> demote(final Command.Builder<Commander>
.argument(rankTypeArg)
.argument(rankIdentifierArg)
.argument(ladderArg)
.meta(CommandMeta.DESCRIPTION, "Demote a subject along a rank ladder")
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, Messages.RANK_DEMOTE_DESCRIPTION.tr())
.permission(promote)
.handler(handler((source, engine, ctx) -> {
final RankLadder ladder = ctx.get(ladderArg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ pex.description=Commands for PermissionsEx

pex.list.header={0} subjects
pex.list.subtitle=All subjects of type {0}
pex.list.description=List all subjects of a certain type

pex.help.description=Get help for PermissionsEx
pex.import.description=Import data from another store

debug.description=Toggle debug mode
debug.success.filter=Debug mode enabled: {0} with filter {1}
Expand All @@ -57,18 +61,19 @@ version.description=Get information about the currently running PermissionsEx in
permission.arg.key=permission
permission.arg.permission-value=value
permission.success=Set permission {0} for {1} in {2} context
permission.description=Set a permission for a subject

permission-default.success=Set default permission to {0} for {1} in {2} context
permission-default.description=Set the fallback permission for a subject

parent.args.parent=parent
parent.add.success=Added parent {0} for {1} in {2} context
parent.remove.success=Removed parent {0} for {1} in {2} context
parent.set.success=Set parent for {0} to {1} in {2} context

option.arg.key=option
option.arg.value=value
option.success.unset=Unset option '{0}' for {1} in {2} context
option.success.set=Set option {0} for {1} in {2} context
option.arg.option.description=any option, suggesting from those that have already been checked

info.description=Provide information about a subject
info.header=Information for {0}
Expand All @@ -85,3 +90,11 @@ info.permissions.default=Default permission: {0}

delete.error.does-not-exist=Subject {0} does not exist!
delete.success=Successfully deleted data for subject {0}

rank.arg.relative.description=Whether the <index> argument should be relative to the current position of the rank
rank.arg.ladder.description=the rank ladder to work on
rank.list.description=List information about existing rank ladders
rank.add.description=Add a rank to a ladder
rank.remove.description=Remove a rank from a ladder
rank.promote.description=Promote a subject along a rank ladder
rank.demote.description=Demote a subject along a rank ladder
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import cloud.commandframework.bukkit.parsers.selector.SinglePlayerSelectorArgument;
import cloud.commandframework.execution.CommandExecutionCoordinator;
import cloud.commandframework.meta.CommandMeta;
import cloud.commandframework.minecraft.extras.MinecraftExtrasMetaKeys;
import cloud.commandframework.paper.PaperCommandManager;
import cloud.commandframework.permission.CommandPermission;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
Expand Down Expand Up @@ -69,7 +70,7 @@ public final class PermissionsExPlugin extends JavaPlugin implements Listener {
// -- PEX core -- //
private @MonotonicNonNull FormattedLogger logger;
private @MonotonicNonNull Path dataPath;
private @MonotonicNonNull BukkitAudiences adventure;
private @Nullable BukkitAudiences adventure;
private @Nullable MinecraftPermissionsEx<BukkitConfiguration> manager;
private final ExecutorService executorService = Executors.newCachedThreadPool();

Expand Down Expand Up @@ -141,20 +142,12 @@ private CommandManager<Commander> createCommandManager(
) throws RuntimeException {
final PaperCommandManager<Commander> mgr;
try {
mgr = new PaperCommandManager<Commander>(
mgr = new PaperCommandManager<>(
this,
execCoord,
sender -> new BukkitCommander(this, sender),
commander -> ((BukkitCommander) commander).source()
) {
@Override
public boolean hasPermission(final Commander sender, final CommandPermission permission) {
if (permission instanceof Permission) {
return sender.hasPermission((Permission) permission);
}
return super.hasPermission(sender, permission);
}
};
);
} catch (final Exception ex) {
throw new RuntimeException(ex);
}
Expand Down Expand Up @@ -182,10 +175,8 @@ private void registerBukkitCommands(final CommandRegistrationContext reg) {
.literal("resendtree")
.argument(targetArg)
.permission(perm)
.meta(CommandMeta.DESCRIPTION, "Force resend a player's command tree")
.meta(CommandMeta.LONG_DESCRIPTION, "Forcibly resend a player's Brigadier command tree\n" +
"This can help resolve issues where the completions on a client\n" +
"do not match what the server thinks a player has permission for.")
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, Messages.COMMAND_TREE_DESCRIPTION.tr())
.meta(MinecraftExtrasMetaKeys.LONG_DESCRIPTION, Messages.COMMAND_TREE_LONG_DESCRIPTION.tr())
.handler(ctx -> {
final SinglePlayerSelector target = ctx.get(targetArg);
if (target.getPlayer() == null) {
Expand Down Expand Up @@ -417,6 +408,9 @@ private void uninjectAllPermissibles() {
}

BukkitAudiences adventure() {
if (this.adventure == null) {
throw new IllegalStateException("Tried to access Adventure while the plugin was not enabled");
}
return this.adventure;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ error.load.prelogin=Error while loading data for user {0}/{1} during prelogin: {
command-tree.refreshed=Command tree for player {0} successfully refreshed
command-tree.unsupported=Re-sending the command tree is unsupported on your server (version {0})
command-tree.no-target=No target matched for selector '{0}'
command-tree.description=Force resend a player's command tree
command-tree.long-description=Forcibly resend a player's Brigadier command tree\nThis can help resolve issues where the completions on a client\ndo not match what the server thinks a player has permission for.

superperms.inject.no-injector=No Permissible injector found for your server implementation!
superperms.inject.error-generic=Unable to inject PEX's permissible for {0}
Expand Down
Loading

0 comments on commit a65c81a

Please sign in to comment.