mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-23 19:16:34 +01:00
Remove debug code in guided waypoint provider, add 'toggle path' to avoid showing waypoint markers
This commit is contained in:
parent
7d8389b736
commit
f7ce723494
@ -25,12 +25,13 @@ import net.citizensnpcs.api.util.prtree.SimplePointND;
|
||||
import net.citizensnpcs.util.Messages;
|
||||
import net.citizensnpcs.util.Util;
|
||||
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
@ -52,6 +53,7 @@ public class GuidedWaypointProvider implements WaypointProvider {
|
||||
public WaypointEditor createEditor(final Player player, CommandContext args) {
|
||||
return new WaypointEditor() {
|
||||
private final WaypointMarkers markers = new WaypointMarkers(player.getWorld());
|
||||
private boolean showPath;
|
||||
|
||||
@Override
|
||||
public void begin() {
|
||||
@ -59,6 +61,12 @@ public class GuidedWaypointProvider implements WaypointProvider {
|
||||
Messaging.sendTr(player, Messages.GUIDED_WAYPOINT_EDITOR_BEGIN);
|
||||
}
|
||||
|
||||
private void createWaypointMarkers() {
|
||||
for (Waypoint waypoint : Iterables.concat(available, helpers)) {
|
||||
markers.createWaypointMarker(waypoint);
|
||||
}
|
||||
}
|
||||
|
||||
private void createWaypointMarkerWithData(Waypoint element) {
|
||||
Entity entity = markers.createWaypointMarker(element);
|
||||
if (entity == null)
|
||||
@ -73,6 +81,18 @@ public class GuidedWaypointProvider implements WaypointProvider {
|
||||
markers.destroyWaypointMarkers();
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPlayerChat(AsyncPlayerChatEvent event) {
|
||||
if (event.getMessage().equalsIgnoreCase("toggle path")) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
togglePath();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (!event.getPlayer().equals(player) || event.getAction() == Action.PHYSICAL
|
||||
@ -113,6 +133,17 @@ public class GuidedWaypointProvider implements WaypointProvider {
|
||||
createWaypointMarkerWithData(element);
|
||||
}
|
||||
}
|
||||
|
||||
private void togglePath() {
|
||||
showPath = !showPath;
|
||||
if (showPath) {
|
||||
createWaypointMarkers();
|
||||
Messaging.sendTr(player, Messages.LINEAR_WAYPOINT_EDITOR_SHOWING_MARKERS);
|
||||
} else {
|
||||
markers.destroyWaypointMarkers();
|
||||
Messaging.sendTr(player, Messages.LINEAR_WAYPOINT_EDITOR_NOT_SHOWING_MARKERS);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ -191,25 +222,19 @@ public class GuidedWaypointProvider implements WaypointProvider {
|
||||
@Override
|
||||
public void reset() {
|
||||
plan = null;
|
||||
System.err.println("Reset");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(GoalSelector selector) {
|
||||
if (plan.isComplete()) {
|
||||
selector.finish();
|
||||
System.err.println("Complete");
|
||||
return;
|
||||
}
|
||||
if (npc.getNavigator().isNavigating()) {
|
||||
return;
|
||||
}
|
||||
System.err.println("Updating target");
|
||||
Waypoint current = plan.getCurrentWaypoint();
|
||||
npc.getNavigator().setTarget(current.getLocation());
|
||||
for (int i = 0; i < 5; i++)
|
||||
current.getLocation().getWorld()
|
||||
.playEffect(current.getLocation().clone().add(0, 1, 0), Effect.STEP_SOUND, 1);
|
||||
npc.getNavigator().getLocalParameters().addSingleUseCallback(new NavigatorCallback() {
|
||||
@Override
|
||||
public void onCompletion(CancelReason cancelReason) {
|
||||
@ -225,8 +250,6 @@ public class GuidedWaypointProvider implements WaypointProvider {
|
||||
}
|
||||
Waypoint target = available.get(Util.getFastRandom().nextInt(available.size()));
|
||||
plan = ASTAR.runFully(new GuidedGoal(target), new GuidedNode(new Waypoint(npc.getStoredLocation())));
|
||||
if (plan == null)
|
||||
System.err.println("No path");
|
||||
return plan != null;
|
||||
}
|
||||
}
|
||||
|
@ -171,7 +171,7 @@ 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.
|
||||
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.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