mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-12-23 17:47:35 +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> {
|
||||
private final Map<T, Entity> markers = Maps.newHashMap();
|
||||
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.
|
||||
@ -63,7 +73,7 @@ public class EntityMarkers<T> {
|
||||
* @return the spawned entity
|
||||
*/
|
||||
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);
|
||||
return npc.getEntity();
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.block.Action;
|
||||
@ -86,18 +87,20 @@ public class GuidedWaypointProvider implements EnumerableWaypointProvider {
|
||||
}
|
||||
final Player player = (Player) sender;
|
||||
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;
|
||||
|
||||
@Override
|
||||
public void begin() {
|
||||
showPath();
|
||||
if (showPath) {
|
||||
createWaypointMarkers();
|
||||
}
|
||||
Messaging.sendTr(player, Messages.GUIDED_WAYPOINT_EDITOR_BEGIN);
|
||||
}
|
||||
|
||||
private void createWaypointMarkers() {
|
||||
for (Waypoint waypoint : Iterables.concat(available, helpers)) {
|
||||
markers.createMarker(waypoint, waypoint.getLocation().clone().add(0, 1, 0));
|
||||
for (Waypoint waypoint : waypoints()) {
|
||||
createWaypointMarkerWithData(waypoint);
|
||||
}
|
||||
}
|
||||
|
||||
@ -148,13 +151,19 @@ public class GuidedWaypointProvider implements EnumerableWaypointProvider {
|
||||
return;
|
||||
event.setCancelled(true);
|
||||
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);
|
||||
if (player.isSneaking()) {
|
||||
available.add(element);
|
||||
Messaging.send(player, Messages.GUIDED_WAYPOINT_EDITOR_ADDED_AVAILABLE);
|
||||
Messaging.sendTr(player, Messages.GUIDED_WAYPOINT_EDITOR_ADDED_AVAILABLE);
|
||||
} else {
|
||||
helpers.add(element);
|
||||
Messaging.send(player, Messages.GUIDED_WAYPOINT_EDITOR_ADDED_GUIDE);
|
||||
Messaging.sendTr(player, Messages.GUIDED_WAYPOINT_EDITOR_ADDED_GUIDE);
|
||||
}
|
||||
if (showPath) {
|
||||
createWaypointMarkerWithData(element);
|
||||
@ -169,19 +178,15 @@ public class GuidedWaypointProvider implements EnumerableWaypointProvider {
|
||||
int hashcode = event.getRightClicked().getMetadata("citizens.waypointhashcode").get(0).asInt();
|
||||
Iterator<Waypoint> itr = Iterables.concat(available, helpers).iterator();
|
||||
while (itr.hasNext()) {
|
||||
if (itr.next().hashCode() == hashcode) {
|
||||
Waypoint next = itr.next();
|
||||
if (next.hashCode() == hashcode) {
|
||||
markers.removeMarker(next);
|
||||
itr.remove();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void showPath() {
|
||||
for (Waypoint element : Iterables.concat(available, helpers)) {
|
||||
createWaypointMarkerWithData(element);
|
||||
}
|
||||
}
|
||||
|
||||
private void togglePath() {
|
||||
showPath = !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 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_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_END = "citizens.editors.waypoints.guided.end";
|
||||
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.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.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.edit-slot-set=Editing slot set to [[{0}]] ({1}).
|
||||
citizens.editors.waypoints.linear.end=Exited the linear waypoint editor.
|
||||
|
Loading…
Reference in New Issue
Block a user