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 | | Platform | Artifact | Minecraft | Java |
|---------------|-------------------------|:----------:|:------:| |---------------|-------------------------|:----------:|:------:|
| Common | `uniform-common` | - | \>`17` | | 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` | | Velocity | `uniform-velocity` | \>`3.3.0` | \>`17` |
| Fabric 1.20.1 | `uniform-fabric-1_20_1` | =`1.20.1` | \>`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` | | Fabric 1.20.6 | `uniform-fabric-1_20_6` | =`1.20.6` | \>`21` |

@ -99,6 +99,10 @@ subprojects {
archiveClassifier.set('') 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 // Don't include example plugin in publishing
if (['example-plugin'].contains(project.name)) return; if (['example-plugin'].contains(project.name)) return;

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

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

@ -6,11 +6,11 @@ plugins {
dependencies { dependencies {
implementation(project(":paper")) 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 { tasks {
runServer { 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.kyori.adventure.text.minimessage.MiniMessage;
import net.william278.uniform.paper.PaperCommand; import net.william278.uniform.paper.PaperCommand;
import java.util.List;
@SuppressWarnings("UnstableApiUsage")
public class ExampleCommand extends PaperCommand { public class ExampleCommand extends PaperCommand {
public ExampleCommand() { public ExampleCommand() {
super("example", "silly-command"); super("example", "An example command", List.of("silly-command"));
addSyntax((context) -> { addSyntax((context) -> {
context.getSource().getBukkitSender().sendMessage("Woah!!!!"); context.getSource().getSender().sendMessage("Woah!!!!");
String arg = context.getArgument("message", String.class); 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")); }, stringArg("message"));
} }

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

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

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

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

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

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

@ -21,7 +21,7 @@
package net.william278.uniform.paper; 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.kyori.adventure.audience.Audience;
import net.william278.uniform.CommandUser; import net.william278.uniform.CommandUser;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -29,23 +29,25 @@ import org.jetbrains.annotations.Nullable;
import java.util.UUID; import java.util.UUID;
public record PaperCommandUser(@NotNull BukkitBrigadierCommandSource source) implements CommandUser { @SuppressWarnings("UnstableApiUsage")
public record PaperCommandUser(@NotNull CommandSourceStack source) implements CommandUser {
@Override @Override
public @NotNull Audience getAudience() { @NotNull
return source.getBukkitSender(); public Audience getAudience() {
return source.getSender();
} }
@Override @Override
@Nullable @Nullable
public String getName() { public String getName() {
return source.getBukkitEntity() != null ? source.getBukkitSender().getName() : null; return source.getExecutor() != null ? source.getExecutor().getName() : null;
} }
@Override @Override
@Nullable @Nullable
public UUID getUuid() { 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; package net.william278.uniform.paper;
import com.destroystokyo.paper.event.brigadier.CommandRegisteredEvent;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents;
import net.william278.uniform.Command; import net.william278.uniform.Command;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List;
import java.util.Set; import java.util.Set;
/** /**
@ -39,23 +38,22 @@ import java.util.Set;
* @since 1.0 * @since 1.0
*/ */
@SuppressWarnings("UnstableApiUsage") @SuppressWarnings("UnstableApiUsage")
public final class PaperUniform implements Listener { public final class PaperUniform {
private static PaperUniform INSTANCE; private static PaperUniform INSTANCE;
private final Set<PaperCommand> commands = Sets.newHashSet(); private final Set<PaperCommand> commands = Sets.newHashSet();
private PaperUniform(@NotNull JavaPlugin plugin) { private PaperUniform(@NotNull JavaPlugin plugin) {
plugin.getServer().getPluginManager().registerEvents(this, plugin); plugin.getLifecycleManager().registerEventHandler(LifecycleEvents.COMMANDS, (event) -> {
} commands.forEach(command -> event.registrar().register(
plugin.getPluginMeta(),
@EventHandler command.build(),
@SuppressWarnings({"rawtypes", "unchecked"}) command.getDescription(),
private void onCommandRegistered(@NotNull CommandRegisteredEvent event) { command.getAliases()
for (PaperCommand command : commands) { ));
event.getRoot().addChild(command.build());
}
commands.clear(); commands.clear();
});
} }
/** /**

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

Loading…
Cancel
Save