commit
9c305f09da
9
pom.xml
9
pom.xml
@ -56,15 +56,10 @@
|
||||
<dependency>
|
||||
<groupId>com.comphenix.protocol</groupId>
|
||||
<artifactId>ProtocolLib</artifactId>
|
||||
<version>2.5.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>craftbukkit</artifactId>
|
||||
<version>1.6.4-R2.1-SNAPSHOT</version>
|
||||
<version>2.7.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<version>7.7.0</version>
|
||||
<version>7.7.0-SNAPSHOT</version>
|
||||
|
||||
<distributionManagement>
|
||||
<repository>
|
||||
|
@ -23,6 +23,10 @@ import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
public abstract class BaseDisguiseCommand implements CommandExecutor {
|
||||
protected ArrayList<String> getAllowedDisguises(CommandSender sender) {
|
||||
String permissionNode = "libsdisguises." + getClass().getSimpleName().replace("Command", "").toLowerCase() + ".";
|
||||
return getAllowedDisguises(sender, permissionNode);
|
||||
}
|
||||
|
||||
protected ArrayList<String> getAllowedDisguises(CommandSender sender, String permissionNode) {
|
||||
ArrayList<String> names = new ArrayList<String>();
|
||||
@ -117,8 +121,7 @@ public abstract class BaseDisguiseCommand implements CommandExecutor {
|
||||
* disguise has been feed a proper disguisetype.
|
||||
*/
|
||||
protected Disguise parseDisguise(CommandSender sender, String[] args) throws Exception {
|
||||
String permissionNode = "libsdisguises." + getClass().getSimpleName().replace("Command", "").toLowerCase() + ".";
|
||||
ArrayList<String> allowedDisguises = getAllowedDisguises(sender, permissionNode);
|
||||
ArrayList<String> allowedDisguises = getAllowedDisguises(sender);
|
||||
if (allowedDisguises.isEmpty()) {
|
||||
throw new Exception(ChatColor.RED + "You are forbidden to use this command.");
|
||||
}
|
||||
@ -345,7 +348,7 @@ public abstract class BaseDisguiseCommand implements CommandExecutor {
|
||||
for (HashSet<String> perms : optionPermissions) {
|
||||
if (!perms.containsAll(usedOptions)) {
|
||||
throw new Exception(ChatColor.RED + "You do not have the permission to use the option "
|
||||
+ usedOptions.iterator().next());
|
||||
+ usedOptions.toArray(new String[usedOptions.size()])[usedOptions.size() - 1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,15 @@
|
||||
package me.libraryaddict.disguise;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.events.DisguiseEvent;
|
||||
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.craftbukkit.v1_6_R3.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.v1_6_R3.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -19,6 +17,7 @@ import com.comphenix.protocol.Packets;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.reflect.StructureModifier;
|
||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
|
||||
|
||||
public class DisguiseAPI {
|
||||
|
||||
@ -48,7 +47,7 @@ public class DisguiseAPI {
|
||||
disguise = disguise.clone();
|
||||
}
|
||||
try {
|
||||
Field field = net.minecraft.server.v1_6_R3.Entity.class.getDeclaredField("entityCount");
|
||||
Field field = ReflectionManager.getNmsClass("Entity").getDeclaredField("entityCount");
|
||||
field.setAccessible(true);
|
||||
int id = field.getInt(null);
|
||||
disguises.put(id, disguise);
|
||||
@ -166,17 +165,29 @@ public class DisguiseAPI {
|
||||
* the entity to all the watching players, which is where the magic begins
|
||||
*/
|
||||
private static void refreshTrackers(Entity entity) {
|
||||
EntityTrackerEntry entry = (EntityTrackerEntry) ((WorldServer) ((CraftEntity) entity).getHandle().world).tracker.trackedEntities
|
||||
.get(entity.getEntityId());
|
||||
if (entry != null) {
|
||||
EntityPlayer[] players = (EntityPlayer[]) entry.trackedPlayers.toArray(new EntityPlayer[entry.trackedPlayers.size()]);
|
||||
for (EntityPlayer player : players) {
|
||||
if (entity instanceof Player && !player.getBukkitEntity().canSee((Player) entity))
|
||||
try {
|
||||
Object world = ReflectionManager.getWorld(entity.getWorld());
|
||||
Object tracker = world.getClass().getField("tracker").get(world);
|
||||
Object trackedEntities = tracker.getClass().getField("trackedEntities").get(tracker);
|
||||
Object entityTrackerEntry = trackedEntities.getClass().getMethod("get", int.class)
|
||||
.invoke(trackedEntities, entity.getEntityId());
|
||||
if (entityTrackerEntry != null) {
|
||||
HashSet trackedPlayers = (HashSet) entityTrackerEntry.getClass().getField("trackedPlayers")
|
||||
.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;
|
||||
entry.clear(player);
|
||||
entry.updatePlayer(player);
|
||||
clear.invoke(entityTrackerEntry, player);
|
||||
updatePlayer.invoke(entityTrackerEntry, player);
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static void removeSelfDisguise(Player player) {
|
||||
@ -192,18 +203,26 @@ public class DisguiseAPI {
|
||||
// Remove the fake entity ID from the disguise bin
|
||||
selfDisguisesIds.remove(player.getEntityId());
|
||||
// Get the entity tracker
|
||||
EntityPlayer entityplayer = ((CraftPlayer) player).getHandle();
|
||||
EntityTrackerEntry tracker = (EntityTrackerEntry) ((WorldServer) entityplayer.world).tracker.trackedEntities
|
||||
.get(player.getEntityId());
|
||||
try {
|
||||
Object world = ReflectionManager.getWorld(player.getWorld());
|
||||
Object tracker = world.getClass().getField("tracker").get(world);
|
||||
Object trackedEntities = tracker.getClass().getField("trackedEntities").get(tracker);
|
||||
Object entityTrackerEntry = trackedEntities.getClass().getMethod("get", int.class)
|
||||
.invoke(trackedEntities, player.getEntityId());
|
||||
if (entityTrackerEntry != null) {
|
||||
HashSet trackedPlayers = (HashSet) entityTrackerEntry.getClass().getField("trackedPlayers")
|
||||
.get(entityTrackerEntry);
|
||||
// If the tracker exists. Remove himself from his tracker
|
||||
if (tracker != null) {
|
||||
tracker.trackedPlayers.remove(entityplayer);
|
||||
trackedPlayers.remove(ReflectionManager.getNmsEntity(player));
|
||||
}
|
||||
// Resend entity metadata else he will be invisible to himself until its resent
|
||||
} 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);
|
||||
StructureModifier<Object> mods = packetMetadata.getModifier();
|
||||
mods.write(0, player.getEntityId());
|
||||
mods.write(1, entityplayer.getDataWatcher().c());
|
||||
packetMetadata.getWatchableCollectionModifier().write(0,
|
||||
WrappedDataWatcher.getEntityWatcher(player).getWatchableObjects());
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packetMetadata);
|
||||
} catch (Exception ex) {
|
||||
@ -268,7 +287,7 @@ public class DisguiseAPI {
|
||||
return;
|
||||
try {
|
||||
// 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);
|
||||
int id = field.getInt(null);
|
||||
// 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.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
|
||||
import me.libraryaddict.disguise.commands.*;
|
||||
@ -14,42 +13,19 @@ import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.Values;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher;
|
||||
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.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.craftbukkit.v1_6_R3.CraftWorld;
|
||||
import org.bukkit.entity.Ageable;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
|
||||
import com.comphenix.protocol.wrappers.WrappedWatchableObject;
|
||||
|
||||
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
|
||||
public void onEnable() {
|
||||
@ -109,7 +85,6 @@ public class LibsDisguises extends JavaPlugin {
|
||||
}
|
||||
|
||||
private void registerValues() {
|
||||
World world = ((CraftWorld) Bukkit.getWorlds().get(0)).getHandle();
|
||||
for (DisguiseType disguiseType : DisguiseType.values()) {
|
||||
Class watcherClass = null;
|
||||
try {
|
||||
@ -196,35 +171,33 @@ public class LibsDisguises extends JavaPlugin {
|
||||
break;
|
||||
}
|
||||
try {
|
||||
net.minecraft.server.v1_6_R3.Entity entity = null;
|
||||
Class entityClass;
|
||||
if (disguiseType == DisguiseType.PLAYER) {
|
||||
entityClass = EntityHuman.class;
|
||||
entity = new DisguiseHuman(world);
|
||||
} else {
|
||||
entityClass = Class.forName(Entity.class.getName() + name);
|
||||
entity = (net.minecraft.server.v1_6_R3.Entity) entityClass.getConstructor(World.class).newInstance(world);
|
||||
Object entity = ReflectionManager.createEntityInstance(name);
|
||||
Entity bukkitEntity = (Entity) ReflectionManager.getNmsClass("Entity").getMethod("getBukkitEntity")
|
||||
.invoke(entity);
|
||||
int size = 0;
|
||||
for (Field field : ReflectionManager.getNmsClass("Entity").getFields()) {
|
||||
if (field.getType().getName().equals("EnumEntitySize")) {
|
||||
Enum a = (Enum) field.get(entity);
|
||||
size = a.ordinal();
|
||||
break;
|
||||
}
|
||||
Values value = new Values(disguiseType, entityClass, entity.at);
|
||||
List<WatchableObject> watchers = entity.getDataWatcher().c();
|
||||
for (WatchableObject watch : watchers)
|
||||
value.setMetaValue(watch.a(), watch.b());
|
||||
if (entity instanceof EntityLiving) {
|
||||
EntityLiving livingEntity = (EntityLiving) entity;
|
||||
value.setAttributesValue(GenericAttributes.d.a(), livingEntity.getAttributeInstance(GenericAttributes.d)
|
||||
.getValue());
|
||||
}
|
||||
Values value = new Values(disguiseType, entity.getClass(), size);
|
||||
WrappedDataWatcher dataWatcher = WrappedDataWatcher.getEntityWatcher(bukkitEntity);
|
||||
List<WrappedWatchableObject> watchers = dataWatcher.getWatchableObjects();
|
||||
for (WrappedWatchableObject watch : watchers)
|
||||
value.setMetaValue(watch.getIndex(), watch.getValue());
|
||||
DisguiseSound sound = DisguiseSound.getType(disguiseType.name());
|
||||
if (sound != null) {
|
||||
Method soundStrength = EntityLiving.class.getDeclaredMethod("ba");
|
||||
// TODO Update this each update!
|
||||
soundStrength.setAccessible(true);
|
||||
sound.setDamageSoundVolume((Float) soundStrength.invoke(entity));
|
||||
Float soundStrength = ReflectionManager.getSoundModifier(entity);
|
||||
if (soundStrength != null) {
|
||||
sound.setDamageSoundVolume((Float) soundStrength);
|
||||
}
|
||||
} catch (Exception e1) {
|
||||
System.out.print("[LibsDisguises] Trouble while making values for " + name + ": " + e1.getMessage());
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
System.out.print("[LibsDisguises] Trouble while making values for " + name + ": " + ex.getMessage());
|
||||
System.out.print("[LibsDisguises] Please report this to LibsDisguises author");
|
||||
e1.printStackTrace();
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,8 +3,7 @@ package me.libraryaddict.disguise;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
@ -18,47 +17,22 @@ import me.libraryaddict.disguise.disguisetypes.MobDisguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.PlayerDisguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.Values;
|
||||
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.Art;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
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.Ageable;
|
||||
import org.bukkit.entity.Arrow;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.ExperienceOrb;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Zombie;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import com.comphenix.protocol.Packets;
|
||||
@ -71,6 +45,8 @@ import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.comphenix.protocol.events.PacketListener;
|
||||
import com.comphenix.protocol.reflect.StructureModifier;
|
||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
|
||||
import com.comphenix.protocol.wrappers.WrappedWatchableObject;
|
||||
|
||||
public class PacketsManager {
|
||||
private static boolean cancelSound;
|
||||
@ -151,7 +127,7 @@ public class PacketsManager {
|
||||
public static PacketContainer[] constructSpawnPackets(Disguise disguise, Entity disguisedEntity) {
|
||||
if (disguise.getEntity() == null)
|
||||
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>();
|
||||
for (int i = 0; i < 5; i++) {
|
||||
int slot = i - 1;
|
||||
@ -160,14 +136,17 @@ public class PacketsManager {
|
||||
org.bukkit.inventory.ItemStack itemstack = disguise.getWatcher().getItemStack(slot);
|
||||
if (itemstack != null && itemstack.getTypeId() != 0) {
|
||||
ItemStack item = null;
|
||||
if (nmsEntity instanceof EntityLiving)
|
||||
item = ((EntityLiving) nmsEntity).getEquipment(i);
|
||||
if (item == null) {
|
||||
if (disguisedEntity instanceof LivingEntity)
|
||||
if (i != 4)
|
||||
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);
|
||||
StructureModifier<Object> mods = packet.getModifier();
|
||||
mods.write(0, disguisedEntity.getEntityId());
|
||||
mods.write(1, i);
|
||||
mods.write(2, CraftItemStack.asNMSCopy(itemstack));
|
||||
mods.write(2, ReflectionManager.getNmsItem(itemstack));
|
||||
packets.add(packet);
|
||||
}
|
||||
}
|
||||
@ -179,7 +158,6 @@ public class PacketsManager {
|
||||
Location loc = disguisedEntity.getLocation().clone().add(0, getYModifier(disguisedEntity, disguise.getType()), 0);
|
||||
byte yaw = getYaw(disguise.getType(), DisguiseType.getType(disguise.getEntity().getType()),
|
||||
(byte) (int) (loc.getYaw() * 256.0F / 360.0F));
|
||||
EnumEntitySize entitySize = Values.getValues(disguise.getType()).getEntitySize();
|
||||
|
||||
if (disguise.getType() == DisguiseType.EXPERIENCE_ORB) {
|
||||
|
||||
@ -201,8 +179,8 @@ public class PacketsManager {
|
||||
mods.write(4, ((int) loc.getYaw()) % 4);
|
||||
int id = ((MiscDisguise) disguise).getData();
|
||||
if (id == -1)
|
||||
id = new Random().nextInt(EnumArt.values().length);
|
||||
mods.write(5, EnumArt.values()[id % EnumArt.values().length].B);
|
||||
id = new Random().nextInt(Art.values().length);
|
||||
mods.write(5, ReflectionManager.getEnumArt(Art.values()[id % Art.values().length]));
|
||||
|
||||
// Make the teleport packet to make it visible..
|
||||
spawnPackets[1] = new PacketContainer(Packets.Server.ENTITY_TELEPORT);
|
||||
@ -220,22 +198,25 @@ public class PacketsManager {
|
||||
StructureModifier<Object> mods = spawnPackets[0].getModifier();
|
||||
mods.write(0, disguisedEntity.getEntityId());
|
||||
mods.write(1, ((PlayerDisguise) disguise).getName());
|
||||
mods.write(2, (int) Math.floor(loc.getX() * 32));
|
||||
mods.write(3, (int) Math.floor(loc.getY() * 32));
|
||||
mods.write(4, (int) Math.floor(loc.getZ() * 32));
|
||||
mods.write(5, yaw);
|
||||
mods.write(6, (byte) (int) (loc.getPitch() * 256F / 360F));
|
||||
mods.write(2, ((PlayerDisguise) disguise).getName());
|
||||
mods.write(3, (int) Math.floor(loc.getX() * 32));
|
||||
mods.write(4, (int) Math.floor(loc.getY() * 32));
|
||||
mods.write(5, (int) Math.floor(loc.getZ() * 32));
|
||||
mods.write(6, yaw);
|
||||
mods.write(7, (byte) (int) (loc.getPitch() * 256F / 360F));
|
||||
ItemStack item = null;
|
||||
if (disguisedEntity instanceof Player && ((Player) disguisedEntity).getItemInHand() != null) {
|
||||
item = CraftItemStack.asNMSCopy(((Player) disguisedEntity).getItemInHand());
|
||||
item = ((Player) disguisedEntity).getItemInHand();
|
||||
} 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, createDataWatcher(nmsEntity.getDataWatcher(), disguise.getWatcher()));
|
||||
mods.write(8, (item == null || item.getType() == Material.AIR ? 0 : item.getTypeId()));
|
||||
spawnPackets[0].getDataWatcherModifier().write(0,
|
||||
createDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity), disguise.getWatcher()));
|
||||
|
||||
} else if (disguise.getType().isMob()) {
|
||||
|
||||
Values values = Values.getValues(disguise.getType());
|
||||
Vector vec = disguisedEntity.getVelocity();
|
||||
spawnPackets[0] = new PacketContainer(Packets.Server.MOB_SPAWN);
|
||||
StructureModifier<Object> mods = spawnPackets[0].getModifier();
|
||||
@ -257,17 +238,18 @@ public class PacketsManager {
|
||||
d3 = d1;
|
||||
if (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(4, entitySize.a(loc.getZ()));
|
||||
mods.write(4, values.getEntitySize(loc.getZ()));
|
||||
mods.write(5, (int) (d2 * 8000.0D));
|
||||
mods.write(6, (int) (d3 * 8000.0D));
|
||||
mods.write(7, (int) (d4 * 8000.0D));
|
||||
mods.write(8, yaw);
|
||||
mods.write(9, (byte) (int) (loc.getPitch() * 256.0F / 360.0F));
|
||||
if (nmsEntity instanceof EntityLiving)
|
||||
mods.write(10, (byte) (int) (((EntityLiving) nmsEntity).aA * 256.0F / 360.0F));
|
||||
mods.write(11, createDataWatcher(nmsEntity.getDataWatcher(), disguise.getWatcher()));
|
||||
// if (nmsEntity instanceof EntityLiving)
|
||||
// mods.write(10, (byte) (int) (((EntityLiving) nmsEntity).aA * 256.0F / 360.0F));
|
||||
spawnPackets[0].getDataWatcherModifier().write(0,
|
||||
createDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity), disguise.getWatcher()));
|
||||
// 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.
|
||||
|
||||
@ -318,7 +300,7 @@ public class PacketsManager {
|
||||
mods.write(5, (int) (d2 * 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(9, id);
|
||||
mods.write(10, data);
|
||||
@ -337,16 +319,13 @@ public class PacketsManager {
|
||||
/**
|
||||
* Create a new datawatcher but with the 'correct' values
|
||||
*/
|
||||
private static DataWatcher createDataWatcher(DataWatcher watcher, FlagWatcher flagWatcher) {
|
||||
DataWatcher newWatcher = new DataWatcher();
|
||||
private static WrappedDataWatcher createDataWatcher(WrappedDataWatcher watcher, FlagWatcher flagWatcher) {
|
||||
WrappedDataWatcher newWatcher = new WrappedDataWatcher();
|
||||
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.
|
||||
List<WatchableObject> list = watcher.c();
|
||||
for (WatchableObject watchableObject : flagWatcher.convert(list)) {
|
||||
c.put(watchableObject.a(), watchableObject);
|
||||
List<WrappedWatchableObject> list = watcher.getWatchableObjects();
|
||||
for (WrappedWatchableObject watchableObject : flagWatcher.convert(list)) {
|
||||
newWatcher.setObject(watchableObject.getIndex(), watchableObject.getValue());
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
@ -463,13 +442,18 @@ public class PacketsManager {
|
||||
soundType = SoundType.DEATH;
|
||||
} else {
|
||||
boolean hasInvun = false;
|
||||
Object nmsEntity = ReflectionManager.getNmsEntity(entity);
|
||||
try {
|
||||
if (entity instanceof LivingEntity) {
|
||||
net.minecraft.server.v1_6_R3.EntityLiving e = ((CraftLivingEntity) entity)
|
||||
.getHandle();
|
||||
hasInvun = (e.noDamageTicks == e.maxNoDamageTicks);
|
||||
Class entityClass = ReflectionManager.getNmsClass("Entity");
|
||||
hasInvun = entityClass.getField("noDamageTicks").getInt(nmsEntity) == entityClass
|
||||
.getField("maxNoDamageTicks").getInt(nmsEntity);
|
||||
} else {
|
||||
net.minecraft.server.v1_6_R3.Entity e = ((CraftEntity) entity).getHandle();
|
||||
hasInvun = e.isInvulnerable();
|
||||
hasInvun = (Boolean) ReflectionManager.getNmsClass("Entity")
|
||||
.getMethod("isInvulnerable").invoke(nmsEntity);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
soundType = entitySound.getType(soundName, !hasInvun);
|
||||
}
|
||||
@ -493,11 +477,18 @@ public class PacketsManager {
|
||||
event.setCancelled(true);
|
||||
} else {
|
||||
if (sound.equals("step.grass")) {
|
||||
World world = ((CraftEntity) disguisedEntity).getHandle().world;
|
||||
Block b = Block.byId[world.getTypeId(soundLoc.getBlockX(), soundLoc.getBlockY() - 1,
|
||||
soundLoc.getBlockZ())];
|
||||
if (b != null)
|
||||
mods.write(0, b.stepSound.getStepSound());
|
||||
try {
|
||||
int typeId = soundLoc.getWorld().getBlockTypeIdAt(soundLoc.getBlockX(),
|
||||
soundLoc.getBlockY() - 1, soundLoc.getBlockZ());
|
||||
Class blockClass = ReflectionManager.getNmsClass("Block");
|
||||
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
|
||||
// someone is
|
||||
// sending fake sounds. In which case. Why cancel it.
|
||||
@ -514,7 +505,12 @@ public class PacketsManager {
|
||||
// Here I assume its the default pitch as I can't calculate if its real.
|
||||
if (disguise instanceof MobDisguise && disguisedEntity instanceof LivingEntity
|
||||
&& ((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) {
|
||||
|
||||
float pitch = (Integer) mods.read(5);
|
||||
@ -552,7 +548,7 @@ public class PacketsManager {
|
||||
}
|
||||
}
|
||||
} 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
|
||||
Entity entity = event.getPacket().getEntityModifier(observer.getWorld()).read(0);
|
||||
Disguise disguise = DisguiseAPI.getDisguise(entity);
|
||||
@ -616,7 +612,7 @@ public class PacketsManager {
|
||||
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.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_VELOCITY, Packets.Server.UPDATE_ATTRIBUTES) {
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent event) {
|
||||
StructureModifier<Entity> entityModifer = event.getPacket().getEntityModifier(event.getPlayer().getWorld());
|
||||
@ -639,16 +635,16 @@ public class PacketsManager {
|
||||
|
||||
if (event.getPacketID() == Packets.Server.ENTITY_METADATA) {
|
||||
event.setPacket(event.getPacket().deepClone());
|
||||
StructureModifier<Object> mods = event.getPacket().getModifier();
|
||||
Iterator<WatchableObject> itel = ((List<WatchableObject>) mods.read(1)).iterator();
|
||||
Iterator<WrappedWatchableObject> itel = event.getPacket().getWatchableCollectionModifier().read(0)
|
||||
.iterator();
|
||||
while (itel.hasNext()) {
|
||||
WatchableObject watch = itel.next();
|
||||
if (watch.a() == 0) {
|
||||
byte b = (Byte) watch.b();
|
||||
WrappedWatchableObject watch = itel.next();
|
||||
if (watch.getIndex() == 0) {
|
||||
byte b = (Byte) watch.getValue();
|
||||
byte a = (byte) (b | 1 << 5);
|
||||
if ((b & 1 << 3) != 0)
|
||||
a = (byte) (a | 1 << 3);
|
||||
watch.a(a);
|
||||
watch.setValue(a);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -666,12 +662,12 @@ public class PacketsManager {
|
||||
PacketContainer packet = new PacketContainer(Packets.Server.ENTITY_METADATA);
|
||||
StructureModifier<Object> mods = packet.getModifier();
|
||||
mods.write(0, entity.getEntityId());
|
||||
List watchableList = new ArrayList();
|
||||
List<WrappedWatchableObject> watchableList = new ArrayList<WrappedWatchableObject>();
|
||||
byte b = (byte) (0 | 1 << 5);
|
||||
if (event.getPlayer().isSprinting())
|
||||
b = (byte) (b | 1 << 3);
|
||||
watchableList.add(new WatchableObject(0, 0, b));
|
||||
mods.write(1, watchableList);
|
||||
watchableList.add(new WrappedWatchableObject(0, b));
|
||||
packet.getWatchableCollectionModifier().write(0, watchableList);
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false);
|
||||
} catch (Exception ex) {
|
||||
@ -681,12 +677,12 @@ public class PacketsManager {
|
||||
event.setCancelled(true);
|
||||
break;
|
||||
|
||||
case Packets.Server.ENTITY_STATUS:
|
||||
/* case Packets.Server.ENTITY_STATUS:
|
||||
if (DisguiseAPI.getDisguise(entity).canHearSelfDisguise()
|
||||
&& (Byte) event.getPacket().getModifier().read(1) == 2) {
|
||||
&& (Byte) event.getPacket().getModifier().read(1) == 1) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
break;
|
||||
break;*/
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -726,7 +722,7 @@ public class PacketsManager {
|
||||
if (item != null && item.getType() != Material.AIR) {
|
||||
event.setPacket(event.getPacket().shallowClone());
|
||||
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
|
||||
@ -738,8 +734,9 @@ public class PacketsManager {
|
||||
org.bukkit.inventory.ItemStack item = event.getPlayer().getItemInHand();
|
||||
if (item != null && item.getType() != Material.AIR) {
|
||||
event.setPacket(event.getPacket().shallowClone());
|
||||
event.getPacket().getModifier()
|
||||
.write(2, CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(0)));
|
||||
event.getPacket()
|
||||
.getModifier()
|
||||
.write(2, ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(0)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -751,8 +748,8 @@ public class PacketsManager {
|
||||
*/
|
||||
case Packets.Server.WINDOW_ITEMS: {
|
||||
event.setPacket(event.getPacket().deepClone());
|
||||
StructureModifier<Object> mods = event.getPacket().getModifier();
|
||||
ItemStack[] items = (ItemStack[]) mods.read(1);
|
||||
StructureModifier<ItemStack[]> mods = event.getPacket().getItemArrayModifier();
|
||||
ItemStack[] items = mods.read(0);
|
||||
for (int slot = 0; slot < items.length; slot++) {
|
||||
if (slot >= 5 && slot <= 8) {
|
||||
if (disguise.isHidingArmorFromSelf()) {
|
||||
@ -760,7 +757,7 @@ public class PacketsManager {
|
||||
int armorSlot = Math.abs((slot - 5) - 3);
|
||||
org.bukkit.inventory.ItemStack item = event.getPlayer().getInventory().getArmorContents()[armorSlot];
|
||||
if (item != null && item.getType() != Material.AIR) {
|
||||
items[slot] = CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(0));
|
||||
items[slot] = new org.bukkit.inventory.ItemStack(0);
|
||||
}
|
||||
}
|
||||
// Else if its a hotbar slot
|
||||
@ -771,12 +768,13 @@ public class PacketsManager {
|
||||
if (slot == currentSlot + 36) {
|
||||
org.bukkit.inventory.ItemStack item = event.getPlayer().getItemInHand();
|
||||
if (item != null && item.getType() != Material.AIR) {
|
||||
items[slot] = CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(0));
|
||||
items[slot] = new org.bukkit.inventory.ItemStack(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
mods.write(0, items);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@ -808,7 +806,7 @@ public class PacketsManager {
|
||||
StructureModifier<Object> mods = packet.getModifier();
|
||||
mods.write(0, 0);
|
||||
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 {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet,
|
||||
false);
|
||||
@ -827,7 +825,7 @@ public class PacketsManager {
|
||||
StructureModifier<Object> mods = packet.getModifier();
|
||||
mods.write(0, 0);
|
||||
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 {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet,
|
||||
false);
|
||||
@ -854,7 +852,7 @@ public class PacketsManager {
|
||||
StructureModifier<Object> mods = packet.getModifier();
|
||||
mods.write(0, 0);
|
||||
mods.write(1, event.getPlayer().getInventory().getHeldItemSlot() + 36);
|
||||
mods.write(2, CraftItemStack.asNMSCopy(currentlyHeld));
|
||||
mods.write(2, ReflectionManager.getNmsItem(currentlyHeld));
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false);
|
||||
} catch (InvocationTargetException e) {
|
||||
@ -869,7 +867,7 @@ public class PacketsManager {
|
||||
StructureModifier<Object> mods = packet.getModifier();
|
||||
mods.write(0, 0);
|
||||
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 {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false);
|
||||
} catch (InvocationTargetException e) {
|
||||
@ -912,7 +910,7 @@ public class PacketsManager {
|
||||
StructureModifier<Object> mods = packet.getModifier();
|
||||
mods.write(0, 0);
|
||||
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 {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet,
|
||||
false);
|
||||
@ -930,7 +928,7 @@ public class PacketsManager {
|
||||
StructureModifier<Object> mods = packet.getModifier();
|
||||
mods.write(0, 0);
|
||||
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 {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet,
|
||||
false);
|
||||
@ -969,10 +967,13 @@ public class PacketsManager {
|
||||
* Sends the self disguise to the 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) {
|
||||
try {
|
||||
Object world = ReflectionManager.getWorld(player.getWorld());
|
||||
Object tracker = world.getClass().getField("tracker").get(world);
|
||||
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..
|
||||
@ -984,81 +985,89 @@ public class PacketsManager {
|
||||
return;
|
||||
}
|
||||
// Add himself to his own entity tracker
|
||||
tracker.trackedPlayers.add(entityplayer);
|
||||
((HashSet) entityTrackerEntry.getClass().getField("trackedPlayers").get(entityTrackerEntry)).add(ReflectionManager
|
||||
.getNmsEntity(player));
|
||||
ProtocolManager manager = ProtocolLibrary.getProtocolManager();
|
||||
// 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();
|
||||
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));
|
||||
|
||||
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 {
|
||||
Field field = EntityTrackerEntry.class.getDeclaredField("isMoving");
|
||||
Field field = ReflectionManager.getNmsClass("EntityTrackerEntry").getDeclaredField("isMoving");
|
||||
field.setAccessible(true);
|
||||
isMoving = field.getBoolean(tracker);
|
||||
isMoving = field.getBoolean(entityTrackerEntry);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
// Send the velocity packets
|
||||
if (isMoving) {
|
||||
entityplayer.playerConnection.sendPacket(new Packet28EntityVelocity(player.getEntityId(), tracker.tracker.motX,
|
||||
tracker.tracker.motY, tracker.tracker.motZ));
|
||||
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 (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()));
|
||||
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 itemstack = ((EntityLiving) tracker.tracker).getEquipment(i);
|
||||
for (int i = 0; i < 5; i++) {
|
||||
ItemStack item;
|
||||
if (i == 0) {
|
||||
item = player.getItemInHand();
|
||||
} else {
|
||||
item = player.getInventory().getArmorContents()[i - 1];
|
||||
}
|
||||
|
||||
if (itemstack != null) {
|
||||
entityplayer.playerConnection.sendPacket(new Packet5EntityEquipment(player.getEntityId(), i, itemstack));
|
||||
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 (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)));
|
||||
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()));
|
||||
}
|
||||
|
||||
// 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
|
||||
// TODO Fix this cos it doesn't move the disguise?
|
||||
byte yaw = (byte) (loc.getYaw() * 256.0F / 360.0F);
|
||||
byte pitch = (byte) (loc.getPitch() * 256.0F / 360.0F);
|
||||
manager.sendServerPacket(
|
||||
player,
|
||||
manager.createPacketConstructor(Packets.Server.ENTITY_LOOK, player.getEntityId(), yaw, pitch).createPacket(
|
||||
player.getEntityId(), yaw, pitch));
|
||||
|
||||
// Resend any active potion effects
|
||||
Iterator iterator = entityplayer.getEffects().iterator();
|
||||
Iterator iterator = player.getActivePotionEffects().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
MobEffect mobeffect = (MobEffect) iterator.next();
|
||||
|
||||
entityplayer.playerConnection.sendPacket(new Packet41MobEffect(player.getEntityId(), mobeffect));
|
||||
PotionEffect potionEffect = (PotionEffect) iterator.next();
|
||||
manager.sendServerPacket(player,
|
||||
manager.createPacketConstructor(Packets.Server.MOB_EFFECT, player.getEntityId(), potionEffect)
|
||||
.createPacket(player.getEntityId(), potionEffect));
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1141,22 +1150,8 @@ public class PacketsManager {
|
||||
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];
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@ -1164,12 +1159,12 @@ public class PacketsManager {
|
||||
case Packets.Server.ENTITY_METADATA:
|
||||
|
||||
{
|
||||
List<WatchableObject> watchableObjects = disguise.getWatcher().convert(
|
||||
(List<WatchableObject>) packets[0].getModifier().read(1));
|
||||
List<WrappedWatchableObject> watchableObjects = disguise.getWatcher().convert(
|
||||
packets[0].getWatchableCollectionModifier().read(0));
|
||||
packets[0] = new PacketContainer(sentPacket.getID());
|
||||
StructureModifier<Object> newMods = packets[0].getModifier();
|
||||
newMods.write(0, entity.getEntityId());
|
||||
newMods.write(1, watchableObjects);
|
||||
packets[0].getWatchableCollectionModifier().write(0, watchableObjects);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -1238,7 +1233,7 @@ public class PacketsManager {
|
||||
if (itemstack != null) {
|
||||
packets[0] = packets[0].shallowClone();
|
||||
packets[0].getModifier().write(2,
|
||||
(itemstack.getTypeId() == 0 ? null : CraftItemStack.asNMSCopy(itemstack)));
|
||||
(itemstack.getTypeId() == 0 ? null : ReflectionManager.getNmsItem(itemstack)));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
158
src/me/libraryaddict/disguise/ReflectionManager.java
Normal file
158
src/me/libraryaddict/disguise/ReflectionManager.java
Normal file
@ -0,0 +1,158 @@
|
||||
package me.libraryaddict.disguise;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
import org.bukkit.Art;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class ReflectionManager {
|
||||
private static String bukkitVersion = Bukkit.getServer().getClass().getName().split("\\.")[3];
|
||||
private static Class itemClass;
|
||||
private static Method soundMethod;
|
||||
static {
|
||||
for (Method method : getNmsClass("EntityLiving").getDeclaredMethods()) {
|
||||
try {
|
||||
if (method.getReturnType() == float.class && Modifier.isProtected(method.getModifiers())
|
||||
&& method.getParameterTypes().length == 0) {
|
||||
Object entity = createEntityInstance("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 {
|
||||
itemClass = getCraftClass("inventory.CraftItemStack");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
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 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) {
|
||||
try {
|
||||
Class c = getCraftClass("CraftSound");
|
||||
return (String) c.getMethod("getSound", Sound.class).invoke(null, sound);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Object createEntityInstance(String entityName) {
|
||||
try {
|
||||
Class entityClass = getNmsClass("Entity" + entityName);
|
||||
Object entityObject;
|
||||
Object world = getWorld(Bukkit.getWorlds().get(0));
|
||||
if (entityName.equals("Player")) {
|
||||
Object minecraftServer = getNmsClass("MinecraftServer").getMethod("getServer").invoke(null);
|
||||
Object playerinteractmanager = getNmsClass("PlayerInteractManager").getConstructor(getNmsClass("World"))
|
||||
.newInstance(world);
|
||||
entityObject = entityClass.getConstructor(getNmsClass("MinecraftServer"), getNmsClass("World"), String.class,
|
||||
playerinteractmanager.getClass()).newInstance(minecraftServer, world, "LibsDisguises",
|
||||
playerinteractmanager);
|
||||
} else {
|
||||
entityObject = entityClass.getConstructor(getNmsClass("World")).newInstance(world);
|
||||
}
|
||||
return entityObject;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
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 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) {
|
||||
try {
|
||||
soundMethod.setAccessible(true);
|
||||
return (Float) soundMethod.invoke(entity);
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Object getWorld(World world) {
|
||||
try {
|
||||
return getCraftClass("CraftWorld").getMethod("getHandle").invoke(world);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Object getNmsItem(ItemStack itemstack) {
|
||||
try {
|
||||
return itemClass.getMethod("asNMSCopy", ItemStack.class).invoke(null, itemstack);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ItemStack getBukkitItem(Object nmsItem) {
|
||||
try {
|
||||
return (ItemStack) itemClass.getMethod("asBukkitCopy", getNmsClass("ItemStack")).invoke(null, nmsItem);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -18,15 +18,19 @@ public class DisguiseCommand extends BaseDisguiseCommand {
|
||||
sender.sendMessage(ChatColor.RED + "You may not use this command from the console!");
|
||||
return true;
|
||||
}
|
||||
Disguise disguise = null;
|
||||
try {
|
||||
Disguise disguise = parseDisguise(sender, args);
|
||||
disguise = parseDisguise(sender, args);
|
||||
} catch (Exception ex) {
|
||||
if (ex.getMessage() != null && !ChatColor.getLastColors(ex.getMessage()).equals("")) {
|
||||
sender.sendMessage(ex.getMessage());
|
||||
} else {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
DisguiseAPI.disguiseToAll((Player) sender, disguise);
|
||||
sender.sendMessage(ChatColor.RED + "Now disguised as a " + disguise.getType().toReadable());
|
||||
} catch (Exception ex) {
|
||||
if (ex.getMessage() != null) {
|
||||
sender.sendMessage(ex.getMessage());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -34,7 +38,7 @@ public class DisguiseCommand extends BaseDisguiseCommand {
|
||||
* Send the player the information
|
||||
*/
|
||||
protected void sendCommandUsage(CommandSender sender) {
|
||||
ArrayList<String> allowedDisguises = getAllowedDisguises(sender, "disguise");
|
||||
ArrayList<String> allowedDisguises = getAllowedDisguises(sender);
|
||||
sender.sendMessage(ChatColor.DARK_GREEN + "Choose a disguise to become the disguise!");
|
||||
sender.sendMessage(ChatColor.DARK_GREEN + "You can use the disguises: " + ChatColor.GREEN
|
||||
+ StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN));
|
||||
|
@ -23,16 +23,20 @@ public class DisguiseEntityCommand extends BaseDisguiseCommand {
|
||||
sender.sendMessage(ChatColor.RED + "You may not use this command from the console!");
|
||||
return true;
|
||||
}
|
||||
Disguise disguise;
|
||||
try {
|
||||
Disguise disguise = parseDisguise(sender, args);
|
||||
disguise = parseDisguise(sender, args);
|
||||
} catch (Exception ex) {
|
||||
if (ex.getMessage() != null && !ChatColor.getLastColors(ex.getMessage()).equals("")) {
|
||||
sender.sendMessage(ex.getMessage());
|
||||
} else {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
listener.setSlap(sender.getName(), disguise);
|
||||
sender.sendMessage(ChatColor.RED + "Right click a entity in the next 10 seconds to disguise it as a "
|
||||
+ disguise.getType().toReadable() + "!");
|
||||
} catch (Exception ex) {
|
||||
if (ex.getMessage() != null) {
|
||||
sender.sendMessage(ex.getMessage());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -40,7 +44,7 @@ public class DisguiseEntityCommand extends BaseDisguiseCommand {
|
||||
* Send the player the information
|
||||
*/
|
||||
protected void sendCommandUsage(CommandSender sender) {
|
||||
ArrayList<String> allowedDisguises = getAllowedDisguises(sender, "disguiseentity");
|
||||
ArrayList<String> allowedDisguises = getAllowedDisguises(sender);
|
||||
sender.sendMessage(ChatColor.DARK_GREEN + "Choose a disguise then slap a entity to disguise it!");
|
||||
sender.sendMessage(ChatColor.DARK_GREEN + "You can use the disguises: " + ChatColor.GREEN
|
||||
+ StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN));
|
||||
|
@ -22,7 +22,7 @@ public class DisguiseHelpCommand extends BaseDisguiseCommand {
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
for (String node : new String[] { "disguise", "disguiseradius", "disguiseentity", "disguiseplayer" }) {
|
||||
ArrayList<String> allowedDisguises = getAllowedDisguises(sender, node);
|
||||
ArrayList<String> allowedDisguises = getAllowedDisguises(sender, "libsdisguises." + node + ".");
|
||||
if (!allowedDisguises.isEmpty()) {
|
||||
if (args.length == 0) {
|
||||
sendCommandUsage(sender);
|
||||
@ -126,6 +126,7 @@ public class DisguiseHelpCommand extends BaseDisguiseCommand {
|
||||
}
|
||||
}
|
||||
}
|
||||
sender.sendMessage(ChatColor.RED + "You are forbidden from using this command!");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@ public class DisguisePlayerCommand extends BaseDisguiseCommand {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
ArrayList<String> allowedDisguises = getAllowedDisguises(sender, "disguiseplayer");
|
||||
ArrayList<String> allowedDisguises = getAllowedDisguises(sender);
|
||||
if (allowedDisguises.isEmpty()) {
|
||||
sender.sendMessage(ChatColor.RED + "You are forbidden to use this command.");
|
||||
return true;
|
||||
@ -33,20 +33,24 @@ public class DisguisePlayerCommand extends BaseDisguiseCommand {
|
||||
sender.sendMessage(ChatColor.RED + "Cannot find the player '" + args[0] + "'");
|
||||
return true;
|
||||
}
|
||||
try {
|
||||
String[] newArgs = new String[args.length - 1];
|
||||
for (int i = 0; i < newArgs.length; i++) {
|
||||
newArgs[i] = args[i + 1];
|
||||
}
|
||||
Disguise disguise = parseDisguise(sender, newArgs);
|
||||
Disguise disguise;
|
||||
try {
|
||||
disguise = parseDisguise(sender, newArgs);
|
||||
} catch (Exception ex) {
|
||||
if (ex.getMessage() != null && !ChatColor.getLastColors(ex.getMessage()).equals("")) {
|
||||
sender.sendMessage(ex.getMessage());
|
||||
} else {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
DisguiseAPI.disguiseToAll(player, disguise);
|
||||
sender.sendMessage(ChatColor.RED + "Successfully disguised " + player.getName() + " as a "
|
||||
+ disguise.getType().toReadable() + "!");
|
||||
} catch (Exception ex) {
|
||||
if (ex.getMessage() != null) {
|
||||
sender.sendMessage(ex.getMessage());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -54,7 +58,7 @@ public class DisguisePlayerCommand extends BaseDisguiseCommand {
|
||||
* Send the player the information
|
||||
*/
|
||||
protected void sendCommandUsage(CommandSender sender) {
|
||||
ArrayList<String> allowedDisguises = getAllowedDisguises(sender, "disguiseplayer");
|
||||
ArrayList<String> allowedDisguises = getAllowedDisguises(sender);
|
||||
sender.sendMessage(ChatColor.DARK_GREEN + "Disguise another player!");
|
||||
sender.sendMessage(ChatColor.DARK_GREEN + "You can use the disguises: " + ChatColor.GREEN
|
||||
+ StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN));
|
||||
|
@ -24,7 +24,7 @@ public class DisguiseRadiusCommand extends BaseDisguiseCommand {
|
||||
sender.sendMessage(ChatColor.RED + "You may not use this command from the console!");
|
||||
return true;
|
||||
}
|
||||
ArrayList<String> allowedDisguises = getAllowedDisguises(sender, "disguiseplayer");
|
||||
ArrayList<String> allowedDisguises = getAllowedDisguises(sender);
|
||||
if (allowedDisguises.isEmpty()) {
|
||||
sender.sendMessage(ChatColor.RED + "You are forbidden to use this command.");
|
||||
return true;
|
||||
@ -46,13 +46,21 @@ public class DisguiseRadiusCommand extends BaseDisguiseCommand {
|
||||
sender.sendMessage(ChatColor.RED + "Limited radius to " + maxRadius + "! Don't want to make too much lag right?");
|
||||
radius = maxRadius;
|
||||
}
|
||||
try {
|
||||
String[] newArgs = new String[args.length - 1];
|
||||
for (int i = 0; i < newArgs.length; i++) {
|
||||
newArgs[i] = args[i + 1];
|
||||
}
|
||||
Disguise disguise = parseDisguise(sender, newArgs);
|
||||
// Time to use it!
|
||||
Disguise disguise;
|
||||
try {
|
||||
disguise = parseDisguise(sender, newArgs);
|
||||
} catch (Exception ex) {
|
||||
if (ex.getMessage() != null && !ChatColor.getLastColors(ex.getMessage()).equals("")) {
|
||||
sender.sendMessage(ex.getMessage());
|
||||
} else {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return true;
|
||||
} // Time to use it!
|
||||
int disguisedEntitys = 0;
|
||||
for (Entity entity : ((Player) sender).getNearbyEntities(radius, radius, radius)) {
|
||||
if (entity == sender)
|
||||
@ -61,11 +69,6 @@ public class DisguiseRadiusCommand extends BaseDisguiseCommand {
|
||||
disguisedEntitys++;
|
||||
}
|
||||
sender.sendMessage(ChatColor.RED + "Successfully disguised " + disguisedEntitys + " entities!");
|
||||
} catch (Exception ex) {
|
||||
if (ex.getMessage() != null) {
|
||||
sender.sendMessage(ex.getMessage());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -73,7 +76,7 @@ public class DisguiseRadiusCommand extends BaseDisguiseCommand {
|
||||
* Send the player the information
|
||||
*/
|
||||
protected void sendCommandUsage(CommandSender sender) {
|
||||
ArrayList<String> allowedDisguises = getAllowedDisguises(sender, "disguiseradius");
|
||||
ArrayList<String> allowedDisguises = getAllowedDisguises(sender);
|
||||
sender.sendMessage(ChatColor.DARK_GREEN + "Disguise all entities in a radius! Caps at 30 blocks!");
|
||||
sender.sendMessage(ChatColor.DARK_GREEN + "You can use the disguises: " + ChatColor.GREEN
|
||||
+ StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN));
|
||||
|
@ -1,25 +1,19 @@
|
||||
package me.libraryaddict.disguise.disguisetypes;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.PacketsManager;
|
||||
import me.libraryaddict.disguise.ReflectionManager;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.HorseWatcher;
|
||||
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.EntityPlayer;
|
||||
import net.minecraft.server.v1_6_R3.EntityTrackerEntry;
|
||||
import net.minecraft.server.v1_6_R3.WorldServer;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_6_R3.entity.CraftEntity;
|
||||
import org.bukkit.entity.Horse.Variant;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
@ -182,7 +176,7 @@ public abstract class Disguise {
|
||||
|
||||
public void run() {
|
||||
// If entity is no longer valid. Remove it.
|
||||
if (!((CraftEntity) entity).getHandle().valid) {
|
||||
if (!getEntity().isValid()) {
|
||||
DisguiseAPI.undisguiseToAll(entity);
|
||||
} else {
|
||||
// If the disguise type is tnt, we need to resend the entity packet else it will turn invisible
|
||||
@ -190,10 +184,7 @@ public abstract class Disguise {
|
||||
i++;
|
||||
if (i % 40 == 0) {
|
||||
i = 0;
|
||||
List<Player> players = new ArrayList<Player>();
|
||||
for (EntityPlayer p : getPerverts())
|
||||
players.add(p.getBukkitEntity());
|
||||
ProtocolLibrary.getProtocolManager().updateEntity(getEntity(), players);
|
||||
ProtocolLibrary.getProtocolManager().updateEntity(getEntity(), getPerverts());
|
||||
}
|
||||
}
|
||||
// If the vectorY isn't 0. Cos if it is. Then it doesn't want to send any vectors.
|
||||
@ -219,16 +210,18 @@ public abstract class Disguise {
|
||||
mods.write(5, (byte) Math.floor(loc.getPitch() * 256.0F / 360.0F));
|
||||
selfLookPacket = lookPacket.shallowClone();
|
||||
}
|
||||
for (EntityPlayer player : getPerverts()) {
|
||||
try {
|
||||
Field ping = ReflectionManager.getNmsClass("EntityPlayer").getField("ping");
|
||||
for (Player player : getPerverts()) {
|
||||
PacketContainer packet = new PacketContainer(Packets.Server.ENTITY_VELOCITY);
|
||||
StructureModifier<Object> mods = packet.getModifier();
|
||||
if (entity == player.getBukkitEntity()) {
|
||||
if (entity == player) {
|
||||
if (!viewSelfDisguise())
|
||||
continue;
|
||||
if (selfLookPacket != null) {
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player.getBukkitEntity(),
|
||||
selfLookPacket, false);
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, selfLookPacket,
|
||||
false);
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -237,17 +230,17 @@ public abstract class Disguise {
|
||||
} else
|
||||
mods.write(0, entity.getEntityId());
|
||||
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(ReflectionManager.getNmsEntity(player)) * 0.069)));
|
||||
mods.write(3, (int) (vector.getZ() * 8000));
|
||||
try {
|
||||
if (lookPacket != null)
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player.getBukkitEntity(),
|
||||
lookPacket, false);
|
||||
ProtocolLibrary.getProtocolManager()
|
||||
.sendServerPacket(player.getBukkitEntity(), packet, false);
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, lookPacket, false);
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
|
||||
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
// If we need to send more packets because else it still 'sinks'
|
||||
@ -255,10 +248,10 @@ public abstract class Disguise {
|
||||
PacketContainer packet = new PacketContainer(Packets.Server.REL_ENTITY_MOVE);
|
||||
StructureModifier<Object> mods = packet.getModifier();
|
||||
mods.write(0, entity.getEntityId());
|
||||
for (EntityPlayer player : getPerverts()) {
|
||||
for (Player player : getPerverts()) {
|
||||
if (DisguiseAPI.isViewDisguises() || entity != player) {
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player.getBukkitEntity(), packet);
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -281,14 +274,26 @@ public abstract class Disguise {
|
||||
/**
|
||||
* Get all EntityPlayers who have this entity in their Entity Tracker
|
||||
*/
|
||||
protected EntityPlayer[] getPerverts() {
|
||||
EntityTrackerEntry entry = (EntityTrackerEntry) ((WorldServer) ((CraftEntity) entity).getHandle().world).tracker.trackedEntities
|
||||
.get(entity.getEntityId());
|
||||
if (entry != null) {
|
||||
EntityPlayer[] players = (EntityPlayer[]) entry.trackedPlayers.toArray(new EntityPlayer[entry.trackedPlayers.size()]);
|
||||
return players;
|
||||
protected ArrayList<Player> getPerverts() {
|
||||
ArrayList<Player> players = new ArrayList<Player>();
|
||||
try {
|
||||
Object world = ReflectionManager.getWorld(getEntity().getWorld());
|
||||
Object tracker = world.getClass().getField("tracker").get(world);
|
||||
Object trackedEntities = tracker.getClass().getField("trackedEntities").get(tracker);
|
||||
Object entityTrackerEntry = trackedEntities.getClass().getMethod("get", int.class)
|
||||
.invoke(trackedEntities, getEntity().getEntityId());
|
||||
if (entityTrackerEntry != null) {
|
||||
Method method = ReflectionManager.getNmsClass("Entity").getMethod("getBukkitEntity");
|
||||
HashSet trackedPlayers = (HashSet) entityTrackerEntry.getClass().getField("trackedPlayers")
|
||||
.get(entityTrackerEntry);
|
||||
for (Object p : trackedPlayers) {
|
||||
players.add((Player) method.invoke(p));
|
||||
}
|
||||
return new EntityPlayer[0];
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return players;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -342,7 +347,7 @@ public abstract class Disguise {
|
||||
// If this disguise has a entity set
|
||||
if (getEntity() != null) {
|
||||
// If the entity is valid
|
||||
if (((CraftEntity) getEntity()).getHandle().valid) {
|
||||
if (getEntity().isValid()) {
|
||||
// If this disguise is active
|
||||
if (disguises.containsKey(getEntity().getEntityId()) && disguises.get(getEntity().getEntityId()) == this) {
|
||||
// Now remove the disguise from the current disguises.
|
||||
@ -478,19 +483,19 @@ public abstract class Disguise {
|
||||
case 7:
|
||||
case 8:
|
||||
case 9:
|
||||
baseClass = EntityLiving.class;
|
||||
baseClass = ReflectionManager.getNmsClass("EntityLiving");
|
||||
break;
|
||||
case 10:
|
||||
case 11:
|
||||
baseClass = EntityInsentient.class;
|
||||
baseClass = ReflectionManager.getNmsClass("EntityInsentient");
|
||||
break;
|
||||
case 16:
|
||||
baseClass = EntityAgeable.class;
|
||||
baseClass = ReflectionManager.getNmsClass("EntityAgeable");
|
||||
break;
|
||||
default:
|
||||
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 (baseClass != null && baseClass.isAssignableFrom(disguiseClass) && baseClass.isAssignableFrom(entityClass))
|
||||
continue;
|
||||
|
@ -3,8 +3,9 @@ package me.libraryaddict.disguise.disguisetypes;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
||||
import me.libraryaddict.disguise.ReflectionManager;
|
||||
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.craftbukkit.v1_6_R3.CraftSound;
|
||||
|
||||
/**
|
||||
* Only living disguises go in here!
|
||||
@ -103,10 +104,6 @@ public enum DisguiseSound {
|
||||
CANCEL, DEATH, HURT, IDLE, STEP;
|
||||
}
|
||||
|
||||
public static String getSoundName(Sound sound) {
|
||||
return CraftSound.getSound(sound);
|
||||
}
|
||||
|
||||
public static DisguiseSound getType(String name) {
|
||||
try {
|
||||
return valueOf(name);
|
||||
@ -128,7 +125,7 @@ public enum DisguiseSound {
|
||||
else if (obj instanceof String)
|
||||
s = (String) obj;
|
||||
else if (obj instanceof Sound)
|
||||
s = CraftSound.getSound((Sound) obj);
|
||||
s = ReflectionManager.getCraftSound((Sound) obj);
|
||||
else
|
||||
throw new RuntimeException("Was given a unknown object " + obj);
|
||||
switch (i) {
|
||||
@ -195,7 +192,7 @@ public enum DisguiseSound {
|
||||
}
|
||||
|
||||
public void removeSound(SoundType type, Sound sound) {
|
||||
removeSound(type, CraftSound.getSound(sound));
|
||||
removeSound(type, ReflectionManager.getCraftSound(sound));
|
||||
}
|
||||
|
||||
public void removeSound(SoundType type, String sound) {
|
||||
@ -211,7 +208,7 @@ public enum DisguiseSound {
|
||||
}
|
||||
|
||||
public void setSound(SoundType type, Sound sound) {
|
||||
setSound(type, CraftSound.getSound(sound));
|
||||
setSound(type, ReflectionManager.getCraftSound(sound));
|
||||
}
|
||||
|
||||
public void setSound(SoundType type, String sound) {
|
||||
|
@ -7,7 +7,6 @@ import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_6_R3.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -17,13 +16,11 @@ import com.comphenix.protocol.Packets;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.reflect.StructureModifier;
|
||||
import com.comphenix.protocol.wrappers.WrappedWatchableObject;
|
||||
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.PacketsManager;
|
||||
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;
|
||||
import me.libraryaddict.disguise.ReflectionManager;
|
||||
|
||||
public class FlagWatcher {
|
||||
public enum SlotType {
|
||||
@ -39,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..
|
||||
*/
|
||||
@ -67,7 +54,6 @@ public class FlagWatcher {
|
||||
try {
|
||||
cloned = getClass().getConstructor(Disguise.class).newInstance(disguise);
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
cloned.entityValues = (HashMap<Integer, Object>) entityValues.clone();
|
||||
@ -75,14 +61,14 @@ public class FlagWatcher {
|
||||
return cloned;
|
||||
}
|
||||
|
||||
public List<WatchableObject> convert(List<WatchableObject> list) {
|
||||
Iterator<WatchableObject> itel = list.iterator();
|
||||
List<WatchableObject> newList = new ArrayList<WatchableObject>();
|
||||
public List<WrappedWatchableObject> convert(List<WrappedWatchableObject> list) {
|
||||
Iterator<WrappedWatchableObject> itel = list.iterator();
|
||||
List<WrappedWatchableObject> newList = new ArrayList<WrappedWatchableObject>();
|
||||
HashSet<Integer> sentValues = new HashSet<Integer>();
|
||||
boolean sendAllCustom = false;
|
||||
while (itel.hasNext()) {
|
||||
WatchableObject watch = itel.next();
|
||||
int dataType = watch.a();
|
||||
WrappedWatchableObject watch = itel.next();
|
||||
int dataType = watch.getIndex();
|
||||
sentValues.add(dataType);
|
||||
// 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!
|
||||
@ -99,15 +85,15 @@ public class FlagWatcher {
|
||||
value = backupEntityValues.get(dataType);
|
||||
}
|
||||
if (value != null) {
|
||||
boolean doD = watch.d();
|
||||
watch = new WatchableObject(classTypes.get(value.getClass()), dataType, value);
|
||||
boolean doD = watch.getDirtyState();
|
||||
watch = new WrappedWatchableObject(dataType, value);
|
||||
if (!doD)
|
||||
watch.a(false);
|
||||
watch.setDirtyState(doD);
|
||||
} else {
|
||||
boolean doD = watch.d();
|
||||
watch = new WatchableObject(watch.c(), dataType, watch.b());
|
||||
boolean doD = watch.getDirtyState();
|
||||
watch = new WrappedWatchableObject(dataType, watch.getValue());
|
||||
if (!doD)
|
||||
watch.a(false);
|
||||
watch.setDirtyState(doD);
|
||||
}
|
||||
newList.add(watch);
|
||||
}
|
||||
@ -119,16 +105,16 @@ public class FlagWatcher {
|
||||
Object obj = entityValues.get(value);
|
||||
if (obj == null)
|
||||
continue;
|
||||
WatchableObject watch = new WatchableObject(classTypes.get(obj.getClass()), value, obj);
|
||||
WrappedWatchableObject watch = new WrappedWatchableObject(value, obj);
|
||||
newList.add(watch);
|
||||
}
|
||||
}
|
||||
// Here we check for if there is a health packet that says they died.
|
||||
if (disguise.viewSelfDisguise() && disguise.getEntity() != null && disguise.getEntity() instanceof Player) {
|
||||
for (WatchableObject watch : newList) {
|
||||
for (WrappedWatchableObject watch : newList) {
|
||||
// Its a health packet
|
||||
if (watch.a() == 6) {
|
||||
Object value = watch.b();
|
||||
if (watch.getIndex() == 6) {
|
||||
Object value = watch.getValue();
|
||||
if (value != null && value instanceof Float) {
|
||||
float newHealth = (Float) value;
|
||||
if (newHealth > 0 && hasDied) {
|
||||
@ -209,17 +195,16 @@ public class FlagWatcher {
|
||||
return;
|
||||
Entity entity = disguise.getEntity();
|
||||
Object value = entityValues.get(data);
|
||||
List<WatchableObject> list = new ArrayList<WatchableObject>();
|
||||
list.add(new WatchableObject(classTypes.get(value.getClass()), data, value));
|
||||
List<WrappedWatchableObject> list = new ArrayList<WrappedWatchableObject>();
|
||||
list.add(new WrappedWatchableObject(data, value));
|
||||
PacketContainer packet = new PacketContainer(Packets.Server.ENTITY_METADATA);
|
||||
StructureModifier<Object> mods = packet.getModifier();
|
||||
mods.write(0, entity.getEntityId());
|
||||
mods.write(1, list);
|
||||
for (EntityPlayer player : disguise.getPerverts()) {
|
||||
Player p = player.getBukkitEntity();
|
||||
if (DisguiseAPI.isViewDisguises() || p != entity) {
|
||||
packet.getWatchableCollectionModifier().write(0, list);
|
||||
for (Player player : disguise.getPerverts()) {
|
||||
if (DisguiseAPI.isViewDisguises() || player != entity) {
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(p, packet);
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -266,7 +251,7 @@ public class FlagWatcher {
|
||||
// Find the item to replace it with
|
||||
if (disguise.getEntity() instanceof LivingEntity) {
|
||||
EntityEquipment enquipment = ((LivingEntity) disguise.getEntity()).getEquipment();
|
||||
if (slot == 4) {
|
||||
if (slot == 0) {
|
||||
itemStack = enquipment.getItemInHand();
|
||||
} else {
|
||||
itemStack = enquipment.getArmorContents()[slot];
|
||||
@ -276,9 +261,9 @@ public class FlagWatcher {
|
||||
}
|
||||
}
|
||||
|
||||
ItemStack itemToSend = null;
|
||||
Object itemToSend = null;
|
||||
if (itemStack != null && itemStack.getTypeId() != 0)
|
||||
itemToSend = CraftItemStack.asNMSCopy(itemStack);
|
||||
itemToSend = ReflectionManager.getNmsItem(itemStack);
|
||||
items[slot] = itemStack;
|
||||
if (DisguiseAPI.getDisguise(disguise.getEntity()) != disguise)
|
||||
return;
|
||||
@ -290,11 +275,10 @@ public class FlagWatcher {
|
||||
mods.write(0, disguise.getEntity().getEntityId());
|
||||
mods.write(1, slot);
|
||||
mods.write(2, itemToSend);
|
||||
for (EntityPlayer player : disguise.getPerverts()) {
|
||||
Player p = player.getBukkitEntity();
|
||||
if (p != disguise.getEntity()) {
|
||||
for (Player player : disguise.getPerverts()) {
|
||||
if (player != disguise.getEntity()) {
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(p, packet);
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -2,16 +2,10 @@ package me.libraryaddict.disguise.disguisetypes;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import net.minecraft.server.v1_6_R3.EnumEntitySize;
|
||||
|
||||
public class Values {
|
||||
|
||||
private static HashMap<DisguiseType, Values> values = new HashMap<DisguiseType, Values>();
|
||||
|
||||
public static HashMap<String, Double> getAttributesValues(DisguiseType type) {
|
||||
return getValues(type).getAttributesValues();
|
||||
}
|
||||
|
||||
public static Class getEntityClass(DisguiseType type) {
|
||||
return getValues(type).getEntityClass();
|
||||
}
|
||||
@ -47,39 +41,68 @@ public class Values {
|
||||
return values.get(type);
|
||||
}
|
||||
|
||||
private HashMap<String, Double> attributesValues = new HashMap<String, Double>();
|
||||
|
||||
private Class declared;
|
||||
private EnumEntitySize enumEntitySize;
|
||||
private int enumEntitySize;
|
||||
|
||||
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);
|
||||
enumEntitySize = entitySize;
|
||||
declared = classType;
|
||||
}
|
||||
|
||||
public HashMap<String, Double> getAttributesValues() {
|
||||
return attributesValues;
|
||||
}
|
||||
|
||||
public Class getEntityClass() {
|
||||
return declared;
|
||||
}
|
||||
|
||||
public EnumEntitySize getEntitySize() {
|
||||
return enumEntitySize;
|
||||
public int getEntitySize(double paramDouble) {
|
||||
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() {
|
||||
return metaValues;
|
||||
}
|
||||
|
||||
public void setAttributesValue(String attribute, Double value) {
|
||||
attributesValues.put(attribute, value);
|
||||
}
|
||||
|
||||
public void setMetaValue(int no, Object value) {
|
||||
metaValues.put(no, value);
|
||||
}
|
||||
|
@ -7,15 +7,14 @@ public class ArrowWatcher extends FlagWatcher {
|
||||
|
||||
public ArrowWatcher(Disguise disguise) {
|
||||
super(disguise);
|
||||
setValue(16, (byte) 0);
|
||||
}
|
||||
|
||||
public boolean isMoving() {
|
||||
public boolean isCritical() {
|
||||
return (Byte) getValue(16, (byte) 0) == 1;
|
||||
}
|
||||
|
||||
public void setMoving(boolean moving) {
|
||||
setValue(16, (byte) (moving ? 1 : 0));
|
||||
public void setCritical(boolean critical) {
|
||||
setValue(16, (byte) (critical ? 1 : 0));
|
||||
sendData(16);
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import me.libraryaddict.disguise.ReflectionManager;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_6_R3.inventory.CraftItemStack;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class DroppedItemWatcher extends FlagWatcher {
|
||||
@ -13,12 +13,11 @@ public class DroppedItemWatcher extends FlagWatcher {
|
||||
}
|
||||
|
||||
public ItemStack getItemStack() {
|
||||
return CraftItemStack.asBukkitCopy((net.minecraft.server.v1_6_R3.ItemStack) getValue(10,
|
||||
CraftItemStack.asNMSCopy(new ItemStack(1))));
|
||||
return ReflectionManager.getBukkitItem(getValue(10, ReflectionManager.getNmsItem(new ItemStack(1))));
|
||||
}
|
||||
|
||||
public void setItemStack(ItemStack item) {
|
||||
setValue(10, CraftItemStack.asNMSCopy(item));
|
||||
setValue(10, ReflectionManager.getNmsItem(item));
|
||||
sendData(10);
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import me.libraryaddict.disguise.ReflectionManager;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_6_R3.inventory.CraftItemStack;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class ItemFrameWatcher extends FlagWatcher {
|
||||
@ -19,7 +19,7 @@ public class ItemFrameWatcher extends FlagWatcher {
|
||||
public ItemStack getItemStack() {
|
||||
if (getValue(2, null) == null)
|
||||
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) {
|
||||
@ -30,7 +30,7 @@ public class ItemFrameWatcher extends FlagWatcher {
|
||||
public void setItemStack(ItemStack newItem) {
|
||||
newItem = newItem.clone();
|
||||
newItem.setAmount(1);
|
||||
setValue(2, CraftItemStack.asNMSCopy(newItem));
|
||||
setValue(2, ReflectionManager.getNmsItem(newItem));
|
||||
sendData(2);
|
||||
}
|
||||
|
||||
|
@ -1,18 +1,38 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
|
||||
import me.libraryaddict.disguise.ReflectionManager;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
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.PotionEffectType;
|
||||
|
||||
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) {
|
||||
super(disguise);
|
||||
@ -22,21 +42,21 @@ public class LivingWatcher extends FlagWatcher {
|
||||
public void addPotionEffect(PotionEffect potionEffect) {
|
||||
if (hasPotionEffect(potionEffect.getType()))
|
||||
removePotionEffect(potionEffect.getType());
|
||||
potionEffects.add(new MobEffect(potionEffect.getType().getId(), potionEffect.getDuration(), potionEffect.getAmplifier()));
|
||||
potionEffects.add(potionEffect.getType().getId());
|
||||
sendPotionEffects();
|
||||
}
|
||||
|
||||
public void addPotionEffect(PotionEffectType potionEffect) {
|
||||
if (hasPotionEffect(potionEffect))
|
||||
removePotionEffect(potionEffect);
|
||||
potionEffects.add(new MobEffect(potionEffect.getId(), 0, 0));
|
||||
potionEffects.add(potionEffect.getId());
|
||||
sendPotionEffects();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LivingWatcher clone(Disguise disguise) {
|
||||
LivingWatcher clone = (LivingWatcher) super.clone(disguise);
|
||||
clone.potionEffects = (HashSet<MobEffect>) potionEffects.clone();
|
||||
clone.potionEffects = (HashSet<Integer>) potionEffects.clone();
|
||||
return clone;
|
||||
}
|
||||
|
||||
@ -57,10 +77,7 @@ public class LivingWatcher extends FlagWatcher {
|
||||
}
|
||||
|
||||
public boolean hasPotionEffect(PotionEffectType type) {
|
||||
for (MobEffect effect : potionEffects)
|
||||
if (effect.getEffectId() == type.getId())
|
||||
return true;
|
||||
return false;
|
||||
return potionEffects.contains(type.getId());
|
||||
}
|
||||
|
||||
public boolean isCustomNameVisible() {
|
||||
@ -68,14 +85,9 @@ public class LivingWatcher extends FlagWatcher {
|
||||
}
|
||||
|
||||
public void removePotionEffect(PotionEffectType type) {
|
||||
Iterator<MobEffect> itel = potionEffects.iterator();
|
||||
while (itel.hasNext()) {
|
||||
MobEffect effect = itel.next();
|
||||
if (effect.getEffectId() == type.getId()) {
|
||||
itel.remove();
|
||||
if (potionEffects.contains(type.getId())) {
|
||||
potionEffects.remove(type.getId());
|
||||
sendPotionEffects();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -85,10 +97,40 @@ public class LivingWatcher extends FlagWatcher {
|
||||
}
|
||||
|
||||
private void sendPotionEffects() {
|
||||
setValue(7, PotionBrewer.a(potionEffects));
|
||||
setValue(7, getPotions());
|
||||
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) {
|
||||
if (name.length() > 64)
|
||||
name = name.substring(0, 64);
|
||||
|
Loading…
Reference in New Issue
Block a user