Development Assistance How to catch NoClassDefFoundError for NMS packages?

Discussion in 'Plugin Help/Development/Requests' started by IconByte, Jun 24, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    IconByte

    Hello. I have been trying to make something like bukkit version checker, but it seems that it ignores the if statements and gives me the NoClassDefFoundError already for the 1st statement..

    Is there any way how to catch the error?

    I have tried this, but it doesn't work:
    Code:
            if (VersionHandler.is1_8_1()) {
                try {
                    net.minecraft.server.v1_8_R1.IChatBaseComponent icbc = net.minecraft.server.v1_8_R1.ChatSerializer.a("{\"text\": \"" + text + "\"}");
                    net.minecraft.server.v1_8_R1.PacketPlayOutChat bar = new net.minecraft.server.v1_8_R1.PacketPlayOutChat(icbc, (byte) 2);
                    ((org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer) player).getHandle().playerConnection.sendPacket(bar);
                } catch (NoClassDefFoundError ex) {}
            } else if (VersionHandler.is1_8_3()) {
                try {
                    net.minecraft.server.v1_8_R2.IChatBaseComponent icbc = net.minecraft.server.v1_8_R2.IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + text + "\"}");
                    net.minecraft.server.v1_8_R2.PacketPlayOutChat bar = new net.minecraft.server.v1_8_R2.PacketPlayOutChat(icbc, (byte) 2);
                    ((org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer) player).getHandle().playerConnection.sendPacket(bar);
                } catch (NoClassDefFoundError ex) {}
            } else if (VersionHandler.is1_8_7()) {
                try {
                    net.minecraft.server.v1_8_R3.IChatBaseComponent icbc = net.minecraft.server.v1_8_R3.IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + text + "\"}");
                    net.minecraft.server.v1_8_R3.PacketPlayOutChat bar = new net.minecraft.server.v1_8_R3.PacketPlayOutChat(icbc, (byte) 2);
                    ((org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer) player).getHandle().playerConnection.sendPacket(bar);
                } catch (NoClassDefFoundError ex) {}
            }
     
  2. Offline

    Bram0101

    when it seems like it ignores the thirst if statements, it's probably the if statement itself that's wrong, how does your VersionHandler look like?
     
  3. Offline

    xTrollxDudex

    To do this, you must edit the constant pool... The entire class is loaded first then your code is executed, if you would like to circumvent the version checks, place it in a separate class.
     
Thread Status:
Not open for further replies.

Share This Page