Compare commits

..

1 Commits

Author SHA1 Message Date
dependabot[bot] 43fc7e0521
deps: bump net.fabricmc.fabric-api:fabric-api
Bumps [net.fabricmc.fabric-api:fabric-api](https://github.com/FabricMC/fabric) from 0.92.2+1.20.1 to 0.102.2+1.21.2.
- [Release notes](https://github.com/FabricMC/fabric/releases)
- [Commits](https://github.com/FabricMC/fabric/commits)

---
updated-dependencies:
- dependency-name: net.fabricmc.fabric-api:fabric-api
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

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

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

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

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

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

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

@ -21,7 +21,6 @@
package net.william278.uniform;
import com.google.common.collect.ImmutableList;
import com.mojang.brigadier.arguments.*;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.suggestion.SuggestionProvider;
@ -115,7 +114,7 @@ public abstract class BaseCommand<S> {
@SafeVarargs
public final void addConditionalSyntax(@Nullable Predicate<S> condition, @NotNull CommandExecutor<S> executor,
@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);
}

@ -21,13 +21,10 @@
package net.william278.uniform;
import com.google.common.collect.ImmutableList;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.Value;
import net.william278.uniform.annotations.Argument;
import net.william278.uniform.annotations.CommandDescription;
import net.william278.uniform.annotations.CommandNode;
@ -42,7 +39,6 @@ import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.function.Predicate;
@ -55,7 +51,7 @@ import static net.william278.uniform.CommandExecutor.methodToExecutor;
public abstract class Command implements CommandProvider {
private final String name;
private List<String> aliases = Collections.emptyList();
private List<String> aliases = List.of();
private String description = "";
@Getter(AccessLevel.NONE)
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");
}
this.name = node.value();
this.aliases = ImmutableList.copyOf(node.aliases());
this.aliases = List.of(node.aliases());
this.description = node.description();
this.scope = node.scope();
Permission.annotated(node.permission()).ifPresent(this::setPermission);
@ -91,16 +87,11 @@ public abstract class Command implements CommandProvider {
}
public boolean contains(@NotNull CommandUser user) {
switch (this) {
case IN_GAME:
return !user.isConsole();
case CONSOLE:
return user.isConsole();
case ALL:
return true;
default:
throw new IllegalArgumentException("Unknown execution scope: " + this);
}
return switch (this) {
case IN_GAME -> !user.isConsole();
case CONSOLE -> user.isConsole();
case ALL -> true;
};
}
}
@ -203,15 +194,8 @@ public abstract class Command implements CommandProvider {
}
}
@Value
@RequiredArgsConstructor
public static class SubCommand {
@NotNull String name;
@NotNull List<String> aliases;
@Nullable Permission permission;
@NotNull ExecutionScope scope;
@NotNull CommandProvider provider;
public record 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,
@NotNull CommandProvider 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) {
this(name, Collections.emptyList(), permission, ExecutionScope.ALL, provider);
this(name, List.of(), permission, ExecutionScope.ALL, 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) {
return (context) -> {
try {
method.invoke(instance, private$injectParams(method, context, cmd));
method.invoke(instance, injectParams(method, context, cmd));
} catch (IllegalAccessException | InvocationTargetException e) {
throw new IllegalStateException("Failed to invoke command executor from annotated method", e);
}
@ -47,7 +47,7 @@ public interface CommandExecutor<S> {
}
@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) {
final Object[] params = new Object[method.getParameterCount()];
for (int i = 0; i < method.getParameterCount(); i++) {

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

@ -21,9 +21,6 @@
package net.william278.uniform;
import com.google.common.collect.ImmutableList;
import lombok.RequiredArgsConstructor;
import lombok.Value;
import net.william278.uniform.element.CommandElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -34,13 +31,8 @@ import java.util.Map;
import static net.william278.uniform.Graph.commandToElement;
@Value
@RequiredArgsConstructor
public class ConversionNode<S> {
@NotNull CommandElement<S> element;
@Nullable Execution<S> execution;
@NotNull Map<CommandElement<S>, ConversionNode<S>> nextMap;
record 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) {
ConversionNode<S> root = new ConversionNode<>(commandToElement(command), Execution.fromCommand(command));
@ -48,8 +40,8 @@ public class ConversionNode<S> {
for (CommandSyntax<S> syntax : command.getSyntaxes()) {
ConversionNode<S> syntaxNode = root;
for (CommandElement<S> element : syntax.getElements()) {
boolean last = element == syntax.getElements().get(syntax.getElements().size() - 1);
for (CommandElement<S> element : syntax.elements()) {
boolean last = element == syntax.elements().get(syntax.elements().size() - 1);
syntaxNode = syntaxNode.nextMap.computeIfAbsent(element, e -> {
Execution<S> execution = last ? Execution.fromSyntax(syntax) : null;
return new ConversionNode<>(e, execution);
@ -77,7 +69,7 @@ public class ConversionNode<S> {
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;
import com.mojang.brigadier.builder.ArgumentBuilder;
import lombok.Value;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -30,16 +29,11 @@ import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.function.Predicate;
@Value
public class Execution<S> implements Predicate<S> {
record Execution<S>(@NotNull Predicate<S> predicate, @Nullable CommandExecutor<S> defaultExecutor,
@Nullable CommandExecutor<S> executor, @Nullable Predicate<S> condition) implements Predicate<S> {
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
static <S> Execution<S> fromCommand(@NotNull BaseCommand<S> command) {
CommandExecutor<S> defaultExecutor = command.getDefaultExecutor();
@ -48,9 +42,9 @@ public class Execution<S> implements Predicate<S> {
CommandExecutor<S> executor = defaultExecutor;
Predicate<S> condition = defaultCondition;
for (CommandSyntax<S> syntax : command.getSyntaxes()) {
if (!syntax.getElements().isEmpty()) continue;
executor = syntax.getExecutor();
condition = syntax.getCondition();
if (!syntax.elements().isEmpty()) continue;
executor = syntax.executor();
condition = syntax.condition();
break;
}
@ -59,8 +53,8 @@ public class Execution<S> implements Predicate<S> {
@NotNull
static <S> Execution<S> fromSyntax(@NotNull CommandSyntax<S> syntax) {
CommandExecutor<S> executor = syntax.getExecutor();
Predicate<S> condition = syntax.getCondition();
CommandExecutor<S> executor = syntax.executor();
Predicate<S> condition = syntax.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.tree.CommandNode;
import com.mojang.brigadier.tree.LiteralCommandNode;
import lombok.Value;
import net.william278.uniform.element.CommandElement;
import net.william278.uniform.element.LiteralElement;
import org.jetbrains.annotations.NotNull;
@Value
public class Graph<S> {
@NotNull Node<S> root;
record Graph<S>(@NotNull Node<S> root) {
static <S> @NotNull Graph<S> create(@NotNull BaseCommand<S> command) {
return new Graph<>(Node.command(command));
@ -44,10 +41,10 @@ public class Graph<S> {
@NotNull
LiteralCommandNode<S> 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.");
}
return (LiteralCommandNode<S>) node;
return literalNode;
}
@NotNull
@ -55,7 +52,7 @@ public class Graph<S> {
final LiteralArgumentBuilder<S> builder = LiteralArgumentBuilder.literal(name);
final CommandNode<S> command = this.root.build();
builder.executes(command.getCommand());
this.root.getChildren().forEach(child -> builder.then(child.build()));
this.root.children().forEach(child -> builder.then(child.build()));
return builder;
}

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

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

@ -32,7 +32,7 @@ public interface Uniform {
default void register(@NotNull Object... 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));
}

@ -50,7 +50,7 @@ public final class ArgumentElement<S, T> implements CommandElement<S> {
@Override
@NotNull
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);
return builder;
}

@ -23,12 +23,9 @@ package net.william278.uniform.element;
import com.mojang.brigadier.builder.ArgumentBuilder;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import lombok.Value;
import org.jetbrains.annotations.NotNull;
@Value
public class LiteralElement<S> implements CommandElement<S> {
@NotNull String name;
public record LiteralElement<S>(@NotNull String name) implements CommandElement<S> {
@Override
@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;
import com.google.common.collect.ImmutableList;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.kyori.adventure.text.Component;
import net.william278.uniform.element.ArgumentElement;
@ -39,7 +38,7 @@ public class ExtendedCommand extends Command {
public ExtendedCommand() {
super("example");
setDescription("An example command for Uniform");
setAliases(ImmutableList.of("helloworld"));
setAliases(List.of("helloworld"));
setPermission(Permission.defaultIfOp("uniform.example"));
}
@ -57,21 +56,9 @@ public class ExtendedCommand extends Command {
final CommandUser user = sub.getUser(ctx.getSource());
final IceCreamFlavor flavor = ctx.getArgument("flavor", IceCreamFlavor.class);
switch (flavor) {
case VANILLA: {
user.getAudience().sendMessage(Component.text("Vanilla ice cream is fine!"));
break;
}
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
}
case VANILLA -> user.getAudience().sendMessage(Component.text("Vanilla ice cream is fine!"));
case CHOCOLATE -> user.getAudience().sendMessage(Component.text("Chocolate ice cream is kino!"));
case STRAWBERRY -> user.getAudience().sendMessage(Component.text("Strawberry ice cream is ok..."));
}
}, exampleCustomArg()));
}

@ -9,7 +9,7 @@ dependencies {
mappings 'net.fabricmc:yarn:1.20.1+build.10:v2'
modCompileOnly 'net.fabricmc:fabric-loader:0.15.11'
modCompileOnly 'net.fabricmc.fabric-api:fabric-api:0.92.2+1.20.1'
modCompileOnly 'net.fabricmc.fabric-api:fabric-api:0.102.2+'
modImplementation include('me.lucko:fabric-permissions-api:0.3.1')
modCompileOnly 'org.projectlombok:lombok:1.18.32'

@ -9,7 +9,7 @@ dependencies {
mappings 'net.fabricmc:yarn:1.21+build.7:v2'
modCompileOnly 'net.fabricmc:fabric-loader:0.15.11'
modCompileOnly 'net.fabricmc.fabric-api:fabric-api:0.100.4+1.21'
modCompileOnly 'net.fabricmc.fabric-api:fabric-api:0.102.2+'
modImplementation include('me.lucko:fabric-permissions-api:0.3.1')
modCompileOnly 'org.projectlombok:lombok:1.18.32'

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

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

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

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

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

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

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