Actually set the bounding box
This commit is contained in:
@@ -11,14 +11,19 @@ import java.util.List;
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.LibsDisguises;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||
import me.libraryaddict.disguise.disguisetypes.TargetedDisguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.TargetedDisguise.TargetType;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Ageable;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Zombie;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.util.Vector;
|
||||
@@ -38,13 +43,14 @@ public class DisguiseUtilities {
|
||||
private static HashMap<Integer, HashSet<TargetedDisguise>> targetedDisguises = new HashMap<Integer, HashSet<TargetedDisguise>>();
|
||||
|
||||
public static void addDisguise(int entityId, TargetedDisguise disguise) {
|
||||
// TODO Make sure that the disguised entity doesn't have the player looking at other girls
|
||||
// ^ Done?
|
||||
if (!getDisguises().containsKey(entityId)) {
|
||||
getDisguises().put(entityId, new HashSet<TargetedDisguise>());
|
||||
}
|
||||
getDisguises().get(entityId).add(disguise);
|
||||
checkConflicts(disguise, null);
|
||||
if (disguise.getDisguiseTarget() == TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS && disguise.isModifyBoundingBox()) {
|
||||
doBoundingBox(disguise);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -126,6 +132,36 @@ public class DisguiseUtilities {
|
||||
}
|
||||
}
|
||||
|
||||
public static void doBoundingBox(TargetedDisguise disguise) {
|
||||
// TODO Slimes
|
||||
Entity entity = disguise.getEntity();
|
||||
if (entity != null) {
|
||||
if (isDisguiseInUse(disguise)) {
|
||||
DisguiseValues values = DisguiseValues.getDisguiseValues(disguise.getType());
|
||||
FakeBoundingBox fakeBox = values.getAdultBox();
|
||||
if (values.getBabyBox() != null) {
|
||||
if (disguise.getWatcher() instanceof AgeableWatcher
|
||||
&& (((AgeableWatcher) disguise.getWatcher()).isBaby())
|
||||
|| (disguise.getWatcher() instanceof ZombieWatcher && ((ZombieWatcher) disguise.getWatcher())
|
||||
.isBaby())) {
|
||||
fakeBox = values.getBabyBox();
|
||||
}
|
||||
}
|
||||
ReflectionManager.setBoundingBox(entity, fakeBox.getX(), fakeBox.getY(), fakeBox.getZ());
|
||||
} else {
|
||||
DisguiseValues values = DisguiseValues.getDisguiseValues(DisguiseType.getType(entity.getType()));
|
||||
FakeBoundingBox fakeBox = values.getAdultBox();
|
||||
if (values.getBabyBox() != null) {
|
||||
if (entity instanceof Ageable && !(((Ageable) entity).isAdult())
|
||||
|| (entity instanceof Zombie && ((Zombie) entity).isBaby())) {
|
||||
fakeBox = values.getBabyBox();
|
||||
}
|
||||
}
|
||||
ReflectionManager.setBoundingBox(disguise.getEntity(), fakeBox.getX(), fakeBox.getY(), fakeBox.getZ());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static TargetedDisguise getDisguise(int entityId) {
|
||||
TargetedDisguise toReturn = null;
|
||||
@@ -275,6 +311,9 @@ public class DisguiseUtilities {
|
||||
if (getDisguises().get(entityId).isEmpty()) {
|
||||
getDisguises().remove(entityId);
|
||||
}
|
||||
if (disguise.getDisguiseTarget() == TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS && disguise.isModifyBoundingBox()) {
|
||||
doBoundingBox(disguise);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@@ -43,11 +43,11 @@ public class DisguiseValues {
|
||||
return getDisguiseValues(type).getNmsEntityClass();
|
||||
}
|
||||
|
||||
private FakeBoundingBox adultBox;
|
||||
private FakeBoundingBox babyBox;
|
||||
private int enumEntitySize;
|
||||
private HashMap<Integer, Object> metaValues = new HashMap<Integer, Object>();
|
||||
private Class nmsEntityClass;
|
||||
private FakeBoundingBox adultBox;
|
||||
private FakeBoundingBox babyBox;
|
||||
|
||||
public DisguiseValues(DisguiseType type, Class classType, int entitySize) {
|
||||
values.put(type, this);
|
||||
@@ -55,22 +55,14 @@ public class DisguiseValues {
|
||||
nmsEntityClass = classType;
|
||||
}
|
||||
|
||||
public FakeBoundingBox getBabyBox() {
|
||||
return babyBox;
|
||||
}
|
||||
|
||||
public void setAdultBox(FakeBoundingBox newBox) {
|
||||
adultBox = newBox;
|
||||
}
|
||||
|
||||
public void setBabyBox(FakeBoundingBox newBox) {
|
||||
babyBox = newBox;
|
||||
}
|
||||
|
||||
public FakeBoundingBox getAdultBox() {
|
||||
return adultBox;
|
||||
}
|
||||
|
||||
public FakeBoundingBox getBabyBox() {
|
||||
return babyBox;
|
||||
}
|
||||
|
||||
public int getEntitySize(double paramDouble) {
|
||||
double d = paramDouble - (((int) Math.floor(paramDouble)) + 0.5D);
|
||||
|
||||
@@ -123,6 +115,14 @@ public class DisguiseValues {
|
||||
return nmsEntityClass;
|
||||
}
|
||||
|
||||
public void setAdultBox(FakeBoundingBox newBox) {
|
||||
adultBox = newBox;
|
||||
}
|
||||
|
||||
public void setBabyBox(FakeBoundingBox newBox) {
|
||||
babyBox = newBox;
|
||||
}
|
||||
|
||||
public void setMetaValue(int no, Object value) {
|
||||
metaValues.put(no, value);
|
||||
}
|
||||
|
@@ -55,6 +55,35 @@ public class ReflectionManager {
|
||||
}
|
||||
}
|
||||
|
||||
public static Object createEntityInstance(String entityName) {
|
||||
try {
|
||||
Class entityClass = getNmsClass("Entity" + entityName);
|
||||
Object entityObject;
|
||||
Object world = getWorld(Bukkit.getWorlds().get(0));
|
||||
if (entityName.equals("Player")) {
|
||||
Object minecraftServer = getNmsClass("MinecraftServer").getMethod("getServer").invoke(null);
|
||||
Object playerinteractmanager = getNmsClass("PlayerInteractManager").getConstructor(getNmsClass("World"))
|
||||
.newInstance(world);
|
||||
if (isAfter17()) {
|
||||
Object gameProfile = getGameProfile("LibsDisguises");
|
||||
entityObject = entityClass.getConstructor(getNmsClass("MinecraftServer"), getNmsClass("WorldServer"),
|
||||
gameProfile.getClass(), playerinteractmanager.getClass()).newInstance(minecraftServer, world,
|
||||
gameProfile, playerinteractmanager);
|
||||
} else {
|
||||
entityObject = entityClass.getConstructor(getNmsClass("MinecraftServer"), getNmsClass("World"), String.class,
|
||||
playerinteractmanager.getClass()).newInstance(minecraftServer, world, "LibsDisguises",
|
||||
playerinteractmanager);
|
||||
}
|
||||
} else {
|
||||
entityObject = entityClass.getConstructor(getNmsClass("World")).newInstance(world);
|
||||
}
|
||||
return entityObject;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static FakeBoundingBox getBoundingBox(Entity entity) {
|
||||
try {
|
||||
Object boundingBox = getNmsClass("Entity").getField("boundingBox").get(getNmsEntity(entity));
|
||||
@@ -94,72 +123,6 @@ public class ReflectionManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void setBoundingBox(Entity entity, double newX, double newY, double newZ) {
|
||||
try {
|
||||
Object boundingBox = getNmsClass("Entity").getField("boundingBox").get(getNmsEntity(entity));
|
||||
double x = 0, y = 0, z = 0;
|
||||
int stage = 0;
|
||||
for (Field field : boundingBox.getClass().getFields()) {
|
||||
if (field.getType().getSimpleName().equals("Double")) {
|
||||
stage++;
|
||||
switch (stage) {
|
||||
case 1:
|
||||
x = field.getDouble(boundingBox);
|
||||
break;
|
||||
case 2:
|
||||
y = field.getDouble(boundingBox);
|
||||
break;
|
||||
case 3:
|
||||
z = field.getDouble(boundingBox);
|
||||
break;
|
||||
case 4:
|
||||
field.setDouble(boundingBox, x);
|
||||
break;
|
||||
case 5:
|
||||
field.setDouble(boundingBox, y);
|
||||
break;
|
||||
case 6:
|
||||
field.setDouble(boundingBox, z);
|
||||
break;
|
||||
default:
|
||||
throw new Exception("Error while setting the bounding box, more doubles than I thought??");
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static Object createEntityInstance(String entityName) {
|
||||
try {
|
||||
Class entityClass = getNmsClass("Entity" + entityName);
|
||||
Object entityObject;
|
||||
Object world = getWorld(Bukkit.getWorlds().get(0));
|
||||
if (entityName.equals("Player")) {
|
||||
Object minecraftServer = getNmsClass("MinecraftServer").getMethod("getServer").invoke(null);
|
||||
Object playerinteractmanager = getNmsClass("PlayerInteractManager").getConstructor(getNmsClass("World"))
|
||||
.newInstance(world);
|
||||
if (isAfter17()) {
|
||||
Object gameProfile = getGameProfile("LibsDisguises");
|
||||
entityObject = entityClass.getConstructor(getNmsClass("MinecraftServer"), getNmsClass("WorldServer"),
|
||||
gameProfile.getClass(), playerinteractmanager.getClass()).newInstance(minecraftServer, world,
|
||||
gameProfile, playerinteractmanager);
|
||||
} else {
|
||||
entityObject = entityClass.getConstructor(getNmsClass("MinecraftServer"), getNmsClass("World"), String.class,
|
||||
playerinteractmanager.getClass()).newInstance(minecraftServer, world, "LibsDisguises",
|
||||
playerinteractmanager);
|
||||
}
|
||||
} else {
|
||||
entityObject = entityClass.getConstructor(getNmsClass("World")).newInstance(world);
|
||||
}
|
||||
return entityObject;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Entity getBukkitEntity(Object nmsEntity) {
|
||||
try {
|
||||
Entity bukkitEntity = (Entity) ReflectionManager.getNmsClass("Entity").getMethod("getBukkitEntity").invoke(nmsEntity);
|
||||
@@ -272,4 +235,41 @@ public class ReflectionManager {
|
||||
return after17;
|
||||
}
|
||||
|
||||
public static void setBoundingBox(Entity entity, double newX, double newY, double newZ) {
|
||||
try {
|
||||
Object boundingBox = getNmsClass("Entity").getField("boundingBox").get(getNmsEntity(entity));
|
||||
double x = 0, y = 0, z = 0;
|
||||
int stage = 0;
|
||||
for (Field field : boundingBox.getClass().getFields()) {
|
||||
if (field.getType().getSimpleName().equals("Double")) {
|
||||
stage++;
|
||||
switch (stage) {
|
||||
case 1:
|
||||
x = field.getDouble(boundingBox);
|
||||
break;
|
||||
case 2:
|
||||
y = field.getDouble(boundingBox);
|
||||
break;
|
||||
case 3:
|
||||
z = field.getDouble(boundingBox);
|
||||
break;
|
||||
case 4:
|
||||
field.setDouble(boundingBox, x);
|
||||
break;
|
||||
case 5:
|
||||
field.setDouble(boundingBox, y);
|
||||
break;
|
||||
case 6:
|
||||
field.setDouble(boundingBox, z);
|
||||
break;
|
||||
default:
|
||||
throw new Exception("Error while setting the bounding box, more doubles than I thought??");
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user