Add ResourcePackAPI patch module for v1_11_R1 support

This commit is contained in:
Daniel Saukel 2017-01-04 21:59:15 +01:00
parent c28bdf1285
commit 640ee498cb
6 changed files with 475 additions and 6 deletions

View File

@ -26,7 +26,7 @@
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
<version>1.11-R0.1-SNAPSHOT</version>
<version>1.11.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>

18
pom.xml
View File

@ -15,6 +15,7 @@
<module>shade</module>
<module>core</module>
<module>abstract</module>
<module>rpapi-patch_1_11_R1</module>
<module>craftbukkit_1_11_R1</module>
<module>craftbukkit_1_10_R1</module>
<module>craftbukkit_1_9_R2</module>
@ -70,9 +71,24 @@
<version>2.6.9</version>
<scope>provided</scope>
</dependency>
<!--<dependency>
<groupId>org.inventivetalent.resourcepackapi</groupId>
<artifactId>v1_11_R1</artifactId>
<version>2.2.1</version>
</dependency>-->
<dependency>
<groupId>org.inventivetalent.resourcepackapi</groupId>
<artifactId>api</artifactId>
<artifactId>v1_10_R1</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>org.inventivetalent.resourcepackapi</groupId>
<artifactId>v1_9_R2</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>org.inventivetalent.resourcepackapi</groupId>
<artifactId>v1_9_R1</artifactId>
<version>2.2.1</version>
</dependency>
</dependencies>

View File

@ -0,0 +1,40 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.github.dre2n</groupId>
<artifactId>dungeonsxl-rpapi-patch_1_11_R1</artifactId>
<version>${parent.version}</version>
<packaging>jar</packaging>
<name>dungeonsxl-rpapi-patch_1_11_R1</name>
<parent>
<groupId>io.github.dre2n</groupId>
<artifactId>dungeonsxl</artifactId>
<version>0.15.6</version>
</parent>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
<version>1.11.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.github.dre2n</groupId>
<artifactId>dungeonsxl-abstract</artifactId>
<version>${parent.version}</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
</dependencies>
</project>

View File

@ -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 <code>&lt;version&gt;.</code>
*/
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 <code>true</code> 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 <code>true</code> 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 <code>true</code> 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);
}
}

View File

@ -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<Object> a3) throws Exception {
}
}
}

View File

@ -34,11 +34,11 @@
<shadedPattern>io.github.dre2n.dungeonsxl.util.resourcepackapi</shadedPattern>
</relocation>
<relocation>
<pattern>de.inventivegames.rpapi</pattern>
<shadedPattern>io.github.dre2n.dungeonsxl.util.resourcepackapi</shadedPattern>
<pattern>org.inventivetalent.reflection</pattern>
<shadedPattern>io.github.dre2n.dungeonsxl.util.reflectionhelper</shadedPattern>
</relocation>
<relocation>
<pattern>org.inventivetalent.reflection</pattern>
<pattern>de.inventivegames.rpapi</pattern>
<shadedPattern>io.github.dre2n.dungeonsxl.util.resourcepackapi</shadedPattern>
</relocation>
</relocations>
@ -47,7 +47,8 @@
<include>io.github.dre2n:commons</include>
<include>io.github.dre2n:caliburn</include>
<include>io.github.dre2n:dungeonsxl-*</include>
<include>org.inventivetalent.resourcepackapi:api</include>
<include>org.inventivetalent:reflection</include>
<include>org.inventivetalent.resourcepackapi:*</include>
</includes>
</artifactSet>
</configuration>
@ -71,6 +72,13 @@
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.github.dre2n</groupId>
<artifactId>dungeonsxl-rpapi-patch_1_11_R1</artifactId>
<version>${parent.version}</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.github.dre2n</groupId>
<artifactId>dungeonsxl-craftbukkit_1_11_R1</artifactId>