Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved PermissionResolver and added support for LuckPerms #519

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,7 @@ object Versions {
const val HIBERNATE_VALIDATOR = "8.0.2.Final"
const val EXPRESSLY = "5.0.0"

// LuckPerms
const val LUCKPERMS_API = "5.4"

}
16 changes: 16 additions & 0 deletions examples/fabric/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ repositories {
mavenCentral()
maven("https://repo.panda-lang.org/releases/")
maven("https://maven.fabricmc.net/")
maven("https://api.modrinth.com/maven")
}

dependencies {
Expand All @@ -21,12 +22,27 @@ dependencies {
modImplementation("net.fabricmc:fabric-loader:0.16.7")
modImplementation("net.fabricmc.fabric-api:fabric-api:0.106.0+1.21.1")

modLocalRuntime("maven.modrinth:fabric-permissions-api:0.3.3")
modLocalRuntime("maven.modrinth:luckperms:v5.4.140-fabric")

// modImplementation("dev.rollczi:litecommands-fabric:3.9.7") // <-- uncomment in your project
implementation(project(path = ":litecommands-fabric", configuration = "namedElements"))
/*"dev.rollczi:litecommands-luckperms:3.9.7".also {
api(it)
include(it)
}*/
project(":litecommands-luckperms").also {
api(it)
include(it)
}

}

sourceSets.test {
java.setSrcDirs(emptyList<String>())
resources.setSrcDirs(emptyList<String>())
}

loom {
accessWidenerPath = project.file("src/main/resources/litecommands-example.accesswidener")
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

import dev.rollczi.example.fabric.server.command.ExampleCommand;
import dev.rollczi.litecommands.fabric.LiteFabricFactory;
import dev.rollczi.litecommands.luckperms.LuckPermsPermissionFactory;
import net.fabricmc.api.DedicatedServerModInitializer;

public class ServerExampleFabric implements DedicatedServerModInitializer {
@Override
public void onInitializeServer() {
LiteFabricFactory.server()
.commands(new ExampleCommand())
.build();
.permissionResolver(new LuckPermsPermissionFactory())
.commands(new ExampleCommand())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
import dev.rollczi.litecommands.annotations.argument.Arg;
import dev.rollczi.litecommands.annotations.async.Async;
import dev.rollczi.litecommands.annotations.command.Command;
import dev.rollczi.litecommands.annotations.context.Sender;
import dev.rollczi.litecommands.annotations.execute.Execute;
import dev.rollczi.litecommands.annotations.join.Join;
import dev.rollczi.litecommands.annotations.quoted.Quoted;
import dev.rollczi.litecommands.platform.PlatformSender;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import org.jetbrains.annotations.ApiStatus;

@Command(name = "example", aliases = "tutorial")
public class ExampleCommand {
Expand All @@ -31,4 +34,5 @@ String thread1() {
String thread2() {
return Thread.currentThread().getName();
}

}
6 changes: 5 additions & 1 deletion examples/fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,9 @@
"client": [
"dev.rollczi.example.fabric.client.ClientExampleFabric"
]
}
},
"depends": {
"luckperms": "*"
},
"accessWidener": "litecommands-example.accesswidener"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessWidener v1 named

accessible field net/minecraft/server/command/ServerCommandSource output Lnet/minecraft/server/command/CommandOutput;
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import java.lang.annotation.Annotation;

@Deprecated
@FunctionalInterface
public interface AnnotatedValidator<SENDER, T, A extends Annotation> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import java.lang.annotation.Annotation;

@Deprecated
public class AnnotatedValidatorProcessor<SENDER, T, A extends Annotation> implements AnnotationProcessor<SENDER> {

private final Class<A> annotationClass;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import java.lang.annotation.Annotation;

@Deprecated
class RequirementAnnotatedValidatorImpl<SENDER, T, A extends Annotation> implements RequirementValidator<SENDER, T> {

private final AnnotatedValidator<SENDER, T, A> validator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public boolean execute(@NotNull CommandSender sender, @NotNull String alias, Str
ParseableInput<?> input = ParseableInput.raw(args);
PlatformSender platformSender = new BukkitPlatformSender(sender);

this.invocationHook.execute(new Invocation<>(sender, platformSender, commandRoute.getName(), alias, input), input);
this.invocationHook.execute(new Invocation<>(platformSender, commandRoute.getName(), alias, input), input);
return true;
}

Expand Down Expand Up @@ -83,7 +83,7 @@ public boolean execute(@NotNull CommandSender sender, @NotNull String alias, Str
public CompletableFuture<Set<Suggestion>> suggest(CommandSender sender, String alias, String[] args) {
SuggestionInput<?> input = SuggestionInput.raw(args);
PlatformSender platformSender = new BukkitPlatformSender(sender);
Invocation<CommandSender> invocation = new Invocation<>(sender, platformSender, commandRoute.getName(), alias, input);
Invocation<CommandSender> invocation = new Invocation<>(platformSender, commandRoute.getName(), alias, input);

return CompletableFuture.completedFuture(this.suggestionHook.suggest(invocation, input).getSuggestions()); // TODO Run suggestion asynchronously inside LiteCommands platform
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ public BukkitPlatformSender(CommandSender handle) {
this.handle = handle;
}

@Override
public boolean hasPermission(String permission) {
return this.handle.hasPermission(permission);
}

@Override
public String getName() {
return this.handle.getName();
Expand Down Expand Up @@ -49,9 +44,13 @@ public Identifier getIdentifier() {
}

@Override
public Comparable<Void> sendMessage(String message) {
public Object getHandle() {
return this.handle;
}

@Override
public void sendMessage(String message) {
this.handle.sendMessage(message);
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public BungeeCommand(LiteBungeeSettings settings, CommandRoute<CommandSender> co
public void execute(CommandSender sender, String[] args) {
ParseableInput<?> input = ParseableInput.raw(args);
BungeeSender platformSender = new BungeeSender(sender);
Invocation<CommandSender> invocation = new Invocation<>(sender, platformSender, this.commandSection.getName(), this.label, input);
Invocation<CommandSender> invocation = new Invocation<>(platformSender, this.commandSection.getName(), this.label, input);

this.executeListener.execute(invocation, input);
}
Expand All @@ -44,7 +44,7 @@ public void execute(CommandSender sender, String[] args) {
public Iterable<String> onTabComplete(CommandSender sender, String[] args) {
SuggestionInput<?> input = SuggestionInput.raw(args);
BungeeSender platformSender = new BungeeSender(sender);
Invocation<CommandSender> invocation = new Invocation<>(sender, platformSender, this.commandSection.getName(), this.label, input);
Invocation<CommandSender> invocation = new Invocation<>(platformSender, this.commandSection.getName(), this.label, input);

return this.suggestionListener.suggest(invocation, input)
.asMultiLevelList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public Identifier getIdentifier() {
}

@Override
public boolean hasPermission(String permission) {
return this.handle.hasPermission(permission);
public Object getHandle() {
return this.handle;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import dev.rollczi.litecommands.command.builder.CommandBuilderCollector;
import dev.rollczi.litecommands.editor.EditorService;
import dev.rollczi.litecommands.message.MessageRegistry;
import dev.rollczi.litecommands.permission.PermissionService;
import dev.rollczi.litecommands.platform.PlatformSettings;
import dev.rollczi.litecommands.platform.Platform;
import dev.rollczi.litecommands.scheduler.Scheduler;
Expand Down Expand Up @@ -39,6 +40,9 @@ public interface LiteCommandsInternal<SENDER, C extends PlatformSettings> {
@ApiStatus.Internal
EditorService<SENDER> getEditorService();

@ApiStatus.Internal
PermissionService getPermissionService();

@ApiStatus.Internal
ValidatorService<SENDER> getValidatorService();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ static <EXPECTED> ParseCompletedResult<EXPECTED> failure(Object failedReason) {
return new ParseCompletedResult<>(null, FailedReason.of(failedReason), false, Collections.emptyList());
}

@Deprecated
static <EXPECTED> ParseCompletedResult<EXPECTED> failure() {
return new ParseCompletedResult<>(null, FailedReason.empty(), false, Collections.emptyList());
}

@ApiStatus.Experimental
static <EXPECTED> ParseCompletedResult<EXPECTED> conditional(EXPECTED parsed, List<RequirementCondition> conditions) {
return new ParseCompletedResult<>(parsed, null, false, Collections.unmodifiableList(conditions));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
package dev.rollczi.litecommands.command;

import dev.rollczi.litecommands.meta.MetaHolder;
import org.jetbrains.annotations.Nullable;

/**
* CommandNode is an any node of the command tree.
* @see CommandRoute
* @see dev.rollczi.litecommands.command.executor.CommandExecutor
*/
public interface CommandNode<SENDER> {
public interface CommandNode<SENDER> extends MetaHolder {

CommandRoute<SENDER> getParent();

@Override
@Nullable
default MetaHolder parentMeta() {
return getParent();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public static CommandExecuteResult failed(CommandExecutor<?> executor, FailedRea
Preconditions.notNull(executor, "executor");
Preconditions.notNull(failedReason, "failed cannot be null");

return new CommandExecuteResult(executor, null, null, failedReason.getReasonOr(null));
return new CommandExecuteResult(executor, null, null, failedReason.getReason());
}

}
Loading
Loading