2019-01-03 03:13:03 +01:00
|
|
|
package me.libraryaddict.disguise.utilities.reflection;
|
|
|
|
|
2020-01-19 03:48:26 +01:00
|
|
|
import com.comphenix.protocol.reflect.FieldAccessException;
|
2019-01-03 03:13:03 +01:00
|
|
|
import com.comphenix.protocol.wrappers.*;
|
|
|
|
import com.comphenix.protocol.wrappers.EnumWrappers.Direction;
|
|
|
|
import com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject;
|
|
|
|
import com.comphenix.protocol.wrappers.nbt.NbtWrapper;
|
2020-08-13 01:51:32 +02:00
|
|
|
import com.mojang.authlib.GameProfile;
|
2019-01-03 03:13:03 +01:00
|
|
|
import me.libraryaddict.disguise.DisguiseConfig;
|
2020-01-19 03:48:26 +01:00
|
|
|
import me.libraryaddict.disguise.LibsDisguises;
|
|
|
|
import me.libraryaddict.disguise.disguisetypes.*;
|
|
|
|
import me.libraryaddict.disguise.disguisetypes.watchers.*;
|
2020-03-08 21:00:58 +01:00
|
|
|
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
|
|
|
import me.libraryaddict.disguise.utilities.DisguiseValues;
|
|
|
|
import me.libraryaddict.disguise.utilities.LibsPremium;
|
2020-05-23 12:48:50 +02:00
|
|
|
import me.libraryaddict.disguise.utilities.sounds.SoundGroup;
|
2020-01-19 03:48:26 +01:00
|
|
|
import org.apache.commons.lang.ArrayUtils;
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
2019-01-03 03:13:03 +01:00
|
|
|
import org.bukkit.*;
|
2020-08-11 23:36:13 +02:00
|
|
|
import org.bukkit.block.data.BlockData;
|
2020-04-27 14:09:05 +02:00
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandMap;
|
|
|
|
import org.bukkit.command.SimpleCommandMap;
|
2019-01-03 03:13:03 +01:00
|
|
|
import org.bukkit.configuration.file.YamlConfiguration;
|
|
|
|
import org.bukkit.entity.*;
|
|
|
|
import org.bukkit.inventory.EquipmentSlot;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
2019-12-21 02:45:10 +01:00
|
|
|
import org.bukkit.inventory.meta.ItemMeta;
|
2020-04-27 14:09:05 +02:00
|
|
|
import org.bukkit.plugin.SimplePluginManager;
|
2019-01-03 03:13:03 +01:00
|
|
|
import org.bukkit.potion.PotionEffect;
|
2021-02-04 16:29:55 +01:00
|
|
|
import org.bukkit.scheduler.BukkitRunnable;
|
2021-01-27 07:19:24 +01:00
|
|
|
import org.bukkit.scoreboard.Scoreboard;
|
2021-05-04 13:06:55 +02:00
|
|
|
import org.bukkit.util.EulerAngle;
|
2019-05-18 08:54:51 +02:00
|
|
|
import org.bukkit.util.Vector;
|
2019-01-03 03:13:03 +01:00
|
|
|
|
2020-11-11 00:32:53 +01:00
|
|
|
import java.io.*;
|
2019-01-03 03:13:03 +01:00
|
|
|
import java.lang.reflect.*;
|
|
|
|
import java.nio.ByteBuffer;
|
2020-02-13 07:47:02 +01:00
|
|
|
import java.nio.charset.StandardCharsets;
|
2020-08-05 14:43:21 +02:00
|
|
|
import java.util.*;
|
2019-05-18 08:54:51 +02:00
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
2021-01-27 07:19:24 +01:00
|
|
|
import java.util.function.Consumer;
|
2020-04-17 04:08:21 +02:00
|
|
|
import java.util.jar.JarEntry;
|
|
|
|
import java.util.jar.JarFile;
|
2020-02-13 07:47:02 +01:00
|
|
|
import java.util.stream.Collectors;
|
2019-01-03 03:13:03 +01:00
|
|
|
|
|
|
|
public class ReflectionManager {
|
2020-08-13 01:51:32 +02:00
|
|
|
private static final HashMap<String, Enum> soundCategories = new HashMap<>();
|
2020-01-19 03:48:26 +01:00
|
|
|
private static String bukkitVersion;
|
2020-08-13 01:51:32 +02:00
|
|
|
private static Method itemAsCraftCopyMethod;
|
|
|
|
private static Method itemAsNmsCopyMethod;
|
2019-01-03 03:13:03 +01:00
|
|
|
private static Method damageAndIdleSoundMethod;
|
2019-12-24 05:40:56 +01:00
|
|
|
private static Constructor<?> boundingBoxConstructor;
|
|
|
|
private static Method setBoundingBoxMethod;
|
|
|
|
private static Field pingField;
|
2020-02-13 07:47:02 +01:00
|
|
|
private static Field entityCountField;
|
2019-12-24 05:40:56 +01:00
|
|
|
private static Field chunkMapField;
|
|
|
|
private static Field chunkProviderField;
|
|
|
|
private static Field entityTrackerField;
|
|
|
|
private static Field trackedEntitiesField;
|
2020-08-14 20:26:00 +02:00
|
|
|
@NmsRemovedIn(NmsVersion.v1_14)
|
2020-02-13 07:47:02 +01:00
|
|
|
private static Method ihmGet;
|
2020-08-14 20:26:00 +02:00
|
|
|
@NmsRemovedIn(NmsVersion.v1_14)
|
2020-02-13 07:47:02 +01:00
|
|
|
private static Field trackerField;
|
2020-08-14 20:26:00 +02:00
|
|
|
@NmsRemovedIn(NmsVersion.v1_14)
|
2020-02-13 07:47:02 +01:00
|
|
|
private static Field entitiesField;
|
2020-02-06 00:15:20 +01:00
|
|
|
private static NmsVersion version;
|
2020-08-13 01:51:32 +02:00
|
|
|
private static Method itemAsBukkitMethod;
|
|
|
|
private static Method soundEffectMethod;
|
|
|
|
private static Method getServerMethod;
|
|
|
|
private static Method getEnumArtMethod;
|
|
|
|
private static Constructor blockPositionConstructor;
|
|
|
|
private static Method enumDirectionMethod;
|
|
|
|
private static Enum[] enumPlayerInfoAction;
|
|
|
|
private static Constructor chatComponentConstructor;
|
|
|
|
private static Constructor packetPlayOutConstructor;
|
|
|
|
private static Enum[] enumGamemode;
|
|
|
|
private static Method getNmsEntityMethod;
|
|
|
|
private static Enum[] enumItemSlots;
|
2020-11-26 06:36:30 +01:00
|
|
|
private static Method soundGetMethod;
|
2020-11-26 06:54:59 +01:00
|
|
|
private static Method soundEffectGetMethod;
|
|
|
|
private static Field soundEffectGetKey;
|
2020-08-13 01:51:32 +02:00
|
|
|
private static Constructor vector3FConstructor;
|
|
|
|
private static Method enumDirectionFrom;
|
|
|
|
private static Constructor villagerDataConstructor;
|
|
|
|
private static Method bukkitKeyToNms;
|
|
|
|
private static Method registryBlocksGetMethod;
|
|
|
|
private static Object villagerTypeRegistry;
|
|
|
|
private static Object villagerProfessionRegistry;
|
|
|
|
private static Constructor dataWatcherItemConstructor;
|
|
|
|
private static Constructor vec3DConstructor;
|
|
|
|
private static Method entityTypesAMethod;
|
|
|
|
private static Class entityPoseClass;
|
|
|
|
private static Method craftBlockDataGetState;
|
|
|
|
private static Method getOldItemAsBlock;
|
|
|
|
private static Method magicGetBlock;
|
2021-05-15 06:29:09 +02:00
|
|
|
private static Method magicGetMaterial;
|
2020-08-13 01:51:32 +02:00
|
|
|
private static Method getNmsItem;
|
|
|
|
private static Method getBlockData;
|
|
|
|
private static Method getBlockDataAsId;
|
|
|
|
private static Method getNmsWorld;
|
|
|
|
private static Method deserializedItemMeta;
|
|
|
|
private static Method mobEffectList;
|
|
|
|
private static Constructor mobEffectConstructor;
|
|
|
|
private static Method boundingBoxMethod;
|
|
|
|
private static Method bukkitEntityMethod;
|
2020-08-13 02:10:48 +02:00
|
|
|
private static Field noDamageTicks;
|
|
|
|
private static Method isInvul;
|
|
|
|
private static Object genericDamage;
|
2021-01-27 07:19:24 +01:00
|
|
|
private static Field boardField;
|
|
|
|
public static Object scoreboardCrtieriaHealth;
|
|
|
|
private static Method getObjectives;
|
2021-02-03 11:06:32 +01:00
|
|
|
private static Method getPlayerScoreObjective;
|
2021-01-27 07:19:24 +01:00
|
|
|
private static Method setScore;
|
2020-02-06 00:15:20 +01:00
|
|
|
|
2019-12-24 05:40:56 +01:00
|
|
|
public static void init() {
|
2020-08-13 01:51:32 +02:00
|
|
|
try {
|
2021-01-27 07:19:24 +01:00
|
|
|
boundingBoxConstructor = getNmsConstructor("AxisAlignedBB", double.class, double.class, double.class, double.class, double.class, double.class);
|
2020-08-13 01:51:32 +02:00
|
|
|
|
|
|
|
setBoundingBoxMethod = getNmsMethod("Entity", "a", getNmsClass("AxisAlignedBB"));
|
|
|
|
entityCountField = getNmsField("Entity", "entityCount");
|
|
|
|
|
2021-01-27 07:19:24 +01:00
|
|
|
mobEffectConstructor = getNmsConstructor("MobEffect", getNmsClass("MobEffectList"), Integer.TYPE, Integer.TYPE, Boolean.TYPE, Boolean.TYPE);
|
2020-08-13 01:51:32 +02:00
|
|
|
mobEffectList = getNmsMethod("MobEffectList", "fromId", Integer.TYPE);
|
|
|
|
boundingBoxMethod = getNmsMethod("Entity", "getBoundingBox");
|
|
|
|
bukkitEntityMethod = getNmsMethod("Entity", "getBukkitEntity");
|
|
|
|
|
|
|
|
Class<?> craftItemClass = getCraftClass("inventory.CraftItemStack");
|
|
|
|
itemAsCraftCopyMethod = getCraftMethod(craftItemClass, "asCraftCopy", ItemStack.class);
|
|
|
|
itemAsNmsCopyMethod = getCraftMethod(craftItemClass, "asNMSCopy", ItemStack.class);
|
|
|
|
itemAsBukkitMethod = getCraftMethod(craftItemClass, "asBukkitCopy", getNmsClass("ItemStack"));
|
2020-11-26 06:54:59 +01:00
|
|
|
|
2020-08-13 01:51:32 +02:00
|
|
|
getServerMethod = getCraftMethod("CraftServer", "getServer");
|
|
|
|
getEnumArtMethod = getCraftMethod("CraftArt", "BukkitToNotch", Art.class);
|
|
|
|
blockPositionConstructor = getNmsConstructor("BlockPosition", int.class, int.class, int.class);
|
|
|
|
enumDirectionMethod = getNmsMethod("EnumDirection", "fromType2", int.class);
|
2021-01-27 07:19:24 +01:00
|
|
|
enumPlayerInfoAction = (Enum[]) getNmsClass("PacketPlayOutPlayerInfo$EnumPlayerInfoAction").getEnumConstants();
|
2020-08-13 01:51:32 +02:00
|
|
|
chatComponentConstructor = getNmsConstructor("ChatComponentText", String.class);
|
|
|
|
packetPlayOutConstructor =
|
2021-01-27 07:19:24 +01:00
|
|
|
getNmsConstructor("PacketPlayOutPlayerInfo$PlayerInfoData", getNmsClass("PacketPlayOutPlayerInfo"), GameProfile.class, int.class,
|
|
|
|
getNmsClass("EnumGamemode"), getNmsClass("IChatBaseComponent"));
|
2020-08-13 01:51:32 +02:00
|
|
|
enumGamemode = (Enum[]) getNmsClass("EnumGamemode").getEnumConstants();
|
|
|
|
getNmsEntityMethod = getCraftMethod("entity.CraftEntity", "getHandle");
|
|
|
|
enumItemSlots = (Enum[]) getNmsClass("EnumItemSlot").getEnumConstants();
|
2020-11-26 06:54:59 +01:00
|
|
|
|
|
|
|
Class craftSound = getCraftClass("CraftSound");
|
|
|
|
|
|
|
|
try {
|
2021-01-27 07:19:24 +01:00
|
|
|
soundGetMethod = craftSound.getMethod("getSound", Sound.class);
|
|
|
|
} catch (Exception ex) {
|
2020-11-26 06:54:59 +01:00
|
|
|
soundEffectGetMethod = getCraftMethod("CraftSound", "getSoundEffect", Sound.class);
|
|
|
|
soundEffectGetKey = getNmsField("SoundEffect", "b");
|
|
|
|
}
|
|
|
|
|
|
|
|
soundEffectMethod = getCraftMethod("CraftSound", "getSoundEffect", String.class);
|
|
|
|
|
2020-08-13 01:51:32 +02:00
|
|
|
vector3FConstructor = getNmsConstructor("Vector3f", float.class, float.class, float.class);
|
|
|
|
enumDirectionFrom = getNmsMethod("EnumDirection", "fromType1", int.class);
|
2020-09-10 01:55:56 +02:00
|
|
|
getBlockData = getNmsMethod(getNmsClass("Block"), "getBlockData");
|
2020-08-13 01:51:32 +02:00
|
|
|
|
|
|
|
if (NmsVersion.v1_13.isSupported()) {
|
|
|
|
craftBlockDataGetState = getCraftMethod("block.data.CraftBlockData", "getState");
|
|
|
|
magicGetBlock = getCraftMethod("util.CraftMagicNumbers", "getBlock", Material.class);
|
2021-05-15 06:29:09 +02:00
|
|
|
magicGetMaterial = getCraftMethod("util.CraftMagicNumbers", "getMaterial", getNmsClass("Block"));
|
2020-08-13 01:51:32 +02:00
|
|
|
entityTypesAMethod = getNmsMethod("EntityTypes", "a", String.class);
|
|
|
|
|
|
|
|
if (NmsVersion.v1_14.isSupported()) {
|
|
|
|
entityPoseClass = getNmsClass("EntityPose");
|
|
|
|
registryBlocksGetMethod = getNmsMethod("RegistryBlocks", "get", getNmsClass("MinecraftKey"));
|
2021-01-27 07:19:24 +01:00
|
|
|
villagerDataConstructor = getNmsConstructor("VillagerData", getNmsClass("VillagerType"), getNmsClass("VillagerProfession"), int.class);
|
2020-08-13 01:51:32 +02:00
|
|
|
villagerProfessionRegistry = getNmsField("IRegistry", "VILLAGER_PROFESSION").get(null);
|
|
|
|
villagerTypeRegistry = getNmsField("IRegistry", "VILLAGER_TYPE").get(null);
|
|
|
|
} else {
|
2021-01-27 07:19:24 +01:00
|
|
|
registryBlocksGetMethod = getNmsMethod("RegistryBlocks", "getOrDefault", getNmsClass("MinecraftKey"));
|
2020-08-13 01:51:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bukkitKeyToNms = getCraftMethod("util.CraftNamespacedKey", "toMinecraft", NamespacedKey.class);
|
2021-01-27 07:19:24 +01:00
|
|
|
dataWatcherItemConstructor = getNmsConstructor("DataWatcher$Item", getNmsClass("DataWatcherObject"), Object.class);
|
2020-08-13 01:51:32 +02:00
|
|
|
vec3DConstructor = getNmsConstructor("Vec3D", double.class, double.class, double.class);
|
|
|
|
getOldItemAsBlock = getNmsMethod(getNmsClass("Block"), "asBlock", getNmsClass("Item"));
|
|
|
|
getNmsItem = getNmsMethod("ItemStack", "getItem");
|
|
|
|
getBlockDataAsId = getNmsMethod("Block", "getCombinedId", getNmsClass("IBlockData"));
|
|
|
|
|
|
|
|
getNmsWorld = getCraftMethod("CraftWorld", "getHandle");
|
2021-01-27 07:19:24 +01:00
|
|
|
deserializedItemMeta = getCraftMethod(getCraftClass("inventory.CraftMetaItem$SerializableMeta"), "deserialize", Map.class);
|
2020-08-13 01:51:32 +02:00
|
|
|
|
2020-08-13 02:10:48 +02:00
|
|
|
noDamageTicks = getNmsField("Entity", "noDamageTicks");
|
|
|
|
isInvul = getNmsMethod("Entity", "isInvulnerable", getNmsClass("DamageSource"));
|
2020-12-04 19:37:37 +01:00
|
|
|
genericDamage = getNmsField("DamageSource", "GENERIC").get(null);
|
2021-01-28 06:20:26 +01:00
|
|
|
boardField = getCraftClass("scoreboard.CraftScoreboard").getDeclaredField("board");
|
2021-01-27 07:19:24 +01:00
|
|
|
boardField.setAccessible(true);
|
2021-02-03 10:59:33 +01:00
|
|
|
scoreboardCrtieriaHealth = getNmsField("IScoreboardCriteria", NmsVersion.v1_13.isSupported() ? "HEALTH" : "g").get(null);
|
2021-01-27 07:19:24 +01:00
|
|
|
setScore = getNmsMethod("ScoreboardScore", "setScore", int.class);
|
2021-01-28 06:20:26 +01:00
|
|
|
|
|
|
|
if (!NmsVersion.v1_13.isSupported()) {
|
2021-02-03 11:06:32 +01:00
|
|
|
getObjectives = getNmsMethod("Scoreboard", "getObjectivesForCriteria", getNmsClass("IScoreboardCriteria"));
|
2021-02-03 11:14:30 +01:00
|
|
|
getPlayerScoreObjective = getNmsMethod("Scoreboard", "getPlayerScoreForObjective", String.class, getNmsClass("ScoreboardObjective"));
|
2021-01-28 06:20:26 +01:00
|
|
|
} else {
|
|
|
|
getObjectives = getNmsMethod("Scoreboard", "getObjectivesForCriteria", getNmsClass("IScoreboardCriteria"), String.class, Consumer.class);
|
|
|
|
}
|
2020-08-13 02:10:48 +02:00
|
|
|
|
2020-08-13 01:51:32 +02:00
|
|
|
Method method = getNmsMethod("SoundCategory", "a");
|
|
|
|
|
|
|
|
for (Enum anEnum : (Enum[]) getNmsClass("SoundCategory").getEnumConstants()) {
|
|
|
|
soundCategories.put((String) method.invoke(anEnum), anEnum);
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
2019-01-03 03:13:03 +01:00
|
|
|
try {
|
2019-05-18 08:54:51 +02:00
|
|
|
Object entity = createEntityInstance(DisguiseType.COW, "Cow");
|
2019-01-03 03:13:03 +01:00
|
|
|
|
2020-04-27 14:59:49 +02:00
|
|
|
for (Method method : getNmsClass("EntityCow").getDeclaredMethods()) {
|
2020-08-13 01:51:32 +02:00
|
|
|
if (method.getReturnType() != float.class) {
|
2019-01-03 03:13:03 +01:00
|
|
|
continue;
|
2020-08-13 01:51:32 +02:00
|
|
|
}
|
2019-01-03 03:13:03 +01:00
|
|
|
|
2020-08-13 01:51:32 +02:00
|
|
|
if (!Modifier.isProtected(method.getModifiers())) {
|
2019-01-03 03:13:03 +01:00
|
|
|
continue;
|
2020-08-13 01:51:32 +02:00
|
|
|
}
|
2019-01-03 03:13:03 +01:00
|
|
|
|
2020-08-13 01:51:32 +02:00
|
|
|
if (method.getParameterTypes().length != 0) {
|
2019-01-03 03:13:03 +01:00
|
|
|
continue;
|
2020-08-13 01:51:32 +02:00
|
|
|
}
|
2019-01-03 03:13:03 +01:00
|
|
|
|
|
|
|
method.setAccessible(true);
|
|
|
|
|
|
|
|
float value = (Float) method.invoke(entity);
|
|
|
|
|
2020-08-13 01:51:32 +02:00
|
|
|
if ((float) method.invoke(entity) != 0.4f) {
|
2019-01-03 03:13:03 +01:00
|
|
|
continue;
|
2020-08-13 01:51:32 +02:00
|
|
|
}
|
2019-01-03 03:13:03 +01:00
|
|
|
|
2020-04-27 14:59:49 +02:00
|
|
|
damageAndIdleSoundMethod = getNmsClass("EntityLiving").getDeclaredMethod(method.getName());
|
|
|
|
damageAndIdleSoundMethod.setAccessible(true);
|
2019-01-03 03:13:03 +01:00
|
|
|
break;
|
|
|
|
}
|
2020-08-13 01:51:32 +02:00
|
|
|
} catch (Exception ex) {
|
2019-01-03 03:13:03 +01:00
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
pingField = getNmsField("EntityPlayer", "ping");
|
|
|
|
|
2020-02-13 07:47:02 +01:00
|
|
|
if (NmsVersion.v1_14.isSupported()) {
|
|
|
|
chunkMapField = getNmsField("ChunkProviderServer", "playerChunkMap");
|
|
|
|
trackedEntitiesField = getNmsField("PlayerChunkMap", "trackedEntities");
|
|
|
|
entityTrackerField = getNmsField("PlayerChunkMap$EntityTracker", "trackerEntry");
|
2020-06-25 05:33:28 +02:00
|
|
|
|
|
|
|
if (NmsVersion.v1_16.isSupported()) {
|
|
|
|
chunkProviderField = getNmsField("WorldServer", "chunkProvider");
|
|
|
|
} else {
|
|
|
|
chunkProviderField = getNmsField("World", "chunkProvider");
|
|
|
|
}
|
2020-02-13 07:47:02 +01:00
|
|
|
} else {
|
|
|
|
trackerField = getNmsField("WorldServer", "tracker");
|
|
|
|
entitiesField = getNmsField("EntityTracker", "trackedEntities");
|
|
|
|
ihmGet = getNmsMethod("IntHashMap", "get", int.class);
|
|
|
|
}
|
2019-01-03 03:13:03 +01:00
|
|
|
}
|
|
|
|
|
2020-08-13 02:10:48 +02:00
|
|
|
public static boolean hasInvul(Entity entity) {
|
|
|
|
Object nmsEntity = ReflectionManager.getNmsEntity(entity);
|
|
|
|
|
|
|
|
try {
|
|
|
|
if (entity instanceof LivingEntity) {
|
|
|
|
return noDamageTicks.getInt(nmsEntity) > 0;
|
|
|
|
} else {
|
|
|
|
return (boolean) isInvul.invoke(nmsEntity, genericDamage);
|
|
|
|
}
|
|
|
|
} catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-02-06 00:15:20 +01:00
|
|
|
public static boolean isSupported(AccessibleObject obj) {
|
2020-02-13 07:47:02 +01:00
|
|
|
if (obj.isAnnotationPresent(NmsAddedIn.class)) {
|
|
|
|
NmsAddedIn added = obj.getAnnotation(NmsAddedIn.class);
|
2020-02-06 00:15:20 +01:00
|
|
|
|
2020-02-13 07:47:02 +01:00
|
|
|
// If it was added after this version
|
2020-08-11 23:36:13 +02:00
|
|
|
if (!added.value().isSupported()) {
|
2020-02-06 00:15:20 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-13 07:47:02 +01:00
|
|
|
if (obj.isAnnotationPresent(NmsRemovedIn.class)) {
|
|
|
|
NmsRemovedIn removed = obj.getAnnotation(NmsRemovedIn.class);
|
2020-02-06 00:15:20 +01:00
|
|
|
|
2020-08-14 20:26:00 +02:00
|
|
|
return !removed.value().isSupported();
|
2020-02-06 00:15:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isSupported(Class cl, String name) {
|
|
|
|
try {
|
|
|
|
for (Field field : cl.getFields()) {
|
|
|
|
if (!field.getName().equals(name)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
return isSupported(field);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (Method method : cl.getMethods()) {
|
|
|
|
if (!method.getName().equals(name)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
return isSupported(method);
|
|
|
|
}
|
2020-08-13 01:51:32 +02:00
|
|
|
} catch (Exception ex) {
|
2020-02-06 00:15:20 +01:00
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-26 19:09:13 +02:00
|
|
|
public static String getResourceAsString(File file, String fileName) {
|
2020-04-17 04:08:21 +02:00
|
|
|
try (JarFile jar = new JarFile(file)) {
|
2020-04-26 19:09:13 +02:00
|
|
|
JarEntry entry = jar.getJarEntry(fileName);
|
2020-04-16 18:41:42 +02:00
|
|
|
|
2020-04-17 04:08:21 +02:00
|
|
|
try (InputStream stream = jar.getInputStream(entry)) {
|
2021-01-27 07:19:24 +01:00
|
|
|
return new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8)).lines().collect(Collectors.joining("\n"));
|
2020-04-16 18:41:42 +02:00
|
|
|
}
|
2020-08-13 01:51:32 +02:00
|
|
|
} catch (Exception ex) {
|
2020-04-16 18:41:42 +02:00
|
|
|
ex.printStackTrace();
|
2019-01-03 03:13:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-04-26 19:09:13 +02:00
|
|
|
/**
|
|
|
|
* Copied from Bukkit
|
|
|
|
*/
|
|
|
|
public static YamlConfiguration getPluginYAML(File file) {
|
|
|
|
try {
|
|
|
|
String s = getResourceAsString(file, "plugin.yml");
|
|
|
|
|
|
|
|
if (s == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
YamlConfiguration config = new YamlConfiguration();
|
|
|
|
|
|
|
|
config.loadFromString(getResourceAsString(file, "plugin.yml"));
|
|
|
|
|
|
|
|
return config;
|
2021-01-28 18:25:50 +01:00
|
|
|
} catch (Exception e) {
|
2020-04-26 19:09:13 +02:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2019-01-03 03:13:03 +01:00
|
|
|
public static int getNewEntityId() {
|
|
|
|
return getNewEntityId(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static int getNewEntityId(boolean increment) {
|
|
|
|
try {
|
2020-02-13 07:47:02 +01:00
|
|
|
Number entityCount = (Number) entityCountField.get(null);
|
2019-01-03 03:13:03 +01:00
|
|
|
|
|
|
|
if (increment) {
|
2020-02-13 07:47:02 +01:00
|
|
|
if (NmsVersion.v1_14.isSupported()) {
|
2020-05-07 12:05:03 +02:00
|
|
|
return ((AtomicInteger) entityCount).incrementAndGet();
|
2020-02-13 07:47:02 +01:00
|
|
|
} else {
|
|
|
|
int id = entityCount.intValue();
|
|
|
|
|
|
|
|
entityCountField.set(null, id + 1);
|
|
|
|
|
|
|
|
return id;
|
|
|
|
}
|
2019-01-03 03:13:03 +01:00
|
|
|
}
|
|
|
|
|
2020-02-13 07:47:02 +01:00
|
|
|
return entityCount.intValue();
|
2020-08-13 01:51:32 +02:00
|
|
|
} catch (IllegalAccessException e) {
|
2019-01-03 03:13:03 +01:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-05-18 08:54:51 +02:00
|
|
|
public static Object createEntityInstance(DisguiseType disguiseType, String entityName) {
|
2019-01-03 03:13:03 +01:00
|
|
|
try {
|
|
|
|
Class<?> entityClass = getNmsClass("Entity" + entityName);
|
|
|
|
Object entityObject;
|
|
|
|
Object world = getWorldServer(Bukkit.getWorlds().get(0));
|
|
|
|
|
2020-02-13 07:47:02 +01:00
|
|
|
if (entityName.equals("Player")) {
|
|
|
|
Object minecraftServer = getNmsMethod("MinecraftServer", "getServer").invoke(null);
|
2019-01-03 03:13:03 +01:00
|
|
|
|
2021-01-27 07:19:24 +01:00
|
|
|
Object playerinteractmanager =
|
|
|
|
getNmsClass("PlayerInteractManager").getDeclaredConstructor(getNmsClass(NmsVersion.v1_14.isSupported() ? "WorldServer" : "World"))
|
|
|
|
.newInstance(world);
|
2019-01-03 03:13:03 +01:00
|
|
|
|
2020-02-13 07:47:02 +01:00
|
|
|
WrappedGameProfile gameProfile = getGameProfile(new UUID(0, 0), "Steve");
|
2019-01-03 03:13:03 +01:00
|
|
|
|
2021-01-27 07:19:24 +01:00
|
|
|
entityObject = entityClass.getDeclaredConstructor(getNmsClass("MinecraftServer"), getNmsClass("WorldServer"), gameProfile.getHandleType(),
|
|
|
|
playerinteractmanager.getClass()).newInstance(minecraftServer, world, gameProfile.getHandle(), playerinteractmanager);
|
2020-02-13 07:47:02 +01:00
|
|
|
} else if (entityName.equals("EnderPearl")) {
|
|
|
|
entityObject = entityClass.getDeclaredConstructor(getNmsClass("World"), getNmsClass("EntityLiving"))
|
|
|
|
.newInstance(world, createEntityInstance(DisguiseType.COW, "Cow"));
|
|
|
|
} else if (entityName.equals("FishingHook")) {
|
|
|
|
if (NmsVersion.v1_14.isSupported()) {
|
2021-01-27 07:19:24 +01:00
|
|
|
entityObject = entityClass.getDeclaredConstructor(getNmsClass("EntityHuman"), getNmsClass("World"), int.class, int.class)
|
2019-05-18 08:54:51 +02:00
|
|
|
.newInstance(createEntityInstance(DisguiseType.PLAYER, "Player"), world, 0, 0);
|
2020-02-13 07:47:02 +01:00
|
|
|
} else {
|
|
|
|
entityObject = entityClass.getDeclaredConstructor(getNmsClass("World"), getNmsClass("EntityHuman"))
|
|
|
|
.newInstance(world, createEntityInstance(DisguiseType.PLAYER, "Player"));
|
|
|
|
}
|
|
|
|
} else if (!NmsVersion.v1_14.isSupported() && entityName.equals("Potion")) {
|
2021-01-27 07:19:24 +01:00
|
|
|
entityObject = entityClass.getDeclaredConstructor(getNmsClass("World"), Double.TYPE, Double.TYPE, Double.TYPE, getNmsClass("ItemStack"))
|
2020-02-13 07:47:02 +01:00
|
|
|
.newInstance(world, 0d, 0d, 0d, getNmsItem(new ItemStack(Material.SPLASH_POTION)));
|
|
|
|
} else {
|
|
|
|
if (NmsVersion.v1_14.isSupported()) {
|
2019-05-18 08:54:51 +02:00
|
|
|
entityObject = entityClass.getDeclaredConstructor(getNmsClass("EntityTypes"), getNmsClass("World"))
|
|
|
|
.newInstance(getEntityType(disguiseType.getEntityType()), world);
|
2020-02-13 07:47:02 +01:00
|
|
|
} else {
|
|
|
|
entityObject = entityClass.getDeclaredConstructor(getNmsClass("World")).newInstance(world);
|
|
|
|
}
|
2019-01-03 03:13:03 +01:00
|
|
|
}
|
|
|
|
|
2020-09-18 23:01:28 +02:00
|
|
|
// Workaround for paper being 2 smart 4 me
|
2021-01-27 07:19:24 +01:00
|
|
|
getNmsMethod("Entity", "setPosition", double.class, double.class, double.class).invoke(entityObject, 1, 1, 1);
|
|
|
|
getNmsMethod("Entity", "setPosition", double.class, double.class, double.class).invoke(entityObject, 0, 0, 0);
|
2020-09-18 23:01:28 +02:00
|
|
|
|
2019-01-03 03:13:03 +01:00
|
|
|
return entityObject;
|
2020-08-13 01:51:32 +02:00
|
|
|
} catch (Exception e) {
|
2021-01-27 07:19:24 +01:00
|
|
|
DisguiseUtilities.getLogger().warning("Error while attempting to create entity instance for " + disguiseType.name());
|
2019-01-03 03:13:03 +01:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Object getMobEffectList(int id) {
|
|
|
|
try {
|
2020-08-13 01:51:32 +02:00
|
|
|
return mobEffectList.invoke(null, id);
|
|
|
|
} catch (IllegalAccessException | InvocationTargetException e) {
|
2019-01-03 03:13:03 +01:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Object createMobEffect(PotionEffect effect) {
|
2021-01-27 07:19:24 +01:00
|
|
|
return createMobEffect(effect.getType().getId(), effect.getDuration(), effect.getAmplifier(), effect.isAmbient(), effect.hasParticles());
|
2019-01-03 03:13:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static Object createMobEffect(int id, int duration, int amplification, boolean ambient, boolean particles) {
|
|
|
|
try {
|
2020-08-13 01:51:32 +02:00
|
|
|
return mobEffectConstructor.newInstance(getMobEffectList(id), duration, amplification, ambient, particles);
|
|
|
|
} catch (Exception e) {
|
2019-01-03 03:13:03 +01:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static FakeBoundingBox getBoundingBox(Entity entity) {
|
|
|
|
try {
|
2020-08-13 01:51:32 +02:00
|
|
|
Object boundingBox = boundingBoxMethod.invoke(getNmsEntity(entity));
|
2019-01-03 03:13:03 +01:00
|
|
|
|
|
|
|
double x = 0, y = 0, z = 0;
|
|
|
|
int stage = 0;
|
|
|
|
|
|
|
|
for (Field field : boundingBox.getClass().getDeclaredFields()) {
|
2020-08-27 18:57:03 +02:00
|
|
|
if (!field.getType().getSimpleName().equals("double") || Modifier.isStatic(field.getModifiers())) {
|
2019-01-03 03:13:03 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
stage++;
|
|
|
|
|
|
|
|
switch (stage) {
|
|
|
|
case 1:
|
|
|
|
x -= field.getDouble(boundingBox);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
y -= field.getDouble(boundingBox);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
z -= field.getDouble(boundingBox);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
x += field.getDouble(boundingBox);
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
y += field.getDouble(boundingBox);
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
z += field.getDouble(boundingBox);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new Exception("Error while setting the bounding box, more doubles than I thought??");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return new FakeBoundingBox(x, y, z);
|
2020-08-13 01:51:32 +02:00
|
|
|
} catch (Exception ex) {
|
2019-01-03 03:13:03 +01:00
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Entity getBukkitEntity(Object nmsEntity) {
|
|
|
|
try {
|
2020-08-13 01:51:32 +02:00
|
|
|
return (Entity) bukkitEntityMethod.invoke(nmsEntity);
|
|
|
|
} catch (Exception ex) {
|
2019-01-03 03:13:03 +01:00
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static ItemStack getBukkitItem(Object nmsItem) {
|
|
|
|
try {
|
2020-08-13 01:51:32 +02:00
|
|
|
return (ItemStack) itemAsBukkitMethod.invoke(null, nmsItem);
|
|
|
|
} catch (Exception e) {
|
2019-01-03 03:13:03 +01:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-03-23 23:54:26 +01:00
|
|
|
public static ItemStack getCraftItem(ItemStack bukkitItem) {
|
|
|
|
try {
|
2020-08-13 01:51:32 +02:00
|
|
|
return (ItemStack) itemAsCraftCopyMethod.invoke(null, bukkitItem);
|
|
|
|
} catch (Exception e) {
|
2020-03-23 23:54:26 +01:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-02-20 00:11:22 +01:00
|
|
|
public static NmsVersion getVersion() {
|
|
|
|
if (version == null) {
|
|
|
|
getBukkitVersion();
|
|
|
|
}
|
|
|
|
|
|
|
|
return version;
|
|
|
|
}
|
|
|
|
|
2019-01-03 03:13:03 +01:00
|
|
|
public static String getBukkitVersion() {
|
2020-01-20 01:35:55 +01:00
|
|
|
if (bukkitVersion == null) {
|
|
|
|
bukkitVersion = Bukkit.getServer().getClass().getName().split("\\.")[3];
|
2020-02-06 00:15:20 +01:00
|
|
|
|
|
|
|
for (NmsVersion v : NmsVersion.values()) {
|
|
|
|
if (!getBukkitVersion().startsWith(v.name())) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
version = v;
|
|
|
|
break;
|
|
|
|
}
|
2020-01-20 01:35:55 +01:00
|
|
|
}
|
|
|
|
|
2019-01-03 03:13:03 +01:00
|
|
|
return bukkitVersion;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Class<?> getCraftClass(String className) {
|
|
|
|
try {
|
|
|
|
return Class.forName("org.bukkit.craftbukkit." + getBukkitVersion() + "." + className);
|
2020-08-13 01:51:32 +02:00
|
|
|
} catch (Exception e) {
|
2019-01-03 03:13:03 +01:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Constructor getCraftConstructor(Class clazz, Class<?>... parameters) {
|
|
|
|
try {
|
|
|
|
Constructor declaredConstructor = clazz.getDeclaredConstructor(parameters);
|
|
|
|
declaredConstructor.setAccessible(true);
|
|
|
|
return declaredConstructor;
|
2020-08-13 01:51:32 +02:00
|
|
|
} catch (NoSuchMethodException e) {
|
2019-01-03 03:13:03 +01:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Constructor getCraftConstructor(String className, Class<?>... parameters) {
|
|
|
|
return getCraftConstructor(getCraftClass(className), parameters);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Object getCraftSound(Sound sound) {
|
|
|
|
try {
|
2020-08-13 01:51:32 +02:00
|
|
|
return soundEffectMethod.invoke(null, getSoundString(sound));
|
|
|
|
} catch (Exception ex) {
|
2019-01-03 03:13:03 +01:00
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Object getEntityTrackerEntry(Entity target) throws Exception {
|
|
|
|
Object world = getWorldServer(target.getWorld());
|
2019-05-18 08:54:51 +02:00
|
|
|
|
2020-02-13 07:47:02 +01:00
|
|
|
if (NmsVersion.v1_14.isSupported()) {
|
|
|
|
Object chunkProvider = chunkProviderField.get(world);
|
|
|
|
Object chunkMap = chunkMapField.get(chunkProvider);
|
|
|
|
Map trackedEntities = (Map) trackedEntitiesField.get(chunkMap);
|
2019-05-18 08:54:51 +02:00
|
|
|
|
2020-02-13 07:47:02 +01:00
|
|
|
Object entityTracker = trackedEntities.get(target.getEntityId());
|
|
|
|
|
|
|
|
if (entityTracker == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return entityTrackerField.get(entityTracker);
|
2019-05-18 08:54:51 +02:00
|
|
|
}
|
2019-01-03 03:13:03 +01:00
|
|
|
|
2020-02-13 07:47:02 +01:00
|
|
|
Object tracker = trackerField.get(world);
|
|
|
|
Object trackedEntities = entitiesField.get(tracker);
|
|
|
|
|
|
|
|
return ihmGet.invoke(trackedEntities, target.getEntityId());
|
2019-01-03 03:13:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static Object getMinecraftServer() {
|
|
|
|
try {
|
2020-08-13 01:51:32 +02:00
|
|
|
return getServerMethod.invoke(Bukkit.getServer());
|
|
|
|
} catch (IllegalAccessException | InvocationTargetException e) {
|
2019-01-03 03:13:03 +01:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String getEnumArt(Art art) {
|
|
|
|
try {
|
2020-08-13 01:51:32 +02:00
|
|
|
Object enumArt = getEnumArtMethod.invoke(null, art);
|
2019-01-03 03:13:03 +01:00
|
|
|
for (Field field : enumArt.getClass().getDeclaredFields()) {
|
|
|
|
if (field.getType() == String.class) {
|
|
|
|
return (String) field.get(enumArt);
|
|
|
|
}
|
|
|
|
}
|
2020-08-13 01:51:32 +02:00
|
|
|
} catch (Exception ex) {
|
2019-01-03 03:13:03 +01:00
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Object getBlockPosition(int x, int y, int z) {
|
|
|
|
try {
|
2020-08-13 01:51:32 +02:00
|
|
|
return blockPositionConstructor.newInstance(x, y, z);
|
|
|
|
} catch (Exception ex) {
|
2019-01-03 03:13:03 +01:00
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Enum getEnumDirection(int direction) {
|
|
|
|
try {
|
2020-08-13 01:51:32 +02:00
|
|
|
return (Enum) enumDirectionMethod.invoke(null, direction);
|
|
|
|
} catch (Exception ex) {
|
2019-01-03 03:13:03 +01:00
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Enum getEnumPlayerInfoAction(int action) {
|
|
|
|
try {
|
2020-08-13 01:51:32 +02:00
|
|
|
return enumPlayerInfoAction[action];
|
|
|
|
} catch (Exception ex) {
|
2019-01-03 03:13:03 +01:00
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Object getPlayerInfoData(Object playerInfoPacket, WrappedGameProfile gameProfile) {
|
|
|
|
try {
|
2020-08-13 01:51:32 +02:00
|
|
|
Object playerListName = chatComponentConstructor.newInstance(gameProfile.getName());
|
2019-01-03 03:13:03 +01:00
|
|
|
|
2021-01-27 07:19:24 +01:00
|
|
|
return packetPlayOutConstructor.newInstance(playerInfoPacket, gameProfile.getHandle(), 0, enumGamemode[1], playerListName);
|
2020-08-13 01:51:32 +02:00
|
|
|
} catch (Exception ex) {
|
2019-01-03 03:13:03 +01:00
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static WrappedGameProfile getGameProfile(Player player) {
|
|
|
|
return WrappedGameProfile.fromPlayer(player);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static WrappedGameProfile getGameProfile(UUID uuid, String playerName) {
|
|
|
|
try {
|
2021-05-17 13:19:27 +02:00
|
|
|
return new WrappedGameProfile(uuid != null ? uuid : getRandomUUID(),
|
|
|
|
playerName == null || playerName.length() < 17 ? playerName : playerName.substring(0, 16));
|
2020-08-13 01:51:32 +02:00
|
|
|
} catch (Exception ex) {
|
2019-01-03 03:13:03 +01:00
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static WrappedGameProfile getClonedProfile(WrappedGameProfile gameProfile) {
|
|
|
|
return getGameProfileWithThisSkin(null, gameProfile.getName(), gameProfile);
|
|
|
|
}
|
|
|
|
|
2021-01-27 07:19:24 +01:00
|
|
|
public static WrappedGameProfile getGameProfileWithThisSkin(UUID uuid, String playerName, WrappedGameProfile profileWithSkin) {
|
2019-01-03 03:13:03 +01:00
|
|
|
try {
|
2021-05-17 13:19:27 +02:00
|
|
|
WrappedGameProfile gameProfile = new WrappedGameProfile(uuid != null ? uuid : getRandomUUID(),
|
|
|
|
playerName == null || playerName.length() < 17 ? playerName : playerName.substring(0, 16));
|
2019-01-03 03:13:03 +01:00
|
|
|
|
|
|
|
if (profileWithSkin != null) {
|
|
|
|
gameProfile.getProperties().putAll(profileWithSkin.getProperties());
|
|
|
|
}
|
|
|
|
|
|
|
|
return gameProfile;
|
2020-08-13 01:51:32 +02:00
|
|
|
} catch (Exception ex) {
|
2019-01-03 03:13:03 +01:00
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used for generating a UUID with a custom version instead of the default 4. Workaround for China's NetEase servers
|
|
|
|
*/
|
2021-02-11 05:56:20 +01:00
|
|
|
public static UUID getRandomUUID() {
|
2019-01-03 03:13:03 +01:00
|
|
|
UUID uuid = UUID.randomUUID();
|
|
|
|
|
|
|
|
if (DisguiseConfig.getUUIDGeneratedVersion() == 4) {
|
|
|
|
return uuid;
|
|
|
|
}
|
|
|
|
|
|
|
|
ByteBuffer bb = ByteBuffer.wrap(new byte[16]);
|
|
|
|
|
|
|
|
bb.putLong(uuid.getMostSignificantBits());
|
|
|
|
bb.putLong(uuid.getLeastSignificantBits());
|
|
|
|
|
|
|
|
bb.put(6, (byte) (bb.get(6) & 0x0f)); // clear version
|
|
|
|
bb.put(6, (byte) (bb.get(6) | DisguiseConfig.getUUIDGeneratedVersion())); // set to version X (Default 4)
|
|
|
|
|
|
|
|
bb.position(0);
|
|
|
|
|
|
|
|
long firstLong = bb.getLong();
|
|
|
|
long secondLong = bb.getLong();
|
|
|
|
|
|
|
|
return new UUID(firstLong, secondLong);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Class getNmsClass(String className) {
|
|
|
|
try {
|
|
|
|
return Class.forName("net.minecraft.server." + getBukkitVersion() + "." + className);
|
2020-08-13 01:51:32 +02:00
|
|
|
} catch (Exception e) {
|
2019-01-03 03:13:03 +01:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Class getNmsClassIgnoreErrors(String className) {
|
|
|
|
try {
|
|
|
|
return Class.forName("net.minecraft.server." + getBukkitVersion() + "." + className);
|
2020-08-13 01:51:32 +02:00
|
|
|
} catch (Exception ignored) {
|
2019-01-03 03:13:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Constructor getNmsConstructor(Class clazz, Class<?>... parameters) {
|
|
|
|
try {
|
|
|
|
Constructor declaredConstructor = clazz.getDeclaredConstructor(parameters);
|
|
|
|
declaredConstructor.setAccessible(true);
|
|
|
|
return declaredConstructor;
|
2020-08-13 01:51:32 +02:00
|
|
|
} catch (NoSuchMethodException e) {
|
2019-01-03 03:13:03 +01:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Constructor getNmsConstructor(String className, Class<?>... parameters) {
|
|
|
|
return getNmsConstructor(getNmsClass(className), parameters);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Object getNmsEntity(Entity entity) {
|
|
|
|
try {
|
2020-08-13 01:51:32 +02:00
|
|
|
return getNmsEntityMethod.invoke(entity);
|
|
|
|
} catch (Exception ex) {
|
2019-01-03 03:13:03 +01:00
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Field getNmsField(Class clazz, String fieldName) {
|
|
|
|
try {
|
|
|
|
Field declaredField = clazz.getDeclaredField(fieldName);
|
|
|
|
declaredField.setAccessible(true);
|
|
|
|
|
|
|
|
return declaredField;
|
2020-08-13 01:51:32 +02:00
|
|
|
} catch (NoSuchFieldException e) {
|
2019-01-03 03:13:03 +01:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Field getNmsField(String className, String fieldName) {
|
|
|
|
return getNmsField(getNmsClass(className), fieldName);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Object getNmsItem(ItemStack itemstack) {
|
|
|
|
try {
|
2020-08-13 01:51:32 +02:00
|
|
|
return itemAsNmsCopyMethod.invoke(null, itemstack);
|
|
|
|
} catch (Exception e) {
|
2019-01-03 03:13:03 +01:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Method getCraftMethod(String className, String methodName, Class<?>... parameters) {
|
|
|
|
return getCraftMethod(getCraftClass(className), methodName, parameters);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Method getCraftMethod(Class<?> clazz, String methodName, Class<?>... parameters) {
|
|
|
|
try {
|
|
|
|
Method declaredMethod = clazz.getDeclaredMethod(methodName, parameters);
|
|
|
|
declaredMethod.setAccessible(true);
|
|
|
|
|
|
|
|
return declaredMethod;
|
2020-08-13 01:51:32 +02:00
|
|
|
} catch (NoSuchMethodException e) {
|
2019-01-03 03:13:03 +01:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Method getNmsMethod(Class<?> clazz, String methodName, Class<?>... parameters) {
|
|
|
|
try {
|
|
|
|
Method declaredMethod = clazz.getDeclaredMethod(methodName, parameters);
|
|
|
|
declaredMethod.setAccessible(true);
|
|
|
|
|
|
|
|
return declaredMethod;
|
2020-08-13 01:51:32 +02:00
|
|
|
} catch (NoSuchMethodException e) {
|
2019-01-03 03:13:03 +01:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Method getNmsMethod(String className, String methodName, Class<?>... parameters) {
|
|
|
|
return getNmsMethod(getNmsClass(className), methodName, parameters);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static double getPing(Player player) {
|
|
|
|
try {
|
2020-04-04 08:58:21 +02:00
|
|
|
return pingField.getInt(ReflectionManager.getNmsEntity(player));
|
2020-08-13 01:51:32 +02:00
|
|
|
} catch (Exception ex) {
|
2019-01-03 03:13:03 +01:00
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static float[] getSize(Entity entity) {
|
|
|
|
try {
|
2020-02-13 07:47:02 +01:00
|
|
|
if (NmsVersion.v1_14.isSupported()) {
|
|
|
|
Object size = getNmsField("Entity", "size").get(getNmsEntity(entity));
|
|
|
|
|
|
|
|
//float length = getNmsField("EntitySize", "length").getFloat(size);
|
|
|
|
float width = getNmsField("EntitySize", "width").getFloat(size);
|
|
|
|
float height = getNmsField("Entity", "headHeight").getFloat(getNmsEntity(entity));
|
2019-05-18 08:54:51 +02:00
|
|
|
|
2020-02-13 07:47:02 +01:00
|
|
|
return new float[]{width, height};
|
|
|
|
} else {
|
2019-01-03 03:13:03 +01:00
|
|
|
|
2020-02-13 07:47:02 +01:00
|
|
|
// float length = getNmsField("Entity", "length").getFloat(getNmsEntity(entity));
|
|
|
|
float width = getNmsField("Entity", "width").getFloat(getNmsEntity(entity));
|
|
|
|
float height = (Float) getNmsMethod("Entity", "getHeadHeight").invoke(getNmsEntity(entity));
|
|
|
|
return new float[]{width, height};
|
|
|
|
}
|
2020-08-13 01:51:32 +02:00
|
|
|
} catch (Exception ex) {
|
2019-01-03 03:13:03 +01:00
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static WrappedGameProfile getSkullBlob(WrappedGameProfile gameProfile) {
|
|
|
|
try {
|
|
|
|
Object minecraftServer = getMinecraftServer();
|
|
|
|
|
|
|
|
for (Method method : getNmsClass("MinecraftServer").getMethods()) {
|
|
|
|
if (method.getReturnType().getSimpleName().equals("MinecraftSessionService")) {
|
|
|
|
Object session = method.invoke(minecraftServer);
|
|
|
|
|
2021-01-27 07:19:24 +01:00
|
|
|
return WrappedGameProfile.fromHandle(
|
|
|
|
session.getClass().getDeclaredMethod("fillProfileProperties", gameProfile.getHandleType(), boolean.class)
|
|
|
|
.invoke(session, gameProfile.getHandle(), true));
|
2019-01-03 03:13:03 +01:00
|
|
|
}
|
|
|
|
}
|
2020-08-13 01:51:32 +02:00
|
|
|
} catch (Exception ex) {
|
2019-01-03 03:13:03 +01:00
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Float getSoundModifier(Object entity) {
|
|
|
|
try {
|
|
|
|
return (Float) damageAndIdleSoundMethod.invoke(entity);
|
2020-08-13 01:51:32 +02:00
|
|
|
} catch (Exception ignored) {
|
2019-01-03 03:13:03 +01:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2019-12-31 07:35:21 +01:00
|
|
|
/**
|
|
|
|
* Gets the UUID of the player, as well as properly capitalized playername
|
|
|
|
*/
|
2019-01-03 03:13:03 +01:00
|
|
|
public static WrappedGameProfile grabProfileAddUUID(String playername) {
|
|
|
|
try {
|
|
|
|
Object minecraftServer = getMinecraftServer();
|
|
|
|
|
|
|
|
for (Method method : getNmsClass("MinecraftServer").getMethods()) {
|
|
|
|
if (method.getReturnType().getSimpleName().equals("GameProfileRepository")) {
|
|
|
|
Object agent = Class.forName("com.mojang.authlib.Agent").getDeclaredField("MINECRAFT").get(null);
|
|
|
|
|
|
|
|
LibsProfileLookupCaller callback = new LibsProfileLookupCaller();
|
|
|
|
Object profileRepo = method.invoke(minecraftServer);
|
|
|
|
|
2021-01-27 07:19:24 +01:00
|
|
|
method.getReturnType()
|
|
|
|
.getMethod("findProfilesByNames", String[].class, agent.getClass(), Class.forName("com.mojang.authlib.ProfileLookupCallback"))
|
2019-01-03 03:13:03 +01:00
|
|
|
.invoke(profileRepo, new String[]{playername}, agent, callback);
|
|
|
|
|
|
|
|
if (callback.getGameProfile() != null) {
|
|
|
|
return callback.getGameProfile();
|
|
|
|
}
|
|
|
|
|
|
|
|
return getGameProfile(null, playername);
|
|
|
|
}
|
|
|
|
}
|
2020-08-13 01:51:32 +02:00
|
|
|
} catch (Exception ex) {
|
2019-01-03 03:13:03 +01:00
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setBoundingBox(Entity entity, FakeBoundingBox newBox) {
|
|
|
|
try {
|
|
|
|
Location loc = entity.getLocation();
|
|
|
|
|
|
|
|
Object boundingBox = boundingBoxConstructor
|
2021-01-27 07:19:24 +01:00
|
|
|
.newInstance(loc.getX() - (newBox.getX() / 2), loc.getY(), loc.getZ() - (newBox.getZ() / 2), loc.getX() + (newBox.getX() / 2),
|
|
|
|
loc.getY() + newBox.getY(), loc.getZ() + (newBox.getZ() / 2));
|
2019-01-03 03:13:03 +01:00
|
|
|
|
|
|
|
setBoundingBoxMethod.invoke(getNmsEntity(entity), boundingBox);
|
2020-08-13 01:51:32 +02:00
|
|
|
} catch (Exception ex) {
|
2019-01-03 03:13:03 +01:00
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Enum getSoundCategory(String category) {
|
2020-08-13 01:51:32 +02:00
|
|
|
return soundCategories.get(category);
|
2019-01-03 03:13:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static Enum getSoundCategory(DisguiseType disguiseType) {
|
2020-08-13 01:51:32 +02:00
|
|
|
if (disguiseType == DisguiseType.PLAYER) {
|
2019-01-03 03:13:03 +01:00
|
|
|
return getSoundCategory("player");
|
2020-08-13 01:51:32 +02:00
|
|
|
}
|
2019-01-03 03:13:03 +01:00
|
|
|
|
|
|
|
Class<? extends Entity> entityClass = disguiseType.getEntityType().getEntityClass();
|
|
|
|
|
2020-08-13 01:51:32 +02:00
|
|
|
if (Monster.class.isAssignableFrom(entityClass)) {
|
2019-01-03 03:13:03 +01:00
|
|
|
return getSoundCategory("hostile");
|
2020-08-13 01:51:32 +02:00
|
|
|
}
|
2019-01-03 03:13:03 +01:00
|
|
|
|
2020-08-13 01:51:32 +02:00
|
|
|
if (Ambient.class.isAssignableFrom(entityClass)) {
|
2019-01-03 03:13:03 +01:00
|
|
|
return getSoundCategory("ambient");
|
2020-08-13 01:51:32 +02:00
|
|
|
}
|
2019-01-03 03:13:03 +01:00
|
|
|
|
|
|
|
return getSoundCategory("neutral");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates the NMS object EnumItemSlot from an EquipmentSlot.
|
|
|
|
*
|
|
|
|
* @param slot
|
|
|
|
* @return null if the equipment slot is null
|
|
|
|
*/
|
|
|
|
public static Enum createEnumItemSlot(EquipmentSlot slot) {
|
|
|
|
switch (slot) {
|
|
|
|
case HAND:
|
2020-08-13 01:51:32 +02:00
|
|
|
return enumItemSlots[0];
|
2019-01-03 03:13:03 +01:00
|
|
|
case OFF_HAND:
|
2020-08-13 01:51:32 +02:00
|
|
|
return enumItemSlots[1];
|
2019-01-03 03:13:03 +01:00
|
|
|
case FEET:
|
2020-08-13 01:51:32 +02:00
|
|
|
return enumItemSlots[2];
|
2019-01-03 03:13:03 +01:00
|
|
|
case LEGS:
|
2020-08-13 01:51:32 +02:00
|
|
|
return enumItemSlots[3];
|
2019-01-03 03:13:03 +01:00
|
|
|
case CHEST:
|
2020-08-13 01:51:32 +02:00
|
|
|
return enumItemSlots[4];
|
2019-01-03 03:13:03 +01:00
|
|
|
case HEAD:
|
2020-08-13 01:51:32 +02:00
|
|
|
return enumItemSlots[5];
|
2019-01-03 03:13:03 +01:00
|
|
|
default:
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates the Bukkit object EquipmentSlot from an EnumItemSlot object.
|
|
|
|
*
|
|
|
|
* @return null if the object isn't an nms EnumItemSlot
|
|
|
|
*/
|
|
|
|
public static EquipmentSlot createEquipmentSlot(Object enumItemSlot) {
|
|
|
|
try {
|
|
|
|
Enum nmsSlot = (Enum) enumItemSlot;
|
|
|
|
|
|
|
|
switch (nmsSlot.name()) {
|
|
|
|
case "MAINHAND":
|
|
|
|
return EquipmentSlot.HAND;
|
|
|
|
case "OFFHAND":
|
|
|
|
return EquipmentSlot.OFF_HAND;
|
|
|
|
case "FEET":
|
|
|
|
return EquipmentSlot.FEET;
|
|
|
|
case "LEGS":
|
|
|
|
return EquipmentSlot.LEGS;
|
|
|
|
case "CHEST":
|
|
|
|
return EquipmentSlot.CHEST;
|
|
|
|
case "HEAD":
|
|
|
|
return EquipmentSlot.HEAD;
|
|
|
|
}
|
2020-08-13 01:51:32 +02:00
|
|
|
} catch (Exception ignored) {
|
2019-01-03 03:13:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets equipment from this entity based on the slot given.
|
|
|
|
*
|
|
|
|
* @param slot
|
|
|
|
* @return null if the disguisedEntity is not an instance of a living entity
|
|
|
|
*/
|
|
|
|
public static ItemStack getEquipment(EquipmentSlot slot, Entity disguisedEntity) {
|
2020-08-13 01:51:32 +02:00
|
|
|
if (!(disguisedEntity instanceof LivingEntity)) {
|
2019-01-03 03:13:03 +01:00
|
|
|
return null;
|
2020-08-13 01:51:32 +02:00
|
|
|
}
|
2019-01-03 03:13:03 +01:00
|
|
|
|
|
|
|
switch (slot) {
|
|
|
|
case HAND:
|
|
|
|
return ((LivingEntity) disguisedEntity).getEquipment().getItemInMainHand();
|
|
|
|
case OFF_HAND:
|
|
|
|
return ((LivingEntity) disguisedEntity).getEquipment().getItemInOffHand();
|
|
|
|
case FEET:
|
|
|
|
return ((LivingEntity) disguisedEntity).getEquipment().getBoots();
|
|
|
|
case LEGS:
|
|
|
|
return ((LivingEntity) disguisedEntity).getEquipment().getLeggings();
|
|
|
|
case CHEST:
|
|
|
|
return ((LivingEntity) disguisedEntity).getEquipment().getChestplate();
|
|
|
|
case HEAD:
|
|
|
|
return ((LivingEntity) disguisedEntity).getEquipment().getHelmet();
|
|
|
|
default:
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Object getSoundString(Sound sound) {
|
|
|
|
try {
|
2020-11-26 06:54:59 +01:00
|
|
|
if (soundGetMethod == null) {
|
|
|
|
return soundEffectGetKey.get(soundEffectGetMethod.invoke(null, sound)).toString();
|
|
|
|
}
|
|
|
|
|
2020-11-26 06:36:30 +01:00
|
|
|
return soundGetMethod.invoke(null, sound);
|
|
|
|
} catch (IllegalAccessException | InvocationTargetException e) {
|
|
|
|
e.printStackTrace();
|
2019-01-03 03:13:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2019-07-09 10:52:00 +02:00
|
|
|
public static Class getNmsClass(Class cl) {
|
|
|
|
if (VillagerData.class.isAssignableFrom(cl)) {
|
|
|
|
return getNmsClass("VillagerData");
|
|
|
|
} else if (BlockPosition.class.isAssignableFrom(cl)) {
|
|
|
|
return getNmsClass("BlockPosition");
|
|
|
|
} else if (WrappedBlockData.class.isAssignableFrom(cl)) {
|
|
|
|
return getNmsClass("IBlockData");
|
|
|
|
} else if (ItemStack.class.isAssignableFrom(cl)) {
|
|
|
|
return getNmsClass("ItemStack");
|
|
|
|
} else if (WrappedChatComponent.class.isAssignableFrom(cl)) {
|
|
|
|
return getNmsClass("IChatBaseComponent");
|
|
|
|
} else if (Vector3F.class.isAssignableFrom(cl)) {
|
|
|
|
return getNmsClass("Vector3f");
|
2021-05-04 13:06:55 +02:00
|
|
|
} else if (EulerAngle.class.isAssignableFrom(cl)) {
|
|
|
|
return getNmsClass("Vector3f");
|
2019-07-09 10:52:00 +02:00
|
|
|
} else if (Direction.class.isAssignableFrom(cl)) {
|
|
|
|
return getNmsClass("EnumDirection");
|
|
|
|
} else if (WrappedParticle.class.isAssignableFrom(cl)) {
|
|
|
|
return getNmsClass("ParticleParam");
|
|
|
|
} else if (EntityPose.class.isAssignableFrom(cl)) {
|
2020-08-13 01:51:32 +02:00
|
|
|
return entityPoseClass;
|
2019-07-09 10:52:00 +02:00
|
|
|
} else if (NbtWrapper.class.isAssignableFrom(cl)) {
|
|
|
|
return getNmsClass("NBTTagCompound");
|
|
|
|
}
|
|
|
|
|
|
|
|
return cl;
|
|
|
|
}
|
|
|
|
|
2019-01-03 03:13:03 +01:00
|
|
|
public static Object convertInvalidMeta(Object value) {
|
|
|
|
if (value instanceof Optional) {
|
|
|
|
Optional opt = (Optional) value;
|
|
|
|
|
2020-08-13 01:51:32 +02:00
|
|
|
if (!opt.isPresent()) {
|
2020-02-13 22:06:49 +01:00
|
|
|
return NmsVersion.v1_13.isSupported() ? value : com.google.common.base.Optional.absent();
|
2020-08-13 01:51:32 +02:00
|
|
|
}
|
2019-01-03 03:13:03 +01:00
|
|
|
|
|
|
|
Object val = opt.get();
|
|
|
|
|
|
|
|
if (val instanceof BlockPosition) {
|
|
|
|
BlockPosition pos = (BlockPosition) val;
|
|
|
|
|
|
|
|
try {
|
2020-08-13 01:51:32 +02:00
|
|
|
Object obj = blockPositionConstructor.newInstance(pos.getX(), pos.getY(), pos.getZ());
|
2020-02-13 22:06:49 +01:00
|
|
|
|
|
|
|
return NmsVersion.v1_13.isSupported() ? Optional.of(obj) : com.google.common.base.Optional.of(obj);
|
2020-08-13 01:51:32 +02:00
|
|
|
} catch (Exception ex) {
|
2019-01-03 03:13:03 +01:00
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
} else if (val instanceof WrappedBlockData) {
|
|
|
|
try {
|
2020-02-13 22:06:49 +01:00
|
|
|
Object obj = ((WrappedBlockData) val).getHandle();
|
|
|
|
return NmsVersion.v1_13.isSupported() ? Optional.of(obj) : com.google.common.base.Optional.of(obj);
|
2020-08-13 01:51:32 +02:00
|
|
|
} catch (Exception ex) {
|
2019-01-03 03:13:03 +01:00
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
} else if (val instanceof ItemStack) {
|
|
|
|
val = getNmsItem((ItemStack) val);
|
|
|
|
|
2020-08-13 01:51:32 +02:00
|
|
|
if (val == null) {
|
2020-02-13 22:06:49 +01:00
|
|
|
return NmsVersion.v1_13.isSupported() ? Optional.empty() : com.google.common.base.Optional.absent();
|
2020-08-13 01:51:32 +02:00
|
|
|
} else {
|
2019-01-03 03:13:03 +01:00
|
|
|
return Optional.of(val);
|
2020-08-13 01:51:32 +02:00
|
|
|
}
|
2019-01-03 03:13:03 +01:00
|
|
|
} else if (val instanceof WrappedChatComponent) {
|
2020-02-13 22:06:49 +01:00
|
|
|
Object obj = ((WrappedChatComponent) val).getHandle();
|
|
|
|
|
|
|
|
return NmsVersion.v1_13.isSupported() ? Optional.of(obj) : com.google.common.base.Optional.of(obj);
|
2020-02-19 00:57:39 +01:00
|
|
|
} else if (!NmsVersion.v1_13.isSupported()) {
|
2020-02-13 22:06:49 +01:00
|
|
|
return com.google.common.base.Optional.of(val);
|
2019-01-03 03:13:03 +01:00
|
|
|
}
|
|
|
|
} else if (value instanceof Vector3F) {
|
|
|
|
Vector3F angle = (Vector3F) value;
|
|
|
|
|
|
|
|
try {
|
2020-08-13 01:51:32 +02:00
|
|
|
return vector3FConstructor.newInstance(angle.getX(), angle.getY(), angle.getZ());
|
|
|
|
} catch (Exception ex) {
|
2019-01-03 03:13:03 +01:00
|
|
|
ex.printStackTrace();
|
2021-05-04 13:06:55 +02:00
|
|
|
}
|
|
|
|
} else if (value instanceof EulerAngle) {
|
|
|
|
EulerAngle angle = (EulerAngle) value;
|
|
|
|
|
|
|
|
try {
|
|
|
|
return vector3FConstructor.newInstance((float) angle.getX(), (float) angle.getY(), (float) angle.getZ());
|
|
|
|
} catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
2019-01-03 03:13:03 +01:00
|
|
|
}
|
|
|
|
} else if (value instanceof Direction) {
|
|
|
|
try {
|
2020-08-13 01:51:32 +02:00
|
|
|
return enumDirectionFrom.invoke(null, ((Direction) value).ordinal());
|
|
|
|
} catch (Exception ex) {
|
2019-01-03 03:13:03 +01:00
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
} else if (value instanceof BlockPosition) {
|
|
|
|
BlockPosition pos = (BlockPosition) value;
|
|
|
|
|
|
|
|
try {
|
2020-08-13 01:51:32 +02:00
|
|
|
return blockPositionConstructor.newInstance(pos.getX(), pos.getY(), pos.getZ());
|
|
|
|
} catch (Exception ex) {
|
2019-01-03 03:13:03 +01:00
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
} else if (value instanceof ItemStack) {
|
|
|
|
return getNmsItem((ItemStack) value);
|
|
|
|
} else if (value instanceof Double) {
|
|
|
|
return ((Double) value).floatValue();
|
|
|
|
} else if (value instanceof NbtWrapper) {
|
|
|
|
return ((NbtWrapper) value).getHandle();
|
|
|
|
} else if (value instanceof WrappedParticle) {
|
|
|
|
return ((WrappedParticle) value).getHandle();
|
2019-05-18 08:54:51 +02:00
|
|
|
} else if (value instanceof EntityPose) {
|
|
|
|
return getNmsEntityPose((EntityPose) value);
|
|
|
|
} else if (value instanceof VillagerData) {
|
|
|
|
return getNmsVillagerData((VillagerData) value);
|
2019-09-16 04:35:39 +02:00
|
|
|
} else if (value instanceof WrappedChatComponent) {
|
|
|
|
return ((WrappedChatComponent) value).getHandle();
|
2019-01-03 03:13:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2020-02-19 00:57:39 +01:00
|
|
|
public static Material getMaterial(String name) {
|
|
|
|
try {
|
|
|
|
if (!NmsVersion.v1_13.isSupported()) {
|
2021-01-27 07:19:24 +01:00
|
|
|
Method toMinecraft = getCraftMethod("util.CraftMagicNumbers", "getMaterialFromInternalName", String.class);
|
2020-02-19 00:57:39 +01:00
|
|
|
|
2020-07-04 08:01:30 +02:00
|
|
|
Object instance = toMinecraft.getDeclaringClass().getField("INSTANCE").get(null);
|
|
|
|
|
|
|
|
return (Material) toMinecraft.invoke(instance, name);
|
2020-02-19 00:57:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Object mcKey = getNmsConstructor("MinecraftKey", String.class).newInstance(name);
|
|
|
|
|
|
|
|
Object registry = getNmsField("IRegistry", "ITEM").get(null);
|
|
|
|
|
|
|
|
Method getMethod = getNmsMethod(getNmsClass("RegistryMaterials"), "get", mcKey.getClass());
|
|
|
|
Object item = getMethod.invoke(registry, mcKey);
|
|
|
|
|
|
|
|
if (item == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
Method getMaterial = getCraftMethod("util.CraftMagicNumbers", "getMaterial", getNmsClass("Item"));
|
|
|
|
|
|
|
|
return (Material) getMaterial.invoke(null, item);
|
2020-08-13 01:51:32 +02:00
|
|
|
} catch (Exception ex) {
|
2020-07-04 08:01:30 +02:00
|
|
|
DisguiseUtilities.getLogger().severe("Error when trying to convert '" + name + "' into a Material");
|
2020-02-19 00:57:39 +01:00
|
|
|
ex.printStackTrace();
|
2020-07-04 08:01:30 +02:00
|
|
|
|
|
|
|
if (ex.getCause() != null) {
|
|
|
|
ex.getCause().printStackTrace();
|
|
|
|
}
|
2020-02-19 00:57:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String getItemName(Material material) {
|
|
|
|
try {
|
|
|
|
Object item = getCraftMethod("util.CraftMagicNumbers", "getItem", Material.class).invoke(null, material);
|
|
|
|
|
|
|
|
if (item == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
Object registry;
|
|
|
|
|
|
|
|
if (NmsVersion.v1_13.isSupported()) {
|
|
|
|
registry = getNmsField("IRegistry", "ITEM").get(null);
|
|
|
|
} else {
|
|
|
|
registry = getNmsField("Item", "REGISTRY").get(null);
|
|
|
|
}
|
|
|
|
|
2021-01-27 07:19:24 +01:00
|
|
|
Method getMethod = getNmsMethod(registry.getClass(), NmsVersion.v1_13.isSupported() ? "getKey" : "b", Object.class);
|
2020-02-19 00:57:39 +01:00
|
|
|
|
|
|
|
Object mcKey = getMethod.invoke(registry, item);
|
|
|
|
|
|
|
|
if (mcKey == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (String) getNmsMethod("MinecraftKey", "getKey").invoke(mcKey);
|
2020-08-13 01:51:32 +02:00
|
|
|
} catch (Exception ex) {
|
2020-02-19 00:57:39 +01:00
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2019-05-18 08:54:51 +02:00
|
|
|
public static Object getNmsVillagerData(VillagerData data) {
|
|
|
|
Object type = getVillagerType(data.getType());
|
|
|
|
Object profession = getVillagerProfession(data.getProfession());
|
|
|
|
|
|
|
|
try {
|
2020-08-13 01:51:32 +02:00
|
|
|
return villagerDataConstructor.newInstance(type, profession, data.getLevel());
|
|
|
|
} catch (Exception e) {
|
2019-05-18 08:54:51 +02:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Object getVillagerType(Villager.Type type) {
|
|
|
|
try {
|
2020-08-13 01:51:32 +02:00
|
|
|
Object mcKey = bukkitKeyToNms.invoke(null, type.getKey());
|
2019-05-18 08:54:51 +02:00
|
|
|
|
2020-08-13 01:51:32 +02:00
|
|
|
return registryBlocksGetMethod.invoke(villagerTypeRegistry, mcKey);
|
|
|
|
} catch (Exception e) {
|
2019-05-18 08:54:51 +02:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-02-13 07:47:02 +01:00
|
|
|
public static boolean isAssignableFrom(Class toCheck, Class checkAgainst) {
|
|
|
|
if (!NmsVersion.v1_14.isSupported() && toCheck != checkAgainst) {
|
|
|
|
if (toCheck == OcelotWatcher.class) {
|
|
|
|
toCheck = TameableWatcher.class;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return checkAgainst.isAssignableFrom(toCheck);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Class getSuperClass(Class cl) {
|
|
|
|
if (cl == FlagWatcher.class) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!NmsVersion.v1_14.isSupported()) {
|
|
|
|
if (cl == OcelotWatcher.class) {
|
|
|
|
return TameableWatcher.class;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return cl.getSuperclass();
|
|
|
|
}
|
|
|
|
|
2019-05-18 08:54:51 +02:00
|
|
|
public static Object getVillagerProfession(Villager.Profession profession) {
|
|
|
|
try {
|
2020-08-13 01:51:32 +02:00
|
|
|
Object mcKey = bukkitKeyToNms.invoke(null, profession.getKey());
|
2019-05-18 08:54:51 +02:00
|
|
|
|
2020-08-13 01:51:32 +02:00
|
|
|
return registryBlocksGetMethod.invoke(villagerProfessionRegistry, mcKey);
|
|
|
|
} catch (Exception e) {
|
2019-05-18 08:54:51 +02:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2019-01-03 03:13:03 +01:00
|
|
|
public static String getMinecraftVersion() {
|
|
|
|
String version = Bukkit.getVersion();
|
|
|
|
version = version.substring(version.lastIndexOf(" ") + 1, version.length() - 1);
|
|
|
|
return version;
|
|
|
|
}
|
|
|
|
|
2019-07-09 10:52:00 +02:00
|
|
|
public static WrappedDataWatcherObject createDataWatcherObject(MetaIndex index, Object value) {
|
2020-08-13 01:51:32 +02:00
|
|
|
if (value == null) {
|
2019-01-03 03:13:03 +01:00
|
|
|
return null;
|
2020-08-13 01:51:32 +02:00
|
|
|
}
|
2019-01-03 03:13:03 +01:00
|
|
|
|
2019-07-09 10:52:00 +02:00
|
|
|
return new WrappedDataWatcherObject(index.getIndex(), index.getSerializer());
|
2019-01-03 03:13:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This creates a DataWatcherItem usable with WrappedWatchableObject
|
|
|
|
*
|
|
|
|
* @param id
|
|
|
|
* @param value
|
|
|
|
* @return
|
|
|
|
*/
|
2019-07-09 10:52:00 +02:00
|
|
|
public static Object createDataWatcherItem(MetaIndex id, Object value) {
|
2019-01-03 03:13:03 +01:00
|
|
|
WrappedDataWatcherObject watcherObject = createDataWatcherObject(id, value);
|
|
|
|
|
|
|
|
try {
|
2020-08-13 01:51:32 +02:00
|
|
|
return dataWatcherItemConstructor.newInstance(watcherObject.getHandle(), convertInvalidMeta(value));
|
|
|
|
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
|
2019-01-03 03:13:03 +01:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-11-20 02:14:42 +01:00
|
|
|
@Deprecated
|
2020-05-23 15:44:19 +02:00
|
|
|
public static Object createSoundEffect(String minecraftKey) {
|
|
|
|
try {
|
2021-01-27 07:19:24 +01:00
|
|
|
return getNmsConstructor("SoundEffect", getNmsClass("MinecraftKey")).newInstance(createMinecraftKey(minecraftKey));
|
2020-08-13 01:51:32 +02:00
|
|
|
} catch (Exception ex) {
|
2020-05-23 15:44:19 +02:00
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2019-01-03 03:13:03 +01:00
|
|
|
public static Object createMinecraftKey(String name) {
|
|
|
|
try {
|
2020-08-13 01:51:32 +02:00
|
|
|
return getNmsConstructor("MinecraftKey", String.class).newInstance(name);
|
|
|
|
} catch (Exception ex) {
|
2019-01-03 03:13:03 +01:00
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2019-05-18 08:54:51 +02:00
|
|
|
public static Object getVec3D(Vector vector) {
|
2019-01-03 03:13:03 +01:00
|
|
|
try {
|
2020-08-13 01:51:32 +02:00
|
|
|
return vec3DConstructor.newInstance(vector.getX(), vector.getY(), vector.getZ());
|
|
|
|
} catch (Exception ex) {
|
2019-05-18 08:54:51 +02:00
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
2019-01-03 03:13:03 +01:00
|
|
|
|
2019-05-18 08:54:51 +02:00
|
|
|
return null;
|
|
|
|
}
|
2019-01-03 03:13:03 +01:00
|
|
|
|
2019-05-18 08:54:51 +02:00
|
|
|
public static Object getEntityType(EntityType entityType) {
|
|
|
|
try {
|
2021-01-27 07:19:24 +01:00
|
|
|
Object val = entityTypesAMethod.invoke(null, entityType.getName() == null ? entityType.name().toLowerCase(Locale.ENGLISH) : entityType.getName());
|
2019-01-03 03:13:03 +01:00
|
|
|
|
2020-02-13 07:47:02 +01:00
|
|
|
if (NmsVersion.v1_14.isSupported()) {
|
|
|
|
return ((Optional<Object>) val).orElse(null);
|
|
|
|
}
|
2019-05-18 08:54:51 +02:00
|
|
|
|
2020-02-13 07:47:02 +01:00
|
|
|
return val;
|
2020-08-13 01:51:32 +02:00
|
|
|
} catch (Exception e) {
|
2019-05-18 08:54:51 +02:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-04-15 14:55:35 +02:00
|
|
|
public static Object registerEntityType(NamespacedKey key) {
|
|
|
|
try {
|
|
|
|
Object mcKey = getNmsConstructor("MinecraftKey", String.class).newInstance(key.toString());
|
|
|
|
|
|
|
|
Class typesClass = getNmsClass("IRegistry");
|
|
|
|
|
|
|
|
Object registry = typesClass.getField("ENTITY_TYPE").get(null);
|
|
|
|
|
|
|
|
Constructor c = getNmsClass("EntityTypes").getConstructors()[0];
|
|
|
|
|
2020-06-25 05:33:28 +02:00
|
|
|
Object entityType;
|
|
|
|
|
2020-04-15 14:55:35 +02:00
|
|
|
// UGLY :D
|
2020-06-25 05:33:28 +02:00
|
|
|
if (NmsVersion.v1_16.isSupported()) {
|
|
|
|
entityType = c.newInstance(null, null, false, false, false, false, null, null, 0, 0);
|
|
|
|
} else {
|
|
|
|
entityType = c.newInstance(null, null, false, false, false, false, null);
|
|
|
|
}
|
2020-04-15 14:55:35 +02:00
|
|
|
|
|
|
|
for (Field f : entityType.getClass().getDeclaredFields()) {
|
|
|
|
if (f.getType() != String.class) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
f.setAccessible(true);
|
|
|
|
f.set(entityType, key.toString());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-01-27 07:19:24 +01:00
|
|
|
typesClass.getMethod("a", typesClass, mcKey.getClass(), Object.class).invoke(null, registry, mcKey, entityType);
|
2020-04-15 14:55:35 +02:00
|
|
|
|
|
|
|
return entityType;
|
2020-08-13 01:51:32 +02:00
|
|
|
} catch (Exception e) {
|
2020-04-15 14:55:35 +02:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new IllegalStateException("Failed to find EntityType id for " + key);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static int getEntityTypeId(Object entityTypes) {
|
|
|
|
try {
|
|
|
|
Class typesClass = getNmsClass("IRegistry");
|
|
|
|
|
|
|
|
Object registry = typesClass.getField("ENTITY_TYPE").get(null);
|
|
|
|
|
|
|
|
return (int) registry.getClass().getMethod("a", Object.class).invoke(registry, entityTypes);
|
2020-08-13 01:51:32 +02:00
|
|
|
} catch (Exception ex) {
|
2020-04-15 14:55:35 +02:00
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new IllegalStateException("Failed to find EntityType id for " + entityTypes);
|
|
|
|
}
|
|
|
|
|
2019-05-18 08:54:51 +02:00
|
|
|
public static int getEntityTypeId(EntityType entityType) {
|
|
|
|
try {
|
2020-02-13 22:06:49 +01:00
|
|
|
if (NmsVersion.v1_13.isSupported()) {
|
|
|
|
Object entityTypes = getEntityType(entityType);
|
2019-05-18 08:54:51 +02:00
|
|
|
|
2020-02-13 22:06:49 +01:00
|
|
|
Class typesClass = getNmsClass("IRegistry");
|
2019-05-18 08:54:51 +02:00
|
|
|
|
2020-02-13 22:06:49 +01:00
|
|
|
Object registry = typesClass.getField("ENTITY_TYPE").get(null);
|
|
|
|
|
|
|
|
return (int) registry.getClass().getMethod("a", Object.class).invoke(registry, entityTypes);
|
|
|
|
}
|
2019-05-18 08:54:51 +02:00
|
|
|
|
2020-02-13 22:06:49 +01:00
|
|
|
return entityType.getTypeId();
|
2020-08-13 01:51:32 +02:00
|
|
|
} catch (Exception ex) {
|
2019-01-03 03:13:03 +01:00
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
|
2019-05-18 08:54:51 +02:00
|
|
|
throw new IllegalStateException("Failed to find EntityType id for " + entityType);
|
|
|
|
}
|
|
|
|
|
2020-04-15 14:55:35 +02:00
|
|
|
public static Object getEntityType(NamespacedKey name) {
|
|
|
|
try {
|
|
|
|
Class typesClass = getNmsClass("IRegistry");
|
|
|
|
|
|
|
|
Object registry = typesClass.getField("ENTITY_TYPE").get(null);
|
|
|
|
Object mcKey = getNmsConstructor("MinecraftKey", String.class).newInstance(name.toString());
|
|
|
|
|
|
|
|
return registry.getClass().getMethod("a", mcKey.getClass()).invoke(registry, mcKey);
|
2020-08-13 01:51:32 +02:00
|
|
|
} catch (Exception ex) {
|
2020-04-15 14:55:35 +02:00
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new IllegalStateException("The entity " + name + " is not registered!");
|
|
|
|
}
|
|
|
|
|
2019-05-18 08:54:51 +02:00
|
|
|
public static Object getNmsEntityPose(EntityPose entityPose) {
|
2021-01-27 07:19:24 +01:00
|
|
|
return Enum.valueOf(entityPoseClass, entityPose == EntityPose.SNEAKING && NmsVersion.v1_15.isSupported() ? "CROUCHING" : entityPose.name());
|
2019-05-18 08:54:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static EntityPose getEntityPose(Object nmsEntityPose) {
|
2020-04-21 10:31:52 +02:00
|
|
|
String name = ((Enum) nmsEntityPose).name();
|
|
|
|
return EntityPose.valueOf(name.equals("CROUCHING") ? "SNEAKING" : name);
|
2019-01-03 03:13:03 +01:00
|
|
|
}
|
|
|
|
|
2019-07-09 10:52:00 +02:00
|
|
|
public static WrappedWatchableObject createWatchable(MetaIndex index, Object obj) {
|
2019-01-03 03:13:03 +01:00
|
|
|
Object watcherItem = createDataWatcherItem(index, obj);
|
|
|
|
|
2020-08-13 01:51:32 +02:00
|
|
|
if (watcherItem == null) {
|
2019-01-03 03:13:03 +01:00
|
|
|
return null;
|
2020-08-13 01:51:32 +02:00
|
|
|
}
|
2019-01-03 03:13:03 +01:00
|
|
|
|
|
|
|
return new WrappedWatchableObject(watcherItem);
|
|
|
|
}
|
|
|
|
|
2020-08-11 23:36:13 +02:00
|
|
|
public static int getCombinedIdByBlockData(BlockData data) {
|
|
|
|
try {
|
2020-08-13 01:51:32 +02:00
|
|
|
Object iBlockData = craftBlockDataGetState.invoke(data);
|
2020-08-11 23:36:13 +02:00
|
|
|
|
|
|
|
return (int) getNmsMethod("Block", "getCombinedId", getNmsClass("IBlockData")).invoke(null, iBlockData);
|
2020-08-13 01:51:32 +02:00
|
|
|
} catch (Exception ex) {
|
2020-08-11 23:36:13 +02:00
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-01-03 03:13:03 +01:00
|
|
|
public static int getCombinedIdByItemStack(ItemStack itemStack) {
|
|
|
|
try {
|
2020-06-24 07:20:18 +02:00
|
|
|
Object nmsBlock;
|
2019-01-03 03:13:03 +01:00
|
|
|
|
2020-06-24 07:20:18 +02:00
|
|
|
if (NmsVersion.v1_13.isSupported()) {
|
2020-08-13 01:51:32 +02:00
|
|
|
nmsBlock = magicGetBlock.invoke(null, itemStack.getType());
|
2020-06-24 07:20:18 +02:00
|
|
|
} else {
|
|
|
|
Object nmsItem = getNmsItem(itemStack);
|
|
|
|
|
2020-08-13 01:51:32 +02:00
|
|
|
Object item = getNmsItem.invoke(nmsItem);
|
2020-06-24 07:20:18 +02:00
|
|
|
|
2020-08-13 01:51:32 +02:00
|
|
|
nmsBlock = getOldItemAsBlock.invoke(null, item);
|
2020-06-24 07:20:18 +02:00
|
|
|
}
|
2019-01-03 03:13:03 +01:00
|
|
|
|
2020-08-13 01:51:32 +02:00
|
|
|
Object iBlockData = getBlockData.invoke(nmsBlock);
|
2019-01-03 03:13:03 +01:00
|
|
|
|
2020-08-13 01:51:32 +02:00
|
|
|
return (int) getBlockDataAsId.invoke(null, iBlockData);
|
|
|
|
} catch (Exception ex) {
|
2019-01-03 03:13:03 +01:00
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-08-12 05:49:03 +02:00
|
|
|
public static BlockData getBlockDataByCombinedId(int id) {
|
|
|
|
try {
|
|
|
|
Method idMethod = getNmsMethod("Block", "getByCombinedId", int.class);
|
|
|
|
Object iBlockData = idMethod.invoke(null, id);
|
|
|
|
Class iBlockClass = getNmsClass("IBlockData");
|
|
|
|
|
2021-01-27 07:19:24 +01:00
|
|
|
return (BlockData) getCraftMethod("block.data.CraftBlockData", "fromData", iBlockClass).invoke(null, iBlockData);
|
2020-08-13 01:51:32 +02:00
|
|
|
} catch (Exception ex) {
|
2020-08-12 05:49:03 +02:00
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2019-01-03 03:13:03 +01:00
|
|
|
public static ItemStack getItemStackByCombinedId(int id) {
|
|
|
|
try {
|
|
|
|
Method idMethod = getNmsMethod("Block", "getByCombinedId", int.class);
|
|
|
|
Object iBlockData = idMethod.invoke(null, id);
|
2021-05-15 06:29:09 +02:00
|
|
|
|
2019-01-03 03:13:03 +01:00
|
|
|
Class iBlockClass = getNmsClass("IBlockData");
|
|
|
|
|
2021-05-15 06:29:09 +02:00
|
|
|
Method getBlock = getNmsMethod(NmsVersion.v1_16.isSupported() ? iBlockClass.getSuperclass() : iBlockClass, "getBlock");
|
2019-01-03 03:13:03 +01:00
|
|
|
Object block = getBlock.invoke(iBlockData);
|
|
|
|
|
2021-05-15 06:29:09 +02:00
|
|
|
if (NmsVersion.v1_13.isSupported()) {
|
|
|
|
return new ItemStack((Material) magicGetMaterial.invoke(null, block));
|
|
|
|
}
|
|
|
|
|
|
|
|
Method getItem = getNmsMethod("Block", "u", iBlockClass);
|
2019-01-03 03:13:03 +01:00
|
|
|
|
|
|
|
return getBukkitItem(getItem.invoke(block, iBlockData));
|
2020-08-13 01:51:32 +02:00
|
|
|
} catch (Exception ex) {
|
2019-01-03 03:13:03 +01:00
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Object getWorldServer(World w) {
|
|
|
|
try {
|
2020-08-13 01:51:32 +02:00
|
|
|
return getNmsWorld.invoke(w);
|
|
|
|
} catch (IllegalAccessException | InvocationTargetException e) {
|
2019-01-03 03:13:03 +01:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2019-12-21 02:45:10 +01:00
|
|
|
|
|
|
|
public static ItemMeta getDeserializedItemMeta(Map<String, Object> meta) {
|
|
|
|
try {
|
2020-08-13 01:51:32 +02:00
|
|
|
return (ItemMeta) deserializedItemMeta.invoke(null, meta);
|
|
|
|
} catch (Exception e) {
|
2019-12-21 02:45:10 +01:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2020-01-19 03:48:26 +01:00
|
|
|
|
|
|
|
private static Class<? extends FlagWatcher> getFlagWatcher(DisguiseType disguiseType) {
|
|
|
|
Class<? extends FlagWatcher> watcherClass;
|
|
|
|
|
|
|
|
try {
|
|
|
|
switch (disguiseType) {
|
|
|
|
case ARROW:
|
|
|
|
watcherClass = TippedArrowWatcher.class;
|
|
|
|
break;
|
2020-04-18 22:19:03 +02:00
|
|
|
case MODDED_LIVING:
|
|
|
|
case MODDED_MISC:
|
|
|
|
watcherClass = ModdedWatcher.class;
|
2020-04-15 14:55:35 +02:00
|
|
|
break;
|
2020-01-19 03:48:26 +01:00
|
|
|
case COD:
|
|
|
|
case SALMON:
|
|
|
|
watcherClass = FishWatcher.class;
|
|
|
|
break;
|
|
|
|
case SPECTRAL_ARROW:
|
|
|
|
watcherClass = ArrowWatcher.class;
|
|
|
|
break;
|
|
|
|
case PRIMED_TNT:
|
|
|
|
watcherClass = TNTWatcher.class;
|
|
|
|
break;
|
|
|
|
case MINECART_CHEST:
|
|
|
|
case MINECART_HOPPER:
|
|
|
|
case MINECART_MOB_SPAWNER:
|
|
|
|
case MINECART_TNT:
|
|
|
|
watcherClass = MinecartWatcher.class;
|
|
|
|
break;
|
|
|
|
case SPIDER:
|
|
|
|
case CAVE_SPIDER:
|
|
|
|
watcherClass = SpiderWatcher.class;
|
|
|
|
break;
|
|
|
|
case PIG_ZOMBIE:
|
|
|
|
case HUSK:
|
|
|
|
case DROWNED:
|
2020-06-25 05:33:28 +02:00
|
|
|
case ZOMBIFIED_PIGLIN:
|
2020-01-19 03:48:26 +01:00
|
|
|
watcherClass = ZombieWatcher.class;
|
|
|
|
break;
|
|
|
|
case MAGMA_CUBE:
|
|
|
|
watcherClass = SlimeWatcher.class;
|
|
|
|
break;
|
|
|
|
case ELDER_GUARDIAN:
|
|
|
|
watcherClass = GuardianWatcher.class;
|
|
|
|
break;
|
|
|
|
case WITHER_SKELETON:
|
|
|
|
case STRAY:
|
|
|
|
watcherClass = SkeletonWatcher.class;
|
|
|
|
break;
|
|
|
|
case ILLUSIONER:
|
|
|
|
case EVOKER:
|
|
|
|
watcherClass = IllagerWizardWatcher.class;
|
|
|
|
break;
|
|
|
|
case PUFFERFISH:
|
|
|
|
watcherClass = PufferFishWatcher.class;
|
|
|
|
break;
|
|
|
|
default:
|
2021-01-27 07:19:24 +01:00
|
|
|
watcherClass = (Class<? extends FlagWatcher>) Class
|
|
|
|
.forName("me.libraryaddict.disguise.disguisetypes.watchers." + toReadable(disguiseType.name()) + "Watcher");
|
2020-01-19 03:48:26 +01:00
|
|
|
break;
|
|
|
|
}
|
2020-08-13 01:51:32 +02:00
|
|
|
} catch (ClassNotFoundException ex) {
|
2020-01-19 03:48:26 +01:00
|
|
|
// There is no explicit watcher for this entity.
|
|
|
|
Class entityClass = disguiseType.getEntityType().getEntityClass();
|
|
|
|
|
|
|
|
if (entityClass != null) {
|
|
|
|
if (Tameable.class.isAssignableFrom(entityClass)) {
|
|
|
|
watcherClass = TameableWatcher.class;
|
|
|
|
} else if (Ageable.class.isAssignableFrom(entityClass)) {
|
|
|
|
watcherClass = AgeableWatcher.class;
|
|
|
|
} else if (Creature.class.isAssignableFrom(entityClass)) {
|
|
|
|
watcherClass = InsentientWatcher.class;
|
|
|
|
} else if (LivingEntity.class.isAssignableFrom(entityClass)) {
|
|
|
|
watcherClass = LivingWatcher.class;
|
|
|
|
} else if (Fish.class.isAssignableFrom(entityClass)) {
|
|
|
|
watcherClass = FishWatcher.class;
|
|
|
|
} else {
|
|
|
|
watcherClass = FlagWatcher.class;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
watcherClass = FlagWatcher.class; // Disguise is unknown type
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return watcherClass;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Here we create a nms entity for each disguise. Then grab their default values in their datawatcher. Then their
|
|
|
|
* sound volume
|
|
|
|
* for mob noises. As well as setting their watcher class and entity size.
|
|
|
|
*/
|
|
|
|
public static void registerValues() {
|
|
|
|
for (DisguiseType disguiseType : DisguiseType.values()) {
|
|
|
|
if (disguiseType.getEntityType() == null) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
Class watcherClass = getFlagWatcher(disguiseType);
|
|
|
|
|
|
|
|
if (watcherClass == null) {
|
2021-01-27 07:19:24 +01:00
|
|
|
DisguiseUtilities.getLogger().severe("Error loading " + disguiseType.name() + ", FlagWatcher not assigned");
|
2020-01-19 03:48:26 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Invalidate invalid distribution
|
2021-01-27 07:19:24 +01:00
|
|
|
if (LibsPremium.isPremium() && ((LibsPremium.getPaidInformation() != null && LibsPremium.getPaidInformation().isPremium() &&
|
|
|
|
!LibsPremium.getPaidInformation().isLegit()) ||
|
|
|
|
(LibsPremium.getPluginInformation() != null && LibsPremium.getPluginInformation().isPremium() &&
|
|
|
|
!LibsPremium.getPluginInformation().isLegit()))) {
|
2020-01-19 03:48:26 +01:00
|
|
|
throw new IllegalStateException(
|
2021-01-27 07:19:24 +01:00
|
|
|
"Error while checking pi rate on startup! Please re-download the jar from SpigotMC before " + "reporting this error!");
|
2020-01-19 03:48:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
disguiseType.setWatcherClass(watcherClass);
|
|
|
|
|
|
|
|
if (LibsDisguises.getInstance() == null || DisguiseValues.getDisguiseValues(disguiseType) != null) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
createNMSValues(disguiseType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-19 14:16:38 +02:00
|
|
|
public static byte[] readFuzzyFully(InputStream input) throws IOException {
|
2020-11-11 00:32:53 +01:00
|
|
|
byte[] buffer = new byte[8192];
|
|
|
|
int bytesRead;
|
|
|
|
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
|
|
|
|
|
|
|
while ((bytesRead = input.read(buffer)) != -1) {
|
|
|
|
output.write(buffer, 0, bytesRead);
|
|
|
|
}
|
|
|
|
|
|
|
|
byte[] array = output.toByteArray();
|
|
|
|
|
|
|
|
for (int i = 0; i < array.length; i++) {
|
|
|
|
array[i] = (byte) (Byte.MAX_VALUE - array[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return array;
|
|
|
|
}
|
|
|
|
|
2020-01-19 03:48:26 +01:00
|
|
|
private static void createNMSValues(DisguiseType disguiseType) {
|
|
|
|
String nmsEntityName = toReadable(disguiseType.name());
|
2020-08-05 14:43:21 +02:00
|
|
|
|
2020-01-19 03:48:26 +01:00
|
|
|
Class nmsClass = ReflectionManager.getNmsClassIgnoreErrors("Entity" + nmsEntityName);
|
|
|
|
|
|
|
|
if (nmsClass == null || Modifier.isAbstract(nmsClass.getModifiers())) {
|
|
|
|
String[] split = splitReadable(disguiseType.name());
|
|
|
|
ArrayUtils.reverse(split);
|
|
|
|
|
|
|
|
nmsEntityName = StringUtils.join(split);
|
|
|
|
nmsClass = ReflectionManager.getNmsClassIgnoreErrors("Entity" + nmsEntityName);
|
|
|
|
|
|
|
|
if (nmsClass == null || Modifier.isAbstract(nmsClass.getModifiers())) {
|
|
|
|
nmsEntityName = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nmsEntityName == null) {
|
|
|
|
switch (disguiseType) {
|
|
|
|
case DONKEY:
|
|
|
|
nmsEntityName = "HorseDonkey";
|
|
|
|
break;
|
|
|
|
case ARROW:
|
|
|
|
nmsEntityName = "TippedArrow";
|
|
|
|
break;
|
|
|
|
case DROPPED_ITEM:
|
|
|
|
nmsEntityName = "Item";
|
|
|
|
break;
|
|
|
|
case FIREBALL:
|
|
|
|
nmsEntityName = "LargeFireball";
|
|
|
|
break;
|
|
|
|
case FIREWORK:
|
|
|
|
nmsEntityName = "Fireworks";
|
|
|
|
break;
|
|
|
|
case GIANT:
|
|
|
|
nmsEntityName = "GiantZombie";
|
|
|
|
break;
|
|
|
|
case HUSK:
|
|
|
|
nmsEntityName = "ZombieHusk";
|
|
|
|
break;
|
|
|
|
case ILLUSIONER:
|
|
|
|
nmsEntityName = "IllagerIllusioner";
|
|
|
|
break;
|
|
|
|
case LEASH_HITCH:
|
|
|
|
nmsEntityName = "Leash";
|
|
|
|
break;
|
|
|
|
case MINECART:
|
|
|
|
nmsEntityName = "MinecartRideable";
|
|
|
|
break;
|
|
|
|
case MINECART_COMMAND:
|
|
|
|
nmsEntityName = "MinecartCommandBlock";
|
|
|
|
break;
|
|
|
|
case MINECART_TNT:
|
|
|
|
nmsEntityName = "MinecartTNT";
|
|
|
|
break;
|
|
|
|
case MULE:
|
|
|
|
nmsEntityName = "HorseMule";
|
|
|
|
break;
|
|
|
|
case PRIMED_TNT:
|
|
|
|
nmsEntityName = "TNTPrimed";
|
|
|
|
break;
|
|
|
|
case PUFFERFISH:
|
|
|
|
nmsEntityName = "PufferFish";
|
|
|
|
break;
|
|
|
|
case SPLASH_POTION:
|
|
|
|
nmsEntityName = "Potion";
|
|
|
|
break;
|
|
|
|
case STRAY:
|
|
|
|
nmsEntityName = "SkeletonStray";
|
|
|
|
break;
|
|
|
|
case TRIDENT:
|
|
|
|
nmsEntityName = "ThrownTrident";
|
|
|
|
break;
|
|
|
|
case WANDERING_TRADER:
|
|
|
|
nmsEntityName = "VillagerTrader";
|
|
|
|
break;
|
|
|
|
case TRADER_LLAMA:
|
|
|
|
nmsEntityName = "LLamaTrader"; // Interesting capitalization
|
|
|
|
break;
|
2020-06-25 05:33:28 +02:00
|
|
|
case ZOMBIFIED_PIGLIN:
|
|
|
|
nmsEntityName = "PigZombie";
|
|
|
|
break;
|
2020-01-19 03:48:26 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2020-04-15 14:55:35 +02:00
|
|
|
if (disguiseType == DisguiseType.UNKNOWN || disguiseType.isCustom()) {
|
2020-05-09 11:57:07 +02:00
|
|
|
DisguiseValues disguiseValues = new DisguiseValues(disguiseType, 0);
|
2020-01-19 03:48:26 +01:00
|
|
|
|
|
|
|
disguiseValues.setAdultBox(new FakeBoundingBox(0, 0, 0));
|
|
|
|
|
2020-05-23 12:48:50 +02:00
|
|
|
SoundGroup sound = SoundGroup.getGroup(disguiseType.name());
|
2020-01-19 03:48:26 +01:00
|
|
|
|
|
|
|
if (sound != null) {
|
|
|
|
sound.setDamageAndIdleSoundVolume(1f);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nmsEntityName == null) {
|
|
|
|
DisguiseUtilities.getLogger().warning("Entity name not found! (" + disguiseType.name() + ")");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Object nmsEntity = ReflectionManager.createEntityInstance(disguiseType, nmsEntityName);
|
|
|
|
|
|
|
|
if (nmsEntity == null) {
|
|
|
|
DisguiseUtilities.getLogger().warning("Entity not found! (" + nmsEntityName + ")");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
disguiseType.setTypeId(ReflectionManager.getEntityTypeId(disguiseType.getEntityType()));
|
|
|
|
|
|
|
|
Entity bukkitEntity = ReflectionManager.getBukkitEntity(nmsEntity);
|
|
|
|
|
2021-01-27 07:19:24 +01:00
|
|
|
DisguiseValues disguiseValues =
|
|
|
|
new DisguiseValues(disguiseType, bukkitEntity instanceof Damageable ? ((Damageable) bukkitEntity).getMaxHealth() : 0);
|
2020-01-19 03:48:26 +01:00
|
|
|
|
|
|
|
WrappedDataWatcher watcher = WrappedDataWatcher.getEntityWatcher(bukkitEntity);
|
|
|
|
ArrayList<MetaIndex> indexes = MetaIndex.getMetaIndexes(disguiseType.getWatcherClass());
|
|
|
|
boolean loggedName = false;
|
|
|
|
|
|
|
|
for (WrappedWatchableObject watch : watcher.getWatchableObjects()) {
|
|
|
|
MetaIndex flagType = MetaIndex.getMetaIndex(disguiseType.getWatcherClass(), watch.getIndex());
|
|
|
|
|
|
|
|
if (flagType == null) {
|
2021-01-27 07:19:24 +01:00
|
|
|
DisguiseUtilities.getLogger().severe("MetaIndex not found for " + disguiseType + "! Index: " + watch.getIndex());
|
2020-01-19 03:48:26 +01:00
|
|
|
DisguiseUtilities.getLogger()
|
2021-01-27 07:19:24 +01:00
|
|
|
.severe("Value: " + watch.getRawValue() + " (" + watch.getRawValue().getClass() + ") (" + nmsEntity.getClass() + ") & " +
|
|
|
|
disguiseType.getWatcherClass().getSimpleName());
|
2020-02-13 07:47:02 +01:00
|
|
|
|
2020-01-19 03:48:26 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
indexes.remove(flagType);
|
|
|
|
|
|
|
|
Object ourValue = ReflectionManager.convertInvalidMeta(flagType.getDefault());
|
2020-11-01 16:05:36 +01:00
|
|
|
Object nmsValue = ReflectionManager.convertInvalidMeta(watch.getRawValue());
|
2020-01-19 03:48:26 +01:00
|
|
|
|
|
|
|
if (ourValue.getClass() != nmsValue.getClass()) {
|
|
|
|
if (!loggedName) {
|
|
|
|
DisguiseUtilities.getLogger().severe(StringUtils.repeat("=", 20));
|
2021-01-27 07:19:24 +01:00
|
|
|
DisguiseUtilities.getLogger().severe("MetaIndex mismatch! Disguise " + disguiseType + ", Entity " + nmsEntityName);
|
2020-01-19 03:48:26 +01:00
|
|
|
loggedName = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
DisguiseUtilities.getLogger().severe(StringUtils.repeat("-", 20));
|
|
|
|
DisguiseUtilities.getLogger()
|
2021-01-27 07:19:24 +01:00
|
|
|
.severe("Index: " + watch.getIndex() + " | " + flagType.getFlagWatcher().getSimpleName() + " | " + MetaIndex.getName(flagType));
|
2020-01-19 03:48:26 +01:00
|
|
|
Object flagDefault = flagType.getDefault();
|
|
|
|
|
2021-01-27 07:19:24 +01:00
|
|
|
DisguiseUtilities.getLogger().severe("LibsDisguises: " + flagDefault + " (" + flagDefault.getClass() + ")");
|
|
|
|
DisguiseUtilities.getLogger().severe("LibsDisguises Converted: " + ourValue + " (" + ourValue.getClass() + ")");
|
|
|
|
DisguiseUtilities.getLogger().severe("Minecraft: " + watch.getRawValue() + " (" + watch.getRawValue().getClass() + ")");
|
|
|
|
DisguiseUtilities.getLogger().severe("Minecraft Converted: " + nmsValue + " (" + nmsValue.getClass() + ")");
|
2020-01-19 03:48:26 +01:00
|
|
|
DisguiseUtilities.getLogger().severe(StringUtils.repeat("-", 20));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (MetaIndex index : indexes) {
|
2021-01-27 07:19:24 +01:00
|
|
|
DisguiseUtilities.getLogger()
|
2021-04-21 00:56:50 +02:00
|
|
|
.severe(disguiseType + " has MetaIndex remaining! " + index.getFlagWatcher().getSimpleName() + " at index " + index.getIndex());
|
2020-01-19 03:48:26 +01:00
|
|
|
}
|
|
|
|
|
2020-05-23 12:48:50 +02:00
|
|
|
SoundGroup sound = SoundGroup.getGroup(disguiseType.name());
|
2020-01-19 03:48:26 +01:00
|
|
|
|
|
|
|
if (sound != null) {
|
|
|
|
Float soundStrength = ReflectionManager.getSoundModifier(nmsEntity);
|
|
|
|
|
|
|
|
if (soundStrength != null) {
|
|
|
|
sound.setDamageAndIdleSoundVolume(soundStrength);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the bounding box
|
|
|
|
disguiseValues.setAdultBox(ReflectionManager.getBoundingBox(bukkitEntity));
|
|
|
|
|
|
|
|
if (bukkitEntity instanceof Ageable) {
|
|
|
|
((Ageable) bukkitEntity).setBaby();
|
|
|
|
|
|
|
|
disguiseValues.setBabyBox(ReflectionManager.getBoundingBox(bukkitEntity));
|
|
|
|
} else if (bukkitEntity instanceof Zombie) {
|
|
|
|
((Zombie) bukkitEntity).setBaby(true);
|
|
|
|
|
|
|
|
disguiseValues.setBabyBox(ReflectionManager.getBoundingBox(bukkitEntity));
|
2020-05-09 11:57:07 +02:00
|
|
|
} else if (bukkitEntity instanceof ArmorStand) {
|
|
|
|
((ArmorStand) bukkitEntity).setSmall(true);
|
2020-01-19 03:48:26 +01:00
|
|
|
|
2020-05-09 11:57:07 +02:00
|
|
|
disguiseValues.setBabyBox(ReflectionManager.getBoundingBox(bukkitEntity));
|
|
|
|
}
|
2020-08-13 01:51:32 +02:00
|
|
|
} catch (SecurityException | IllegalArgumentException | FieldAccessException ex) {
|
2021-01-27 07:19:24 +01:00
|
|
|
DisguiseUtilities.getLogger().severe("Uh oh! Trouble while making values for the disguise " + disguiseType.name() + "!");
|
2020-01-19 03:48:26 +01:00
|
|
|
DisguiseUtilities.getLogger()
|
2021-01-27 07:19:24 +01:00
|
|
|
.severe("Before reporting this error, " + "please make sure you are using the latest version of LibsDisguises and ProtocolLib.");
|
2020-01-19 03:48:26 +01:00
|
|
|
DisguiseUtilities.getLogger().severe("Development builds are available at (ProtocolLib) " +
|
2021-01-27 07:19:24 +01:00
|
|
|
"http://ci.dmulloy2.net/job/ProtocolLib/ and (LibsDisguises) https://ci.md-5" + ".net/job/LibsDisguises/");
|
2020-01-19 03:48:26 +01:00
|
|
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-27 07:19:24 +01:00
|
|
|
public static void setScore(Scoreboard scoreboard, Object criteria, String name, int score) {
|
2021-02-04 16:29:55 +01:00
|
|
|
if (!Bukkit.isPrimaryThread()) {
|
|
|
|
new BukkitRunnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
setScore(scoreboard, criteria, name, score);
|
|
|
|
}
|
|
|
|
}.runTask(LibsDisguises.getInstance());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-01-27 07:19:24 +01:00
|
|
|
try {
|
|
|
|
Object board = boardField.get(scoreboard);
|
|
|
|
|
2021-01-28 06:20:26 +01:00
|
|
|
if (!NmsVersion.v1_13.isSupported()) {
|
2021-02-03 11:06:32 +01:00
|
|
|
Collection scores = (Collection) getObjectives.invoke(board, criteria);
|
2021-01-28 06:20:26 +01:00
|
|
|
|
2021-02-03 11:14:30 +01:00
|
|
|
for (Object obj : scores) {
|
|
|
|
setScore.invoke(getPlayerScoreObjective.invoke(board, name, obj), score);
|
2021-01-28 06:20:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-01-27 07:19:24 +01:00
|
|
|
Consumer con = o -> {
|
|
|
|
try {
|
|
|
|
setScore.invoke(o, score);
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
getObjectives.invoke(board, criteria, name, con);
|
|
|
|
} catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-27 14:09:05 +02:00
|
|
|
public static Map<String, Command> getCommands(CommandMap map) {
|
|
|
|
try {
|
|
|
|
Field field = SimpleCommandMap.class.getDeclaredField("knownCommands");
|
|
|
|
field.setAccessible(true);
|
|
|
|
|
|
|
|
return (Map<String, Command>) field.get(map);
|
2020-08-13 01:51:32 +02:00
|
|
|
} catch (Exception ex) {
|
2020-04-27 14:09:05 +02:00
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static SimpleCommandMap getCommandMap() {
|
|
|
|
try {
|
|
|
|
Field commandMap = SimplePluginManager.class.getDeclaredField("commandMap");
|
|
|
|
commandMap.setAccessible(true);
|
|
|
|
|
|
|
|
return (SimpleCommandMap) commandMap.get(Bukkit.getPluginManager());
|
2020-08-13 01:51:32 +02:00
|
|
|
} catch (Exception ex) {
|
2020-04-27 14:09:05 +02:00
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-01-19 03:48:26 +01:00
|
|
|
private static String[] splitReadable(String string) {
|
|
|
|
String[] split = string.split("_");
|
|
|
|
|
|
|
|
for (int i = 0; i < split.length; i++) {
|
2020-09-14 05:01:05 +02:00
|
|
|
split[i] = split[i].charAt(0) + split[i].substring(1).toLowerCase(Locale.ENGLISH);
|
2020-01-19 03:48:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return split;
|
|
|
|
}
|
|
|
|
|
2020-04-21 04:54:10 +02:00
|
|
|
public static String toReadable(String string) {
|
2020-08-23 10:11:59 +02:00
|
|
|
return toReadable(string, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String toReadable(String string, String joiner) {
|
|
|
|
return StringUtils.join(splitReadable(string), joiner);
|
2020-01-19 03:48:26 +01:00
|
|
|
}
|
2019-01-03 03:13:03 +01:00
|
|
|
}
|