Fixed Wolves, Endermen, and Ocelots

All mob and misc disguises work now
This commit is contained in:
NavidK0 2016-03-13 21:27:46 -04:00
parent e95df4a2df
commit 27baf53073
5 changed files with 51 additions and 11 deletions

View File

@ -124,8 +124,7 @@ public class FlagWatcher {
} }
} }
// Here we check for if there is a health packet that says they died. // Here we check for if there is a health packet that says they died.
if (getDisguise().isSelfDisguiseVisible() && getDisguise().getEntity() != null if (getDisguise().isSelfDisguiseVisible() && getDisguise().getEntity() != null && getDisguise().getEntity() instanceof Player) {
&& getDisguise().getEntity() instanceof Player) {
for (WrappedWatchableObject watch : newList) { for (WrappedWatchableObject watch : newList) {
// Its a health packet // Its a health packet
if (watch.getIndex() == 6) { if (watch.getIndex() == 6) {
@ -261,6 +260,9 @@ public class FlagWatcher {
} }
Object value = entityValues.get(data); Object value = entityValues.get(data);
if (isEntityAnimationsAdded() && DisguiseConfig.isMetadataPacketsEnabled() && data == 0) { if (isEntityAnimationsAdded() && DisguiseConfig.isMetadataPacketsEnabled() && data == 0) {
if (disguise.getType() != DisguiseType.WOLF &&
disguise.getType() != DisguiseType.OCELOT &&
disguise.getType() != DisguiseType.ENDERMAN)
value = addEntityAnimations((byte) value, WrappedDataWatcher.getEntityWatcher(disguise.getEntity()).getByte(0)); value = addEntityAnimations((byte) value, WrappedDataWatcher.getEntityWatcher(disguise.getEntity()).getByte(0));
} }
WrappedWatchableObject watch = new WrappedWatchableObject(ReflectionManager.createDataWatcherItem(data, value)); WrappedWatchableObject watch = new WrappedWatchableObject(ReflectionManager.createDataWatcherItem(data, value));
@ -341,6 +343,7 @@ public class FlagWatcher {
/** /**
* Don't use this, use setItemInMainHand instead * Don't use this, use setItemInMainHand instead
*
* @param itemstack * @param itemstack
*/ */
@Deprecated @Deprecated

View File

@ -1,6 +1,9 @@
package me.libraryaddict.disguise.disguisetypes.watchers; package me.libraryaddict.disguise.disguisetypes.watchers;
import com.google.common.base.Optional;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.utilities.ReflectionManager;
import org.apache.commons.lang3.tuple.Pair;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
public class EndermanWatcher extends LivingWatcher { public class EndermanWatcher extends LivingWatcher {
@ -11,12 +14,29 @@ public class EndermanWatcher extends LivingWatcher {
@Override @Override
public ItemStack getItemInMainHand() { public ItemStack getItemInMainHand() {
return new ItemStack((int) getValue(11, 1), 1, (short) 0); Optional<Integer> value = (Optional<Integer>) getValue(11, Optional.of(1));
if (value.isPresent()) {
Pair<Integer, Integer> pair = ReflectionManager.getFromCombinedId(value.get());
int id = pair.getLeft();
int data = pair.getRight();
return new ItemStack(id, 1, (short) data);
} else {
return null;
}
} }
@Override @Override
public void setItemInMainHand(ItemStack itemstack) { public void setItemInMainHand(ItemStack itemstack) {
setValue(11, itemstack.getTypeId()); setItemInMainHand(itemstack.getTypeId(), itemstack.getDurability());
}
public void setItemInMainHand(int typeId) {
setItemInMainHand(typeId, 0);
}
public void setItemInMainHand(int typeId, int data) {
int combined = ReflectionManager.getCombinedId(typeId, data);
setValue(11, Optional.of(combined));
} }
public boolean isAggressive() { public boolean isAggressive() {

View File

@ -25,8 +25,9 @@ public enum DisguiseSound {
ELDER_GUARDIAN("entity.guardian.elder.hit", null, "entity.guardian.elder.death", "entity.guardian.elder.death"), ELDER_GUARDIAN("entity.guardian.elder.hit", null, "entity.guardian.elder.death", "entity.guardian.elder.death"),
ENDER_DRAGON("entity.enderdragon.hit", null, "entity.enderdragon.end", "entity.enderdragon.growl", "damage.fallsmall", ENDER_DRAGON("entity.enderdragon.hit", null, "entity.enderdragon.end", "entity.enderdragon.growl", "damage.fallsmall",
"entity.enderdragon.wings", "damage.fallbig"), "entity.enderdragon.wings", "damage.fallbig"),
ENDERMAN("entity.endermen.hit", "step.grass", "entity.endermen.death", "entity.endermen.idle", "entity.endermen.scream", //TODO: Fix enderman sounds
"entity.endermen.portal", "entity.endermen.stare"), // ENDERMAN("entity.endermen.hit", "step.grass", "entity.endermen.death", "entity.endermen.idle", "entity.endermen.scream",
// "entity.endermen.portal", "entity.endermen.stare"),
ENDERMITE("entity.silverfish.hit", "entity.silverfish.step", "entity.silverfish.kill", "entity.silverfish.ambient"), ENDERMITE("entity.silverfish.hit", "entity.silverfish.step", "entity.silverfish.kill", "entity.silverfish.ambient"),
GHAST("entity.ghast.scream", null, "entity.ghast.death", "entity.ghast.moan", "damage.fallsmall", "entity.ghast.fireball", GHAST("entity.ghast.scream", null, "entity.ghast.death", "entity.ghast.moan", "damage.fallsmall", "entity.ghast.fireball",
"damage.fallbig", "entity.ghast.affectionate_scream", "entity.ghast.charge"), "damage.fallbig", "entity.ghast.affectionate_scream", "entity.ghast.charge"),

View File

@ -284,7 +284,7 @@ public class PacketsManager {
int objectId = disguise.getType().getObjectId(); int objectId = disguise.getType().getObjectId();
int data = ((MiscDisguise) disguise).getData(); int data = ((MiscDisguise) disguise).getData();
if (disguise.getType() == DisguiseType.FALLING_BLOCK) { if (disguise.getType() == DisguiseType.FALLING_BLOCK) {
data = ((MiscDisguise) disguise).getId() + (data << 12); data = ReflectionManager.getCombinedId(((MiscDisguise) disguise).getId(), data);
} else if (disguise.getType() == DisguiseType.FISHING_HOOK && data == 0) { } else if (disguise.getType() == DisguiseType.FISHING_HOOK && data == 0) {
// If the MiscDisguise data isn't set. Then no entity id was provided, so default to the owners entity id // If the MiscDisguise data isn't set. Then no entity id was provided, so default to the owners entity id
data = disguisedEntity.getEntityId(); data = disguisedEntity.getEntityId();
@ -326,9 +326,9 @@ public class PacketsManager {
private static WrappedDataWatcher createDataWatcher(WrappedDataWatcher watcher, FlagWatcher flagWatcher) { private static WrappedDataWatcher createDataWatcher(WrappedDataWatcher watcher, FlagWatcher flagWatcher) {
WrappedDataWatcher newWatcher = new WrappedDataWatcher(); WrappedDataWatcher newWatcher = new WrappedDataWatcher();
try { try {
List<WrappedWatchableObject> list = DisguiseConfig.isMetadataPacketsEnabled() ? List<WrappedWatchableObject> list = DisguiseConfig.isMetadataPacketsEnabled() ? flagWatcher.convert(watcher.getWatchableObjects()) : flagWatcher.getWatchableObjects();
flagWatcher.convert(watcher.getWatchableObjects()) : flagWatcher.getWatchableObjects();
for (WrappedWatchableObject watchableObject : list) { for (WrappedWatchableObject watchableObject : list) {
if (watchableObject == null) continue;
if (watchableObject.getValue() == null) continue; if (watchableObject.getValue() == null) continue;
if (Registry.get(watchableObject.getValue().getClass()) == null) continue; if (Registry.get(watchableObject.getValue().getClass()) == null) continue;
WrappedDataWatcherObject obj = new WrappedDataWatcherObject(watchableObject.getIndex(), Registry.get(watchableObject.getValue().getClass())); WrappedDataWatcherObject obj = new WrappedDataWatcherObject(watchableObject.getIndex(), Registry.get(watchableObject.getValue().getClass()));
@ -1281,7 +1281,9 @@ public class PacketsManager {
// Else if the packet is sending entity metadata // Else if the packet is sending entity metadata
else if (sentPacket.getType() == Server.ENTITY_METADATA) { else if (sentPacket.getType() == Server.ENTITY_METADATA) {
if (DisguiseConfig.isMetadataPacketsEnabled()) { if (DisguiseConfig.isMetadataPacketsEnabled() && (disguise.getType() != DisguiseType.WOLF &&
disguise.getType() != DisguiseType.OCELOT &&
disguise.getType() != DisguiseType.ENDERMAN)) {
List<WrappedWatchableObject> watchableObjects = disguise.getWatcher().convert( List<WrappedWatchableObject> watchableObjects = disguise.getWatcher().convert(
packets[0].getWatchableCollectionModifier().read(0)); packets[0].getWatchableCollectionModifier().read(0));
packets[0] = new PacketContainer(sentPacket.getType()); packets[0] = new PacketContainer(sentPacket.getType());
@ -1394,7 +1396,9 @@ public class PacketsManager {
if (heldItem != null && heldItem.getType() != Material.AIR) { if (heldItem != null && heldItem.getType() != Material.AIR) {
// Convert the datawatcher // Convert the datawatcher
List<WrappedWatchableObject> list = new ArrayList<>(); List<WrappedWatchableObject> list = new ArrayList<>();
if (DisguiseConfig.isMetadataPacketsEnabled()) { if (DisguiseConfig.isMetadataPacketsEnabled() && (disguise.getType() != DisguiseType.WOLF &&
disguise.getType() != DisguiseType.OCELOT &&
disguise.getType() != DisguiseType.ENDERMAN)) {
WrappedWatchableObject watch = new WrappedWatchableObject(ReflectionManager.createDataWatcherItem(0, WrappedWatchableObject watch = new WrappedWatchableObject(ReflectionManager.createDataWatcherItem(0,
WrappedDataWatcher.getEntityWatcher(entity).getByte(0))); WrappedDataWatcher.getEntityWatcher(entity).getByte(0)));
list.add(watch); list.add(watch);

View File

@ -6,6 +6,8 @@ import com.comphenix.protocol.wrappers.WrappedDataWatcher.Serializer;
import com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject; import com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject;
import com.comphenix.protocol.wrappers.WrappedGameProfile; import com.comphenix.protocol.wrappers.WrappedGameProfile;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import org.bukkit.Art; import org.bukkit.Art;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
@ -667,4 +669,14 @@ public class ReflectionManager {
} }
return null; return null;
} }
public static int getCombinedId(int id, int data) {
return id + (data << 12);
}
public static Pair<Integer, Integer> getFromCombinedId(int combinedId) {
int j = combinedId & 4095;
int k = combinedId >> 12 & 15;
return new ImmutablePair<>(j, k);
}
} }