Finish converting it all to reflection. Removed cb dependency ;D
This commit is contained in:
parent
85f4bfbdc7
commit
33460a6fb7
5
pom.xml
5
pom.xml
@ -58,11 +58,6 @@
|
|||||||
<artifactId>ProtocolLib</artifactId>
|
<artifactId>ProtocolLib</artifactId>
|
||||||
<version>2.7.0</version>
|
<version>2.7.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.bukkit</groupId>
|
|
||||||
<artifactId>craftbukkit</artifactId>
|
|
||||||
<version>1.6.4-R2.1-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<version>7.7.0-SNAPSHOT</version>
|
<version>7.7.0-SNAPSHOT</version>
|
||||||
|
|
||||||
|
@ -1,17 +1,15 @@
|
|||||||
package me.libraryaddict.disguise;
|
package me.libraryaddict.disguise;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||||
import me.libraryaddict.disguise.events.DisguiseEvent;
|
import me.libraryaddict.disguise.events.DisguiseEvent;
|
||||||
import me.libraryaddict.disguise.events.UndisguiseEvent;
|
import me.libraryaddict.disguise.events.UndisguiseEvent;
|
||||||
import net.minecraft.server.v1_6_R3.EntityPlayer;
|
|
||||||
import net.minecraft.server.v1_6_R3.EntityTrackerEntry;
|
|
||||||
import net.minecraft.server.v1_6_R3.WorldServer;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.craftbukkit.v1_6_R3.entity.CraftEntity;
|
|
||||||
import org.bukkit.craftbukkit.v1_6_R3.entity.CraftPlayer;
|
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@ -19,6 +17,7 @@ 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.WrappedDataWatcher;
|
||||||
|
|
||||||
public class DisguiseAPI {
|
public class DisguiseAPI {
|
||||||
|
|
||||||
@ -166,16 +165,28 @@ public class DisguiseAPI {
|
|||||||
* the entity to all the watching players, which is where the magic begins
|
* the entity to all the watching players, which is where the magic begins
|
||||||
*/
|
*/
|
||||||
private static void refreshTrackers(Entity entity) {
|
private static void refreshTrackers(Entity entity) {
|
||||||
EntityTrackerEntry entry = (EntityTrackerEntry) ((WorldServer) ((CraftEntity) entity).getHandle().world).tracker.trackedEntities
|
try {
|
||||||
.get(entity.getEntityId());
|
Object world = ReflectionManager.getWorld(entity.getWorld());
|
||||||
if (entry != null) {
|
Object tracker = world.getClass().getField("tracker").get(world);
|
||||||
EntityPlayer[] players = (EntityPlayer[]) entry.trackedPlayers.toArray(new EntityPlayer[entry.trackedPlayers.size()]);
|
Object trackedEntities = tracker.getClass().getField("trackedEntities").get(tracker);
|
||||||
for (EntityPlayer player : players) {
|
Object entityTrackerEntry = trackedEntities.getClass().getMethod("get", int.class)
|
||||||
if (entity instanceof Player && !player.getBukkitEntity().canSee((Player) entity))
|
.invoke(trackedEntities, entity.getEntityId());
|
||||||
continue;
|
if (entityTrackerEntry != null) {
|
||||||
entry.clear(player);
|
HashSet trackedPlayers = (HashSet) entityTrackerEntry.getClass().getField("trackedPlayers")
|
||||||
entry.updatePlayer(player);
|
.get(entityTrackerEntry);
|
||||||
|
Method getBukkitEntity = ReflectionManager.getNmsClass("Entity").getMethod("getBukkitEntity");
|
||||||
|
Method clear = entityTrackerEntry.getClass().getMethod("clear", ReflectionManager.getNmsClass("EntityPlayer"));
|
||||||
|
Method updatePlayer = entityTrackerEntry.getClass().getMethod("updatePlayer",
|
||||||
|
ReflectionManager.getNmsClass("EntityPlayer"));
|
||||||
|
for (Object player : trackedPlayers) {
|
||||||
|
if (entity instanceof Player && !((Player) getBukkitEntity.invoke(player)).canSee((Player) entity))
|
||||||
|
continue;
|
||||||
|
clear.invoke(entityTrackerEntry, player);
|
||||||
|
updatePlayer.invoke(entityTrackerEntry, player);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,18 +203,26 @@ public class DisguiseAPI {
|
|||||||
// Remove the fake entity ID from the disguise bin
|
// Remove the fake entity ID from the disguise bin
|
||||||
selfDisguisesIds.remove(player.getEntityId());
|
selfDisguisesIds.remove(player.getEntityId());
|
||||||
// Get the entity tracker
|
// Get the entity tracker
|
||||||
EntityPlayer entityplayer = ((CraftPlayer) player).getHandle();
|
try {
|
||||||
EntityTrackerEntry tracker = (EntityTrackerEntry) ((WorldServer) entityplayer.world).tracker.trackedEntities
|
Object world = ReflectionManager.getWorld(player.getWorld());
|
||||||
.get(player.getEntityId());
|
Object tracker = world.getClass().getField("tracker").get(world);
|
||||||
// If the tracker exists. Remove himself from his tracker
|
Object trackedEntities = tracker.getClass().getField("trackedEntities").get(tracker);
|
||||||
if (tracker != null) {
|
Object entityTrackerEntry = trackedEntities.getClass().getMethod("get", int.class)
|
||||||
tracker.trackedPlayers.remove(entityplayer);
|
.invoke(trackedEntities, player.getEntityId());
|
||||||
}
|
if (entityTrackerEntry != null) {
|
||||||
// Resend entity metadata else he will be invisible to himself until its resent
|
HashSet trackedPlayers = (HashSet) entityTrackerEntry.getClass().getField("trackedPlayers")
|
||||||
|
.get(entityTrackerEntry);
|
||||||
|
// If the tracker exists. Remove himself from his tracker
|
||||||
|
trackedPlayers.remove(ReflectionManager.getNmsEntity(player));
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}// Resend entity metadata else he will be invisible to himself until its resent
|
||||||
PacketContainer packetMetadata = new PacketContainer(Packets.Server.ENTITY_METADATA);
|
PacketContainer packetMetadata = new PacketContainer(Packets.Server.ENTITY_METADATA);
|
||||||
StructureModifier<Object> mods = packetMetadata.getModifier();
|
StructureModifier<Object> mods = packetMetadata.getModifier();
|
||||||
mods.write(0, player.getEntityId());
|
mods.write(0, player.getEntityId());
|
||||||
mods.write(1, entityplayer.getDataWatcher().c());
|
packetMetadata.getWatchableCollectionModifier().write(0,
|
||||||
|
WrappedDataWatcher.getEntityWatcher(player).getWatchableObjects());
|
||||||
try {
|
try {
|
||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packetMetadata);
|
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packetMetadata);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
@ -3,7 +3,7 @@ package me.libraryaddict.disguise;
|
|||||||
import java.lang.reflect.Field;
|
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.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
@ -17,41 +17,22 @@ 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.Block;
|
|
||||||
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.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.World;
|
|
||||||
import net.minecraft.server.v1_6_R3.WorldServer;
|
|
||||||
|
|
||||||
import org.bukkit.Art;
|
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.CraftEntity;
|
import org.bukkit.entity.Ageable;
|
||||||
import org.bukkit.craftbukkit.v1_6_R3.entity.CraftLivingEntity;
|
|
||||||
import org.bukkit.craftbukkit.v1_6_R3.entity.CraftPlayer;
|
|
||||||
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.entity.Zombie;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.bukkit.potion.PotionEffect;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
import com.comphenix.protocol.Packets;
|
import com.comphenix.protocol.Packets;
|
||||||
@ -146,7 +127,7 @@ public class PacketsManager {
|
|||||||
public static PacketContainer[] constructSpawnPackets(Disguise disguise, Entity disguisedEntity) {
|
public static PacketContainer[] constructSpawnPackets(Disguise disguise, Entity disguisedEntity) {
|
||||||
if (disguise.getEntity() == null)
|
if (disguise.getEntity() == null)
|
||||||
disguise.setEntity(disguisedEntity);
|
disguise.setEntity(disguisedEntity);
|
||||||
net.minecraft.server.v1_6_R3.Entity nmsEntity = ((CraftEntity) disguisedEntity).getHandle();
|
// net.minecraft.server.v1_6_R3.Entity nmsEntity = ((CraftEntity) disguisedEntity).getHandle();
|
||||||
ArrayList<PacketContainer> packets = new ArrayList<PacketContainer>();
|
ArrayList<PacketContainer> packets = new ArrayList<PacketContainer>();
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
int slot = i - 1;
|
int slot = i - 1;
|
||||||
@ -265,8 +246,8 @@ public class PacketsManager {
|
|||||||
mods.write(7, (int) (d4 * 8000.0D));
|
mods.write(7, (int) (d4 * 8000.0D));
|
||||||
mods.write(8, yaw);
|
mods.write(8, yaw);
|
||||||
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));
|
||||||
spawnPackets[0].getDataWatcherModifier().write(0,
|
spawnPackets[0].getDataWatcherModifier().write(0,
|
||||||
createDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity), disguise.getWatcher()));
|
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!
|
||||||
@ -461,13 +442,18 @@ public class PacketsManager {
|
|||||||
soundType = SoundType.DEATH;
|
soundType = SoundType.DEATH;
|
||||||
} else {
|
} else {
|
||||||
boolean hasInvun = false;
|
boolean hasInvun = false;
|
||||||
if (entity instanceof LivingEntity) {
|
Object nmsEntity = ReflectionManager.getNmsEntity(entity);
|
||||||
net.minecraft.server.v1_6_R3.EntityLiving e = ((CraftLivingEntity) entity)
|
try {
|
||||||
.getHandle();
|
if (entity instanceof LivingEntity) {
|
||||||
hasInvun = (e.noDamageTicks == e.maxNoDamageTicks);
|
Class entityClass = ReflectionManager.getNmsClass("Entity");
|
||||||
} else {
|
hasInvun = entityClass.getField("noDamageTicks").getInt(nmsEntity) == entityClass
|
||||||
net.minecraft.server.v1_6_R3.Entity e = ((CraftEntity) entity).getHandle();
|
.getField("maxNoDamageTicks").getInt(nmsEntity);
|
||||||
hasInvun = e.isInvulnerable();
|
} else {
|
||||||
|
hasInvun = (Boolean) ReflectionManager.getNmsClass("Entity")
|
||||||
|
.getMethod("isInvulnerable").invoke(nmsEntity);
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
soundType = entitySound.getType(soundName, !hasInvun);
|
soundType = entitySound.getType(soundName, !hasInvun);
|
||||||
}
|
}
|
||||||
@ -491,11 +477,18 @@ public class PacketsManager {
|
|||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
} else {
|
} else {
|
||||||
if (sound.equals("step.grass")) {
|
if (sound.equals("step.grass")) {
|
||||||
World world = ((CraftEntity) disguisedEntity).getHandle().world;
|
try {
|
||||||
Block b = Block.byId[world.getTypeId(soundLoc.getBlockX(), soundLoc.getBlockY() - 1,
|
int typeId = soundLoc.getWorld().getBlockTypeIdAt(soundLoc.getBlockX(),
|
||||||
soundLoc.getBlockZ())];
|
soundLoc.getBlockY() - 1, soundLoc.getBlockZ());
|
||||||
if (b != null)
|
Class blockClass = ReflectionManager.getNmsClass("Block");
|
||||||
mods.write(0, b.stepSound.getStepSound());
|
Object block = ((Object[]) blockClass.getField("byId").get(null))[typeId];
|
||||||
|
if (block != null) {
|
||||||
|
Object step = blockClass.getField("stepSound").get(block);
|
||||||
|
mods.write(0, step.getClass().getMethod("getStepSound").invoke(step));
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
// There is no else statement. Because seriously. This should never be null. Unless
|
// There is no else statement. Because seriously. This should never be null. Unless
|
||||||
// someone is
|
// someone is
|
||||||
// sending fake sounds. In which case. Why cancel it.
|
// sending fake sounds. In which case. Why cancel it.
|
||||||
@ -512,7 +505,12 @@ public class PacketsManager {
|
|||||||
// Here I assume its the default pitch as I can't calculate if its real.
|
// Here I assume its the default pitch as I can't calculate if its real.
|
||||||
if (disguise instanceof MobDisguise && disguisedEntity instanceof LivingEntity
|
if (disguise instanceof MobDisguise && disguisedEntity instanceof LivingEntity
|
||||||
&& ((MobDisguise) disguise).doesDisguiseAge()) {
|
&& ((MobDisguise) disguise).doesDisguiseAge()) {
|
||||||
boolean baby = ((CraftLivingEntity) disguisedEntity).getHandle().isBaby();
|
boolean baby = false;
|
||||||
|
if (disguisedEntity instanceof Zombie) {
|
||||||
|
baby = ((Zombie) disguisedEntity).isBaby();
|
||||||
|
} else if (disguisedEntity instanceof Ageable) {
|
||||||
|
baby = !((Ageable) disguisedEntity).isAdult();
|
||||||
|
}
|
||||||
if (((MobDisguise) disguise).isAdult() == baby) {
|
if (((MobDisguise) disguise).isAdult() == baby) {
|
||||||
|
|
||||||
float pitch = (Integer) mods.read(5);
|
float pitch = (Integer) mods.read(5);
|
||||||
@ -969,97 +967,107 @@ public class PacketsManager {
|
|||||||
* Sends the self disguise to the player
|
* Sends the self disguise to the player
|
||||||
*/
|
*/
|
||||||
public static void sendSelfDisguise(final Player player) {
|
public static void sendSelfDisguise(final Player player) {
|
||||||
EntityPlayer entityplayer = ((CraftPlayer) player).getHandle();
|
|
||||||
EntityTrackerEntry tracker = (EntityTrackerEntry) ((WorldServer) entityplayer.world).tracker.trackedEntities.get(player
|
|
||||||
.getEntityId());
|
|
||||||
if (tracker == null) {
|
|
||||||
// A check incase the tracker is null.
|
|
||||||
// If it is, then this method will be run again in one tick. Which is when it should be constructed.
|
|
||||||
// Else its going to run in a infinite loop hue hue hue..
|
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() {
|
|
||||||
public void run() {
|
|
||||||
sendSelfDisguise(player);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Add himself to his own entity tracker
|
|
||||||
tracker.trackedPlayers.add(entityplayer);
|
|
||||||
// Send the player a packet with himself being spawned
|
|
||||||
Packet20NamedEntitySpawn packet = new Packet20NamedEntitySpawn((EntityHuman) entityplayer);
|
|
||||||
entityplayer.playerConnection.sendPacket(packet);
|
|
||||||
if (!tracker.tracker.getDataWatcher().d()) {
|
|
||||||
entityplayer.playerConnection.sendPacket(new Packet40EntityMetadata(player.getEntityId(), tracker.tracker
|
|
||||||
.getDataWatcher(), true));
|
|
||||||
}
|
|
||||||
// Send himself some entity attributes
|
|
||||||
if (tracker.tracker instanceof EntityLiving) {
|
|
||||||
AttributeMapServer attributemapserver = (AttributeMapServer) ((EntityLiving) tracker.tracker).aX();
|
|
||||||
Collection collection = attributemapserver.c();
|
|
||||||
|
|
||||||
if (!collection.isEmpty()) {
|
|
||||||
entityplayer.playerConnection.sendPacket(new Packet44UpdateAttributes(player.getEntityId(), collection));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Why do we even have this?
|
|
||||||
tracker.j = tracker.tracker.motX;
|
|
||||||
tracker.k = tracker.tracker.motY;
|
|
||||||
tracker.l = tracker.tracker.motZ;
|
|
||||||
boolean isMoving = false;
|
|
||||||
try {
|
try {
|
||||||
Field field = EntityTrackerEntry.class.getDeclaredField("isMoving");
|
Object world = ReflectionManager.getWorld(player.getWorld());
|
||||||
field.setAccessible(true);
|
Object tracker = world.getClass().getField("tracker").get(world);
|
||||||
isMoving = field.getBoolean(tracker);
|
Object trackedEntities = tracker.getClass().getField("trackedEntities").get(tracker);
|
||||||
|
Object entityTrackerEntry = trackedEntities.getClass().getMethod("get", int.class)
|
||||||
|
.invoke(trackedEntities, player.getEntityId());
|
||||||
|
if (entityTrackerEntry == null) {
|
||||||
|
// A check incase the tracker is null.
|
||||||
|
// If it is, then this method will be run again in one tick. Which is when it should be constructed.
|
||||||
|
// Else its going to run in a infinite loop hue hue hue..
|
||||||
|
Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
sendSelfDisguise(player);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Add himself to his own entity tracker
|
||||||
|
((HashSet) entityTrackerEntry.getClass().getField("trackedPlayers").get(entityTrackerEntry)).add(ReflectionManager
|
||||||
|
.getNmsEntity(player));
|
||||||
|
ProtocolManager manager = ProtocolLibrary.getProtocolManager();
|
||||||
|
// Send the player a packet with himself being spawned
|
||||||
|
manager.sendServerPacket(player, manager.createPacketConstructor(Packets.Server.NAMED_ENTITY_SPAWN, player)
|
||||||
|
.createPacket(player));
|
||||||
|
manager.sendServerPacket(
|
||||||
|
player,
|
||||||
|
manager.createPacketConstructor(Packets.Server.ENTITY_METADATA, player.getEntityId(),
|
||||||
|
WrappedDataWatcher.getEntityWatcher(player), true).createPacket(player.getEntityId(),
|
||||||
|
WrappedDataWatcher.getEntityWatcher(player), true));
|
||||||
|
|
||||||
|
boolean isMoving = false;
|
||||||
|
try {
|
||||||
|
Field field = ReflectionManager.getNmsClass("EntityTrackerEntry").getDeclaredField("isMoving");
|
||||||
|
field.setAccessible(true);
|
||||||
|
isMoving = field.getBoolean(entityTrackerEntry);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
// Send the velocity packets
|
||||||
|
if (isMoving) {
|
||||||
|
Vector velocity = player.getVelocity();
|
||||||
|
manager.sendServerPacket(
|
||||||
|
player,
|
||||||
|
manager.createPacketConstructor(Packets.Server.ENTITY_VELOCITY, player.getEntityId(), velocity.getX(),
|
||||||
|
velocity.getY(), velocity.getZ()).createPacket(player.getEntityId(), velocity.getX(),
|
||||||
|
velocity.getY(), velocity.getZ()));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Why the hell would he even need this. Meh.
|
||||||
|
if (player.getVehicle() != null && player.getEntityId() > player.getVehicle().getEntityId()) {
|
||||||
|
manager.sendServerPacket(player,
|
||||||
|
manager.createPacketConstructor(Packets.Server.ATTACH_ENTITY, 0, player, player.getVehicle())
|
||||||
|
.createPacket(0, player, player.getVehicle()));
|
||||||
|
} else if (player.getPassenger() != null && player.getEntityId() > player.getPassenger().getEntityId()) {
|
||||||
|
manager.sendServerPacket(player,
|
||||||
|
manager.createPacketConstructor(Packets.Server.ATTACH_ENTITY, 0, player.getPassenger(), player)
|
||||||
|
.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];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (item != null && item.getType() != Material.AIR) {
|
||||||
|
manager.sendServerPacket(player,
|
||||||
|
manager.createPacketConstructor(Packets.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()) {
|
||||||
|
manager.sendServerPacket(
|
||||||
|
player,
|
||||||
|
manager.createPacketConstructor(Packets.Server.ENTITY_LOCATION_ACTION, player, 0, loc.getBlockX(),
|
||||||
|
loc.getBlockY(), loc.getBlockZ()).createPacket(player, 0, loc.getBlockX(), loc.getBlockY(),
|
||||||
|
loc.getBlockZ()));
|
||||||
|
}
|
||||||
|
|
||||||
|
manager.sendServerPacket(
|
||||||
|
player,
|
||||||
|
manager.createPacketConstructor(Packets.Server.ENTITY_HEAD_ROTATION, player.getEntityId(),
|
||||||
|
(byte) Math.floor(loc.getYaw() * 256.0F / 360.0F)).createPacket(player.getEntityId(),
|
||||||
|
(byte) Math.floor(loc.getYaw() * 256.0F / 360.0F)));
|
||||||
|
|
||||||
|
// Resend any active potion effects
|
||||||
|
Iterator iterator = player.getActivePotionEffects().iterator();
|
||||||
|
while (iterator.hasNext()) {
|
||||||
|
PotionEffect potionEffect = (PotionEffect) iterator.next();
|
||||||
|
manager.sendServerPacket(player,
|
||||||
|
manager.createPacketConstructor(Packets.Server.MOB_EFFECT, player.getEntityId(), potionEffect)
|
||||||
|
.createPacket(player.getEntityId(), potionEffect));
|
||||||
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
// Send the velocity packets
|
|
||||||
if (isMoving) {
|
|
||||||
entityplayer.playerConnection.sendPacket(new Packet28EntityVelocity(player.getEntityId(), tracker.tracker.motX,
|
|
||||||
tracker.tracker.motY, tracker.tracker.motZ));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Why the hell would he even need this. Meh.
|
|
||||||
if (tracker.tracker.vehicle != null && player.getEntityId() > tracker.tracker.vehicle.id) {
|
|
||||||
entityplayer.playerConnection.sendPacket(new Packet39AttachEntity(0, tracker.tracker, tracker.tracker.vehicle));
|
|
||||||
} else if (tracker.tracker.passenger != null && player.getEntityId() > tracker.tracker.passenger.id) {
|
|
||||||
entityplayer.playerConnection.sendPacket(new Packet39AttachEntity(0, tracker.tracker.passenger, tracker.tracker));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tracker.tracker instanceof EntityInsentient && ((EntityInsentient) tracker.tracker).getLeashHolder() != null) {
|
|
||||||
entityplayer.playerConnection.sendPacket(new Packet39AttachEntity(1, tracker.tracker,
|
|
||||||
((EntityInsentient) tracker.tracker).getLeashHolder()));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Resend the armor
|
|
||||||
for (int i = 0; i < 5; ++i) {
|
|
||||||
net.minecraft.server.v1_6_R3.ItemStack itemstack = ((EntityLiving) tracker.tracker).getEquipment(i);
|
|
||||||
|
|
||||||
if (itemstack != null) {
|
|
||||||
entityplayer.playerConnection.sendPacket(new Packet5EntityEquipment(player.getEntityId(), i, itemstack));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// If the disguised is sleeping for w/e reason
|
|
||||||
if (entityplayer.isSleeping()) {
|
|
||||||
entityplayer.playerConnection
|
|
||||||
.sendPacket(new Packet17EntityLocationAction(entityplayer, 0, (int) Math.floor(tracker.tracker.locX),
|
|
||||||
(int) Math.floor(tracker.tracker.locY), (int) Math.floor(tracker.tracker.locZ)));
|
|
||||||
}
|
|
||||||
|
|
||||||
// CraftBukkit start - Fix for nonsensical head yaw
|
|
||||||
tracker.i = (int) Math.floor(tracker.tracker.getHeadRotation() * 256.0F / 360.0F); // tracker.ao() should be
|
|
||||||
// getHeadRotation
|
|
||||||
tracker.broadcast(new Packet35EntityHeadRotation(player.getEntityId(), (byte) tracker.i));
|
|
||||||
// CraftBukkit end
|
|
||||||
|
|
||||||
// Resend any active potion effects
|
|
||||||
Iterator iterator = entityplayer.getEffects().iterator();
|
|
||||||
while (iterator.hasNext()) {
|
|
||||||
MobEffect mobeffect = (MobEffect) iterator.next();
|
|
||||||
|
|
||||||
entityplayer.playerConnection.sendPacket(new Packet41MobEffect(player.getEntityId(), mobeffect));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setHearDisguisesListener(boolean enabled) {
|
public static void setHearDisguisesListener(boolean enabled) {
|
||||||
|
@ -2,18 +2,44 @@ package me.libraryaddict.disguise;
|
|||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
import java.lang.reflect.Modifier;
|
||||||
|
|
||||||
import org.bukkit.Art;
|
import org.bukkit.Art;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
public class ReflectionManager {
|
public class ReflectionManager {
|
||||||
private static String bukkitVersion = Bukkit.getServer().getClass().getName().split("\\.")[3];
|
private static String bukkitVersion = Bukkit.getServer().getClass().getName().split("\\.")[3];
|
||||||
private static Class itemClass;
|
private static Class itemClass;
|
||||||
|
private static Method soundMethod;
|
||||||
static {
|
static {
|
||||||
|
for (Method method : getNmsClass("EntityLiving").getDeclaredMethods()) {
|
||||||
|
try {
|
||||||
|
if (method.getReturnType() == float.class && Modifier.isProtected(method.getModifiers())
|
||||||
|
&& method.getParameterTypes().length == 0) {
|
||||||
|
Object entity = getEntityInstance("Pig");
|
||||||
|
method.setAccessible(true);
|
||||||
|
method.invoke(entity);
|
||||||
|
Field random = getNmsClass("Entity").getDeclaredField("random");
|
||||||
|
random.setAccessible(true);
|
||||||
|
random.set(entity, null);
|
||||||
|
method.setAccessible(true);
|
||||||
|
try {
|
||||||
|
method.invoke(entity);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
soundMethod = method;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
itemClass = Class.forName("org.bukkit.craftbukkit." + bukkitVersion + ".inventory.CraftItemStack");
|
itemClass = getCraftClass("inventory.CraftItemStack");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -34,9 +60,18 @@ public class ReflectionManager {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Object getNmsEntity(Entity entity) {
|
||||||
|
try {
|
||||||
|
return getCraftClass("entity.CraftEntity").getMethod("getHandle").invoke(entity);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public static String getCraftSound(Sound sound) {
|
public static String getCraftSound(Sound sound) {
|
||||||
try {
|
try {
|
||||||
Class c = Class.forName("org.bukkit.craftbukkit." + bukkitVersion + ".CraftSound");
|
Class c = getCraftClass("CraftSound");
|
||||||
return (String) c.getMethod("getSound", Sound.class).invoke(null, sound);
|
return (String) c.getMethod("getSound", Sound.class).invoke(null, sound);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
@ -75,22 +110,32 @@ public class ReflectionManager {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Class getCraftClass(String className) {
|
||||||
|
try {
|
||||||
|
return Class.forName("org.bukkit.craftbukkit." + bukkitVersion + "." + className);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public static Float getSoundModifier(Object entity) {
|
public static Float getSoundModifier(Object entity) {
|
||||||
try {
|
try {
|
||||||
Method soundStrength = getNmsClass("EntityLiving").getDeclaredMethod("ba");
|
|
||||||
// TODO Update this each update!
|
// TODO Update this each update!
|
||||||
soundStrength.setAccessible(true);
|
soundMethod.setAccessible(true);
|
||||||
return (Float) soundStrength.invoke(entity);
|
return (Float) soundMethod.invoke(entity);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Object getWorld() {
|
private static Object getWorld() {
|
||||||
try {
|
return getWorld(Bukkit.getWorlds().get(0));
|
||||||
return Class.forName("org.bukkit.craftbukkit." + bukkitVersion + ".CraftWorld").getMethod("getHandle")
|
}
|
||||||
.invoke(Bukkit.getWorlds().get(0));
|
|
||||||
|
|
||||||
|
public static Object getWorld(World world) {
|
||||||
|
try {
|
||||||
|
return getCraftClass("CraftWorld").getMethod("getHandle").invoke(world);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ 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.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import me.libraryaddict.disguise.DisguiseAPI;
|
import me.libraryaddict.disguise.DisguiseAPI;
|
||||||
import me.libraryaddict.disguise.PacketsManager;
|
import me.libraryaddict.disguise.PacketsManager;
|
||||||
@ -11,14 +12,7 @@ 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.EntityInsentient;
|
|
||||||
import net.minecraft.server.v1_6_R3.EntityLiving;
|
|
||||||
import net.minecraft.server.v1_6_R3.EntityTrackerEntry;
|
|
||||||
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.entity.Entity;
|
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;
|
||||||
@ -182,7 +176,7 @@ public abstract class Disguise {
|
|||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
// If entity is no longer valid. Remove it.
|
// If entity is no longer valid. Remove it.
|
||||||
if (!((CraftEntity) entity).getHandle().valid) {
|
if (!getEntity().isValid()) {
|
||||||
DisguiseAPI.undisguiseToAll(entity);
|
DisguiseAPI.undisguiseToAll(entity);
|
||||||
} else {
|
} else {
|
||||||
// If the disguise type is tnt, we need to resend the entity packet else it will turn invisible
|
// If the disguise type is tnt, we need to resend the entity packet else it will turn invisible
|
||||||
@ -282,11 +276,16 @@ public abstract class Disguise {
|
|||||||
protected ArrayList<Player> getPerverts() {
|
protected ArrayList<Player> getPerverts() {
|
||||||
ArrayList<Player> players = new ArrayList<Player>();
|
ArrayList<Player> players = new ArrayList<Player>();
|
||||||
try {
|
try {
|
||||||
EntityTrackerEntry entry = (EntityTrackerEntry) ((WorldServer) ((CraftEntity) entity).getHandle().world).tracker.trackedEntities
|
Object world = ReflectionManager.getWorld(getEntity().getWorld());
|
||||||
.get(entity.getEntityId());
|
Object tracker = world.getClass().getField("tracker").get(world);
|
||||||
if (entry != null) {
|
Object trackedEntities = tracker.getClass().getField("trackedEntities").get(tracker);
|
||||||
|
Object entityTrackerEntry = trackedEntities.getClass().getMethod("get", int.class)
|
||||||
|
.invoke(trackedEntities, getEntity().getEntityId());
|
||||||
|
if (entityTrackerEntry != null) {
|
||||||
Field field = ReflectionManager.getNmsClass("Entity").getField("getBukkitEntity");
|
Field field = ReflectionManager.getNmsClass("Entity").getField("getBukkitEntity");
|
||||||
for (Object p : entry.trackedPlayers) {
|
HashSet trackedPlayers = (HashSet) entityTrackerEntry.getClass().getField("trackedPlayers")
|
||||||
|
.get(entityTrackerEntry);
|
||||||
|
for (Object p : trackedPlayers) {
|
||||||
players.add((Player) field.get(p));
|
players.add((Player) field.get(p));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -347,7 +346,7 @@ public abstract class Disguise {
|
|||||||
// If this disguise has a entity set
|
// If this disguise has a entity set
|
||||||
if (getEntity() != null) {
|
if (getEntity() != null) {
|
||||||
// If the entity is valid
|
// If the entity is valid
|
||||||
if (((CraftEntity) getEntity()).getHandle().valid) {
|
if (getEntity().isValid()) {
|
||||||
// If this disguise is active
|
// If this disguise is active
|
||||||
if (disguises.containsKey(getEntity().getEntityId()) && disguises.get(getEntity().getEntityId()) == this) {
|
if (disguises.containsKey(getEntity().getEntityId()) && disguises.get(getEntity().getEntityId()) == this) {
|
||||||
// Now remove the disguise from the current disguises.
|
// Now remove the disguise from the current disguises.
|
||||||
@ -483,19 +482,19 @@ public abstract class Disguise {
|
|||||||
case 7:
|
case 7:
|
||||||
case 8:
|
case 8:
|
||||||
case 9:
|
case 9:
|
||||||
baseClass = EntityLiving.class;
|
baseClass = ReflectionManager.getNmsClass("EntityLiving");
|
||||||
break;
|
break;
|
||||||
case 10:
|
case 10:
|
||||||
case 11:
|
case 11:
|
||||||
baseClass = EntityInsentient.class;
|
baseClass = ReflectionManager.getNmsClass("EntityInsentient");
|
||||||
break;
|
break;
|
||||||
case 16:
|
case 16:
|
||||||
baseClass = EntityAgeable.class;
|
baseClass = ReflectionManager.getNmsClass("EntityAgeable");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Class entityClass = ((CraftEntity) entity).getHandle().getClass();
|
Class entityClass = ReflectionManager.getNmsEntity(getEntity()).getClass();
|
||||||
// If they both extend the same base class. They OBVIOUSLY share the same datavalue. Right..?
|
// If they both extend the same base class. They OBVIOUSLY share the same datavalue. Right..?
|
||||||
if (baseClass != null && baseClass.isAssignableFrom(disguiseClass) && baseClass.isAssignableFrom(entityClass))
|
if (baseClass != null && baseClass.isAssignableFrom(disguiseClass) && baseClass.isAssignableFrom(entityClass))
|
||||||
continue;
|
continue;
|
||||||
|
@ -251,7 +251,7 @@ public class FlagWatcher {
|
|||||||
// Find the item to replace it with
|
// Find the item to replace it with
|
||||||
if (disguise.getEntity() instanceof LivingEntity) {
|
if (disguise.getEntity() instanceof LivingEntity) {
|
||||||
EntityEquipment enquipment = ((LivingEntity) disguise.getEntity()).getEquipment();
|
EntityEquipment enquipment = ((LivingEntity) disguise.getEntity()).getEquipment();
|
||||||
if (slot == 4) {
|
if (slot == 0) {
|
||||||
itemStack = enquipment.getItemInHand();
|
itemStack = enquipment.getItemInHand();
|
||||||
} else {
|
} else {
|
||||||
itemStack = enquipment.getArmorContents()[slot];
|
itemStack = enquipment.getArmorContents()[slot];
|
||||||
|
Loading…
Reference in New Issue
Block a user