ReflectionMethod(Class<?> targetClass, Class<?>[] args, MinecraftVersion addedSince, Since... methodnames){ MinecraftVersion server = MinecraftVersion.getVersion(); if(server.compareTo(addedSince) < 0)return; compatible = true; Since target = methodnames[0]; for(Since s : methodnames){ if(s.version.getVersionId() <= server.getVersionId() && target.version.getVersionId() < s.version.getVersionId()) target = s; } targetVersion = target; try{ method = targetClass.getMethod(targetVersion.name, args); method.setAccessible(true); loaded = true; }catch(NullPointerException | NoSuchMethodException | SecurityException ex){ ex.printStackTrace(); } }
public NBTType getType(String name) { if (MinecraftVersion.getVersion() == MinecraftVersion.MC1_7_R4) return null; Object o = NBTReflectionUtil.getData(this, ReflectionMethod.COMPOUND_GET_TYPE, name); if(o == null)return null; return NBTType.valueOf((byte) o); }
@SuppressWarnings({"unchecked"}) public static Object convertNBTCompoundtoNMSItem(NBTCompound nbtcompound) { @SuppressWarnings("rawtypes") Class clazz = ClassWrapper.NMS_ITEMSTACK.getClazz(); try { if(MinecraftVersion.getVersion().getVersionId() >= MinecraftVersion.MC1_12_R1.getVersionId()){ Constructor<?> constructor = clazz.getConstructor(ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz()); constructor.setAccessible(true); return constructor.newInstance(nbtcompound.getCompound()); }else{ Method method = clazz.getMethod("createStack", ClassWrapper.NMS_NBTTAGCOMPOUND.getClazz()); method.setAccessible(true); return method.invoke(null, nbtcompound.getCompound()); } } catch (Exception e) { e.printStackTrace(); } return null; }
getLogger().info("Checking bindings..."); getLogger().info("Minecraft Version:"); MinecraftVersion.getVersion(); getLogger().info("Gson:"); MinecraftVersion.hasGsonSupport(); comp.setDouble(DOUBLE_TEST_KEY, DOUBLE_TEST_VALUE * 2); NBTList list = comp.getList("testlist", NBTType.NBTTagString); if (MinecraftVersion.getVersion() == MinecraftVersion.MC1_7_R4) { getLogger().warning( "Skipped the NBTList check, because 1.7 doesn't fully support it! The Item-NBT-API may not work!");