Progress! Some mob disguises are working now
Added in dual hand animations Removed libraryaddict
This commit is contained in:
parent
cf1b15942c
commit
99daf8246d
@ -9,11 +9,11 @@ public class PigWatcher extends AgeableWatcher {
|
||||
}
|
||||
|
||||
public boolean isSaddled() {
|
||||
return (byte) getValue(16, (byte) 0) == 1;
|
||||
return (boolean) getValue(12, false);
|
||||
}
|
||||
|
||||
public void setSaddled(boolean isSaddled) {
|
||||
setValue(16, (byte) (isSaddled ? 1 : 0));
|
||||
sendData(16);
|
||||
setValue(12, isSaddled);
|
||||
sendData(12);
|
||||
}
|
||||
}
|
||||
|
@ -6,9 +6,6 @@ import com.comphenix.protocol.ProtocolManager;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.reflect.StructureModifier;
|
||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
|
||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher.Registry;
|
||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher.Serializer;
|
||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject;
|
||||
import com.comphenix.protocol.wrappers.WrappedGameProfile;
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.DisguiseConfig;
|
||||
@ -28,7 +25,6 @@ import org.bukkit.World;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Ageable;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Zombie;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
@ -42,7 +38,6 @@ import org.bukkit.scoreboard.Team.OptionStatus;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
@ -898,22 +893,55 @@ public class DisguiseUtilities {
|
||||
.createPacket(0, player.getPassenger(), player));
|
||||
}
|
||||
|
||||
// Resend the armor
|
||||
for (int i = 0; i < 5; i++) {
|
||||
ItemStack item;
|
||||
if (i == 0) {
|
||||
item = player.getItemInHand();
|
||||
} else {
|
||||
item = player.getInventory().getArmorContents()[i - 1];
|
||||
}
|
||||
sendSelfPacket(player,
|
||||
manager.createPacketConstructor(
|
||||
Server.ENTITY_EQUIPMENT,
|
||||
0,
|
||||
ReflectionManager.createEnumItemSlot(EquipmentSlot.HEAD),
|
||||
ReflectionManager.getNmsItem(new ItemStack(Material.STONE)))
|
||||
.createPacket(player.getEntityId(), ReflectionManager.createEnumItemSlot(EquipmentSlot.HEAD),
|
||||
ReflectionManager.getNmsItem(player.getInventory().getHelmet())));
|
||||
sendSelfPacket(player,
|
||||
manager.createPacketConstructor(
|
||||
Server.ENTITY_EQUIPMENT,
|
||||
0,
|
||||
ReflectionManager.createEnumItemSlot(EquipmentSlot.HEAD),
|
||||
ReflectionManager.getNmsItem(new ItemStack(Material.STONE)))
|
||||
.createPacket(player.getEntityId(), ReflectionManager.createEnumItemSlot(EquipmentSlot.CHEST),
|
||||
ReflectionManager.getNmsItem(player.getInventory().getChestplate())));
|
||||
sendSelfPacket(player,
|
||||
manager.createPacketConstructor(
|
||||
Server.ENTITY_EQUIPMENT,
|
||||
0,
|
||||
ReflectionManager.createEnumItemSlot(EquipmentSlot.HEAD),
|
||||
ReflectionManager.getNmsItem(new ItemStack(Material.STONE)))
|
||||
.createPacket(player.getEntityId(), ReflectionManager.createEnumItemSlot(EquipmentSlot.LEGS),
|
||||
ReflectionManager.getNmsItem(player.getInventory().getLeggings())));
|
||||
sendSelfPacket(player,
|
||||
manager.createPacketConstructor(
|
||||
Server.ENTITY_EQUIPMENT,
|
||||
0,
|
||||
ReflectionManager.createEnumItemSlot(EquipmentSlot.HEAD),
|
||||
ReflectionManager.getNmsItem(new ItemStack(Material.STONE)))
|
||||
.createPacket(player.getEntityId(), ReflectionManager.createEnumItemSlot(EquipmentSlot.FEET),
|
||||
ReflectionManager.getNmsItem(player.getInventory().getBoots())));
|
||||
sendSelfPacket(player,
|
||||
manager.createPacketConstructor(
|
||||
Server.ENTITY_EQUIPMENT,
|
||||
0,
|
||||
ReflectionManager.createEnumItemSlot(EquipmentSlot.HEAD),
|
||||
ReflectionManager.getNmsItem(new ItemStack(Material.STONE)))
|
||||
.createPacket(player.getEntityId(), ReflectionManager.createEnumItemSlot(EquipmentSlot.HAND),
|
||||
ReflectionManager.getNmsItem(player.getInventory().getItemInMainHand())));
|
||||
sendSelfPacket(player,
|
||||
manager.createPacketConstructor(
|
||||
Server.ENTITY_EQUIPMENT,
|
||||
0,
|
||||
ReflectionManager.createEnumItemSlot(EquipmentSlot.HEAD),
|
||||
ReflectionManager.getNmsItem(new ItemStack(Material.STONE)))
|
||||
.createPacket(player.getEntityId(), ReflectionManager.createEnumItemSlot(EquipmentSlot.OFF_HAND),
|
||||
ReflectionManager.getNmsItem(player.getInventory().getItemInOffHand())));
|
||||
|
||||
if (item != null && item.getType() != Material.AIR) {
|
||||
sendSelfPacket(
|
||||
player,
|
||||
manager.createPacketConstructor(Server.ENTITY_EQUIPMENT, player.getEntityId(), i,
|
||||
item).createPacket(player.getEntityId(), i, item));
|
||||
}
|
||||
}
|
||||
Location loc = player.getLocation();
|
||||
// If the disguised is sleeping for w/e reason
|
||||
if (player.isSleeping()) {
|
||||
|
@ -46,7 +46,6 @@ import org.bukkit.entity.Zombie;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
@ -176,15 +175,13 @@ public class PacketsManager {
|
||||
}
|
||||
|
||||
if (disguise.getType() == DisguiseType.EXPERIENCE_ORB) {
|
||||
|
||||
spawnPackets[0] = new PacketContainer(Server.SPAWN_ENTITY_EXPERIENCE_ORB);
|
||||
StructureModifier<Object> mods = spawnPackets[0].getModifier();
|
||||
mods.write(0, disguisedEntity.getEntityId());
|
||||
mods.write(1, (int) Math.floor(loc.getX() * 32));
|
||||
mods.write(2, (int) Math.floor(loc.getY() * 32) + 2);
|
||||
mods.write(3, (int) Math.floor(loc.getZ() * 32));
|
||||
mods.write(1, Math.floor(loc.getX() * 32));
|
||||
mods.write(2, Math.floor(loc.getY() * 32) + 2);
|
||||
mods.write(3, Math.floor(loc.getZ() * 32));
|
||||
mods.write(4, 1);
|
||||
|
||||
} else if (disguise.getType() == DisguiseType.PAINTING) {
|
||||
spawnPackets[0] = new PacketContainer(Server.SPAWN_ENTITY_PAINTING);
|
||||
StructureModifier<Object> mods = spawnPackets[0].getModifier();
|
||||
@ -198,52 +195,44 @@ public class PacketsManager {
|
||||
spawnPackets[1] = new PacketContainer(Server.ENTITY_TELEPORT);
|
||||
mods = spawnPackets[1].getModifier();
|
||||
mods.write(0, disguisedEntity.getEntityId());
|
||||
mods.write(1, (int) Math.floor(loc.getX() * 32D));
|
||||
mods.write(2, (int) Math.floor(loc.getY() * 32D));
|
||||
mods.write(3, (int) Math.floor(loc.getZ() * 32D));
|
||||
mods.write(1, Math.floor(loc.getX() * 32D));
|
||||
mods.write(2, Math.floor(loc.getY() * 32D));
|
||||
mods.write(3, Math.floor(loc.getZ() * 32D));
|
||||
mods.write(4, yaw);
|
||||
mods.write(5, pitch);
|
||||
|
||||
} else if (disguise.getType().isPlayer()) {
|
||||
|
||||
//TODO: Make player disguises visible again
|
||||
spawnPackets[0] = new PacketContainer(Server.NAMED_ENTITY_SPAWN);
|
||||
StructureModifier<String> stringMods = spawnPackets[0].getStrings();
|
||||
WrappedGameProfile gameProfile;
|
||||
if (stringMods.size() > 0) {
|
||||
for (int i = 0; i < stringMods.size(); i++) {
|
||||
stringMods.write(i, ((PlayerDisguise) disguise).getName());
|
||||
}
|
||||
} else {
|
||||
PlayerDisguise playerDisguise = (PlayerDisguise) disguise;
|
||||
String name = playerDisguise.getSkin() != null ? playerDisguise.getSkin() : playerDisguise.getName();
|
||||
boolean removeName = false;
|
||||
if (!DisguiseUtilities.hasGameProfile(name)) {
|
||||
removeName = !DisguiseUtilities.getAddedByPlugins().contains(name);
|
||||
}
|
||||
gameProfile = playerDisguise.getGameProfile();
|
||||
if (removeName) {
|
||||
DisguiseUtilities.getAddedByPlugins().remove(name);
|
||||
}
|
||||
spawnPackets[0].getSpecificModifier(UUID.class).write(0, gameProfile.getUUID());
|
||||
PlayerDisguise playerDisguise = (PlayerDisguise) disguise;
|
||||
String name = playerDisguise.getSkin() != null ? playerDisguise.getSkin() : playerDisguise.getName();
|
||||
boolean removeName = false;
|
||||
if (!DisguiseUtilities.hasGameProfile(name)) {
|
||||
removeName = !DisguiseUtilities.getAddedByPlugins().contains(name);
|
||||
}
|
||||
StructureModifier<Integer> intMods = spawnPackets[0].getIntegers();
|
||||
intMods.write(0, disguisedEntity.getEntityId());
|
||||
WrappedGameProfile gameProfile = playerDisguise.getGameProfile();
|
||||
if (removeName) {
|
||||
DisguiseUtilities.getAddedByPlugins().remove(name);
|
||||
}
|
||||
|
||||
//Write spawn packet in order
|
||||
//Id
|
||||
//UUID
|
||||
//x
|
||||
//y
|
||||
//z
|
||||
//pitch
|
||||
//yaw
|
||||
spawnPackets[0].getIntegers().write(0, disguisedEntity.getEntityId());
|
||||
spawnPackets[0].getSpecificModifier(UUID.class).write(0, gameProfile.getUUID());
|
||||
StructureModifier<Double> doubleMods = spawnPackets[0].getDoubles();
|
||||
doubleMods.write(0, Math.floor(loc.getX() * 32));
|
||||
doubleMods.write(1, Math.floor(loc.getY() * 32));
|
||||
doubleMods.write(2, Math.floor(loc.getZ() * 32));
|
||||
ItemStack item = null;
|
||||
if (disguisedEntity instanceof Player && ((Player) disguisedEntity).getInventory().getItemInMainHand() != null) {
|
||||
item = ((Player) disguisedEntity).getInventory().getItemInMainHand();
|
||||
} else if (disguisedEntity instanceof LivingEntity) {
|
||||
item = ((LivingEntity) disguisedEntity).getEquipment().getItemInMainHand();
|
||||
}
|
||||
intMods.write(4, (item == null || item.getType() == Material.AIR ? 0 : item.getTypeId()));
|
||||
StructureModifier<Byte> byteMods = spawnPackets[0].getBytes();
|
||||
byteMods.write(1, yaw);
|
||||
byteMods.write(0, pitch);
|
||||
spawnPackets[0].getDataWatcherModifier().write(0,
|
||||
createDataWatcher(player, WrappedDataWatcher.getEntityWatcher(disguisedEntity), disguise.getWatcher()));
|
||||
byteMods.write(1, yaw);
|
||||
|
||||
spawnPackets[0].getDataWatcherModifier().write(0, createDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity), disguise.getWatcher()));
|
||||
|
||||
if (DisguiseConfig.isBedPacketsEnabled() && ((PlayerWatcher) disguise.getWatcher()).isSleeping()) {
|
||||
PacketContainer[] newPackets = new PacketContainer[spawnPackets.length + 1];
|
||||
@ -263,53 +252,36 @@ public class PacketsManager {
|
||||
newPackets.add(spawnPacket);
|
||||
}
|
||||
}
|
||||
|
||||
//Send player info along with the disguise
|
||||
spawnPackets = newPackets.toArray(new PacketContainer[newPackets.size()]);
|
||||
spawnPackets[0] = new PacketContainer(Server.PLAYER_INFO);
|
||||
|
||||
//Add player to the list, necessary to spawn them
|
||||
spawnPackets[0].getModifier().write(0, ReflectionManager.getEnumPlayerInfoAction(0));
|
||||
List playerList = new ArrayList();
|
||||
PlayerDisguise playerDisguise = (PlayerDisguise) disguise;
|
||||
playerList.add(ReflectionManager.getPlayerInfoData(spawnPackets[0].getHandle(), playerDisguise.getGameProfile()));
|
||||
spawnPackets[0].getModifier().write(1, playerList);
|
||||
|
||||
//Remove player from the list
|
||||
PacketContainer delayedPacket = spawnPackets[0].shallowClone();
|
||||
delayedPacket.getModifier().write(0, ReflectionManager.getEnumPlayerInfoAction(4));
|
||||
delayedPackets = new PacketContainer[]{delayedPacket};
|
||||
|
||||
} else if (disguise.getType().isMob() || disguise.getType() == DisguiseType.ARMOR_STAND) {
|
||||
DisguiseValues values = DisguiseValues.getDisguiseValues(disguise.getType());
|
||||
Vector vec = disguisedEntity.getVelocity();
|
||||
spawnPackets[0] = new PacketContainer(Server.SPAWN_ENTITY_LIVING);
|
||||
StructureModifier<Object> mods = spawnPackets[0].getModifier();
|
||||
mods.write(0, disguisedEntity.getEntityId());
|
||||
mods.write(1, disguise.getType().getTypeId());
|
||||
double d1 = 3.9D;
|
||||
double d2 = vec.getX();
|
||||
double d3 = vec.getY();
|
||||
double d4 = vec.getZ();
|
||||
if (d2 < -d1)
|
||||
d2 = -d1;
|
||||
if (d3 < -d1)
|
||||
d3 = -d1;
|
||||
if (d4 < -d1)
|
||||
d4 = -d1;
|
||||
if (d2 > d1)
|
||||
d2 = d1;
|
||||
if (d3 > d1)
|
||||
d3 = d1;
|
||||
if (d4 > d1)
|
||||
d4 = d1;
|
||||
mods.write(2, values.getEntitySize(loc.getX()));
|
||||
mods.write(3, (int) Math.floor(loc.getY() * 32D));
|
||||
mods.write(4, values.getEntitySize(loc.getZ()));
|
||||
mods.write(5, (int) (d2 * 8000.0D));
|
||||
mods.write(6, (int) (d3 * 8000.0D));
|
||||
mods.write(7, (int) (d4 * 8000.0D));
|
||||
mods.write(8, yaw);
|
||||
mods.write(9, pitch);
|
||||
Class<? extends Entity> entityClass = disguise.getType().getEntityClass();
|
||||
Entity entity = Bukkit.getWorlds().get(0).spawn(disguise.getEntity().getLocation(), entityClass);
|
||||
entity.setVelocity(disguisedEntity.getVelocity());
|
||||
Object nms = ReflectionManager.getNmsEntity(entity);
|
||||
PacketContainer packet = ProtocolLibrary.getProtocolManager().createPacketConstructor(Server.SPAWN_ENTITY_LIVING, nms)
|
||||
.createPacket(nms);
|
||||
spawnPackets[0] = packet;
|
||||
spawnPackets[0].getDataWatcherModifier().write(0,
|
||||
createDataWatcher(player, WrappedDataWatcher.getEntityWatcher(disguisedEntity), disguise.getWatcher()));
|
||||
|
||||
createDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity), disguise.getWatcher()));
|
||||
entity.remove();
|
||||
//You know, as cheap as this may seem, this is pretty damn effective
|
||||
} else if (disguise.getType().isMisc()) {
|
||||
|
||||
//TODO: Fix miscs
|
||||
int id = disguise.getType().getEntityId();
|
||||
int data = ((MiscDisguise) disguise).getData();
|
||||
if (disguise.getType() == DisguiseType.FALLING_BLOCK) {
|
||||
@ -352,13 +324,13 @@ public class PacketsManager {
|
||||
/**
|
||||
* Create a new datawatcher but with the 'correct' values
|
||||
*/
|
||||
private static WrappedDataWatcher createDataWatcher(Player player, WrappedDataWatcher watcher, FlagWatcher flagWatcher) {
|
||||
private static WrappedDataWatcher createDataWatcher(WrappedDataWatcher watcher, FlagWatcher flagWatcher) {
|
||||
WrappedDataWatcher newWatcher = new WrappedDataWatcher();
|
||||
try {
|
||||
List<WrappedWatchableObject> list = DisguiseConfig.isMetadataPacketsEnabled() ? flagWatcher.convert(watcher
|
||||
.getWatchableObjects()) : flagWatcher.getWatchableObjects();
|
||||
List<WrappedWatchableObject> list = DisguiseConfig.isMetadataPacketsEnabled() ?
|
||||
flagWatcher.convert(watcher.getWatchableObjects()) : flagWatcher.getWatchableObjects();
|
||||
for (WrappedWatchableObject watchableObject : list) {
|
||||
newWatcher.setObject(watchableObject.getIndex(), watchableObject.getValue());
|
||||
newWatcher.setObject(watchableObject.getWatcherObject(), watchableObject.getValue());
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
|
@ -38,7 +38,7 @@ DyeableWolf: false
|
||||
# Such as prophunt. Its also false because its kind of a retarded feature.
|
||||
# This is pretty simple. It shows the players displayname (Name as it appears in chat) above their head.
|
||||
# This also overrides any custom name they have set in their disguise options.
|
||||
ShowNamesAboveDisguises: false
|
||||
ShowNamesAboveDisguises: false
|
||||
# This supports the above option.
|
||||
# If this is true, then the name shown above the head appears regardless of if you are looking at the disguise directly or not.
|
||||
NameAboveHeadAlwaysVisible: true
|
||||
|
Loading…
Reference in New Issue
Block a user