Skip to content

Commit

Permalink
Remove editing slot from linear waypoint editor, make showing points …
Browse files Browse the repository at this point in the history
…the default and adjust messages to explain this
  • Loading branch information
fullwall committed Oct 13, 2020
1 parent c46362b commit 306a448
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerItemHeldEvent;
import org.bukkit.util.Vector;

import com.google.common.collect.Lists;
Expand Down Expand Up @@ -176,10 +175,10 @@ public Iterable<Waypoint> waypoints() {
private final class LinearWaypointEditor extends WaypointEditor {
Conversation conversation;
boolean editing = true;
int editingSlot = waypoints.size() - 1;
EntityMarkers<Waypoint> markers;
private final Player player;
private boolean showPath;
private Waypoint selectedWaypoint;
private boolean showPath = true;

private LinearWaypointEditor(Player player) {
this.player = player;
Expand All @@ -192,7 +191,6 @@ public void begin() {
}

private void clearWaypoints() {
editingSlot = 0;
waypoints.clear();
onWaypointsModified();
markers.destroyMarkers();
Expand Down Expand Up @@ -229,20 +227,13 @@ public Waypoint getCurrentWaypoint() {
if (waypoints.size() == 0 || !editing) {
return null;
}
normaliseEditingSlot();
return waypoints.get(editingSlot);
return selectedWaypoint == null ? waypoints.get(waypoints.size() - 1) : selectedWaypoint;
}

private Location getPreviousWaypoint(int fromSlot) {
private Location getPreviousWaypoint() {
if (waypoints.size() <= 1)
return null;
if (--fromSlot < 0)
fromSlot = waypoints.size() - 1;
return waypoints.get(fromSlot).getLocation();
}

private void normaliseEditingSlot() {
editingSlot = Math.max(0, Math.min(waypoints.size() - 1, editingSlot));
return waypoints.get(waypoints.size() - 2).getLocation();
}

@EventHandler
Expand Down Expand Up @@ -309,7 +300,7 @@ public void onPlayerInteract(PlayerInteractEvent event) {
return;
event.setCancelled(true);
Location at = event.getClickedBlock().getLocation();
Location prev = getPreviousWaypoint(editingSlot);
Location prev = getPreviousWaypoint();

if (prev != null && prev.getWorld() == at.getWorld()) {
double distance = at.distanceSquared(prev);
Expand All @@ -322,28 +313,22 @@ public void onPlayerInteract(PlayerInteractEvent event) {
}

Waypoint element = new Waypoint(at);
normaliseEditingSlot();
if (editingSlot >= waypoints.size()) {
waypoints.add(element);
} else {
waypoints.add(editingSlot, element);
}
waypoints.add(element);
if (showPath) {
markers.createMarker(element, element.getLocation().clone().add(0, 1, 0));
}
editingSlot = Math.min(editingSlot + 1, waypoints.size());
Messaging.sendTr(player, Messages.LINEAR_WAYPOINT_EDITOR_ADDED_WAYPOINT, formatLoc(at), editingSlot + 1,
Messaging.sendTr(player, Messages.LINEAR_WAYPOINT_EDITOR_ADDED_WAYPOINT, formatLoc(at),
waypoints.size());
} else if (waypoints.size() > 0 && !event.getPlayer().isSneaking()) {
event.setCancelled(true);
normaliseEditingSlot();
Waypoint waypoint = waypoints.remove(editingSlot);
Waypoint waypoint = waypoints.remove(waypoints.size() - 1);
if (waypoint.equals(selectedWaypoint)) {
selectedWaypoint = null;
}
if (showPath) {
markers.removeMarker(waypoint);
}
editingSlot = Math.max(0, editingSlot - 1);
Messaging.sendTr(player, Messages.LINEAR_WAYPOINT_EDITOR_REMOVED_WAYPOINT, waypoints.size(),
editingSlot + 1);
Messaging.sendTr(player, Messages.LINEAR_WAYPOINT_EDITOR_REMOVED_WAYPOINT, waypoints.size());
}
onWaypointsModified();
}
Expand All @@ -364,33 +349,15 @@ public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
}
if (slot == -1)
return;
editingSlot = slot;
Messaging.sendTr(player, Messages.LINEAR_WAYPOINT_EDITOR_EDIT_SLOT_SET, editingSlot,
formatLoc(waypoints.get(editingSlot).getLocation()));
}

@EventHandler
public void onPlayerItemHeldChange(PlayerItemHeldEvent event) {
if (!event.getPlayer().equals(player) || waypoints.size() == 0)
if (selectedWaypoint != null && waypoints.get(slot) == selectedWaypoint) {
waypoints.remove(slot);
selectedWaypoint = null;
Messaging.sendTr(player, Messages.LINEAR_WAYPOINT_EDITOR_REMOVED_WAYPOINT, waypoints.size());
return;
int previousSlot = event.getPreviousSlot(), newSlot = event.getNewSlot();
// handle wrap-arounds
if (previousSlot == 0 && newSlot == LARGEST_SLOT) {
editingSlot--;
} else if (previousSlot == LARGEST_SLOT && newSlot == 0) {
editingSlot++;
} else {
int diff = newSlot - previousSlot;
if (Math.abs(diff) != 1)
return; // the player isn't scrolling
editingSlot += diff > 0 ? 1 : -1;
}
normaliseEditingSlot();
if (conversation != null) {
getCurrentWaypoint().describeTriggers(player);
}
Messaging.sendTr(player, Messages.LINEAR_WAYPOINT_EDITOR_EDIT_SLOT_SET, editingSlot,
formatLoc(waypoints.get(editingSlot).getLocation()));
selectedWaypoint = waypoints.get(slot);
Messaging.sendTr(player, Messages.LINEAR_WAYPOINT_EDITOR_SELECTED_WAYPOINT,
formatLoc(selectedWaypoint.getLocation()));
}

private void onWaypointsModified() {
Expand All @@ -412,8 +379,6 @@ private void togglePath() {
Messaging.sendTr(player, Messages.LINEAR_WAYPOINT_EDITOR_NOT_SHOWING_MARKERS);
}
}

private static final int LARGEST_SLOT = 8;
}

private class LinearWaypointGoal implements Goal {
Expand Down
2 changes: 1 addition & 1 deletion main/src/main/java/net/citizensnpcs/util/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,11 @@ public class Messages {
public static final String LEASHABLE_STOPPED = "citizens.commands.npc.leashable.stopped";
public static final String LINEAR_WAYPOINT_EDITOR_ADDED_WAYPOINT = "citizens.editors.waypoints.linear.added-waypoint";
public static final String LINEAR_WAYPOINT_EDITOR_BEGIN = "citizens.editors.waypoints.linear.begin";
public static final String LINEAR_WAYPOINT_EDITOR_EDIT_SLOT_SET = "citizens.editors.waypoints.linear.edit-slot-set";
public static final String LINEAR_WAYPOINT_EDITOR_END = "citizens.editors.waypoints.linear.end";
public static final String LINEAR_WAYPOINT_EDITOR_NOT_SHOWING_MARKERS = "citizens.editors.waypoints.linear.not-showing-markers";
public static final String LINEAR_WAYPOINT_EDITOR_RANGE_EXCEEDED = "citizens.editors.waypoints.linear.range-exceeded";
public static final String LINEAR_WAYPOINT_EDITOR_REMOVED_WAYPOINT = "citizens.editors.waypoints.linear.removed-waypoint";
public static final String LINEAR_WAYPOINT_EDITOR_SELECTED_WAYPOINT = "citizens.editors.waypoints.linear.selected-waypoint";
public static final String LINEAR_WAYPOINT_EDITOR_SHOWING_MARKERS = "citizens.editors.waypoints.linear.showing-markers";
public static final String LINEAR_WAYPOINT_EDITOR_WAYPOINTS_CLEARED = "citizens.editors.waypoints.linear.waypoints-cleared";
public static final String LLAMA_COLOR_SET = "citizens.commands.npc.llama.color-set";
Expand Down
4 changes: 2 additions & 2 deletions main/src/main/resources/messages_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,8 @@ citizens.editors.waypoints.guided.added-guide=Added a [[guide]] waypoint. This w
citizens.editors.waypoints.guided.added-available=Added a [[destination]] waypoint. This will be available for NPCs to path to.
citizens.editors.waypoints.guided.already-taken=There is already a waypoint here.
citizens.editors.waypoints.linear.added-waypoint=[[Added]] a waypoint at ({0}) ([[{1}]], [[{2}]]).
citizens.editors.waypoints.linear.begin=<b>Entered the <l>linear waypoint editor!<br> [[Left click]] to add a waypoint, [[right click]] to remove.<br> Type [[toggle path]] to toggle showing entities at waypoints,<br> [[triggers]] to enter the trigger editor,<br> [[clear]] to clear all waypoints<br> [[cycle]] to make NPCs go back to cycle through waypoints instead of looping.
citizens.editors.waypoints.linear.edit-slot-set=Editing slot set to [[{0}]] ({1}).
citizens.editors.waypoints.linear.begin=<b>=== <l>Linear Waypoint Editor ===<br> [[Left click]] to add a waypoint, [[right click]] to remove it.<br> You can right click while sneaking to select and remove specific points.<br> Type [[markers]] to hide waypoints,<br> [[triggers]] to enter the trigger editor,<br> [[clear]] to clear all waypoints,<br> [[cycle]] to make NPCs cycle through waypoints instead of looping.
citizens.editors.waypoints.linear.selected-waypoint=Selected waypoint at {1}. Sneak + right click again to remove this waypoint.
citizens.editors.waypoints.linear.end=Exited the linear waypoint editor.
citizens.editors.waypoints.linear.not-showing-markers=[[Stopped]] showing waypoint markers.
citizens.editors.waypoints.linear.range-exceeded=Previous waypoint is {0} blocks away but the distance limit is {1}.
Expand Down

0 comments on commit 306a448

Please sign in to comment.