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 bc99195 commit a7ffebc
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
package net.thenextlvl.character.plugin.command;

import com.mojang.brigadier.Command;
import com.mojang.brigadier.builder.ArgumentBuilder;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.context.CommandContext;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import io.papermc.paper.command.brigadier.Commands;
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
import io.papermc.paper.util.Tick;
import net.kyori.adventure.text.minimessage.tag.resolver.Formatter;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.thenextlvl.character.Character;
import net.thenextlvl.character.plugin.CharacterPlugin;
import net.thenextlvl.character.plugin.command.suggestion.CharacterWithActionSuggestionProvider;
import org.jspecify.annotations.NullMarked;

import java.util.Objects;

import static net.thenextlvl.character.plugin.command.CharacterActionCommand.actionArgument;
import static net.thenextlvl.character.plugin.command.CharacterCommand.characterArgument;

Expand All @@ -27,6 +34,30 @@ static LiteralArgumentBuilder<CommandSourceStack> create(CharacterPlugin plugin)
}

private static int set(CommandContext<CommandSourceStack> context, CharacterPlugin plugin) {
return 0; // todo implement
var sender = context.getSource().getSender();
var character = context.getArgument("character", Character.class);
var actionName = context.getArgument("action", String.class);
var action = character.getAction(actionName);

if (action == null) {
plugin.bundle().sendMessage(sender, "character.action.not_found",
Placeholder.parsed("character", character.getName()),
Placeholder.unparsed("name", actionName));
return 0;
}

var cooldown = Tick.of(context.getArgument("cooldown", int.class));

var success = !Objects.equals(action.getCooldown(), cooldown);
if (success) action.setCooldown(cooldown);

var message = success ? cooldown.isZero()
? "character.action.cooldown.removed" : "character.action.cooldown.set"
: "nothing.changed";
plugin.bundle().sendMessage(sender, message,
Placeholder.unparsed("action", actionName),
Placeholder.unparsed("character", character.getName()),
Formatter.number("cooldown", cooldown.toSeconds()));
return success ? Command.SINGLE_SUCCESS : 0;
}
}
2 changes: 2 additions & 0 deletions src/main/resources/messages.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
character.action.added=<gray><prefix> Added action <green><action></green> to <green><character></green></gray>
character.action.cooldown.removed=<gray><prefix> Removed cooldown from action <green><action></green></gray>
character.action.cooldown.set=<gray><prefix> Set cooldown of action <green><action></green> to <green><cooldown:#.###> seconds</green></gray>
character.action.list.empty=<red><prefix> <dark_red><character></dark_red> has no click actions</red>
character.action.list.header=<gray><prefix> Click actions of <green><character></green></gray>
character.action.list=<gray><prefix> <action> <dark_gray>(<yellow><action_type></yellow>) [\
Expand Down

0 comments on commit a7ffebc

Please sign in to comment.