Update for reflection
This commit is contained in:
parent
71d0b64e82
commit
c25519158a
2
pom.xml
2
pom.xml
@ -56,7 +56,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.comphenix.protocol</groupId>
|
<groupId>com.comphenix.protocol</groupId>
|
||||||
<artifactId>ProtocolLib</artifactId>
|
<artifactId>ProtocolLib</artifactId>
|
||||||
<version>2.5.0</version>
|
<version>2.7.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.bukkit</groupId>
|
<groupId>org.bukkit</groupId>
|
||||||
|
@ -48,7 +48,7 @@ public class DisguiseAPI {
|
|||||||
disguise = disguise.clone();
|
disguise = disguise.clone();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Field field = net.minecraft.server.v1_6_R3.Entity.class.getDeclaredField("entityCount");
|
Field field = ReflectionManager.getNmsClass("Entity").getDeclaredField("entityCount");
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
int id = field.getInt(null);
|
int id = field.getInt(null);
|
||||||
disguises.put(id, disguise);
|
disguises.put(id, disguise);
|
||||||
@ -268,7 +268,7 @@ public class DisguiseAPI {
|
|||||||
return;
|
return;
|
||||||
try {
|
try {
|
||||||
// Grab the entity ID the fake disguise will use
|
// Grab the entity ID the fake disguise will use
|
||||||
Field field = net.minecraft.server.v1_6_R3.Entity.class.getDeclaredField("entityCount");
|
Field field = ReflectionManager.getNmsClass("Entity").getDeclaredField("entityCount");
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
int id = field.getInt(null);
|
int id = field.getInt(null);
|
||||||
// Set the entitycount plus one so we don't have the id being reused
|
// Set the entitycount plus one so we don't have the id being reused
|
||||||
|
@ -3,7 +3,6 @@ package me.libraryaddict.disguise;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import me.libraryaddict.disguise.commands.*;
|
import me.libraryaddict.disguise.commands.*;
|
||||||
@ -23,7 +22,6 @@ import org.bukkit.entity.Entity;
|
|||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import com.comphenix.protocol.wrappers.WrappedAttribute;
|
|
||||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
|
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
|
||||||
import com.comphenix.protocol.wrappers.WrappedWatchableObject;
|
import com.comphenix.protocol.wrappers.WrappedWatchableObject;
|
||||||
|
|
||||||
@ -174,7 +172,8 @@ public class LibsDisguises extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Object entity = ReflectionManager.getEntityInstance(name);
|
Object entity = ReflectionManager.getEntityInstance(name);
|
||||||
Entity bukkitEntity = (Entity) entity.getClass().getMethod("getBukkitEntity").invoke(entity);
|
Entity bukkitEntity = (Entity) ReflectionManager.getNmsClass("Entity").getMethod("getBukkitEntity")
|
||||||
|
.invoke(entity);
|
||||||
int size = 0;
|
int size = 0;
|
||||||
for (Field field : ReflectionManager.getNmsClass("Entity").getFields()) {
|
for (Field field : ReflectionManager.getNmsClass("Entity").getFields()) {
|
||||||
if (field.getType().getName().equals("EnumEntitySize")) {
|
if (field.getType().getName().equals("EnumEntitySize")) {
|
||||||
@ -188,11 +187,6 @@ public class LibsDisguises extends JavaPlugin {
|
|||||||
List<WrappedWatchableObject> watchers = dataWatcher.getWatchableObjects();
|
List<WrappedWatchableObject> watchers = dataWatcher.getWatchableObjects();
|
||||||
for (WrappedWatchableObject watch : watchers)
|
for (WrappedWatchableObject watch : watchers)
|
||||||
value.setMetaValue(watch.getTypeID(), watch.getValue());
|
value.setMetaValue(watch.getTypeID(), watch.getValue());
|
||||||
WrappedAttribute s;
|
|
||||||
if (bukkitEntity instanceof LivingEntity) {
|
|
||||||
value.setAttributesValue("generic.movementSpeed", livingEntity.getAttributeInstance(GenericAttributes.d)
|
|
||||||
.getValue());
|
|
||||||
}
|
|
||||||
DisguiseSound sound = DisguiseSound.getType(disguiseType.name());
|
DisguiseSound sound = DisguiseSound.getType(disguiseType.name());
|
||||||
if (sound != null) {
|
if (sound != null) {
|
||||||
Float soundStrength = ReflectionManager.getSoundModifier(entity);
|
Float soundStrength = ReflectionManager.getSoundModifier(entity);
|
||||||
|
@ -4,7 +4,6 @@ import java.lang.reflect.Field;
|
|||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
@ -18,10 +17,13 @@ import me.libraryaddict.disguise.disguisetypes.MobDisguise;
|
|||||||
import me.libraryaddict.disguise.disguisetypes.PlayerDisguise;
|
import me.libraryaddict.disguise.disguisetypes.PlayerDisguise;
|
||||||
import me.libraryaddict.disguise.disguisetypes.Values;
|
import me.libraryaddict.disguise.disguisetypes.Values;
|
||||||
import me.libraryaddict.disguise.disguisetypes.DisguiseSound.SoundType;
|
import me.libraryaddict.disguise.disguisetypes.DisguiseSound.SoundType;
|
||||||
|
import net.minecraft.server.v1_6_R3.*;
|
||||||
|
|
||||||
|
import org.bukkit.Art;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.craftbukkit.v1_6_R3.entity.*;
|
||||||
import org.bukkit.entity.Arrow;
|
import org.bukkit.entity.Arrow;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.ExperienceOrb;
|
import org.bukkit.entity.ExperienceOrb;
|
||||||
@ -42,6 +44,8 @@ import com.comphenix.protocol.events.PacketContainer;
|
|||||||
import com.comphenix.protocol.events.PacketEvent;
|
import com.comphenix.protocol.events.PacketEvent;
|
||||||
import com.comphenix.protocol.events.PacketListener;
|
import com.comphenix.protocol.events.PacketListener;
|
||||||
import com.comphenix.protocol.reflect.StructureModifier;
|
import com.comphenix.protocol.reflect.StructureModifier;
|
||||||
|
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
|
||||||
|
import com.comphenix.protocol.wrappers.WrappedWatchableObject;
|
||||||
|
|
||||||
public class PacketsManager {
|
public class PacketsManager {
|
||||||
private static boolean cancelSound;
|
private static boolean cancelSound;
|
||||||
@ -131,9 +135,12 @@ public class PacketsManager {
|
|||||||
org.bukkit.inventory.ItemStack itemstack = disguise.getWatcher().getItemStack(slot);
|
org.bukkit.inventory.ItemStack itemstack = disguise.getWatcher().getItemStack(slot);
|
||||||
if (itemstack != null && itemstack.getTypeId() != 0) {
|
if (itemstack != null && itemstack.getTypeId() != 0) {
|
||||||
ItemStack item = null;
|
ItemStack item = null;
|
||||||
if (nmsEntity instanceof EntityLiving)
|
if (disguisedEntity instanceof LivingEntity)
|
||||||
item = ((EntityLiving) nmsEntity).getEquipment(i);
|
if (i != 4)
|
||||||
if (item == null) {
|
item = ((LivingEntity) disguisedEntity).getEquipment().getArmorContents()[i];
|
||||||
|
else
|
||||||
|
item = ((LivingEntity) disguisedEntity).getEquipment().getItemInHand();
|
||||||
|
if (item == null || item.getType() == Material.AIR) {
|
||||||
PacketContainer packet = new PacketContainer(Packets.Server.ENTITY_EQUIPMENT);
|
PacketContainer packet = new PacketContainer(Packets.Server.ENTITY_EQUIPMENT);
|
||||||
StructureModifier<Object> mods = packet.getModifier();
|
StructureModifier<Object> mods = packet.getModifier();
|
||||||
mods.write(0, disguisedEntity.getEntityId());
|
mods.write(0, disguisedEntity.getEntityId());
|
||||||
@ -171,8 +178,8 @@ public class PacketsManager {
|
|||||||
mods.write(4, ((int) loc.getYaw()) % 4);
|
mods.write(4, ((int) loc.getYaw()) % 4);
|
||||||
int id = ((MiscDisguise) disguise).getData();
|
int id = ((MiscDisguise) disguise).getData();
|
||||||
if (id == -1)
|
if (id == -1)
|
||||||
id = new Random().nextInt(EnumArt.values().length);
|
id = new Random().nextInt(Art.values().length);
|
||||||
mods.write(5, EnumArt.values()[id % EnumArt.values().length].B);
|
mods.write(5, ReflectionManager.getEnumArt(Art.values()[id % Art.values().length]));
|
||||||
|
|
||||||
// Make the teleport packet to make it visible..
|
// Make the teleport packet to make it visible..
|
||||||
spawnPackets[1] = new PacketContainer(Packets.Server.ENTITY_TELEPORT);
|
spawnPackets[1] = new PacketContainer(Packets.Server.ENTITY_TELEPORT);
|
||||||
@ -202,8 +209,9 @@ public class PacketsManager {
|
|||||||
} else if (disguisedEntity instanceof LivingEntity) {
|
} else if (disguisedEntity instanceof LivingEntity) {
|
||||||
item = ((LivingEntity) disguisedEntity).getEquipment().getItemInHand();
|
item = ((LivingEntity) disguisedEntity).getEquipment().getItemInHand();
|
||||||
}
|
}
|
||||||
mods.write(8, (item == null || item.getType() == Material.AIR ? 0 : item.getTypeId());
|
mods.write(8, (item == null || item.getType() == Material.AIR ? 0 : item.getTypeId()));
|
||||||
mods.write(9, createDataWatcher(nmsEntity.getDataWatcher(), disguise.getWatcher()));
|
spawnPackets[0].getDataWatcherModifier().write(0,
|
||||||
|
createDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity), disguise.getWatcher()));
|
||||||
|
|
||||||
} else if (disguise.getType().isMob()) {
|
} else if (disguise.getType().isMob()) {
|
||||||
|
|
||||||
@ -239,7 +247,8 @@ public class PacketsManager {
|
|||||||
mods.write(9, (byte) (int) (loc.getPitch() * 256.0F / 360.0F));
|
mods.write(9, (byte) (int) (loc.getPitch() * 256.0F / 360.0F));
|
||||||
if (nmsEntity instanceof EntityLiving)
|
if (nmsEntity instanceof EntityLiving)
|
||||||
mods.write(10, (byte) (int) (((EntityLiving) nmsEntity).aA * 256.0F / 360.0F));
|
mods.write(10, (byte) (int) (((EntityLiving) nmsEntity).aA * 256.0F / 360.0F));
|
||||||
mods.write(11, createDataWatcher(nmsEntity.getDataWatcher(), disguise.getWatcher()));
|
spawnPackets[0].getDataWatcherModifier().write(0,
|
||||||
|
createDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity), disguise.getWatcher()));
|
||||||
// Theres a list sometimes written with this. But no problems have appeared!
|
// Theres a list sometimes written with this. But no problems have appeared!
|
||||||
// Probably just the metadata to be sent. But the next meta packet after fixes that anyways.
|
// Probably just the metadata to be sent. But the next meta packet after fixes that anyways.
|
||||||
|
|
||||||
@ -309,16 +318,13 @@ public class PacketsManager {
|
|||||||
/**
|
/**
|
||||||
* Create a new datawatcher but with the 'correct' values
|
* Create a new datawatcher but with the 'correct' values
|
||||||
*/
|
*/
|
||||||
private static DataWatcher createDataWatcher(DataWatcher watcher, FlagWatcher flagWatcher) {
|
private static WrappedDataWatcher createDataWatcher(WrappedDataWatcher watcher, FlagWatcher flagWatcher) {
|
||||||
DataWatcher newWatcher = new DataWatcher();
|
WrappedDataWatcher newWatcher = new WrappedDataWatcher();
|
||||||
try {
|
try {
|
||||||
Field map = newWatcher.getClass().getDeclaredField("c");
|
|
||||||
map.setAccessible(true);
|
|
||||||
HashMap c = (HashMap) map.get(newWatcher);
|
|
||||||
// Calling c() gets the watchable objects exactly as they are.
|
// Calling c() gets the watchable objects exactly as they are.
|
||||||
List<WatchableObject> list = watcher.c();
|
List<WrappedWatchableObject> list = watcher.getWatchableObjects();
|
||||||
for (WatchableObject watchableObject : flagWatcher.convert(list)) {
|
for (WrappedWatchableObject watchableObject : flagWatcher.convert(list)) {
|
||||||
c.put(watchableObject.a(), watchableObject);
|
newWatcher.setObject(watchableObject.getIndex(), watchableObject.getValue());
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
@ -611,16 +617,16 @@ public class PacketsManager {
|
|||||||
|
|
||||||
if (event.getPacketID() == Packets.Server.ENTITY_METADATA) {
|
if (event.getPacketID() == Packets.Server.ENTITY_METADATA) {
|
||||||
event.setPacket(event.getPacket().deepClone());
|
event.setPacket(event.getPacket().deepClone());
|
||||||
StructureModifier<Object> mods = event.getPacket().getModifier();
|
Iterator<WrappedWatchableObject> itel = event.getPacket().getWatchableCollectionModifier().read(0)
|
||||||
Iterator<WatchableObject> itel = ((List<WatchableObject>) mods.read(1)).iterator();
|
.iterator();
|
||||||
while (itel.hasNext()) {
|
while (itel.hasNext()) {
|
||||||
WatchableObject watch = itel.next();
|
WrappedWatchableObject watch = itel.next();
|
||||||
if (watch.a() == 0) {
|
if (watch.getTypeID() == 0) {
|
||||||
byte b = (Byte) watch.b();
|
byte b = (Byte) watch.getValue();
|
||||||
byte a = (byte) (b | 1 << 5);
|
byte a = (byte) (b | 1 << 5);
|
||||||
if ((b & 1 << 3) != 0)
|
if ((b & 1 << 3) != 0)
|
||||||
a = (byte) (a | 1 << 3);
|
a = (byte) (a | 1 << 3);
|
||||||
watch.a(a);
|
watch.setValue(a);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -642,7 +648,7 @@ public class PacketsManager {
|
|||||||
byte b = (byte) (0 | 1 << 5);
|
byte b = (byte) (0 | 1 << 5);
|
||||||
if (event.getPlayer().isSprinting())
|
if (event.getPlayer().isSprinting())
|
||||||
b = (byte) (b | 1 << 3);
|
b = (byte) (b | 1 << 3);
|
||||||
watchableList.add(new WatchableObject(0, 0, b));
|
watchableList.add(new WrappedWatchableObject(0, b));
|
||||||
mods.write(1, watchableList);
|
mods.write(1, watchableList);
|
||||||
try {
|
try {
|
||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false);
|
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false);
|
||||||
@ -710,7 +716,8 @@ public class PacketsManager {
|
|||||||
org.bukkit.inventory.ItemStack item = event.getPlayer().getItemInHand();
|
org.bukkit.inventory.ItemStack item = event.getPlayer().getItemInHand();
|
||||||
if (item != null && item.getType() != Material.AIR) {
|
if (item != null && item.getType() != Material.AIR) {
|
||||||
event.setPacket(event.getPacket().shallowClone());
|
event.setPacket(event.getPacket().shallowClone());
|
||||||
event.getPacket().getModifier()
|
event.getPacket()
|
||||||
|
.getModifier()
|
||||||
.write(2, ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(0)));
|
.write(2, ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(0)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -723,8 +730,8 @@ public class PacketsManager {
|
|||||||
*/
|
*/
|
||||||
case Packets.Server.WINDOW_ITEMS: {
|
case Packets.Server.WINDOW_ITEMS: {
|
||||||
event.setPacket(event.getPacket().deepClone());
|
event.setPacket(event.getPacket().deepClone());
|
||||||
StructureModifier<Object> mods = event.getPacket().getModifier();
|
StructureModifier<ItemStack[]> mods = event.getPacket().getItemArrayModifier();
|
||||||
ItemStack[] items = (ItemStack[]) mods.read(1);
|
ItemStack[] items = mods.read(0);
|
||||||
for (int slot = 0; slot < items.length; slot++) {
|
for (int slot = 0; slot < items.length; slot++) {
|
||||||
if (slot >= 5 && slot <= 8) {
|
if (slot >= 5 && slot <= 8) {
|
||||||
if (disguise.isHidingArmorFromSelf()) {
|
if (disguise.isHidingArmorFromSelf()) {
|
||||||
@ -732,7 +739,7 @@ public class PacketsManager {
|
|||||||
int armorSlot = Math.abs((slot - 5) - 3);
|
int armorSlot = Math.abs((slot - 5) - 3);
|
||||||
org.bukkit.inventory.ItemStack item = event.getPlayer().getInventory().getArmorContents()[armorSlot];
|
org.bukkit.inventory.ItemStack item = event.getPlayer().getInventory().getArmorContents()[armorSlot];
|
||||||
if (item != null && item.getType() != Material.AIR) {
|
if (item != null && item.getType() != Material.AIR) {
|
||||||
items[slot] = ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(0));
|
items[slot] = new org.bukkit.inventory.ItemStack(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Else if its a hotbar slot
|
// Else if its a hotbar slot
|
||||||
@ -743,12 +750,13 @@ public class PacketsManager {
|
|||||||
if (slot == currentSlot + 36) {
|
if (slot == currentSlot + 36) {
|
||||||
org.bukkit.inventory.ItemStack item = event.getPlayer().getItemInHand();
|
org.bukkit.inventory.ItemStack item = event.getPlayer().getItemInHand();
|
||||||
if (item != null && item.getType() != Material.AIR) {
|
if (item != null && item.getType() != Material.AIR) {
|
||||||
items[slot] = ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(0));
|
items[slot] = new org.bukkit.inventory.ItemStack(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
mods.write(0, items);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
@ -1006,7 +1014,7 @@ public class PacketsManager {
|
|||||||
|
|
||||||
// Resend the armor
|
// Resend the armor
|
||||||
for (int i = 0; i < 5; ++i) {
|
for (int i = 0; i < 5; ++i) {
|
||||||
ItemStack itemstack = ((EntityLiving) tracker.tracker).getEquipment(i);
|
net.minecraft.server.v1_6_R3.ItemStack itemstack = ((EntityLiving) tracker.tracker).getEquipment(i);
|
||||||
|
|
||||||
if (itemstack != null) {
|
if (itemstack != null) {
|
||||||
entityplayer.playerConnection.sendPacket(new Packet5EntityEquipment(player.getEntityId(), i, itemstack));
|
entityplayer.playerConnection.sendPacket(new Packet5EntityEquipment(player.getEntityId(), i, itemstack));
|
||||||
@ -1113,22 +1121,8 @@ public class PacketsManager {
|
|||||||
case Packets.Server.UPDATE_ATTRIBUTES:
|
case Packets.Server.UPDATE_ATTRIBUTES:
|
||||||
|
|
||||||
{
|
{
|
||||||
// Grab the values which are 'approved' to be sent for this entity
|
|
||||||
HashMap<String, Double> values = Values.getAttributesValues(disguise.getType());
|
|
||||||
Collection collection = new ArrayList<AttributeSnapshot>();
|
|
||||||
for (AttributeSnapshot att : (List<AttributeSnapshot>) sentPacket.getModifier().read(1)) {
|
|
||||||
if (values.containsKey(att.a())) {
|
|
||||||
collection.add(new AttributeSnapshot(null, att.a(), values.get(att.a()), att.c()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (collection.size() > 0) {
|
|
||||||
packets[0] = new PacketContainer(sentPacket.getID());
|
|
||||||
StructureModifier<Object> mods = packets[0].getModifier();
|
|
||||||
mods.write(0, entity.getEntityId());
|
|
||||||
mods.write(1, collection);
|
|
||||||
} else {
|
|
||||||
packets = new PacketContainer[0];
|
packets = new PacketContainer[0];
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1136,12 +1130,12 @@ public class PacketsManager {
|
|||||||
case Packets.Server.ENTITY_METADATA:
|
case Packets.Server.ENTITY_METADATA:
|
||||||
|
|
||||||
{
|
{
|
||||||
List<WatchableObject> watchableObjects = disguise.getWatcher().convert(
|
List<WrappedWatchableObject> watchableObjects = disguise.getWatcher().convert(
|
||||||
(List<WatchableObject>) packets[0].getModifier().read(1));
|
packets[0].getWatchableCollectionModifier().read(0));
|
||||||
packets[0] = new PacketContainer(sentPacket.getID());
|
packets[0] = new PacketContainer(sentPacket.getID());
|
||||||
StructureModifier<Object> newMods = packets[0].getModifier();
|
StructureModifier<Object> newMods = packets[0].getModifier();
|
||||||
newMods.write(0, entity.getEntityId());
|
newMods.write(0, entity.getEntityId());
|
||||||
newMods.write(1, watchableObjects);
|
packets[0].getWatchableCollectionModifier().write(0, watchableObjects);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
package me.libraryaddict.disguise;
|
package me.libraryaddict.disguise;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
import net.minecraft.server.v1_6_R3.World;
|
import org.bukkit.Art;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.craftbukkit.v1_6_R3.inventory.CraftItemStack;
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
public class ReflectionManager {
|
public class ReflectionManager {
|
||||||
@ -20,18 +19,44 @@ public class ReflectionManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getEnumArt(Art art) {
|
||||||
|
try {
|
||||||
|
Class craftArt = Class.forName("org.bukkit.craftbukkit." + bukkitVersion + ".CraftArt");
|
||||||
|
Object enumArt = craftArt.getMethod("BukkitToNotch", Art.class).invoke(null, art);
|
||||||
|
for (Field field : enumArt.getClass().getFields()) {
|
||||||
|
if (field.getType() == String.class) {
|
||||||
|
return (String) field.get(enumArt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getCraftSound(Sound sound) {
|
||||||
|
try {
|
||||||
|
Class c = Class.forName("org.bukkit.craftbukkit." + bukkitVersion + ".CraftSound");
|
||||||
|
return (String) c.getMethod("getSound", Sound.class).invoke(null, sound);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public static Object getEntityInstance(String entityName) {
|
public static Object getEntityInstance(String entityName) {
|
||||||
try {
|
try {
|
||||||
Class entityClass = getNmsClass("Entity" + entityName);
|
Class entityClass = getNmsClass("Entity" + entityName);
|
||||||
Object entityObject;
|
Object entityObject;
|
||||||
Object world = getWorld();
|
Object world = getWorld();
|
||||||
if (entityName.equals("Human")) {
|
if (entityName.equals("Human")) {
|
||||||
entityObject = entityClass.getConstructor(world.getClass(), String.class).newInstance(world, "LibsDisguises");
|
entityObject = entityClass.getConstructor(getNmsClass("World"), String.class).newInstance(world, "LibsDisguises");
|
||||||
} else {
|
} else {
|
||||||
entityObject = entityClass.getConstructor(world.getClass()).newInstance(world);
|
entityObject = entityClass.getConstructor(getNmsClass("World")).newInstance(world);
|
||||||
}
|
}
|
||||||
return entityObject;
|
return entityObject;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -58,7 +83,9 @@ public class ReflectionManager {
|
|||||||
|
|
||||||
private static Object getWorld() {
|
private static Object getWorld() {
|
||||||
try {
|
try {
|
||||||
return World.class.getMethod("getHandle").invoke(Bukkit.getWorlds().get(0));
|
return Class.forName("org.bukkit.craftbukkit." + bukkitVersion + ".CraftWorld").getMethod("getHandle")
|
||||||
|
.invoke(Bukkit.getWorlds().get(0));
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -1,25 +1,25 @@
|
|||||||
package me.libraryaddict.disguise.disguisetypes;
|
package me.libraryaddict.disguise.disguisetypes;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import me.libraryaddict.disguise.DisguiseAPI;
|
import me.libraryaddict.disguise.DisguiseAPI;
|
||||||
import me.libraryaddict.disguise.PacketsManager;
|
import me.libraryaddict.disguise.PacketsManager;
|
||||||
|
import me.libraryaddict.disguise.ReflectionManager;
|
||||||
import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher;
|
import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher;
|
||||||
import me.libraryaddict.disguise.disguisetypes.watchers.HorseWatcher;
|
import me.libraryaddict.disguise.disguisetypes.watchers.HorseWatcher;
|
||||||
import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher;
|
import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher;
|
||||||
import net.minecraft.server.v1_6_R3.EntityAgeable;
|
import net.minecraft.server.v1_6_R3.EntityAgeable;
|
||||||
import net.minecraft.server.v1_6_R3.EntityInsentient;
|
import net.minecraft.server.v1_6_R3.EntityInsentient;
|
||||||
import net.minecraft.server.v1_6_R3.EntityLiving;
|
import net.minecraft.server.v1_6_R3.EntityLiving;
|
||||||
import net.minecraft.server.v1_6_R3.EntityPlayer;
|
|
||||||
import net.minecraft.server.v1_6_R3.EntityTrackerEntry;
|
import net.minecraft.server.v1_6_R3.EntityTrackerEntry;
|
||||||
import net.minecraft.server.v1_6_R3.WorldServer;
|
import net.minecraft.server.v1_6_R3.WorldServer;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.craftbukkit.v1_6_R3.entity.CraftEntity;
|
import org.bukkit.craftbukkit.v1_6_R3.entity.CraftEntity;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Horse.Variant;
|
import org.bukkit.entity.Horse.Variant;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
@ -190,10 +190,7 @@ public abstract class Disguise {
|
|||||||
i++;
|
i++;
|
||||||
if (i % 40 == 0) {
|
if (i % 40 == 0) {
|
||||||
i = 0;
|
i = 0;
|
||||||
List<Player> players = new ArrayList<Player>();
|
ProtocolLibrary.getProtocolManager().updateEntity(getEntity(), getPerverts());
|
||||||
for (EntityPlayer p : getPerverts())
|
|
||||||
players.add(p.getBukkitEntity());
|
|
||||||
ProtocolLibrary.getProtocolManager().updateEntity(getEntity(), players);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// If the vectorY isn't 0. Cos if it is. Then it doesn't want to send any vectors.
|
// If the vectorY isn't 0. Cos if it is. Then it doesn't want to send any vectors.
|
||||||
@ -219,16 +216,19 @@ public abstract class Disguise {
|
|||||||
mods.write(5, (byte) Math.floor(loc.getPitch() * 256.0F / 360.0F));
|
mods.write(5, (byte) Math.floor(loc.getPitch() * 256.0F / 360.0F));
|
||||||
selfLookPacket = lookPacket.shallowClone();
|
selfLookPacket = lookPacket.shallowClone();
|
||||||
}
|
}
|
||||||
for (EntityPlayer player : getPerverts()) {
|
try {
|
||||||
|
Field ping = ReflectionManager.getNmsClass("EntityPlayer").getField("ping");
|
||||||
|
Field handle = Entity.class.getField("getHandle");
|
||||||
|
for (Player player : getPerverts()) {
|
||||||
PacketContainer packet = new PacketContainer(Packets.Server.ENTITY_VELOCITY);
|
PacketContainer packet = new PacketContainer(Packets.Server.ENTITY_VELOCITY);
|
||||||
StructureModifier<Object> mods = packet.getModifier();
|
StructureModifier<Object> mods = packet.getModifier();
|
||||||
if (entity == player.getBukkitEntity()) {
|
if (entity == player) {
|
||||||
if (!viewSelfDisguise())
|
if (!viewSelfDisguise())
|
||||||
continue;
|
continue;
|
||||||
if (selfLookPacket != null) {
|
if (selfLookPacket != null) {
|
||||||
try {
|
try {
|
||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player.getBukkitEntity(),
|
ProtocolLibrary.getProtocolManager().sendServerPacket(player, selfLookPacket,
|
||||||
selfLookPacket, false);
|
false);
|
||||||
} catch (InvocationTargetException e) {
|
} catch (InvocationTargetException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -237,17 +237,15 @@ public abstract class Disguise {
|
|||||||
} else
|
} else
|
||||||
mods.write(0, entity.getEntityId());
|
mods.write(0, entity.getEntityId());
|
||||||
mods.write(1, (int) (vector.getX() * 8000));
|
mods.write(1, (int) (vector.getX() * 8000));
|
||||||
mods.write(2, (int) (8000 * (vectorY * (double) player.ping * 0.069)));
|
mods.write(2, (int) (8000 * (vectorY * (double) ping.getInt(handle.get(player)) * 0.069)));
|
||||||
mods.write(3, (int) (vector.getZ() * 8000));
|
mods.write(3, (int) (vector.getZ() * 8000));
|
||||||
try {
|
|
||||||
if (lookPacket != null)
|
if (lookPacket != null)
|
||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player.getBukkitEntity(),
|
ProtocolLibrary.getProtocolManager().sendServerPacket(player, lookPacket, false);
|
||||||
lookPacket, false);
|
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
|
||||||
ProtocolLibrary.getProtocolManager()
|
|
||||||
.sendServerPacket(player.getBukkitEntity(), packet, false);
|
|
||||||
} catch (InvocationTargetException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// If we need to send more packets because else it still 'sinks'
|
// If we need to send more packets because else it still 'sinks'
|
||||||
@ -255,10 +253,10 @@ public abstract class Disguise {
|
|||||||
PacketContainer packet = new PacketContainer(Packets.Server.REL_ENTITY_MOVE);
|
PacketContainer packet = new PacketContainer(Packets.Server.REL_ENTITY_MOVE);
|
||||||
StructureModifier<Object> mods = packet.getModifier();
|
StructureModifier<Object> mods = packet.getModifier();
|
||||||
mods.write(0, entity.getEntityId());
|
mods.write(0, entity.getEntityId());
|
||||||
for (EntityPlayer player : getPerverts()) {
|
for (Player player : getPerverts()) {
|
||||||
if (DisguiseAPI.isViewDisguises() || entity != player) {
|
if (DisguiseAPI.isViewDisguises() || entity != player) {
|
||||||
try {
|
try {
|
||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player.getBukkitEntity(), packet);
|
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
|
||||||
} catch (InvocationTargetException e) {
|
} catch (InvocationTargetException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -281,14 +279,21 @@ public abstract class Disguise {
|
|||||||
/**
|
/**
|
||||||
* Get all EntityPlayers who have this entity in their Entity Tracker
|
* Get all EntityPlayers who have this entity in their Entity Tracker
|
||||||
*/
|
*/
|
||||||
protected EntityPlayer[] getPerverts() {
|
protected ArrayList<Player> getPerverts() {
|
||||||
|
ArrayList<Player> players = new ArrayList<Player>();
|
||||||
|
try {
|
||||||
EntityTrackerEntry entry = (EntityTrackerEntry) ((WorldServer) ((CraftEntity) entity).getHandle().world).tracker.trackedEntities
|
EntityTrackerEntry entry = (EntityTrackerEntry) ((WorldServer) ((CraftEntity) entity).getHandle().world).tracker.trackedEntities
|
||||||
.get(entity.getEntityId());
|
.get(entity.getEntityId());
|
||||||
if (entry != null) {
|
if (entry != null) {
|
||||||
EntityPlayer[] players = (EntityPlayer[]) entry.trackedPlayers.toArray(new EntityPlayer[entry.trackedPlayers.size()]);
|
Field field = ReflectionManager.getNmsClass("Entity").getField("getBukkitEntity");
|
||||||
return players;
|
for (Object p : entry.trackedPlayers) {
|
||||||
|
players.add((Player) field.get(p));
|
||||||
}
|
}
|
||||||
return new EntityPlayer[0];
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
return players;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -3,8 +3,9 @@ package me.libraryaddict.disguise.disguisetypes;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
import me.libraryaddict.disguise.ReflectionManager;
|
||||||
|
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.craftbukkit.v1_6_R3.CraftSound;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Only living disguises go in here!
|
* Only living disguises go in here!
|
||||||
@ -103,10 +104,6 @@ public enum DisguiseSound {
|
|||||||
CANCEL, DEATH, HURT, IDLE, STEP;
|
CANCEL, DEATH, HURT, IDLE, STEP;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getSoundName(Sound sound) {
|
|
||||||
return CraftSound.getSound(sound);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static DisguiseSound getType(String name) {
|
public static DisguiseSound getType(String name) {
|
||||||
try {
|
try {
|
||||||
return valueOf(name);
|
return valueOf(name);
|
||||||
@ -128,7 +125,7 @@ public enum DisguiseSound {
|
|||||||
else if (obj instanceof String)
|
else if (obj instanceof String)
|
||||||
s = (String) obj;
|
s = (String) obj;
|
||||||
else if (obj instanceof Sound)
|
else if (obj instanceof Sound)
|
||||||
s = CraftSound.getSound((Sound) obj);
|
s = ReflectionManager.getCraftSound((Sound) obj);
|
||||||
else
|
else
|
||||||
throw new RuntimeException("Was given a unknown object " + obj);
|
throw new RuntimeException("Was given a unknown object " + obj);
|
||||||
switch (i) {
|
switch (i) {
|
||||||
@ -195,7 +192,7 @@ public enum DisguiseSound {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void removeSound(SoundType type, Sound sound) {
|
public void removeSound(SoundType type, Sound sound) {
|
||||||
removeSound(type, CraftSound.getSound(sound));
|
removeSound(type, ReflectionManager.getCraftSound(sound));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeSound(SoundType type, String sound) {
|
public void removeSound(SoundType type, String sound) {
|
||||||
@ -211,7 +208,7 @@ public enum DisguiseSound {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setSound(SoundType type, Sound sound) {
|
public void setSound(SoundType type, Sound sound) {
|
||||||
setSound(type, CraftSound.getSound(sound));
|
setSound(type, ReflectionManager.getCraftSound(sound));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSound(SoundType type, String sound) {
|
public void setSound(SoundType type, String sound) {
|
||||||
|
@ -7,7 +7,6 @@ import java.util.HashSet;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_6_R3.inventory.CraftItemStack;
|
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -17,14 +16,11 @@ import com.comphenix.protocol.Packets;
|
|||||||
import com.comphenix.protocol.ProtocolLibrary;
|
import com.comphenix.protocol.ProtocolLibrary;
|
||||||
import com.comphenix.protocol.events.PacketContainer;
|
import com.comphenix.protocol.events.PacketContainer;
|
||||||
import com.comphenix.protocol.reflect.StructureModifier;
|
import com.comphenix.protocol.reflect.StructureModifier;
|
||||||
|
import com.comphenix.protocol.wrappers.WrappedWatchableObject;
|
||||||
|
|
||||||
import me.libraryaddict.disguise.DisguiseAPI;
|
import me.libraryaddict.disguise.DisguiseAPI;
|
||||||
import me.libraryaddict.disguise.PacketsManager;
|
import me.libraryaddict.disguise.PacketsManager;
|
||||||
import me.libraryaddict.disguise.ReflectionManager;
|
import me.libraryaddict.disguise.ReflectionManager;
|
||||||
import net.minecraft.server.v1_6_R3.ChunkCoordinates;
|
|
||||||
import net.minecraft.server.v1_6_R3.EntityPlayer;
|
|
||||||
import net.minecraft.server.v1_6_R3.ItemStack;
|
|
||||||
import net.minecraft.server.v1_6_R3.WatchableObject;
|
|
||||||
|
|
||||||
public class FlagWatcher {
|
public class FlagWatcher {
|
||||||
public enum SlotType {
|
public enum SlotType {
|
||||||
@ -40,16 +36,6 @@ public class FlagWatcher {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static HashMap<Class, Integer> classTypes = new HashMap<Class, Integer>();
|
|
||||||
static {
|
|
||||||
classTypes.put(Byte.class, 0);
|
|
||||||
classTypes.put(Short.class, 1);
|
|
||||||
classTypes.put(Integer.class, 2);
|
|
||||||
classTypes.put(Float.class, 3);
|
|
||||||
classTypes.put(String.class, 4);
|
|
||||||
classTypes.put(ItemStack.class, 5);
|
|
||||||
classTypes.put(ChunkCoordinates.class, 6);
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* This is the entity values I need to add else it could crash them..
|
* This is the entity values I need to add else it could crash them..
|
||||||
*/
|
*/
|
||||||
@ -68,7 +54,6 @@ public class FlagWatcher {
|
|||||||
try {
|
try {
|
||||||
cloned = getClass().getConstructor(Disguise.class).newInstance(disguise);
|
cloned = getClass().getConstructor(Disguise.class).newInstance(disguise);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
cloned.entityValues = (HashMap<Integer, Object>) entityValues.clone();
|
cloned.entityValues = (HashMap<Integer, Object>) entityValues.clone();
|
||||||
@ -76,14 +61,14 @@ public class FlagWatcher {
|
|||||||
return cloned;
|
return cloned;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<WatchableObject> convert(List<WatchableObject> list) {
|
public List<WrappedWatchableObject> convert(List<WrappedWatchableObject> list) {
|
||||||
Iterator<WatchableObject> itel = list.iterator();
|
Iterator<WrappedWatchableObject> itel = list.iterator();
|
||||||
List<WatchableObject> newList = new ArrayList<WatchableObject>();
|
List<WrappedWatchableObject> newList = new ArrayList<WrappedWatchableObject>();
|
||||||
HashSet<Integer> sentValues = new HashSet<Integer>();
|
HashSet<Integer> sentValues = new HashSet<Integer>();
|
||||||
boolean sendAllCustom = false;
|
boolean sendAllCustom = false;
|
||||||
while (itel.hasNext()) {
|
while (itel.hasNext()) {
|
||||||
WatchableObject watch = itel.next();
|
WrappedWatchableObject watch = itel.next();
|
||||||
int dataType = watch.a();
|
int dataType = watch.getTypeID();
|
||||||
sentValues.add(dataType);
|
sentValues.add(dataType);
|
||||||
// Its sending the air metadata. This is the least commonly sent metadata which all entitys still share.
|
// Its sending the air metadata. This is the least commonly sent metadata which all entitys still share.
|
||||||
// I send my custom values if I see this!
|
// I send my custom values if I see this!
|
||||||
@ -100,15 +85,15 @@ public class FlagWatcher {
|
|||||||
value = backupEntityValues.get(dataType);
|
value = backupEntityValues.get(dataType);
|
||||||
}
|
}
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
boolean doD = watch.d();
|
boolean doD = watch.getDirtyState();
|
||||||
watch = new WatchableObject(classTypes.get(value.getClass()), dataType, value);
|
watch = new WrappedWatchableObject(dataType, value);
|
||||||
if (!doD)
|
if (!doD)
|
||||||
watch.a(false);
|
watch.setDirtyState(doD);
|
||||||
} else {
|
} else {
|
||||||
boolean doD = watch.d();
|
boolean doD = watch.getDirtyState();
|
||||||
watch = new WatchableObject(watch.c(), dataType, watch.b());
|
watch = new WrappedWatchableObject(dataType, watch.getValue());
|
||||||
if (!doD)
|
if (!doD)
|
||||||
watch.a(false);
|
watch.setDirtyState(doD);
|
||||||
}
|
}
|
||||||
newList.add(watch);
|
newList.add(watch);
|
||||||
}
|
}
|
||||||
@ -120,16 +105,16 @@ public class FlagWatcher {
|
|||||||
Object obj = entityValues.get(value);
|
Object obj = entityValues.get(value);
|
||||||
if (obj == null)
|
if (obj == null)
|
||||||
continue;
|
continue;
|
||||||
WatchableObject watch = new WatchableObject(classTypes.get(obj.getClass()), value, obj);
|
WrappedWatchableObject watch = new WrappedWatchableObject(value, obj);
|
||||||
newList.add(watch);
|
newList.add(watch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 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 (disguise.viewSelfDisguise() && disguise.getEntity() != null && disguise.getEntity() instanceof Player) {
|
if (disguise.viewSelfDisguise() && disguise.getEntity() != null && disguise.getEntity() instanceof Player) {
|
||||||
for (WatchableObject watch : newList) {
|
for (WrappedWatchableObject watch : newList) {
|
||||||
// Its a health packet
|
// Its a health packet
|
||||||
if (watch.a() == 6) {
|
if (watch.getTypeID() == 6) {
|
||||||
Object value = watch.b();
|
Object value = watch.getValue();
|
||||||
if (value != null && value instanceof Float) {
|
if (value != null && value instanceof Float) {
|
||||||
float newHealth = (Float) value;
|
float newHealth = (Float) value;
|
||||||
if (newHealth > 0 && hasDied) {
|
if (newHealth > 0 && hasDied) {
|
||||||
@ -210,17 +195,16 @@ public class FlagWatcher {
|
|||||||
return;
|
return;
|
||||||
Entity entity = disguise.getEntity();
|
Entity entity = disguise.getEntity();
|
||||||
Object value = entityValues.get(data);
|
Object value = entityValues.get(data);
|
||||||
List<WatchableObject> list = new ArrayList<WatchableObject>();
|
List<WrappedWatchableObject> list = new ArrayList<WrappedWatchableObject>();
|
||||||
list.add(new WatchableObject(classTypes.get(value.getClass()), data, value));
|
list.add(new WrappedWatchableObject(data, value));
|
||||||
PacketContainer packet = new PacketContainer(Packets.Server.ENTITY_METADATA);
|
PacketContainer packet = new PacketContainer(Packets.Server.ENTITY_METADATA);
|
||||||
StructureModifier<Object> mods = packet.getModifier();
|
StructureModifier<Object> mods = packet.getModifier();
|
||||||
mods.write(0, entity.getEntityId());
|
mods.write(0, entity.getEntityId());
|
||||||
mods.write(1, list);
|
packet.getWatchableCollectionModifier().write(0, list);
|
||||||
for (EntityPlayer player : disguise.getPerverts()) {
|
for (Player player : disguise.getPerverts()) {
|
||||||
Player p = player.getBukkitEntity();
|
if (DisguiseAPI.isViewDisguises() || player != entity) {
|
||||||
if (DisguiseAPI.isViewDisguises() || p != entity) {
|
|
||||||
try {
|
try {
|
||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(p, packet);
|
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
|
||||||
} catch (InvocationTargetException e) {
|
} catch (InvocationTargetException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -277,7 +261,7 @@ public class FlagWatcher {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemStack itemToSend = null;
|
Object itemToSend = null;
|
||||||
if (itemStack != null && itemStack.getTypeId() != 0)
|
if (itemStack != null && itemStack.getTypeId() != 0)
|
||||||
itemToSend = ReflectionManager.getNmsItem(itemStack);
|
itemToSend = ReflectionManager.getNmsItem(itemStack);
|
||||||
items[slot] = itemStack;
|
items[slot] = itemStack;
|
||||||
@ -291,11 +275,10 @@ public class FlagWatcher {
|
|||||||
mods.write(0, disguise.getEntity().getEntityId());
|
mods.write(0, disguise.getEntity().getEntityId());
|
||||||
mods.write(1, slot);
|
mods.write(1, slot);
|
||||||
mods.write(2, itemToSend);
|
mods.write(2, itemToSend);
|
||||||
for (EntityPlayer player : disguise.getPerverts()) {
|
for (Player player : disguise.getPerverts()) {
|
||||||
Player p = player.getBukkitEntity();
|
if (player != disguise.getEntity()) {
|
||||||
if (p != disguise.getEntity()) {
|
|
||||||
try {
|
try {
|
||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(p, packet);
|
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
|
||||||
} catch (InvocationTargetException e) {
|
} catch (InvocationTargetException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -2,15 +2,13 @@ package me.libraryaddict.disguise.disguisetypes;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import net.minecraft.server.v1_6_R3.EnumEntitySize;
|
|
||||||
|
|
||||||
public class Values {
|
public class Values {
|
||||||
|
|
||||||
private static HashMap<DisguiseType, Values> values = new HashMap<DisguiseType, Values>();
|
private static HashMap<DisguiseType, Values> values = new HashMap<DisguiseType, Values>();
|
||||||
|
|
||||||
public static HashMap<String, Double> getAttributesValues(DisguiseType type) {
|
/* public static HashMap<String, Double> getAttributesValues(DisguiseType type) {
|
||||||
return getValues(type).getAttributesValues();
|
return getValues(type).getAttributesValues();
|
||||||
}
|
}*/
|
||||||
|
|
||||||
public static Class getEntityClass(DisguiseType type) {
|
public static Class getEntityClass(DisguiseType type) {
|
||||||
return getValues(type).getEntityClass();
|
return getValues(type).getEntityClass();
|
||||||
@ -47,7 +45,7 @@ public class Values {
|
|||||||
return values.get(type);
|
return values.get(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
private HashMap<String, Double> attributesValues = new HashMap<String, Double>();
|
// private HashMap<String, Double> attributesValues = new HashMap<String, Double>();
|
||||||
|
|
||||||
private Class declared;
|
private Class declared;
|
||||||
private int enumEntitySize;
|
private int enumEntitySize;
|
||||||
@ -60,9 +58,9 @@ public class Values {
|
|||||||
declared = classType;
|
declared = classType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HashMap<String, Double> getAttributesValues() {
|
/*public HashMap<String, Double> getAttributesValues() {
|
||||||
return attributesValues;
|
return attributesValues;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
public Class getEntityClass() {
|
public Class getEntityClass() {
|
||||||
return declared;
|
return declared;
|
||||||
@ -115,9 +113,9 @@ public class Values {
|
|||||||
return metaValues;
|
return metaValues;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAttributesValue(String attribute, Double value) {
|
/*public void setAttributesValue(String attribute, Double value) {
|
||||||
attributesValues.put(attribute, value);
|
attributesValues.put(attribute, value);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
public void setMetaValue(int no, Object value) {
|
public void setMetaValue(int no, Object value) {
|
||||||
metaValues.put(no, value);
|
metaValues.put(no, value);
|
||||||
|
@ -4,7 +4,6 @@ import me.libraryaddict.disguise.ReflectionManager;
|
|||||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_6_R3.inventory.CraftItemStack;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
public class DroppedItemWatcher extends FlagWatcher {
|
public class DroppedItemWatcher extends FlagWatcher {
|
||||||
@ -14,8 +13,7 @@ public class DroppedItemWatcher extends FlagWatcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack getItemStack() {
|
public ItemStack getItemStack() {
|
||||||
return CraftItemStack.asBukkitCopy((net.minecraft.server.v1_6_R3.ItemStack) getValue(10,
|
return ReflectionManager.getBukkitItem(getValue(10, ReflectionManager.getNmsItem(new ItemStack(1))));
|
||||||
ReflectionManager.getNmsItem(new ItemStack(1))));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setItemStack(ItemStack item) {
|
public void setItemStack(ItemStack item) {
|
||||||
|
@ -4,7 +4,6 @@ import me.libraryaddict.disguise.ReflectionManager;
|
|||||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_6_R3.inventory.CraftItemStack;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
public class ItemFrameWatcher extends FlagWatcher {
|
public class ItemFrameWatcher extends FlagWatcher {
|
||||||
@ -20,7 +19,7 @@ public class ItemFrameWatcher extends FlagWatcher {
|
|||||||
public ItemStack getItemStack() {
|
public ItemStack getItemStack() {
|
||||||
if (getValue(2, null) == null)
|
if (getValue(2, null) == null)
|
||||||
return new ItemStack(0);
|
return new ItemStack(0);
|
||||||
return CraftItemStack.asBukkitCopy((net.minecraft.server.v1_6_R3.ItemStack) getValue(2, null));
|
return ReflectionManager.getBukkitItem(getValue(2, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setItemRotation(int rotation) {
|
public void setItemRotation(int rotation) {
|
||||||
|
@ -1,18 +1,38 @@
|
|||||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import me.libraryaddict.disguise.ReflectionManager;
|
||||||
|
|
||||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
||||||
import net.minecraft.server.v1_6_R3.MobEffect;
|
|
||||||
import net.minecraft.server.v1_6_R3.PotionBrewer;
|
|
||||||
|
|
||||||
import org.bukkit.potion.PotionEffect;
|
import org.bukkit.potion.PotionEffect;
|
||||||
import org.bukkit.potion.PotionEffectType;
|
import org.bukkit.potion.PotionEffectType;
|
||||||
|
|
||||||
public class LivingWatcher extends FlagWatcher {
|
public class LivingWatcher extends FlagWatcher {
|
||||||
private HashSet<MobEffect> potionEffects = new HashSet<MobEffect>();
|
private HashSet<Integer> potionEffects = new HashSet<Integer>();
|
||||||
|
static Object[] list;
|
||||||
|
static Method potionNo;
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
Class mobEffectList = ReflectionManager.getNmsClass("MobEffectList");
|
||||||
|
list = (Object[]) mobEffectList.getField("byId").get(null);
|
||||||
|
for (Object obj : list) {
|
||||||
|
if (obj != null) {
|
||||||
|
for (Method field : obj.getClass().getMethods()) {
|
||||||
|
if (field.getReturnType() == int.class) {
|
||||||
|
if ((Integer) field.invoke(obj) > 10000) {
|
||||||
|
potionNo = field;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public LivingWatcher(Disguise disguise) {
|
public LivingWatcher(Disguise disguise) {
|
||||||
super(disguise);
|
super(disguise);
|
||||||
@ -22,21 +42,21 @@ public class LivingWatcher extends FlagWatcher {
|
|||||||
public void addPotionEffect(PotionEffect potionEffect) {
|
public void addPotionEffect(PotionEffect potionEffect) {
|
||||||
if (hasPotionEffect(potionEffect.getType()))
|
if (hasPotionEffect(potionEffect.getType()))
|
||||||
removePotionEffect(potionEffect.getType());
|
removePotionEffect(potionEffect.getType());
|
||||||
potionEffects.add(new MobEffect(potionEffect.getType().getId(), potionEffect.getDuration(), potionEffect.getAmplifier()));
|
potionEffects.add(potionEffect.getType().getId());
|
||||||
sendPotionEffects();
|
sendPotionEffects();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addPotionEffect(PotionEffectType potionEffect) {
|
public void addPotionEffect(PotionEffectType potionEffect) {
|
||||||
if (hasPotionEffect(potionEffect))
|
if (hasPotionEffect(potionEffect))
|
||||||
removePotionEffect(potionEffect);
|
removePotionEffect(potionEffect);
|
||||||
potionEffects.add(new MobEffect(potionEffect.getId(), 0, 0));
|
potionEffects.add(potionEffect.getId());
|
||||||
sendPotionEffects();
|
sendPotionEffects();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LivingWatcher clone(Disguise disguise) {
|
public LivingWatcher clone(Disguise disguise) {
|
||||||
LivingWatcher clone = (LivingWatcher) super.clone(disguise);
|
LivingWatcher clone = (LivingWatcher) super.clone(disguise);
|
||||||
clone.potionEffects = (HashSet<MobEffect>) potionEffects.clone();
|
clone.potionEffects = (HashSet<Integer>) potionEffects.clone();
|
||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,10 +77,7 @@ public class LivingWatcher extends FlagWatcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasPotionEffect(PotionEffectType type) {
|
public boolean hasPotionEffect(PotionEffectType type) {
|
||||||
for (MobEffect effect : potionEffects)
|
return potionEffects.contains(type.getId());
|
||||||
if (effect.getEffectId() == type.getId())
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isCustomNameVisible() {
|
public boolean isCustomNameVisible() {
|
||||||
@ -68,14 +85,9 @@ public class LivingWatcher extends FlagWatcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void removePotionEffect(PotionEffectType type) {
|
public void removePotionEffect(PotionEffectType type) {
|
||||||
Iterator<MobEffect> itel = potionEffects.iterator();
|
if (potionEffects.contains(type.getId())) {
|
||||||
while (itel.hasNext()) {
|
potionEffects.remove(type.getId());
|
||||||
MobEffect effect = itel.next();
|
|
||||||
if (effect.getEffectId() == type.getId()) {
|
|
||||||
itel.remove();
|
|
||||||
sendPotionEffects();
|
sendPotionEffects();
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,10 +97,40 @@ public class LivingWatcher extends FlagWatcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void sendPotionEffects() {
|
private void sendPotionEffects() {
|
||||||
setValue(7, PotionBrewer.a(potionEffects));
|
setValue(7, getPotions());
|
||||||
sendData(7);
|
sendData(7);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int getPotions() {
|
||||||
|
int m = 3694022;
|
||||||
|
|
||||||
|
if (potionEffects.isEmpty()) {
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
|
||||||
|
float f1 = 0.0F;
|
||||||
|
float f2 = 0.0F;
|
||||||
|
float f3 = 0.0F;
|
||||||
|
float f4 = 0.0F;
|
||||||
|
try {
|
||||||
|
for (int localMobEffect : potionEffects) {
|
||||||
|
int n = (Integer) potionNo.invoke(list[localMobEffect]);
|
||||||
|
f1 += (n >> 16 & 0xFF) / 255.0F;
|
||||||
|
f2 += (n >> 8 & 0xFF) / 255.0F;
|
||||||
|
f3 += (n >> 0 & 0xFF) / 255.0F;
|
||||||
|
f4 += 1.0F;
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
f1 = f1 / f4 * 255.0F;
|
||||||
|
f2 = f2 / f4 * 255.0F;
|
||||||
|
f3 = f3 / f4 * 255.0F;
|
||||||
|
|
||||||
|
return (int) f1 << 16 | (int) f2 << 8 | (int) f3;
|
||||||
|
}
|
||||||
|
|
||||||
public void setCustomName(String name) {
|
public void setCustomName(String name) {
|
||||||
if (name.length() > 64)
|
if (name.length() > 64)
|
||||||
name = name.substring(0, 64);
|
name = name.substring(0, 64);
|
||||||
|
Loading…
Reference in New Issue
Block a user