feat: start data edit commands

feat/data-edit-commands
William 4 months ago
parent 07da1c04ce
commit c93681b888
No known key found for this signature in database

@ -22,6 +22,7 @@ package net.william278.husksync.command;
import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.william278.husksync.HuskSync; import net.william278.husksync.HuskSync;
import net.william278.husksync.data.Identifier;
import net.william278.husksync.user.CommandUser; import net.william278.husksync.user.CommandUser;
import net.william278.husksync.user.User; import net.william278.husksync.user.User;
import net.william278.uniform.BaseCommand; import net.william278.uniform.BaseCommand;
@ -99,6 +100,18 @@ public abstract class PluginCommand extends Command {
}, (context, builder) -> builder.buildFuture()); }, (context, builder) -> builder.buildFuture());
} }
@NotNull
protected <S> ArgumentElement<S, Identifier> 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 { public enum Type {
HUSKSYNC_COMMAND(HuskSyncCommand::new), HUSKSYNC_COMMAND(HuskSyncCommand::new),

@ -29,6 +29,7 @@ import lombok.experimental.Accessors;
import net.kyori.adventure.key.Key; import net.kyori.adventure.key.Key;
import net.william278.husksync.HuskSync; import net.william278.husksync.HuskSync;
import net.william278.husksync.user.OnlineUser; import net.william278.husksync.user.OnlineUser;
import org.apache.commons.text.WordUtils;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@ -146,6 +147,12 @@ public interface Data {
@SerializedName("show_particles") boolean showParticles, @SerializedName("show_particles") boolean showParticles,
@SerializedName("has_icon") boolean hasIcon) { @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<Advancement> completed); void setCompleted(@NotNull List<Advancement> completed);
@NoArgsConstructor(access = AccessLevel.PRIVATE)
class Advancement { class Advancement {
@SerializedName("key") @SerializedName("key")
private String key; private String key;
@ -179,10 +187,6 @@ public interface Data {
this.completedCriteria = adaptDateMap(completedCriteria); this.completedCriteria = adaptDateMap(completedCriteria);
} }
@SuppressWarnings("unused")
private Advancement() {
}
@NotNull @NotNull
public static Advancement adapt(@NotNull String key, @NotNull Map<String, Date> completedCriteria) { public static Advancement adapt(@NotNull String key, @NotNull Map<String, Date> completedCriteria) {
return new Advancement(key, completedCriteria); return new Advancement(key, completedCriteria);

Loading…
Cancel
Save