Compare commits

..

1 Commits

Author SHA1 Message Date
dependabot[bot] f87d4a8bbf
deps: bump net.kyori:adventure-platform-bukkit from 4.3.3 to 4.3.4
Bumps [net.kyori:adventure-platform-bukkit](https://github.com/KyoriPowered/adventure-platform) from 4.3.3 to 4.3.4.
- [Release notes](https://github.com/KyoriPowered/adventure-platform/releases)
- [Commits](https://github.com/KyoriPowered/adventure-platform/compare/v4.3.3...v4.3.4)

---
updated-dependencies:
- dependency-name: net.kyori:adventure-platform-bukkit
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
3 months ago

@ -9,7 +9,7 @@ plugins {
id 'java' id 'java'
} }
group 'org.inksnow.husk' group 'net.william278'
version "$ext.library_version${versionMetadata()}" version "$ext.library_version${versionMetadata()}"
description "$ext.library_description" description "$ext.library_description"
defaultTasks 'licenseFormat', 'build' defaultTasks 'licenseFormat', 'build'
@ -21,12 +21,30 @@ ext {
publishing { publishing {
repositories { repositories {
maven { if (System.getenv("RELEASES_MAVEN_USERNAME") != null) {
name = 'husk-release' maven {
url = findProperty("repository.huskrelease.url") name = "william278-releases"
credentials { url = "https://repo.william278.net/releases"
username = findProperty("repository.huskrelease.username") credentials {
password = findProperty("repository.huskrelease.password") username = System.getenv("RELEASES_MAVEN_USERNAME")
password = System.getenv("RELEASES_MAVEN_PASSWORD")
}
authentication {
basic(BasicAuthentication)
}
}
}
if (System.getenv("SNAPSHOTS_MAVEN_USERNAME") != null) {
maven {
name = "william278-snapshots"
url = "https://repo.william278.net/snapshots"
credentials {
username = System.getenv("SNAPSHOTS_MAVEN_USERNAME")
password = System.getenv("SNAPSHOTS_MAVEN_PASSWORD")
}
authentication {
basic(BasicAuthentication)
}
} }
} }
} }
@ -38,7 +56,7 @@ allprojects {
apply plugin: 'java' apply plugin: 'java'
compileJava.options.encoding = 'UTF-8' compileJava.options.encoding = 'UTF-8'
compileJava.options.release.set 8 compileJava.options.release.set 17
javadoc.options.encoding = 'UTF-8' javadoc.options.encoding = 'UTF-8'
javadoc.options.addStringOption('Xdoclint:none', '-quiet') javadoc.options.addStringOption('Xdoclint:none', '-quiet')
@ -116,7 +134,7 @@ subprojects {
if (['common'].contains(project.name)) { if (['common'].contains(project.name)) {
publications { publications {
mavenJavaCommon(MavenPublication) { mavenJavaCommon(MavenPublication) {
groupId = 'org.inksnow.husk.uniform' groupId = 'net.william278.uniform'
artifactId = 'uniform-common' artifactId = 'uniform-common'
version = "$rootProject.version" version = "$rootProject.version"
artifact shadowJar artifact shadowJar
@ -129,7 +147,7 @@ subprojects {
if (['paper'].contains(project.name)) { if (['paper'].contains(project.name)) {
publications { publications {
mavenJavaPaper(MavenPublication) { mavenJavaPaper(MavenPublication) {
groupId = 'org.inksnow.husk.uniform' groupId = 'net.william278.uniform'
artifactId = 'uniform-paper' artifactId = 'uniform-paper'
version = "$rootProject.version" version = "$rootProject.version"
artifact shadowJar artifact shadowJar
@ -142,7 +160,7 @@ subprojects {
if (['bukkit'].contains(project.name)) { if (['bukkit'].contains(project.name)) {
publications { publications {
mavenJavaBukkit(MavenPublication) { mavenJavaBukkit(MavenPublication) {
groupId = 'org.inksnow.husk.uniform' groupId = 'net.william278.uniform'
artifactId = 'uniform-bukkit' artifactId = 'uniform-bukkit'
version = "$rootProject.version" version = "$rootProject.version"
artifact shadowJar artifact shadowJar
@ -155,7 +173,7 @@ subprojects {
if (['velocity'].contains(project.name)) { if (['velocity'].contains(project.name)) {
publications { publications {
mavenJavaVelocity(MavenPublication) { mavenJavaVelocity(MavenPublication) {
groupId = 'org.inksnow.husk.uniform' groupId = 'net.william278.uniform'
artifactId = 'uniform-velocity' artifactId = 'uniform-velocity'
version = "$rootProject.version" version = "$rootProject.version"
artifact shadowJar artifact shadowJar
@ -168,7 +186,7 @@ subprojects {
if (['fabric-1.20.1'].contains(project.name)) { if (['fabric-1.20.1'].contains(project.name)) {
publications { publications {
mavenJavaFabric1_20_1(MavenPublication) { mavenJavaFabric1_20_1(MavenPublication) {
groupId = 'org.inksnow.husk.uniform' groupId = 'net.william278.uniform'
artifactId = 'uniform-fabric' artifactId = 'uniform-fabric'
version = "${rootProject.version}+1.20.1" version = "${rootProject.version}+1.20.1"
artifact remapJar artifact remapJar
@ -181,7 +199,7 @@ subprojects {
if (['fabric-1.21'].contains(project.name)) { if (['fabric-1.21'].contains(project.name)) {
publications { publications {
mavenJavaFabric1_21(MavenPublication) { mavenJavaFabric1_21(MavenPublication) {
groupId = 'org.inksnow.husk.uniform' groupId = 'net.william278.uniform'
artifactId = 'uniform-fabric' artifactId = 'uniform-fabric'
version = "${rootProject.version}+1.21" version = "${rootProject.version}+1.21"
artifact remapJar artifact remapJar
@ -194,7 +212,7 @@ subprojects {
if (['sponge-11'].contains(project.name)) { if (['sponge-11'].contains(project.name)) {
publications { publications {
mavenSponge11(MavenPublication) { mavenSponge11(MavenPublication) {
groupId = 'org.inksnow.husk.uniform' groupId = 'net.william278.uniform'
artifactId = 'uniform-sponge' artifactId = 'uniform-sponge'
version = "${rootProject.version}+11" version = "${rootProject.version}+11"
artifact shadowJar artifact shadowJar

@ -6,7 +6,7 @@ plugins {
dependencies { dependencies {
api project(path: ':common') api project(path: ':common')
implementation 'net.kyori:adventure-platform-bukkit:4.3.3' implementation 'net.kyori:adventure-platform-bukkit:4.3.4'
implementation 'space.arim.morepaperlib:morepaperlib:0.4.4' implementation 'space.arim.morepaperlib:morepaperlib:0.4.4'
compileOnlyApi 'org.spigotmc:spigot-api:1.17.1-R0.1-SNAPSHOT' compileOnlyApi 'org.spigotmc:spigot-api:1.17.1-R0.1-SNAPSHOT'

@ -32,7 +32,6 @@ import net.william278.uniform.BaseCommand;
import net.william278.uniform.Command; import net.william278.uniform.Command;
import net.william278.uniform.Permission; import net.william278.uniform.Permission;
import net.william278.uniform.Uniform; import net.william278.uniform.Uniform;
import net.william278.uniform.util.StringUtil;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.CommandException; import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -83,17 +82,14 @@ public class BukkitCommand extends BaseCommand<CommandSender> {
this.setAliases(command.getAliases()); this.setAliases(command.getAliases());
this.setUsage(getUsageText()); this.setUsage(getUsageText());
if (permission != null) { if (permission != null) {
this.setPermission(permission.getNode()); this.setPermission(permission.node());
} }
} }
@NotNull @NotNull
private String getUsageText() { private String getUsageText() {
return dispatcher.getSmartUsage(dispatcher.getRoot(), Bukkit.getConsoleSender()) return dispatcher.getSmartUsage(dispatcher.getRoot(), Bukkit.getConsoleSender()).values().stream()
.values() .map("/%s"::formatted).collect(Collectors.joining("\n"));
.stream()
.map("/"::concat)
.collect(Collectors.joining("\n"));
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@ -125,15 +121,13 @@ public class BukkitCommand extends BaseCommand<CommandSender> {
dispatcher.parse(passed, sender), dispatcher.parse(passed, sender),
passed.length() // Spigot API limitation - we can only TAB complete the full text length :( passed.length() // Spigot API limitation - we can only TAB complete the full text length :(
) )
.thenApply(suggestions -> suggestions.getList().stream() .thenApply(suggestions -> suggestions.getList().stream().map(Suggestion::getText).toList())
.map(Suggestion::getText)
.collect(Collectors.toList()))
.join(); .join();
} }
@Override @Override
public boolean testPermissionSilent(@NotNull CommandSender target) { public boolean testPermissionSilent(@NotNull CommandSender target) {
if (permission == null || StringUtil.isBlank(permission.getNode())) { if (permission == null || permission.node().isBlank()) {
return true; return true;
} }
return new BukkitCommandUser(target).checkPermission(permission); return new BukkitCommandUser(target).checkPermission(permission);
@ -146,10 +140,7 @@ public class BukkitCommand extends BaseCommand<CommandSender> {
@NotNull @NotNull
private String getInput(@NotNull String[] args) { private String getInput(@NotNull String[] args) {
if (args.length == 0) { return args.length == 0 ? getName() : "%s %s".formatted(getName(), String.join(" ", args));
return getName();
}
return getName() + " " + String.join(" ", args);
} }
} }

@ -21,7 +21,6 @@
package net.william278.uniform.bukkit; package net.william278.uniform.bukkit;
import lombok.Value;
import net.kyori.adventure.audience.Audience; import net.kyori.adventure.audience.Audience;
import net.william278.uniform.CommandUser; import net.william278.uniform.CommandUser;
import net.william278.uniform.Permission; import net.william278.uniform.Permission;
@ -33,10 +32,7 @@ import org.jetbrains.annotations.Nullable;
import java.util.UUID; import java.util.UUID;
@Value public record BukkitCommandUser(@NotNull CommandSender sender) implements CommandUser {
public class BukkitCommandUser implements CommandUser {
@NotNull CommandSender sender;
@Override @Override
@NotNull @NotNull
@ -52,15 +48,15 @@ public class BukkitCommandUser implements CommandUser {
@Override @Override
@Nullable @Nullable
public UUID getUuid() { public UUID getUuid() {
return sender instanceof Player ? ((Player) sender).getUniqueId() : null; return sender instanceof Player player ? player.getUniqueId() : null;
} }
@Override @Override
public boolean checkPermission(@NotNull Permission permission) { public boolean checkPermission(@NotNull Permission permission) {
if (sender.isPermissionSet(permission.getNode())) { if (sender.isPermissionSet(permission.node())) {
return sender.hasPermission(permission.getNode()); return sender.hasPermission(permission.node());
} }
return permission.getDefaultValue().check( return permission.defaultValue().check(
sender.isOp() || sender instanceof ConsoleCommandSender sender.isOp() || sender instanceof ConsoleCommandSender
); );
} }

@ -37,7 +37,6 @@ import space.arim.morepaperlib.commands.CommandRegistration;
import java.util.Arrays; import java.util.Arrays;
import java.util.Locale; import java.util.Locale;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors;
/** /**
* A class for registering commands with the Bukkit server's CommandMap * A class for registering commands with the Bukkit server's CommandMap
@ -92,8 +91,7 @@ public final class BukkitUniform implements Uniform {
registrar.getServerCommandMap().registerAll( registrar.getServerCommandMap().registerAll(
PLUGIN.getName().toLowerCase(Locale.ENGLISH).replaceAll("[^a-z0-9_]", ""), PLUGIN.getName().toLowerCase(Locale.ENGLISH).replaceAll("[^a-z0-9_]", ""),
Arrays.stream(commands).map(c -> (BukkitCommand) c) Arrays.stream(commands).map(c -> (BukkitCommand) c)
.map(c -> (org.bukkit.command.Command) c.getImpl(this)) .map(c -> (org.bukkit.command.Command) c.getImpl(this)).toList()
.collect(Collectors.toList())
); );
} }

@ -6,7 +6,6 @@ plugins {
dependencies { dependencies {
compileOnlyApi 'com.mojang:brigadier:1.1.8' compileOnlyApi 'com.mojang:brigadier:1.1.8'
compileOnlyApi 'net.kyori:adventure-api:4.17.0' compileOnlyApi 'net.kyori:adventure-api:4.17.0'
compileOnlyApi 'com.google.guava:guava:21.0'
compileOnly 'org.jetbrains:annotations:24.1.0' compileOnly 'org.jetbrains:annotations:24.1.0'
compileOnly 'org.projectlombok:lombok:1.18.32' compileOnly 'org.projectlombok:lombok:1.18.32'

@ -21,7 +21,6 @@
package net.william278.uniform; package net.william278.uniform;
import com.google.common.collect.ImmutableList;
import com.mojang.brigadier.arguments.*; import com.mojang.brigadier.arguments.*;
import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.suggestion.SuggestionProvider; import com.mojang.brigadier.suggestion.SuggestionProvider;
@ -115,7 +114,7 @@ public abstract class BaseCommand<S> {
@SafeVarargs @SafeVarargs
public final void addConditionalSyntax(@Nullable Predicate<S> condition, @NotNull CommandExecutor<S> executor, public final void addConditionalSyntax(@Nullable Predicate<S> condition, @NotNull CommandExecutor<S> executor,
@NotNull CommandElement<S>... elements) { @NotNull CommandElement<S>... elements) {
CommandSyntax<S> syntax = new CommandSyntax<>(condition, executor, ImmutableList.copyOf(elements)); var syntax = new CommandSyntax<>(condition, executor, List.of(elements));
this.syntaxes.add(syntax); this.syntaxes.add(syntax);
} }

@ -21,13 +21,10 @@
package net.william278.uniform; package net.william278.uniform;
import com.google.common.collect.ImmutableList;
import lombok.AccessLevel; import lombok.AccessLevel;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter; import lombok.Setter;
import lombok.Value;
import net.william278.uniform.annotations.Argument; import net.william278.uniform.annotations.Argument;
import net.william278.uniform.annotations.CommandDescription; import net.william278.uniform.annotations.CommandDescription;
import net.william278.uniform.annotations.CommandNode; import net.william278.uniform.annotations.CommandNode;
@ -42,7 +39,6 @@ import java.lang.reflect.Method;
import java.lang.reflect.Parameter; import java.lang.reflect.Parameter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.function.Predicate; import java.util.function.Predicate;
@ -55,7 +51,7 @@ import static net.william278.uniform.CommandExecutor.methodToExecutor;
public abstract class Command implements CommandProvider { public abstract class Command implements CommandProvider {
private final String name; private final String name;
private List<String> aliases = Collections.emptyList(); private List<String> aliases = List.of();
private String description = ""; private String description = "";
@Getter(AccessLevel.NONE) @Getter(AccessLevel.NONE)
private @Nullable Permission permission = null; private @Nullable Permission permission = null;
@ -74,7 +70,7 @@ public abstract class Command implements CommandProvider {
throw new IllegalArgumentException("@CommandNode annotation is required on annotated command/sub-commands"); throw new IllegalArgumentException("@CommandNode annotation is required on annotated command/sub-commands");
} }
this.name = node.value(); this.name = node.value();
this.aliases = ImmutableList.copyOf(node.aliases()); this.aliases = List.of(node.aliases());
this.description = node.description(); this.description = node.description();
this.scope = node.scope(); this.scope = node.scope();
Permission.annotated(node.permission()).ifPresent(this::setPermission); Permission.annotated(node.permission()).ifPresent(this::setPermission);
@ -91,16 +87,11 @@ public abstract class Command implements CommandProvider {
} }
public boolean contains(@NotNull CommandUser user) { public boolean contains(@NotNull CommandUser user) {
switch (this) { return switch (this) {
case IN_GAME: case IN_GAME -> !user.isConsole();
return !user.isConsole(); case CONSOLE -> user.isConsole();
case CONSOLE: case ALL -> true;
return user.isConsole(); };
case ALL:
return true;
default:
throw new IllegalArgumentException("Unknown execution scope: " + this);
}
} }
} }
@ -203,15 +194,8 @@ public abstract class Command implements CommandProvider {
} }
} }
@Value public record SubCommand(@NotNull String name, @NotNull List<String> aliases, @Nullable Permission permission,
@RequiredArgsConstructor @NotNull ExecutionScope scope, @NotNull CommandProvider provider) {
public static class SubCommand {
@NotNull String name;
@NotNull List<String> aliases;
@Nullable Permission permission;
@NotNull ExecutionScope scope;
@NotNull CommandProvider provider;
public SubCommand(@NotNull String name, @NotNull List<String> aliases, @Nullable Permission permission, public SubCommand(@NotNull String name, @NotNull List<String> aliases, @Nullable Permission permission,
@NotNull CommandProvider provider) { @NotNull CommandProvider provider) {
this(name, aliases, permission, ExecutionScope.ALL, provider); this(name, aliases, permission, ExecutionScope.ALL, provider);
@ -222,11 +206,11 @@ public abstract class Command implements CommandProvider {
} }
public SubCommand(@NotNull String name, @Nullable Permission permission, @NotNull CommandProvider provider) { public SubCommand(@NotNull String name, @Nullable Permission permission, @NotNull CommandProvider provider) {
this(name, Collections.emptyList(), permission, ExecutionScope.ALL, provider); this(name, List.of(), permission, ExecutionScope.ALL, provider);
} }
public SubCommand(@NotNull String name, @NotNull CommandProvider provider) { public SubCommand(@NotNull String name, @NotNull CommandProvider provider) {
this(name, Collections.emptyList(), null, ExecutionScope.ALL, provider); this(name, List.of(), null, ExecutionScope.ALL, provider);
} }

@ -39,7 +39,7 @@ public interface CommandExecutor<S> {
@NotNull BaseCommand<?> cmd) { @NotNull BaseCommand<?> cmd) {
return (context) -> { return (context) -> {
try { try {
method.invoke(instance, private$injectParams(method, context, cmd)); method.invoke(instance, injectParams(method, context, cmd));
} catch (IllegalAccessException | InvocationTargetException e) { } catch (IllegalAccessException | InvocationTargetException e) {
throw new IllegalStateException("Failed to invoke command executor from annotated method", e); throw new IllegalStateException("Failed to invoke command executor from annotated method", e);
} }
@ -47,8 +47,8 @@ public interface CommandExecutor<S> {
} }
@Nullable @Nullable
static Object @NotNull [] private$injectParams(@NotNull Method method, @NotNull CommandContext<?> context, private static Object @NotNull [] injectParams(@NotNull Method method, @NotNull CommandContext<?> context,
@NotNull BaseCommand<?> cmd) { @NotNull BaseCommand<?> cmd) {
final Object[] params = new Object[method.getParameterCount()]; final Object[] params = new Object[method.getParameterCount()];
for (int i = 0; i < method.getParameterCount(); i++) { for (int i = 0; i < method.getParameterCount(); i++) {
final Parameter param = method.getParameters()[i]; final Parameter param = method.getParameters()[i];

@ -21,7 +21,6 @@
package net.william278.uniform; package net.william278.uniform;
import lombok.Value;
import net.william278.uniform.element.CommandElement; import net.william278.uniform.element.CommandElement;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@ -29,9 +28,7 @@ import org.jetbrains.annotations.Nullable;
import java.util.List; import java.util.List;
import java.util.function.Predicate; import java.util.function.Predicate;
@Value public record CommandSyntax<S>(@Nullable Predicate<S> condition, @NotNull CommandExecutor<S> executor,
public class CommandSyntax<S> { @NotNull List<CommandElement<S>> elements) {
@Nullable Predicate<S> condition;
@NotNull CommandExecutor<S> executor;
@NotNull List<CommandElement<S>> elements;
} }

@ -21,9 +21,6 @@
package net.william278.uniform; package net.william278.uniform;
import com.google.common.collect.ImmutableList;
import lombok.RequiredArgsConstructor;
import lombok.Value;
import net.william278.uniform.element.CommandElement; import net.william278.uniform.element.CommandElement;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@ -34,13 +31,8 @@ import java.util.Map;
import static net.william278.uniform.Graph.commandToElement; import static net.william278.uniform.Graph.commandToElement;
@Value record ConversionNode<S>(@NotNull CommandElement<S> element, @Nullable Execution<S> execution,
@RequiredArgsConstructor @NotNull Map<CommandElement<S>, ConversionNode<S>> nextMap) {
public class ConversionNode<S> {
@NotNull CommandElement<S> element;
@Nullable Execution<S> execution;
@NotNull Map<CommandElement<S>, ConversionNode<S>> nextMap;
static <S> @NotNull ConversionNode<S> fromCommand(@NotNull BaseCommand<S> command) { static <S> @NotNull ConversionNode<S> fromCommand(@NotNull BaseCommand<S> command) {
ConversionNode<S> root = new ConversionNode<>(commandToElement(command), Execution.fromCommand(command)); ConversionNode<S> root = new ConversionNode<>(commandToElement(command), Execution.fromCommand(command));
@ -48,8 +40,8 @@ public class ConversionNode<S> {
for (CommandSyntax<S> syntax : command.getSyntaxes()) { for (CommandSyntax<S> syntax : command.getSyntaxes()) {
ConversionNode<S> syntaxNode = root; ConversionNode<S> syntaxNode = root;
for (CommandElement<S> element : syntax.getElements()) { for (CommandElement<S> element : syntax.elements()) {
boolean last = element == syntax.getElements().get(syntax.getElements().size() - 1); boolean last = element == syntax.elements().get(syntax.elements().size() - 1);
syntaxNode = syntaxNode.nextMap.computeIfAbsent(element, e -> { syntaxNode = syntaxNode.nextMap.computeIfAbsent(element, e -> {
Execution<S> execution = last ? Execution.fromSyntax(syntax) : null; Execution<S> execution = last ? Execution.fromSyntax(syntax) : null;
return new ConversionNode<>(e, execution); return new ConversionNode<>(e, execution);
@ -77,7 +69,7 @@ public class ConversionNode<S> {
nodes[i++] = entry.toNode(); nodes[i++] = entry.toNode();
} }
return new Node<>(this.element, this.execution, ImmutableList.copyOf(nodes)); return new Node<>(this.element, this.execution, List.of(nodes));
} }
} }

@ -22,7 +22,6 @@
package net.william278.uniform; package net.william278.uniform;
import com.mojang.brigadier.builder.ArgumentBuilder; import com.mojang.brigadier.builder.ArgumentBuilder;
import lombok.Value;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@ -30,16 +29,11 @@ import java.util.concurrent.Executor;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.function.Predicate; import java.util.function.Predicate;
@Value record Execution<S>(@NotNull Predicate<S> predicate, @Nullable CommandExecutor<S> defaultExecutor,
public class Execution<S> implements Predicate<S> { @Nullable CommandExecutor<S> executor, @Nullable Predicate<S> condition) implements Predicate<S> {
private static final Executor CACHED_EXECUTOR = Executors.newCachedThreadPool(); private static final Executor CACHED_EXECUTOR = Executors.newCachedThreadPool();
@NotNull Predicate<S> predicate;
@Nullable CommandExecutor<S> defaultExecutor;
@Nullable CommandExecutor<S> executor;
@Nullable Predicate<S> condition;
@NotNull @NotNull
static <S> Execution<S> fromCommand(@NotNull BaseCommand<S> command) { static <S> Execution<S> fromCommand(@NotNull BaseCommand<S> command) {
CommandExecutor<S> defaultExecutor = command.getDefaultExecutor(); CommandExecutor<S> defaultExecutor = command.getDefaultExecutor();
@ -48,9 +42,9 @@ public class Execution<S> implements Predicate<S> {
CommandExecutor<S> executor = defaultExecutor; CommandExecutor<S> executor = defaultExecutor;
Predicate<S> condition = defaultCondition; Predicate<S> condition = defaultCondition;
for (CommandSyntax<S> syntax : command.getSyntaxes()) { for (CommandSyntax<S> syntax : command.getSyntaxes()) {
if (!syntax.getElements().isEmpty()) continue; if (!syntax.elements().isEmpty()) continue;
executor = syntax.getExecutor(); executor = syntax.executor();
condition = syntax.getCondition(); condition = syntax.condition();
break; break;
} }
@ -59,8 +53,8 @@ public class Execution<S> implements Predicate<S> {
@NotNull @NotNull
static <S> Execution<S> fromSyntax(@NotNull CommandSyntax<S> syntax) { static <S> Execution<S> fromSyntax(@NotNull CommandSyntax<S> syntax) {
CommandExecutor<S> executor = syntax.getExecutor(); CommandExecutor<S> executor = syntax.executor();
Predicate<S> condition = syntax.getCondition(); Predicate<S> condition = syntax.condition();
return new Execution<>(source -> condition == null || condition.test(source), null, executor, condition); return new Execution<>(source -> condition == null || condition.test(source), null, executor, condition);
} }

@ -24,14 +24,11 @@ package net.william278.uniform;
import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.tree.CommandNode; import com.mojang.brigadier.tree.CommandNode;
import com.mojang.brigadier.tree.LiteralCommandNode; import com.mojang.brigadier.tree.LiteralCommandNode;
import lombok.Value;
import net.william278.uniform.element.CommandElement; import net.william278.uniform.element.CommandElement;
import net.william278.uniform.element.LiteralElement; import net.william278.uniform.element.LiteralElement;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@Value record Graph<S>(@NotNull Node<S> root) {
public class Graph<S> {
@NotNull Node<S> root;
static <S> @NotNull Graph<S> create(@NotNull BaseCommand<S> command) { static <S> @NotNull Graph<S> create(@NotNull BaseCommand<S> command) {
return new Graph<>(Node.command(command)); return new Graph<>(Node.command(command));
@ -44,10 +41,10 @@ public class Graph<S> {
@NotNull @NotNull
LiteralCommandNode<S> build() { LiteralCommandNode<S> build() {
CommandNode<S> node = this.root.build(); CommandNode<S> node = this.root.build();
if (!(node instanceof LiteralCommandNode)) { if (!(node instanceof LiteralCommandNode<S> literalNode)) {
throw new IllegalStateException("Root node is somehow not a literal node. This should be impossible."); throw new IllegalStateException("Root node is somehow not a literal node. This should be impossible.");
} }
return (LiteralCommandNode<S>) node; return literalNode;
} }
@NotNull @NotNull
@ -55,7 +52,7 @@ public class Graph<S> {
final LiteralArgumentBuilder<S> builder = LiteralArgumentBuilder.literal(name); final LiteralArgumentBuilder<S> builder = LiteralArgumentBuilder.literal(name);
final CommandNode<S> command = this.root.build(); final CommandNode<S> command = this.root.build();
builder.executes(command.getCommand()); builder.executes(command.getCommand());
this.root.getChildren().forEach(child -> builder.then(child.build())); this.root.children().forEach(child -> builder.then(child.build()));
return builder; return builder;
} }

@ -23,18 +23,13 @@ package net.william278.uniform;
import com.mojang.brigadier.builder.ArgumentBuilder; import com.mojang.brigadier.builder.ArgumentBuilder;
import com.mojang.brigadier.tree.CommandNode; import com.mojang.brigadier.tree.CommandNode;
import lombok.Value;
import net.william278.uniform.element.CommandElement; import net.william278.uniform.element.CommandElement;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.List; import java.util.List;
@Value record Node<S>(@NotNull CommandElement<S> element, @Nullable Execution<S> execution, @NotNull List<Node<S>> children) {
public class Node<S> {
@NotNull CommandElement<S> element;
@Nullable Execution<S> execution;
@NotNull List<Node<S>> children;
static <S> @NotNull Node<S> command(@NotNull BaseCommand<S> command) { static <S> @NotNull Node<S> command(@NotNull BaseCommand<S> command) {
return ConversionNode.fromCommand(command).toNode(); return ConversionNode.fromCommand(command).toNode();

@ -21,22 +21,14 @@
package net.william278.uniform; package net.william278.uniform;
import lombok.RequiredArgsConstructor;
import lombok.Value;
import net.william278.uniform.annotations.PermissionNode; import net.william278.uniform.annotations.PermissionNode;
import net.william278.uniform.util.StringUtil;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.Optional; import java.util.Optional;
import java.util.function.Predicate; import java.util.function.Predicate;
@SuppressWarnings("unused") @SuppressWarnings("unused")
@Value public record Permission(@NotNull String node, @NotNull Default defaultValue) {
@RequiredArgsConstructor
public class Permission {
@NotNull String node;
@NotNull Default defaultValue;
Permission(@NotNull String node) { Permission(@NotNull String node) {
this(node, Default.FALSE); this(node, Default.FALSE);
@ -59,7 +51,7 @@ public class Permission {
@NotNull @NotNull
static Optional<Permission> annotated(@NotNull PermissionNode annotation) { static Optional<Permission> annotated(@NotNull PermissionNode annotation) {
if (StringUtil.isBlank(annotation.value())) { if (annotation.value().isBlank()) {
return Optional.empty(); return Optional.empty();
} }
return Optional.of(new Permission(annotation.value(), annotation.defaultValue())); return Optional.of(new Permission(annotation.value(), annotation.defaultValue()));
@ -71,12 +63,11 @@ public class Permission {
FALSE; FALSE;
public boolean check(boolean op) { public boolean check(boolean op) {
switch (this) { return switch (this) {
case IF_OP: return op; case IF_OP -> op;
case TRUE: return true; case TRUE -> true;
case FALSE: return false; case FALSE -> false;
default: throw new IllegalStateException("Unexpected value: " + this); };
}
} }
} }

@ -32,7 +32,7 @@ public interface Uniform {
default void register(@NotNull Object... annotated) { default void register(@NotNull Object... annotated) {
register(Arrays.stream(annotated) register(Arrays.stream(annotated)
.map(c -> c instanceof Command ? (Command) c : new Command.AnnotatedCommand(c)) .map(c -> c instanceof Command cmd ? cmd : new Command.AnnotatedCommand(c))
.toArray(Command[]::new)); .toArray(Command[]::new));
} }

@ -50,7 +50,7 @@ public final class ArgumentElement<S, T> implements CommandElement<S> {
@Override @Override
@NotNull @NotNull
public ArgumentBuilder<S, ?> toBuilder() { public ArgumentBuilder<S, ?> toBuilder() {
RequiredArgumentBuilder<S, T> builder = RequiredArgumentBuilder.<S, T>argument(this.name, this.type); var builder = RequiredArgumentBuilder.<S, T>argument(this.name, this.type);
if (this.suggestionProvider != null) builder.suggests(this.suggestionProvider); if (this.suggestionProvider != null) builder.suggests(this.suggestionProvider);
return builder; return builder;
} }

@ -23,12 +23,9 @@ package net.william278.uniform.element;
import com.mojang.brigadier.builder.ArgumentBuilder; import com.mojang.brigadier.builder.ArgumentBuilder;
import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import lombok.Value;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@Value public record LiteralElement<S>(@NotNull String name) implements CommandElement<S> {
public class LiteralElement<S> implements CommandElement<S> {
@NotNull String name;
@Override @Override
@NotNull @NotNull

@ -1,40 +0,0 @@
/*
* This file is part of Uniform, licensed under the GNU General Public License v3.0.
*
* Copyright (c) Tofaa2
* Copyright (c) William278 <will27528@gmail.com>
* Copyright (c) contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.william278.uniform.util;
import lombok.experimental.UtilityClass;
@UtilityClass
public class StringUtil {
public static boolean isBlank(String $this) {
final int strLen = $this.length();
if (strLen == 0) {
return true;
}
for (int i = 0; i < strLen; i++) {
if (!Character.isWhitespace($this.charAt(i))) {
return false;
}
}
return true;
}
}

@ -21,7 +21,6 @@
package net.william278.uniform; package net.william278.uniform;
import com.google.common.collect.ImmutableList;
import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.william278.uniform.element.ArgumentElement; import net.william278.uniform.element.ArgumentElement;
@ -39,7 +38,7 @@ public class ExtendedCommand extends Command {
public ExtendedCommand() { public ExtendedCommand() {
super("example"); super("example");
setDescription("An example command for Uniform"); setDescription("An example command for Uniform");
setAliases(ImmutableList.of("helloworld")); setAliases(List.of("helloworld"));
setPermission(Permission.defaultIfOp("uniform.example")); setPermission(Permission.defaultIfOp("uniform.example"));
} }
@ -57,21 +56,9 @@ public class ExtendedCommand extends Command {
final CommandUser user = sub.getUser(ctx.getSource()); final CommandUser user = sub.getUser(ctx.getSource());
final IceCreamFlavor flavor = ctx.getArgument("flavor", IceCreamFlavor.class); final IceCreamFlavor flavor = ctx.getArgument("flavor", IceCreamFlavor.class);
switch (flavor) { switch (flavor) {
case VANILLA: { case VANILLA -> user.getAudience().sendMessage(Component.text("Vanilla ice cream is fine!"));
user.getAudience().sendMessage(Component.text("Vanilla ice cream is fine!")); case CHOCOLATE -> user.getAudience().sendMessage(Component.text("Chocolate ice cream is kino!"));
break; case STRAWBERRY -> user.getAudience().sendMessage(Component.text("Strawberry ice cream is ok..."));
}
case CHOCOLATE: {
user.getAudience().sendMessage(Component.text("Chocolate ice cream is kino!"));
break;
}
case STRAWBERRY: {
user.getAudience().sendMessage(Component.text("Strawberry ice cream is ok..."));
break;
}
default: {
// do nothing
}
} }
}, exampleCustomArg())); }, exampleCustomArg()));
} }

@ -27,7 +27,6 @@ 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.*; import net.william278.uniform.*;
import net.william278.uniform.util.StringUtil;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.CommandException; import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -88,14 +87,14 @@ public class LegacyPaperCommand extends BaseCommand<CommandSender> {
this.setAliases(command.getAliases()); this.setAliases(command.getAliases());
this.setUsage(getUsageText()); this.setUsage(getUsageText());
if (permission != null) { if (permission != null) {
this.setPermission(permission.getNode()); this.setPermission(permission.node());
} }
} }
@NotNull @NotNull
private String getUsageText() { private String getUsageText() {
return dispatcher.getSmartUsage(dispatcher.getRoot(), Bukkit.getConsoleSender()).values().stream() return dispatcher.getSmartUsage(dispatcher.getRoot(), Bukkit.getConsoleSender()).values().stream()
.map("/"::concat).collect(Collectors.joining("\n")); .map("/%s"::formatted).collect(Collectors.joining("\n"));
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@ -127,16 +126,13 @@ public class LegacyPaperCommand extends BaseCommand<CommandSender> {
dispatcher.parse(passed, sender), dispatcher.parse(passed, sender),
passed.length() // Spigot API limitation - we can only TAB complete the full text length :( passed.length() // Spigot API limitation - we can only TAB complete the full text length :(
) )
.thenApply(suggestions -> suggestions.getList() .thenApply(suggestions -> suggestions.getList().stream().map(Suggestion::getText).toList())
.stream()
.map(Suggestion::getText)
.collect(Collectors.toList()))
.join(); .join();
} }
@Override @Override
public boolean testPermissionSilent(@NotNull CommandSender target) { public boolean testPermissionSilent(@NotNull CommandSender target) {
if (permission == null || StringUtil.isBlank(permission.getNode())) { if (permission == null || permission.node().isBlank()) {
return true; return true;
} }
return new LegacyPaperCommandUser(target).checkPermission(permission); return new LegacyPaperCommandUser(target).checkPermission(permission);
@ -144,10 +140,7 @@ public class LegacyPaperCommand extends BaseCommand<CommandSender> {
@NotNull @NotNull
private String getInput(@NotNull String[] args) { private String getInput(@NotNull String[] args) {
if (args.length == 0) { return args.length == 0 ? getName() : "%s %s".formatted(getName(), String.join(" ", args));
return getName();
}
return getName() + " " + String.join(" ", args);
} }
} }

@ -21,7 +21,6 @@
package net.william278.uniform.paper; package net.william278.uniform.paper;
import lombok.Value;
import net.kyori.adventure.audience.Audience; import net.kyori.adventure.audience.Audience;
import net.william278.uniform.CommandUser; import net.william278.uniform.CommandUser;
import net.william278.uniform.Permission; import net.william278.uniform.Permission;
@ -33,10 +32,7 @@ import org.jetbrains.annotations.Nullable;
import java.util.UUID; import java.util.UUID;
@Value public record LegacyPaperCommandUser(@NotNull CommandSender sender) implements CommandUser {
public class LegacyPaperCommandUser implements CommandUser {
@NotNull CommandSender sender;
@Override @Override
@NotNull @NotNull
@ -52,15 +48,15 @@ public class LegacyPaperCommandUser implements CommandUser {
@Override @Override
@Nullable @Nullable
public UUID getUuid() { public UUID getUuid() {
return sender instanceof Player ? ((Player) sender).getUniqueId() : null; return sender instanceof Player player ? player.getUniqueId() : null;
} }
@Override @Override
public boolean checkPermission(@NotNull Permission permission) { public boolean checkPermission(@NotNull Permission permission) {
if (sender.isPermissionSet(permission.getNode())) { if (sender.isPermissionSet(permission.node())) {
return sender.hasPermission(permission.getNode()); return sender.hasPermission(permission.node());
} }
return permission.getDefaultValue().check( return permission.defaultValue().check(
sender.isOp() || sender instanceof ConsoleCommandSender sender.isOp() || sender instanceof ConsoleCommandSender
); );
} }

@ -21,7 +21,6 @@
package net.william278.uniform.paper; package net.william278.uniform.paper;
import com.google.common.collect.ImmutableList;
import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.CommandSyntaxException;
import io.papermc.paper.command.brigadier.CommandSourceStack; import io.papermc.paper.command.brigadier.CommandSourceStack;
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents; import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents;
@ -39,7 +38,6 @@ import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors;
@SuppressWarnings({"unused", "UnstableApiUsage"}) @SuppressWarnings({"unused", "UnstableApiUsage"})
public class PaperCommand extends BaseCommand<CommandSourceStack> { public class PaperCommand extends BaseCommand<CommandSourceStack> {
@ -94,11 +92,11 @@ public class PaperCommand extends BaseCommand<CommandSourceStack> {
if (playerName.equals("@a")) { if (playerName.equals("@a")) {
return Bukkit.getOnlinePlayers(); return Bukkit.getOnlinePlayers();
} }
Player player = Bukkit.getPlayer(playerName); var player = Bukkit.getPlayer(playerName);
if (player == null) { if (player == null) {
throw CommandSyntaxException.BUILT_IN_EXCEPTIONS.dispatcherUnknownArgument().createWithContext(reader); throw CommandSyntaxException.BUILT_IN_EXCEPTIONS.dispatcherUnknownArgument().createWithContext(reader);
} }
return ImmutableList.of(player); return List.of(player);
}, (context, builder) -> { }, (context, builder) -> {
builder.suggest("@a"); builder.suggest("@a");
for (Player player : Bukkit.getOnlinePlayers()) { for (Player player : Bukkit.getOnlinePlayers()) {
@ -114,9 +112,9 @@ public class PaperCommand extends BaseCommand<CommandSourceStack> {
public List<CommandSyntax<CommandSourceStack>> getSyntaxes() { public List<CommandSyntax<CommandSourceStack>> getSyntaxes() {
return super.getSyntaxes().stream().map( return super.getSyntaxes().stream().map(
syntax -> new CommandSyntax<>( syntax -> new CommandSyntax<>(
syntax.getCondition(), syntax.condition(),
syntax.getExecutor(), syntax.executor(),
syntax.getElements().stream() syntax.elements().stream()
.filter(e -> e instanceof ArgumentElement) .filter(e -> e instanceof ArgumentElement)
.map(e -> (ArgumentElement<?, ?>) e) .map(e -> (ArgumentElement<?, ?>) e)
.map(e -> e.custom() ? new ArgumentElement<>( .map(e -> e.custom() ? new ArgumentElement<>(
@ -125,9 +123,9 @@ public class PaperCommand extends BaseCommand<CommandSourceStack> {
e.suggestionProvider() e.suggestionProvider()
) : e) ) : e)
.map(e -> (CommandElement<CommandSourceStack>) e) .map(e -> (CommandElement<CommandSourceStack>) e)
.collect(Collectors.toList()) .toList()
) )
).collect(Collectors.toList()); ).toList();
} }
@Override @Override

@ -22,7 +22,6 @@
package net.william278.uniform.paper; package net.william278.uniform.paper;
import io.papermc.paper.command.brigadier.CommandSourceStack; import io.papermc.paper.command.brigadier.CommandSourceStack;
import lombok.Value;
import net.kyori.adventure.audience.Audience; import net.kyori.adventure.audience.Audience;
import net.william278.uniform.CommandUser; import net.william278.uniform.CommandUser;
import net.william278.uniform.Permission; import net.william278.uniform.Permission;
@ -33,9 +32,8 @@ import org.jetbrains.annotations.Nullable;
import java.util.UUID; import java.util.UUID;
@SuppressWarnings("UnstableApiUsage") @SuppressWarnings("UnstableApiUsage")
@Value public record PaperCommandUser(@NotNull CommandSourceStack source) implements CommandUser {
public class PaperCommandUser implements CommandUser {
@NotNull CommandSourceStack source;
@Override @Override
@NotNull @NotNull
@ -57,10 +55,10 @@ public class PaperCommandUser implements CommandUser {
@Override @Override
public boolean checkPermission(@NotNull Permission permission) { public boolean checkPermission(@NotNull Permission permission) {
if (source.getSender().isPermissionSet(permission.getNode())) { if (source.getSender().isPermissionSet(permission.node())) {
return source.getSender().hasPermission(permission.getNode()); return source.getSender().hasPermission(permission.node());
} }
return permission.getDefaultValue().check( return permission.defaultValue().check(
source.getSender().isOp() || source.getSender() instanceof ConsoleCommandSender source.getSender().isOp() || source.getSender() instanceof ConsoleCommandSender
); );
} }

@ -35,7 +35,6 @@ import java.util.Arrays;
import java.util.Locale; import java.util.Locale;
import java.util.Set; import java.util.Set;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
/** /**
@ -109,8 +108,7 @@ public final class PaperUniform implements Uniform {
// Register with the legacy API // Register with the legacy API
plugin.getServer().getCommandMap().registerAll( plugin.getServer().getCommandMap().registerAll(
plugin.getName().toLowerCase(Locale.ENGLISH).replaceAll("[^a-z0-9_]", ""), plugin.getName().toLowerCase(Locale.ENGLISH).replaceAll("[^a-z0-9_]", ""),
s.map(c -> (LegacyPaperCommand) c).map(c -> (org.bukkit.command.Command) c.getImpl(this)) s.map(c -> (LegacyPaperCommand) c).map(c -> (org.bukkit.command.Command) c.getImpl(this)).toList()
.collect(Collectors.toList())
); );
} }

@ -12,14 +12,14 @@ include(
// Server Plugins // Server Plugins
'paper', 'paper',
'bukkit', 'bukkit',
// 'sponge-11', 'sponge-11',
// Proxy Plugins // Proxy Plugins
'velocity', 'velocity',
// Fabric Server-Side Mods // Fabric Server-Side Mods
// 'fabric-1.20.1', 'fabric-1.20.1',
// 'fabric-1.21', 'fabric-1.21',
// Example plugin // Example plugin
'example-plugin' 'example-plugin'

@ -24,7 +24,6 @@ package net.william278.uniform.velocity;
import com.velocitypowered.api.command.CommandSource; import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.permission.Tristate; import com.velocitypowered.api.permission.Tristate;
import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.Player;
import lombok.Value;
import net.kyori.adventure.audience.Audience; import net.kyori.adventure.audience.Audience;
import net.william278.uniform.CommandUser; import net.william278.uniform.CommandUser;
import net.william278.uniform.Permission; import net.william278.uniform.Permission;
@ -33,10 +32,7 @@ import org.jetbrains.annotations.Nullable;
import java.util.UUID; import java.util.UUID;
@Value public record VelocityCommandUser(CommandSource source) implements CommandUser {
public class VelocityCommandUser implements CommandUser {
CommandSource source;
@Override @Override
@NotNull @NotNull
@ -58,10 +54,10 @@ public class VelocityCommandUser implements CommandUser {
@Override @Override
public boolean checkPermission(@NotNull Permission permission) { public boolean checkPermission(@NotNull Permission permission) {
if (source.getPermissionValue(permission.getNode()) != Tristate.UNDEFINED) { if (source.getPermissionValue(permission.node()) != Tristate.UNDEFINED) {
return source.getPermissionValue(permission.getNode()) == Tristate.TRUE; return source.getPermissionValue(permission.node()) == Tristate.TRUE;
} }
return permission.getDefaultValue().check(source.hasPermission(permission.getNode())); return permission.defaultValue().check(source.hasPermission(permission.node()));
} }
} }

Loading…
Cancel
Save