feat: bukkit support, x-plat sub-commands

Also changes how the fabric modules are published
dependabot/gradle/org.projectlombok-lombok-1.18.34
William 5 months ago
parent d78847550c
commit 331f54407b
No known key found for this signature in database

@ -17,23 +17,17 @@
Uniform _currently_ targets the following platforms:
Please note Uniform on Fabric requires [adventure-platform-fabric](https://docs.advntr.dev/platform/fabric.html) and the [Fabric API](https://fabricmc.net/) as dependencies.
| Platform | Artifact | Minecraft | Java |
|---------------|-------------------------|:----------:|:------:|
|---------------|--------------------|:----------:|:------:|
| Common | `uniform-common` | - | \>`17` |
| Paper | `uniform-paper` | \>`1.20.6` | \>`21` |
| Velocity | `uniform-velocity` | \>`3.3.0` | \>`17` |
| Fabric 1.20.1 | `uniform-fabric-1_20_1` | =`1.20.1` | \>`17` |
| Fabric 1.20.6 | `uniform-fabric-1_20_6` | =`1.20.6` | \>`21` |
Uniform _plans_ to support the following platforms in the future:
| Platform | Version | Java |
|----------|------------|:------:|
| Spigot | \>`1.17.1` | \>`17` |
| Sponge 8 | =`1.19.4` | \>`17` |
| Fabric 1.20.1 | `uniform-fabric` | =`1.20.1` | \>`17` |
| Fabric 1.20.6 | `uniform-fabric` | =`1.20.6` | \>`21` |
| Bukkit | `uniform-bukkit` | \>`1.17.1` | \>`17` |
* **Fabric:** Please note Uniform on Fabric requires [adventure-platform-fabric](https://docs.advntr.dev/platform/fabric.html) and the [Fabric API](https://fabricmc.net/) as dependencies. To target Fabric, use `uniform-fabric` as the artifact and `<uniform_version>+<minecraft_version>` as the version (e.g. `net.william278.uniform:uniform-fabric:1.0+1.20.1`).
* **Sponge**: Support for Sponge 8 is also planned in a future version.
## Setup
Uniform is available [on Maven](https://repo.william278.net/#/releases/net/william278/uniform/). You can browse the Javadocs [here](https://repo.william278.net/javadoc/releases/net/william278/uniform/latest).

@ -60,6 +60,7 @@ allprojects {
maven { url 'https://repo.papermc.io/repository/maven-public/' }
maven { url 'https://libraries.minecraft.net/' }
maven { url 'https://maven.fabricmc.net/' }
maven { url 'https://mvn-repo.arim.space/lesser-gpl3/' }
}
dependencies {
@ -146,6 +147,19 @@ subprojects {
}
}
if (['bukkit'].contains(project.name)) {
publications {
mavenJavaBukkit(MavenPublication) {
groupId = 'net.william278.uniform'
artifactId = 'uniform-bukkit'
version = "$rootProject.version"
artifact shadowJar
artifact sourcesJar
artifact javadocJar
}
}
}
if (['velocity'].contains(project.name)) {
publications {
mavenJavaVelocity(MavenPublication) {
@ -158,24 +172,26 @@ subprojects {
}
}
}
if (['fabric-1.20.1'].contains(project.name)) {
publications {
mavenJavaFabric1_20_1(MavenPublication) {
groupId = 'net.william278.uniform'
artifactId = 'uniform-fabric-1_20_1'
version = "$rootProject.version"
artifactId = 'uniform-fabric'
version = "${rootProject.version}+1.20.1"
artifact shadowJar
artifact sourcesJar
artifact javadocJar
}
}
}
if (['fabric-1.20.6'].contains(project.name)) {
publications {
mavenJavaFabric1_20_6(MavenPublication) {
groupId = 'net.william278.uniform'
artifactId = 'uniform-fabric-1_20_6'
version = "$rootProject.version"
artifactId = 'uniform-fabric'
version = "${rootProject.version}+1.20.6"
artifact shadowJar
artifact sourcesJar
artifact javadocJar

@ -0,0 +1,16 @@
plugins {
id 'java-library'
id 'maven-publish'
}
dependencies {
api project(path: ':common')
implementation 'net.kyori:adventure-platform-bukkit:4.3.3'
implementation 'space.arim.morepaperlib:morepaperlib:0.4.3'
compileOnlyApi 'org.spigotmc:spigot-api:1.17.1-R0.1-SNAPSHOT'
compileOnly 'org.projectlombok:lombok:1.18.32'
annotationProcessor 'org.projectlombok:lombok:1.18.32'
}

@ -0,0 +1,153 @@
/*
* 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.bukkit;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.suggestion.Suggestion;
import com.mojang.brigadier.tree.LiteralCommandNode;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.william278.uniform.BaseCommand;
import net.william278.uniform.Command;
import net.william278.uniform.CommandUser;
import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.List;
@SuppressWarnings("unused")
public class BukkitCommand extends BaseCommand<CommandSender> {
private final JavaPlugin plugin;
private BukkitAudiences audiences;
public BukkitCommand(@NotNull Command command, @NotNull JavaPlugin plugin) {
super(command);
this.plugin = plugin;
}
public BukkitCommand(@NotNull JavaPlugin plugin, @NotNull String name, @NotNull String description,
@NotNull List<String> aliases) {
super(name, description, aliases);
this.plugin = plugin;
}
public BukkitCommand(@NotNull JavaPlugin plugin, @NotNull String name, @NotNull List<String> aliases) {
super(name, aliases);
this.plugin = plugin;
}
@NotNull
Impl getImpl() {
return new Impl(this);
}
static final class Impl extends org.bukkit.command.Command {
private static final int COMMAND_SUCCESS = com.mojang.brigadier.Command.SINGLE_SUCCESS;
private final LiteralCommandNode<CommandSender> commandNode;
private final CommandDispatcher<CommandSender> dispatcher;
private final JavaPlugin plugin;
private BukkitAudiences audiences;
public Impl(@NotNull BukkitCommand command) {
super(command.getName());
this.audiences = command.audiences;
this.plugin = command.plugin;
// Register command, setup description and aliases
this.dispatcher = new CommandDispatcher<>();
this.commandNode = this.dispatcher.register(command.build().createBuilder());
this.setDescription(command.getDescription());
this.setAliases(command.getAliases());
}
@Override
public boolean execute(@NotNull CommandSender commandSender, @NotNull String alias, @NotNull String[] args) {
try {
final String string = getInput(alias, args);
System.out.println("Usage: \"" + Arrays.toString(dispatcher.getAllUsage(commandNode, commandSender, false)) + "\"");
return dispatcher.execute(string, commandSender) == COMMAND_SUCCESS;
} catch (CommandSyntaxException e) {
getAudience(commandSender).sendMessage(Component
.translatable("command.context.parse_error", NamedTextColor.RED)
.arguments(
Component.text(e.getRawMessage().getString()),
Component.text(e.getCursor()),
Component.text(e.getContext())
));
return false;
} catch (CommandException e) {
getAudience(commandSender).sendMessage(Component.text(e.getMessage(), NamedTextColor.RED));
return true;
}
}
@NotNull
@Override
public List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args)
throws IllegalArgumentException {
final String passed = getInput(alias, args);
return dispatcher.getCompletionSuggestions(
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).toList())
.join();
}
@NotNull
private Audience getAudience(@NotNull CommandSender sender) {
if (audiences == null) {
audiences = BukkitAudiences.create(plugin);
}
return audiences.sender(sender);
}
@NotNull
private String getInput(@NotNull String alias, @NotNull String[] args) {
return args.length == 0 ? alias : "%s %s".formatted(alias, String.join(" ", args));
}
}
@Override
@NotNull
protected CommandUser getUser(@NotNull Object user) {
if (audiences == null) {
audiences = BukkitAudiences.create(plugin);
}
return new BukkitCommandUser((CommandSender) user, audiences);
}
@Override
public void addSubCommand(@NotNull Command command) {
addSubCommand(new BukkitCommand(command, plugin));
}
}

@ -19,33 +19,35 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.william278.uniform;
package net.william278.uniform.bukkit;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.william278.uniform.CommandUser;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class ExampleCrossPlatCommand implements Command {
import java.util.UUID;
public record BukkitCommandUser(@NotNull CommandSender sender, @NotNull BukkitAudiences adv) implements CommandUser {
@Override
@NotNull
public String getName() {
return "example-crossplat";
public Audience getAudience() {
return adv.sender(sender);
}
@Override
@NotNull
public String getDescription() {
return "An example cross-platform command";
public String getName() {
return sender.getName();
}
@Override
public <S> void provide(@NotNull BaseCommand<S> command) {
command.setCondition(source -> true);
command.setDefaultExecutor((ctx) -> {
final Audience user = command.getUser(ctx.getSource()).getAudience();
user.sendMessage(Component.text("Hello, world!"));
});
@Nullable
public UUID getUuid() {
return sender instanceof Player player ? player.getUniqueId() : null;
}
}

@ -0,0 +1,110 @@
/*
* 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.bukkit;/*
* 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/>.
*/
import net.william278.uniform.Command;
import net.william278.uniform.Uniform;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import space.arim.morepaperlib.MorePaperLib;
import space.arim.morepaperlib.commands.CommandRegistration;
import java.util.Arrays;
import java.util.Locale;
/**
* A class for registering commands with the Bukkit server's CommandMap
*
* @since 1.0
*/
public final class BukkitUniform implements Uniform<CommandSender, BukkitCommand> {
private static BukkitUniform INSTANCE;
private final JavaPlugin plugin;
private final CommandRegistration registrar;
private BukkitUniform(@NotNull JavaPlugin plugin) {
this.plugin = plugin;
this.registrar = new MorePaperLib(plugin).commandRegistration();
}
/**
* Get the BukkitUniform instance for registering commands
*
* @param plugin The plugin instance
* @return BukkitUniform instance
* @since 1.0
*/
@NotNull
public static BukkitUniform getInstance(@NotNull JavaPlugin plugin) {
return INSTANCE != null ? INSTANCE : (INSTANCE = new BukkitUniform(plugin));
}
/**
* Register a command to be added to the server's command map
*
* @param commands The commands to register
* @since 1.0
*/
@Override
public void register(@NotNull BukkitCommand... commands) {
registrar.getServerCommandMap().registerAll(
plugin.getName().toLowerCase(Locale.ENGLISH),
Arrays.stream(commands).map(c -> (org.bukkit.command.Command) c.getImpl()).toList()
);
}
/**
* Register command(s) to be added to the server's command map
*
* @param commands The commands to register
* @since 1.0
*/
@Override
public void register(@NotNull Command... commands) {
register(Arrays.stream(commands)
.map(command -> new BukkitCommand(command, plugin))
.toArray(BukkitCommand[]::new));
}
}

@ -75,91 +75,112 @@ public abstract class BaseCommand<S> {
private final List<BaseCommand<S>> subCommands = new ArrayList<>();
@NotNull
protected abstract CommandUser getUser(@NotNull S user);
protected abstract CommandUser getUser(@NotNull Object user);
protected final void setCondition(@NotNull Predicate<S> condition) {
public final void setCondition(@NotNull Predicate<S> condition) {
this.condition = condition;
}
protected final void setDefaultExecutor(@NotNull CommandExecutor<S> executor) {
public final void setDefaultExecutor(@NotNull CommandExecutor<S> executor) {
this.defaultExecutor = executor;
}
@SafeVarargs
protected 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) {
var syntax = new CommandSyntax<>(condition, executor, List.of(elements));
this.syntaxes.add(syntax);
}
@SafeVarargs
protected final void addSyntax(@NotNull CommandExecutor<S> executor, @NotNull CommandElement<S>... elements) {
public final void addSyntax(@NotNull CommandExecutor<S> executor, @NotNull CommandElement<S>... elements) {
this.addConditionalSyntax(null, executor, elements);
}
protected final void addSubCommand(@NotNull BaseCommand<S> command) {
public final void addSubCommand(@NotNull BaseCommand<S> command) {
this.subCommands.add(command);
}
public final void addSubCommand(@NotNull String name, @NotNull CommandProvider provider) {
this.addSubCommand(new Command.SubCommand(name, provider).command());
}
public final void addSubCommand(@NotNull String name, @NotNull List<String> aliases,
@NotNull CommandProvider provider) {
this.addSubCommand(new Command.SubCommand(name, provider, aliases).command());
}
public abstract void addSubCommand(@NotNull Command command);
@NotNull
public final LiteralCommandNode<S> build() {
return Graph.create(this).build();
}
@NotNull
protected static <S> LiteralElement<S> literalArg(@NotNull String name) {
public static <S> LiteralElement<S> literal(@NotNull String name) {
return new LiteralElement<>(name);
}
@NotNull
protected static <S> ArgumentElement<S, String> stringArg(@NotNull String name) {
return argument(name, StringArgumentType.string());
public static <S> ArgumentElement<S, String> greedyString(@NotNull String name) {
return arg(name, StringArgumentType.greedyString());
}
@NotNull
public static <S> ArgumentElement<S, String> string(@NotNull String name) {
return arg(name, StringArgumentType.string());
}
@NotNull
public static <S> ArgumentElement<S, String> word(@NotNull String name) {
return arg(name, StringArgumentType.word());
}
@NotNull
protected static <S> ArgumentElement<S, Integer> integerArg(@NotNull String name) {
return argument(name, IntegerArgumentType.integer());
public static <S> ArgumentElement<S, Integer> intNum(@NotNull String name) {
return arg(name, IntegerArgumentType.integer());
}
@NotNull
protected static <S> ArgumentElement<S, Integer> integerArg(@NotNull String name, int min) {
return argument(name, IntegerArgumentType.integer(min));
public static <S> ArgumentElement<S, Integer> intNum(@NotNull String name, int min) {
return arg(name, IntegerArgumentType.integer(min));
}
@NotNull
protected static <S> ArgumentElement<S, Integer> integerArg(@NotNull String name, int min, int max) {
return argument(name, IntegerArgumentType.integer(min, max));
public static <S> ArgumentElement<S, Integer> intNum(@NotNull String name, int min, int max) {
return arg(name, IntegerArgumentType.integer(min, max));
}
@NotNull
protected static <S> ArgumentElement<S, Float> floatArg(@NotNull String name) {
return argument(name, FloatArgumentType.floatArg());
public static <S> ArgumentElement<S, Float> floatNum(@NotNull String name) {
return arg(name, FloatArgumentType.floatArg());
}
@NotNull
protected static <S> ArgumentElement<S, Float> floatArg(@NotNull String name, float min) {
return argument(name, FloatArgumentType.floatArg(min));
public static <S> ArgumentElement<S, Float> floatNum(@NotNull String name, float min) {
return arg(name, FloatArgumentType.floatArg(min));
}
@NotNull
protected static <S> ArgumentElement<S, Float> floatArg(@NotNull String name, float min, float max) {
return argument(name, FloatArgumentType.floatArg(min, max));
public static <S> ArgumentElement<S, Float> floatNum(@NotNull String name, float min, float max) {
return arg(name, FloatArgumentType.floatArg(min, max));
}
@NotNull
protected static <S> ArgumentElement<S, Boolean> booleanArg(@NotNull String name) {
return argument(name, BoolArgumentType.bool());
public static <S> ArgumentElement<S, Boolean> bool(@NotNull String name) {
return arg(name, BoolArgumentType.bool());
}
@NotNull
protected static <S, T> ArgumentElement<S, T> argument(@NotNull String name, @NotNull ArgumentType<T> type,
public static <S, T> ArgumentElement<S, T> arg(@NotNull String name, @NotNull ArgumentType<T> type,
@Nullable SuggestionProvider<S> suggestionProvider) {
return new ArgumentElement<>(name, type, suggestionProvider);
}
@NotNull
protected static <S, T> ArgumentElement<S, T> argument(@NotNull String name, @NotNull ArgumentType<T> type) {
return argument(name, type, null);
public static <S, T> ArgumentElement<S, T> arg(@NotNull String name, @NotNull ArgumentType<T> type) {
return arg(name, type, null);
}
}

@ -21,25 +21,38 @@
package net.william278.uniform;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import org.jetbrains.annotations.NotNull;
import java.util.List;
public interface Command {
@Getter
@Setter
@RequiredArgsConstructor
@AllArgsConstructor
public abstract class Command implements CommandProvider {
@NotNull
String getName();
private final String name;
private String description = "";
private List<String> aliases = List.of();
@NotNull
default String getDescription() {
return "";
record SubCommand(@NotNull String name, @NotNull CommandProvider provider, @NotNull List<String> aliases) {
SubCommand(@NotNull String name, @NotNull CommandProvider provider) {
this(name, provider, List.of());
}
@NotNull
default List<String> getAliases() {
return List.of();
Command command() {
return new Command(name, "", aliases) {
@Override
public void provide(@NotNull BaseCommand<?> command) {
provider.provide(command);
}
};
}
}
<S> void provide(@NotNull BaseCommand<S> command);
}

@ -0,0 +1,10 @@
package net.william278.uniform;
import org.jetbrains.annotations.NotNull;
@FunctionalInterface
public interface CommandProvider {
void provide(@NotNull BaseCommand<?> command);
}

@ -0,0 +1,31 @@
/*
* 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;
public interface Uniform<S, T extends BaseCommand<S>> {
void register(Command... commands);
@SuppressWarnings("unchecked")
void register(T... commands);
}

@ -5,6 +5,7 @@ plugins {
dependencies {
implementation(project(":paper"))
// implementation(project(":bukkit"))
compileOnly 'io.papermc.paper:paper-api:1.20.6-R0.1-SNAPSHOT'
}

@ -21,21 +21,28 @@
package net.william278.uniform;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.william278.uniform.paper.PaperCommand;
import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import static net.william278.uniform.BaseCommand.greedyString;
@SuppressWarnings("UnstableApiUsage")
public class ExampleCommand extends PaperCommand {
public class ExampleCommand extends Command {
public ExampleCommand() {
super("example", "An example command", List.of("silly-command"));
addSyntax((context) -> {
context.getSource().getSender().sendMessage("Woah!!!!");
String arg = context.getArgument("message", String.class);
context.getSource().getSender().sendMessage(MiniMessage.miniMessage().deserialize(arg));
}, stringArg("message"));
super("example");
setDescription("An example command for Uniform");
}
@Override
public void provide(@NotNull BaseCommand<?> command) {
command.setDefaultExecutor((ctx) -> {
final CommandUser user = command.getUser(ctx.getSource());
user.getAudience().sendMessage(Component.text("Hello, World!"));
});
command.addSubCommand("message", (sub) -> sub.addSyntax((ctx) -> {
final CommandUser user = sub.getUser(ctx.getSource());
user.getAudience().sendMessage(Component.text(ctx.getArgument("message", String.class)));
}, greedyString("message")));
}
}

@ -31,7 +31,6 @@ public class UniformExample extends JavaPlugin {
public void onLoad() {
PaperUniform uniform = PaperUniform.getInstance(this);
uniform.register(new ExampleCommand());
uniform.register(new ExampleCrossPlatCommand());
}
}

@ -81,7 +81,13 @@ public class FabricCommand extends BaseCommand<ServerCommandSource> {
@Override
@NotNull
protected CommandUser getUser(@NotNull ServerCommandSource user) {
return new FabricCommandUser(user);
protected CommandUser getUser(@NotNull Object user) {
return new FabricCommandUser((ServerCommandSource) user);
}
@Override
public void addSubCommand(@NotNull Command command) {
addSubCommand(new FabricCommand(command));
}
}

@ -24,7 +24,9 @@ package net.william278.uniform.fabric;
import com.google.common.collect.Sets;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.minecraft.server.command.ServerCommandSource;
import net.william278.uniform.Command;
import net.william278.uniform.Uniform;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
@ -36,7 +38,7 @@ import java.util.Set;
*
* @since 1.0
*/
public final class FabricUniform {
public final class FabricUniform implements Uniform<ServerCommandSource, FabricCommand> {
private static FabricUniform INSTANCE;
@ -65,6 +67,7 @@ public final class FabricUniform {
* @param commands The commands to register
* @since 1.0
*/
@Override
public void register(@NotNull FabricCommand... commands) {
Collections.addAll(this.commands, commands);
}
@ -75,6 +78,7 @@ public final class FabricUniform {
* @param commands The commands to register
* @since 1.0
*/
@Override
public void register(@NotNull Command... commands) {
register(Arrays.stream(commands).map(FabricCommand::new).toArray(FabricCommand[]::new));
}

@ -81,8 +81,12 @@ public class FabricCommand extends BaseCommand<ServerCommandSource> {
@Override
@NotNull
protected CommandUser getUser(@NotNull ServerCommandSource user) {
return new FabricCommandUser(user);
protected CommandUser getUser(@NotNull Object user) {
return new FabricCommandUser((ServerCommandSource) user);
}
@Override
public void addSubCommand(@NotNull Command command) {
addSubCommand(new FabricCommand(command));
}
}

@ -24,7 +24,9 @@ package net.william278.uniform.fabric;
import com.google.common.collect.Sets;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.minecraft.server.command.ServerCommandSource;
import net.william278.uniform.Command;
import net.william278.uniform.Uniform;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
@ -36,7 +38,7 @@ import java.util.Set;
*
* @since 1.0
*/
public final class FabricUniform {
public final class FabricUniform implements Uniform<ServerCommandSource, FabricCommand> {
private static FabricUniform INSTANCE;
@ -65,6 +67,7 @@ public final class FabricUniform {
* @param commands The commands to register
* @since 1.0
*/
@Override
public void register(@NotNull FabricCommand... commands) {
Collections.addAll(this.commands, commands);
}
@ -75,6 +78,7 @@ public final class FabricUniform {
* @param commands The commands to register
* @since 1.0
*/
@Override
public void register(@NotNull Command... commands) {
register(Arrays.stream(commands).map(FabricCommand::new).toArray(FabricCommand[]::new));
}

@ -88,8 +88,13 @@ public class PaperCommand extends BaseCommand<CommandSourceStack> {
@Override
@NotNull
protected CommandUser getUser(@NotNull CommandSourceStack user) {
return new PaperCommandUser(user);
protected CommandUser getUser(@NotNull Object user) {
return new PaperCommandUser((CommandSourceStack) user);
}
@Override
public void addSubCommand(@NotNull Command command) {
addSubCommand(new PaperCommand(command));
}
}

@ -22,14 +22,15 @@
package net.william278.uniform.paper;
import com.google.common.collect.Sets;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents;
import net.william278.uniform.Command;
import net.william278.uniform.Uniform;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Set;
/**
@ -38,7 +39,7 @@ import java.util.Set;
* @since 1.0
*/
@SuppressWarnings("UnstableApiUsage")
public final class PaperUniform {
public final class PaperUniform implements Uniform<CommandSourceStack, PaperCommand> {
private static PaperUniform INSTANCE;
@ -74,6 +75,7 @@ public final class PaperUniform {
* @param commands The commands to register
* @since 1.0
*/
@Override
public void register(@NotNull PaperCommand... commands) {
Collections.addAll(this.commands, commands);
}
@ -84,6 +86,7 @@ public final class PaperUniform {
* @param commands The commands to register
* @since 1.0
*/
@Override
public void register(@NotNull Command... commands) {
register(Arrays.stream(commands).map(PaperCommand::new).toArray(PaperCommand[]::new));
}

@ -11,6 +11,7 @@ include(
// Server Plugins
'paper',
'bukkit',
// Proxy Plugins
'velocity',

@ -97,7 +97,13 @@ public class VelocityCommand extends BaseCommand<CommandSource> {
@Override
@NotNull
protected CommandUser getUser(@NotNull CommandSource user) {
return new VelocityCommandUser(user);
protected CommandUser getUser(@NotNull Object user) {
return new VelocityCommandUser((CommandSource) user);
}
@Override
public void addSubCommand(@NotNull Command command) {
addSubCommand(new VelocityCommand(command));
}
}

@ -22,8 +22,10 @@
package net.william278.uniform.velocity;
import com.velocitypowered.api.command.BrigadierCommand;
import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.proxy.ProxyServer;
import net.william278.uniform.Command;
import net.william278.uniform.Uniform;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
@ -34,7 +36,7 @@ import java.util.Arrays;
* @since 1.0
*/
@SuppressWarnings("unused")
public final class VelocityUniform {
public final class VelocityUniform implements Uniform<CommandSource, VelocityCommand> {
private static VelocityUniform INSTANCE;
@ -62,6 +64,7 @@ public final class VelocityUniform {
* @param commands The commands to register
* @since 1.0
*/
@Override
public void register(@NotNull VelocityCommand... commands) {
Arrays.stream(commands).forEach(cmd -> server.getCommandManager().register(new BrigadierCommand(cmd.build())));
}
@ -72,6 +75,7 @@ public final class VelocityUniform {
* @param commands The commands to register
* @since 1.0
*/
@Override
public void register(@NotNull Command... commands) {
register(Arrays.stream(commands).map(VelocityCommand::new).toArray(VelocityCommand[]::new));
}

Loading…
Cancel
Save