Solved FurnaceSmeltEvent

Discussion in 'Spigot Plugin Development' started by Lifeonblack, May 28, 2017.

  1. Hello so I have my furnace smelt event
    Code (Java):

    @EventHandler
        public void onBurn(FurnaceSmeltEvent e) {
            if(e.getResult() == null) {
                return;
            }
            if(e.getSource() == null) {
                return;
            }
            if(ca.getConfig2() == null) {
                return;
            }
            Set<String> sets = ca.getConfig2().getKeys(false);
            for(String set : sets) {
                if(e.getSource().equals(ca.getConfig2().getItemStack(set + ".Input"))) {
                   System.out.println("equals");
                    e.setResult(ca.getConfig2().getItemStack(set + ".Product"));
                    System.out.println("created");
                    return;
                }
                System.out.println("cancelled");
               e.setCancelled(true);
                return;
            }
        }
    I wanted to check if the itemstack is equals to the itemstack in config if so the product will be created from inputted materials, but for some reason if I put Itemstack with item meta it does not read or perhaps it does not for every set when it comes to furnace?
     
  2. Try the #isSimilar() method inside of ItemStack
     
  3. on the second section in config it does not work nothing happens even I changed.
     
  4. Show me your configs and your code that has the #getItemStack() method in it.
     
  5. Have you tried broadcasting both itemstacks as a string to see the difference between them? Your saved one may not have item meta where as that one does for example.


    On a side not you can change this
    Code (Text):

            if(e.getResult() == null) {
                return;
            }
            if(e.getSource() == null) {
                return;
            }
            if(ca.getConfig2() == null) {
                return;
            }
     
    to
    Code (Text):

            if(e.getResult() == null || e.getSource() == null || ca.getConfig2() == null)
                return;
     
     
  6. Code (Java):
    // the code is posted but this is a sample data
    flower:
      Input:
        ==: org.bukkit.inventory.ItemStack
        type: LONG_GRASS
        damage: 1
        meta:
          ==: ItemMeta
          meta-type: UNSPECIFIC
          display-name: Trash
      Product:
        ==: org.bukkit.inventory.ItemStack
        type: DOUBLE_PLANT
        damage: 4
      Enabled: true
      Type: Furnace

    it won't change anything

    as I see that my problem is for loop does not work with furnace smelt event,
    so is there an event where you are just placing itemstacks?
     
  7. Your for loop should work. Add some debug print statements. For example, add a print statement printing out each key inside of your config within your for loop.
     
  8. that is what I did so I said it does not check for every section in the config after the input smelt. haven't you check the code I sent? it has a bunch of debug statements.
     
  9. Could you give yourself those items in your config using the #getItemStack() method to verify that the items are correct?
     
  10. yes it is correct as what I said before it works but the rest of the section don't so I have the hunch that for loop is not working with smelt event
    only the first section works.
     
  11. So at one point String set is equal to "flower", correct?
     
  12. yes but didn't get other strings as I said the rest of the config section.
     
  13. Elaborate on what you mean by "didn't get other strings"
     
  14. I already elaborate rest of the config section it means there was another string aside from flower example flower2 flower3 even though there is an for loop it didn't get the string.
     
  15. Well if your source item does not equal the input item of the first iterated ItemStack in your config, the for loop terminates.

    Remove the code after the if block inside of your for loop then run your code.
     
  16. =_= you really didn't get what I am saying it is equal as I said the rest of the config section didn't get the string simply said the loop terminated

    for example flower is on the first section it seems equal and created successfully

    second flower2 is not working already so I tried to delete flower and then flower2 works perfectly so it means they are equal and the loop terminated already so I have a hunch it is going to be insane to use for loop with this case of config in furnace smelt so I am trying to gather some help.
     
  17. I really don't think you get what I'm saying. You don't need to cancel the event and come out of the for loop if the initial check fails, that's why flower2 doesn't work when flower exists in the config.
     
  18. I fixed it already it has nothing to do with the problem since it is for loop it may get the value of others that will make the statement false if comparing itemstack to the config so I didn't tend to use setCancelled(true); instead I used setResult to null. thanks for help anyway.
     
  19. No problem. I'm happy you solved your problem