From 3a084f6159930a2ad8befd3cfe7144fc197c2a56 Mon Sep 17 00:00:00 2001 From: fullwall Date: Mon, 21 Oct 2013 00:24:48 +0800 Subject: [PATCH] Remove debug code in guided waypoint provider, add 'toggle path' to avoid showing waypoint markers --- .../waypoint/GuidedWaypointProvider.java | 41 +++++++++++++++---- src/main/resources/messages_en.properties | 2 +- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/src/main/java/net/citizensnpcs/trait/waypoint/GuidedWaypointProvider.java b/src/main/java/net/citizensnpcs/trait/waypoint/GuidedWaypointProvider.java index 012b65a7c..481843b71 100644 --- a/src/main/java/net/citizensnpcs/trait/waypoint/GuidedWaypointProvider.java +++ b/src/main/java/net/citizensnpcs/trait/waypoint/GuidedWaypointProvider.java @@ -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; } } diff --git a/src/main/resources/messages_en.properties b/src/main/resources/messages_en.properties index 991c87408..a3ab8ed27 100644 --- a/src/main/resources/messages_en.properties +++ b/src/main/resources/messages_en.properties @@ -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=Entered the guided waypoint editor!
[[Left click]] to add a waypoint guide, [[right click]] an existing waypoint to remove.
[[Sneak]] while left clicking to add a destination waypoint. +citizens.editors.waypoints.guided.begin=Entered the guided waypoint editor!
[[Left click]] to add a waypoint guide, [[right click]] an existing waypoint to remove.
[[Sneak]] while left clicking to add a destination waypoint.
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.