mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-26 04:35:50 +01:00
Add basic editor for wander waypoints
This commit is contained in:
parent
226470d743
commit
49c6d3cbed
@ -1,34 +1,69 @@
|
||||
package net.citizensnpcs.trait.waypoint;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.ai.Goal;
|
||||
import net.citizensnpcs.api.ai.goals.WanderGoal;
|
||||
import net.citizensnpcs.api.command.CommandContext;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.api.persistence.Persist;
|
||||
import net.citizensnpcs.api.util.DataKey;
|
||||
import net.citizensnpcs.api.util.Messaging;
|
||||
import net.citizensnpcs.util.Messages;
|
||||
|
||||
public class WanderWaypointProvider implements WaypointProvider {
|
||||
private Goal currentGoal;
|
||||
private NPC npc;
|
||||
private volatile boolean paused;
|
||||
@Persist
|
||||
private final int xrange = DEFAULT_XRANGE;
|
||||
public int xrange = DEFAULT_XRANGE;
|
||||
@Persist
|
||||
private final int yrange = DEFAULT_YRANGE;
|
||||
public int yrange = DEFAULT_YRANGE;
|
||||
|
||||
@Override
|
||||
public WaypointEditor createEditor(CommandSender sender, CommandContext args) {
|
||||
public WaypointEditor createEditor(final CommandSender sender, CommandContext args) {
|
||||
return new WaypointEditor() {
|
||||
@Override
|
||||
public void begin() {
|
||||
// TODO Auto-generated method stub
|
||||
Messaging.sendTr(sender, Messages.WANDER_WAYPOINTS_BEGIN);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void end() {
|
||||
// TODO Auto-generated method stub
|
||||
Messaging.sendTr(sender, Messages.WANDER_WAYPOINTS_END);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPlayerChat(AsyncPlayerChatEvent event) {
|
||||
if (!event.getPlayer().equals(sender))
|
||||
return;
|
||||
String message = event.getMessage().toLowerCase();
|
||||
if (message.startsWith("xrange") || message.startsWith("yrange")) {
|
||||
event.setCancelled(true);
|
||||
int range = 0;
|
||||
try {
|
||||
range = Integer.parseInt(message.split(" ", 2)[1]);
|
||||
if (range <= 0) {
|
||||
range = 0;
|
||||
}
|
||||
if (message.startsWith("xrange")) {
|
||||
xrange = range;
|
||||
} else {
|
||||
yrange = range;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Messaging.sendTr(sender, Messages.WANDER_WAYPOINTS_RANGE_SET, xrange, yrange);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -66,6 +101,5 @@ public class WanderWaypointProvider implements WaypointProvider {
|
||||
}
|
||||
|
||||
private static final int DEFAULT_XRANGE = 3;
|
||||
|
||||
private static final int DEFAULT_YRANGE = 25;
|
||||
}
|
||||
|
@ -265,6 +265,9 @@ public class Messages {
|
||||
public static final String UNKNOWN_MATERIAL = "citizens.commands.npc.item.unknown-material";
|
||||
public static final String VULNERABLE_SET = "citizens.commands.npc.vulnerable.set";
|
||||
public static final String VULNERABLE_STOPPED = "citizens.commands.npc.vulnerable.stopped";
|
||||
public static final String WANDER_WAYPOINTS_BEGIN = "citizens.editors.waypoints.wander.begin";
|
||||
public static final String WANDER_WAYPOINTS_END = "citizens.editors.waypoints.wander.end";
|
||||
public static final String WANDER_WAYPOINTS_RANGE_SET = "citizens.editors.waypoints.wander.range-set";
|
||||
public static final String WAYPOINT_PROVIDER_SET = "citizens.waypoints.set-provider";
|
||||
public static final String WAYPOINT_TELEPORTING_DISABLED = "citizens.commands.waypoints.disableteleporting.disabled";
|
||||
public static final String WAYPOINT_TRIGGER_ADD_PROMPT = "citizens.editors.waypoints.triggers.add.prompt";
|
||||
|
@ -213,7 +213,9 @@ citizens.editors.text.remove-prompt=Enter the index of the entry you wish to rem
|
||||
citizens.editors.text.removed-entry=[[Removed]] entry at index [[{0}]].
|
||||
citizens.editors.text.start-prompt=Type [[add]] to add an entry, [[edit]] to edit entries, [[remove]] to remove entries, [[close]] to toggle the NPC as a close talker, [[item]] to set the item in hand pattern, [[range]] to set the talking range, and [[random]] to toggle the NPC as a random talker. Type [[help]] to show this again.
|
||||
citizens.editors.text.talk-item-set=[[Talk item pattern]] set to [[{0}]].
|
||||
citizens.editors.waypoints.guided.begin=<b>Entered the guided waypoint editor!<br> [[Left click]] to add a waypoint guide, [[right click]] an existing waypoint to remove.<br> [[Sneak]] while left clicking to add a destination waypoint.<br> Type [[toggle path]] to toggle showing entities at waypoints.
|
||||
citizens.editors.waypoints.wander.range-set=Wander range set to xrange [[{0}]] and yrange [[{1}]].
|
||||
citizens.editors.waypoints.wander.begin=<b>Entered the wander waypoint editor.<br> Type [[xrange <number>]] or [[yrange <number>]] to modify the random wander range.
|
||||
citizens.editors.waypoints.wander.end=Exited the wander waypoint editor.
|
||||
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.
|
||||
|
Loading…
Reference in New Issue
Block a user