mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-12-28 20:17:50 +01:00
Fixed an issue with waypoints
This commit is contained in:
parent
5bf0e6b0fe
commit
99f6f28e24
@ -15,12 +15,12 @@ import org.bukkit.entity.Player;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
public class MCNavigationStrategy implements PathStrategy {
|
||||
private EntityHumanNPC entity = null;
|
||||
private final EntityLiving entity;
|
||||
private final Navigation navigation;
|
||||
|
||||
MCNavigationStrategy(CitizensNPC npc, Location dest) {
|
||||
entity = npc.getHandle();
|
||||
if (npc.getBukkitEntity() instanceof Player) {
|
||||
entity = (EntityHumanNPC) npc.getHandle();
|
||||
entity.onGround = true;
|
||||
// not sure of a better way around this - if onGround is false, then
|
||||
// navigation won't execute, and calling entity.move doesn't
|
||||
@ -32,8 +32,8 @@ public class MCNavigationStrategy implements PathStrategy {
|
||||
}
|
||||
|
||||
MCNavigationStrategy(EntityLiving entity, EntityLiving target) {
|
||||
this.entity = entity;
|
||||
if (entity instanceof EntityHumanNPC) {
|
||||
this.entity = (EntityHumanNPC) entity;
|
||||
entity.onGround = true; // see above
|
||||
}
|
||||
navigation = entity.al();
|
||||
@ -60,9 +60,9 @@ public class MCNavigationStrategy implements PathStrategy {
|
||||
|
||||
@Override
|
||||
public boolean update() {
|
||||
if (entity != null) {
|
||||
if (entity instanceof EntityHumanNPC) {
|
||||
navigation.d();
|
||||
entity.moveOnCurrentHeading();
|
||||
((EntityHumanNPC) entity).moveOnCurrentHeading();
|
||||
}
|
||||
return navigation.e();
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHandle {
|
||||
@Override
|
||||
public void F_() {
|
||||
super.F_();
|
||||
if (motX != 0 || motZ != 0 || motY != 0) {
|
||||
if (!npc.getAI().hasDestination() && (motX != 0 || motZ != 0 || motY != 0)) {
|
||||
a(0, 0);
|
||||
}
|
||||
if (noDamageTicks > 0)
|
||||
|
@ -40,9 +40,11 @@ public class LinearWaypointProvider implements WaypointProvider, Iterable<Waypoi
|
||||
@EventHandler
|
||||
@SuppressWarnings("unused")
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (!event.getPlayer().equals(player))
|
||||
if (!event.getPlayer().equals(player) || event.getAction() == Action.PHYSICAL)
|
||||
return;
|
||||
if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
|
||||
if (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.LEFT_CLICK_AIR) {
|
||||
if (event.getClickedBlock() == null)
|
||||
return;
|
||||
Location at = event.getClickedBlock().getLocation();
|
||||
waypoints.add(new Waypoint(at));
|
||||
Messaging.send(player, String.format("<e>Added<a> a waypoint at (<e>%d<a>, <e>%d<a>, <e>%d<a>).",
|
||||
@ -67,6 +69,11 @@ public class LinearWaypointProvider implements WaypointProvider, Iterable<Waypoi
|
||||
return waypoints.iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach() {
|
||||
callback.onProviderChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(DataKey key) {
|
||||
for (DataKey root : key.getRelative("points").getIntegerSubKeys()) {
|
||||
@ -75,7 +82,6 @@ public class LinearWaypointProvider implements WaypointProvider, Iterable<Waypoi
|
||||
.getDouble("y"), root.getDouble("z"), (float) root.getDouble("yaw", 0), (float) root.getDouble(
|
||||
"pitch", 0))));
|
||||
}
|
||||
callback.onProviderChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -41,4 +41,6 @@ public interface WaypointProvider {
|
||||
* The key to save to
|
||||
*/
|
||||
public void save(DataKey key);
|
||||
|
||||
public void onAttach();
|
||||
}
|
@ -15,7 +15,7 @@ import org.bukkit.entity.Player;
|
||||
public class Waypoints extends Trait {
|
||||
private final NPC npc;
|
||||
private WaypointProvider provider = new LinearWaypointProvider();
|
||||
private String providerName;
|
||||
private String providerName = "linear";
|
||||
|
||||
public Waypoints(NPC npc) {
|
||||
this.npc = npc;
|
||||
@ -32,6 +32,11 @@ public class Waypoints extends Trait {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNPCSpawn() {
|
||||
npc.getAI().registerNavigationCallback(provider.getCallback());
|
||||
}
|
||||
|
||||
public Editor getEditor(Player player) {
|
||||
return provider.createEditor(player);
|
||||
}
|
||||
@ -49,7 +54,6 @@ public class Waypoints extends Trait {
|
||||
if (provider == null)
|
||||
return;
|
||||
provider.load(key.getRelative(providerName));
|
||||
npc.getAI().registerNavigationCallback(provider.getCallback());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user