Disable cooking food in furnaces

Discussion in 'Plugin Development' started by Regenwurm97, Apr 12, 2013.

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

    Regenwurm97

    Yo guys,

    I wondered how to disable the guys on my server from cooking their general food in furnaces as I use a special plugin for cooking food at barbeque places...

    Well, I first tried the "FurnaceSmeltEvent" but it doesn't really work for me. The FurnaceSmeltEvent always gets active when an item has been completely cooked...
    I'd need something that prevents the Users from putting raw food inside the furnaces.

    Also found this but dont know how to use it ...
    http://jd.bukkit.org/rb/doxygen/d1/d1c/interfaceorg_1_1bukkit_1_1inventory_1_1FurnaceInventory.html

    Maybe you can help me with this?
     
  2. Offline

    macguy8

    Regenwurm97
    I think you'd be able to use InventoryClickEvent, check if it's to a furnace, from their inv, and the ItemStack is food. Then, cancel the event
     
  3. Offline

    randomizer1234

    You should listen to InventoryClickEvent and check if it consists in a player putting fuel (or whatever you want to check) in a furnace, and in that case cancel it :)
    EDIT: some seconds late ahahah
     
  4. Offline

    macguy8

  5. Shift+Clicking in your inventory on food would also put it in furnace.

    It would be easier if you'd just remove the recipes in your onEnable()... use Bukkit.recipeIterator() to iterate through recipes, check if it's instanceof FurnaceRecipe, cast and then check ingredient if it's food, if it is then use iterator.remove().
     
  6. Offline

    Regenwurm97

    Wow these are very good options :)

    Well, think I'll use Digi's because I really want to be sure users are not able to cook food
    But the inventory click event could be very interesting for some other things I'm doing at the moment ;)

    Thx guys, really helped me!

    Hey again...

    Well, seems as I couldn't really get anything to my scripts yet...
    Sry but I cant really understand your way of solution...never worked with anything comparable ;)

    Code:
    if(Bukkit.recipeIterator() instanceof FurnaceRecipe) {
                    Bukkit.recipeIterator().remove();
                   
                }
    SO this is the veeeery basic layout...what do I have to do now?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  7. This is how iterators work:
    Code:
    Iterator<TypeHere> it = iteratorClassHere (e.g. Bukkit.recipeIterator() )
    
    for(it.hasNext())
    {
        TypeHere var = it.next(); // make sure you call this once and store it, otherwise it will keep going to the next one every time you call it.
    
        // do stuff (like if(var instanceof FurnaceRecipe) )
    
        it.remove(); // remove the current element
    }
     
  8. Offline

    Regenwurm97

    Ok after some time with trying arround with it i finally got it to work :) Thx

    It would also be interesting for me to know what the Iterator actually is... is it like a hashmap or an array...or how are things beeing saved inside of these?
     
  9. It's Java related, google its documentation to find out more :p
     
Thread Status:
Not open for further replies.

Share This Page