Missed last commit for 1.6, whoopsies! This commit is from 1.6.1.
Some cleanup on SetPathfinderGoal effect, and also testing support for multiple entities.
This commit is contained in:
@@ -26,6 +26,8 @@ public interface NMSInterface {
|
||||
|
||||
public Object getIndex(Object nbtList, int index);
|
||||
|
||||
public void clearPathfinderGoals(Entity entity);
|
||||
|
||||
public void removePathfinderGoal(Object entity, Class<?> goalClass, boolean isTargetSelector);
|
||||
|
||||
public void addPathfinderGoal(Object entity, int priority, Object goal, boolean isTargetSelector);
|
||||
|
||||
@@ -166,6 +166,11 @@ public class NMS_v1_7_R4 implements NMSInterface {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearPathfinderGoals(Entity entity) {
|
||||
Bukkit.getLogger().warning("Sorry, Pathfinder Goal are only supported in 1.8 and above");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removePathfinderGoal(Object entity, Class<?> goalClass, boolean isTargetSelector) {
|
||||
Bukkit.getLogger().warning("Sorry, Pathfinder Goals are only supported in 1.8 and above");
|
||||
|
||||
@@ -148,6 +148,15 @@ public class NMS_v1_8_R1 implements NMSInterface {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearPathfinderGoals(Entity entity) {
|
||||
EntityInsentient nmsEnt = (EntityInsentient) ((CraftEntity) entity).getHandle();
|
||||
((List<?>) ReflectionUtils.getField("b", PathfinderGoalSelector.class, nmsEnt.goalSelector)).clear();
|
||||
((List<?>) ReflectionUtils.getField("c", PathfinderGoalSelector.class, nmsEnt.goalSelector)).clear();
|
||||
((List<?>) ReflectionUtils.getField("b", PathfinderGoalSelector.class, nmsEnt.targetSelector)).clear();
|
||||
((List<?>) ReflectionUtils.getField("c", PathfinderGoalSelector.class, nmsEnt.targetSelector)).clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removePathfinderGoal(Object entity, Class<?> goalClass, boolean isTargetSelector) {
|
||||
if (entity instanceof EntityInsentient) {
|
||||
|
||||
@@ -154,6 +154,15 @@ public class NMS_v1_8_R2 implements NMSInterface {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearPathfinderGoals(Entity entity) {
|
||||
EntityInsentient nmsEnt = (EntityInsentient) ((CraftEntity) entity).getHandle();
|
||||
((List<?>) ReflectionUtils.getField("b", PathfinderGoalSelector.class, nmsEnt.goalSelector)).clear();
|
||||
((List<?>) ReflectionUtils.getField("c", PathfinderGoalSelector.class, nmsEnt.goalSelector)).clear();
|
||||
((List<?>) ReflectionUtils.getField("b", PathfinderGoalSelector.class, nmsEnt.targetSelector)).clear();
|
||||
((List<?>) ReflectionUtils.getField("c", PathfinderGoalSelector.class, nmsEnt.targetSelector)).clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removePathfinderGoal(Object entity, Class<?> goalClass, boolean isTargetSelector) {
|
||||
if (entity instanceof EntityInsentient) {
|
||||
|
||||
@@ -154,6 +154,15 @@ public class NMS_v1_8_R3 implements NMSInterface {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearPathfinderGoals(Entity entity) {
|
||||
EntityInsentient nmsEnt = (EntityInsentient) ((CraftEntity) entity).getHandle();
|
||||
((List<?>) ReflectionUtils.getField("b", PathfinderGoalSelector.class, nmsEnt.goalSelector)).clear();
|
||||
((List<?>) ReflectionUtils.getField("c", PathfinderGoalSelector.class, nmsEnt.goalSelector)).clear();
|
||||
((List<?>) ReflectionUtils.getField("b", PathfinderGoalSelector.class, nmsEnt.targetSelector)).clear();
|
||||
((List<?>) ReflectionUtils.getField("c", PathfinderGoalSelector.class, nmsEnt.targetSelector)).clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removePathfinderGoal(Object entity, Class<?> goalClass, boolean isTargetSelector) {
|
||||
if (entity instanceof EntityInsentient) {
|
||||
|
||||
@@ -10,10 +10,12 @@ import java.io.NotSerializableException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.StreamCorruptedException;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.craftbukkit.v1_9_R1.CraftWorld;
|
||||
@@ -155,6 +157,15 @@ public class NMS_v1_9_R1 implements NMSInterface {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearPathfinderGoals(Entity entity) {
|
||||
EntityInsentient nmsEnt = (EntityInsentient) ((CraftEntity) entity).getHandle();
|
||||
((LinkedHashSet<?>) ReflectionUtils.getField("b", PathfinderGoalSelector.class, nmsEnt.goalSelector)).clear();
|
||||
((LinkedHashSet<?>) ReflectionUtils.getField("c", PathfinderGoalSelector.class, nmsEnt.goalSelector)).clear();
|
||||
((LinkedHashSet<?>) ReflectionUtils.getField("b", PathfinderGoalSelector.class, nmsEnt.targetSelector)).clear();
|
||||
((LinkedHashSet<?>) ReflectionUtils.getField("c", PathfinderGoalSelector.class, nmsEnt.targetSelector)).clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removePathfinderGoal(Object entity, Class<?> goalClass, boolean isTargetSelector) {
|
||||
if (entity instanceof EntityInsentient) {
|
||||
@@ -205,7 +216,9 @@ public class NMS_v1_9_R1 implements NMSInterface {
|
||||
|
||||
@Override
|
||||
public void change(NBTTagCompound[] NBT, @Nullable Object[] delta, ChangeMode mode) {
|
||||
Bukkit.broadcastMessage("Changing a compound");
|
||||
if (mode == ChangeMode.SET) {
|
||||
Bukkit.broadcastMessage("is setting");
|
||||
if (delta[0] instanceof NBTTagCompound) {
|
||||
NBT[0] = (NBTTagCompound) delta[0];
|
||||
} else {
|
||||
@@ -214,6 +227,7 @@ public class NMS_v1_9_R1 implements NMSInterface {
|
||||
NBT[0] = parsedNBT;
|
||||
}
|
||||
} else if (mode == ChangeMode.ADD) {
|
||||
Bukkit.broadcastMessage("is adding");
|
||||
if (delta[0] instanceof String) {
|
||||
NBTTagCompound parsedNBT = null;
|
||||
parsedNBT = parseRawNBT((String) delta[0]);
|
||||
@@ -222,6 +236,7 @@ public class NMS_v1_9_R1 implements NMSInterface {
|
||||
addToCompound(NBT[0], delta[0]);
|
||||
}
|
||||
} else if (mode == ChangeMode.REMOVE) {
|
||||
Bukkit.broadcastMessage("is removing");
|
||||
if (delta[0] instanceof NBTTagCompound)
|
||||
return;
|
||||
for (Object s : delta) {
|
||||
@@ -308,13 +323,14 @@ public class NMS_v1_9_R1 implements NMSInterface {
|
||||
@Nullable
|
||||
public Class<?>[] acceptChange(ChangeMode mode) {
|
||||
if (mode == ChangeMode.ADD || mode == ChangeMode.SET || mode == ChangeMode.DELETE || mode == ChangeMode.RESET) {
|
||||
return CollectionUtils.array(Float[].class, Double[].class, String[].class, NBTTagCompound[].class, Integer[].class, NBTTagList[].class);
|
||||
return CollectionUtils.array(Byte.class, Short.class, Integer.class, Long.class, Float.class, Double.class, String.class, NBTTagCompound.class, NBTTagList.class);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void change(NBTTagList[] nbtList, @Nullable Object[] delta, ChangeMode mode) {
|
||||
Bukkit.broadcastMessage("Changing a NBTList");
|
||||
int typeId = 0;
|
||||
if (delta instanceof Byte[]) {
|
||||
typeId = 1;
|
||||
@@ -335,9 +351,11 @@ public class NMS_v1_9_R1 implements NMSInterface {
|
||||
} else if (delta instanceof NBTTagCompound[]) {
|
||||
typeId = 10;
|
||||
} else {
|
||||
Bukkit.broadcastMessage("No compatible class: " + delta.getClass() + "\nStopping...");
|
||||
return;
|
||||
}
|
||||
if (mode == ChangeMode.SET) {
|
||||
Bukkit.broadcastMessage("is setting");
|
||||
if (typeId == 9)
|
||||
nbtList[0] = (NBTTagList) delta[0];
|
||||
} else if (mode == ChangeMode.ADD) {
|
||||
@@ -350,6 +368,7 @@ public class NMS_v1_9_R1 implements NMSInterface {
|
||||
addToList(nbtList, delta[0]);
|
||||
}
|
||||
} else if (mode == ChangeMode.DELETE || mode == ChangeMode.RESET) {
|
||||
Bukkit.broadcastMessage("Is deleting/resetting");
|
||||
nbtList[0] = new NBTTagList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ public class ReflectionUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static Constructor<?> getConstructor(String constructor, Class<?> clazz, Object object, Class<?> ... params) {
|
||||
public static Constructor<?> getConstructor(Class<?> clazz, Class<?> ... params) {
|
||||
Constructor<?> constr = null;
|
||||
try {
|
||||
constr = clazz.getDeclaredConstructor(params);
|
||||
|
||||
Reference in New Issue
Block a user