Add some plugin remapping to assist compatibility
This commit is contained in:
@@ -75,6 +75,12 @@
|
|||||||
<!-- not part of the API proper -->
|
<!-- not part of the API proper -->
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.ow2.asm</groupId>
|
||||||
|
<artifactId>asm-commons</artifactId>
|
||||||
|
<version>9.8</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.yaml</groupId>
|
<groupId>org.yaml</groupId>
|
||||||
<artifactId>snakeyaml</artifactId>
|
<artifactId>snakeyaml</artifactId>
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
package net.md_5.bungee.api.plugin;
|
package net.md_5.bungee.api.plugin;
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -9,13 +10,20 @@ import java.net.URL;
|
|||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
import java.security.CodeSigner;
|
import java.security.CodeSigner;
|
||||||
import java.security.CodeSource;
|
import java.security.CodeSource;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.CopyOnWriteArraySet;
|
import java.util.concurrent.CopyOnWriteArraySet;
|
||||||
import java.util.jar.JarEntry;
|
import java.util.jar.JarEntry;
|
||||||
import java.util.jar.JarFile;
|
import java.util.jar.JarFile;
|
||||||
import java.util.jar.Manifest;
|
import java.util.jar.Manifest;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
|
import org.objectweb.asm.ClassReader;
|
||||||
|
import org.objectweb.asm.ClassWriter;
|
||||||
|
import org.objectweb.asm.commons.ClassRemapper;
|
||||||
|
import org.objectweb.asm.commons.SimpleRemapper;
|
||||||
|
|
||||||
@ToString(of = "desc")
|
@ToString(of = "desc")
|
||||||
final class PluginClassloader extends URLClassLoader
|
final class PluginClassloader extends URLClassLoader
|
||||||
@@ -121,6 +129,15 @@ final class PluginClassloader extends URLClassLoader
|
|||||||
throw new ClassNotFoundException( name, ex );
|
throw new ClassNotFoundException( name, ex );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
classBytes = remap( classBytes );
|
||||||
|
} catch ( Exception ex )
|
||||||
|
{
|
||||||
|
Logger logger = ( plugin != null ) ? plugin.getLogger() : proxy.getLogger();
|
||||||
|
logger.log( Level.SEVERE, "Error trying to remap class " + path, ex );
|
||||||
|
}
|
||||||
|
|
||||||
int dot = name.lastIndexOf( '.' );
|
int dot = name.lastIndexOf( '.' );
|
||||||
if ( dot != -1 )
|
if ( dot != -1 )
|
||||||
{
|
{
|
||||||
@@ -155,6 +172,27 @@ final class PluginClassloader extends URLClassLoader
|
|||||||
return super.findClass( name );
|
return super.findClass( name );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final Map<String, String> MAPPINGS = ImmutableMap.of(
|
||||||
|
"net/md_5/bungee/protocol/ChatChain", "net/md_5/bungee/protocol/data/ChatChain",
|
||||||
|
"net/md_5/bungee/protocol/Location", "net/md_5/bungee/protocol/data/Location",
|
||||||
|
"net/md_5/bungee/protocol/NumberFormat", "net/md_5/bungee/protocol/data/NumberFormat",
|
||||||
|
"net/md_5/bungee/protocol/PlayerPublicKey", "net/md_5/bungee/protocol/data/PlayerPublicKey",
|
||||||
|
"net/md_5/bungee/protocol/Property", "net/md_5/bungee/protocol/data/Property",
|
||||||
|
"net/md_5/bungee/protocol/SeenMessages", "net/md_5/bungee/protocol/data/SeenMessages",
|
||||||
|
"net/md_5/bungee/protocol/Either", "net/md_5/bungee/protocol/util/Either",
|
||||||
|
"net/md_5/bungee/protocol/TagUtil", "net/md_5/bungee/protocol/util/TagUtil"
|
||||||
|
);
|
||||||
|
|
||||||
|
private static byte[] remap(byte[] b)
|
||||||
|
{
|
||||||
|
ClassReader cr = new ClassReader( b );
|
||||||
|
ClassWriter cw = new ClassWriter( cr, 0 );
|
||||||
|
|
||||||
|
cr.accept( new ClassRemapper( cw, new SimpleRemapper( MAPPINGS ) ), 0 );
|
||||||
|
|
||||||
|
return cw.toByteArray();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() throws IOException
|
public void close() throws IOException
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user