mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-27 13:15:33 +01:00
Attempted fixes
This commit is contained in:
parent
5b8a02d39c
commit
23ab7664a2
@ -4,6 +4,7 @@ import java.lang.reflect.Field;
|
||||
import java.util.Random;
|
||||
|
||||
import net.citizensnpcs.npc.CitizensNPC;
|
||||
import net.citizensnpcs.util.Messaging;
|
||||
import net.minecraft.server.EntityLiving;
|
||||
import net.minecraft.server.MathHelper;
|
||||
import net.minecraft.server.PathEntity;
|
||||
@ -18,6 +19,7 @@ public class MoveStrategy implements PathStrategy {
|
||||
private final EntityLiving handle;
|
||||
private final PathEntity path;
|
||||
private final Random random = new Random();
|
||||
|
||||
public MoveStrategy(CitizensNPC handle, Location destination) {
|
||||
this.handle = handle.getHandle();
|
||||
this.path = this.handle.world.a(this.handle, destination.getBlockX(), destination.getBlockY(),
|
||||
@ -79,6 +81,7 @@ public class MoveStrategy implements PathStrategy {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
Messaging.log(cachedSpeed);
|
||||
handle.e(cachedSpeed);
|
||||
// handle.walk();
|
||||
|
||||
@ -95,6 +98,7 @@ public class MoveStrategy implements PathStrategy {
|
||||
static {
|
||||
try {
|
||||
SPEED_FIELD = EntityLiving.class.getDeclaredField("bb");
|
||||
SPEED_FIELD.setAccessible(true);
|
||||
} catch (SecurityException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NoSuchFieldException e) {
|
||||
|
@ -9,12 +9,17 @@ import org.bukkit.Location;
|
||||
|
||||
public class GenericWaypointCallback extends NavigationCallback {
|
||||
private Location dest;
|
||||
private AI ai;
|
||||
private boolean executing;
|
||||
private Iterator<Waypoint> itr;
|
||||
private final Iterable<Waypoint> provider;
|
||||
|
||||
public GenericWaypointCallback(Iterable<Waypoint> provider) {
|
||||
this.provider = provider;
|
||||
this.itr = provider.iterator();
|
||||
if (itr.hasNext()) {
|
||||
dest = itr.next().getLocation();
|
||||
}
|
||||
}
|
||||
|
||||
private void ensureItr() {
|
||||
@ -24,6 +29,7 @@ public class GenericWaypointCallback extends NavigationCallback {
|
||||
|
||||
@Override
|
||||
public void onAttach(AI ai) {
|
||||
this.ai = ai;
|
||||
executing = !ai.hasDestination();
|
||||
if (!executing)
|
||||
return;
|
||||
@ -57,11 +63,7 @@ public class GenericWaypointCallback extends NavigationCallback {
|
||||
@Override
|
||||
public boolean onCompletion(AI ai) {
|
||||
if (executing) { // if we're executing, we need to get the next waypoint
|
||||
if (!itr.hasNext()) {
|
||||
dest = null;
|
||||
} else {
|
||||
dest = itr.next().getLocation();
|
||||
}
|
||||
dest = itr.hasNext() ? itr.next().getLocation() : null;
|
||||
} else {
|
||||
executing = true;
|
||||
// we're free to return to our waypoints!
|
||||
@ -76,5 +78,8 @@ public class GenericWaypointCallback extends NavigationCallback {
|
||||
public void onProviderChanged() {
|
||||
itr = provider.iterator();
|
||||
dest = itr.hasNext() ? itr.next().getLocation() : null;
|
||||
if (dest != null) {
|
||||
ai.setDestination(dest);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import net.citizensnpcs.editor.Editor;
|
||||
import net.citizensnpcs.util.Messaging;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.block.Action;
|
||||
@ -19,7 +20,6 @@ import com.google.common.collect.Lists;
|
||||
|
||||
public class LinearWaypointProvider implements WaypointProvider, Iterable<Waypoint> {
|
||||
private final GenericWaypointCallback callback = new GenericWaypointCallback(this);
|
||||
|
||||
private final List<Waypoint> waypoints = Lists.newArrayList();
|
||||
|
||||
@Override
|
||||
@ -28,12 +28,12 @@ public class LinearWaypointProvider implements WaypointProvider, Iterable<Waypoi
|
||||
@Override
|
||||
public void begin() {
|
||||
player.sendMessage(ChatColor.AQUA + "Entered the linear waypoint editor!");
|
||||
player.sendMessage(ChatColor.GREEN + "Left click to add waypoint, right click to remove.");
|
||||
Messaging.send(player, "<e>Left click<a> to add a waypoint, <e>right click<a> to remove.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void end() {
|
||||
player.sendMessage(ChatColor.GREEN + "Exited linear waypoint editor.");
|
||||
player.sendMessage(ChatColor.AQUA + "Exited the linear waypoint editor.");
|
||||
callback.onProviderChanged();
|
||||
}
|
||||
|
||||
@ -42,10 +42,11 @@ public class LinearWaypointProvider implements WaypointProvider, Iterable<Waypoi
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (!event.getPlayer().equals(player))
|
||||
return;
|
||||
|
||||
if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
|
||||
waypoints.add(new Waypoint(event.getClickedBlock().getLocation()));
|
||||
Messaging.send(player, "<e>Added<a> a waypoint.");
|
||||
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>).",
|
||||
at.getBlockX(), at.getBlockY(), at.getBlockZ()));
|
||||
} else if (waypoints.size() > 0) {
|
||||
waypoints.remove(waypoints.size() - 1);
|
||||
Messaging.send(player,
|
||||
@ -70,6 +71,7 @@ public class LinearWaypointProvider implements WaypointProvider, Iterable<Waypoi
|
||||
for (DataKey root : key.getRelative("waypoints").getIntegerSubKeys()) {
|
||||
waypoints.add(new Waypoint(StorageUtils.loadLocation(root)));
|
||||
}
|
||||
callback.onProviderChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user