Skip to content

Commit

Permalink
Add cooldown management for character actions
Browse files Browse the repository at this point in the history
Implemented setting and removing cooldowns for character actions via a new command. Updated messages to reflect cooldown changes and added proper feedback for successful or redundant operations.
  • Loading branch information
NonSwag committed Jan 15, 2025
1 parent a7ffebc commit 29bc13e
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import org.jspecify.annotations.NullMarked;

import java.time.Duration;
import java.util.EnumSet;
import java.util.stream.Collectors;

@NullMarked
public class ClickActionAdapter implements TagAdapter<ClickAction<?>> {
Expand All @@ -27,7 +29,7 @@ public ClickAction<?> deserialize(Tag tag, TagDeserializationContext context) th
var clickTypes = root.<StringTag>getAsList("clickTypes").stream()
.map(StringTag::getAsString)
.map(ClickType::valueOf)
.toArray(ClickType[]::new);
.collect(Collectors.toCollection(() -> EnumSet.noneOf(ClickType.class)));
var input = context.deserialize(root.get("input"), actionType.type());
return new ClickAction<>(actionType, clickTypes, input, cooldown, permission);
}
Expand All @@ -36,7 +38,7 @@ public ClickAction<?> deserialize(Tag tag, TagDeserializationContext context) th
public Tag serialize(ClickAction<?> action, TagSerializationContext context) throws ParserException {
var tag = new CompoundTag();
if (action.getPermission() != null) tag.add("permission", action.getPermission());
if (!action.getCooldown().equals(Duration.ZERO)) tag.add("cooldown", action.getCooldown().toMillis());
if (!action.getCooldown().isZero()) tag.add("cooldown", action.getCooldown().toMillis());
tag.add("actionType", context.serialize(action.getActionType()));
var types = new ListTag<StringTag>(StringTag.ID);
for (var type : action.getClickTypes()) types.add(new StringTag(type.name()));
Expand Down

0 comments on commit 29bc13e

Please sign in to comment.