This reverts the 2 reverted commits
This commit is contained in:
parent
2820311551
commit
71d0b64e82
@ -14,42 +14,20 @@ import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
|||||||
import me.libraryaddict.disguise.disguisetypes.Values;
|
import me.libraryaddict.disguise.disguisetypes.Values;
|
||||||
import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher;
|
import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher;
|
||||||
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
|
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
|
||||||
import net.minecraft.server.v1_6_R3.ChatMessage;
|
|
||||||
import net.minecraft.server.v1_6_R3.ChunkCoordinates;
|
|
||||||
import net.minecraft.server.v1_6_R3.Entity;
|
|
||||||
import net.minecraft.server.v1_6_R3.EntityHuman;
|
|
||||||
import net.minecraft.server.v1_6_R3.EntityLiving;
|
|
||||||
import net.minecraft.server.v1_6_R3.GenericAttributes;
|
|
||||||
import net.minecraft.server.v1_6_R3.WatchableObject;
|
|
||||||
import net.minecraft.server.v1_6_R3.World;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.craftbukkit.v1_6_R3.CraftWorld;
|
|
||||||
import org.bukkit.entity.Ageable;
|
import org.bukkit.entity.Ageable;
|
||||||
|
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.WrappedWatchableObject;
|
||||||
|
|
||||||
public class LibsDisguises extends JavaPlugin {
|
public class LibsDisguises extends JavaPlugin {
|
||||||
private class DisguiseHuman extends EntityHuman {
|
|
||||||
|
|
||||||
public DisguiseHuman(World world) {
|
|
||||||
super(world, "LibsDisguises");
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean a(int arg0, String arg1) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ChunkCoordinates b() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void sendMessage(ChatMessage arg0) {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
@ -109,7 +87,6 @@ public class LibsDisguises extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void registerValues() {
|
private void registerValues() {
|
||||||
World world = ((CraftWorld) Bukkit.getWorlds().get(0)).getHandle();
|
|
||||||
for (DisguiseType disguiseType : DisguiseType.values()) {
|
for (DisguiseType disguiseType : DisguiseType.values()) {
|
||||||
Class watcherClass = null;
|
Class watcherClass = null;
|
||||||
try {
|
try {
|
||||||
@ -196,30 +173,32 @@ public class LibsDisguises extends JavaPlugin {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
net.minecraft.server.v1_6_R3.Entity entity = null;
|
Object entity = ReflectionManager.getEntityInstance(name);
|
||||||
Class entityClass;
|
Entity bukkitEntity = (Entity) entity.getClass().getMethod("getBukkitEntity").invoke(entity);
|
||||||
if (disguiseType == DisguiseType.PLAYER) {
|
int size = 0;
|
||||||
entityClass = EntityHuman.class;
|
for (Field field : ReflectionManager.getNmsClass("Entity").getFields()) {
|
||||||
entity = new DisguiseHuman(world);
|
if (field.getType().getName().equals("EnumEntitySize")) {
|
||||||
} else {
|
Enum a = (Enum) field.get(entity);
|
||||||
entityClass = Class.forName(Entity.class.getName() + name);
|
size = a.ordinal();
|
||||||
entity = (net.minecraft.server.v1_6_R3.Entity) entityClass.getConstructor(World.class).newInstance(world);
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Values value = new Values(disguiseType, entityClass, entity.at);
|
Values value = new Values(disguiseType, entity.getClass(), size);
|
||||||
List<WatchableObject> watchers = entity.getDataWatcher().c();
|
WrappedDataWatcher dataWatcher = WrappedDataWatcher.getEntityWatcher(bukkitEntity);
|
||||||
for (WatchableObject watch : watchers)
|
List<WrappedWatchableObject> watchers = dataWatcher.getWatchableObjects();
|
||||||
value.setMetaValue(watch.a(), watch.b());
|
for (WrappedWatchableObject watch : watchers)
|
||||||
if (entity instanceof EntityLiving) {
|
value.setMetaValue(watch.getTypeID(), watch.getValue());
|
||||||
EntityLiving livingEntity = (EntityLiving) entity;
|
WrappedAttribute s;
|
||||||
value.setAttributesValue(GenericAttributes.d.a(), livingEntity.getAttributeInstance(GenericAttributes.d)
|
if (bukkitEntity instanceof LivingEntity) {
|
||||||
|
value.setAttributesValue("generic.movementSpeed", livingEntity.getAttributeInstance(GenericAttributes.d)
|
||||||
.getValue());
|
.getValue());
|
||||||
}
|
}
|
||||||
DisguiseSound sound = DisguiseSound.getType(disguiseType.name());
|
DisguiseSound sound = DisguiseSound.getType(disguiseType.name());
|
||||||
if (sound != null) {
|
if (sound != null) {
|
||||||
Method soundStrength = EntityLiving.class.getDeclaredMethod("ba");
|
Float soundStrength = ReflectionManager.getSoundModifier(entity);
|
||||||
// TODO Update this each update!
|
if (soundStrength != null) {
|
||||||
soundStrength.setAccessible(true);
|
sound.setDamageSoundVolume((Float) soundStrength);
|
||||||
sound.setDamageSoundVolume((Float) soundStrength.invoke(entity));
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e1) {
|
} catch (Exception e1) {
|
||||||
System.out.print("[LibsDisguises] Trouble while making values for " + name + ": " + e1.getMessage());
|
System.out.print("[LibsDisguises] Trouble while making values for " + name + ": " + e1.getMessage());
|
||||||
|
@ -18,46 +18,17 @@ 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.AttributeMapServer;
|
|
||||||
import net.minecraft.server.v1_6_R3.AttributeSnapshot;
|
|
||||||
import net.minecraft.server.v1_6_R3.Block;
|
|
||||||
import net.minecraft.server.v1_6_R3.DataWatcher;
|
|
||||||
import net.minecraft.server.v1_6_R3.EntityHuman;
|
|
||||||
import net.minecraft.server.v1_6_R3.EntityInsentient;
|
|
||||||
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.EnumArt;
|
|
||||||
import net.minecraft.server.v1_6_R3.EnumEntitySize;
|
|
||||||
import net.minecraft.server.v1_6_R3.ItemStack;
|
|
||||||
import net.minecraft.server.v1_6_R3.MathHelper;
|
|
||||||
import net.minecraft.server.v1_6_R3.MobEffect;
|
|
||||||
import net.minecraft.server.v1_6_R3.Packet17EntityLocationAction;
|
|
||||||
import net.minecraft.server.v1_6_R3.Packet20NamedEntitySpawn;
|
|
||||||
import net.minecraft.server.v1_6_R3.Packet28EntityVelocity;
|
|
||||||
import net.minecraft.server.v1_6_R3.Packet35EntityHeadRotation;
|
|
||||||
import net.minecraft.server.v1_6_R3.Packet39AttachEntity;
|
|
||||||
import net.minecraft.server.v1_6_R3.Packet40EntityMetadata;
|
|
||||||
import net.minecraft.server.v1_6_R3.Packet41MobEffect;
|
|
||||||
import net.minecraft.server.v1_6_R3.Packet44UpdateAttributes;
|
|
||||||
import net.minecraft.server.v1_6_R3.Packet5EntityEquipment;
|
|
||||||
import net.minecraft.server.v1_6_R3.WatchableObject;
|
|
||||||
import net.minecraft.server.v1_6_R3.World;
|
|
||||||
import net.minecraft.server.v1_6_R3.WorldServer;
|
|
||||||
|
|
||||||
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.CraftEntity;
|
|
||||||
import org.bukkit.craftbukkit.v1_6_R3.entity.CraftLivingEntity;
|
|
||||||
import org.bukkit.craftbukkit.v1_6_R3.entity.CraftPlayer;
|
|
||||||
import org.bukkit.craftbukkit.v1_6_R3.inventory.CraftItemStack;
|
|
||||||
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;
|
||||||
import org.bukkit.entity.Item;
|
import org.bukkit.entity.Item;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
@ -167,7 +138,7 @@ public class PacketsManager {
|
|||||||
StructureModifier<Object> mods = packet.getModifier();
|
StructureModifier<Object> mods = packet.getModifier();
|
||||||
mods.write(0, disguisedEntity.getEntityId());
|
mods.write(0, disguisedEntity.getEntityId());
|
||||||
mods.write(1, i);
|
mods.write(1, i);
|
||||||
mods.write(2, CraftItemStack.asNMSCopy(itemstack));
|
mods.write(2, ReflectionManager.getNmsItem(itemstack));
|
||||||
packets.add(packet);
|
packets.add(packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -179,7 +150,6 @@ public class PacketsManager {
|
|||||||
Location loc = disguisedEntity.getLocation().clone().add(0, getYModifier(disguisedEntity, disguise.getType()), 0);
|
Location loc = disguisedEntity.getLocation().clone().add(0, getYModifier(disguisedEntity, disguise.getType()), 0);
|
||||||
byte yaw = getYaw(disguise.getType(), DisguiseType.getType(disguise.getEntity().getType()),
|
byte yaw = getYaw(disguise.getType(), DisguiseType.getType(disguise.getEntity().getType()),
|
||||||
(byte) (int) (loc.getYaw() * 256.0F / 360.0F));
|
(byte) (int) (loc.getYaw() * 256.0F / 360.0F));
|
||||||
EnumEntitySize entitySize = Values.getValues(disguise.getType()).getEntitySize();
|
|
||||||
|
|
||||||
if (disguise.getType() == DisguiseType.EXPERIENCE_ORB) {
|
if (disguise.getType() == DisguiseType.EXPERIENCE_ORB) {
|
||||||
|
|
||||||
@ -220,22 +190,24 @@ public class PacketsManager {
|
|||||||
StructureModifier<Object> mods = spawnPackets[0].getModifier();
|
StructureModifier<Object> mods = spawnPackets[0].getModifier();
|
||||||
mods.write(0, disguisedEntity.getEntityId());
|
mods.write(0, disguisedEntity.getEntityId());
|
||||||
mods.write(1, ((PlayerDisguise) disguise).getName());
|
mods.write(1, ((PlayerDisguise) disguise).getName());
|
||||||
mods.write(2, (int) Math.floor(loc.getX() * 32));
|
mods.write(2, ((PlayerDisguise) disguise).getName());
|
||||||
mods.write(3, (int) Math.floor(loc.getY() * 32));
|
mods.write(3, (int) Math.floor(loc.getX() * 32));
|
||||||
mods.write(4, (int) Math.floor(loc.getZ() * 32));
|
mods.write(4, (int) Math.floor(loc.getY() * 32));
|
||||||
mods.write(5, yaw);
|
mods.write(5, (int) Math.floor(loc.getZ() * 32));
|
||||||
mods.write(6, (byte) (int) (loc.getPitch() * 256F / 360F));
|
mods.write(6, yaw);
|
||||||
|
mods.write(7, (byte) (int) (loc.getPitch() * 256F / 360F));
|
||||||
ItemStack item = null;
|
ItemStack item = null;
|
||||||
if (disguisedEntity instanceof Player && ((Player) disguisedEntity).getItemInHand() != null) {
|
if (disguisedEntity instanceof Player && ((Player) disguisedEntity).getItemInHand() != null) {
|
||||||
item = CraftItemStack.asNMSCopy(((Player) disguisedEntity).getItemInHand());
|
item = ((Player) disguisedEntity).getItemInHand();
|
||||||
} else if (disguisedEntity instanceof LivingEntity) {
|
} else if (disguisedEntity instanceof LivingEntity) {
|
||||||
item = CraftItemStack.asNMSCopy(((CraftLivingEntity) disguisedEntity).getEquipment().getItemInHand());
|
item = ((LivingEntity) disguisedEntity).getEquipment().getItemInHand();
|
||||||
}
|
}
|
||||||
mods.write(7, (item == null ? 0 : item.id));
|
mods.write(8, (item == null || item.getType() == Material.AIR ? 0 : item.getTypeId());
|
||||||
mods.write(8, createDataWatcher(nmsEntity.getDataWatcher(), disguise.getWatcher()));
|
mods.write(9, createDataWatcher(nmsEntity.getDataWatcher(), disguise.getWatcher()));
|
||||||
|
|
||||||
} else if (disguise.getType().isMob()) {
|
} else if (disguise.getType().isMob()) {
|
||||||
|
|
||||||
|
Values values = Values.getValues(disguise.getType());
|
||||||
Vector vec = disguisedEntity.getVelocity();
|
Vector vec = disguisedEntity.getVelocity();
|
||||||
spawnPackets[0] = new PacketContainer(Packets.Server.MOB_SPAWN);
|
spawnPackets[0] = new PacketContainer(Packets.Server.MOB_SPAWN);
|
||||||
StructureModifier<Object> mods = spawnPackets[0].getModifier();
|
StructureModifier<Object> mods = spawnPackets[0].getModifier();
|
||||||
@ -257,9 +229,9 @@ public class PacketsManager {
|
|||||||
d3 = d1;
|
d3 = d1;
|
||||||
if (d4 > d1)
|
if (d4 > d1)
|
||||||
d4 = d1;
|
d4 = d1;
|
||||||
mods.write(2, entitySize.a(loc.getX()));
|
mods.write(2, values.getEntitySize(loc.getX()));
|
||||||
mods.write(3, (int) Math.floor(loc.getY() * 32D));
|
mods.write(3, (int) Math.floor(loc.getY() * 32D));
|
||||||
mods.write(4, entitySize.a(loc.getZ()));
|
mods.write(4, values.getEntitySize(loc.getZ()));
|
||||||
mods.write(5, (int) (d2 * 8000.0D));
|
mods.write(5, (int) (d2 * 8000.0D));
|
||||||
mods.write(6, (int) (d3 * 8000.0D));
|
mods.write(6, (int) (d3 * 8000.0D));
|
||||||
mods.write(7, (int) (d4 * 8000.0D));
|
mods.write(7, (int) (d4 * 8000.0D));
|
||||||
@ -318,7 +290,7 @@ public class PacketsManager {
|
|||||||
mods.write(5, (int) (d2 * 8000.0D));
|
mods.write(5, (int) (d2 * 8000.0D));
|
||||||
mods.write(6, (int) (d3 * 8000.0D));
|
mods.write(6, (int) (d3 * 8000.0D));
|
||||||
}
|
}
|
||||||
mods.write(7, (int) MathHelper.floor(loc.getPitch() * 256.0F / 360.0F));
|
mods.write(7, (int) Math.floor(loc.getPitch() * 256.0F / 360.0F));
|
||||||
mods.write(8, yaw);
|
mods.write(8, yaw);
|
||||||
mods.write(9, id);
|
mods.write(9, id);
|
||||||
mods.write(10, data);
|
mods.write(10, data);
|
||||||
@ -552,7 +524,7 @@ public class PacketsManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (event.getPacketID() == Packets.Server.ENTITY_STATUS) {
|
} else if (event.getPacketID() == Packets.Server.ENTITY_STATUS) {
|
||||||
if ((Byte) mods.read(1) == 2) {
|
if ((Byte) mods.read(1) == 1) {
|
||||||
// It made a damage animation
|
// It made a damage animation
|
||||||
Entity entity = event.getPacket().getEntityModifier(observer.getWorld()).read(0);
|
Entity entity = event.getPacket().getEntityModifier(observer.getWorld()).read(0);
|
||||||
Disguise disguise = DisguiseAPI.getDisguise(entity);
|
Disguise disguise = DisguiseAPI.getDisguise(entity);
|
||||||
@ -616,7 +588,7 @@ public class PacketsManager {
|
|||||||
Packets.Server.REL_ENTITY_MOVE_LOOK, Packets.Server.ENTITY_LOOK, Packets.Server.ENTITY_TELEPORT,
|
Packets.Server.REL_ENTITY_MOVE_LOOK, Packets.Server.ENTITY_LOOK, Packets.Server.ENTITY_TELEPORT,
|
||||||
Packets.Server.ENTITY_HEAD_ROTATION, Packets.Server.ENTITY_METADATA, Packets.Server.ENTITY_EQUIPMENT,
|
Packets.Server.ENTITY_HEAD_ROTATION, Packets.Server.ENTITY_METADATA, Packets.Server.ENTITY_EQUIPMENT,
|
||||||
Packets.Server.ARM_ANIMATION, Packets.Server.ENTITY_LOCATION_ACTION, Packets.Server.MOB_EFFECT,
|
Packets.Server.ARM_ANIMATION, Packets.Server.ENTITY_LOCATION_ACTION, Packets.Server.MOB_EFFECT,
|
||||||
Packets.Server.ENTITY_STATUS, Packets.Server.ENTITY_VELOCITY, Packets.Server.UPDATE_ATTRIBUTES) {
|
/* Packets.Server.ENTITY_STATUS, */Packets.Server.ENTITY_VELOCITY, Packets.Server.UPDATE_ATTRIBUTES) {
|
||||||
@Override
|
@Override
|
||||||
public void onPacketSending(PacketEvent event) {
|
public void onPacketSending(PacketEvent event) {
|
||||||
StructureModifier<Entity> entityModifer = event.getPacket().getEntityModifier(event.getPlayer().getWorld());
|
StructureModifier<Entity> entityModifer = event.getPacket().getEntityModifier(event.getPlayer().getWorld());
|
||||||
@ -681,12 +653,12 @@ public class PacketsManager {
|
|||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Server.ENTITY_STATUS:
|
/* case Packets.Server.ENTITY_STATUS:
|
||||||
if (DisguiseAPI.getDisguise(entity).canHearSelfDisguise()
|
if (DisguiseAPI.getDisguise(entity).canHearSelfDisguise()
|
||||||
&& (Byte) event.getPacket().getModifier().read(1) == 2) {
|
&& (Byte) event.getPacket().getModifier().read(1) == 1) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
break;
|
break;*/
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -726,7 +698,7 @@ public class PacketsManager {
|
|||||||
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, CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(0)));
|
.write(2, ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(0)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Else if its a hotbar slot
|
// Else if its a hotbar slot
|
||||||
@ -739,7 +711,7 @@ public class PacketsManager {
|
|||||||
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, CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(0)));
|
.write(2, ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(0)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -760,7 +732,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] = CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(0));
|
items[slot] = ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Else if its a hotbar slot
|
// Else if its a hotbar slot
|
||||||
@ -771,7 +743,7 @@ 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] = CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(0));
|
items[slot] = ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -808,7 +780,7 @@ public class PacketsManager {
|
|||||||
StructureModifier<Object> mods = packet.getModifier();
|
StructureModifier<Object> mods = packet.getModifier();
|
||||||
mods.write(0, 0);
|
mods.write(0, 0);
|
||||||
mods.write(1, slot);
|
mods.write(1, slot);
|
||||||
mods.write(2, CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(0)));
|
mods.write(2, ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(0)));
|
||||||
try {
|
try {
|
||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet,
|
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet,
|
||||||
false);
|
false);
|
||||||
@ -827,7 +799,7 @@ public class PacketsManager {
|
|||||||
StructureModifier<Object> mods = packet.getModifier();
|
StructureModifier<Object> mods = packet.getModifier();
|
||||||
mods.write(0, 0);
|
mods.write(0, 0);
|
||||||
mods.write(1, slot);
|
mods.write(1, slot);
|
||||||
mods.write(2, CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(0)));
|
mods.write(2, ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(0)));
|
||||||
try {
|
try {
|
||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet,
|
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet,
|
||||||
false);
|
false);
|
||||||
@ -854,7 +826,7 @@ public class PacketsManager {
|
|||||||
StructureModifier<Object> mods = packet.getModifier();
|
StructureModifier<Object> mods = packet.getModifier();
|
||||||
mods.write(0, 0);
|
mods.write(0, 0);
|
||||||
mods.write(1, event.getPlayer().getInventory().getHeldItemSlot() + 36);
|
mods.write(1, event.getPlayer().getInventory().getHeldItemSlot() + 36);
|
||||||
mods.write(2, CraftItemStack.asNMSCopy(currentlyHeld));
|
mods.write(2, ReflectionManager.getNmsItem(currentlyHeld));
|
||||||
try {
|
try {
|
||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false);
|
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false);
|
||||||
} catch (InvocationTargetException e) {
|
} catch (InvocationTargetException e) {
|
||||||
@ -869,7 +841,7 @@ public class PacketsManager {
|
|||||||
StructureModifier<Object> mods = packet.getModifier();
|
StructureModifier<Object> mods = packet.getModifier();
|
||||||
mods.write(0, 0);
|
mods.write(0, 0);
|
||||||
mods.write(1, event.getPacket().getIntegers().read(0) + 36);
|
mods.write(1, event.getPacket().getIntegers().read(0) + 36);
|
||||||
mods.write(2, CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(0)));
|
mods.write(2, ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(0)));
|
||||||
try {
|
try {
|
||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false);
|
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false);
|
||||||
} catch (InvocationTargetException e) {
|
} catch (InvocationTargetException e) {
|
||||||
@ -912,7 +884,7 @@ public class PacketsManager {
|
|||||||
StructureModifier<Object> mods = packet.getModifier();
|
StructureModifier<Object> mods = packet.getModifier();
|
||||||
mods.write(0, 0);
|
mods.write(0, 0);
|
||||||
mods.write(1, slot);
|
mods.write(1, slot);
|
||||||
mods.write(2, CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(0)));
|
mods.write(2, ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(0)));
|
||||||
try {
|
try {
|
||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet,
|
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet,
|
||||||
false);
|
false);
|
||||||
@ -930,7 +902,7 @@ public class PacketsManager {
|
|||||||
StructureModifier<Object> mods = packet.getModifier();
|
StructureModifier<Object> mods = packet.getModifier();
|
||||||
mods.write(0, 0);
|
mods.write(0, 0);
|
||||||
mods.write(1, slot);
|
mods.write(1, slot);
|
||||||
mods.write(2, CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(0)));
|
mods.write(2, ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(0)));
|
||||||
try {
|
try {
|
||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet,
|
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet,
|
||||||
false);
|
false);
|
||||||
@ -1238,7 +1210,7 @@ public class PacketsManager {
|
|||||||
if (itemstack != null) {
|
if (itemstack != null) {
|
||||||
packets[0] = packets[0].shallowClone();
|
packets[0] = packets[0].shallowClone();
|
||||||
packets[0].getModifier().write(2,
|
packets[0].getModifier().write(2,
|
||||||
(itemstack.getTypeId() == 0 ? null : CraftItemStack.asNMSCopy(itemstack)));
|
(itemstack.getTypeId() == 0 ? null : ReflectionManager.getNmsItem(itemstack)));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
86
src/me/libraryaddict/disguise/ReflectionManager.java
Normal file
86
src/me/libraryaddict/disguise/ReflectionManager.java
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
package me.libraryaddict.disguise;
|
||||||
|
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
|
import net.minecraft.server.v1_6_R3.World;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.v1_6_R3.inventory.CraftItemStack;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
public class ReflectionManager {
|
||||||
|
private static String bukkitVersion = Bukkit.getServer().getClass().getName().split("\\.")[3];
|
||||||
|
private static Class itemClass;
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
itemClass = Class.forName("org.bukkit.craftbukkit." + bukkitVersion + ".inventory.CraftItemStack");
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Object getEntityInstance(String entityName) {
|
||||||
|
try {
|
||||||
|
Class entityClass = getNmsClass("Entity" + entityName);
|
||||||
|
Object entityObject;
|
||||||
|
Object world = getWorld();
|
||||||
|
if (entityName.equals("Human")) {
|
||||||
|
entityObject = entityClass.getConstructor(world.getClass(), String.class).newInstance(world, "LibsDisguises");
|
||||||
|
} else {
|
||||||
|
entityObject = entityClass.getConstructor(world.getClass()).newInstance(world);
|
||||||
|
}
|
||||||
|
return entityObject;
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Class getNmsClass(String className) {
|
||||||
|
try {
|
||||||
|
return Class.forName("net.minecraft.server." + bukkitVersion + "." + className);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Float getSoundModifier(Object entity) {
|
||||||
|
try {
|
||||||
|
Method soundStrength = getNmsClass("EntityLiving").getDeclaredMethod("ba");
|
||||||
|
// TODO Update this each update!
|
||||||
|
soundStrength.setAccessible(true);
|
||||||
|
return (Float) soundStrength.invoke(entity);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Object getWorld() {
|
||||||
|
try {
|
||||||
|
return World.class.getMethod("getHandle").invoke(Bukkit.getWorlds().get(0));
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Object getNmsItem(ItemStack itemstack) {
|
||||||
|
try {
|
||||||
|
return itemClass.getMethod("asNMSCopy", getNmsClass("ItemStack")).invoke(null, itemstack);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ItemStack getBukkitItem(Object nmsItem) {
|
||||||
|
try {
|
||||||
|
return (ItemStack) itemClass.getMethod("asBukkitCopy", ItemStack.class).invoke(null, nmsItem);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -20,6 +20,7 @@ import com.comphenix.protocol.reflect.StructureModifier;
|
|||||||
|
|
||||||
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 net.minecraft.server.v1_6_R3.ChunkCoordinates;
|
import net.minecraft.server.v1_6_R3.ChunkCoordinates;
|
||||||
import net.minecraft.server.v1_6_R3.EntityPlayer;
|
import net.minecraft.server.v1_6_R3.EntityPlayer;
|
||||||
import net.minecraft.server.v1_6_R3.ItemStack;
|
import net.minecraft.server.v1_6_R3.ItemStack;
|
||||||
@ -278,7 +279,7 @@ public class FlagWatcher {
|
|||||||
|
|
||||||
ItemStack itemToSend = null;
|
ItemStack itemToSend = null;
|
||||||
if (itemStack != null && itemStack.getTypeId() != 0)
|
if (itemStack != null && itemStack.getTypeId() != 0)
|
||||||
itemToSend = CraftItemStack.asNMSCopy(itemStack);
|
itemToSend = ReflectionManager.getNmsItem(itemStack);
|
||||||
items[slot] = itemStack;
|
items[slot] = itemStack;
|
||||||
if (DisguiseAPI.getDisguise(disguise.getEntity()) != disguise)
|
if (DisguiseAPI.getDisguise(disguise.getEntity()) != disguise)
|
||||||
return;
|
return;
|
||||||
|
@ -50,11 +50,11 @@ public class Values {
|
|||||||
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 EnumEntitySize enumEntitySize;
|
private int enumEntitySize;
|
||||||
|
|
||||||
private HashMap<Integer, Object> metaValues = new HashMap<Integer, Object>();
|
private HashMap<Integer, Object> metaValues = new HashMap<Integer, Object>();
|
||||||
|
|
||||||
public Values(DisguiseType type, Class classType, EnumEntitySize entitySize) {
|
public Values(DisguiseType type, Class classType, int entitySize) {
|
||||||
values.put(type, this);
|
values.put(type, this);
|
||||||
enumEntitySize = entitySize;
|
enumEntitySize = entitySize;
|
||||||
declared = classType;
|
declared = classType;
|
||||||
@ -68,8 +68,47 @@ public class Values {
|
|||||||
return declared;
|
return declared;
|
||||||
}
|
}
|
||||||
|
|
||||||
public EnumEntitySize getEntitySize() {
|
public int getEntitySize(double paramDouble) {
|
||||||
return enumEntitySize;
|
double d = paramDouble - (((int) Math.floor(paramDouble)) + 0.5D);
|
||||||
|
|
||||||
|
switch (enumEntitySize) {
|
||||||
|
case 1:
|
||||||
|
if (d < 0.0D ? d < -0.3125D : d < 0.3125D) {
|
||||||
|
return (int) Math.ceil(paramDouble * 32.0D);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (int) Math.floor(paramDouble * 32.0D);
|
||||||
|
case 2:
|
||||||
|
if (d < 0.0D ? d < -0.3125D : d < 0.3125D) {
|
||||||
|
return (int) Math.floor(paramDouble * 32.0D);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (int) Math.ceil(paramDouble * 32.0D);
|
||||||
|
case 3:
|
||||||
|
if (d > 0.0D) {
|
||||||
|
return (int) Math.floor(paramDouble * 32.0D);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (int) Math.ceil(paramDouble * 32.0D);
|
||||||
|
case 4:
|
||||||
|
if (d < 0.0D ? d < -0.1875D : d < 0.1875D) {
|
||||||
|
return (int) Math.ceil(paramDouble * 32.0D);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (int) Math.floor(paramDouble * 32.0D);
|
||||||
|
case 5:
|
||||||
|
if (d < 0.0D ? d < -0.1875D : d < 0.1875D) {
|
||||||
|
return (int) Math.floor(paramDouble * 32.0D);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (int) Math.ceil(paramDouble * 32.0D);
|
||||||
|
case 6:
|
||||||
|
}
|
||||||
|
if (d > 0.0D) {
|
||||||
|
return (int) Math.ceil(paramDouble * 32.0D);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (int) Math.floor(paramDouble * 32.0D);
|
||||||
}
|
}
|
||||||
|
|
||||||
public HashMap<Integer, Object> getMetaValues() {
|
public HashMap<Integer, Object> getMetaValues() {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
@ -14,11 +15,11 @@ public class DroppedItemWatcher extends FlagWatcher {
|
|||||||
|
|
||||||
public ItemStack getItemStack() {
|
public ItemStack getItemStack() {
|
||||||
return CraftItemStack.asBukkitCopy((net.minecraft.server.v1_6_R3.ItemStack) getValue(10,
|
return CraftItemStack.asBukkitCopy((net.minecraft.server.v1_6_R3.ItemStack) getValue(10,
|
||||||
CraftItemStack.asNMSCopy(new ItemStack(1))));
|
ReflectionManager.getNmsItem(new ItemStack(1))));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setItemStack(ItemStack item) {
|
public void setItemStack(ItemStack item) {
|
||||||
setValue(10, CraftItemStack.asNMSCopy(item));
|
setValue(10, ReflectionManager.getNmsItem(item));
|
||||||
sendData(10);
|
sendData(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
@ -30,7 +31,7 @@ public class ItemFrameWatcher extends FlagWatcher {
|
|||||||
public void setItemStack(ItemStack newItem) {
|
public void setItemStack(ItemStack newItem) {
|
||||||
newItem = newItem.clone();
|
newItem = newItem.clone();
|
||||||
newItem.setAmount(1);
|
newItem.setAmount(1);
|
||||||
setValue(2, CraftItemStack.asNMSCopy(newItem));
|
setValue(2, ReflectionManager.getNmsItem(newItem));
|
||||||
sendData(2);
|
sendData(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user