mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-23 11:05:49 +01:00
Add speed waypoint trigger, stop pathfinding if y < -5
This commit is contained in:
parent
4b5100b9ce
commit
dc0fc270f1
@ -255,6 +255,10 @@ public class CitizensNavigator implements Navigator, Runnable {
|
||||
if (localParams.stationaryTicks() < 0)
|
||||
return false;
|
||||
Location current = npc.getEntity().getLocation(STATIONARY_LOCATION);
|
||||
if (current.getY() < -5) {
|
||||
stopNavigating(CancelReason.STUCK);
|
||||
return true;
|
||||
}
|
||||
if (lastX == current.getBlockX() && lastY == current.getBlockY() && lastZ == current.getBlockZ()) {
|
||||
if (++stationaryTicks >= localParams.stationaryTicks()) {
|
||||
stopNavigating(CancelReason.STUCK);
|
||||
|
@ -0,0 +1,32 @@
|
||||
package net.citizensnpcs.trait.waypoint.triggers;
|
||||
|
||||
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;
|
||||
|
||||
public SpeedTrigger() {
|
||||
}
|
||||
|
||||
public SpeedTrigger(float speed) {
|
||||
this.speed = speed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String description() {
|
||||
return String.format("Speed change to %f", speed);
|
||||
}
|
||||
|
||||
public float getSpeed() {
|
||||
return speed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWaypointReached(NPC npc, Location waypoint) {
|
||||
npc.getNavigator().getDefaultParameters().speedModifier(speed);
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
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;
|
||||
|
||||
public class SpeedTriggerPrompt extends NumericPrompt implements WaypointTriggerPrompt {
|
||||
@Override
|
||||
protected Prompt acceptValidatedInput(ConversationContext context, Number input) {
|
||||
float speed = (float) Math.max(input.doubleValue(), 0);
|
||||
context.setSessionData(WaypointTriggerPrompt.CREATED_TRIGGER_KEY, new SpeedTrigger(speed));
|
||||
return (Prompt) context.getSessionData(WaypointTriggerPrompt.RETURN_PROMPT_KEY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPromptText(ConversationContext context) {
|
||||
return Messaging.tr(Messages.SPEED_TRIGGER_PROMPT);
|
||||
}
|
||||
}
|
@ -24,9 +24,6 @@ public class WaypointTriggerRegistry implements Persister<WaypointTrigger> {
|
||||
PersistenceLoader.save(instance, root);
|
||||
}
|
||||
|
||||
private static final Map<String, Class<? extends Prompt>> triggerPrompts = Maps.newHashMap();
|
||||
private static final Map<String, Class<? extends WaypointTrigger>> triggers = Maps.newHashMap();
|
||||
|
||||
public static void addTrigger(String name, Class<? extends WaypointTrigger> triggerClass,
|
||||
Class<? extends WaypointTriggerPrompt> promptClass) {
|
||||
triggers.put(name, triggerClass);
|
||||
@ -48,11 +45,15 @@ public class WaypointTriggerRegistry implements Persister<WaypointTrigger> {
|
||||
}
|
||||
}
|
||||
|
||||
private static final Map<String, Class<? extends Prompt>> triggerPrompts = Maps.newHashMap();
|
||||
private static final Map<String, Class<? extends WaypointTrigger>> triggers = Maps.newHashMap();
|
||||
|
||||
static {
|
||||
addTrigger("animation", AnimationTrigger.class, AnimationTriggerPrompt.class);
|
||||
addTrigger("chat", ChatTrigger.class, ChatTriggerPrompt.class);
|
||||
addTrigger("delay", DelayTrigger.class, DelayTriggerPrompt.class);
|
||||
addTrigger("teleport", TeleportTrigger.class, TeleportTriggerPrompt.class);
|
||||
addTrigger("speed", SpeedTrigger.class, SpeedTriggerPrompt.class);
|
||||
// addTrigger("pose", PoseTrigger.class, PoseTriggerPrompt.class);
|
||||
}
|
||||
}
|
||||
|
@ -191,6 +191,7 @@ public class Messages {
|
||||
public static final String SPAWN_NUMERIC_ID_ONLY = "citizens.commands.npc.spawn.numeric-id-only";
|
||||
public static final String SPEED_MODIFIER_ABOVE_LIMIT = "citizens.commands.npc.speed.modifier-above-limit";
|
||||
public static final String SPEED_MODIFIER_SET = "citizens.commands.npc.speed.set";
|
||||
public static final String SPEED_TRIGGER_PROMPT = "citizens.editors.waypoints.triggers.speed.prompt";
|
||||
public static final String SWIMMING_SET = "citizens.commands.npc.swim.set";
|
||||
public static final String SWIMMING_UNSET = "citizens.commands.npc.swim.unset";
|
||||
public static final String TARGETABLE_SET = "citizens.commands.npc.targetable.set";
|
||||
|
@ -215,6 +215,7 @@ citizens.editors.waypoints.triggers.remove.index-out-of-range=Index must be in t
|
||||
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.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.
|
||||
citizens.limits.over-npc-limit=Over the NPC limit of {0}.
|
||||
|
Loading…
Reference in New Issue
Block a user