Make triggers prompt pause the pathfinding to prevent difficult states to problem solve. Add CommandTrigger.
This commit is contained in:
parent
2082a98a79
commit
e64816eda2
|
@ -1339,6 +1339,23 @@ public class NPCCommands {
|
|||
NMS.setShouldJump(npc.getEntity());
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "knockback (--explicit true|false)",
|
||||
desc = "Toggle NPC knockback",
|
||||
modifiers = { "knockback" },
|
||||
min = 1,
|
||||
max = 1,
|
||||
permission = "citizens.npc.knockback")
|
||||
public void knockback(CommandContext args, CommandSender sender, NPC npc, @Flag("explicit") Boolean explicit) {
|
||||
boolean kb = !npc.data().get(NPC.Metadata.KNOCKBACK, true);
|
||||
if (explicit != null) {
|
||||
kb = explicit;
|
||||
}
|
||||
npc.data().set(NPC.Metadata.KNOCKBACK, kb);
|
||||
Messaging.sendTr(sender, kb ? Messages.KNOCKBACK_SET : Messages.KNOCKBACK_UNSET, npc.getName());
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "leashable",
|
||||
|
|
|
@ -66,10 +66,17 @@ public class CatTrait extends Trait {
|
|||
}
|
||||
|
||||
public void setType(Cat.Type type) {
|
||||
if (type == null) {
|
||||
type = Cat.Type.BLACK;
|
||||
}
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public void setType(Type type2) {
|
||||
if (type2 == null) {
|
||||
this.type = Cat.Type.BLACK;
|
||||
return;
|
||||
}
|
||||
switch (type2) {
|
||||
case WILD_OCELOT:
|
||||
this.type = Cat.Type.CALICO;
|
||||
|
|
|
@ -326,7 +326,11 @@ public class LinearWaypointProvider implements EnumerableWaypointProvider {
|
|||
event.setCancelled(true);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), () -> {
|
||||
conversation = TriggerEditPrompt.start(player, LinearWaypointEditor.this);
|
||||
conversation.addConversationAbandonedListener(e -> conversation = null);
|
||||
conversation.addConversationAbandonedListener(e -> {
|
||||
setPaused(false);
|
||||
conversation = null;
|
||||
});
|
||||
setPaused(true);
|
||||
});
|
||||
} else if (message.equalsIgnoreCase("clear")) {
|
||||
event.setCancelled(true);
|
||||
|
|
|
@ -56,7 +56,11 @@ public class AnimationTriggerPrompt extends StringPrompt implements WaypointTrig
|
|||
|
||||
@Override
|
||||
public WaypointTrigger createFromShortInput(ConversationContext context, String input) {
|
||||
return null;
|
||||
PlayerAnimation anim = Util.matchEnum(PlayerAnimation.values(), input);
|
||||
if (anim == null)
|
||||
return null;
|
||||
|
||||
return new AnimationTrigger(Lists.newArrayList(anim), at);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
package net.citizensnpcs.trait.waypoint.triggers;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.api.persistence.Persist;
|
||||
import net.citizensnpcs.util.Util;
|
||||
|
||||
public class CommandTrigger implements WaypointTrigger {
|
||||
@Persist(required = true)
|
||||
private final Collection<String> commands;
|
||||
|
||||
public CommandTrigger(Collection<String> commands) {
|
||||
this.commands = commands;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String description() {
|
||||
return String.format("[[Command]] running %s", Joiner.on(", ").join(commands));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWaypointReached(NPC npc, Location waypoint) {
|
||||
for (String command : commands) {
|
||||
Util.runCommand(npc, null, command, false, false);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
package net.citizensnpcs.trait.waypoint.triggers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.conversations.ConversationContext;
|
||||
import org.bukkit.conversations.Prompt;
|
||||
import org.bukkit.conversations.StringPrompt;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import net.citizensnpcs.api.util.Messaging;
|
||||
import net.citizensnpcs.util.Messages;
|
||||
|
||||
public class CommandTriggerPrompt extends StringPrompt implements WaypointTriggerPrompt {
|
||||
private final List<String> commands = Lists.newArrayList();
|
||||
|
||||
@Override
|
||||
public Prompt acceptInput(ConversationContext context, String input) {
|
||||
if (input.equalsIgnoreCase("back")) {
|
||||
return (Prompt) context.getSessionData("previous");
|
||||
}
|
||||
if (input.equalsIgnoreCase("finish")) {
|
||||
context.setSessionData(WaypointTriggerPrompt.CREATED_TRIGGER_KEY, new CommandTrigger(commands));
|
||||
return (Prompt) context.getSessionData(WaypointTriggerPrompt.RETURN_PROMPT_KEY);
|
||||
}
|
||||
commands.add(input);
|
||||
Messaging.sendTr((CommandSender) context.getForWhom(), Messages.COMMAND_TRIGGER_ADDED, input);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WaypointTrigger createFromShortInput(ConversationContext context, String input) {
|
||||
return new CommandTrigger(Lists.newArrayList(input));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPromptText(ConversationContext context) {
|
||||
Messaging.sendTr((CommandSender) context.getForWhom(), Messages.COMMAND_TRIGGER_PROMPT);
|
||||
return "";
|
||||
}
|
||||
}
|
|
@ -61,6 +61,7 @@ public class WaypointTriggerRegistry implements Persister<WaypointTrigger> {
|
|||
|
||||
static {
|
||||
addTrigger("animation", AnimationTrigger.class, AnimationTriggerPrompt.class);
|
||||
addTrigger("command", AnimationTrigger.class, CommandTriggerPrompt.class);
|
||||
addTrigger("chat", ChatTrigger.class, ChatTriggerPrompt.class);
|
||||
addTrigger("delay", DelayTrigger.class, DelayTriggerPrompt.class);
|
||||
addTrigger("teleport", TeleportTrigger.class, TeleportTriggerPrompt.class);
|
||||
|
|
|
@ -76,6 +76,8 @@ public class Messages {
|
|||
public static final String COMMAND_RIGHT_HAND_HEADER = "citizens.commands.npc.command.right-hand-header";
|
||||
public static final String COMMAND_SAVE_HELP = "citizens.commands.citizens.save.help";
|
||||
public static final String COMMAND_TEMPORARY_PERMISSIONS_SET = "citizens.commands.npc.command.temporary-permissions-set";
|
||||
public static final String COMMAND_TRIGGER_ADDED = "citizens.editors.waypoints.triggers.command.added";
|
||||
public static final String COMMAND_TRIGGER_PROMPT = "citizens.editors.waypoints.triggers.command.prompt";
|
||||
public static final String COMMAND_UNKNOWN_COMMAND_ID = "citizens.commands.npc.command.unknown-id";
|
||||
public static final String COMMANDS_PERSIST_SEQUENCE_SET = "citizens.commands.npc.command.persist-sequence-set";
|
||||
public static final String COMMANDS_PERSIST_SEQUENCE_UNSET = "citizens.commands.npc.command.persist-sequence-unset";
|
||||
|
@ -199,6 +201,8 @@ public class Messages {
|
|||
public static final String INVALID_TROPICALFISH_PATTERN = "citizens.commands.npc.tropicalfish.invalid-pattern";
|
||||
public static final String INVALID_VILLAGER_TYPE = "citizens.commands.npc.villager.invalid-type";
|
||||
public static final String ITEM_SET = "citizens.commands.npc.item.item-set";
|
||||
public static final String KNOCKBACK_SET = "citizens.commands.npc.knockback.set";
|
||||
public static final String KNOCKBACK_UNSET = "citizens.commands.npc.knockback.unset";
|
||||
public static final String LEASHABLE_SET = "citizens.commands.npc.leashable.set";
|
||||
public static final String LEASHABLE_STOPPED = "citizens.commands.npc.leashable.stopped";
|
||||
public static final String LINEAR_WAYPOINT_EDITOR_ADDED_WAYPOINT = "citizens.editors.waypoints.linear.added-waypoint";
|
||||
|
|
|
@ -143,6 +143,8 @@ citizens.commands.npc.hurt.not-damageable=NPC type [[{0}]] cannot be hurt.
|
|||
citizens.commands.npc.hurt.protected=NPC is protected and cannot be hurt. <click:run_command:/npc vulnerable>[[<u>Click to unprotect</click>
|
||||
citizens.commands.npc.item.item-set=NPC item set to [[{0}]].
|
||||
citizens.commands.npc.item.unknown-material=Unknown material given.
|
||||
citizens.commands.npc.knockback.set=[[{0}]] will now take knockback.
|
||||
citizens.commands.npc.knockback.unset=[[{0}]] will no longer take knockback.
|
||||
citizens.commands.npc.leashable.set=[[{0}]] is now leashable.
|
||||
citizens.commands.npc.leashable.stopped=[[{0}]] is no longer leashable.
|
||||
citizens.commands.npc.llama.strength-set=Llama strength set to [[{0}]].
|
||||
|
@ -433,6 +435,8 @@ citizens.editors.waypoints.triggers.add.prompt=Enter in a trigger name to add or
|
|||
citizens.editors.waypoints.triggers.animation.added=Animation [[{0}]] added.
|
||||
citizens.editors.waypoints.triggers.animation.at-set=Animation location set to [[{0}]].
|
||||
citizens.editors.waypoints.triggers.list=Current triggers are:{0}
|
||||
citizens.editors.waypoints.triggers.command.added=Command [[{0}]] added.
|
||||
citizens.editors.waypoints.triggers.command.prompt=Enter one or more commands (without the leading slash).
|
||||
citizens.editors.waypoints.triggers.animation.prompt=Enter in animations to perform - valid animations are {0}.<br>[[at (x:y:z:world)]] optionally set a location to perform the animation at.<br>Type in [[finish]] to finish the animation trigger or [[back]] to return to the previous prompt.
|
||||
citizens.editors.waypoints.triggers.animation.invalid-animation=Invalid animation [[{0}]]. Valid animations are {1}.
|
||||
citizens.editors.waypoints.triggers.chat.invalid-radius=The radius must be a number.
|
||||
|
|
Loading…
Reference in New Issue