Add support for health below names

This commit is contained in:
libraryaddict 2021-01-27 19:19:24 +13:00
parent b872ddc137
commit 438e9cffd9
8 changed files with 152 additions and 141 deletions

View File

@ -15,6 +15,7 @@ import lombok.Getter;
import me.libraryaddict.disguise.DisguiseAPI; import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.DisguiseConfig; import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.LibsDisguises; import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.LibsPremium; import me.libraryaddict.disguise.utilities.LibsPremium;
import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue; import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue;
@ -250,7 +251,7 @@ public class FlagWatcher {
} }
} }
public List<WrappedWatchableObject> convert(List<WrappedWatchableObject> list) { public List<WrappedWatchableObject> convert(Player player, List<WrappedWatchableObject> list) {
List<WrappedWatchableObject> newList = new ArrayList<>(); List<WrappedWatchableObject> newList = new ArrayList<>();
HashSet<Integer> sentValues = new HashSet<>(); HashSet<Integer> sentValues = new HashSet<>();
boolean sendAllCustom = false; boolean sendAllCustom = false;
@ -323,6 +324,15 @@ public class FlagWatcher {
} }
newList.add(watch); newList.add(watch);
if (!sendAllCustom && getDisguise().isPlayerDisguise() && index == MetaIndex.LIVING_HEALTH) {
float health = ((Number) watch.getRawValue()).floatValue();
String name = DisguiseConfig.isScoreboardNames() ? ((PlayerDisguise) getDisguise()).getName() :
((PlayerDisguise) getDisguise()).getScoreboardName().getPlayer();
ReflectionManager.setScore(player.getScoreboard(), ReflectionManager.scoreboardCrtieriaHealth, name, (int) Math.ceil(health));
}
} }
if (sendAllCustom) { if (sendAllCustom) {
@ -346,7 +356,25 @@ public class FlagWatcher {
newList.add(watch); newList.add(watch);
} }
if (getDisguise().isPlayerDisguise()) {
float health;
if (hasValue(MetaIndex.LIVING_HEALTH)) {
health = ((LivingWatcher) this).getHealth();
} else if (getDisguise().getEntity() instanceof LivingEntity) {
health = (float) ((LivingEntity) getDisguise().getEntity()).getHealth();
} else {
health = MetaIndex.LIVING_HEALTH.getDefault();
}
String name = !DisguiseConfig.isScoreboardNames() ? ((PlayerDisguise) getDisguise()).getName() :
((PlayerDisguise) getDisguise()).getScoreboardName().getPlayer();
ReflectionManager.setScore(player.getScoreboard(), ReflectionManager.scoreboardCrtieriaHealth, name, (int) Math.ceil(health));
}
} }
// Here we check for if there is a health packet that says they died. // Here we check for if there is a health packet that says they died.
if (getDisguise().isSelfDisguiseVisible() && getDisguise().getEntity() != null && getDisguise().getEntity() instanceof Player) { if (getDisguise().isSelfDisguiseVisible() && getDisguise().getEntity() != null && getDisguise().getEntity() instanceof Player) {
for (WrappedWatchableObject watch : newList) { for (WrappedWatchableObject watch : newList) {

View File

@ -144,8 +144,7 @@ public class PlayerDisguise extends TargetedDisguise {
} }
public String getProfileName() { public String getProfileName() {
return isUpsideDown() ? "Dinnerbone" : return isUpsideDown() ? "Dinnerbone" : isDeadmau5Ears() ? "deadmau5" : hasScoreboardName() ? getScoreboardName().getPlayer() : getName();
isDeadmau5Ears() ? "deadmau5" : hasScoreboardName() ? getScoreboardName().getPlayer() : getName();
} }
public UUID getUUID() { public UUID getUUID() {
@ -246,8 +245,7 @@ public class PlayerDisguise extends TargetedDisguise {
if (currentLookup == null && gameProfile != null) { if (currentLookup == null && gameProfile != null) {
disguise.skinToUse = getSkin(); disguise.skinToUse = getSkin();
disguise.gameProfile = ReflectionManager disguise.gameProfile = ReflectionManager.getGameProfileWithThisSkin(disguise.uuid, getGameProfile().getName(), getGameProfile());
.getGameProfileWithThisSkin(disguise.uuid, getGameProfile().getName(), getGameProfile());
} else { } else {
disguise.setSkin(getSkin()); disguise.setSkin(getSkin());
} }
@ -268,8 +266,7 @@ public class PlayerDisguise extends TargetedDisguise {
if (getSkin() != null) { if (getSkin() != null) {
gameProfile = ReflectionManager.getGameProfile(uuid, getProfileName()); gameProfile = ReflectionManager.getGameProfile(uuid, getProfileName());
} else { } else {
gameProfile = ReflectionManager.getGameProfileWithThisSkin(uuid, getProfileName(), gameProfile = ReflectionManager.getGameProfileWithThisSkin(uuid, getProfileName(), DisguiseUtilities.getProfileFromMojang(this));
DisguiseUtilities.getProfileFromMojang(this));
} }
} }
@ -293,9 +290,8 @@ public class PlayerDisguise extends TargetedDisguise {
} }
} }
if (DisguiseConfig.isCopyPlayerTeamInfo() && if (DisguiseConfig.isCopyPlayerTeamInfo() && (DisguiseConfig.getPlayerNameType() == DisguiseConfig.PlayerNameType.TEAMS ||
(DisguiseConfig.getPlayerNameType() == DisguiseConfig.PlayerNameType.TEAMS || DisguiseConfig.getPlayerNameType() == DisguiseConfig.PlayerNameType.ARMORSTANDS)) {
DisguiseConfig.getPlayerNameType() == DisguiseConfig.PlayerNameType.ARMORSTANDS)) {
name = DisguiseUtilities.getDisplayName(name); name = DisguiseUtilities.getDisplayName(name);
} }
@ -341,8 +337,7 @@ public class PlayerDisguise extends TargetedDisguise {
setScoreboardName(split); setScoreboardName(split);
} }
resendDisguise = !DisguiseConfig.isScoreboardNames() || isStaticName(name) || isStaticName(getName()) || resendDisguise = !DisguiseConfig.isScoreboardNames() || isStaticName(name) || isStaticName(getName()) || resendDisguise;
resendDisguise;
if (resendDisguise) { if (resendDisguise) {
resendDisguise(name, false); resendDisguise(name, false);
@ -473,8 +468,8 @@ public class PlayerDisguise extends TargetedDisguise {
} }
}; };
WrappedGameProfile gameProfile = DisguiseUtilities.getProfileFromMojang(this.skinToUse, currentLookup, WrappedGameProfile gameProfile = DisguiseUtilities
LibsDisguises.getInstance().getConfig().getBoolean("ContactMojangServers", true)); .getProfileFromMojang(this.skinToUse, currentLookup, LibsDisguises.getInstance().getConfig().getBoolean("ContactMojangServers", true));
if (gameProfile != null) { if (gameProfile != null) {
setSkin(gameProfile); setSkin(gameProfile);
@ -509,13 +504,11 @@ public class PlayerDisguise extends TargetedDisguise {
} }
private WrappedGameProfile getProfile(String string) { private WrappedGameProfile getProfile(String string) {
if (string != null && string.length() > 70 && string.startsWith("{\"id\":") && string.endsWith("}") && if (string != null && string.length() > 70 && string.startsWith("{\"id\":") && string.endsWith("}") && string.contains(",\"name\":")) {
string.contains(",\"name\":")) {
try { try {
return DisguiseUtilities.getGson().fromJson(string, WrappedGameProfile.class); return DisguiseUtilities.getGson().fromJson(string, WrappedGameProfile.class);
} catch (Exception ex) { } catch (Exception ex) {
throw new IllegalStateException( throw new IllegalStateException("Tried to parse " + string + " to a GameProfile, but it has been formatted incorrectly!");
"Tried to parse " + string + " to a GameProfile, but it has been formatted incorrectly!");
} }
} }
@ -641,8 +634,8 @@ public class PlayerDisguise extends TargetedDisguise {
} }
}; };
WrappedGameProfile gameProfile = DisguiseUtilities.getProfileFromMojang(this.skinToUse, currentLookup, WrappedGameProfile gameProfile = DisguiseUtilities
LibsDisguises.getInstance().getConfig().getBoolean("ContactMojangServers", true)); .getProfileFromMojang(this.skinToUse, currentLookup, LibsDisguises.getInstance().getConfig().getBoolean("ContactMojangServers", true));
if (gameProfile != null) { if (gameProfile != null) {
setSkin(gameProfile); setSkin(gameProfile);
@ -702,7 +695,17 @@ public class PlayerDisguise extends TargetedDisguise {
public boolean removeDisguise(boolean disguiseBeingReplaced) { public boolean removeDisguise(boolean disguiseBeingReplaced) {
boolean result = super.removeDisguise(disguiseBeingReplaced); boolean result = super.removeDisguise(disguiseBeingReplaced);
if (result && hasScoreboardName()) { if (!result) {
return result;
}
String name = !DisguiseConfig.isScoreboardNames() ? getName() : getScoreboardName().getPlayer();
if (Bukkit.getPlayer(name) == null) {
DisguiseUtilities.getAllScoreboards().forEach(s -> s.resetScores(name));
}
if (hasScoreboardName()) {
if (disguiseBeingReplaced) { if (disguiseBeingReplaced) {
new BukkitRunnable() { new BukkitRunnable() {
@Override @Override

View File

@ -2778,11 +2778,11 @@ public class DisguiseUtilities {
/** /**
* Create a new datawatcher but with the 'correct' values * Create a new datawatcher but with the 'correct' values
*/ */
public static WrappedDataWatcher createSanitizedDataWatcher(WrappedDataWatcher entityWatcher, FlagWatcher disguiseWatcher) { public static WrappedDataWatcher createSanitizedDataWatcher(Player player, WrappedDataWatcher entityWatcher, FlagWatcher disguiseWatcher) {
WrappedDataWatcher newWatcher = new WrappedDataWatcher(); WrappedDataWatcher newWatcher = new WrappedDataWatcher();
try { try {
List<WrappedWatchableObject> list = DisguiseConfig.isMetaPacketsEnabled() ? disguiseWatcher.convert(entityWatcher.getWatchableObjects()) : List<WrappedWatchableObject> list = DisguiseConfig.isMetaPacketsEnabled() ? disguiseWatcher.convert(player, entityWatcher.getWatchableObjects()) :
disguiseWatcher.getWatchableObjects(); disguiseWatcher.getWatchableObjects();
for (WrappedWatchableObject watchableObject : list) { for (WrappedWatchableObject watchableObject : list) {

View File

@ -254,7 +254,7 @@ public class PlayerSkinHandler implements Listener {
private void addMetadata(Player player, PlayerSkin skin) throws InvocationTargetException { private void addMetadata(Player player, PlayerSkin skin) throws InvocationTargetException {
PlayerDisguise disguise = skin.getDisguise().get(); PlayerDisguise disguise = skin.getDisguise().get();
Entity entity = disguise.getEntity(); Entity entity = disguise.getEntity();
WrappedDataWatcher watcher = DisguiseUtilities.createSanitizedDataWatcher(WrappedDataWatcher.getEntityWatcher(entity), disguise.getWatcher()); WrappedDataWatcher watcher = DisguiseUtilities.createSanitizedDataWatcher(player, WrappedDataWatcher.getEntityWatcher(entity), disguise.getWatcher());
PacketContainer metaPacket = PacketContainer metaPacket =
ProtocolLibrary.getProtocolManager().createPacketConstructor(PacketType.Play.Server.ENTITY_METADATA, entity.getEntityId(), watcher, true) ProtocolLibrary.getProtocolManager().createPacketConstructor(PacketType.Play.Server.ENTITY_METADATA, entity.getEntityId(), watcher, true)

View File

@ -99,7 +99,7 @@ public class PacketHandlerEquipment implements IPacketHandler {
if (watch != null) if (watch != null)
list.add(watch); list.add(watch);
list = disguise.getWatcher().convert(list); list = disguise.getWatcher().convert(observer, list);
} else { } else {
for (WrappedWatchableObject obj : disguise.getWatcher().getWatchableObjects()) { for (WrappedWatchableObject obj : disguise.getWatcher().getWatchableObjects()) {
if (obj.getIndex() == MetaIndex.LIVING_HAND.getIndex()) { if (obj.getIndex() == MetaIndex.LIVING_HAND.getIndex()) {
@ -174,7 +174,7 @@ public class PacketHandlerEquipment implements IPacketHandler {
if (watch != null) if (watch != null)
list.add(watch); list.add(watch);
list = disguise.getWatcher().convert(list); list = disguise.getWatcher().convert(observer, list);
} else { } else {
for (WrappedWatchableObject obj : disguise.getWatcher().getWatchableObjects()) { for (WrappedWatchableObject obj : disguise.getWatcher().getWatchableObjects()) {
if (obj.getIndex() == toUse.getIndex()) { if (obj.getIndex() == toUse.getIndex()) {

View File

@ -40,7 +40,7 @@ public class PacketHandlerMetadata implements IPacketHandler {
} }
List<WrappedWatchableObject> watchableObjects = disguise.getWatcher() List<WrappedWatchableObject> watchableObjects = disguise.getWatcher()
.convert(sentPacket.getWatchableCollectionModifier().read(0)); .convert(observer, sentPacket.getWatchableCollectionModifier().read(0));
PacketContainer metaPacket = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA); PacketContainer metaPacket = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);

View File

@ -236,7 +236,7 @@ public class PacketHandlerSpawn implements IPacketHandler {
// Set invis // Set invis
toSend.setObject(obj, (byte) 32); toSend.setObject(obj, (byte) 32);
} else { } else {
toSend = DisguiseUtilities.createSanitizedDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity), disguise.getWatcher()); toSend = DisguiseUtilities.createSanitizedDataWatcher(observer, WrappedDataWatcher.getEntityWatcher(disguisedEntity), disguise.getWatcher());
} }
if (NmsVersion.v1_15.isSupported()) { if (NmsVersion.v1_15.isSupported()) {
@ -305,7 +305,7 @@ public class PacketHandlerSpawn implements IPacketHandler {
mods.write(11, yaw); mods.write(11, yaw);
WrappedDataWatcher newWatcher = WrappedDataWatcher newWatcher =
DisguiseUtilities.createSanitizedDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity), disguise.getWatcher()); DisguiseUtilities.createSanitizedDataWatcher(observer, WrappedDataWatcher.getEntityWatcher(disguisedEntity), disguise.getWatcher());
if (NmsVersion.v1_15.isSupported()) { if (NmsVersion.v1_15.isSupported()) {
PacketContainer metaPacket = ProtocolLibrary.getProtocolManager() PacketContainer metaPacket = ProtocolLibrary.getProtocolManager()

View File

@ -29,6 +29,7 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.SimplePluginManager; import org.bukkit.plugin.SimplePluginManager;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import java.io.*; import java.io.*;
@ -37,6 +38,7 @@ import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.*; import java.util.*;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
import java.util.jar.JarEntry; import java.util.jar.JarEntry;
import java.util.jar.JarFile; import java.util.jar.JarFile;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -103,19 +105,19 @@ public class ReflectionManager {
private static Field noDamageTicks; private static Field noDamageTicks;
private static Method isInvul; private static Method isInvul;
private static Object genericDamage; private static Object genericDamage;
private static Field boardField;
public static Object scoreboardCrtieriaHealth;
private static Method getObjectives;
private static Method setScore;
public static void init() { public static void init() {
try { try {
boundingBoxConstructor = boundingBoxConstructor = getNmsConstructor("AxisAlignedBB", double.class, double.class, double.class, double.class, double.class, double.class);
getNmsConstructor("AxisAlignedBB", double.class, double.class, double.class, double.class,
double.class, double.class);
setBoundingBoxMethod = getNmsMethod("Entity", "a", getNmsClass("AxisAlignedBB")); setBoundingBoxMethod = getNmsMethod("Entity", "a", getNmsClass("AxisAlignedBB"));
entityCountField = getNmsField("Entity", "entityCount"); entityCountField = getNmsField("Entity", "entityCount");
mobEffectConstructor = mobEffectConstructor = getNmsConstructor("MobEffect", getNmsClass("MobEffectList"), Integer.TYPE, Integer.TYPE, Boolean.TYPE, Boolean.TYPE);
getNmsConstructor("MobEffect", getNmsClass("MobEffectList"), Integer.TYPE, Integer.TYPE,
Boolean.TYPE, Boolean.TYPE);
mobEffectList = getNmsMethod("MobEffectList", "fromId", Integer.TYPE); mobEffectList = getNmsMethod("MobEffectList", "fromId", Integer.TYPE);
boundingBoxMethod = getNmsMethod("Entity", "getBoundingBox"); boundingBoxMethod = getNmsMethod("Entity", "getBoundingBox");
bukkitEntityMethod = getNmsMethod("Entity", "getBukkitEntity"); bukkitEntityMethod = getNmsMethod("Entity", "getBukkitEntity");
@ -125,19 +127,15 @@ public class ReflectionManager {
itemAsNmsCopyMethod = getCraftMethod(craftItemClass, "asNMSCopy", ItemStack.class); itemAsNmsCopyMethod = getCraftMethod(craftItemClass, "asNMSCopy", ItemStack.class);
itemAsBukkitMethod = getCraftMethod(craftItemClass, "asBukkitCopy", getNmsClass("ItemStack")); itemAsBukkitMethod = getCraftMethod(craftItemClass, "asBukkitCopy", getNmsClass("ItemStack"));
getServerMethod = getCraftMethod("CraftServer", "getServer"); getServerMethod = getCraftMethod("CraftServer", "getServer");
getEnumArtMethod = getCraftMethod("CraftArt", "BukkitToNotch", Art.class); getEnumArtMethod = getCraftMethod("CraftArt", "BukkitToNotch", Art.class);
blockPositionConstructor = getNmsConstructor("BlockPosition", int.class, int.class, int.class); blockPositionConstructor = getNmsConstructor("BlockPosition", int.class, int.class, int.class);
enumDirectionMethod = getNmsMethod("EnumDirection", "fromType2", int.class); enumDirectionMethod = getNmsMethod("EnumDirection", "fromType2", int.class);
enumPlayerInfoAction = enumPlayerInfoAction = (Enum[]) getNmsClass("PacketPlayOutPlayerInfo$EnumPlayerInfoAction").getEnumConstants();
(Enum[]) getNmsClass("PacketPlayOutPlayerInfo$EnumPlayerInfoAction").getEnumConstants();
chatComponentConstructor = getNmsConstructor("ChatComponentText", String.class); chatComponentConstructor = getNmsConstructor("ChatComponentText", String.class);
packetPlayOutConstructor = packetPlayOutConstructor =
getNmsConstructor("PacketPlayOutPlayerInfo$PlayerInfoData", getNmsClass("PacketPlayOutPlayerInfo"), getNmsConstructor("PacketPlayOutPlayerInfo$PlayerInfoData", getNmsClass("PacketPlayOutPlayerInfo"), GameProfile.class, int.class,
GameProfile.class, int.class, getNmsClass("EnumGamemode"), getNmsClass("EnumGamemode"), getNmsClass("IChatBaseComponent"));
getNmsClass("IChatBaseComponent"));
enumGamemode = (Enum[]) getNmsClass("EnumGamemode").getEnumConstants(); enumGamemode = (Enum[]) getNmsClass("EnumGamemode").getEnumConstants();
getNmsEntityMethod = getCraftMethod("entity.CraftEntity", "getHandle"); getNmsEntityMethod = getCraftMethod("entity.CraftEntity", "getHandle");
enumItemSlots = (Enum[]) getNmsClass("EnumItemSlot").getEnumConstants(); enumItemSlots = (Enum[]) getNmsClass("EnumItemSlot").getEnumConstants();
@ -145,8 +143,8 @@ public class ReflectionManager {
Class craftSound = getCraftClass("CraftSound"); Class craftSound = getCraftClass("CraftSound");
try { try {
soundGetMethod = craftSound.getMethod("getSound",Sound.class); soundGetMethod = craftSound.getMethod("getSound", Sound.class);
}catch (Exception ex) { } catch (Exception ex) {
soundEffectGetMethod = getCraftMethod("CraftSound", "getSoundEffect", Sound.class); soundEffectGetMethod = getCraftMethod("CraftSound", "getSoundEffect", Sound.class);
soundEffectGetKey = getNmsField("SoundEffect", "b"); soundEffectGetKey = getNmsField("SoundEffect", "b");
} }
@ -165,31 +163,32 @@ public class ReflectionManager {
if (NmsVersion.v1_14.isSupported()) { if (NmsVersion.v1_14.isSupported()) {
entityPoseClass = getNmsClass("EntityPose"); entityPoseClass = getNmsClass("EntityPose");
registryBlocksGetMethod = getNmsMethod("RegistryBlocks", "get", getNmsClass("MinecraftKey")); registryBlocksGetMethod = getNmsMethod("RegistryBlocks", "get", getNmsClass("MinecraftKey"));
villagerDataConstructor = getNmsConstructor("VillagerData", getNmsClass("VillagerType"), villagerDataConstructor = getNmsConstructor("VillagerData", getNmsClass("VillagerType"), getNmsClass("VillagerProfession"), int.class);
getNmsClass("VillagerProfession"), int.class);
villagerProfessionRegistry = getNmsField("IRegistry", "VILLAGER_PROFESSION").get(null); villagerProfessionRegistry = getNmsField("IRegistry", "VILLAGER_PROFESSION").get(null);
villagerTypeRegistry = getNmsField("IRegistry", "VILLAGER_TYPE").get(null); villagerTypeRegistry = getNmsField("IRegistry", "VILLAGER_TYPE").get(null);
} else { } else {
registryBlocksGetMethod = registryBlocksGetMethod = getNmsMethod("RegistryBlocks", "getOrDefault", getNmsClass("MinecraftKey"));
getNmsMethod("RegistryBlocks", "getOrDefault", getNmsClass("MinecraftKey"));
} }
} }
bukkitKeyToNms = getCraftMethod("util.CraftNamespacedKey", "toMinecraft", NamespacedKey.class); bukkitKeyToNms = getCraftMethod("util.CraftNamespacedKey", "toMinecraft", NamespacedKey.class);
dataWatcherItemConstructor = dataWatcherItemConstructor = getNmsConstructor("DataWatcher$Item", getNmsClass("DataWatcherObject"), Object.class);
getNmsConstructor("DataWatcher$Item", getNmsClass("DataWatcherObject"), Object.class);
vec3DConstructor = getNmsConstructor("Vec3D", double.class, double.class, double.class); vec3DConstructor = getNmsConstructor("Vec3D", double.class, double.class, double.class);
getOldItemAsBlock = getNmsMethod(getNmsClass("Block"), "asBlock", getNmsClass("Item")); getOldItemAsBlock = getNmsMethod(getNmsClass("Block"), "asBlock", getNmsClass("Item"));
getNmsItem = getNmsMethod("ItemStack", "getItem"); getNmsItem = getNmsMethod("ItemStack", "getItem");
getBlockDataAsId = getNmsMethod("Block", "getCombinedId", getNmsClass("IBlockData")); getBlockDataAsId = getNmsMethod("Block", "getCombinedId", getNmsClass("IBlockData"));
getNmsWorld = getCraftMethod("CraftWorld", "getHandle"); getNmsWorld = getCraftMethod("CraftWorld", "getHandle");
deserializedItemMeta = deserializedItemMeta = getCraftMethod(getCraftClass("inventory.CraftMetaItem$SerializableMeta"), "deserialize", Map.class);
getCraftMethod(getCraftClass("inventory.CraftMetaItem$SerializableMeta"), "deserialize", Map.class);
noDamageTicks = getNmsField("Entity", "noDamageTicks"); noDamageTicks = getNmsField("Entity", "noDamageTicks");
isInvul = getNmsMethod("Entity", "isInvulnerable", getNmsClass("DamageSource")); isInvul = getNmsMethod("Entity", "isInvulnerable", getNmsClass("DamageSource"));
genericDamage = getNmsField("DamageSource", "GENERIC").get(null); genericDamage = getNmsField("DamageSource", "GENERIC").get(null);
boardField = getCraftClass("scoreboard.CraftScoreboard").getDeclaredField("board");
boardField.setAccessible(true);
scoreboardCrtieriaHealth = getNmsField("IScoreboardCriteria", "HEALTH").get(null);
setScore = getNmsMethod("ScoreboardScore", "setScore", int.class);
getObjectives = getNmsMethod("Scoreboard", "getObjectivesForCriteria", getNmsClass("IScoreboardCriteria"), String.class, Consumer.class);
Method method = getNmsMethod("SoundCategory", "a"); Method method = getNmsMethod("SoundCategory", "a");
@ -315,8 +314,7 @@ public class ReflectionManager {
JarEntry entry = jar.getJarEntry(fileName); JarEntry entry = jar.getJarEntry(fileName);
try (InputStream stream = jar.getInputStream(entry)) { try (InputStream stream = jar.getInputStream(entry)) {
return new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8)).lines() return new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8)).lines().collect(Collectors.joining("\n"));
.collect(Collectors.joining("\n"));
} }
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
@ -385,33 +383,27 @@ public class ReflectionManager {
if (entityName.equals("Player")) { if (entityName.equals("Player")) {
Object minecraftServer = getNmsMethod("MinecraftServer", "getServer").invoke(null); Object minecraftServer = getNmsMethod("MinecraftServer", "getServer").invoke(null);
Object playerinteractmanager = getNmsClass("PlayerInteractManager") Object playerinteractmanager =
.getDeclaredConstructor(getNmsClass(NmsVersion.v1_14.isSupported() ? "WorldServer" : "World")) getNmsClass("PlayerInteractManager").getDeclaredConstructor(getNmsClass(NmsVersion.v1_14.isSupported() ? "WorldServer" : "World"))
.newInstance(world); .newInstance(world);
WrappedGameProfile gameProfile = getGameProfile(new UUID(0, 0), "Steve"); WrappedGameProfile gameProfile = getGameProfile(new UUID(0, 0), "Steve");
entityObject = entityClass entityObject = entityClass.getDeclaredConstructor(getNmsClass("MinecraftServer"), getNmsClass("WorldServer"), gameProfile.getHandleType(),
.getDeclaredConstructor(getNmsClass("MinecraftServer"), getNmsClass("WorldServer"), playerinteractmanager.getClass()).newInstance(minecraftServer, world, gameProfile.getHandle(), playerinteractmanager);
gameProfile.getHandleType(), playerinteractmanager.getClass())
.newInstance(minecraftServer, world, gameProfile.getHandle(), playerinteractmanager);
} else if (entityName.equals("EnderPearl")) { } else if (entityName.equals("EnderPearl")) {
entityObject = entityClass.getDeclaredConstructor(getNmsClass("World"), getNmsClass("EntityLiving")) entityObject = entityClass.getDeclaredConstructor(getNmsClass("World"), getNmsClass("EntityLiving"))
.newInstance(world, createEntityInstance(DisguiseType.COW, "Cow")); .newInstance(world, createEntityInstance(DisguiseType.COW, "Cow"));
} else if (entityName.equals("FishingHook")) { } else if (entityName.equals("FishingHook")) {
if (NmsVersion.v1_14.isSupported()) { if (NmsVersion.v1_14.isSupported()) {
entityObject = entityClass entityObject = entityClass.getDeclaredConstructor(getNmsClass("EntityHuman"), getNmsClass("World"), int.class, int.class)
.getDeclaredConstructor(getNmsClass("EntityHuman"), getNmsClass("World"), int.class,
int.class)
.newInstance(createEntityInstance(DisguiseType.PLAYER, "Player"), world, 0, 0); .newInstance(createEntityInstance(DisguiseType.PLAYER, "Player"), world, 0, 0);
} else { } else {
entityObject = entityClass.getDeclaredConstructor(getNmsClass("World"), getNmsClass("EntityHuman")) entityObject = entityClass.getDeclaredConstructor(getNmsClass("World"), getNmsClass("EntityHuman"))
.newInstance(world, createEntityInstance(DisguiseType.PLAYER, "Player")); .newInstance(world, createEntityInstance(DisguiseType.PLAYER, "Player"));
} }
} else if (!NmsVersion.v1_14.isSupported() && entityName.equals("Potion")) { } else if (!NmsVersion.v1_14.isSupported() && entityName.equals("Potion")) {
entityObject = entityClass entityObject = entityClass.getDeclaredConstructor(getNmsClass("World"), Double.TYPE, Double.TYPE, Double.TYPE, getNmsClass("ItemStack"))
.getDeclaredConstructor(getNmsClass("World"), Double.TYPE, Double.TYPE, Double.TYPE,
getNmsClass("ItemStack"))
.newInstance(world, 0d, 0d, 0d, getNmsItem(new ItemStack(Material.SPLASH_POTION))); .newInstance(world, 0d, 0d, 0d, getNmsItem(new ItemStack(Material.SPLASH_POTION)));
} else { } else {
if (NmsVersion.v1_14.isSupported()) { if (NmsVersion.v1_14.isSupported()) {
@ -423,15 +415,12 @@ public class ReflectionManager {
} }
// Workaround for paper being 2 smart 4 me // Workaround for paper being 2 smart 4 me
getNmsMethod("Entity", "setPosition", double.class, double.class, double.class) getNmsMethod("Entity", "setPosition", double.class, double.class, double.class).invoke(entityObject, 1, 1, 1);
.invoke(entityObject, 1, 1, 1); getNmsMethod("Entity", "setPosition", double.class, double.class, double.class).invoke(entityObject, 0, 0, 0);
getNmsMethod("Entity", "setPosition", double.class, double.class, double.class)
.invoke(entityObject, 0, 0, 0);
return entityObject; return entityObject;
} catch (Exception e) { } catch (Exception e) {
DisguiseUtilities.getLogger() DisguiseUtilities.getLogger().warning("Error while attempting to create entity instance for " + disguiseType.name());
.warning("Error while attempting to create entity instance for " + disguiseType.name());
e.printStackTrace(); e.printStackTrace();
} }
@ -449,8 +438,7 @@ public class ReflectionManager {
} }
public static Object createMobEffect(PotionEffect effect) { public static Object createMobEffect(PotionEffect effect) {
return createMobEffect(effect.getType().getId(), effect.getDuration(), effect.getAmplifier(), return createMobEffect(effect.getType().getId(), effect.getDuration(), effect.getAmplifier(), effect.isAmbient(), effect.hasParticles());
effect.isAmbient(), effect.hasParticles());
} }
public static Object createMobEffect(int id, int duration, int amplification, boolean ambient, boolean particles) { public static Object createMobEffect(int id, int duration, int amplification, boolean ambient, boolean particles) {
@ -681,8 +669,7 @@ public class ReflectionManager {
try { try {
Object playerListName = chatComponentConstructor.newInstance(gameProfile.getName()); Object playerListName = chatComponentConstructor.newInstance(gameProfile.getName());
return packetPlayOutConstructor return packetPlayOutConstructor.newInstance(playerInfoPacket, gameProfile.getHandle(), 0, enumGamemode[1], playerListName);
.newInstance(playerInfoPacket, gameProfile.getHandle(), 0, enumGamemode[1], playerListName);
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
@ -707,8 +694,7 @@ public class ReflectionManager {
return getGameProfileWithThisSkin(null, gameProfile.getName(), gameProfile); return getGameProfileWithThisSkin(null, gameProfile.getName(), gameProfile);
} }
public static WrappedGameProfile getGameProfileWithThisSkin(UUID uuid, String playerName, public static WrappedGameProfile getGameProfileWithThisSkin(UUID uuid, String playerName, WrappedGameProfile profileWithSkin) {
WrappedGameProfile profileWithSkin) {
try { try {
WrappedGameProfile gameProfile = new WrappedGameProfile(uuid != null ? uuid : getRandomUUID(), playerName); WrappedGameProfile gameProfile = new WrappedGameProfile(uuid != null ? uuid : getRandomUUID(), playerName);
@ -898,9 +884,9 @@ public class ReflectionManager {
if (method.getReturnType().getSimpleName().equals("MinecraftSessionService")) { if (method.getReturnType().getSimpleName().equals("MinecraftSessionService")) {
Object session = method.invoke(minecraftServer); Object session = method.invoke(minecraftServer);
return WrappedGameProfile.fromHandle(session.getClass() return WrappedGameProfile.fromHandle(
.getDeclaredMethod("fillProfileProperties", gameProfile.getHandleType(), boolean.class) session.getClass().getDeclaredMethod("fillProfileProperties", gameProfile.getHandleType(), boolean.class)
.invoke(session, gameProfile.getHandle(), true)); .invoke(session, gameProfile.getHandle(), true));
} }
} }
} catch (Exception ex) { } catch (Exception ex) {
@ -932,8 +918,8 @@ public class ReflectionManager {
LibsProfileLookupCaller callback = new LibsProfileLookupCaller(); LibsProfileLookupCaller callback = new LibsProfileLookupCaller();
Object profileRepo = method.invoke(minecraftServer); Object profileRepo = method.invoke(minecraftServer);
method.getReturnType().getMethod("findProfilesByNames", String[].class, agent.getClass(), method.getReturnType()
Class.forName("com.mojang.authlib.ProfileLookupCallback")) .getMethod("findProfilesByNames", String[].class, agent.getClass(), Class.forName("com.mojang.authlib.ProfileLookupCallback"))
.invoke(profileRepo, new String[]{playername}, agent, callback); .invoke(profileRepo, new String[]{playername}, agent, callback);
if (callback.getGameProfile() != null) { if (callback.getGameProfile() != null) {
@ -955,9 +941,8 @@ public class ReflectionManager {
Location loc = entity.getLocation(); Location loc = entity.getLocation();
Object boundingBox = boundingBoxConstructor Object boundingBox = boundingBoxConstructor
.newInstance(loc.getX() - (newBox.getX() / 2), loc.getY(), loc.getZ() - (newBox.getZ() / 2), .newInstance(loc.getX() - (newBox.getX() / 2), loc.getY(), loc.getZ() - (newBox.getZ() / 2), loc.getX() + (newBox.getX() / 2),
loc.getX() + (newBox.getX() / 2), loc.getY() + newBox.getY(), loc.getY() + newBox.getY(), loc.getZ() + (newBox.getZ() / 2));
loc.getZ() + (newBox.getZ() / 2));
setBoundingBoxMethod.invoke(getNmsEntity(entity), boundingBox); setBoundingBoxMethod.invoke(getNmsEntity(entity), boundingBox);
} catch (Exception ex) { } catch (Exception ex) {
@ -1196,8 +1181,7 @@ public class ReflectionManager {
public static Material getMaterial(String name) { public static Material getMaterial(String name) {
try { try {
if (!NmsVersion.v1_13.isSupported()) { if (!NmsVersion.v1_13.isSupported()) {
Method toMinecraft = Method toMinecraft = getCraftMethod("util.CraftMagicNumbers", "getMaterialFromInternalName", String.class);
getCraftMethod("util.CraftMagicNumbers", "getMaterialFromInternalName", String.class);
Object instance = toMinecraft.getDeclaringClass().getField("INSTANCE").get(null); Object instance = toMinecraft.getDeclaringClass().getField("INSTANCE").get(null);
@ -1246,8 +1230,7 @@ public class ReflectionManager {
registry = getNmsField("Item", "REGISTRY").get(null); registry = getNmsField("Item", "REGISTRY").get(null);
} }
Method getMethod = Method getMethod = getNmsMethod(registry.getClass(), NmsVersion.v1_13.isSupported() ? "getKey" : "b", Object.class);
getNmsMethod(registry.getClass(), NmsVersion.v1_13.isSupported() ? "getKey" : "b", Object.class);
Object mcKey = getMethod.invoke(registry, item); Object mcKey = getMethod.invoke(registry, item);
@ -1360,8 +1343,7 @@ public class ReflectionManager {
@Deprecated @Deprecated
public static Object createSoundEffect(String minecraftKey) { public static Object createSoundEffect(String minecraftKey) {
try { try {
return getNmsConstructor("SoundEffect", getNmsClass("MinecraftKey")) return getNmsConstructor("SoundEffect", getNmsClass("MinecraftKey")).newInstance(createMinecraftKey(minecraftKey));
.newInstance(createMinecraftKey(minecraftKey));
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
@ -1391,9 +1373,7 @@ public class ReflectionManager {
public static Object getEntityType(EntityType entityType) { public static Object getEntityType(EntityType entityType) {
try { try {
Object val = entityTypesAMethod.invoke(null, Object val = entityTypesAMethod.invoke(null, entityType.getName() == null ? entityType.name().toLowerCase(Locale.ENGLISH) : entityType.getName());
entityType.getName() == null ? entityType.name().toLowerCase(Locale.ENGLISH) :
entityType.getName());
if (NmsVersion.v1_14.isSupported()) { if (NmsVersion.v1_14.isSupported()) {
return ((Optional<Object>) val).orElse(null); return ((Optional<Object>) val).orElse(null);
@ -1436,8 +1416,7 @@ public class ReflectionManager {
break; break;
} }
typesClass.getMethod("a", typesClass, mcKey.getClass(), Object.class) typesClass.getMethod("a", typesClass, mcKey.getClass(), Object.class).invoke(null, registry, mcKey, entityType);
.invoke(null, registry, mcKey, entityType);
return entityType; return entityType;
} catch (Exception e) { } catch (Exception e) {
@ -1497,8 +1476,7 @@ public class ReflectionManager {
} }
public static Object getNmsEntityPose(EntityPose entityPose) { public static Object getNmsEntityPose(EntityPose entityPose) {
return Enum.valueOf(entityPoseClass, return Enum.valueOf(entityPoseClass, entityPose == EntityPose.SNEAKING && NmsVersion.v1_15.isSupported() ? "CROUCHING" : entityPose.name());
entityPose == EntityPose.SNEAKING && NmsVersion.v1_15.isSupported() ? "CROUCHING" : entityPose.name());
} }
public static EntityPose getEntityPose(Object nmsEntityPose) { public static EntityPose getEntityPose(Object nmsEntityPose) {
@ -1558,8 +1536,7 @@ public class ReflectionManager {
Object iBlockData = idMethod.invoke(null, id); Object iBlockData = idMethod.invoke(null, id);
Class iBlockClass = getNmsClass("IBlockData"); Class iBlockClass = getNmsClass("IBlockData");
return (BlockData) getCraftMethod("block.data.CraftBlockData", "fromData", iBlockClass) return (BlockData) getCraftMethod("block.data.CraftBlockData", "fromData", iBlockClass).invoke(null, iBlockData);
.invoke(null, iBlockData);
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
@ -1662,9 +1639,8 @@ public class ReflectionManager {
watcherClass = PufferFishWatcher.class; watcherClass = PufferFishWatcher.class;
break; break;
default: default:
watcherClass = (Class<? extends FlagWatcher>) Class.forName( watcherClass = (Class<? extends FlagWatcher>) Class
"me.libraryaddict.disguise.disguisetypes.watchers." + toReadable(disguiseType.name()) + .forName("me.libraryaddict.disguise.disguisetypes.watchers." + toReadable(disguiseType.name()) + "Watcher");
"Watcher");
break; break;
} }
} catch (ClassNotFoundException ex) { } catch (ClassNotFoundException ex) {
@ -1707,21 +1683,17 @@ public class ReflectionManager {
Class watcherClass = getFlagWatcher(disguiseType); Class watcherClass = getFlagWatcher(disguiseType);
if (watcherClass == null) { if (watcherClass == null) {
DisguiseUtilities.getLogger() DisguiseUtilities.getLogger().severe("Error loading " + disguiseType.name() + ", FlagWatcher not assigned");
.severe("Error loading " + disguiseType.name() + ", FlagWatcher not assigned");
continue; continue;
} }
// Invalidate invalid distribution // Invalidate invalid distribution
if (LibsPremium.isPremium() && if (LibsPremium.isPremium() && ((LibsPremium.getPaidInformation() != null && LibsPremium.getPaidInformation().isPremium() &&
((LibsPremium.getPaidInformation() != null && LibsPremium.getPaidInformation().isPremium() && !LibsPremium.getPaidInformation().isLegit()) ||
!LibsPremium.getPaidInformation().isLegit()) || (LibsPremium.getPluginInformation() != null && LibsPremium.getPluginInformation().isPremium() &&
(LibsPremium.getPluginInformation() != null && !LibsPremium.getPluginInformation().isLegit()))) {
LibsPremium.getPluginInformation().isPremium() &&
!LibsPremium.getPluginInformation().isLegit()))) {
throw new IllegalStateException( throw new IllegalStateException(
"Error while checking pi rate on startup! Please re-download the jar from SpigotMC before " + "Error while checking pi rate on startup! Please re-download the jar from SpigotMC before " + "reporting this error!");
"reporting this error!");
} }
disguiseType.setWatcherClass(watcherClass); disguiseType.setWatcherClass(watcherClass);
@ -1870,8 +1842,8 @@ public class ReflectionManager {
Entity bukkitEntity = ReflectionManager.getBukkitEntity(nmsEntity); Entity bukkitEntity = ReflectionManager.getBukkitEntity(nmsEntity);
DisguiseValues disguiseValues = new DisguiseValues(disguiseType, DisguiseValues disguiseValues =
bukkitEntity instanceof Damageable ? ((Damageable) bukkitEntity).getMaxHealth() : 0); new DisguiseValues(disguiseType, bukkitEntity instanceof Damageable ? ((Damageable) bukkitEntity).getMaxHealth() : 0);
WrappedDataWatcher watcher = WrappedDataWatcher.getEntityWatcher(bukkitEntity); WrappedDataWatcher watcher = WrappedDataWatcher.getEntityWatcher(bukkitEntity);
ArrayList<MetaIndex> indexes = MetaIndex.getMetaIndexes(disguiseType.getWatcherClass()); ArrayList<MetaIndex> indexes = MetaIndex.getMetaIndexes(disguiseType.getWatcherClass());
@ -1881,11 +1853,10 @@ public class ReflectionManager {
MetaIndex flagType = MetaIndex.getMetaIndex(disguiseType.getWatcherClass(), watch.getIndex()); MetaIndex flagType = MetaIndex.getMetaIndex(disguiseType.getWatcherClass(), watch.getIndex());
if (flagType == null) { if (flagType == null) {
DisguiseUtilities.getLogger().severe("MetaIndex not found for " + disguiseType + "! Index: " + watch.getIndex());
DisguiseUtilities.getLogger() DisguiseUtilities.getLogger()
.severe("MetaIndex not found for " + disguiseType + "! Index: " + watch.getIndex()); .severe("Value: " + watch.getRawValue() + " (" + watch.getRawValue().getClass() + ") (" + nmsEntity.getClass() + ") & " +
DisguiseUtilities.getLogger() disguiseType.getWatcherClass().getSimpleName());
.severe("Value: " + watch.getRawValue() + " (" + watch.getRawValue().getClass() + ") (" +
nmsEntity.getClass() + ") & " + disguiseType.getWatcherClass().getSimpleName());
continue; continue;
} }
@ -1898,33 +1869,26 @@ public class ReflectionManager {
if (ourValue.getClass() != nmsValue.getClass()) { if (ourValue.getClass() != nmsValue.getClass()) {
if (!loggedName) { if (!loggedName) {
DisguiseUtilities.getLogger().severe(StringUtils.repeat("=", 20)); DisguiseUtilities.getLogger().severe(StringUtils.repeat("=", 20));
DisguiseUtilities.getLogger() DisguiseUtilities.getLogger().severe("MetaIndex mismatch! Disguise " + disguiseType + ", Entity " + nmsEntityName);
.severe("MetaIndex mismatch! Disguise " + disguiseType + ", Entity " + nmsEntityName);
loggedName = true; loggedName = true;
} }
DisguiseUtilities.getLogger().severe(StringUtils.repeat("-", 20)); DisguiseUtilities.getLogger().severe(StringUtils.repeat("-", 20));
DisguiseUtilities.getLogger() DisguiseUtilities.getLogger()
.severe("Index: " + watch.getIndex() + " | " + flagType.getFlagWatcher().getSimpleName() + .severe("Index: " + watch.getIndex() + " | " + flagType.getFlagWatcher().getSimpleName() + " | " + MetaIndex.getName(flagType));
" | " + MetaIndex.getName(flagType));
Object flagDefault = flagType.getDefault(); Object flagDefault = flagType.getDefault();
DisguiseUtilities.getLogger() DisguiseUtilities.getLogger().severe("LibsDisguises: " + flagDefault + " (" + flagDefault.getClass() + ")");
.severe("LibsDisguises: " + flagDefault + " (" + flagDefault.getClass() + ")"); DisguiseUtilities.getLogger().severe("LibsDisguises Converted: " + ourValue + " (" + ourValue.getClass() + ")");
DisguiseUtilities.getLogger() DisguiseUtilities.getLogger().severe("Minecraft: " + watch.getRawValue() + " (" + watch.getRawValue().getClass() + ")");
.severe("LibsDisguises Converted: " + ourValue + " (" + ourValue.getClass() + ")"); DisguiseUtilities.getLogger().severe("Minecraft Converted: " + nmsValue + " (" + nmsValue.getClass() + ")");
DisguiseUtilities.getLogger()
.severe("Minecraft: " + watch.getRawValue() + " (" + watch.getRawValue().getClass() + ")");
DisguiseUtilities.getLogger()
.severe("Minecraft Converted: " + nmsValue + " (" + nmsValue.getClass() + ")");
DisguiseUtilities.getLogger().severe(StringUtils.repeat("-", 20)); DisguiseUtilities.getLogger().severe(StringUtils.repeat("-", 20));
} }
} }
for (MetaIndex index : indexes) { for (MetaIndex index : indexes) {
DisguiseUtilities.getLogger().warning( DisguiseUtilities.getLogger()
disguiseType + " has MetaIndex remaining! " + index.getFlagWatcher().getSimpleName() + .warning(disguiseType + " has MetaIndex remaining! " + index.getFlagWatcher().getSimpleName() + " at index " + index.getIndex());
" at index " + index.getIndex());
} }
SoundGroup sound = SoundGroup.getGroup(disguiseType.name()); SoundGroup sound = SoundGroup.getGroup(disguiseType.name());
@ -1954,18 +1918,34 @@ public class ReflectionManager {
disguiseValues.setBabyBox(ReflectionManager.getBoundingBox(bukkitEntity)); disguiseValues.setBabyBox(ReflectionManager.getBoundingBox(bukkitEntity));
} }
} catch (SecurityException | IllegalArgumentException | FieldAccessException ex) { } catch (SecurityException | IllegalArgumentException | FieldAccessException ex) {
DisguiseUtilities.getLogger().severe("Uh oh! Trouble while making values for the disguise " + disguiseType.name() + "!");
DisguiseUtilities.getLogger() DisguiseUtilities.getLogger()
.severe("Uh oh! Trouble while making values for the disguise " + disguiseType.name() + "!"); .severe("Before reporting this error, " + "please make sure you are using the latest version of LibsDisguises and ProtocolLib.");
DisguiseUtilities.getLogger().severe("Before reporting this error, " +
"please make sure you are using the latest version of LibsDisguises and ProtocolLib.");
DisguiseUtilities.getLogger().severe("Development builds are available at (ProtocolLib) " + DisguiseUtilities.getLogger().severe("Development builds are available at (ProtocolLib) " +
"http://ci.dmulloy2.net/job/ProtocolLib/ and (LibsDisguises) https://ci.md-5" + "http://ci.dmulloy2.net/job/ProtocolLib/ and (LibsDisguises) https://ci.md-5" + ".net/job/LibsDisguises/");
".net/job/LibsDisguises/");
ex.printStackTrace(); ex.printStackTrace();
} }
} }
public static void setScore(Scoreboard scoreboard, Object criteria, String name, int score) {
try {
Object board = boardField.get(scoreboard);
Consumer con = o -> {
try {
setScore.invoke(o, score);
} catch (Exception e) {
e.printStackTrace();
}
};
getObjectives.invoke(board, criteria, name, con);
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static Map<String, Command> getCommands(CommandMap map) { public static Map<String, Command> getCommands(CommandMap map) {
try { try {
Field field = SimpleCommandMap.class.getDeclaredField("knownCommands"); Field field = SimpleCommandMap.class.getDeclaredField("knownCommands");