Improve waypoint triggers

This commit is contained in:
fullwall 2017-02-28 21:36:10 +08:00
parent f65d87c2db
commit 7e6cf4f7cd
7 changed files with 38 additions and 31 deletions

View File

@ -132,7 +132,9 @@ public class LinearWaypointProvider implements EnumerableWaypointProvider {
@Override
public void setPaused(boolean paused) {
currentGoal.setPaused(paused);
if (currentGoal != null) {
currentGoal.setPaused(paused);
}
}
@Override
@ -462,8 +464,8 @@ public class LinearWaypointProvider implements EnumerableWaypointProvider {
getNavigator().getLocalParameters().addSingleUseCallback(new NavigatorCallback() {
@Override
public void onCompletion(@Nullable CancelReason cancelReason) {
if (npc.isSpawned() && currentDestination != null && Util
.locationWithinRange(npc.getEntity().getLocation(), currentDestination.getLocation(), 4)) {
if (npc.isSpawned() && currentDestination != null
&& Util.locationWithinRange(npc.getStoredLocation(), currentDestination.getLocation(), 2)) {
currentDestination.onReach(npc);
}
selector.finish();

View File

@ -3,6 +3,11 @@ package net.citizensnpcs.trait.waypoint;
import java.util.Collections;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import com.google.common.collect.Lists;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.persistence.Persist;
@ -11,11 +16,6 @@ import net.citizensnpcs.trait.waypoint.triggers.DelayTrigger;
import net.citizensnpcs.trait.waypoint.triggers.WaypointTrigger;
import net.citizensnpcs.trait.waypoint.triggers.WaypointTriggerRegistry;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import com.google.common.collect.Lists;
public class Waypoint {
@Persist(required = true)
private Location location;
@ -69,9 +69,8 @@ public class Waypoint {
return location;
}
@SuppressWarnings("unchecked")
public List<WaypointTrigger> getTriggers() {
return triggers == null ? Collections.EMPTY_LIST : triggers;
return triggers == null ? Collections.<WaypointTrigger> emptyList() : triggers;
}
@Override
@ -96,7 +95,7 @@ public class Waypoint {
int delay = ((DelayTrigger) trigger).getDelay();
if (delay <= 0)
continue;
final int newStart = i;
final int newStart = i + 1;
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
@Override
public void run() {

View File

@ -1,14 +1,14 @@
package net.citizensnpcs.trait.waypoint.triggers;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.persistence.Persist;
import net.citizensnpcs.trait.waypoint.WaypointProvider;
import net.citizensnpcs.trait.waypoint.Waypoints;
import org.bukkit.Bukkit;
import org.bukkit.Location;
public class DelayTrigger implements WaypointTrigger {
@Persist
private int delay = 0;

View File

@ -1,11 +1,5 @@
package net.citizensnpcs.trait.waypoint.triggers;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.trait.waypoint.Waypoint;
import net.citizensnpcs.trait.waypoint.WaypointEditor;
import net.citizensnpcs.util.Messages;
import org.bukkit.command.CommandSender;
import org.bukkit.conversations.Conversation;
import org.bukkit.conversations.ConversationContext;
@ -14,6 +8,12 @@ import org.bukkit.conversations.Prompt;
import org.bukkit.conversations.StringPrompt;
import org.bukkit.entity.Player;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.trait.waypoint.Waypoint;
import net.citizensnpcs.trait.waypoint.WaypointEditor;
import net.citizensnpcs.util.Messages;
public class TriggerEditPrompt extends StringPrompt {
private final WaypointEditor editor;
@ -54,8 +54,8 @@ public class TriggerEditPrompt extends StringPrompt {
public static Conversation start(Player player, WaypointEditor editor) {
final Conversation conversation = new ConversationFactory(CitizensAPI.getPlugin()).withLocalEcho(false)
.withEscapeSequence("exit").withEscapeSequence("/npc path").withModality(false)
.withFirstPrompt(new TriggerEditPrompt(editor)).buildConversation(player);
.withEscapeSequence("exit").withEscapeSequence("triggers").withEscapeSequence("/npc path")
.withModality(false).withFirstPrompt(new TriggerEditPrompt(editor)).buildConversation(player);
conversation.begin();
return conversation;
}

View File

@ -2,15 +2,15 @@ package net.citizensnpcs.trait.waypoint.triggers;
import java.util.List;
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 net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.trait.waypoint.WaypointEditor;
import net.citizensnpcs.util.Messages;
public class TriggerRemovePrompt extends StringPrompt {
private final WaypointEditor editor;
@ -37,7 +37,7 @@ public class TriggerRemovePrompt extends StringPrompt {
return this;
}
List<WaypointTrigger> triggers = editor.getCurrentWaypoint().getTriggers();
if (index < triggers.size() || index >= triggers.size()) {
if (index >= triggers.size()) {
Messaging.sendErrorTr((CommandSender) context.getForWhom(),
Messages.WAYPOINT_TRIGGER_REMOVE_INDEX_OUT_OF_RANGE, triggers.size());
} else {
@ -61,7 +61,7 @@ public class TriggerRemovePrompt extends StringPrompt {
for (WaypointTrigger trigger : editor.getCurrentWaypoint().getTriggers()) {
root += String.format("<br> %d. " + trigger.description(), i++);
}
Messaging.sendTr((CommandSender) context.getForWhom(), Messages.WAYPOINT_TRIGGER_REMOVE_PROMPT + root);
Messaging.send((CommandSender) context.getForWhom(), root);
return "";
}
}

View File

@ -22,6 +22,12 @@ public class WaypointTriggerRegistry implements Persister<WaypointTrigger> {
@Override
public void save(WaypointTrigger instance, DataKey root) {
PersistenceLoader.save(instance, root);
for (Map.Entry<String, Class<? extends WaypointTrigger>> entry : triggers.entrySet()) {
if (entry.getValue() == instance.getClass()) {
root.setString("type", entry.getKey());
break;
}
}
}
public static void addTrigger(String name, Class<? extends WaypointTrigger> triggerClass,

View File

@ -220,7 +220,7 @@ citizens.editors.waypoints.guided.end=Exited the guided waypoint editor.
citizens.editors.waypoints.guided.added-guide=Added a [[guide]] waypoint. This will guide NPCs to their destination.
citizens.editors.waypoints.guided.added-available=Added a [[destination]] waypoint. This will be available for NPCs to path to.
citizens.editors.waypoints.linear.added-waypoint=[[Added]] a waypoint at ({0}) ([[{1}]], [[{2}]])
citizens.editors.waypoints.linear.begin=<b>Entered the linear waypoint editor!<br><b> [[Left click]] to add a waypoint, [[right click]] to remove.<br><b> Type [[toggle path]] to toggle showing entities at waypoints, [[triggers]] to enter the trigger editor and [[clear]] to clear all waypoints.
citizens.editors.waypoints.linear.begin=<b>Entered the linear waypoint editor!<br> [[Left click]] to add a waypoint, [[right click]] to remove.<br> Type [[toggle path]] to toggle showing entities at waypoints, [[triggers]] to enter the trigger editor and [[clear]] to clear all waypoints.
citizens.editors.waypoints.linear.edit-slot-set=Editing slot set to [[{0}]] ({1}).
citizens.editors.waypoints.linear.end=Exited the linear waypoint editor.
citizens.editors.waypoints.linear.not-showing-markers=[[Stopped]] showing waypoint markers.
@ -239,11 +239,11 @@ 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><b> Current triggers are:
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.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:
citizens.editors.waypoints.triggers.remove.removed=Successfully removed trigger {0}.
citizens.editors.waypoints.triggers.remove.removed=Successfully removed trigger [[{0}]].
citizens.editors.waypoints.triggers.speed.prompt=Enter the speed modifier as a [[percentage]] of its base speed.
citizens.editors.waypoints.triggers.teleport.invalid-format=Invalid location given. Format is [[world]]:[[x]]:[[y]]:[[z]].
citizens.editors.waypoints.triggers.teleport.prompt=Enter the destination in the format world:x:y:z. Type [[here]] to use your current location. Type [[back]] to return to the edit prompt.