Armorstand names now adapt to basic entity sizes, and player sneaking. Doesn't handle poses.

This commit is contained in:
libraryaddict
2020-05-09 21:57:07 +12:00
parent 93eef36c58
commit e6b7651571
13 changed files with 171 additions and 33 deletions

View File

@@ -22,7 +22,7 @@ import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.disguisetypes.*;
import me.libraryaddict.disguise.disguisetypes.TargetedDisguise.TargetType;
import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.ArmorStandWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher;
import me.libraryaddict.disguise.utilities.json.*;
import me.libraryaddict.disguise.utilities.mineskin.MineSkinAPI;
@@ -2323,6 +2323,8 @@ public class DisguiseUtilities {
destroyIds = Arrays.copyOfRange(standIds, newNames.length, internalOldNames.length);
}
double height = disguise.getHeight();
for (int i = 0; i < newNames.length; i++) {
if (i < internalOldNames.length) {
if (newNames[i].equals(internalOldNames[i]) || newNames[i].isEmpty()) {
@@ -2358,19 +2360,19 @@ public class DisguiseUtilities {
Location loc = disguise.getEntity().getLocation();
packet.getDoubles().write(0, loc.getX());
packet.getDoubles().write(1, loc.getY() + -0.175 + (0.28 * i));
packet.getDoubles().write(1, loc.getY() + height + (0.28 * i));
packet.getDoubles().write(2, loc.getZ());
packets.add(packet);
WrappedDataWatcher watcher = new WrappedDataWatcher();
for (MetaIndex index : MetaIndex.getMetaIndexes(LivingWatcher.class)) {
for (MetaIndex index : MetaIndex.getMetaIndexes(ArmorStandWatcher.class)) {
Object val = index.getDefault();
if (index == MetaIndex.ENTITY_META) {
val = (byte) 32;
} else if (index == MetaIndex.ARMORSTAND_META) {
val = (byte) 17;
val = (byte) 19;
} else if (index == MetaIndex.ENTITY_CUSTOM_NAME) {
val = Optional.of(WrappedChatComponent.fromText(newNames[i]));
} else if (index == MetaIndex.ENTITY_CUSTOM_NAME_OLD) {
@@ -2387,7 +2389,7 @@ public class DisguiseUtilities {
if (NmsVersion.v1_15.isSupported()) {
PacketContainer metaPacket = ProtocolLibrary.getProtocolManager()
.createPacketConstructor(PacketType.Play.Server.ENTITY_METADATA, 0, watcher, true)
.createPacketConstructor(PacketType.Play.Server.ENTITY_METADATA, standIds[i], watcher, true)
.createPacket(standIds[i], watcher, true);
packets.add(metaPacket);

View File

@@ -15,19 +15,12 @@ public class DisguiseValues {
return values.get(type);
}
public static Class getNmsEntityClass(DisguiseType type) {
return getDisguiseValues(type).getNmsEntityClass();
}
private FakeBoundingBox adultBox;
private FakeBoundingBox babyBox;
private float[] entitySize;
private double maxHealth;
private Class nmsEntityClass;
private final double maxHealth;
public DisguiseValues(DisguiseType type, Class classType, double maxHealth) {
public DisguiseValues(DisguiseType type, double maxHealth) {
values.put(type, this);
nmsEntityClass = classType;
this.maxHealth = maxHealth;
}
@@ -50,8 +43,4 @@ public class DisguiseValues {
public double getMaxHealth() {
return maxHealth;
}
public Class getNmsEntityClass() {
return nmsEntityClass;
}
}

View File

@@ -49,6 +49,7 @@ public class PacketHandlerMovement implements IPacketHandler {
}
ArrayList<PacketContainer> toAdd = new ArrayList<>();
double height = disguise.getHeight();
for (PacketContainer packet : packets.getPackets()) {
for (int i = 0; i < len; i++) {
@@ -57,7 +58,7 @@ public class PacketHandlerMovement implements IPacketHandler {
packet2.getIntegers().write(0, standId);
if (packet2.getType() == PacketType.Play.Server.ENTITY_TELEPORT) {
packet2.getDoubles().write(1, packet2.getDoubles().read(1) + -0.175 + (0.28 * i));
packet2.getDoubles().write(1, packet2.getDoubles().read(1) + height + (0.28 * i));
}
toAdd.add(packet2);

View File

@@ -48,8 +48,10 @@ public class DisguiseParser {
disguise = new MiscDisguise(type);
} else if (type.isMob()) {
disguise = new MobDisguise(type);
} else {
} else if (type.isPlayer()) {
disguise = new PlayerDisguise("Foobar");
} else {
continue;
}
FlagWatcher watcher = type.getWatcherClass().getConstructor(Disguise.class).newInstance(disguise);
@@ -217,15 +219,14 @@ public class DisguiseParser {
}
private static void addWatcherDefault(Method setMethod, Method getMethod, Object object) {
if (defaultWatcherValues.containsKey(setMethod)) {
Object dObj = defaultWatcherValues.get(setMethod).getValue();
if (!Objects.deepEquals(dObj, object)) {
throw new IllegalStateException(String.format(
"%s has conflicting values! This means it expected the same value again but received a " +
"different value on a different disguise! %s is not the same as %s!", setMethod.getName(), object,
dObj));
"different value on a different disguise! %s is not the same as %s!",
setMethod.getName(), object, dObj));
}
return;

View File

@@ -1722,7 +1722,7 @@ public class ReflectionManager {
try {
if (disguiseType == DisguiseType.UNKNOWN || disguiseType.isCustom()) {
DisguiseValues disguiseValues = new DisguiseValues(disguiseType, null, 0);
DisguiseValues disguiseValues = new DisguiseValues(disguiseType, 0);
disguiseValues.setAdultBox(new FakeBoundingBox(0, 0, 0));
@@ -1763,7 +1763,7 @@ public class ReflectionManager {
}
}
DisguiseValues disguiseValues = new DisguiseValues(disguiseType, nmsEntity.getClass(),
DisguiseValues disguiseValues = new DisguiseValues(disguiseType,
bukkitEntity instanceof Damageable ? ((Damageable) bukkitEntity).getMaxHealth() : 0);
WrappedDataWatcher watcher = WrappedDataWatcher.getEntityWatcher(bukkitEntity);
@@ -1841,9 +1841,11 @@ public class ReflectionManager {
((Zombie) bukkitEntity).setBaby(true);
disguiseValues.setBabyBox(ReflectionManager.getBoundingBox(bukkitEntity));
}
} else if (bukkitEntity instanceof ArmorStand) {
((ArmorStand) bukkitEntity).setSmall(true);
//disguiseValues.setEntitySize(ReflectionManager.getSize(bukkitEntity));
disguiseValues.setBabyBox(ReflectionManager.getBoundingBox(bukkitEntity));
}
}
catch (SecurityException | IllegalArgumentException | IllegalAccessException | FieldAccessException ex) {
DisguiseUtilities.getLogger()