actions woo
This commit is contained in:
parent
750ca0e387
commit
baf6ea2622
9 changed files with 116 additions and 1 deletions
|
@ -11,6 +11,8 @@ import lol.pyr.znpcsplus.config.Configs;
|
|||
import lol.pyr.znpcsplus.entity.EntityProperty;
|
||||
import lol.pyr.znpcsplus.entity.PacketLocation;
|
||||
import lol.pyr.znpcsplus.interaction.InteractionPacketListener;
|
||||
import lol.pyr.znpcsplus.interaction.types.ConsoleCommandAction;
|
||||
import lol.pyr.znpcsplus.interaction.types.MessageAction;
|
||||
import lol.pyr.znpcsplus.npc.NPC;
|
||||
import lol.pyr.znpcsplus.npc.NPCRegistry;
|
||||
import lol.pyr.znpcsplus.npc.NPCType;
|
||||
|
@ -151,10 +153,12 @@ public class ZNPCsPlus extends JavaPlugin {
|
|||
}
|
||||
NPC npc = new NPC(world, NPCType.byName("player"), new PacketLocation(x * 3, 200, z * 3, 0, 0));
|
||||
npc.setProperty(EntityProperty.SKIN, new FetchingDescriptor("jeb_"));
|
||||
npc.addAction(new MessageAction(1000L, "<red>Hi, I'm jeb!"));
|
||||
NPCRegistry.register("debug_npc" + (z * wrap + x), npc);
|
||||
x++;
|
||||
npc = new NPC(world, NPCType.byName("player"), new PacketLocation(x * 3, 200, z * 3, 0, 0));
|
||||
npc.setProperty(EntityProperty.SKIN, new MirrorDescriptor());
|
||||
npc.addAction(new ConsoleCommandAction(1000L, "kick {player}"));
|
||||
NPCRegistry.register("debug_npc" + (z * wrap + x), npc);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,10 +7,12 @@ import java.util.UUID;
|
|||
public abstract class NPCAction {
|
||||
private final UUID id;
|
||||
private final long delay;
|
||||
protected final String argument;
|
||||
|
||||
protected NPCAction(long delay) {
|
||||
protected NPCAction(long delay, String argument) {
|
||||
this.id = UUID.randomUUID();
|
||||
this.delay = delay;
|
||||
this.argument = argument;
|
||||
}
|
||||
|
||||
public UUID getUuid() {
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
package lol.pyr.znpcsplus.interaction;
|
||||
|
||||
@FunctionalInterface
|
||||
interface NPCActionDeserializer {
|
||||
NPCAction deserialize(long delay, String argument);
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package lol.pyr.znpcsplus.interaction;
|
||||
|
||||
import lol.pyr.znpcsplus.interaction.types.*;
|
||||
|
||||
public enum NPCActionType implements NPCActionDeserializer {
|
||||
CONSOLE_CMD(ConsoleCommandAction::new),
|
||||
MESSAGE(MessageAction::new),
|
||||
PLAYER_CMD(PlayerCommandAction::new),
|
||||
SERVER(SwitchServerAction::new);
|
||||
|
||||
private final NPCActionDeserializer deserializer;
|
||||
|
||||
NPCActionType(NPCActionDeserializer deserializer) {
|
||||
this.deserializer = deserializer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NPCAction deserialize(long delay, String str) {
|
||||
return deserializer.deserialize(delay, str);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package lol.pyr.znpcsplus.interaction.types;
|
||||
|
||||
import lol.pyr.znpcsplus.ZNPCsPlus;
|
||||
import lol.pyr.znpcsplus.interaction.NPCAction;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class ConsoleCommandAction extends NPCAction {
|
||||
public ConsoleCommandAction(long delay, String argument) {
|
||||
super(delay, argument);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(Player player) {
|
||||
String cmd = argument.replace("{player}", player.getName()).replace("{uuid}", player.getUniqueId().toString());
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), ZNPCsPlus.PLACEHOLDERS_SUPPORTED ? PlaceholderAPI.setPlaceholders(player, cmd) : cmd);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package lol.pyr.znpcsplus.interaction.types;
|
||||
|
||||
import lol.pyr.znpcsplus.ZNPCsPlus;
|
||||
import lol.pyr.znpcsplus.interaction.NPCAction;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class MessageAction extends NPCAction {
|
||||
private final Component message;
|
||||
|
||||
public MessageAction(long delay, String argument) {
|
||||
super(delay, argument);
|
||||
message = MiniMessage.miniMessage().deserialize(argument);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(Player player) {
|
||||
ZNPCsPlus.ADVENTURE.player(player).sendMessage(message);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package lol.pyr.znpcsplus.interaction.types;
|
||||
|
||||
import lol.pyr.znpcsplus.ZNPCsPlus;
|
||||
import lol.pyr.znpcsplus.interaction.NPCAction;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class PlayerCommandAction extends NPCAction {
|
||||
public PlayerCommandAction(long delay, String argument) {
|
||||
super(delay, argument);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(Player player) {
|
||||
String cmd = argument.replace("{player}", player.getName()).replace("{uuid}", player.getUniqueId().toString());
|
||||
Bukkit.dispatchCommand(player, ZNPCsPlus.PLACEHOLDERS_SUPPORTED ? PlaceholderAPI.setPlaceholders(player, cmd) : cmd);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package lol.pyr.znpcsplus.interaction.types;
|
||||
|
||||
import lol.pyr.znpcsplus.ZNPCsPlus;
|
||||
import lol.pyr.znpcsplus.interaction.NPCAction;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class SwitchServerAction extends NPCAction {
|
||||
public SwitchServerAction(long delay, String argument) {
|
||||
super(delay, argument);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(Player player) {
|
||||
ZNPCsPlus.BUNGEE_UTILS.sendPlayerToServer(player, argument);
|
||||
}
|
||||
}
|
7
src/main/java/lol/pyr/znpcsplus/util/StringUtils.java
Normal file
7
src/main/java/lol/pyr/znpcsplus/util/StringUtils.java
Normal file
|
@ -0,0 +1,7 @@
|
|||
package lol.pyr.znpcsplus.util;
|
||||
|
||||
public class StringUtils {
|
||||
public static boolean startsWithIgnoreCase(String s1, String s2) {
|
||||
return s1.toLowerCase().startsWith(s2.toLowerCase());
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue