Update to 1.14.1, first dev build. Other changes included.

This commit is contained in:
libraryaddict
2019-05-18 18:54:51 +12:00
parent 5208424373
commit a834190209
86 changed files with 1228 additions and 610 deletions

View File

@@ -27,13 +27,13 @@ import me.libraryaddict.disguise.utilities.reflection.FakeBoundingBox;
import me.libraryaddict.disguise.utilities.reflection.LibsProfileLookup;
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import org.apache.commons.io.FileUtils;
import org.apache.logging.log4j.util.Strings;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.BlockFace;
import org.bukkit.craftbukkit.libs.org.apache.commons.io.FileUtils;
import org.bukkit.entity.*;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
@@ -559,13 +559,13 @@ public class DisguiseUtilities {
int entity = disguise.getEntity().getEntityId();
PlayerWatcher watcher = disguise.getWatcher();
PacketContainer setBed = new PacketContainer(Server.BED);
//PacketContainer setBed = new PacketContainer(Server.BED);
int bX = (getChunkCord(playerLocation.getBlockX()) * 16) + 1 + watcher.getSleepingDirection().getModX();
int bZ = (getChunkCord(playerLocation.getBlockZ()) * 16) + 1 + watcher.getSleepingDirection().getModZ();
setBed.getIntegers().write(0, entity);
setBed.getBlockPositionModifier().write(0, new BlockPosition(bX, 0, bZ));
// setBed.getIntegers().write(0, entity);
// setBed.getBlockPositionModifier().write(0, new BlockPosition(bX, 0, bZ));
PacketContainer teleport = new PacketContainer(Server.ENTITY_TELEPORT);
@@ -577,7 +577,7 @@ public class DisguiseUtilities {
doubles.write(1, DisguiseUtilities.getYModifier(disguise.getEntity(), disguise) + sleepingLocation.getY());
doubles.write(2, sleepingLocation.getZ());
return new PacketContainer[]{setBed, teleport};
return new PacketContainer[]{teleport};
}
public static Disguise getClonedDisguise(String key) {
@@ -903,10 +903,13 @@ public class DisguiseUtilities {
}
for (Constructor constructor : chunkClass.getConstructors()) {
if (constructor.getParameterTypes().length != 8)
if (constructor.getParameterTypes().length != 9)
continue;
bedChunk = constructor.newInstance(world, 0, 0, biomes, null, null, null, 0L);
Object cords = ReflectionManager.getNmsConstructor("ChunkCoordIntPair", int.class, int.class)
.newInstance(0, 0);
bedChunk = constructor.newInstance(world, cords, biomes, null, null, null, 0L, null, null);
break;
}
@@ -917,8 +920,8 @@ public class DisguiseUtilities {
Field cSection = chunkClass.getDeclaredField("sections");
cSection.setAccessible(true);
Object chunkSection = ReflectionManager.getNmsClass("ChunkSection").getConstructor(int.class, boolean.class)
.newInstance(0, true);
Object chunkSection = ReflectionManager.getNmsClass("ChunkSection").getConstructor(int.class)
.newInstance(0);
Class blockClass = ReflectionManager.getNmsClass("Block");
Object REGISTRY = ReflectionManager.getNmsField("IRegistry", "BLOCK").get(null);
@@ -938,8 +941,6 @@ public class DisguiseUtilities {
Method setType = chunkSection.getClass()
.getMethod("setType", int.class, int.class, int.class, ReflectionManager.getNmsClass("IBlockData"));
Method setSky = chunkSection.getClass().getMethod("a", int.class, int.class, int.class, int.class);
Method setEmitted = chunkSection.getClass().getMethod("b", int.class, int.class, int.class, int.class);
for (BlockFace face : new BlockFace[]{BlockFace.EAST, BlockFace.WEST, BlockFace.NORTH, BlockFace.SOUTH}) {
int x = 1 + face.getModX();
@@ -961,7 +962,7 @@ public class DisguiseUtilities {
.createPacketConstructor(PacketType.Play.Server.MAP_CHUNK, bedChunk, 65535)
.createPacket(bedChunk, 65535);
Field threadField = ReflectionManager.getNmsField("MinecraftServer", "primaryThread");
Field threadField = ReflectionManager.getNmsField("MinecraftServer", "serverThread");
threadField.setAccessible(true);
mainThread = (Thread) threadField.get(ReflectionManager.getMinecraftServer());
@@ -1036,10 +1037,10 @@ public class DisguiseUtilities {
.get(entityTrackerEntry);
Method clear = ReflectionManager
.getNmsMethod("EntityTrackerEntry", "clear", ReflectionManager.getNmsClass("EntityPlayer"));
.getNmsMethod("EntityTrackerEntry", "a", ReflectionManager.getNmsClass("EntityPlayer"));
final Method updatePlayer = ReflectionManager.getNmsMethod("EntityTrackerEntry", "updatePlayer",
ReflectionManager.getNmsClass("EntityPlayer"));
final Method updatePlayer = ReflectionManager
.getNmsMethod("EntityTrackerEntry", "b", ReflectionManager.getNmsClass("EntityPlayer"));
trackedPlayers = (Set) new HashSet(trackedPlayers).clone(); // Copy before iterating to prevent
// ConcurrentModificationException
@@ -1090,10 +1091,10 @@ public class DisguiseUtilities {
.get(entityTrackerEntry);
Method clear = ReflectionManager
.getNmsMethod("EntityTrackerEntry", "clear", ReflectionManager.getNmsClass("EntityPlayer"));
.getNmsMethod("EntityTrackerEntry", "a", ReflectionManager.getNmsClass("EntityPlayer"));
final Method updatePlayer = ReflectionManager.getNmsMethod("EntityTrackerEntry", "updatePlayer",
ReflectionManager.getNmsClass("EntityPlayer"));
final Method updatePlayer = ReflectionManager
.getNmsMethod("EntityTrackerEntry", "b", ReflectionManager.getNmsClass("EntityPlayer"));
trackedPlayers = (Set) new HashSet(trackedPlayers).clone(); // Copy before iterating to prevent
// ConcurrentModificationException
@@ -1161,10 +1162,10 @@ public class DisguiseUtilities {
.get(entityTrackerEntry);
final Method clear = ReflectionManager
.getNmsMethod("EntityTrackerEntry", "clear", ReflectionManager.getNmsClass("EntityPlayer"));
.getNmsMethod("EntityTrackerEntry", "a", ReflectionManager.getNmsClass("EntityPlayer"));
final Method updatePlayer = ReflectionManager.getNmsMethod("EntityTrackerEntry", "updatePlayer",
ReflectionManager.getNmsClass("EntityPlayer"));
final Method updatePlayer = ReflectionManager
.getNmsMethod("EntityTrackerEntry", "b", ReflectionManager.getNmsClass("EntityPlayer"));
trackedPlayers = (Set) new HashSet(trackedPlayers).clone();
@@ -1567,7 +1568,7 @@ public class DisguiseUtilities {
boolean isMoving = false;
try {
Field field = ReflectionManager.getNmsClass("EntityTrackerEntry").getDeclaredField("isMoving");
Field field = ReflectionManager.getNmsClass("EntityTrackerEntry").getDeclaredField("q");
field.setAccessible(true);
isMoving = field.getBoolean(entityTrackerEntry);
}
@@ -1630,10 +1631,10 @@ public class DisguiseUtilities {
// If the disguised is sleeping for w/e reason
if (player.isSleeping()) {
sendSelfPacket(player,
/* sendSelfPacket(player,
manager.createPacketConstructor(Server.BED, player, ReflectionManager.getBlockPosition(0, 0, 0))
.createPacket(player, ReflectionManager
.getBlockPosition(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())));
.getBlockPosition(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())));*/
}
// Resend any active potion effects
@@ -1811,7 +1812,6 @@ public class DisguiseUtilities {
case WITHER_SKULL:
return (byte) (value - 128);
case ARROW:
case TIPPED_ARROW:
case SPECTRAL_ARROW:
return (byte) -value;
case PAINTING:
@@ -1832,8 +1832,7 @@ public class DisguiseUtilities {
public static double getYModifier(Entity entity, Disguise disguise) {
double yMod = 0;
if ((disguise.getType() != DisguiseType.PLAYER || !((PlayerWatcher) disguise.getWatcher()).isSleeping()) &&
entity.getType() == EntityType.DROPPED_ITEM) {
if (disguise.getType() != DisguiseType.PLAYER && entity.getType() == EntityType.DROPPED_ITEM) {
yMod -= 0.13;
}
@@ -1859,7 +1858,7 @@ public class DisguiseUtilities {
default:
return yMod + 0.4;
}
case TIPPED_ARROW:
case ARROW:
case SPECTRAL_ARROW:
case BOAT:
case EGG:
@@ -1873,12 +1872,6 @@ public class DisguiseUtilities {
case THROWN_EXP_BOTTLE:
case WITHER_SKULL:
return yMod + 0.7;
case PLAYER:
if (DisguiseConfig.isBedPacketsEnabled() && ((PlayerWatcher) disguise.getWatcher()).isSleeping()) {
return yMod + 0.35;
}
break;
case DROPPED_ITEM:
return yMod + 0.13;
default:

View File

@@ -1,6 +1,7 @@
package me.libraryaddict.disguise.utilities;
import com.comphenix.protocol.PacketType;
import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
import org.bukkit.configuration.file.YamlConfiguration;
@@ -235,9 +236,6 @@ public class LibsPremium {
}
}
/**
* Add a naughty message for the invalid user ids
*/
private static String getSanitizedUser(String userID) {
if (userID == null) {
return "N/A";
@@ -247,13 +245,19 @@ public class LibsPremium {
return String.format("... %s? Am I reading this right?", userID);
}
return userID;
int total = 0;
for (char c : userID.toCharArray()) {
total += Character.getNumericValue(c);
}
return String.format("%s(%s)", userID, total);
}
public static void check(String version) {
thisPluginIsPaidFor = isPremium();
if (!isPremium()) {
if (!isPremium() || !LibsDisguises.getInstance().isReleaseBuild()) {
doSecondaryCheck(version);
} else {
DisguiseUtilities.getLogger().info("Registered to: " + getSanitizedUser(getUserID()));

View File

@@ -1,7 +1,7 @@
package me.libraryaddict.disguise.utilities;
import com.google.gson.Gson;
import org.apache.commons.io.IOUtils;
import org.bukkit.craftbukkit.libs.org.apache.commons.io.IOUtils;
import java.io.InputStream;
import java.io.OutputStream;

View File

@@ -6,13 +6,9 @@ import com.comphenix.protocol.wrappers.WrappedGameProfile;
import com.google.gson.*;
import com.google.gson.reflect.TypeToken;
import com.mojang.authlib.properties.PropertyMap;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import me.libraryaddict.disguise.disguisetypes.*;
import me.libraryaddict.disguise.disguisetypes.watchers.ArrowWatcher;
import org.bukkit.inventory.ItemStack;
import sun.reflect.generics.tree.BaseType;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
@@ -67,23 +63,30 @@ public class SerializerFlagWatcher implements JsonDeserializer<FlagWatcher>, Jso
HashMap<Integer, Object> map = (HashMap<Integer, Object>) field.get(watcher);
for (Map.Entry<Integer, Object> entry : map.entrySet()) {
if (!(entry.getValue() instanceof Double))
continue;
if (entry.getValue() instanceof Double) {
MetaIndex index = MetaIndex.getMetaIndex(flagWatcher, entry.getKey());
MetaIndex index = MetaIndex.getMetaIndex(flagWatcher, entry.getKey());
Object def = index.getDefault();
Object def = index.getDefault();
if (def instanceof Long)
entry.setValue(((Double) entry.getValue()).longValue());
else if (def instanceof Float)
entry.setValue(((Double) entry.getValue()).floatValue());
else if (def instanceof Integer)
entry.setValue(((Double) entry.getValue()).intValue());
else if (def instanceof Short)
entry.setValue(((Double) entry.getValue()).shortValue());
else if (def instanceof Byte)
entry.setValue(((Double) entry.getValue()).byteValue());
} else if (entry.getValue() instanceof Map) {
MetaIndex index = MetaIndex.getMetaIndex(flagWatcher, entry.getKey());
if (def instanceof Long)
entry.setValue(((Double) entry.getValue()).longValue());
else if (def instanceof Float)
entry.setValue(((Double) entry.getValue()).floatValue());
else if (def instanceof Integer)
entry.setValue(((Double) entry.getValue()).intValue());
else if (def instanceof Short)
entry.setValue(((Double) entry.getValue()).shortValue());
else if (def instanceof Byte)
entry.setValue(((Double) entry.getValue()).byteValue());
if (!(index.getDefault() instanceof VillagerData)) {
continue;
}
entry.setValue(new Gson().fromJson(new Gson().toJson(entry.getValue()),VillagerData.class));
}
}
}

View File

@@ -23,6 +23,6 @@ public class SerializerItemStack implements JsonSerializer<ItemStack>, JsonDeser
@Override
public ItemStack deserialize(JsonElement json, Type typeOfT,
JsonDeserializationContext context) throws JsonParseException {
return ItemStack.deserialize((Map<String, Object>) context.deserialize(json, HashMap.class));
return ItemStack.deserialize(context.deserialize(json, HashMap.class));
}
}

View File

@@ -14,6 +14,7 @@ import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.logging.Level;
import java.util.zip.GZIPOutputStream;
@@ -321,7 +322,7 @@ public class Metrics {
}
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
GZIPOutputStream gzip = new GZIPOutputStream(outputStream);
gzip.write(str.getBytes("UTF-8"));
gzip.write(str.getBytes(StandardCharsets.UTF_8));
gzip.close();
return outputStream.toByteArray();
}

View File

@@ -136,11 +136,6 @@ public class PacketsManager {
packetsToListen.add(Server.UPDATE_ATTRIBUTES);
}
// The bed packet.
if (DisguiseConfig.isBedPacketsEnabled()) {
packetsToListen.add(Server.BED);
}
// Add movement packets
if (DisguiseConfig.isMovementPacketsEnabled()) {
packetsToListen.add(Server.ENTITY_LOOK);

View File

@@ -23,8 +23,7 @@ public class PacketHandlerAnimation implements IPacketHandler {
public void handle(Disguise disguise, PacketContainer sentPacket, LibsPackets packets, Player observer,
Entity entity) {
// Else if the disguise is attempting to send players a forbidden packet
if (disguise.getType().isMisc() || (sentPacket.getIntegers().read(1) == 2 && (!disguise.getType().isPlayer() ||
(DisguiseConfig.isBedPacketsEnabled() && ((PlayerWatcher) disguise.getWatcher()).isSleeping())))) {
if (disguise.getType().isMisc()) {
packets.clear();
}
}

View File

@@ -14,7 +14,7 @@ import org.bukkit.entity.Player;
public class PacketHandlerBed implements IPacketHandler {
@Override
public PacketType[] getHandledPackets() {
return new PacketType[]{PacketType.Play.Server.BED};
return new PacketType[]{};
}
@Override

View File

@@ -25,18 +25,6 @@ public class PacketHandlerCollect implements IPacketHandler {
Entity entity) {
if (disguise.getType().isMisc()) {
packets.clear();
} else if (DisguiseConfig.isBedPacketsEnabled() && disguise.getType().isPlayer() &&
((PlayerWatcher) disguise.getWatcher()).isSleeping()) {
PacketContainer newPacket = new PacketContainer(PacketType.Play.Server.ANIMATION);
StructureModifier<Integer> mods = newPacket.getIntegers();
mods.write(0, disguise.getEntity().getEntityId());
mods.write(1, 3);
packets.clear();
packets.addPacket(newPacket);
packets.addPacket(sentPacket);
}
}
}

View File

@@ -240,15 +240,7 @@ public class PacketHandlerSpawn implements IPacketHandler {
packets.addPacket(spawnPlayer);
if (DisguiseConfig.isBedPacketsEnabled() && ((PlayerWatcher) disguise.getWatcher()).isSleeping()) {
PacketContainer[] bedPackets = DisguiseUtilities.getBedPackets(
loc.clone().subtract(0, DisguiseUtilities.getYModifier(disguisedEntity, disguise), 0),
observer.getLocation(), ((PlayerDisguise) disguise));
for (PacketContainer packet : bedPackets) {
packets.addPacket(packet);
}
} else if (!selfDisguise) {
if (!selfDisguise) {
// Teleport the player back to where he's supposed to be
PacketContainer teleportPacket = new PacketContainer(PacketType.Play.Server.ENTITY_TELEPORT);
@@ -336,7 +328,6 @@ public class PacketHandlerSpawn implements IPacketHandler {
.createSanitizedDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity),
disguise.getWatcher()));
} else if (disguise.getType().isMisc()) {
int objectId = disguise.getType().getObjectId();
int data = ((MiscDisguise) disguise).getData();
if (disguise.getType() == DisguiseType.FALLING_BLOCK) {
@@ -351,11 +342,14 @@ public class PacketHandlerSpawn implements IPacketHandler {
data = ((((int) loc.getYaw() % 360) + 720 + 45) / 90) % 4;
}
Object nmsEntity = ReflectionManager.getNmsEntity(disguisedEntity);
Object entityType = ReflectionManager.getEntityType(disguise.getType().getEntityType());
Object[] params = new Object[]{disguisedEntity.getEntityId(), disguisedEntity.getUniqueId(), loc.getX(),
loc.getY(), loc.getZ(), loc.getPitch(), loc.getYaw(), entityType, data,
ReflectionManager.getVec3D(disguisedEntity.getVelocity())};
PacketContainer spawnEntity = ProtocolLibrary.getProtocolManager()
.createPacketConstructor(PacketType.Play.Server.SPAWN_ENTITY, nmsEntity, objectId, data)
.createPacket(nmsEntity, objectId, data);
.createPacketConstructor(PacketType.Play.Server.SPAWN_ENTITY, params).createPacket(params);
packets.addPacket(spawnEntity);
// If it's not the same type, then highly likely they have different velocity settings which we'd want to

View File

@@ -26,7 +26,7 @@ public class PacketListenerViewSelfDisguise extends PacketAdapter {
public PacketListenerViewSelfDisguise(LibsDisguises plugin) {
super(plugin, ListenerPriority.HIGH, Server.NAMED_ENTITY_SPAWN, Server.ATTACH_ENTITY, Server.REL_ENTITY_MOVE,
Server.REL_ENTITY_MOVE_LOOK, Server.ENTITY_LOOK, Server.ENTITY_TELEPORT, Server.ENTITY_HEAD_ROTATION,
Server.ENTITY_METADATA, Server.ENTITY_EQUIPMENT, Server.ANIMATION, Server.BED, Server.ENTITY_EFFECT,
Server.ENTITY_METADATA, Server.ENTITY_EQUIPMENT, Server.ANIMATION, Server.ENTITY_EFFECT,
Server.ENTITY_VELOCITY, Server.UPDATE_ATTRIBUTES, Server.ENTITY_STATUS);
}

View File

@@ -5,6 +5,7 @@ import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.disguisetypes.*;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.parser.params.ParamInfo;
import me.libraryaddict.disguise.utilities.parser.params.ParamInfoManager;
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import me.libraryaddict.disguise.utilities.translations.TranslateType;

View File

@@ -1,9 +1,10 @@
package me.libraryaddict.disguise.utilities.parser;
package me.libraryaddict.disguise.utilities.parser.params;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
import me.libraryaddict.disguise.utilities.parser.DisguisePerm;
import me.libraryaddict.disguise.utilities.parser.params.ParamInfo;
import me.libraryaddict.disguise.utilities.parser.params.ParamInfoTypes;
import org.bukkit.ChatColor;

View File

@@ -4,6 +4,7 @@ import com.comphenix.protocol.wrappers.BlockPosition;
import com.comphenix.protocol.wrappers.WrappedGameProfile;
import com.comphenix.protocol.wrappers.WrappedParticle;
import me.libraryaddict.disguise.disguisetypes.AnimalColor;
import me.libraryaddict.disguise.disguisetypes.EntityPose;
import me.libraryaddict.disguise.disguisetypes.RabbitType;
import me.libraryaddict.disguise.utilities.parser.params.types.ParamInfoEnum;
import me.libraryaddict.disguise.utilities.parser.params.types.base.*;
@@ -31,15 +32,13 @@ public class ParamInfoTypes {
List<ParamInfo> paramInfos = new ArrayList<>();
// Register enum types
paramInfos.add(new ParamInfoEnum(AnimalColor.class, "Animal Color",
"View all the colors you can use for an animal color"));
//paramInfos.add(new ParamInfoEnum(AnimalColor.class, "Animal Color",
// "View all the colors you can use for an animal color"));
paramInfos
.add(new ParamInfoEnum(Art.class, "Art", "View all the paintings you can use for a painting disguise"));
paramInfos.add(new ParamInfoEnum(Horse.Color.class, "Horse Color",
"View all the colors you can use for a horses color"));
paramInfos.add(new ParamInfoEnum(Ocelot.Type.class, "Ocelot Type",
"View all the ocelot types you can use for ocelots"));
paramInfos.add(new ParamInfoEnum(Villager.Profession.class, "Villager Profession",
"View all the professions you can set on a Zombie and Normal Villager"));
paramInfos.add(new ParamInfoEnum(BlockFace.class, "Direction", "Direction (North, East, South, West, Up, Down)",
@@ -61,6 +60,12 @@ public class ParamInfoTypes {
paramInfos.add(new ParamInfoEnum(DyeColor.class, "DyeColor", "Dye colors of many different colors"));
paramInfos.add(new ParamInfoEnum(Horse.Style.class, "Horse Style",
"Horse style which is the patterns on the horse"));
paramInfos.add(new ParamInfoEnum(EntityPose.class, "EntityPose", "The pose the entity should strike"));
paramInfos.add(new ParamInfoEnum(Cat.Type.class, "Cat Type", "The type of cat"));
paramInfos.add(new ParamInfoEnum(Fox.Type.class, "Fox Type", "The type of fox"));
paramInfos.add(new ParamInfoEnum(Panda.Gene.class, "Panda Gene", "The panda gene type"));
paramInfos.add(new ParamInfoEnum(MushroomCow.Variant.class, "Mushroom Cow Variant",
"The different variants for mushroom cows"));
// Register custom types
paramInfos.add(new ParamInfoEulerAngle(EulerAngle.class, "Euler Angle", "Euler Angle (X,Y,Z)",

View File

@@ -5,7 +5,7 @@ import com.comphenix.protocol.wrappers.WrappedParticle;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import me.libraryaddict.disguise.utilities.parser.DisguiseParseException;
import me.libraryaddict.disguise.utilities.parser.params.types.ParamInfoEnum;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Color;
import org.bukkit.Material;
import org.bukkit.Particle;

View File

@@ -36,10 +36,6 @@ public class DisguiseValues {
return babyBox;
}
public float[] getEntitySize() {
return entitySize;
}
public double getMaxHealth() {
return maxHealth;
}
@@ -55,8 +51,4 @@ public class DisguiseValues {
public void setBabyBox(FakeBoundingBox newBox) {
babyBox = newBox;
}
public void setEntitySize(float[] size) {
this.entitySize = size;
}
}

View File

@@ -1,21 +1,32 @@
package me.libraryaddict.disguise.utilities.reflection;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.reflect.cloning.AggregateCloner;
import com.comphenix.protocol.wrappers.*;
import com.comphenix.protocol.wrappers.EnumWrappers.Direction;
import com.comphenix.protocol.wrappers.WrappedDataWatcher.Registry;
import com.comphenix.protocol.wrappers.WrappedDataWatcher.Serializer;
import com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject;
import com.comphenix.protocol.wrappers.nbt.NbtWrapper;
import com.mojang.datafixers.Dynamic;
import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import org.apache.commons.io.IOUtils;
import me.libraryaddict.disguise.disguisetypes.EntityPose;
import me.libraryaddict.disguise.disguisetypes.VillagerData;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import net.minecraft.server.v1_14_R1.IRegistry;
import org.bukkit.*;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.craftbukkit.libs.it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import org.bukkit.craftbukkit.libs.org.apache.commons.io.IOUtils;
import org.bukkit.craftbukkit.v1_14_R1.util.CraftNamespacedKey;
import org.bukkit.entity.*;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.util.Vector;
import java.io.IOException;
import java.io.InputStream;
@@ -23,22 +34,24 @@ import java.lang.reflect.*;
import java.nio.ByteBuffer;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
public class ReflectionManager {
private static final String bukkitVersion = Bukkit.getServer().getClass().getName().split("\\.")[3];
private static final Class<?> craftItemClass;
private static Method damageAndIdleSoundMethod;
private static final Field entitiesField;
private static final Constructor<?> boundingBoxConstructor;
private static final Method setBoundingBoxMethod;
private static final Method ihmGet;
private static final Field pingField;
private static final Field trackerField;
public static final Field entityCountField;
private static final Field chunkMapField;
private static final Field chunkProviderField;
private static final Field entityTrackerField;
private static final Field trackedEntitiesField;
static {
try {
Object entity = createEntityInstance("Cow");
Object entity = createEntityInstance(DisguiseType.COW, "Cow");
for (Method method : getNmsClass("EntityLiving").getDeclaredMethods()) {
if (method.getReturnType() != float.class)
@@ -69,11 +82,10 @@ public class ReflectionManager {
pingField = getNmsField("EntityPlayer", "ping");
trackerField = getNmsField("WorldServer", "tracker");
entitiesField = getNmsField("EntityTracker", "trackedEntities");
ihmGet = getNmsMethod("IntHashMap", "get", int.class);
chunkProviderField = getNmsField("World", "chunkProvider");
chunkMapField = getNmsField("ChunkProviderServer", "playerChunkMap");
trackedEntitiesField = getNmsField("PlayerChunkMap", "trackedEntities");
entityTrackerField = getNmsField("PlayerChunkMap$EntityTracker", "trackerEntry");
boundingBoxConstructor = getNmsConstructor("AxisAlignedBB", double.class, double.class, double.class,
double.class, double.class, double.class);
@@ -105,10 +117,14 @@ public class ReflectionManager {
public static int getNewEntityId(boolean increment) {
try {
int id = entityCountField.getInt(null);
AtomicInteger entityCount = (AtomicInteger) entityCountField.get(null);
int id;
if (increment) {
entityCountField.set(null, id + 1);
id = entityCount.getAndIncrement();
} else {
id = entityCount.get();
}
return id;
@@ -120,7 +136,7 @@ public class ReflectionManager {
return -1;
}
public static Object createEntityInstance(String entityName) {
public static Object createEntityInstance(DisguiseType disguiseType, String entityName) {
try {
Class<?> entityClass = getNmsClass("Entity" + entityName);
Object entityObject;
@@ -131,7 +147,7 @@ public class ReflectionManager {
Object minecraftServer = getNmsMethod("MinecraftServer", "getServer").invoke(null);
Object playerinteractmanager = getNmsClass("PlayerInteractManager")
.getDeclaredConstructor(getNmsClass("World")).newInstance(world);
.getDeclaredConstructor(getNmsClass("WorldServer")).newInstance(world);
WrappedGameProfile gameProfile = getGameProfile(new UUID(0, 0), "Steve");
@@ -142,26 +158,25 @@ public class ReflectionManager {
break;
case "EnderPearl":
entityObject = entityClass.getDeclaredConstructor(getNmsClass("World"), getNmsClass("EntityLiving"))
.newInstance(world, createEntityInstance("Cow"));
break;
case "Potion":
entityObject = entityClass
.getDeclaredConstructor(getNmsClass("World"), Double.TYPE, Double.TYPE, Double.TYPE,
getNmsClass("ItemStack"))
.newInstance(world, 0d, 0d, 0d, getNmsItem(new ItemStack(Material.SPLASH_POTION)));
.newInstance(world, createEntityInstance(DisguiseType.COW, "Cow"));
break;
case "FishingHook":
entityObject = entityClass.getDeclaredConstructor(getNmsClass("World"), getNmsClass("EntityHuman"))
.newInstance(world, createEntityInstance("Player"));
entityObject = entityClass
.getDeclaredConstructor(getNmsClass("EntityHuman"), getNmsClass("World"), int.class,
int.class)
.newInstance(createEntityInstance(DisguiseType.PLAYER, "Player"), world, 0, 0);
break;
default:
entityObject = entityClass.getDeclaredConstructor(getNmsClass("World")).newInstance(world);
entityObject = entityClass.getDeclaredConstructor(getNmsClass("EntityTypes"), getNmsClass("World"))
.newInstance(getEntityType(disguiseType.getEntityType()), world);
break;
}
return entityObject;
}
catch (Exception e) {
DisguiseUtilities.getLogger()
.warning("Error while attempting to create entity instance for " + disguiseType.name());
e.printStackTrace();
}
@@ -315,10 +330,17 @@ public class ReflectionManager {
public static Object getEntityTrackerEntry(Entity target) throws Exception {
Object world = getWorldServer(target.getWorld());
Object tracker = trackerField.get(world);
Object trackedEntities = entitiesField.get(tracker);
Object chunkProvider = chunkProviderField.get(world);
Object chunkMap = chunkMapField.get(chunkProvider);
Int2ObjectMap trackedEntities = (Int2ObjectMap) trackedEntitiesField.get(chunkMap);
return ihmGet.invoke(trackedEntities, target.getEntityId());
Object entityTracker = trackedEntities.get(target.getEntityId());
if (entityTracker == null) {
return null;
}
return entityTrackerField.get(entityTracker);
}
public static Object getMinecraftServer() {
@@ -588,11 +610,13 @@ public class ReflectionManager {
public static float[] getSize(Entity entity) {
try {
float length = getNmsField("Entity", "length").getFloat(getNmsEntity(entity));
float width = getNmsField("Entity", "width").getFloat(getNmsEntity(entity));
Object size = getNmsField("Entity", "size").get(getNmsEntity(entity));
float height = (Float) getNmsMethod("Entity", "getHeadHeight").invoke(getNmsEntity(entity));
return new float[]{length, width, height};
//float length = getNmsField("EntitySize", "length").getFloat(size);
float width = getNmsField("EntitySize", "width").getFloat(size);
float height = getNmsField("Entity", "headHeight").getFloat(getNmsEntity(entity));
return new float[]{width, height};
}
catch (Exception ex) {
ex.printStackTrace();
@@ -884,11 +908,64 @@ public class ReflectionManager {
return ((NbtWrapper) value).getHandle();
} else if (value instanceof WrappedParticle) {
return ((WrappedParticle) value).getHandle();
} else if (value instanceof EntityPose) {
return getNmsEntityPose((EntityPose) value);
} else if (value instanceof VillagerData) {
return getNmsVillagerData((VillagerData) value);
}
return value;
}
public static Object getNmsVillagerData(VillagerData data) {
Object type = getVillagerType(data.getType());
Object profession = getVillagerProfession(data.getProfession());
try {
return getNmsConstructor("VillagerData", getNmsClass("VillagerType"), profession.getClass(), int.class)
.newInstance(type, profession, data.getLevel());
}
catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static Object getVillagerType(Villager.Type type) {
try {
Object villagerType = getNmsField("IRegistry", "VILLAGER_TYPE").get(null);
Method toMinecraft = getCraftMethod("util.CraftNamespacedKey", "toMinecraft", NamespacedKey.class);
Object mcKey = toMinecraft.invoke(null, type.getKey());
Method getField = getNmsMethod("RegistryBlocks", "get", mcKey.getClass());
return getField.invoke(villagerType, mcKey);
}
catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static Object getVillagerProfession(Villager.Profession profession) {
try {
Object villagerProfession = getNmsField("IRegistry", "VILLAGER_PROFESSION").get(null);
Method toMinecraft = getCraftMethod("util.CraftNamespacedKey", "toMinecraft", NamespacedKey.class);
Object mcKey = toMinecraft.invoke(null, profession.getKey());
Method getField = getNmsMethod("RegistryBlocks", "get", mcKey.getClass());
return getField.invoke(villagerProfession, mcKey);
}
catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static String getMinecraftVersion() {
String version = Bukkit.getVersion();
version = version.substring(version.lastIndexOf(" ") + 1, version.length() - 1);
@@ -976,27 +1053,57 @@ public class ReflectionManager {
return null;
}
public static int getEntityType(Object nmsEntity) {
public static Object getVec3D(Vector vector) {
try {
Field entityTypesField = null;
Constructor c = getNmsConstructor("Vec3D", double.class, double.class, double.class);
for (Method method : getNmsClass("Entity").getMethods()) {
if (!method.getReturnType().getSimpleName().equals("EntityTypes"))
continue;
Object entityType = method.invoke(nmsEntity);
Class typesClass = getNmsClass("IRegistry");
Object registry = typesClass.getField("ENTITY_TYPE").get(null);
return (int) registry.getClass().getMethod("a", Object.class).invoke(registry, entityType);
}
return c.newInstance(vector.getX(), vector.getY(), vector.getZ());
}
catch (Exception ex) {
ex.printStackTrace();
}
throw new IllegalStateException("Failed to find EntityType for " + nmsEntity.getClass().getSimpleName());
return null;
}
public static Object getEntityType(EntityType entityType) {
try {
Method entityTypes = getNmsMethod("EntityTypes", "a", String.class);
Optional<Object> entityObj = (Optional<Object>) entityTypes.invoke(null, entityType.getName());
return entityObj.orElse(null);
}
catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static int getEntityTypeId(EntityType entityType) {
try {
Object entityTypes = getEntityType(entityType);
Class typesClass = getNmsClass("IRegistry");
Object registry = typesClass.getField("ENTITY_TYPE").get(null);
return (int) registry.getClass().getMethod("a", Object.class).invoke(registry, entityTypes);
}
catch (Exception ex) {
ex.printStackTrace();
}
throw new IllegalStateException("Failed to find EntityType id for " + entityType);
}
public static Object getNmsEntityPose(EntityPose entityPose) {
return Enum.valueOf(getNmsClass("EntityPose"), entityPose.name());
}
public static EntityPose getEntityPose(Object nmsEntityPose) {
return EntityPose.valueOf(((Enum) nmsEntityPose).name());
}
public static WrappedWatchableObject createWatchable(int index, Object obj) {

View File

@@ -1,7 +1,7 @@
package me.libraryaddict.disguise.utilities.translations;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
/**

View File

@@ -2,7 +2,7 @@ package me.libraryaddict.disguise.utilities.translations;
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.utilities.reflection.ClassGetter;
import me.libraryaddict.disguise.utilities.parser.ParamInfoManager;
import me.libraryaddict.disguise.utilities.parser.params.ParamInfoManager;
import me.libraryaddict.disguise.utilities.parser.params.ParamInfo;
import org.apache.commons.lang.StringUtils;
import org.bukkit.entity.Entity;