CommandAction
Represents a command to execute when a citizen is interacted with. Supports server vs. player execution, delays, and a special message-sending shorthand.
package com.electro.hycitizens.models;
Constructors
CommandAction(@Nonnull String command, boolean runAsServer)
CommandAction(@Nonnull String command, boolean runAsServer, float delaySeconds)
CommandAction(@Nonnull String command, boolean runAsServer, float delaySeconds, @Nullable String interactionTrigger)
getCommand / setCommand
@Nonnull String getCommand()
void setCommand(@Nonnull String command)
The command string to run, without a leading /. Supports placeholders {PlayerName} and {CitizenName} (case-insensitive).
Special prefix: if the command starts with {SendMessage}, the remainder is sent as a formatted chat message to the player instead of running a command. Color tags and placeholders are supported in the message.
isRunAsServer / setRunAsServer
boolean isRunAsServer()
void setRunAsServer(boolean runAsServer)
If true, the command runs as the console with full server permissions. If false, it runs as the interacting player.
getDelaySeconds / setDelaySeconds
float getDelaySeconds()
void setDelaySeconds(float delaySeconds)
Seconds to wait before executing this command. Commands in a citizen's list are chained sequentially — each delay applies relative to the previous command's completion.
getInteractionTrigger / setInteractionTrigger
@Nullable String getInteractionTrigger()
void setInteractionTrigger(@Nullable String trigger)
Which interaction fires this command: "F_KEY", "LEFT_CLICK", or "BOTH" (default).
isTriggeredBy
boolean isTriggeredBy(@Nonnull String interactionSource)
Returns true if this command should fire for the given interaction source.
getFormattedCommand
@Nonnull String getFormattedCommand()
Returns the command with a leading / prepended. Convenience method for display purposes.
Example
List<CommandAction> actions = new ArrayList<>();
// Announce to the player
actions.add(new CommandAction(
"{SendMessage}{WHITE}Stand by...",
false, 0.0f, "F_KEY"
));
// Run a server command after 1 second
actions.add(new CommandAction(
"warp dungeon {PlayerName}",
true, 1.0f, "F_KEY"
));
citizen.setCommandActions(actions);