add player chat action
This commit is contained in:
parent
cd2cdd6869
commit
0a6f599ece
2 changed files with 84 additions and 0 deletions
|
@ -0,0 +1,24 @@
|
|||
package lol.pyr.znpcsplus.interaction.playerchat;
|
||||
|
||||
import lol.pyr.znpcsplus.api.interaction.InteractionType;
|
||||
import lol.pyr.znpcsplus.interaction.InteractionAction;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class PlayerChatAction extends InteractionAction {
|
||||
private final String message;
|
||||
|
||||
public PlayerChatAction(String message, InteractionType interactionType, long delay) {
|
||||
super(delay, interactionType);
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(Player player) {
|
||||
player.chat(message.replace("{player}", player.getName())
|
||||
.replace("{uuid}", player.getUniqueId().toString()));
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
package lol.pyr.znpcsplus.interaction.playerchat;
|
||||
|
||||
import lol.pyr.director.adventure.command.CommandContext;
|
||||
import lol.pyr.director.common.command.CommandExecutionException;
|
||||
import lol.pyr.znpcsplus.api.interaction.InteractionType;
|
||||
import lol.pyr.znpcsplus.interaction.InteractionAction;
|
||||
import lol.pyr.znpcsplus.interaction.InteractionActionType;
|
||||
import lol.pyr.znpcsplus.interaction.InteractionCommandHandler;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Base64;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class PlayerChatActionType implements InteractionActionType<PlayerChatAction>, InteractionCommandHandler {
|
||||
|
||||
public PlayerChatActionType() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serialize(PlayerChatAction obj) {
|
||||
return Base64.getEncoder().encodeToString(obj.getMessage().getBytes(StandardCharsets.UTF_8)) + ";" + obj.getCooldown() + ";" + obj.getInteractionType().name();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerChatAction deserialize(String str) {
|
||||
String[] split = str.split(";");
|
||||
return new PlayerChatAction(new String(Base64.getDecoder().decode(split[0]), StandardCharsets.UTF_8), InteractionType.valueOf(split[2]), Long.parseLong(split[1]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<PlayerChatAction> getActionClass() {
|
||||
return PlayerChatAction.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSubcommandName() {
|
||||
return "playerchat";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendUsage(CommandContext context) {
|
||||
context.setUsage(context.getUsage() + " " + getSubcommandName() + " <id> <click type> <cooldown seconds> <server>");
|
||||
}
|
||||
|
||||
@Override
|
||||
public InteractionAction parse(CommandContext context) throws CommandExecutionException {
|
||||
InteractionType type = context.parse(InteractionType.class);
|
||||
long cooldown = (long) (context.parse(Double.class) * 1000D);
|
||||
String message = context.dumpAllArgs();
|
||||
return new PlayerChatAction(message, type, cooldown);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> suggest(CommandContext context) throws CommandExecutionException {
|
||||
if (context.argSize() == 1) return context.suggestEnum(InteractionType.values());
|
||||
if (context.argSize() == 2) return context.suggestLiteral("1");
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue