From c93681b888cec66f402c69975c8af2c134fcb04d Mon Sep 17 00:00:00 2001 From: William Date: Sat, 3 Aug 2024 13:21:26 +0100 Subject: [PATCH] feat: start data edit commands --- .../william278/husksync/command/PluginCommand.java | 13 +++++++++++++ .../java/net/william278/husksync/data/Data.java | 12 ++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/common/src/main/java/net/william278/husksync/command/PluginCommand.java b/common/src/main/java/net/william278/husksync/command/PluginCommand.java index b1eda665..b1b754d0 100644 --- a/common/src/main/java/net/william278/husksync/command/PluginCommand.java +++ b/common/src/main/java/net/william278/husksync/command/PluginCommand.java @@ -22,6 +22,7 @@ package net.william278.husksync.command; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import net.william278.husksync.HuskSync; +import net.william278.husksync.data.Identifier; import net.william278.husksync.user.CommandUser; import net.william278.husksync.user.User; import net.william278.uniform.BaseCommand; @@ -99,6 +100,18 @@ public abstract class PluginCommand extends Command { }, (context, builder) -> builder.buildFuture()); } + @NotNull + protected ArgumentElement identifier(@NotNull String name) { + return new ArgumentElement<>(name, reader -> { + final String prefixed = !name.contains(":") ? "husksync:%s".formatted(name) : name; + return plugin.getIdentifier(prefixed).orElseThrow(() -> CommandSyntaxException. + BUILT_IN_EXCEPTIONS.dispatcherUnknownArgument().createWithContext(reader)); + }, (context, builder) -> { + plugin.getRegisteredDataTypes().stream().map(d -> d.getKey().asString()).forEach(builder::suggest); + return builder.buildFuture(); + }); + } + public enum Type { HUSKSYNC_COMMAND(HuskSyncCommand::new), diff --git a/common/src/main/java/net/william278/husksync/data/Data.java b/common/src/main/java/net/william278/husksync/data/Data.java index 46074204..51d62033 100644 --- a/common/src/main/java/net/william278/husksync/data/Data.java +++ b/common/src/main/java/net/william278/husksync/data/Data.java @@ -29,6 +29,7 @@ import lombok.experimental.Accessors; import net.kyori.adventure.key.Key; import net.william278.husksync.HuskSync; import net.william278.husksync.user.OnlineUser; +import org.apache.commons.text.WordUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -146,6 +147,12 @@ public interface Data { @SerializedName("show_particles") boolean showParticles, @SerializedName("has_icon") boolean hasIcon) { + @NotNull + private String asString() { + return "[❌] %s %s (⏰ %d:%02d)".formatted(WordUtils.capitalizeFully(type()), + amplifier(), duration() / (60 * 1000), (duration() / 1000) % 60); + } + } } @@ -167,6 +174,7 @@ public interface Data { void setCompleted(@NotNull List completed); + @NoArgsConstructor(access = AccessLevel.PRIVATE) class Advancement { @SerializedName("key") private String key; @@ -179,10 +187,6 @@ public interface Data { this.completedCriteria = adaptDateMap(completedCriteria); } - @SuppressWarnings("unused") - private Advancement() { - } - @NotNull public static Advancement adapt(@NotNull String key, @NotNull Map completedCriteria) { return new Advancement(key, completedCriteria);