Compare commits

...

1 Commits

Author SHA1 Message Date
William c93681b888
feat: start data edit commands 4 months ago

@ -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 <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 {
HUSKSYNC_COMMAND(HuskSyncCommand::new),

@ -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<Advancement> 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<String, Date> completedCriteria) {
return new Advancement(key, completedCriteria);

Loading…
Cancel
Save