public FancyMessage achievementTooltip(final Achievement which) { Object achievement = new SafeMethod( ReflectionUtil.getCBCClass("CraftStatistic"), "getNMSAchievement", Achievement.class) .invoke(null, which); return achievementTooltip( new SafeField<String>(achievement.getClass(), "name").get(achievement)); }
public FancyMessage itemTooltip(final ItemStack itemStack) { Object nmsCopy = new SafeMethod( ReflectionUtil.getCBCClass("inventory.CraftItemStack"), "asNMSCopy", ItemStack.class) .invoke(null, itemStack); Object nbtData = new SafeMethod(nmsCopy.getClass(), "save", ReflectionUtil.getNMSClass("NBTTagCompound")) .invoke( nmsCopy, new SafeConstructor(ReflectionUtil.getNMSClass("NBTTagCompound")).newInstance()); return itemTooltip(nbtData.toString()); }
public FancyMessage statisticTooltip(final Statistic which) { Type type = which.getType(); if (type != Type.UNTYPED) { throw new IllegalArgumentException( "That statistic requires an additional " + type + " parameter!"); } Object achievement = new SafeMethod( ReflectionUtil.getCBCClass("CraftStatistic"), "getNMSStatistic", Statistic.class) .invoke(null, which); return achievementTooltip( new SafeField<String>(achievement.getClass(), "name").get(achievement)); }
public class PlayerUtil { public static final Method getHandle = ReflectionUtil.getMethod(ReflectionUtil.getCBCClass("entity.CraftEntity"), "getHandle"); public static final Field playerConnection = ReflectionUtil.getField(ReflectionUtil.getNMSClass("EntityPlayer"), "playerConnection"); public static final Method sendPacket = ReflectionUtil.getMethod( ReflectionUtil.getNMSClass("PlayerConnection"), "sendPacket", ReflectionUtil.getNMSClass("Packet")); public static final Field networkManager = ReflectionUtil.getField(ReflectionUtil.getNMSClass("PlayerConnection"), "networkManager"); public static final Field channelField = ReflectionUtil.getField( ReflectionUtil.getNMSClass("NetworkManager"), HoloAPI.SERVER.getMCVersion().contains("v1_7_R2") ? "m" : "k"); public static final Field protocolPhase = ReflectionUtil.getField( ReflectionUtil.getNMSClass("NetworkManager"), HoloAPI.SERVER.getMCVersion().contains("v1_7_R2") ? "p" : "n"); public static Object toNMS(Player player) { return ReflectionUtil.invokeMethod(getHandle, player); } public static Object getPlayerConnection(Player player) { return ReflectionUtil.getField(playerConnection, toNMS(player)); } public static void sendPacket(Player player, Object packet) { ReflectionUtil.invokeMethod(sendPacket, getPlayerConnection(player), packet); } public static Object getNetworkManager(Player player) { return ReflectionUtil.getField(networkManager, getPlayerConnection(player)); } public static Object getChannel(Player player) { return ReflectionUtil.getField(channelField, getNetworkManager(player)); } public static Enum getProtocolPhase(Player player) { return ReflectionUtil.getField(protocolPhase, getNetworkManager(player)); } }
public FancyMessage statisticTooltip(final Statistic which, EntityType entity) { Type type = which.getType(); if (type == Type.UNTYPED) { throw new IllegalArgumentException("That statistic needs no additional parameter!"); } if (type != Type.ENTITY) { throw new IllegalArgumentException( "Wrong parameter type for that statistic - needs " + type + "!"); } Object achievement = new SafeMethod( ReflectionUtil.getCBCClass("CraftStatistic"), "getEntityStatistic", Statistic.class, EntityType.class) .invoke(null, which, entity); return achievementTooltip( new SafeField<String>(achievement.getClass(), "name").get(achievement)); }