mirror of
https://github.com/libraryaddict/LibsDisguises.git
synced 2024-12-14 15:26:54 +01:00
Add support for health below names
This commit is contained in:
parent
b872ddc137
commit
438e9cffd9
@ -15,6 +15,7 @@ import lombok.Getter;
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.DisguiseConfig;
|
||||
import me.libraryaddict.disguise.LibsDisguises;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.LibsPremium;
|
||||
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<>();
|
||||
HashSet<Integer> sentValues = new HashSet<>();
|
||||
boolean sendAllCustom = false;
|
||||
@ -323,6 +324,15 @@ public class FlagWatcher {
|
||||
}
|
||||
|
||||
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) {
|
||||
@ -346,7 +356,25 @@ public class FlagWatcher {
|
||||
|
||||
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.
|
||||
if (getDisguise().isSelfDisguiseVisible() && getDisguise().getEntity() != null && getDisguise().getEntity() instanceof Player) {
|
||||
for (WrappedWatchableObject watch : newList) {
|
||||
|
@ -144,8 +144,7 @@ public class PlayerDisguise extends TargetedDisguise {
|
||||
}
|
||||
|
||||
public String getProfileName() {
|
||||
return isUpsideDown() ? "Dinnerbone" :
|
||||
isDeadmau5Ears() ? "deadmau5" : hasScoreboardName() ? getScoreboardName().getPlayer() : getName();
|
||||
return isUpsideDown() ? "Dinnerbone" : isDeadmau5Ears() ? "deadmau5" : hasScoreboardName() ? getScoreboardName().getPlayer() : getName();
|
||||
}
|
||||
|
||||
public UUID getUUID() {
|
||||
@ -246,8 +245,7 @@ public class PlayerDisguise extends TargetedDisguise {
|
||||
|
||||
if (currentLookup == null && gameProfile != null) {
|
||||
disguise.skinToUse = getSkin();
|
||||
disguise.gameProfile = ReflectionManager
|
||||
.getGameProfileWithThisSkin(disguise.uuid, getGameProfile().getName(), getGameProfile());
|
||||
disguise.gameProfile = ReflectionManager.getGameProfileWithThisSkin(disguise.uuid, getGameProfile().getName(), getGameProfile());
|
||||
} else {
|
||||
disguise.setSkin(getSkin());
|
||||
}
|
||||
@ -268,8 +266,7 @@ public class PlayerDisguise extends TargetedDisguise {
|
||||
if (getSkin() != null) {
|
||||
gameProfile = ReflectionManager.getGameProfile(uuid, getProfileName());
|
||||
} else {
|
||||
gameProfile = ReflectionManager.getGameProfileWithThisSkin(uuid, getProfileName(),
|
||||
DisguiseUtilities.getProfileFromMojang(this));
|
||||
gameProfile = ReflectionManager.getGameProfileWithThisSkin(uuid, getProfileName(), DisguiseUtilities.getProfileFromMojang(this));
|
||||
}
|
||||
}
|
||||
|
||||
@ -293,9 +290,8 @@ public class PlayerDisguise extends TargetedDisguise {
|
||||
}
|
||||
}
|
||||
|
||||
if (DisguiseConfig.isCopyPlayerTeamInfo() &&
|
||||
(DisguiseConfig.getPlayerNameType() == DisguiseConfig.PlayerNameType.TEAMS ||
|
||||
DisguiseConfig.getPlayerNameType() == DisguiseConfig.PlayerNameType.ARMORSTANDS)) {
|
||||
if (DisguiseConfig.isCopyPlayerTeamInfo() && (DisguiseConfig.getPlayerNameType() == DisguiseConfig.PlayerNameType.TEAMS ||
|
||||
DisguiseConfig.getPlayerNameType() == DisguiseConfig.PlayerNameType.ARMORSTANDS)) {
|
||||
name = DisguiseUtilities.getDisplayName(name);
|
||||
}
|
||||
|
||||
@ -341,8 +337,7 @@ public class PlayerDisguise extends TargetedDisguise {
|
||||
setScoreboardName(split);
|
||||
}
|
||||
|
||||
resendDisguise = !DisguiseConfig.isScoreboardNames() || isStaticName(name) || isStaticName(getName()) ||
|
||||
resendDisguise;
|
||||
resendDisguise = !DisguiseConfig.isScoreboardNames() || isStaticName(name) || isStaticName(getName()) || resendDisguise;
|
||||
|
||||
if (resendDisguise) {
|
||||
resendDisguise(name, false);
|
||||
@ -473,8 +468,8 @@ public class PlayerDisguise extends TargetedDisguise {
|
||||
}
|
||||
};
|
||||
|
||||
WrappedGameProfile gameProfile = DisguiseUtilities.getProfileFromMojang(this.skinToUse, currentLookup,
|
||||
LibsDisguises.getInstance().getConfig().getBoolean("ContactMojangServers", true));
|
||||
WrappedGameProfile gameProfile = DisguiseUtilities
|
||||
.getProfileFromMojang(this.skinToUse, currentLookup, LibsDisguises.getInstance().getConfig().getBoolean("ContactMojangServers", true));
|
||||
|
||||
if (gameProfile != null) {
|
||||
setSkin(gameProfile);
|
||||
@ -509,13 +504,11 @@ public class PlayerDisguise extends TargetedDisguise {
|
||||
}
|
||||
|
||||
private WrappedGameProfile getProfile(String string) {
|
||||
if (string != null && string.length() > 70 && string.startsWith("{\"id\":") && string.endsWith("}") &&
|
||||
string.contains(",\"name\":")) {
|
||||
if (string != null && string.length() > 70 && string.startsWith("{\"id\":") && string.endsWith("}") && string.contains(",\"name\":")) {
|
||||
try {
|
||||
return DisguiseUtilities.getGson().fromJson(string, WrappedGameProfile.class);
|
||||
} catch (Exception ex) {
|
||||
throw new IllegalStateException(
|
||||
"Tried to parse " + string + " to a GameProfile, but it has been formatted incorrectly!");
|
||||
throw new IllegalStateException("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,
|
||||
LibsDisguises.getInstance().getConfig().getBoolean("ContactMojangServers", true));
|
||||
WrappedGameProfile gameProfile = DisguiseUtilities
|
||||
.getProfileFromMojang(this.skinToUse, currentLookup, LibsDisguises.getInstance().getConfig().getBoolean("ContactMojangServers", true));
|
||||
|
||||
if (gameProfile != null) {
|
||||
setSkin(gameProfile);
|
||||
@ -702,7 +695,17 @@ public class PlayerDisguise extends TargetedDisguise {
|
||||
public boolean removeDisguise(boolean 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) {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
|
@ -2778,11 +2778,11 @@ public class DisguiseUtilities {
|
||||
/**
|
||||
* 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();
|
||||
|
||||
try {
|
||||
List<WrappedWatchableObject> list = DisguiseConfig.isMetaPacketsEnabled() ? disguiseWatcher.convert(entityWatcher.getWatchableObjects()) :
|
||||
List<WrappedWatchableObject> list = DisguiseConfig.isMetaPacketsEnabled() ? disguiseWatcher.convert(player, entityWatcher.getWatchableObjects()) :
|
||||
disguiseWatcher.getWatchableObjects();
|
||||
|
||||
for (WrappedWatchableObject watchableObject : list) {
|
||||
|
@ -254,7 +254,7 @@ public class PlayerSkinHandler implements Listener {
|
||||
private void addMetadata(Player player, PlayerSkin skin) throws InvocationTargetException {
|
||||
PlayerDisguise disguise = skin.getDisguise().get();
|
||||
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 =
|
||||
ProtocolLibrary.getProtocolManager().createPacketConstructor(PacketType.Play.Server.ENTITY_METADATA, entity.getEntityId(), watcher, true)
|
||||
|
@ -99,7 +99,7 @@ public class PacketHandlerEquipment implements IPacketHandler {
|
||||
if (watch != null)
|
||||
list.add(watch);
|
||||
|
||||
list = disguise.getWatcher().convert(list);
|
||||
list = disguise.getWatcher().convert(observer, list);
|
||||
} else {
|
||||
for (WrappedWatchableObject obj : disguise.getWatcher().getWatchableObjects()) {
|
||||
if (obj.getIndex() == MetaIndex.LIVING_HAND.getIndex()) {
|
||||
@ -174,7 +174,7 @@ public class PacketHandlerEquipment implements IPacketHandler {
|
||||
if (watch != null)
|
||||
list.add(watch);
|
||||
|
||||
list = disguise.getWatcher().convert(list);
|
||||
list = disguise.getWatcher().convert(observer, list);
|
||||
} else {
|
||||
for (WrappedWatchableObject obj : disguise.getWatcher().getWatchableObjects()) {
|
||||
if (obj.getIndex() == toUse.getIndex()) {
|
||||
|
@ -40,7 +40,7 @@ public class PacketHandlerMetadata implements IPacketHandler {
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
|
@ -236,7 +236,7 @@ public class PacketHandlerSpawn implements IPacketHandler {
|
||||
// Set invis
|
||||
toSend.setObject(obj, (byte) 32);
|
||||
} else {
|
||||
toSend = DisguiseUtilities.createSanitizedDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity), disguise.getWatcher());
|
||||
toSend = DisguiseUtilities.createSanitizedDataWatcher(observer, WrappedDataWatcher.getEntityWatcher(disguisedEntity), disguise.getWatcher());
|
||||
}
|
||||
|
||||
if (NmsVersion.v1_15.isSupported()) {
|
||||
@ -305,7 +305,7 @@ public class PacketHandlerSpawn implements IPacketHandler {
|
||||
mods.write(11, yaw);
|
||||
|
||||
WrappedDataWatcher newWatcher =
|
||||
DisguiseUtilities.createSanitizedDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity), disguise.getWatcher());
|
||||
DisguiseUtilities.createSanitizedDataWatcher(observer, WrappedDataWatcher.getEntityWatcher(disguisedEntity), disguise.getWatcher());
|
||||
|
||||
if (NmsVersion.v1_15.isSupported()) {
|
||||
PacketContainer metaPacket = ProtocolLibrary.getProtocolManager()
|
||||
|
@ -29,6 +29,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.plugin.SimplePluginManager;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.scoreboard.Scoreboard;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.io.*;
|
||||
@ -37,6 +38,7 @@ import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.stream.Collectors;
|
||||
@ -103,19 +105,19 @@ public class ReflectionManager {
|
||||
private static Field noDamageTicks;
|
||||
private static Method isInvul;
|
||||
private static Object genericDamage;
|
||||
private static Field boardField;
|
||||
public static Object scoreboardCrtieriaHealth;
|
||||
private static Method getObjectives;
|
||||
private static Method setScore;
|
||||
|
||||
public static void init() {
|
||||
try {
|
||||
boundingBoxConstructor =
|
||||
getNmsConstructor("AxisAlignedBB", double.class, double.class, double.class, double.class,
|
||||
double.class, double.class);
|
||||
boundingBoxConstructor = getNmsConstructor("AxisAlignedBB", double.class, double.class, double.class, double.class, double.class, double.class);
|
||||
|
||||
setBoundingBoxMethod = getNmsMethod("Entity", "a", getNmsClass("AxisAlignedBB"));
|
||||
entityCountField = getNmsField("Entity", "entityCount");
|
||||
|
||||
mobEffectConstructor =
|
||||
getNmsConstructor("MobEffect", getNmsClass("MobEffectList"), Integer.TYPE, Integer.TYPE,
|
||||
Boolean.TYPE, Boolean.TYPE);
|
||||
mobEffectConstructor = getNmsConstructor("MobEffect", getNmsClass("MobEffectList"), Integer.TYPE, Integer.TYPE, Boolean.TYPE, Boolean.TYPE);
|
||||
mobEffectList = getNmsMethod("MobEffectList", "fromId", Integer.TYPE);
|
||||
boundingBoxMethod = getNmsMethod("Entity", "getBoundingBox");
|
||||
bukkitEntityMethod = getNmsMethod("Entity", "getBukkitEntity");
|
||||
@ -125,19 +127,15 @@ public class ReflectionManager {
|
||||
itemAsNmsCopyMethod = getCraftMethod(craftItemClass, "asNMSCopy", ItemStack.class);
|
||||
itemAsBukkitMethod = getCraftMethod(craftItemClass, "asBukkitCopy", getNmsClass("ItemStack"));
|
||||
|
||||
|
||||
|
||||
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);
|
||||
enumPlayerInfoAction =
|
||||
(Enum[]) getNmsClass("PacketPlayOutPlayerInfo$EnumPlayerInfoAction").getEnumConstants();
|
||||
enumPlayerInfoAction = (Enum[]) getNmsClass("PacketPlayOutPlayerInfo$EnumPlayerInfoAction").getEnumConstants();
|
||||
chatComponentConstructor = getNmsConstructor("ChatComponentText", String.class);
|
||||
packetPlayOutConstructor =
|
||||
getNmsConstructor("PacketPlayOutPlayerInfo$PlayerInfoData", getNmsClass("PacketPlayOutPlayerInfo"),
|
||||
GameProfile.class, int.class, getNmsClass("EnumGamemode"),
|
||||
getNmsClass("IChatBaseComponent"));
|
||||
getNmsConstructor("PacketPlayOutPlayerInfo$PlayerInfoData", getNmsClass("PacketPlayOutPlayerInfo"), GameProfile.class, int.class,
|
||||
getNmsClass("EnumGamemode"), getNmsClass("IChatBaseComponent"));
|
||||
enumGamemode = (Enum[]) getNmsClass("EnumGamemode").getEnumConstants();
|
||||
getNmsEntityMethod = getCraftMethod("entity.CraftEntity", "getHandle");
|
||||
enumItemSlots = (Enum[]) getNmsClass("EnumItemSlot").getEnumConstants();
|
||||
@ -145,8 +143,8 @@ public class ReflectionManager {
|
||||
Class craftSound = getCraftClass("CraftSound");
|
||||
|
||||
try {
|
||||
soundGetMethod = craftSound.getMethod("getSound",Sound.class);
|
||||
}catch (Exception ex) {
|
||||
soundGetMethod = craftSound.getMethod("getSound", Sound.class);
|
||||
} catch (Exception ex) {
|
||||
soundEffectGetMethod = getCraftMethod("CraftSound", "getSoundEffect", Sound.class);
|
||||
soundEffectGetKey = getNmsField("SoundEffect", "b");
|
||||
}
|
||||
@ -165,31 +163,32 @@ public class ReflectionManager {
|
||||
if (NmsVersion.v1_14.isSupported()) {
|
||||
entityPoseClass = getNmsClass("EntityPose");
|
||||
registryBlocksGetMethod = getNmsMethod("RegistryBlocks", "get", getNmsClass("MinecraftKey"));
|
||||
villagerDataConstructor = getNmsConstructor("VillagerData", getNmsClass("VillagerType"),
|
||||
getNmsClass("VillagerProfession"), int.class);
|
||||
villagerDataConstructor = getNmsConstructor("VillagerData", getNmsClass("VillagerType"), getNmsClass("VillagerProfession"), int.class);
|
||||
villagerProfessionRegistry = getNmsField("IRegistry", "VILLAGER_PROFESSION").get(null);
|
||||
villagerTypeRegistry = getNmsField("IRegistry", "VILLAGER_TYPE").get(null);
|
||||
} else {
|
||||
registryBlocksGetMethod =
|
||||
getNmsMethod("RegistryBlocks", "getOrDefault", getNmsClass("MinecraftKey"));
|
||||
registryBlocksGetMethod = getNmsMethod("RegistryBlocks", "getOrDefault", getNmsClass("MinecraftKey"));
|
||||
}
|
||||
}
|
||||
|
||||
bukkitKeyToNms = getCraftMethod("util.CraftNamespacedKey", "toMinecraft", NamespacedKey.class);
|
||||
dataWatcherItemConstructor =
|
||||
getNmsConstructor("DataWatcher$Item", getNmsClass("DataWatcherObject"), Object.class);
|
||||
dataWatcherItemConstructor = getNmsConstructor("DataWatcher$Item", getNmsClass("DataWatcherObject"), Object.class);
|
||||
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");
|
||||
deserializedItemMeta =
|
||||
getCraftMethod(getCraftClass("inventory.CraftMetaItem$SerializableMeta"), "deserialize", Map.class);
|
||||
deserializedItemMeta = getCraftMethod(getCraftClass("inventory.CraftMetaItem$SerializableMeta"), "deserialize", Map.class);
|
||||
|
||||
noDamageTicks = getNmsField("Entity", "noDamageTicks");
|
||||
isInvul = getNmsMethod("Entity", "isInvulnerable", getNmsClass("DamageSource"));
|
||||
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");
|
||||
|
||||
@ -315,8 +314,7 @@ public class ReflectionManager {
|
||||
JarEntry entry = jar.getJarEntry(fileName);
|
||||
|
||||
try (InputStream stream = jar.getInputStream(entry)) {
|
||||
return new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8)).lines()
|
||||
.collect(Collectors.joining("\n"));
|
||||
return new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8)).lines().collect(Collectors.joining("\n"));
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
@ -385,33 +383,27 @@ public class ReflectionManager {
|
||||
if (entityName.equals("Player")) {
|
||||
Object minecraftServer = getNmsMethod("MinecraftServer", "getServer").invoke(null);
|
||||
|
||||
Object playerinteractmanager = getNmsClass("PlayerInteractManager")
|
||||
.getDeclaredConstructor(getNmsClass(NmsVersion.v1_14.isSupported() ? "WorldServer" : "World"))
|
||||
.newInstance(world);
|
||||
Object playerinteractmanager =
|
||||
getNmsClass("PlayerInteractManager").getDeclaredConstructor(getNmsClass(NmsVersion.v1_14.isSupported() ? "WorldServer" : "World"))
|
||||
.newInstance(world);
|
||||
|
||||
WrappedGameProfile gameProfile = getGameProfile(new UUID(0, 0), "Steve");
|
||||
|
||||
entityObject = entityClass
|
||||
.getDeclaredConstructor(getNmsClass("MinecraftServer"), getNmsClass("WorldServer"),
|
||||
gameProfile.getHandleType(), playerinteractmanager.getClass())
|
||||
.newInstance(minecraftServer, world, gameProfile.getHandle(), playerinteractmanager);
|
||||
entityObject = entityClass.getDeclaredConstructor(getNmsClass("MinecraftServer"), getNmsClass("WorldServer"), gameProfile.getHandleType(),
|
||||
playerinteractmanager.getClass()).newInstance(minecraftServer, world, gameProfile.getHandle(), playerinteractmanager);
|
||||
} 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()) {
|
||||
entityObject = entityClass
|
||||
.getDeclaredConstructor(getNmsClass("EntityHuman"), getNmsClass("World"), int.class,
|
||||
int.class)
|
||||
entityObject = entityClass.getDeclaredConstructor(getNmsClass("EntityHuman"), getNmsClass("World"), int.class, int.class)
|
||||
.newInstance(createEntityInstance(DisguiseType.PLAYER, "Player"), world, 0, 0);
|
||||
} else {
|
||||
entityObject = entityClass.getDeclaredConstructor(getNmsClass("World"), getNmsClass("EntityHuman"))
|
||||
.newInstance(world, createEntityInstance(DisguiseType.PLAYER, "Player"));
|
||||
}
|
||||
} else if (!NmsVersion.v1_14.isSupported() && entityName.equals("Potion")) {
|
||||
entityObject = entityClass
|
||||
.getDeclaredConstructor(getNmsClass("World"), Double.TYPE, Double.TYPE, Double.TYPE,
|
||||
getNmsClass("ItemStack"))
|
||||
entityObject = entityClass.getDeclaredConstructor(getNmsClass("World"), Double.TYPE, Double.TYPE, Double.TYPE, getNmsClass("ItemStack"))
|
||||
.newInstance(world, 0d, 0d, 0d, getNmsItem(new ItemStack(Material.SPLASH_POTION)));
|
||||
} else {
|
||||
if (NmsVersion.v1_14.isSupported()) {
|
||||
@ -423,15 +415,12 @@ public class ReflectionManager {
|
||||
}
|
||||
|
||||
// Workaround for paper being 2 smart 4 me
|
||||
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);
|
||||
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);
|
||||
|
||||
return entityObject;
|
||||
} catch (Exception e) {
|
||||
DisguiseUtilities.getLogger()
|
||||
.warning("Error while attempting to create entity instance for " + disguiseType.name());
|
||||
DisguiseUtilities.getLogger().warning("Error while attempting to create entity instance for " + disguiseType.name());
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@ -449,8 +438,7 @@ public class ReflectionManager {
|
||||
}
|
||||
|
||||
public static Object createMobEffect(PotionEffect effect) {
|
||||
return createMobEffect(effect.getType().getId(), effect.getDuration(), effect.getAmplifier(),
|
||||
effect.isAmbient(), effect.hasParticles());
|
||||
return createMobEffect(effect.getType().getId(), effect.getDuration(), effect.getAmplifier(), effect.isAmbient(), effect.hasParticles());
|
||||
}
|
||||
|
||||
public static Object createMobEffect(int id, int duration, int amplification, boolean ambient, boolean particles) {
|
||||
@ -681,8 +669,7 @@ public class ReflectionManager {
|
||||
try {
|
||||
Object playerListName = chatComponentConstructor.newInstance(gameProfile.getName());
|
||||
|
||||
return packetPlayOutConstructor
|
||||
.newInstance(playerInfoPacket, gameProfile.getHandle(), 0, enumGamemode[1], playerListName);
|
||||
return packetPlayOutConstructor.newInstance(playerInfoPacket, gameProfile.getHandle(), 0, enumGamemode[1], playerListName);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
@ -707,8 +694,7 @@ public class ReflectionManager {
|
||||
return getGameProfileWithThisSkin(null, gameProfile.getName(), gameProfile);
|
||||
}
|
||||
|
||||
public static WrappedGameProfile getGameProfileWithThisSkin(UUID uuid, String playerName,
|
||||
WrappedGameProfile profileWithSkin) {
|
||||
public static WrappedGameProfile getGameProfileWithThisSkin(UUID uuid, String playerName, WrappedGameProfile profileWithSkin) {
|
||||
try {
|
||||
WrappedGameProfile gameProfile = new WrappedGameProfile(uuid != null ? uuid : getRandomUUID(), playerName);
|
||||
|
||||
@ -898,9 +884,9 @@ public class ReflectionManager {
|
||||
if (method.getReturnType().getSimpleName().equals("MinecraftSessionService")) {
|
||||
Object session = method.invoke(minecraftServer);
|
||||
|
||||
return WrappedGameProfile.fromHandle(session.getClass()
|
||||
.getDeclaredMethod("fillProfileProperties", gameProfile.getHandleType(), boolean.class)
|
||||
.invoke(session, gameProfile.getHandle(), true));
|
||||
return WrappedGameProfile.fromHandle(
|
||||
session.getClass().getDeclaredMethod("fillProfileProperties", gameProfile.getHandleType(), boolean.class)
|
||||
.invoke(session, gameProfile.getHandle(), true));
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
@ -932,8 +918,8 @@ public class ReflectionManager {
|
||||
LibsProfileLookupCaller callback = new LibsProfileLookupCaller();
|
||||
Object profileRepo = method.invoke(minecraftServer);
|
||||
|
||||
method.getReturnType().getMethod("findProfilesByNames", String[].class, agent.getClass(),
|
||||
Class.forName("com.mojang.authlib.ProfileLookupCallback"))
|
||||
method.getReturnType()
|
||||
.getMethod("findProfilesByNames", String[].class, agent.getClass(), Class.forName("com.mojang.authlib.ProfileLookupCallback"))
|
||||
.invoke(profileRepo, new String[]{playername}, agent, callback);
|
||||
|
||||
if (callback.getGameProfile() != null) {
|
||||
@ -955,9 +941,8 @@ public class ReflectionManager {
|
||||
Location loc = entity.getLocation();
|
||||
|
||||
Object boundingBox = boundingBoxConstructor
|
||||
.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));
|
||||
.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));
|
||||
|
||||
setBoundingBoxMethod.invoke(getNmsEntity(entity), boundingBox);
|
||||
} catch (Exception ex) {
|
||||
@ -1196,8 +1181,7 @@ public class ReflectionManager {
|
||||
public static Material getMaterial(String name) {
|
||||
try {
|
||||
if (!NmsVersion.v1_13.isSupported()) {
|
||||
Method toMinecraft =
|
||||
getCraftMethod("util.CraftMagicNumbers", "getMaterialFromInternalName", String.class);
|
||||
Method toMinecraft = getCraftMethod("util.CraftMagicNumbers", "getMaterialFromInternalName", String.class);
|
||||
|
||||
Object instance = toMinecraft.getDeclaringClass().getField("INSTANCE").get(null);
|
||||
|
||||
@ -1246,8 +1230,7 @@ public class ReflectionManager {
|
||||
registry = getNmsField("Item", "REGISTRY").get(null);
|
||||
}
|
||||
|
||||
Method getMethod =
|
||||
getNmsMethod(registry.getClass(), NmsVersion.v1_13.isSupported() ? "getKey" : "b", Object.class);
|
||||
Method getMethod = getNmsMethod(registry.getClass(), NmsVersion.v1_13.isSupported() ? "getKey" : "b", Object.class);
|
||||
|
||||
Object mcKey = getMethod.invoke(registry, item);
|
||||
|
||||
@ -1360,8 +1343,7 @@ public class ReflectionManager {
|
||||
@Deprecated
|
||||
public static Object createSoundEffect(String minecraftKey) {
|
||||
try {
|
||||
return getNmsConstructor("SoundEffect", getNmsClass("MinecraftKey"))
|
||||
.newInstance(createMinecraftKey(minecraftKey));
|
||||
return getNmsConstructor("SoundEffect", getNmsClass("MinecraftKey")).newInstance(createMinecraftKey(minecraftKey));
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
@ -1391,9 +1373,7 @@ public class ReflectionManager {
|
||||
|
||||
public static Object getEntityType(EntityType entityType) {
|
||||
try {
|
||||
Object val = entityTypesAMethod.invoke(null,
|
||||
entityType.getName() == null ? entityType.name().toLowerCase(Locale.ENGLISH) :
|
||||
entityType.getName());
|
||||
Object val = entityTypesAMethod.invoke(null, entityType.getName() == null ? entityType.name().toLowerCase(Locale.ENGLISH) : entityType.getName());
|
||||
|
||||
if (NmsVersion.v1_14.isSupported()) {
|
||||
return ((Optional<Object>) val).orElse(null);
|
||||
@ -1436,8 +1416,7 @@ public class ReflectionManager {
|
||||
break;
|
||||
}
|
||||
|
||||
typesClass.getMethod("a", typesClass, mcKey.getClass(), Object.class)
|
||||
.invoke(null, registry, mcKey, entityType);
|
||||
typesClass.getMethod("a", typesClass, mcKey.getClass(), Object.class).invoke(null, registry, mcKey, entityType);
|
||||
|
||||
return entityType;
|
||||
} catch (Exception e) {
|
||||
@ -1497,8 +1476,7 @@ public class ReflectionManager {
|
||||
}
|
||||
|
||||
public static Object getNmsEntityPose(EntityPose entityPose) {
|
||||
return Enum.valueOf(entityPoseClass,
|
||||
entityPose == EntityPose.SNEAKING && NmsVersion.v1_15.isSupported() ? "CROUCHING" : entityPose.name());
|
||||
return Enum.valueOf(entityPoseClass, entityPose == EntityPose.SNEAKING && NmsVersion.v1_15.isSupported() ? "CROUCHING" : entityPose.name());
|
||||
}
|
||||
|
||||
public static EntityPose getEntityPose(Object nmsEntityPose) {
|
||||
@ -1558,8 +1536,7 @@ public class ReflectionManager {
|
||||
Object iBlockData = idMethod.invoke(null, id);
|
||||
Class iBlockClass = getNmsClass("IBlockData");
|
||||
|
||||
return (BlockData) getCraftMethod("block.data.CraftBlockData", "fromData", iBlockClass)
|
||||
.invoke(null, iBlockData);
|
||||
return (BlockData) getCraftMethod("block.data.CraftBlockData", "fromData", iBlockClass).invoke(null, iBlockData);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
@ -1662,9 +1639,8 @@ public class ReflectionManager {
|
||||
watcherClass = PufferFishWatcher.class;
|
||||
break;
|
||||
default:
|
||||
watcherClass = (Class<? extends FlagWatcher>) Class.forName(
|
||||
"me.libraryaddict.disguise.disguisetypes.watchers." + toReadable(disguiseType.name()) +
|
||||
"Watcher");
|
||||
watcherClass = (Class<? extends FlagWatcher>) Class
|
||||
.forName("me.libraryaddict.disguise.disguisetypes.watchers." + toReadable(disguiseType.name()) + "Watcher");
|
||||
break;
|
||||
}
|
||||
} catch (ClassNotFoundException ex) {
|
||||
@ -1707,21 +1683,17 @@ public class ReflectionManager {
|
||||
Class watcherClass = getFlagWatcher(disguiseType);
|
||||
|
||||
if (watcherClass == null) {
|
||||
DisguiseUtilities.getLogger()
|
||||
.severe("Error loading " + disguiseType.name() + ", FlagWatcher not assigned");
|
||||
DisguiseUtilities.getLogger().severe("Error loading " + disguiseType.name() + ", FlagWatcher not assigned");
|
||||
continue;
|
||||
}
|
||||
|
||||
// Invalidate invalid distribution
|
||||
if (LibsPremium.isPremium() &&
|
||||
((LibsPremium.getPaidInformation() != null && LibsPremium.getPaidInformation().isPremium() &&
|
||||
!LibsPremium.getPaidInformation().isLegit()) ||
|
||||
(LibsPremium.getPluginInformation() != null &&
|
||||
LibsPremium.getPluginInformation().isPremium() &&
|
||||
!LibsPremium.getPluginInformation().isLegit()))) {
|
||||
if (LibsPremium.isPremium() && ((LibsPremium.getPaidInformation() != null && LibsPremium.getPaidInformation().isPremium() &&
|
||||
!LibsPremium.getPaidInformation().isLegit()) ||
|
||||
(LibsPremium.getPluginInformation() != null && LibsPremium.getPluginInformation().isPremium() &&
|
||||
!LibsPremium.getPluginInformation().isLegit()))) {
|
||||
throw new IllegalStateException(
|
||||
"Error while checking pi rate on startup! Please re-download the jar from SpigotMC before " +
|
||||
"reporting this error!");
|
||||
"Error while checking pi rate on startup! Please re-download the jar from SpigotMC before " + "reporting this error!");
|
||||
}
|
||||
|
||||
disguiseType.setWatcherClass(watcherClass);
|
||||
@ -1870,8 +1842,8 @@ public class ReflectionManager {
|
||||
|
||||
Entity bukkitEntity = ReflectionManager.getBukkitEntity(nmsEntity);
|
||||
|
||||
DisguiseValues disguiseValues = new DisguiseValues(disguiseType,
|
||||
bukkitEntity instanceof Damageable ? ((Damageable) bukkitEntity).getMaxHealth() : 0);
|
||||
DisguiseValues disguiseValues =
|
||||
new DisguiseValues(disguiseType, bukkitEntity instanceof Damageable ? ((Damageable) bukkitEntity).getMaxHealth() : 0);
|
||||
|
||||
WrappedDataWatcher watcher = WrappedDataWatcher.getEntityWatcher(bukkitEntity);
|
||||
ArrayList<MetaIndex> indexes = MetaIndex.getMetaIndexes(disguiseType.getWatcherClass());
|
||||
@ -1881,11 +1853,10 @@ public class ReflectionManager {
|
||||
MetaIndex flagType = MetaIndex.getMetaIndex(disguiseType.getWatcherClass(), watch.getIndex());
|
||||
|
||||
if (flagType == null) {
|
||||
DisguiseUtilities.getLogger().severe("MetaIndex not found for " + disguiseType + "! Index: " + watch.getIndex());
|
||||
DisguiseUtilities.getLogger()
|
||||
.severe("MetaIndex not found for " + disguiseType + "! Index: " + watch.getIndex());
|
||||
DisguiseUtilities.getLogger()
|
||||
.severe("Value: " + watch.getRawValue() + " (" + watch.getRawValue().getClass() + ") (" +
|
||||
nmsEntity.getClass() + ") & " + disguiseType.getWatcherClass().getSimpleName());
|
||||
.severe("Value: " + watch.getRawValue() + " (" + watch.getRawValue().getClass() + ") (" + nmsEntity.getClass() + ") & " +
|
||||
disguiseType.getWatcherClass().getSimpleName());
|
||||
|
||||
continue;
|
||||
}
|
||||
@ -1898,33 +1869,26 @@ public class ReflectionManager {
|
||||
if (ourValue.getClass() != nmsValue.getClass()) {
|
||||
if (!loggedName) {
|
||||
DisguiseUtilities.getLogger().severe(StringUtils.repeat("=", 20));
|
||||
DisguiseUtilities.getLogger()
|
||||
.severe("MetaIndex mismatch! Disguise " + disguiseType + ", Entity " + nmsEntityName);
|
||||
DisguiseUtilities.getLogger().severe("MetaIndex mismatch! Disguise " + disguiseType + ", Entity " + nmsEntityName);
|
||||
loggedName = true;
|
||||
}
|
||||
|
||||
DisguiseUtilities.getLogger().severe(StringUtils.repeat("-", 20));
|
||||
DisguiseUtilities.getLogger()
|
||||
.severe("Index: " + watch.getIndex() + " | " + flagType.getFlagWatcher().getSimpleName() +
|
||||
" | " + MetaIndex.getName(flagType));
|
||||
.severe("Index: " + watch.getIndex() + " | " + flagType.getFlagWatcher().getSimpleName() + " | " + MetaIndex.getName(flagType));
|
||||
Object flagDefault = flagType.getDefault();
|
||||
|
||||
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() + ")");
|
||||
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() + ")");
|
||||
DisguiseUtilities.getLogger().severe(StringUtils.repeat("-", 20));
|
||||
}
|
||||
}
|
||||
|
||||
for (MetaIndex index : indexes) {
|
||||
DisguiseUtilities.getLogger().warning(
|
||||
disguiseType + " has MetaIndex remaining! " + index.getFlagWatcher().getSimpleName() +
|
||||
" at index " + index.getIndex());
|
||||
DisguiseUtilities.getLogger()
|
||||
.warning(disguiseType + " has MetaIndex remaining! " + index.getFlagWatcher().getSimpleName() + " at index " + index.getIndex());
|
||||
}
|
||||
|
||||
SoundGroup sound = SoundGroup.getGroup(disguiseType.name());
|
||||
@ -1954,18 +1918,34 @@ public class ReflectionManager {
|
||||
disguiseValues.setBabyBox(ReflectionManager.getBoundingBox(bukkitEntity));
|
||||
}
|
||||
} catch (SecurityException | IllegalArgumentException | FieldAccessException ex) {
|
||||
DisguiseUtilities.getLogger().severe("Uh oh! Trouble while making values for the disguise " + disguiseType.name() + "!");
|
||||
DisguiseUtilities.getLogger()
|
||||
.severe("Uh oh! Trouble while making values for the disguise " + disguiseType.name() + "!");
|
||||
DisguiseUtilities.getLogger().severe("Before reporting this error, " +
|
||||
"please make sure you are using the latest version of LibsDisguises and ProtocolLib.");
|
||||
.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) " +
|
||||
"http://ci.dmulloy2.net/job/ProtocolLib/ and (LibsDisguises) https://ci.md-5" +
|
||||
".net/job/LibsDisguises/");
|
||||
"http://ci.dmulloy2.net/job/ProtocolLib/ and (LibsDisguises) https://ci.md-5" + ".net/job/LibsDisguises/");
|
||||
|
||||
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) {
|
||||
try {
|
||||
Field field = SimpleCommandMap.class.getDeclaredField("knownCommands");
|
||||
|
Loading…
Reference in New Issue
Block a user