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