updating a plugin for 1.14.4

Discussion in 'Spigot Plugin Development' started by DiegoDev, Sep 19, 2019.

  1. I am updating a plugin that was abandoned a while ago but I know a little bit of code, I want to update it to 1.14.4 the plugin.

    the error is in getMaterial

    Code (Java):
        private boolean _whatIs(CommandSender cs, String[] args)
        {
            if(args.length < 2 || args[1].equalsIgnoreCase("?"))
            {
                cs.sendMessage(ChatColor.DARK_GREEN+"------  /ri whatis | wi <property name>  ------");
                cs.sendMessage("Describes a rare item property to you.");
                cs.sendMessage("");

               
                String sProperties = "";
               
                for(ItemProperty ip : plugin.propertyManager.getAllProperties())
                {
                    sProperties += ", "+ip.getName();
                }
               
                cs.sendMessage(ChatColor.GRAY+"Available properties: "+ChatColor.WHITE+sProperties.substring(2));
                cs.sendMessage(ChatColor.DARK_GREEN+"---------------------------------");
            }
            else
            {
                String sPropertyName = "";
                for(int i=1;i<args.length;i++)
                {
                    sPropertyName += " "+args[i];
                }
                sPropertyName = sPropertyName.substring(1);
               
                ItemProperty property = plugin.propertyManager.getProperty(sPropertyName);
               
                if(property == null)
                {
                    cs.sendMessage(ChatColor.RED+"'"+sPropertyName+"' is not a valid rare item property!");
                   
                    return true;
                }
               
                cs.sendMessage(ChatColor.DARK_GREEN+"------  "+property.getName()+"  ------");
                cs.sendMessage(property.getDescription());
                cs.sendMessage("");
               
                cs.sendMessage(ChatColor.GRAY+"Recipe:");
               
                if(property.getRecipeLines() == null)
                {
                    cs.sendMessage(ChatColor.RED+"No recipe found.");
                }
                else
                {
                    for(String sLine : property.getRecipeLines())
                    {
                        cs.sendMessage(sLine);
                    }
                }
               
                cs.sendMessage("");
               
                cs.sendMessage(ChatColor.GRAY+"Can be put on:");
               
                String sAllowedItems = "";
               
                for(int iItemId : plugin.recipeManager.getPropertyRecipeItemList(property))
                {
                    sAllowedItems += ", "+Material.getMaterial(iItemId);
                }
               
                cs.sendMessage(sAllowedItems.substring(2));
               
                cs.sendMessage(ChatColor.GRAY+"Max level: "+ChatColor.WHITE+property.getMaxLevel());        
                cs.sendMessage(ChatColor.GRAY+"Cost: "+ChatColor.WHITE+property.getCost(1));
               
    /* TODO : figure out what's up with cost increments
                for(int i=1;i<=property.getMaxLevel();i++)
                {
                    cs.sendMessage(ChatColor.WHITE+"lv"+i+" - "
                            +ChatColor.RESET+((property.getCost(i) - plugin.COST_LEVEL_INCREMENT) * plugin.COST_MULTIPLIER)
                            +" "+plugin.COST_TYPE.name().toLowerCase());
                }*/

               
                cs.sendMessage("");
                cs.sendMessage(ChatColor.DARK_GREEN+"-------------------------");
            }
           
            return true;
        }
    }
     
  2. Materials are no longer integers, you need a String and do Material.valueOf(string)
     
  3. I get the same error, I get to change it to String,

    Code (Java):
                for(int iItemId : plugin.recipeManager.getPropertyRecipeItemList(property))
                {
                    sAllowedItems += ", "+ Material.valueOf(iItemId);
                }
     
  4. I get red in plugin.recipeManager.getPropertyRecipeItemList(property))

    Code (Java):
                for(String iItemId: plugin.recipeManager.getPropertyRecipeItemList(property))
                {
                    sAllowedItems += ", "+ Material.valueOf(iItemId);
                }
     
  5. I dont think you get the Problem here.
    Seems like the Method "plugin.recipeManager.getPropertyRecipeItemList(property)" returns an iterable Object containing old Item IDs (as i don´t think you changed what gets stored in that iterable Object).

    Item IDs were Numbers - Datatype Int/Integer
    But what you want/need to use aren´t no longer the numeric IDs, but the Material Name (since Spigot 1.13).

    For Example: Grass had the ID 2 (if i recall correct). But now Minecraft wouldn´t know what "2" is, as Grass is defined as "minecraft:grass".
    As you can see, this is no longer a numeric object but actual letters which are normally saved as a String Datatype.

    And you "get red" because you want to work with the Strings/"letters" from a Iterable Object which seems to only contain Numbers. And That doesn´t work, as you can´t convert these Numbers into Letters (Technically you could, but in this case it wouldn´t help you as you would just get the old ID as a Letter, which still doesn´t tells Minecraft what item it is).
     
  6. I see now I understand
    here I have this problem will it be for this?

    Code (Java):
            for(String iMaterialId : ALL_TYPE_MATERIALS)
            {
                for(int i = 1;i<9;i++)
                {
                    ShapelessRecipe recipe = new ShapelessRecipe(DEFAULT_IS);
                 
                    recipe.addIngredient(Material.valueOf(iMaterialId));
                 
                    recipe.addIngredient(i, Material.MAGMA_CREAM);
                 
                    plugin.getServer().addRecipe(recipe);
                }
            }
     
    #7 DiegoDev, Sep 19, 2019
    Last edited: Sep 19, 2019