Crash NPE after server restart

Discussion in 'Bukkit Help' started by Unica, Oct 27, 2015.

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

    Unica

    Hello.

    I've been playing with custom enchantments lately.
    After every server restart (local machine) these items with those enchantments
    make me 'disconnect' from my server after some of interaction with it.

    Error detail:

    Code:
    [18:14:44 INFO]: Unica lost connection: Internal Exception: io.netty.handler.co
    dec.DecoderException: java.lang.NullPointerException
    Notes:

    - These custom enchantments are just objects that get returned because of the LORE text. No metadata changes to these items. They are not related to the actual Enchantment object of the bukkit API.
    - Every interaction with that item will crash/kick me. (Ex. Opening my inventory while the item is inside it / Right-click using it / clicking on it in inventory)
    - If I 'destroy' or drop the item (using 'Q' if in hotbar) and I 'create' the same weapon + enchantment again, it works fine.
    - I am using a custom Enchantment class to create the Glow effect.
    - I am using the Particle Effect library from click here

    Server/plugin details:

    - Spigot/craftbukkit build 1.8.7
    - Implementing API version 1.8.7-R0.1-SNAPSHOT
    - Playing on 1.8.5

    Screenshot

    The lore looks like this
    [​IMG]

    Kicking message
    [​IMG]

     
  2. Offline

    RoboticPlayer

    @Unica Are you a developer testing a plugin or a server owner? If you are a server owner, you might want to send this to the creator of the plugin of which you are having issues with. If you are a developer, can we see relevant parts of your code? Either way, we need the entire stacktrace (error log).
     
  3. Offline

    Unica

    @henderry2019

    Code:
    package nl.dubehh.lib;
    
    import org.bukkit.enchantments.Enchantment;
    import org.bukkit.enchantments.EnchantmentTarget;
    import org.bukkit.enchantments.EnchantmentWrapper;
    import org.bukkit.inventory.ItemStack;
    
    import java.lang.reflect.Field;
    
    public class Glow extends EnchantmentWrapper {
    
        private static Enchantment glow;
    
        public Glow(int id) {
            super(id);
        }
    
        @Override
        public boolean canEnchantItem(ItemStack item) {
            return true;
        }
    
        @Override
        public boolean conflictsWith(Enchantment other) {
            return false;
        }
    
        @Override
        public EnchantmentTarget getItemTarget() {
            return null;
        }
    
        @Override
        public int getMaxLevel() {
            return 10;
        }
    
        @Override
        public String getName() {
            return "Glow";
        }
    
        @Override
        public int getStartLevel() {
            return 1;
        }
    
        @SuppressWarnings("deprecation")
        public static Enchantment getGlow() {
            if (glow != null)
                return glow;
            Enchantment g = Enchantment.getById(255);
            if (g instanceof Glow) {
                glow = (Glow) g;
                return glow;
            }
            try {
                Field f = Enchantment.class.getDeclaredField("acceptingNew");
                f.setAccessible(true);
                f.set(null, true);
            } catch (Exception e) {
                e.printStackTrace();
            }
            glow = new Glow(255);
            for(Enchantment e : Enchantment.values()){
                if(e.equals(glow))
                    return glow;
            }
            Enchantment.registerEnchantment(glow);
            return glow;
        }
    
        public static void addGlow(ItemStack item) {
            Enchantment glow = getGlow();
            if (item.containsEnchantment(glow)) {
                item.removeEnchantment(glow);
            }
            item.addEnchantment(glow, 1);
        }
    }
    That is only piece of code of which I believe to be possible for this type of error.

    That is the entire stacktrace.
    According to internet, it is not related to my code, but due to conflict within the changed item and minecraft.

    The item is just an item with Itemmeta (aka lore).

    EDIT: It's not the Glow enchantment. I just recreated it without the glow. Still kicked me after a restart.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Oct 29, 2015
  4. Offline

    Unica

    Bump
     
  5. Offline

    RoboticPlayer

    Wait so it is a client crash? Or a server error?
     
Thread Status:
Not open for further replies.

Share This Page