|
1 | 1 | package net.md_5.bungee.api.plugin;
|
2 | 2 |
|
3 | 3 | import com.google.common.base.Preconditions;
|
| 4 | +import com.google.common.collect.ImmutableMap; |
4 | 5 | import com.google.common.io.ByteStreams;
|
5 | 6 | import java.io.File;
|
6 | 7 | import java.io.IOException;
|
|
9 | 10 | import java.net.URLClassLoader;
|
10 | 11 | import java.security.CodeSigner;
|
11 | 12 | import java.security.CodeSource;
|
| 13 | +import java.util.Map; |
12 | 14 | import java.util.Set;
|
13 | 15 | import java.util.concurrent.CopyOnWriteArraySet;
|
14 | 16 | import java.util.jar.JarEntry;
|
15 | 17 | import java.util.jar.JarFile;
|
16 | 18 | import java.util.jar.Manifest;
|
| 19 | +import java.util.logging.Level; |
| 20 | +import java.util.logging.Logger; |
17 | 21 | import lombok.ToString;
|
18 | 22 | import net.md_5.bungee.api.ProxyServer;
|
| 23 | +import org.objectweb.asm.ClassReader; |
| 24 | +import org.objectweb.asm.ClassWriter; |
| 25 | +import org.objectweb.asm.commons.ClassRemapper; |
| 26 | +import org.objectweb.asm.commons.SimpleRemapper; |
19 | 27 |
|
20 | 28 | @ToString(of = "desc")
|
21 | 29 | final class PluginClassloader extends URLClassLoader
|
@@ -121,6 +129,15 @@ protected Class<?> findClass(String name) throws ClassNotFoundException
|
121 | 129 | throw new ClassNotFoundException( name, ex );
|
122 | 130 | }
|
123 | 131 |
|
| 132 | + try |
| 133 | + { |
| 134 | + classBytes = remap( classBytes ); |
| 135 | + } catch ( Exception ex ) |
| 136 | + { |
| 137 | + Logger logger = ( plugin != null ) ? plugin.getLogger() : proxy.getLogger(); |
| 138 | + logger.log( Level.SEVERE, "Error trying to remap class " + path, ex ); |
| 139 | + } |
| 140 | + |
124 | 141 | int dot = name.lastIndexOf( '.' );
|
125 | 142 | if ( dot != -1 )
|
126 | 143 | {
|
@@ -155,6 +172,27 @@ protected Class<?> findClass(String name) throws ClassNotFoundException
|
155 | 172 | return super.findClass( name );
|
156 | 173 | }
|
157 | 174 |
|
| 175 | + private static final Map<String, String> MAPPINGS = ImmutableMap.of( |
| 176 | + "net/md_5/bungee/protocol/ChatChain", "net/md_5/bungee/protocol/data/ChatChain", |
| 177 | + "net/md_5/bungee/protocol/Location", "net/md_5/bungee/protocol/data/Location", |
| 178 | + "net/md_5/bungee/protocol/NumberFormat", "net/md_5/bungee/protocol/data/NumberFormat", |
| 179 | + "net/md_5/bungee/protocol/PlayerPublicKey", "net/md_5/bungee/protocol/data/PlayerPublicKey", |
| 180 | + "net/md_5/bungee/protocol/Property", "net/md_5/bungee/protocol/data/Property", |
| 181 | + "net/md_5/bungee/protocol/SeenMessages", "net/md_5/bungee/protocol/data/SeenMessages", |
| 182 | + "net/md_5/bungee/protocol/Either", "net/md_5/bungee/protocol/util/Either", |
| 183 | + "net/md_5/bungee/protocol/TagUtil", "net/md_5/bungee/protocol/util/TagUtil" |
| 184 | + ); |
| 185 | + |
| 186 | + private static byte[] remap(byte[] b) |
| 187 | + { |
| 188 | + ClassReader cr = new ClassReader( b ); |
| 189 | + ClassWriter cw = new ClassWriter( cr, 0 ); |
| 190 | + |
| 191 | + cr.accept( new ClassRemapper( cw, new SimpleRemapper( MAPPINGS ) ), 0 ); |
| 192 | + |
| 193 | + return cw.toByteArray(); |
| 194 | + } |
| 195 | + |
158 | 196 | @Override
|
159 | 197 | public void close() throws IOException
|
160 | 198 | {
|
|
0 commit comments