mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-12-25 02:27:41 +01:00
Further fixes for guided waypoints
This commit is contained in:
parent
b14663c588
commit
64e47912c7
@ -21,6 +21,16 @@ import net.citizensnpcs.api.npc.NPCRegistry;
|
|||||||
public class EntityMarkers<T> {
|
public class EntityMarkers<T> {
|
||||||
private final Map<T, Entity> markers = Maps.newHashMap();
|
private final Map<T, Entity> markers = Maps.newHashMap();
|
||||||
private final NPCRegistry registry = CitizensAPI.createAnonymousNPCRegistry(new MemoryNPCDataStore());
|
private final NPCRegistry registry = CitizensAPI.createAnonymousNPCRegistry(new MemoryNPCDataStore());
|
||||||
|
private EntityType type;
|
||||||
|
|
||||||
|
public EntityMarkers() {
|
||||||
|
this(EntityType.ENDER_SIGNAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityMarkers(EntityType type) {
|
||||||
|
this.type = type;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates and persists (in memory) an {@link Entity} marker.
|
* Creates and persists (in memory) an {@link Entity} marker.
|
||||||
@ -63,7 +73,7 @@ public class EntityMarkers<T> {
|
|||||||
* @return the spawned entity
|
* @return the spawned entity
|
||||||
*/
|
*/
|
||||||
public Entity spawnMarker(World world, Location at) {
|
public Entity spawnMarker(World world, Location at) {
|
||||||
NPC npc = registry.createNPC(EntityType.ENDER_SIGNAL, "");
|
NPC npc = registry.createNPC(type, "");
|
||||||
npc.spawn(at.clone().add(0.5, 0, 0.5), SpawnReason.CREATE);
|
npc.spawn(at.clone().add(0.5, 0, 0.5), SpawnReason.CREATE);
|
||||||
return npc.getEntity();
|
return npc.getEntity();
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.block.Action;
|
import org.bukkit.event.block.Action;
|
||||||
@ -86,18 +87,20 @@ public class GuidedWaypointProvider implements EnumerableWaypointProvider {
|
|||||||
}
|
}
|
||||||
final Player player = (Player) sender;
|
final Player player = (Player) sender;
|
||||||
return new WaypointEditor() {
|
return new WaypointEditor() {
|
||||||
private final EntityMarkers<Waypoint> markers = new EntityMarkers<Waypoint>();
|
private final EntityMarkers<Waypoint> markers = new EntityMarkers<Waypoint>(EntityType.ITEM_FRAME);
|
||||||
private boolean showPath;
|
private boolean showPath;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void begin() {
|
public void begin() {
|
||||||
showPath();
|
if (showPath) {
|
||||||
|
createWaypointMarkers();
|
||||||
|
}
|
||||||
Messaging.sendTr(player, Messages.GUIDED_WAYPOINT_EDITOR_BEGIN);
|
Messaging.sendTr(player, Messages.GUIDED_WAYPOINT_EDITOR_BEGIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createWaypointMarkers() {
|
private void createWaypointMarkers() {
|
||||||
for (Waypoint waypoint : Iterables.concat(available, helpers)) {
|
for (Waypoint waypoint : waypoints()) {
|
||||||
markers.createMarker(waypoint, waypoint.getLocation().clone().add(0, 1, 0));
|
createWaypointMarkerWithData(waypoint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,13 +151,19 @@ public class GuidedWaypointProvider implements EnumerableWaypointProvider {
|
|||||||
return;
|
return;
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
Location at = event.getClickedBlock().getLocation();
|
Location at = event.getClickedBlock().getLocation();
|
||||||
|
for (Waypoint waypoint : waypoints()) {
|
||||||
|
if (waypoint.getLocation().equals(at)) {
|
||||||
|
Messaging.sendTr(player, Messages.GUIDED_WAYPOINT_EDITOR_ALREADY_TAKEN);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
Waypoint element = new Waypoint(at);
|
Waypoint element = new Waypoint(at);
|
||||||
if (player.isSneaking()) {
|
if (player.isSneaking()) {
|
||||||
available.add(element);
|
available.add(element);
|
||||||
Messaging.send(player, Messages.GUIDED_WAYPOINT_EDITOR_ADDED_AVAILABLE);
|
Messaging.sendTr(player, Messages.GUIDED_WAYPOINT_EDITOR_ADDED_AVAILABLE);
|
||||||
} else {
|
} else {
|
||||||
helpers.add(element);
|
helpers.add(element);
|
||||||
Messaging.send(player, Messages.GUIDED_WAYPOINT_EDITOR_ADDED_GUIDE);
|
Messaging.sendTr(player, Messages.GUIDED_WAYPOINT_EDITOR_ADDED_GUIDE);
|
||||||
}
|
}
|
||||||
if (showPath) {
|
if (showPath) {
|
||||||
createWaypointMarkerWithData(element);
|
createWaypointMarkerWithData(element);
|
||||||
@ -169,19 +178,15 @@ public class GuidedWaypointProvider implements EnumerableWaypointProvider {
|
|||||||
int hashcode = event.getRightClicked().getMetadata("citizens.waypointhashcode").get(0).asInt();
|
int hashcode = event.getRightClicked().getMetadata("citizens.waypointhashcode").get(0).asInt();
|
||||||
Iterator<Waypoint> itr = Iterables.concat(available, helpers).iterator();
|
Iterator<Waypoint> itr = Iterables.concat(available, helpers).iterator();
|
||||||
while (itr.hasNext()) {
|
while (itr.hasNext()) {
|
||||||
if (itr.next().hashCode() == hashcode) {
|
Waypoint next = itr.next();
|
||||||
|
if (next.hashCode() == hashcode) {
|
||||||
|
markers.removeMarker(next);
|
||||||
itr.remove();
|
itr.remove();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showPath() {
|
|
||||||
for (Waypoint element : Iterables.concat(available, helpers)) {
|
|
||||||
createWaypointMarkerWithData(element);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void togglePath() {
|
private void togglePath() {
|
||||||
showPath = !showPath;
|
showPath = !showPath;
|
||||||
if (showPath) {
|
if (showPath) {
|
||||||
|
@ -109,6 +109,7 @@ public class Messages {
|
|||||||
public static final String GRAVITY_ENABLED = "citizens.commands.npc.gravity.enabled";
|
public static final String GRAVITY_ENABLED = "citizens.commands.npc.gravity.enabled";
|
||||||
public static final String GUIDED_WAYPOINT_EDITOR_ADDED_AVAILABLE = "citizens.editors.waypoints.guided.added-available";
|
public static final String GUIDED_WAYPOINT_EDITOR_ADDED_AVAILABLE = "citizens.editors.waypoints.guided.added-available";
|
||||||
public static final String GUIDED_WAYPOINT_EDITOR_ADDED_GUIDE = "citizens.editors.waypoints.guided.added-guide";
|
public static final String GUIDED_WAYPOINT_EDITOR_ADDED_GUIDE = "citizens.editors.waypoints.guided.added-guide";
|
||||||
|
public static final String GUIDED_WAYPOINT_EDITOR_ALREADY_TAKEN = "citizens.editors.waypoints.guided.already-taken";
|
||||||
public static final String GUIDED_WAYPOINT_EDITOR_BEGIN = "citizens.editors.waypoints.guided.begin";
|
public static final String GUIDED_WAYPOINT_EDITOR_BEGIN = "citizens.editors.waypoints.guided.begin";
|
||||||
public static final String GUIDED_WAYPOINT_EDITOR_END = "citizens.editors.waypoints.guided.end";
|
public static final String GUIDED_WAYPOINT_EDITOR_END = "citizens.editors.waypoints.guided.end";
|
||||||
public static final String HORSE_CHEST_SET = "citizens.commands.npc.horse.chest-set";
|
public static final String HORSE_CHEST_SET = "citizens.commands.npc.horse.chest-set";
|
||||||
|
@ -279,7 +279,8 @@ citizens.editors.waypoints.guided.end=Exited the guided waypoint editor.
|
|||||||
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.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.added-guide=Added a [[guide]] waypoint. This will guide NPCs to their destination.
|
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.
|
citizens.editors.waypoints.guided.added-available=Added a [[destination]] waypoint. This will be available for NPCs to path to.
|
||||||
citizens.editors.waypoints.linear.added-waypoint=[[Added]] a waypoint at ({0}) ([[{1}]], [[{2}]])
|
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 linear waypoint editor!<br> [[Left click]] to add a waypoint, [[right click]] to remove.<br> Type [[toggle path]] to toggle showing entities at waypoints, [[triggers]] to enter the trigger editor and [[clear]] to clear all waypoints.
|
citizens.editors.waypoints.linear.begin=<b>Entered the linear waypoint editor!<br> [[Left click]] to add a waypoint, [[right click]] to remove.<br> Type [[toggle path]] to toggle showing entities at waypoints, [[triggers]] to enter the trigger editor and [[clear]] to clear all waypoints.
|
||||||
citizens.editors.waypoints.linear.edit-slot-set=Editing slot set to [[{0}]] ({1}).
|
citizens.editors.waypoints.linear.edit-slot-set=Editing slot set to [[{0}]] ({1}).
|
||||||
citizens.editors.waypoints.linear.end=Exited the linear waypoint editor.
|
citizens.editors.waypoints.linear.end=Exited the linear waypoint editor.
|
||||||
|
Loading…
Reference in New Issue
Block a user