NullPointerException in Plugin.

Discussion in 'Plugin Development' started by CelestilsLLC, Mar 28, 2017.

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

    CelestilsLLC

    When our command (CelestialsLLC) ported plugin CivCraft (github.com/ataranlen/civcraft) to bukkit version 1_6_3R on minecraft version 1.6.4 we ran into problem java.lang.NullPointerException (https://pastebin.com/LA6UWbVx)
    code (open)

    AttributeUtil:
    Code:
    (231)public AttributeUtil(ItemStack stack) {
            // Create a CraftItemStack (under the hood)
            this.nmsStack = CraftItemStack.asNMSCopy(stack);
           
            if (this.nmsStack == null) {
                return;
            }
           
            if (nmsStack == null) {
                CivLog.error("Couldn't make NMS copyyy of:"+stack);
                this.nmsStack = CraftItemStack.asNMSCopy(ItemManager.createItemStack(CivData.WOOL, 1));
                if (this.nmsStack == null) {
                    return;
                }
            }
           
            // Load NBT
            if (nmsStack.tag == null) {
                parent = (nmsStack.tag = new NBTTagCompound());
            } else {
                parent = nmsStack.tag;
            }
           
            // Load attribute list
            if (parent.hasKey("AttributeModifiers")) {
                attributes = parent.getList("AttributeModifiers");
            } else {
                /* No attributes on this item detected. */
                attributes = new NBTTagList();
                parent.set("AttributeModifiers", attributes);
            }
    (262)    }
    LoreMaterial:

    Code:
    public static ItemStack spawn(LoreMaterial material) {
    (269)    return spawn(material,1);
    }
    
    public static ItemStack spawn(LoreMaterial material, int quantity) {
            ItemStack stack = ItemManager.createItemStack(material.getTypeID(), quantity, material.getDamage());
    (174)    AttributeUtil attrs = new AttributeUtil(stack);
            setMIDAndName(attrs, material.getId(), material.getName());
           
            if (material instanceof LoreCraftableMaterial) {
                LoreCraftableMaterial craftMat = (LoreCraftableMaterial)material;
                    attrs.addLore(CivColor.ITALIC+craftMat.getConfigMaterial().category);
                    if (craftMat.getConfigMaterial().tradeable) {
                        attrs.setCivCraftProperty("tradeable", "true");
                    }
                    if (craftMat.getConfigMaterial().tradeValue >= 0) {
                        attrs.setCivCraftProperty("tradeValue", ""+craftMat.getConfigMaterial().tradeValue);
                    }
                    if (craftMat.getConfigMaterial().shiny) {
                        attrs.setShiny();
                    }
            }
           
            material.applyAttributes(attrs);
            return attrs.getStack();
        }
    LoreCraftableMaterial:
    Code:
    public static void buildRecipes() {
            /*
             * Loads in materials from configuration file.
             */
            for (LoreCraftableMaterial loreMat : materials.values()) {
                if (!loreMat.isCraftable()) {
                    continue;
                }
               
    (217)        ItemStack stack = LoreMaterial.spawn(loreMat);           
                ConfigMaterial configMaterial = loreMat.configMaterial;
               
                if (loreMat.isShaped()) {
                    ItemStack[] matrix = new ItemStack[10];
                    ShapedRecipe recipe = new ShapedRecipe(stack);
                    recipe.shape(configMaterial.shape[0], configMaterial.shape[1], configMaterial.shape[2]);
                   
                    /* Setup the ingredients. */
                    for (ConfigIngredient ingred : configMaterial.ingredients.values()) {
                        ItemStack ingredStack = null;
    
                        if (ingred.custom_id == null) {
                            recipe.setIngredient(ingred.letter.charAt(0), ItemManager.getMaterialData(ingred.type_id, ingred.data));
                            ingredStack = ItemManager.createItemStack(ingred.type_id, 1, (short)ingred.data);
                        } else{
                            LoreCraftableMaterial customLoreMat = materials.get(ingred.custom_id);
                            if (customLoreMat == null) {
                                CivLog.warning("Couldn't find custom material id:"+ingred.custom_id);
                            }
                           
                            ConfigMaterial customMat = customLoreMat.configMaterial;
                            if (customMat != null) {
                                recipe.setIngredient(ingred.letter.charAt(0), ItemManager.getMaterialData(customMat.item_id, customMat.item_data));
                            } else {
                                CivLog.warning("Couldn't find custom material id:"+ingred.custom_id);
                            }
    
                            ingredStack = LoreMaterial.spawn(customLoreMat);
                        }
                   
                        /* Add this incred to the shape. */
                        int i = 0;
                        for (String row : configMaterial.shape) {
                            for (int c = 0; c < row.length(); c++) {
                                if (row.charAt(c) == ingred.letter.charAt(0)) {
                                    matrix[i] = ingredStack;
                                } else if (row.charAt(c) == ' '){
                                    matrix[i] = new ItemStack(Material.AIR, 0, (short)-1);
                                }
                                i++;
                            }
                        }
                   
                    }
                   
                    shapedRecipes.put(loreMat, matrix);
                    String key = getShapedRecipeKey(matrix);
                    shapedKeys.put(key, loreMat);
                   
    
                    /* Register recipe with server. */
                    Bukkit.getServer().addRecipe(recipe);
                } else {
                    /* Shapeless Recipe */
                    ShapelessRecipe recipe = new ShapelessRecipe(stack);
                    LinkedList<ItemStack> items = new LinkedList<ItemStack>();
                    ItemStack[] matrix = new ItemStack[9];
                    int matrixIndex = 0;
                   
                    /* Setup the ingredients. */
                    for (ConfigIngredient ingred : configMaterial.ingredients.values()) {
                        ItemStack ingredStack = null;
                       
                        try {
                        if (ingred.custom_id == null) {
                            recipe.addIngredient(ingred.count, ItemManager.getMaterialData(ingred.type_id, ingred.data));
                            ingredStack = ItemManager.createItemStack(ingred.type_id, 1, (short)ingred.data);
                        } else {
                            LoreCraftableMaterial customLoreMat = materials.get(ingred.custom_id);
                            if (customLoreMat == null) {
                                CivLog.error("Couldn't configure ingredient:"+ingred.custom_id+" in config mat:"+configMaterial.id);
                            }
                            ConfigMaterial customMat = customLoreMat.configMaterial;
                            if (customMat != null) {
                                recipe.addIngredient(ingred.count, ItemManager.getMaterialData(customMat.item_id, customMat.item_data));
                                ingredStack = LoreMaterial.spawn(customLoreMat);
                            } else {
                                CivLog.warning("Couldn't find custom material id:"+ingred.custom_id);
                            }
                        }
                        } catch (IllegalArgumentException e) {
                            CivLog.warning("Trying to process ingredient:"+ingred.type_id+":"+ingred.custom_id+" for material:"+configMaterial.id);
                            throw e;
                        }
                       
                        if (ingredStack != null) {
                        //    loreMat.shaplessIngredientList.add(ingredStack);
                            for (int i = 0; i < ingred.count; i++) {
                                if (matrixIndex > 9) {
                                    break;
                                }
                               
                                matrix[matrixIndex] = ingredStack;
                                matrixIndex++;
                            }
                           
                            ingredStack.setAmount(ingred.count);
                            items.add(ingredStack);
                        }
                    }
                   
                    shapelessRecipes.put(loreMat, items);
                    String key = getShapelessRecipeKey(matrix);
                    shapelessKeys.put(key, loreMat);
                   
                    /* Register recipe with server. */
                    Bukkit.getServer().addRecipe(recipe);
                }
            }
    CivSettings:

    Code:
    public static void init(JavaPlugin plugin) throws FileNotFoundException, IOException, InvalidConfigurationException, InvalidConfiguration {
            CivSettings.plugin = (CivCraft)plugin;
           
    
            String languageFile = CivSettings.getStringBase("localization_file");
            localize = new Localize(plugin, languageFile);
    
    
            CivLog.debug(localize.localizedString("welcome_string","test",1337,100.50));
            CURRENCY_NAME = localize.localizedString("civ_currencyName");
            CivGlobal.fullMessage = CivSettings.localize.localizedString("civGlobal_serverFullMsg");
           
            // Check for required data folder, if it's not there export it.
            CivSettings.validateFiles();
           
            initRestrictedItems();
            initRestrictedUndoBlocks();
            initSwitchItems();
            initRestrictedSpawns();
            initBlockPlaceExceptions();
            initPlayerEntityWeapons();
           
            loadConfigFiles();
            loadConfigObjects();
           
            Perk.init();
            Unit.init();
           
            //CivSettings.leather_speed = (float)CivSettings.getDouble(CivSettings.unitConfig, "base.leather_speed");
            //CivSettings.metal_speed = (float)CivSettings.getDouble(CivSettings.unitConfig, "base.metal_speed");
            CivSettings.T1_leather_speed = (float)CivSettings.getDouble(CivSettings.unitConfig, "base.T1_leather_speed");
            CivSettings.T2_leather_speed = (float)CivSettings.getDouble(CivSettings.unitConfig, "base.T2_leather_speed");
            CivSettings.T3_leather_speed = (float)CivSettings.getDouble(CivSettings.unitConfig, "base.T3_leather_speed");
            CivSettings.T4_leather_speed = (float)CivSettings.getDouble(CivSettings.unitConfig, "base.T4_leather_speed");
            CivSettings.T1_metal_speed = (float)CivSettings.getDouble(CivSettings.unitConfig, "base.T1_metal_speed");
            CivSettings.T2_metal_speed = (float)CivSettings.getDouble(CivSettings.unitConfig, "base.T2_metal_speed");
            CivSettings.T3_metal_speed = (float)CivSettings.getDouble(CivSettings.unitConfig, "base.T3_metal_speed");
            CivSettings.T4_metal_speed = (float)CivSettings.getDouble(CivSettings.unitConfig, "base.T4_metal_speed");
            CivSettings.normal_speed = 0.2f;   
           
            for (Object obj : civConfig.getList("global.start_kit")) {
                if (obj instanceof String) {
                    kitItems.add((String)obj);
                }
            }
           
           
            CivGlobal.banWords.add("fuck");
            CivGlobal.banWords.add("shit");
            CivGlobal.banWords.add("nigger");
            CivGlobal.banWords.add("faggot");
            CivGlobal.banWords.add("gay");
            CivGlobal.banWords.add("rape");
            CivGlobal.banWords.add("http");
            CivGlobal.banWords.add("cunt");
           
            iron_rate = CivSettings.getDouble(civConfig, "ore_rates.iron");
            gold_rate = CivSettings.getDouble(civConfig, "ore_rates.gold");
            diamond_rate = CivSettings.getDouble(civConfig, "ore_rates.diamond");
            emerald_rate = CivSettings.getDouble(civConfig, "ore_rates.emerald");
            startingCoins = CivSettings.getDouble(civConfig, "global.starting_coins");
           
            alwaysCrumble.add(CivData.BEDROCK);
            alwaysCrumble.add(CivData.COAL_BLOCK);
            alwaysCrumble.add(CivData.EMERALD_BLOCK);
            alwaysCrumble.add(CivData.LAPIS_BLOCK);
            alwaysCrumble.add(CivData.SPONGE);
            alwaysCrumble.add(CivData.HAY_BALE);
            alwaysCrumble.add(CivData.GOLD_BLOCK);
            alwaysCrumble.add(CivData.DIAMOND_BLOCK);
            alwaysCrumble.add(CivData.IRON_BLOCK);
            alwaysCrumble.add(CivData.REDSTONE_BLOCK);
            alwaysCrumble.add(CivData.ENDER_CHEST);
            alwaysCrumble.add(CivData.BEACON);
           
            LoreEnhancement.init();
            LoreCraftableMaterial.buildStaticMaterials();
     (306)       LoreCraftableMaterial.buildRecipes();
            Template.initAttachableTypes();
           
            if (CivSettings.plugin.hasPlugin("VanishNoPacket")) {
                hasVanishNoPacket = true;
            }
           
            if (CivSettings.plugin.hasPlugin("TitleAPI")) {
                hasTitleAPI = true;
            }
    
        }

    Please help us!
    HAVE A GOOD DAY!
     
  2. Offline

    Zombie_Striker

    Is itemstack null? for the spawn method? Are you sure 'stack' for the util is not null?
     
  3. Offline

    CelestilsLLC

    yeah,sure
     
  4. Offline

    MagicWinner

    You have found a solution to this problem?! Urgent help!
     
  5. Offline

    timtower Administrator Administrator Moderator

    @MagicWinner And you related to this project?
    And there were multiple questions asked, yet no response on those.
     
  6. Offline

    MagicWinner

    @timtower No, I just have the same problem.:)
     
Thread Status:
Not open for further replies.

Share This Page