Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add speed waypoint trigger, stop pathfinding if y < -5
- Loading branch information
Showing
6 changed files
with
64 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/main/java/net/citizensnpcs/trait/waypoint/triggers/SpeedTrigger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/net/citizensnpcs/trait/waypoint/triggers/SpeedTriggerPrompt.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters