1.15.2 Errors in my Plugin

Discussion in 'Spigot Plugin Development' started by MonsterXtreme, Feb 20, 2020.

  1. Good, I'm a little cold because it's been a while since I played Java and Minecraft plugins, so I have several errors, to see if please someone help me to solve them :)


    Here I leave the pastebin with the types of errors that arise and see if someone gives me a solution please

    https://pastebin.com/dha90MuU
     
  2. SteelPhoenix

    Moderator

    Item IDs have been deprecated since 1.8 and have been removed in later version. Don't use them.
     
  3. So what solution do you recommend for such cases, remove the parts of the id and not change it for anything? just remove them?
     
  4. Replace them by, for example, a Material constant to compare them against.
     
  5. that for what kind of pastebin error?

    Could you give me an example and I fix the others?

    thanks
     
    • Funny Funny x 1
  6. For all errors where you're using numerical ids.

    As an example:
    Code (Java):
    boolean isStone = item.getType() == Material.STONE; //checks whether the item is stone
     


  7. forgive me for being so short minded now but I still don't understand it xD I mean in this case that I expose you now how would you make the change?

    Code (Java):
    i = f.createItem(p.getName(), item, 1);
                meta = i.getItemMeta();
                id = i.getTypeId()+((i.getDurability() > 0)?":"+i.getDurability():"");
                precioBuy = f.getPrice(item);
                precioSell = precioBuy*f.SELLRATE/f.MULTIPLIER;
    How would you solve the getTypeId in this case?
     
  8. I have solved the issue of the ids but I still have several errors that I cannot solve
    Let's see if someone can solve them please

    In this code the part doesnt work "" ItemStack stack = new ItemStack(getId(item)); ""

    Code (Java):
    public ItemStack createItem(String p, String item, int size){
            ItemStack stack = new ItemStack(getId(item));
            short data = (short)getData(item);
            if(haveData(item)){
                stack.setDurability(data);
            }
    In this code the part doesnt work "" int maxStack = Material.getMaterial(getId(item)).getMaxStackSize(); ""
    Code (Java):
     public List<ItemStack> createItems(String p, String item, int num){
            List<ItemStack> items = new ArrayList<>();
            int maxStack = Material.getMaterial(getId(item)).getMaxStackSize();
            if(num%maxStack > 0){
                items.add(createItem(p, item, num%maxStack));
                num -= num%maxStack;
            }
            for(int i = 0; i < num/maxStack; i++){
                items.add(createItem(p, item, maxStack));
            }
            return items;
        }
    In this code the part doesnt work "" if(!(event.getInventory().getName() == getShopName())){ ""
    Code (Java):
    private void onClickInventory(InventoryClickEvent event){
            // TEST long timeI = System.nanoTime();
            if(event.getInventory().getType() != InventoryType.CHEST){
                return;
            }
            if(event.getInventory().getSize() != FactoryGui.SIZE){
                return;
            }
            if(!(event.getInventory().getName() == getShopName())){
                return;
            }

    the getid that comes out in the errors comes from this method

    Code (Java):
        private int getId(String item){
            int id = getCache().getInt("item."+item+".id");
            if (id == 0) {
                SpiceCraft.log("Item: " + item + "not found in shop.yml.");
            }
            return id == 0 ? 1 : id;
        }
    I would be very grateful if someone would help me with these 3 errors and give me the solution or example of how to fix it regards
     
    #8 MonsterXtreme, Feb 20, 2020
    Last edited: Feb 20, 2020
  9. Try using .equals instead of == in java strings.
    example:
    Code (Text):
    if(!(event.getInventory().getName().equals(getShopName()))){
        return;
    }
     
     
  10. I'm not trying to be rude or anything, but how can you play java or minecraft plugins?
    I think that sentence was a mistake from you.
     
  11. You're trying to create items from numerical IDs. That's no longer possible, you'll have to provide a string representation of the material (e.g., "stone" for stone). If you still want to use numerical IDs, you'll need to make some mappings from numerical IDs to string IDs.