mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-02 17:32:03 +01:00
Reformat Commodore.java
By: md_5 <git@md-5.net>
This commit is contained in:
parent
19e69bb8fc
commit
8f59d4abd3
1 changed files with 149 additions and 218 deletions
|
@ -27,16 +27,9 @@ import org.objectweb.asm.MethodVisitor;
|
|||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.Type;
|
||||
|
||||
/**
|
||||
* This file is imported from Commodore.
|
||||
*
|
||||
* @author md_5
|
||||
*/
|
||||
// CHECKSTYLE:OFF
|
||||
public class Commodore
|
||||
{
|
||||
public class Commodore {
|
||||
|
||||
private static final Set<String> EVIL = new HashSet<>( Arrays.asList(
|
||||
private static final Set<String> EVIL = new HashSet<>(Arrays.asList(
|
||||
"org/bukkit/World (III)I getBlockTypeIdAt",
|
||||
"org/bukkit/World (Lorg/bukkit/Location;)I getBlockTypeIdAt",
|
||||
"org/bukkit/block/Block ()I getTypeId",
|
||||
|
@ -47,177 +40,147 @@ public class Commodore
|
|||
"org/bukkit/block/Block (BZ)V setData",
|
||||
"org/bukkit/inventory/ItemStack ()I getTypeId",
|
||||
"org/bukkit/inventory/ItemStack (I)V setTypeId"
|
||||
) );
|
||||
));
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
public static void main(String[] args) {
|
||||
OptionParser parser = new OptionParser();
|
||||
OptionSpec<File> inputFlag = parser.acceptsAll( Arrays.asList( "i", "input" ) ).withRequiredArg().ofType( File.class ).required();
|
||||
OptionSpec<File> outputFlag = parser.acceptsAll( Arrays.asList( "o", "output" ) ).withRequiredArg().ofType( File.class ).required();
|
||||
OptionSpec<File> inputFlag = parser.acceptsAll(Arrays.asList("i", "input")).withRequiredArg().ofType(File.class).required();
|
||||
OptionSpec<File> outputFlag = parser.acceptsAll(Arrays.asList("o", "output")).withRequiredArg().ofType(File.class).required();
|
||||
|
||||
OptionSet options = parser.parse( args );
|
||||
OptionSet options = parser.parse(args);
|
||||
|
||||
File input = options.valueOf( inputFlag );
|
||||
File output = options.valueOf( outputFlag );
|
||||
File input = options.valueOf(inputFlag);
|
||||
File output = options.valueOf(outputFlag);
|
||||
|
||||
if ( input.isDirectory() )
|
||||
{
|
||||
if ( !output.isDirectory() )
|
||||
{
|
||||
System.err.println( "If input directory specified, output directory required too" );
|
||||
if (input.isDirectory()) {
|
||||
if (!output.isDirectory()) {
|
||||
System.err.println("If input directory specified, output directory required too");
|
||||
return;
|
||||
}
|
||||
|
||||
for ( File in : input.listFiles() )
|
||||
{
|
||||
if ( in.getName().endsWith( ".jar" ) )
|
||||
{
|
||||
convert( in, new File( output, in.getName() ) );
|
||||
for (File in : input.listFiles()) {
|
||||
if (in.getName().endsWith(".jar")) {
|
||||
convert(in, new File(output, in.getName()));
|
||||
}
|
||||
}
|
||||
} else
|
||||
{
|
||||
convert( input, output );
|
||||
} else {
|
||||
convert(input, output);
|
||||
}
|
||||
}
|
||||
|
||||
private static void convert(File in, File out)
|
||||
{
|
||||
System.out.println( "Attempting to convert " + in + " to " + out );
|
||||
private static void convert(File in, File out) {
|
||||
System.out.println("Attempting to convert " + in + " to " + out);
|
||||
|
||||
try
|
||||
{
|
||||
try ( JarFile inJar = new JarFile( in, false ) )
|
||||
{
|
||||
JarEntry entry = inJar.getJarEntry( ".commodore" );
|
||||
if ( entry != null )
|
||||
{
|
||||
try {
|
||||
try (JarFile inJar = new JarFile(in, false)) {
|
||||
JarEntry entry = inJar.getJarEntry(".commodore");
|
||||
if (entry != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try ( JarOutputStream outJar = new JarOutputStream( new FileOutputStream( out ) ) )
|
||||
{
|
||||
for ( Enumeration<JarEntry> entries = inJar.entries(); entries.hasMoreElements(); )
|
||||
{
|
||||
try (JarOutputStream outJar = new JarOutputStream(new FileOutputStream(out))) {
|
||||
for (Enumeration<JarEntry> entries = inJar.entries(); entries.hasMoreElements();) {
|
||||
entry = entries.nextElement();
|
||||
|
||||
try ( InputStream is = inJar.getInputStream( entry ) )
|
||||
{
|
||||
byte[] b = ByteStreams.toByteArray( is );
|
||||
try (InputStream is = inJar.getInputStream(entry)) {
|
||||
byte[] b = ByteStreams.toByteArray(is);
|
||||
|
||||
if ( entry.getName().endsWith( ".class" ) )
|
||||
{
|
||||
b = convert( b, false );
|
||||
entry = new JarEntry( entry.getName() );
|
||||
if (entry.getName().endsWith(".class")) {
|
||||
b = convert(b, false);
|
||||
entry = new JarEntry(entry.getName());
|
||||
}
|
||||
|
||||
outJar.putNextEntry( entry );
|
||||
outJar.write( b );
|
||||
outJar.putNextEntry(entry);
|
||||
outJar.write(b);
|
||||
}
|
||||
}
|
||||
|
||||
outJar.putNextEntry( new ZipEntry( ".commodore" ) );
|
||||
outJar.putNextEntry(new ZipEntry(".commodore"));
|
||||
}
|
||||
}
|
||||
} catch ( Exception ex )
|
||||
{
|
||||
System.err.println( "Fatal error trying to convert " + in );
|
||||
} catch (Exception ex) {
|
||||
System.err.println("Fatal error trying to convert " + in);
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] convert(byte[] b, final boolean modern)
|
||||
{
|
||||
ClassReader cr = new ClassReader( b );
|
||||
ClassWriter cw = new ClassWriter( cr, 0 );
|
||||
public static byte[] convert(byte[] b, final boolean modern) {
|
||||
ClassReader cr = new ClassReader(b);
|
||||
ClassWriter cw = new ClassWriter(cr, 0);
|
||||
|
||||
cr.accept( new ClassVisitor( Opcodes.ASM9, cw )
|
||||
{
|
||||
cr.accept(new ClassVisitor(Opcodes.ASM9, cw) {
|
||||
@Override
|
||||
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions)
|
||||
{
|
||||
return new MethodVisitor( api, super.visitMethod( access, name, desc, signature, exceptions ) )
|
||||
{
|
||||
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
|
||||
return new MethodVisitor(api, super.visitMethod(access, name, desc, signature, exceptions)) {
|
||||
|
||||
@Override
|
||||
public void visitFieldInsn(int opcode, String owner, String name, String desc)
|
||||
{
|
||||
if ( owner.equals( "org/bukkit/block/Biome" ) )
|
||||
{
|
||||
switch ( name )
|
||||
{
|
||||
public void visitFieldInsn(int opcode, String owner, String name, String desc) {
|
||||
if (owner.equals("org/bukkit/block/Biome")) {
|
||||
switch (name) {
|
||||
case "NETHER":
|
||||
super.visitFieldInsn( opcode, owner, "NETHER_WASTES", desc );
|
||||
super.visitFieldInsn(opcode, owner, "NETHER_WASTES", desc);
|
||||
return;
|
||||
case "TALL_BIRCH_FOREST":
|
||||
super.visitFieldInsn( opcode, owner, "OLD_GROWTH_BIRCH_FOREST", desc );
|
||||
super.visitFieldInsn(opcode, owner, "OLD_GROWTH_BIRCH_FOREST", desc);
|
||||
return;
|
||||
case "GIANT_TREE_TAIGA":
|
||||
super.visitFieldInsn( opcode, owner, "OLD_GROWTH_PINE_TAIGA", desc );
|
||||
super.visitFieldInsn(opcode, owner, "OLD_GROWTH_PINE_TAIGA", desc);
|
||||
return;
|
||||
case "GIANT_SPRUCE_TAIGA":
|
||||
super.visitFieldInsn( opcode, owner, "OLD_GROWTH_SPRUCE_TAIGA", desc );
|
||||
super.visitFieldInsn(opcode, owner, "OLD_GROWTH_SPRUCE_TAIGA", desc);
|
||||
return;
|
||||
case "SNOWY_TUNDRA":
|
||||
super.visitFieldInsn( opcode, owner, "SNOWY_PLAINS", desc );
|
||||
super.visitFieldInsn(opcode, owner, "SNOWY_PLAINS", desc);
|
||||
return;
|
||||
case "JUNGLE_EDGE":
|
||||
super.visitFieldInsn( opcode, owner, "SPARSE_JUNGLE", desc );
|
||||
super.visitFieldInsn(opcode, owner, "SPARSE_JUNGLE", desc);
|
||||
return;
|
||||
case "STONE_SHORE":
|
||||
super.visitFieldInsn( opcode, owner, "STONY_SHORE", desc );
|
||||
super.visitFieldInsn(opcode, owner, "STONY_SHORE", desc);
|
||||
return;
|
||||
case "MOUNTAINS":
|
||||
super.visitFieldInsn( opcode, owner, "WINDSWEPT_HILLS", desc );
|
||||
super.visitFieldInsn(opcode, owner, "WINDSWEPT_HILLS", desc);
|
||||
return;
|
||||
case "WOODED_MOUNTAINS":
|
||||
super.visitFieldInsn( opcode, owner, "WINDSWEPT_FOREST", desc );
|
||||
super.visitFieldInsn(opcode, owner, "WINDSWEPT_FOREST", desc);
|
||||
return;
|
||||
case "GRAVELLY_MOUNTAINS":
|
||||
super.visitFieldInsn( opcode, owner, "WINDSWEPT_GRAVELLY_HILLS", desc );
|
||||
super.visitFieldInsn(opcode, owner, "WINDSWEPT_GRAVELLY_HILLS", desc);
|
||||
return;
|
||||
case "SHATTERED_SAVANNA":
|
||||
super.visitFieldInsn( opcode, owner, "WINDSWEPT_SAVANNA", desc );
|
||||
super.visitFieldInsn(opcode, owner, "WINDSWEPT_SAVANNA", desc);
|
||||
return;
|
||||
case "WOODED_BADLANDS_PLATEAU":
|
||||
super.visitFieldInsn( opcode, owner, "WOODED_BADLANDS", desc );
|
||||
super.visitFieldInsn(opcode, owner, "WOODED_BADLANDS", desc);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ( owner.equals( "org/bukkit/entity/EntityType" ) )
|
||||
{
|
||||
switch ( name )
|
||||
{
|
||||
if (owner.equals("org/bukkit/entity/EntityType")) {
|
||||
switch (name) {
|
||||
case "PIG_ZOMBIE":
|
||||
super.visitFieldInsn( opcode, owner, "ZOMBIFIED_PIGLIN", desc );
|
||||
super.visitFieldInsn(opcode, owner, "ZOMBIFIED_PIGLIN", desc);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ( owner.equals( "org/bukkit/loot/LootTables" ) )
|
||||
{
|
||||
switch ( name )
|
||||
{
|
||||
if (owner.equals("org/bukkit/loot/LootTables")) {
|
||||
switch (name) {
|
||||
case "ZOMBIE_PIGMAN":
|
||||
super.visitFieldInsn( opcode, owner, "ZOMBIFIED_PIGLIN", desc );
|
||||
super.visitFieldInsn(opcode, owner, "ZOMBIFIED_PIGLIN", desc);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// SPIGOT-7335
|
||||
if ( owner.equals( "org/bukkit/entity/TextDisplay$TextAligment" ) )
|
||||
{
|
||||
super.visitFieldInsn( opcode, "org/bukkit/entity/TextDisplay$TextAlignment", name, desc );
|
||||
if (owner.equals("org/bukkit/entity/TextDisplay$TextAligment")) {
|
||||
super.visitFieldInsn(opcode, "org/bukkit/entity/TextDisplay$TextAlignment", name, desc);
|
||||
return;
|
||||
}
|
||||
|
||||
if ( modern )
|
||||
{
|
||||
if ( owner.equals( "org/bukkit/Material" ) )
|
||||
{
|
||||
switch ( name )
|
||||
{
|
||||
if (modern) {
|
||||
if (owner.equals("org/bukkit/Material")) {
|
||||
switch (name) {
|
||||
case "CACTUS_GREEN":
|
||||
name = "GREEN_DYE";
|
||||
break;
|
||||
|
@ -245,231 +208,199 @@ public class Commodore
|
|||
}
|
||||
}
|
||||
|
||||
super.visitFieldInsn( opcode, owner, name, desc );
|
||||
super.visitFieldInsn(opcode, owner, name, desc);
|
||||
return;
|
||||
}
|
||||
|
||||
if ( owner.equals( "org/bukkit/Material" ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
Material.valueOf( "LEGACY_" + name );
|
||||
} catch ( IllegalArgumentException ex )
|
||||
{
|
||||
throw new AuthorNagException( "No legacy enum constant for " + name + ". Did you forget to define a modern (1.13+) api-version in your plugin.yml?" );
|
||||
if (owner.equals("org/bukkit/Material")) {
|
||||
try {
|
||||
Material.valueOf("LEGACY_" + name);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
throw new AuthorNagException("No legacy enum constant for " + name + ". Did you forget to define a modern (1.13+) api-version in your plugin.yml?");
|
||||
}
|
||||
|
||||
super.visitFieldInsn( opcode, owner, "LEGACY_" + name, desc );
|
||||
super.visitFieldInsn(opcode, owner, "LEGACY_" + name, desc);
|
||||
return;
|
||||
}
|
||||
|
||||
if ( owner.equals( "org/bukkit/Art" ) )
|
||||
{
|
||||
switch ( name )
|
||||
{
|
||||
if (owner.equals("org/bukkit/Art")) {
|
||||
switch (name) {
|
||||
case "BURNINGSKULL":
|
||||
super.visitFieldInsn( opcode, owner, "BURNING_SKULL", desc );
|
||||
super.visitFieldInsn(opcode, owner, "BURNING_SKULL", desc);
|
||||
return;
|
||||
case "DONKEYKONG":
|
||||
super.visitFieldInsn( opcode, owner, "DONKEY_KONG", desc );
|
||||
super.visitFieldInsn(opcode, owner, "DONKEY_KONG", desc);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ( owner.equals( "org/bukkit/DyeColor" ) )
|
||||
{
|
||||
switch ( name )
|
||||
{
|
||||
if (owner.equals("org/bukkit/DyeColor")) {
|
||||
switch (name) {
|
||||
case "SILVER":
|
||||
super.visitFieldInsn( opcode, owner, "LIGHT_GRAY", desc );
|
||||
super.visitFieldInsn(opcode, owner, "LIGHT_GRAY", desc);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ( owner.equals( "org/bukkit/Particle" ) )
|
||||
{
|
||||
switch ( name )
|
||||
{
|
||||
if (owner.equals("org/bukkit/Particle")) {
|
||||
switch (name) {
|
||||
case "BLOCK_CRACK":
|
||||
case "BLOCK_DUST":
|
||||
case "FALLING_DUST":
|
||||
super.visitFieldInsn( opcode, owner, "LEGACY_" + name, desc );
|
||||
super.visitFieldInsn(opcode, owner, "LEGACY_" + name, desc);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
super.visitFieldInsn( opcode, owner, name, desc );
|
||||
super.visitFieldInsn(opcode, owner, name, desc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf)
|
||||
{
|
||||
public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) {
|
||||
// SPIGOT-4496
|
||||
if ( owner.equals( "org/bukkit/map/MapView" ) && name.equals( "getId" ) && desc.equals( "()S" ) )
|
||||
{
|
||||
if (owner.equals("org/bukkit/map/MapView") && name.equals("getId") && desc.equals("()S")) {
|
||||
// Should be same size on stack so just call other method
|
||||
super.visitMethodInsn( opcode, owner, name, "()I", itf );
|
||||
super.visitMethodInsn(opcode, owner, name, "()I", itf);
|
||||
return;
|
||||
}
|
||||
// SPIGOT-4608
|
||||
if ( (owner.equals( "org/bukkit/Bukkit" ) || owner.equals( "org/bukkit/Server" ) ) && name.equals( "getMap" ) && desc.equals( "(S)Lorg/bukkit/map/MapView;" ) )
|
||||
{
|
||||
if ((owner.equals("org/bukkit/Bukkit") || owner.equals("org/bukkit/Server")) && name.equals("getMap") && desc.equals("(S)Lorg/bukkit/map/MapView;")) {
|
||||
// Should be same size on stack so just call other method
|
||||
super.visitMethodInsn( opcode, owner, name, "(I)Lorg/bukkit/map/MapView;", itf );
|
||||
super.visitMethodInsn(opcode, owner, name, "(I)Lorg/bukkit/map/MapView;", itf);
|
||||
return;
|
||||
}
|
||||
// SPIGOT-7335
|
||||
if ( owner.equals( "org/bukkit/entity/TextDisplay$TextAligment" ) )
|
||||
{
|
||||
super.visitMethodInsn( opcode, "org/bukkit/entity/TextDisplay$TextAlignment", name, desc, itf );
|
||||
if (owner.equals("org/bukkit/entity/TextDisplay$TextAligment")) {
|
||||
super.visitMethodInsn(opcode, "org/bukkit/entity/TextDisplay$TextAlignment", name, desc, itf);
|
||||
return;
|
||||
}
|
||||
if ( desc.equals( "(Lorg/bukkit/entity/TextDisplay$TextAligment;)V" ) )
|
||||
{
|
||||
super.visitMethodInsn( opcode, owner, name, "(Lorg/bukkit/entity/TextDisplay$TextAlignment;)V", itf );
|
||||
if (desc.equals("(Lorg/bukkit/entity/TextDisplay$TextAligment;)V")) {
|
||||
super.visitMethodInsn(opcode, owner, name, "(Lorg/bukkit/entity/TextDisplay$TextAlignment;)V", itf);
|
||||
return;
|
||||
}
|
||||
if ( desc.equals( "()Lorg/bukkit/entity/TextDisplay$TextAligment;" ) )
|
||||
{
|
||||
super.visitMethodInsn( opcode, owner, name, "()Lorg/bukkit/entity/TextDisplay$TextAlignment;", itf );
|
||||
if (desc.equals("()Lorg/bukkit/entity/TextDisplay$TextAligment;")) {
|
||||
super.visitMethodInsn(opcode, owner, name, "()Lorg/bukkit/entity/TextDisplay$TextAlignment;", itf);
|
||||
return;
|
||||
}
|
||||
|
||||
if ( owner.startsWith( "org/bukkit" ) && desc.contains( "org/bukkit/util/Consumer" ) )
|
||||
{
|
||||
super.visitMethodInsn( opcode, owner, name, desc.replace( "org/bukkit/util/Consumer", "java/util/function/Consumer" ), itf );
|
||||
if (owner.startsWith("org/bukkit") && desc.contains("org/bukkit/util/Consumer")) {
|
||||
super.visitMethodInsn(opcode, owner, name, desc.replace("org/bukkit/util/Consumer", "java/util/function/Consumer"), itf);
|
||||
return;
|
||||
}
|
||||
|
||||
if ( modern )
|
||||
{
|
||||
if ( owner.equals( "org/bukkit/Material" ) )
|
||||
{
|
||||
switch ( name )
|
||||
{
|
||||
if (modern) {
|
||||
if (owner.equals("org/bukkit/Material")) {
|
||||
switch (name) {
|
||||
case "values":
|
||||
super.visitMethodInsn( opcode, "org/bukkit/craftbukkit/util/CraftLegacy", "modern_" + name, desc, itf );
|
||||
super.visitMethodInsn(opcode, "org/bukkit/craftbukkit/util/CraftLegacy", "modern_" + name, desc, itf);
|
||||
return;
|
||||
case "ordinal":
|
||||
super.visitMethodInsn( Opcodes.INVOKESTATIC, "org/bukkit/craftbukkit/util/CraftLegacy", "modern_" + name, "(Lorg/bukkit/Material;)I", false );
|
||||
super.visitMethodInsn(Opcodes.INVOKESTATIC, "org/bukkit/craftbukkit/util/CraftLegacy", "modern_" + name, "(Lorg/bukkit/Material;)I", false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
super.visitMethodInsn( opcode, owner, name, desc, itf );
|
||||
super.visitMethodInsn(opcode, owner, name, desc, itf);
|
||||
return;
|
||||
}
|
||||
|
||||
if ( owner.equals( "org/bukkit/ChunkSnapshot" ) && name.equals( "getBlockData" ) && desc.equals( "(III)I" ) )
|
||||
{
|
||||
super.visitMethodInsn( opcode, owner, "getData", desc, itf );
|
||||
if (owner.equals("org/bukkit/ChunkSnapshot") && name.equals("getBlockData") && desc.equals("(III)I")) {
|
||||
super.visitMethodInsn(opcode, owner, "getData", desc, itf);
|
||||
return;
|
||||
}
|
||||
|
||||
Type retType = Type.getReturnType( desc );
|
||||
Type retType = Type.getReturnType(desc);
|
||||
|
||||
if ( EVIL.contains( owner + " " + desc + " " + name )
|
||||
|| ( owner.startsWith( "org/bukkit/block/" ) && ( desc + " " + name ).equals( "()I getTypeId" ) )
|
||||
|| ( owner.startsWith( "org/bukkit/block/" ) && ( desc + " " + name ).equals( "(I)Z setTypeId" ) )
|
||||
|| ( owner.startsWith( "org/bukkit/block/" ) && ( desc + " " + name ).equals( "()Lorg/bukkit/Material; getType" ) ) )
|
||||
{
|
||||
Type[] args = Type.getArgumentTypes( desc );
|
||||
Type[] newArgs = new Type[ args.length + 1 ];
|
||||
newArgs[0] = Type.getObjectType( owner );
|
||||
System.arraycopy( args, 0, newArgs, 1, args.length );
|
||||
if (EVIL.contains(owner + " " + desc + " " + name)
|
||||
|| (owner.startsWith("org/bukkit/block/") && (desc + " " + name).equals("()I getTypeId"))
|
||||
|| (owner.startsWith("org/bukkit/block/") && (desc + " " + name).equals("(I)Z setTypeId"))
|
||||
|| (owner.startsWith("org/bukkit/block/") && (desc + " " + name).equals("()Lorg/bukkit/Material; getType"))) {
|
||||
Type[] args = Type.getArgumentTypes(desc);
|
||||
Type[] newArgs = new Type[args.length + 1];
|
||||
newArgs[0] = Type.getObjectType(owner);
|
||||
System.arraycopy(args, 0, newArgs, 1, args.length);
|
||||
|
||||
super.visitMethodInsn( Opcodes.INVOKESTATIC, "org/bukkit/craftbukkit/legacy/CraftEvil", name, Type.getMethodDescriptor( retType, newArgs ), false );
|
||||
super.visitMethodInsn(Opcodes.INVOKESTATIC, "org/bukkit/craftbukkit/legacy/CraftEvil", name, Type.getMethodDescriptor(retType, newArgs), false);
|
||||
return;
|
||||
}
|
||||
|
||||
if ( owner.equals( "org/bukkit/DyeColor" ) )
|
||||
{
|
||||
if ( name.equals( "valueOf" ) && desc.equals( "(Ljava/lang/String;)Lorg/bukkit/DyeColor;" ) )
|
||||
{
|
||||
super.visitMethodInsn( opcode, owner, "legacyValueOf", desc, itf );
|
||||
if (owner.equals("org/bukkit/DyeColor")) {
|
||||
if (name.equals("valueOf") && desc.equals("(Ljava/lang/String;)Lorg/bukkit/DyeColor;")) {
|
||||
super.visitMethodInsn(opcode, owner, "legacyValueOf", desc, itf);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ( owner.equals( "org/bukkit/Material" ) )
|
||||
{
|
||||
if ( name.equals( "getMaterial" ) && desc.equals( "(I)Lorg/bukkit/Material;" ) )
|
||||
{
|
||||
super.visitMethodInsn( opcode, "org/bukkit/craftbukkit/legacy/CraftEvil", name, desc, itf );
|
||||
if (owner.equals("org/bukkit/Material")) {
|
||||
if (name.equals("getMaterial") && desc.equals("(I)Lorg/bukkit/Material;")) {
|
||||
super.visitMethodInsn(opcode, "org/bukkit/craftbukkit/legacy/CraftEvil", name, desc, itf);
|
||||
return;
|
||||
}
|
||||
|
||||
switch ( name )
|
||||
{
|
||||
switch (name) {
|
||||
case "values":
|
||||
case "valueOf":
|
||||
case "getMaterial":
|
||||
case "matchMaterial":
|
||||
super.visitMethodInsn( opcode, "org/bukkit/craftbukkit/legacy/CraftLegacy", name, desc, itf );
|
||||
super.visitMethodInsn(opcode, "org/bukkit/craftbukkit/legacy/CraftLegacy", name, desc, itf);
|
||||
return;
|
||||
case "ordinal":
|
||||
super.visitMethodInsn( Opcodes.INVOKESTATIC, "org/bukkit/craftbukkit/legacy/CraftLegacy", "ordinal", "(Lorg/bukkit/Material;)I", false );
|
||||
super.visitMethodInsn(Opcodes.INVOKESTATIC, "org/bukkit/craftbukkit/legacy/CraftLegacy", "ordinal", "(Lorg/bukkit/Material;)I", false);
|
||||
return;
|
||||
case "name":
|
||||
case "toString":
|
||||
super.visitMethodInsn( Opcodes.INVOKESTATIC, "org/bukkit/craftbukkit/legacy/CraftLegacy", name, "(Lorg/bukkit/Material;)Ljava/lang/String;", false );
|
||||
super.visitMethodInsn(Opcodes.INVOKESTATIC, "org/bukkit/craftbukkit/legacy/CraftLegacy", name, "(Lorg/bukkit/Material;)Ljava/lang/String;", false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ( retType.getSort() == Type.OBJECT && retType.getInternalName().equals( "org/bukkit/Material" ) && owner.startsWith( "org/bukkit" ) )
|
||||
{
|
||||
super.visitMethodInsn( opcode, owner, name, desc, itf );
|
||||
super.visitMethodInsn( Opcodes.INVOKESTATIC, "org/bukkit/craftbukkit/legacy/CraftLegacy", "toLegacy", "(Lorg/bukkit/Material;)Lorg/bukkit/Material;", false );
|
||||
if (retType.getSort() == Type.OBJECT && retType.getInternalName().equals("org/bukkit/Material") && owner.startsWith("org/bukkit")) {
|
||||
super.visitMethodInsn(opcode, owner, name, desc, itf);
|
||||
super.visitMethodInsn(Opcodes.INVOKESTATIC, "org/bukkit/craftbukkit/legacy/CraftLegacy", "toLegacy", "(Lorg/bukkit/Material;)Lorg/bukkit/Material;", false);
|
||||
return;
|
||||
}
|
||||
|
||||
super.visitMethodInsn( opcode, owner, name, desc, itf );
|
||||
super.visitMethodInsn(opcode, owner, name, desc, itf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitLdcInsn(Object value)
|
||||
{
|
||||
if ( value instanceof String && ( (String) value ).equals( "com.mysql.jdbc.Driver" ) )
|
||||
{
|
||||
super.visitLdcInsn( "com.mysql.cj.jdbc.Driver" );
|
||||
public void visitLdcInsn(Object value) {
|
||||
if (value instanceof String && ((String) value).equals("com.mysql.jdbc.Driver")) {
|
||||
super.visitLdcInsn("com.mysql.cj.jdbc.Driver");
|
||||
return;
|
||||
}
|
||||
|
||||
super.visitLdcInsn( value );
|
||||
super.visitLdcInsn(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitInvokeDynamicInsn( String name, String descriptor, Handle bootstrapMethodHandle, Object... bootstrapMethodArguments )
|
||||
{
|
||||
if ( bootstrapMethodHandle.getOwner().equals( "java/lang/invoke/LambdaMetafactory" )
|
||||
&& bootstrapMethodHandle.getName().equals( "metafactory" ) && bootstrapMethodArguments.length == 3 )
|
||||
{
|
||||
Type samMethodType = (Type) bootstrapMethodArguments[ 0 ];
|
||||
Handle implMethod = (Handle) bootstrapMethodArguments[ 1 ];
|
||||
Type instantiatedMethodType = (Type) bootstrapMethodArguments[ 2 ];
|
||||
public void visitInvokeDynamicInsn(String name, String descriptor, Handle bootstrapMethodHandle, Object... bootstrapMethodArguments) {
|
||||
if (bootstrapMethodHandle.getOwner().equals("java/lang/invoke/LambdaMetafactory")
|
||||
&& bootstrapMethodHandle.getName().equals("metafactory") && bootstrapMethodArguments.length == 3) {
|
||||
Type samMethodType = (Type) bootstrapMethodArguments[0];
|
||||
Handle implMethod = (Handle) bootstrapMethodArguments[1];
|
||||
Type instantiatedMethodType = (Type) bootstrapMethodArguments[2];
|
||||
|
||||
List<Object> newTypes = new ArrayList<>();
|
||||
newTypes.add( samMethodType );
|
||||
newTypes.add(samMethodType);
|
||||
|
||||
if ( implMethod.getOwner().startsWith( "org/bukkit" ) && implMethod.getDesc().contains( "org/bukkit/util/Consumer" ) )
|
||||
{
|
||||
implMethod = new Handle( implMethod.getTag(), implMethod.getOwner(), implMethod.getName(),
|
||||
implMethod.getDesc().replace( "org/bukkit/util/Consumer", "java/util/function/Consumer" ), implMethod.isInterface() );
|
||||
if (implMethod.getOwner().startsWith("org/bukkit") && implMethod.getDesc().contains("org/bukkit/util/Consumer")) {
|
||||
implMethod = new Handle(implMethod.getTag(), implMethod.getOwner(), implMethod.getName(),
|
||||
implMethod.getDesc().replace("org/bukkit/util/Consumer", "java/util/function/Consumer"), implMethod.isInterface());
|
||||
}
|
||||
|
||||
newTypes.add( implMethod );
|
||||
newTypes.add( instantiatedMethodType );
|
||||
newTypes.add(implMethod);
|
||||
newTypes.add(instantiatedMethodType);
|
||||
|
||||
super.visitInvokeDynamicInsn( name, descriptor, bootstrapMethodHandle, newTypes.toArray() );
|
||||
super.visitInvokeDynamicInsn(name, descriptor, bootstrapMethodHandle, newTypes.toArray());
|
||||
return;
|
||||
}
|
||||
|
||||
super.visitInvokeDynamicInsn( name, descriptor, bootstrapMethodHandle, bootstrapMethodArguments );
|
||||
super.visitInvokeDynamicInsn(name, descriptor, bootstrapMethodHandle, bootstrapMethodArguments);
|
||||
}
|
||||
};
|
||||
}
|
||||
}, 0 );
|
||||
}, 0);
|
||||
|
||||
return cw.toByteArray();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue