feat: target Paper 1.20.6, add command descriptions

dependabot/gradle/org.projectlombok-lombok-1.18.34
William 5 months ago
parent accf186c33
commit d78847550c
No known key found for this signature in database

@ -22,7 +22,7 @@ Please note Uniform on Fabric requires [adventure-platform-fabric](https://docs.
| Platform | Artifact | Minecraft | Java |
|---------------|-------------------------|:----------:|:------:|
| Common | `uniform-common` | - | \>`17` |
| Paper | `uniform-paper` | \>`1.20.4` | \>`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` |

@ -99,6 +99,10 @@ subprojects {
archiveClassifier.set('')
}
if (['example-plugin', 'fabric-1.20.6', 'paper'].contains(project.name)) {
compileJava.options.release.set 21
}
// Don't include example plugin in publishing
if (['example-plugin'].contains(project.name)) return;

@ -42,17 +42,25 @@ public abstract class BaseCommand<S> {
@Getter
private final String name;
@Getter
private final String[] aliases;
private final String description;
@Getter
private final List<String> aliases;
public BaseCommand(@NotNull Command command) {
this.name = command.getName();
this.aliases = command.getAliases().toArray(new String[0]);
this.aliases = command.getAliases();
this.description = command.getDescription();
command.provide(this);
}
public BaseCommand(@NotNull String name, @NotNull String... aliases) {
public BaseCommand(@NotNull String name, @NotNull String description, @NotNull List<String> aliases) {
this.name = name;
this.aliases = aliases;
this.description = description;
}
public BaseCommand(@NotNull String name, @NotNull List<String> aliases) {
this(name, "", aliases);
}
@Nullable

@ -30,6 +30,11 @@ public interface Command {
@NotNull
String getName();
@NotNull
default String getDescription() {
return "";
}
@NotNull
default List<String> getAliases() {
return List.of();

@ -6,11 +6,11 @@ plugins {
dependencies {
implementation(project(":paper"))
compileOnly 'io.papermc.paper:paper-api:1.20.4-R0.1-SNAPSHOT'
compileOnly 'io.papermc.paper:paper-api:1.20.6-R0.1-SNAPSHOT'
}
tasks {
runServer {
minecraftVersion("1.20.4")
minecraftVersion("1.20.6")
}
}

@ -24,14 +24,17 @@ package net.william278.uniform;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.william278.uniform.paper.PaperCommand;
import java.util.List;
@SuppressWarnings("UnstableApiUsage")
public class ExampleCommand extends PaperCommand {
public ExampleCommand() {
super("example", "silly-command");
super("example", "An example command", List.of("silly-command"));
addSyntax((context) -> {
context.getSource().getBukkitSender().sendMessage("Woah!!!!");
context.getSource().getSender().sendMessage("Woah!!!!");
String arg = context.getArgument("message", String.class);
context.getSource().getBukkitSender().sendMessage(MiniMessage.miniMessage().deserialize(arg));
context.getSource().getSender().sendMessage(MiniMessage.miniMessage().deserialize(arg));
}, stringArg("message"));
}

@ -33,6 +33,12 @@ public class ExampleCrossPlatCommand implements Command {
return "example-crossplat";
}
@Override
@NotNull
public String getDescription() {
return "An example cross-platform command";
}
@Override
public <S> void provide(@NotNull BaseCommand<S> command) {
command.setCondition(source -> true);

@ -28,7 +28,7 @@ import org.bukkit.plugin.java.JavaPlugin;
public class UniformExample extends JavaPlugin {
@Override
public void onEnable() {
public void onLoad() {
PaperUniform uniform = PaperUniform.getInstance(this);
uniform.register(new ExampleCommand());
uniform.register(new ExampleCrossPlatCommand());

@ -35,6 +35,8 @@ import net.william278.uniform.CommandUser;
import net.william278.uniform.element.ArgumentElement;
import org.jetbrains.annotations.NotNull;
import java.util.List;
@SuppressWarnings("unused")
public class FabricCommand extends BaseCommand<ServerCommandSource> {
@ -42,10 +44,14 @@ public class FabricCommand extends BaseCommand<ServerCommandSource> {
super(command);
}
public FabricCommand(@NotNull String name, @NotNull String... aliases) {
public FabricCommand(@NotNull String name, @NotNull List<String> aliases) {
super(name, aliases);
}
public FabricCommand(@NotNull String name, @NotNull String description, @NotNull List<String> aliases) {
super(name, description, aliases);
}
protected static ArgumentElement<ServerCommandSource, Item> itemArg(String name) {
return registryArg(name, Registries.ITEM);
}

@ -35,15 +35,21 @@ import net.william278.uniform.CommandUser;
import net.william278.uniform.element.ArgumentElement;
import org.jetbrains.annotations.NotNull;
import java.util.List;
@SuppressWarnings("unused")
public class FabricCommand extends BaseCommand<ServerCommandSource> {
public FabricCommand(@NotNull String name, @NotNull String... aliases) {
public FabricCommand(@NotNull Command command) {
super(command);
}
public FabricCommand(@NotNull String name, @NotNull List<String> aliases) {
super(name, aliases);
}
public FabricCommand(@NotNull Command command) {
super(command);
public FabricCommand(@NotNull String name, @NotNull String description, @NotNull List<String> aliases) {
super(name, description, aliases);
}
protected static ArgumentElement<ServerCommandSource, Item> itemArg(String name) {

@ -6,8 +6,7 @@ plugins {
dependencies {
api project(path: ':common')
compileOnlyApi 'io.papermc.paper:paper-mojangapi:1.20.4-R0.1-SNAPSHOT'
compileOnlyApi 'io.papermc.paper:paper-api:1.20.4-R0.1-SNAPSHOT'
compileOnlyApi 'io.papermc.paper:paper-api:1.20.6-R0.1-SNAPSHOT'
compileOnly 'org.projectlombok:lombok:1.18.32'
annotationProcessor 'org.projectlombok:lombok:1.18.32'

@ -21,8 +21,8 @@
package net.william278.uniform.paper;
import com.destroystokyo.paper.brigadier.BukkitBrigadierCommandSource;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import net.william278.uniform.BaseCommand;
import net.william278.uniform.Command;
import net.william278.uniform.CommandUser;
@ -35,18 +35,22 @@ import org.jetbrains.annotations.NotNull;
import java.util.Collection;
import java.util.List;
@SuppressWarnings("unused")
public class PaperCommand extends BaseCommand<BukkitBrigadierCommandSource> {
@SuppressWarnings({"unused", "UnstableApiUsage"})
public class PaperCommand extends BaseCommand<CommandSourceStack> {
public PaperCommand(@NotNull Command command) {
super(command);
}
public PaperCommand(@NotNull String name, @NotNull String... aliases) {
public PaperCommand(@NotNull String name, @NotNull List<String> aliases) {
super(name, aliases);
}
protected static ArgumentElement<BukkitBrigadierCommandSource, Material> materialArg(String name) {
public PaperCommand(@NotNull String name, @NotNull String description, @NotNull List<String> aliases) {
super(name, description, aliases);
}
protected static ArgumentElement<CommandSourceStack, Material> materialArg(String name) {
return new ArgumentElement<>(name, reader -> {
String materialName = reader.readString();
Material material = Material.matchMaterial(materialName);
@ -62,7 +66,7 @@ public class PaperCommand extends BaseCommand<BukkitBrigadierCommandSource> {
});
}
protected static ArgumentElement<BukkitBrigadierCommandSource, Collection<? extends Player>> playerArg(String name) {
protected static ArgumentElement<CommandSourceStack, Collection<? extends Player>> playerArg(String name) {
return new ArgumentElement<>(name, reader -> {
String playerName = reader.readString();
if (playerName.equals("@a")) {
@ -84,7 +88,7 @@ public class PaperCommand extends BaseCommand<BukkitBrigadierCommandSource> {
@Override
@NotNull
protected CommandUser getUser(@NotNull BukkitBrigadierCommandSource user) {
protected CommandUser getUser(@NotNull CommandSourceStack user) {
return new PaperCommandUser(user);
}

@ -21,7 +21,7 @@
package net.william278.uniform.paper;
import com.destroystokyo.paper.brigadier.BukkitBrigadierCommandSource;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import net.kyori.adventure.audience.Audience;
import net.william278.uniform.CommandUser;
import org.jetbrains.annotations.NotNull;
@ -29,23 +29,25 @@ import org.jetbrains.annotations.Nullable;
import java.util.UUID;
public record PaperCommandUser(@NotNull BukkitBrigadierCommandSource source) implements CommandUser {
@SuppressWarnings("UnstableApiUsage")
public record PaperCommandUser(@NotNull CommandSourceStack source) implements CommandUser {
@Override
public @NotNull Audience getAudience() {
return source.getBukkitSender();
@NotNull
public Audience getAudience() {
return source.getSender();
}
@Override
@Nullable
public String getName() {
return source.getBukkitEntity() != null ? source.getBukkitSender().getName() : null;
return source.getExecutor() != null ? source.getExecutor().getName() : null;
}
@Override
@Nullable
public UUID getUuid() {
return source.getBukkitEntity() != null ? source.getBukkitEntity().getUniqueId() : null;
return source.getExecutor() != null ? source.getExecutor().getUniqueId() : null;
}
}

@ -21,16 +21,15 @@
package net.william278.uniform.paper;
import com.destroystokyo.paper.event.brigadier.CommandRegisteredEvent;
import com.google.common.collect.Sets;
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents;
import net.william278.uniform.Command;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
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;
/**
@ -39,23 +38,22 @@ import java.util.Set;
* @since 1.0
*/
@SuppressWarnings("UnstableApiUsage")
public final class PaperUniform implements Listener {
public final class PaperUniform {
private static PaperUniform INSTANCE;
private final Set<PaperCommand> commands = Sets.newHashSet();
private PaperUniform(@NotNull JavaPlugin plugin) {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
@EventHandler
@SuppressWarnings({"rawtypes", "unchecked"})
private void onCommandRegistered(@NotNull CommandRegisteredEvent event) {
for (PaperCommand command : commands) {
event.getRoot().addChild(command.build());
}
commands.clear();
plugin.getLifecycleManager().registerEventHandler(LifecycleEvents.COMMANDS, (event) -> {
commands.forEach(command -> event.registrar().register(
plugin.getPluginMeta(),
command.build(),
command.getDescription(),
command.getAliases()
));
commands.clear();
});
}
/**

@ -34,6 +34,8 @@ import net.william278.uniform.CommandUser;
import net.william278.uniform.element.ArgumentElement;
import org.jetbrains.annotations.NotNull;
import java.util.List;
@SuppressWarnings("unused")
public class VelocityCommand extends BaseCommand<CommandSource> {
@ -41,10 +43,14 @@ public class VelocityCommand extends BaseCommand<CommandSource> {
super(command);
}
public VelocityCommand(@NotNull String name, @NotNull String... aliases) {
public VelocityCommand(@NotNull String name, @NotNull List<String> aliases) {
super(name, aliases);
}
public VelocityCommand(@NotNull String name, @NotNull String description, @NotNull List<String> aliases) {
super(name, description, aliases);
}
protected static ArgumentElement<CommandSource, RegisteredServer> serverArg(ProxyServer server, String name,
SuggestionProvider<CommandSource> suggestionProvider) {
ArgumentType<RegisteredServer> argumentType = reader -> {

Loading…
Cancel
Save