QoL enhancements for waypoints triggers

This commit is contained in:
fullwall 2018-10-07 13:20:56 +08:00
parent a3c99e63e7
commit 4424f8b9ae
16 changed files with 109 additions and 44 deletions

View File

@ -3,10 +3,6 @@ package net.citizensnpcs.trait.waypoint.triggers;
import java.util.Collection;
import java.util.List;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.persistence.Persist;
import net.citizensnpcs.util.PlayerAnimation;
import org.bukkit.Location;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
@ -14,6 +10,10 @@ import org.bukkit.entity.Player;
import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.persistence.Persist;
import net.citizensnpcs.util.PlayerAnimation;
public class AnimationTrigger implements WaypointTrigger {
@Persist(required = true)
private List<PlayerAnimation> animations;
@ -27,7 +27,7 @@ public class AnimationTrigger implements WaypointTrigger {
@Override
public String description() {
return String.format("Animation Trigger [animating %s]", Joiner.on(", ").join(animations));
return String.format("[[Animation]] animating %s", Joiner.on(", ").join(animations));
}
@Override

View File

@ -2,11 +2,6 @@ package net.citizensnpcs.trait.waypoint.triggers;
import java.util.List;
import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.util.Messages;
import net.citizensnpcs.util.PlayerAnimation;
import net.citizensnpcs.util.Util;
import org.bukkit.command.CommandSender;
import org.bukkit.conversations.ConversationContext;
import org.bukkit.conversations.Prompt;
@ -15,6 +10,11 @@ import org.bukkit.conversations.StringPrompt;
import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.util.Messages;
import net.citizensnpcs.util.PlayerAnimation;
import net.citizensnpcs.util.Util;
public class AnimationTriggerPrompt extends StringPrompt implements WaypointTriggerPrompt {
private final List<PlayerAnimation> animations = Lists.newArrayList();
@ -37,6 +37,11 @@ public class AnimationTriggerPrompt extends StringPrompt implements WaypointTrig
return this;
}
@Override
public WaypointTrigger createFromShortInput(ConversationContext context, String input) {
return null;
}
@Override
public String getPromptText(ConversationContext context) {
Messaging.sendTr((CommandSender) context.getForWhom(), Messages.ANIMATION_TRIGGER_PROMPT, getValidAnimations());

View File

@ -3,10 +3,6 @@ package net.citizensnpcs.trait.waypoint.triggers;
import java.util.Collection;
import java.util.List;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.persistence.Persist;
import net.citizensnpcs.api.util.Messaging;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
@ -14,6 +10,10 @@ import org.bukkit.entity.Player;
import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.persistence.Persist;
import net.citizensnpcs.api.util.Messaging;
public class ChatTrigger implements WaypointTrigger {
@Persist(required = true)
private List<String> lines;
@ -30,7 +30,7 @@ public class ChatTrigger implements WaypointTrigger {
@Override
public String description() {
return String.format("Chat Trigger [radius %d, %s]", radius, Joiner.on(", ").join(lines));
return String.format("[[Chat]] [radius %d, %s]", radius, Joiner.on(", ").join(lines));
}
@Override

View File

@ -2,9 +2,6 @@ package net.citizensnpcs.trait.waypoint.triggers;
import java.util.List;
import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.util.Messages;
import org.bukkit.command.CommandSender;
import org.bukkit.conversations.ConversationContext;
import org.bukkit.conversations.Prompt;
@ -12,6 +9,9 @@ import org.bukkit.conversations.StringPrompt;
import com.google.common.collect.Lists;
import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.util.Messages;
public class ChatTriggerPrompt extends StringPrompt implements WaypointTriggerPrompt {
private final List<String> lines = Lists.newArrayList();
private double radius = -1;
@ -39,6 +39,11 @@ public class ChatTriggerPrompt extends StringPrompt implements WaypointTriggerPr
return this;
}
@Override
public WaypointTrigger createFromShortInput(ConversationContext context, String input) {
return null;
}
@Override
public String getPromptText(ConversationContext context) {
Messaging.sendTr((CommandSender) context.getForWhom(), Messages.CHAT_TRIGGER_PROMPT);

View File

@ -22,7 +22,7 @@ public class DelayTrigger implements WaypointTrigger {
@Override
public String description() {
return String.format("Delay for %d ticks", delay);
return String.format("[[Delay]] for [[%d]] ticks", delay);
}
public int getDelay() {

View File

@ -1,12 +1,12 @@
package net.citizensnpcs.trait.waypoint.triggers;
import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.util.Messages;
import org.bukkit.conversations.ConversationContext;
import org.bukkit.conversations.NumericPrompt;
import org.bukkit.conversations.Prompt;
import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.util.Messages;
public class DelayTriggerPrompt extends NumericPrompt implements WaypointTriggerPrompt {
@Override
protected Prompt acceptValidatedInput(ConversationContext context, Number input) {
@ -15,6 +15,16 @@ public class DelayTriggerPrompt extends NumericPrompt implements WaypointTrigger
return (Prompt) context.getSessionData(WaypointTriggerPrompt.RETURN_PROMPT_KEY);
}
@Override
public WaypointTrigger createFromShortInput(ConversationContext context, String input) {
try {
int delay = Math.max(Integer.parseInt(input), 0);
return new DelayTrigger(delay);
} catch (NumberFormatException ex) {
return null;
}
}
@Override
public String getPromptText(ConversationContext context) {
return Messaging.tr(Messages.DELAY_TRIGGER_PROMPT);

View File

@ -1,10 +1,10 @@
package net.citizensnpcs.trait.waypoint.triggers;
import org.bukkit.Location;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.persistence.Persist;
import org.bukkit.Location;
public class SpeedTrigger implements WaypointTrigger {
@Persist
private float speed = 1F;
@ -18,7 +18,7 @@ public class SpeedTrigger implements WaypointTrigger {
@Override
public String description() {
return String.format("Speed change to %f", speed);
return String.format("[[Speed]] change to %f", speed);
}
public float getSpeed() {

View File

@ -1,12 +1,12 @@
package net.citizensnpcs.trait.waypoint.triggers;
import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.util.Messages;
import org.bukkit.conversations.ConversationContext;
import org.bukkit.conversations.NumericPrompt;
import org.bukkit.conversations.Prompt;
import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.util.Messages;
public class SpeedTriggerPrompt extends NumericPrompt implements WaypointTriggerPrompt {
@Override
protected Prompt acceptValidatedInput(ConversationContext context, Number input) {
@ -15,6 +15,16 @@ public class SpeedTriggerPrompt extends NumericPrompt implements WaypointTrigger
return (Prompt) context.getSessionData(WaypointTriggerPrompt.RETURN_PROMPT_KEY);
}
@Override
public WaypointTrigger createFromShortInput(ConversationContext context, String input) {
try {
float speed = (float) Math.max(Double.parseDouble(input), 0);
return new SpeedTrigger(speed);
} catch (NumberFormatException ex) {
return null;
}
}
@Override
public String getPromptText(ConversationContext context) {
return Messaging.tr(Messages.SPEED_TRIGGER_PROMPT);

View File

@ -19,7 +19,7 @@ public class TeleportTrigger implements WaypointTrigger {
@Override
public String description() {
return String.format("Teleport to [%s, %d, %d, %d]", location.getWorld().getName(), location.getBlockX(),
return String.format("[[Teleport]] to [%s, %d, %d, %d]", location.getWorld().getName(), location.getBlockX(),
location.getBlockY(), location.getBlockZ());
}

View File

@ -48,6 +48,11 @@ public class TeleportTriggerPrompt extends RegexPrompt implements WaypointTrigge
return (Prompt) context.getSessionData(WaypointTriggerPrompt.RETURN_PROMPT_KEY);
}
@Override
public WaypointTrigger createFromShortInput(ConversationContext context, String input) {
return null;
}
@Override
public String getPromptText(ConversationContext context) {
return Messaging.tr(Messages.WAYPOINT_TRIGGER_TELEPORT_PROMPT);

View File

@ -1,14 +1,16 @@
package net.citizensnpcs.trait.waypoint.triggers;
import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.trait.waypoint.WaypointEditor;
import net.citizensnpcs.util.Messages;
import org.bukkit.command.CommandSender;
import org.bukkit.conversations.ConversationContext;
import org.bukkit.conversations.Prompt;
import org.bukkit.conversations.StringPrompt;
import com.google.common.base.Joiner;
import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.trait.waypoint.WaypointEditor;
import net.citizensnpcs.util.Messages;
public class TriggerAddPrompt extends StringPrompt {
private final WaypointEditor editor;
@ -23,12 +25,22 @@ public class TriggerAddPrompt extends StringPrompt {
context.setSessionData("said", false);
return (Prompt) context.getSessionData("previous");
}
String[] split = input.split(" ");
input = split[0];
split[0] = null;
Prompt prompt = WaypointTriggerRegistry.getTriggerPromptFrom(input);
String extraInput = Joiner.on(' ').skipNulls().join(split);
if (prompt == null) {
Messaging.sendErrorTr((CommandSender) context.getForWhom(),
Messages.WAYPOINT_TRIGGER_EDITOR_INVALID_TRIGGER, input);
context.setSessionData("said", false);
return this;
} else if (extraInput.length() > 0) {
WaypointTrigger returned = ((WaypointTriggerPrompt) prompt).createFromShortInput(context, extraInput);
if (returned != null) {
context.setSessionData(WaypointTriggerPrompt.CREATED_TRIGGER_KEY, returned);
return this;
}
}
return prompt;
}
@ -36,12 +48,18 @@ public class TriggerAddPrompt extends StringPrompt {
@Override
public String getPromptText(ConversationContext context) {
WaypointTrigger returned = (WaypointTrigger) context.getSessionData(WaypointTriggerPrompt.CREATED_TRIGGER_KEY);
if (returned != null) {
if (editor.getCurrentWaypoint() != null) {
editor.getCurrentWaypoint().addTrigger(returned);
context.setSessionData(WaypointTriggerPrompt.CREATED_TRIGGER_KEY, null);
Messaging.sendTr((CommandSender) context.getForWhom(), Messages.WAYPOINT_TRIGGER_ADDED_SUCCESSFULLY,
returned.description());
String base = "";
for (WaypointTrigger trigger : editor.getCurrentWaypoint().getTriggers()) {
base += "\n - " + trigger.description();
}
Messaging.sendTr((CommandSender) context.getForWhom(), Messages.WAYPOINT_TRIGGER_LIST, base);
} else {
Messaging.sendErrorTr((CommandSender) context.getForWhom(), Messages.WAYPOINT_TRIGGER_EDITOR_INACTIVE);
}

View File

@ -2,6 +2,8 @@ package net.citizensnpcs.trait.waypoint.triggers;
import org.bukkit.command.CommandSender;
import org.bukkit.conversations.Conversation;
import org.bukkit.conversations.ConversationAbandonedEvent;
import org.bukkit.conversations.ConversationAbandonedListener;
import org.bukkit.conversations.ConversationContext;
import org.bukkit.conversations.ConversationFactory;
import org.bukkit.conversations.Prompt;
@ -41,20 +43,26 @@ public class TriggerEditPrompt extends StringPrompt {
if (context.getSessionData("said") == Boolean.TRUE)
return "";
context.setSessionData("said", true);
String base = Messaging.tr(Messages.WAYPOINT_TRIGGER_EDITOR_PROMPT);
String base = "";
if (editor.getCurrentWaypoint() != null) {
Waypoint waypoint = editor.getCurrentWaypoint();
for (WaypointTrigger trigger : waypoint.getTriggers()) {
base += "\n - " + trigger.description();
}
}
Messaging.send((CommandSender) context.getForWhom(), base);
Messaging.sendTr((CommandSender) context.getForWhom(), Messages.WAYPOINT_TRIGGER_EDITOR_PROMPT, base);
return "";
}
public static Conversation start(Player player, WaypointEditor editor) {
final Conversation conversation = new ConversationFactory(CitizensAPI.getPlugin()).withLocalEcho(false)
.withEscapeSequence("exit").withEscapeSequence("triggers").withEscapeSequence("/npc path")
.addConversationAbandonedListener(new ConversationAbandonedListener() {
@Override
public void conversationAbandoned(ConversationAbandonedEvent event) {
event.getContext().getForWhom()
.sendRawMessage(Messaging.tr(Messages.WAYPOINT_TRIGGER_EDITOR_EXIT));
}
}).withEscapeSequence("exit").withEscapeSequence("triggers").withEscapeSequence("/npc path")
.withModality(false).withFirstPrompt(new TriggerEditPrompt(editor)).buildConversation(player);
conversation.begin();
return conversation;

View File

@ -13,6 +13,8 @@ import org.bukkit.conversations.Prompt;
* displayed.
*/
public interface WaypointTriggerPrompt extends Prompt {
public WaypointTrigger createFromShortInput(ConversationContext context, String input);
static final String CREATED_TRIGGER_KEY = "created-trigger";
static final String RETURN_PROMPT_KEY = "return-to";
}

View File

@ -298,9 +298,11 @@ public class Messages {
public static final String WAYPOINT_TRIGGER_ADDED_SUCCESSFULLY = "citizens.editors.waypoints.triggers.add.added";
public static final String WAYPOINT_TRIGGER_CHAT_INVALID_RADIUS = "citizens.editors.waypoints.triggers.chat.invalid-radius";
public static final String WAYPOINT_TRIGGER_CHAT_NO_RADIUS = "citizens.editors.waypoints.triggers.chat.missing-radius";
public static final String WAYPOINT_TRIGGER_EDITOR_EXIT = "citizens.editors.waypoints.triggers.main.exit";
public static final String WAYPOINT_TRIGGER_EDITOR_INACTIVE = "citizens.editors.waypoints.triggers.main.missing-waypoint";
public static final String WAYPOINT_TRIGGER_EDITOR_INVALID_TRIGGER = "citizens.editors.waypoints.triggers.add.invalid-trigger";
public static final String WAYPOINT_TRIGGER_EDITOR_PROMPT = "citizens.editors.waypoints.triggers.main.prompt";
public static final String WAYPOINT_TRIGGER_LIST = "citizens.editors.waypoints.triggers.list";
public static final String WAYPOINT_TRIGGER_REMOVE_INDEX_OUT_OF_RANGE = "citizens.editors.waypoints.triggers.remove.index-out-of-range";
public static final String WAYPOINT_TRIGGER_REMOVE_INVALID_NUMBER = "citizens.editors.waypoints.triggers.remove.not-a-number";
public static final String WAYPOINT_TRIGGER_REMOVE_PROMPT = "citizens.editors.waypoints.triggers.remove.prompt";

View File

@ -254,10 +254,11 @@ citizens.editors.waypoints.linear.range-exceeded=Previous waypoint is {0} blocks
citizens.editors.waypoints.linear.removed-waypoint=[[Removed]] a waypoint ([[{0}]] remaining) ([[{1}]])
citizens.editors.waypoints.linear.showing-markers=[[Showing]] waypoint markers.
citizens.editors.waypoints.linear.waypoints-cleared=Waypoints cleared.
citizens.editors.waypoints.triggers.add.added=<b>[[Added]] waypoint trigger successfully ({0}).
citizens.editors.waypoints.triggers.add.added=<b>Added waypoint trigger successfully ({0}).
citizens.editors.waypoints.triggers.add.invalid-trigger=Couldn''t create a trigger by the name [[{0}]].
citizens.editors.waypoints.triggers.add.prompt=Enter in a trigger name to add or type [[back]] to return to the edit prompt. Valid trigger names are {0}.
citizens.editors.waypoints.triggers.animation.added=Animation [[{0}]] added.
citizens.editors.waypoints.triggers.list=Current triggers are:{0}
citizens.editors.waypoints.triggers.animation.prompt=Enter in animations to perform - valid animations are {0}.<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.
@ -265,7 +266,8 @@ citizens.editors.waypoints.triggers.chat.missing-radius=No radius supplied.
citizens.editors.waypoints.triggers.chat.prompt=Enter in chat lines to say.<br>Type in [[radius (radius)]] to set the block radius to broadcast the messages.<br>Type [[finish]] to finish the chat trigger or [[back]] to return to the previous prompt.
citizens.editors.waypoints.triggers.delay.prompt=Enter the delay in [[server ticks]] to use. (20 ticks = 1 second)
citizens.editors.waypoints.triggers.main.missing-waypoint=Not editing a waypoint.
citizens.editors.waypoints.triggers.main.prompt=<b>Entered the waypoint trigger editor.<br> Type [[add]] to begin adding triggers and [[remove]] to remove triggers.<br> Type [[triggers]] to enter the waypoint trigger editor.<br> Current triggers are:
citizens.editors.waypoints.triggers.main.exit=<b>Exited the waypoint trigger editor.
citizens.editors.waypoints.triggers.main.prompt=<b>- Waypoint Trigger Editor -<br> Type [[add]] or [[remove]] to edit triggers.<br> Type [[triggers]] or [[exit]] to exit this editor.<br> Current triggers are:{0}
citizens.editors.waypoints.triggers.remove.index-out-of-range=Index must be in the range [[1-{0}]].
citizens.editors.waypoints.triggers.remove.not-a-number=Index must be a number.
citizens.editors.waypoints.triggers.remove.prompt=Enter in the index of the trigger to delete or [[back]] to return to the edit prompt. Current triggers are:

View File

@ -1,9 +1,8 @@
package net.citizensnpcs.nms.v1_8_R3.util;
import net.citizensnpcs.nms.v1_8_R3.entity.EntityHumanNPC;
import net.minecraft.server.v1_8_R3.Entity;
import net.minecraft.server.v1_8_R3.EntityLiving;
import net.minecraft.server.v1_8_R3.MathHelper;
import net.minecraft.server.v1_13_R2.EntityLiving;
import net.minecraft.server.v1_13_R2.MathHelper;
public class PlayerControllerLook {
private final EntityHumanNPC a;
@ -42,7 +41,6 @@ public class PlayerControllerLook {
while (this.a.aK < -180F) {
this.a.aK += 360F;
}
System.out.println(this.a.aK);
} else {
// this.a.aK = a(this.a.aK, this.a.aI, 10.0F);
}