diff --git a/craftbukkit_1_11_R1/pom.xml b/craftbukkit_1_11_R1/pom.xml index 40242574..4c1092b7 100644 --- a/craftbukkit_1_11_R1/pom.xml +++ b/craftbukkit_1_11_R1/pom.xml @@ -26,7 +26,7 @@ org.bukkit craftbukkit - 1.11-R0.1-SNAPSHOT + 1.11.2-R0.1-SNAPSHOT provided diff --git a/pom.xml b/pom.xml index 876d3b83..0877f194 100644 --- a/pom.xml +++ b/pom.xml @@ -15,6 +15,7 @@ shade core abstract + rpapi-patch_1_11_R1 craftbukkit_1_11_R1 craftbukkit_1_10_R1 craftbukkit_1_9_R2 @@ -70,9 +71,24 @@ 2.6.9 provided + org.inventivetalent.resourcepackapi - api + v1_10_R1 + 2.2.1 + + + org.inventivetalent.resourcepackapi + v1_9_R2 + 2.2.1 + + + org.inventivetalent.resourcepackapi + v1_9_R1 2.2.1 diff --git a/rpapi-patch_1_11_R1/pom.xml b/rpapi-patch_1_11_R1/pom.xml new file mode 100644 index 00000000..eb4b9b77 --- /dev/null +++ b/rpapi-patch_1_11_R1/pom.xml @@ -0,0 +1,40 @@ + + 4.0.0 + io.github.dre2n + dungeonsxl-rpapi-patch_1_11_R1 + ${parent.version} + jar + dungeonsxl-rpapi-patch_1_11_R1 + + io.github.dre2n + dungeonsxl + 0.15.6 + + + + + maven-compiler-plugin + 2.5.1 + + 1.7 + 1.7 + + + + + + + org.bukkit + craftbukkit + 1.11.2-R0.1-SNAPSHOT + provided + + + io.github.dre2n + dungeonsxl-abstract + ${parent.version} + jar + compile + + + diff --git a/rpapi-patch_1_11_R1/src/main/java/io/github/dre2n/dungeonsxl/util/reflectionhelper/minecraft/Minecraft.java b/rpapi-patch_1_11_R1/src/main/java/io/github/dre2n/dungeonsxl/util/reflectionhelper/minecraft/Minecraft.java new file mode 100644 index 00000000..9784bf93 --- /dev/null +++ b/rpapi-patch_1_11_R1/src/main/java/io/github/dre2n/dungeonsxl/util/reflectionhelper/minecraft/Minecraft.java @@ -0,0 +1,243 @@ +/* + * Copyright 2016 inventivetalent. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and contributors and should not be interpreted as representing official policies, + * either expressed or implied, of anybody else. + */ + +package io.github.dre2n.dungeonsxl.util.reflectionhelper.minecraft; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Entity; +import org.inventivetalent.reflection.resolver.ConstructorResolver; +import org.inventivetalent.reflection.resolver.FieldResolver; +import org.inventivetalent.reflection.resolver.MethodResolver; +import org.inventivetalent.reflection.resolver.minecraft.NMSClassResolver; +import org.inventivetalent.reflection.resolver.minecraft.OBCClassResolver; +import org.inventivetalent.reflection.util.AccessUtil; +import sun.reflect.ConstructorAccessor; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * Helper class to access minecraft/bukkit specific objects + */ +public class Minecraft { + static final Pattern NUMERIC_VERSION_PATTERN = Pattern.compile("v([0-9])_([0-9])*_R([0-9])"); + + public static final Version VERSION; + + private static NMSClassResolver nmsClassResolver = new NMSClassResolver(); + private static OBCClassResolver obcClassResolver = new OBCClassResolver(); + private static Class NmsEntity; + private static Class CraftEntity; + + static { + VERSION = Version.getVersion(); + System.out.println("[ReflectionHelper] Version is " + VERSION); + + try { + NmsEntity = nmsClassResolver.resolve("Entity"); + CraftEntity = obcClassResolver.resolve("entity.CraftEntity"); + } catch (ReflectiveOperationException e) { + throw new RuntimeException(e); + } + } + + /** + * @return the current NMS/OBC version (format <version>. + */ + public static String getVersion() { + return VERSION.name() + "."; + } + + public static Object getHandle(Object object) throws ReflectiveOperationException { + Method method; + try { + method = AccessUtil.setAccessible(object.getClass().getDeclaredMethod("getHandle")); + } catch (ReflectiveOperationException e) { + method = AccessUtil.setAccessible(CraftEntity.getDeclaredMethod("getHandle")); + } + return method.invoke(object); + } + + public static Entity getBukkitEntity(Object object) throws ReflectiveOperationException { + Method method; + try { + method = AccessUtil.setAccessible(NmsEntity.getDeclaredMethod("getBukkitEntity")); + } catch (ReflectiveOperationException e) { + method = AccessUtil.setAccessible(CraftEntity.getDeclaredMethod("getHandle")); + } + return (Entity) method.invoke(object); + } + + public static Object getHandleSilent(Object object) { + try { + return getHandle(object); + } catch (Exception e) { + } + return null; + } + + public enum Version { + UNKNOWN(-1) { + @Override + public boolean matchesPackageName(String packageName) { + return false; + } + }, + + v1_7_R1(10701), + v1_7_R2(10702), + v1_7_R3(10703), + v1_7_R4(10704), + + v1_8_R1(10801), + v1_8_R2(10802), + v1_8_R3(10803), + //Does this even exists? + v1_8_R4(10804), + + v1_9_R1(10901), + v1_9_R2(10902), + + v1_10_R1(11001), + + v1_11_R1(11101); + + private int version; + + Version(int version) { + this.version = version; + } + + /** + * @return the version-number + */ + public int version() { + return version; + } + + /** + * @param version the version to check + * @return true if this version is older than the specified version + */ + public boolean olderThan(Version version) { + return version() < version.version(); + } + + /** + * @param version the version to check + * @return true if this version is newer than the specified version + */ + public boolean newerThan(Version version) { + return version() >= version.version(); + } + + /** + * @param oldVersion The older version to check + * @param newVersion The newer version to check + * @return true if this version is newer than the oldVersion and older that the newVersion + */ + public boolean inRange(Version oldVersion, Version newVersion) { + return newerThan(oldVersion) && olderThan(newVersion); + } + + public boolean matchesPackageName(String packageName) { + return packageName.toLowerCase().contains(name().toLowerCase()); + } + + public static Version getVersion() { + String name = Bukkit.getServer().getClass().getPackage().getName(); + String versionPackage = name.substring(name.lastIndexOf('.') + 1) + "."; + for (Version version : values()) { + if (version.matchesPackageName(versionPackage)) { return version; } + } + System.err.println("[ReflectionHelper] Failed to find version enum for '" + name + "'/'" + versionPackage + "'"); + + System.out.println("[ReflectionHelper] Generating dynamic constant..."); + Matcher matcher = NUMERIC_VERSION_PATTERN.matcher(versionPackage); + while (matcher.find()) { + if (matcher.groupCount() < 3) { continue; } + + String majorString = matcher.group(1); + String minorString = matcher.group(2); + if (minorString.length() == 1) { minorString = "0" + minorString; } + String patchString = matcher.group(3); + if (patchString.length() == 1) { patchString = "0" + patchString; } + + String numVersionString = majorString + minorString + patchString; + int numVersion = Integer.parseInt(numVersionString); + String packge = versionPackage.substring(0, versionPackage.length() - 1); + + try { + // Add enum value + Field valuesField = new FieldResolver(Version.class).resolve("$VALUES"); + Version[] oldValues = (Version[]) valuesField.get(null); + Version[] newValues = new Version[oldValues.length + 1]; + System.arraycopy(oldValues, 0, newValues, 0, oldValues.length); + Version dynamicVersion = (Version) newEnumInstance(Version.class, new Class[] { + String.class, + int.class, + int.class }, new Object[] { + packge, + newValues.length - 1, + numVersion }); + newValues[newValues.length - 1] = dynamicVersion; + valuesField.set(null, newValues); + + System.out.println("[ReflectionHelper] Injected dynamic version " + packge + " (#" + numVersion + ")."); + System.out.println("[ReflectionHelper] Please inform inventivetalent about the outdated version, as this is not guaranteed to work."); + return dynamicVersion; + } catch (ReflectiveOperationException e) { + e.printStackTrace(); + } + } + + return UNKNOWN; + } + + @Override + public String toString() { + return name() + " (" + version() + ")"; + } + } + + public static Object newEnumInstance(Class clazz, Class[] types, Object[] values) throws ReflectiveOperationException { + Constructor constructor = new ConstructorResolver(clazz).resolve(types); + Field accessorField = new FieldResolver(Constructor.class).resolve("constructorAccessor"); + ConstructorAccessor constructorAccessor = (ConstructorAccessor) accessorField.get(constructor); + if (constructorAccessor == null) { + new MethodResolver(Constructor.class).resolve("acquireConstructorAccessor").invoke(constructor); + constructorAccessor = (ConstructorAccessor) accessorField.get(constructor); + } + return constructorAccessor.newInstance(values); + + } + +} diff --git a/rpapi-patch_1_11_R1/src/main/java/io/github/dre2n/dungeonsxl/util/resourcepackapi/packet/PacketPlayResourcePackStatus_v1_11_R1.java b/rpapi-patch_1_11_R1/src/main/java/io/github/dre2n/dungeonsxl/util/resourcepackapi/packet/PacketPlayResourcePackStatus_v1_11_R1.java new file mode 100644 index 00000000..fb13f3ef --- /dev/null +++ b/rpapi-patch_1_11_R1/src/main/java/io/github/dre2n/dungeonsxl/util/resourcepackapi/packet/PacketPlayResourcePackStatus_v1_11_R1.java @@ -0,0 +1,162 @@ +/* + * Copyright 2016 inventivetalent. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and contributors and should not be interpreted as representing official policies, + * either expressed or implied, of anybody else. + */ + +package io.github.dre2n.dungeonsxl.util.resourcepackapi.packet; + +import io.netty.buffer.ByteBuf; +import io.netty.channel.Channel; +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.ByteToMessageDecoder; +import java.lang.reflect.Field; +import java.util.List; +import net.minecraft.server.v1_11_R1.EntityPlayer; +import net.minecraft.server.v1_11_R1.NetworkManager; +import net.minecraft.server.v1_11_R1.Packet; +import net.minecraft.server.v1_11_R1.PacketPlayInResourcePackStatus; +import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer; +import org.bukkit.entity.Player; +import org.inventivetalent.rpapi.IPacketPlayResourcePackStatus; +import org.inventivetalent.rpapi.RPApiPlugin; +import org.inventivetalent.rpapi.Status; + +public class PacketPlayResourcePackStatus_v1_11_R1 implements IPacketPlayResourcePackStatus +{ + private Status status; + private Player p; + private static Field channelField; + + @Override + public Status getStatus() { + /*SL:55*/return this.status; + } + + @Override + public String getHash() { + /*SL:60*/return null; + } + + @Override + public void onPacketReceive(final Object v2, final Player v3) { + /*SL:65*/if (!(v2 instanceof Packet)) { + return; + } + /*SL:66*/this.p = v3; + try { + final Field a1 = /*EL:69*/PacketPlayInResourcePackStatus.class.getDeclaredField("status"); + /*SL:70*/a1.setAccessible(true); + /*SL:72*/this.status = Status.byID(((PacketPlayInResourcePackStatus.EnumResourcePackStatus)a1.get(v2)).ordinal()); + } + catch (Exception a2) { + /*SL:74*/a2.printStackTrace(); + } + /*SL:77*/if (this.getStatus() != null && v3 != null) { + /*SL:78*/RPApiPlugin.onResourcePackResult(this.getStatus(), v3, this.getHash()); + } + } + + @Override + public void inject() throws NoSuchFieldException, IllegalAccessException { + } + + @Override + public void addChannelForPlayer(final Player v0) { + /*SL:90*/if (PacketPlayResourcePackStatus_v1_11_R1.channelField == null) { + try { + PacketPlayResourcePackStatus_v1_11_R1.channelField = /*EL:92*/NetworkManager.class.getDeclaredField("channel"); + } + catch (NoSuchFieldException | SecurityException a1) { + /*SL:94*/a1.printStackTrace(); + } + PacketPlayResourcePackStatus_v1_11_R1.channelField.setAccessible(/*EL:96*/true); + } + try { + final EntityPlayer v = /*EL:99*/((CraftPlayer)v0).getHandle(); + final Channel v2 = (Channel)PacketPlayResourcePackStatus_v1_11_R1.channelField.get(/*EL:100*/v.playerConnection.networkManager); + /*SL:101*/new Thread(new Runnable() { + @Override + public void run() { + try { + /*SL:106*//*EL:109*/v2.pipeline().addBefore("packet_handler", "RPApi", (io.netty.channel.ChannelHandler)new ChannelHandler(v0)); + } + catch (Exception ex) {} + } + }, "RPApi channel adder").start(); + } + catch (Exception v3) { + /*SL:112*/v3.printStackTrace(); + } + } + + @Override + public void removeChannelForPlayer(final Player v0) { + /*SL:118*/if (PacketPlayResourcePackStatus_v1_11_R1.channelField == null) { + try { + PacketPlayResourcePackStatus_v1_11_R1.channelField = /*EL:120*/NetworkManager.class.getDeclaredField("channel"); + } + catch (NoSuchFieldException | SecurityException a1) { + /*SL:122*/a1.printStackTrace(); + } + PacketPlayResourcePackStatus_v1_11_R1.channelField.setAccessible(/*EL:124*/true); + } + try { + final EntityPlayer v = /*EL:127*/((CraftPlayer)v0).getHandle(); + final Channel v2 = (Channel)PacketPlayResourcePackStatus_v1_11_R1.channelField.get(/*EL:128*/v.playerConnection.networkManager); + /*SL:129*/new Thread(new Runnable() { + @Override + public void run() { + try { + /*SL:134*//*EL:137*/v2.pipeline().remove("RPApi"); + } + catch (Exception ex) {} + } + }, "RPApi channel remover").start(); + } + catch (Exception v3) { + /*SL:140*/v3.printStackTrace(); + } + } + + public class ChannelHandler extends ByteToMessageDecoder + { + private Player p; + + public ChannelHandler(final Player a2) { + this.p = a2; + } + + public void channelRead(final ChannelHandlerContext a1, final Object a2) throws Exception { + /*SL:154*/if (PacketPlayInResourcePackStatus.class.isAssignableFrom(a2.getClass())) { + /*SL:155*/PacketPlayResourcePackStatus_v1_11_R1.this.onPacketReceive(a2, this.p); + } + /*SL:157*/super.channelRead(a1, a2); + } + + protected void decode(final ChannelHandlerContext a1, final ByteBuf a2, final List a3) throws Exception { + } + } +} diff --git a/shade/pom.xml b/shade/pom.xml index 2935efbc..76c4925b 100644 --- a/shade/pom.xml +++ b/shade/pom.xml @@ -34,11 +34,11 @@ io.github.dre2n.dungeonsxl.util.resourcepackapi - de.inventivegames.rpapi - io.github.dre2n.dungeonsxl.util.resourcepackapi + org.inventivetalent.reflection + io.github.dre2n.dungeonsxl.util.reflectionhelper - org.inventivetalent.reflection + de.inventivegames.rpapi io.github.dre2n.dungeonsxl.util.resourcepackapi @@ -47,7 +47,8 @@ io.github.dre2n:commons io.github.dre2n:caliburn io.github.dre2n:dungeonsxl-* - org.inventivetalent.resourcepackapi:api + org.inventivetalent:reflection + org.inventivetalent.resourcepackapi:* @@ -71,6 +72,13 @@ jar compile + + io.github.dre2n + dungeonsxl-rpapi-patch_1_11_R1 + ${parent.version} + jar + compile + io.github.dre2n dungeonsxl-craftbukkit_1_11_R1