Problem with BlockDispenseEvent

Discussion in 'Plugin Development' started by ZephaniahNoah, Oct 1, 2017.

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

    ZephaniahNoah

    My code:
    Code:
    @org.bukkit.event.EventHandler(priority=EventPriority.HIGHEST)
    public void BlockDispense(BlockDispenseEvent e){
        System.out.println("DISPENSED");
        Block block = e.getBlock();
        final Dispenser dispenser = (Dispenser)block.getState();
    
        e.setItem(new ItemStack(Material.BARRIER));
        ItemStack itm = dispenser.getInventory().getItem(4);
        System.out.println(itm);
    }
    I set it to dispense barriers to not touch any of the items inside. So I can activate the dispenser as many times as I want and the contents won't change. Good. That's what I want. Now I need to read the dispenser's contents so I can modify it. But there is a problem...

    When I put 13 crafting tables in the middle the console says,
    [22:31:07 INFO]: DISPENSED
    [22:31:07 INFO]: ItemStack{WORKBENCH x 12}

    No matter how many times I activate the dispenser it says there are 12 even though I looked back and there were still 13.

    And when I put one in it says,
    [22:32:29 INFO]: DISPENSED
    [22:32:29 INFO]: null


    How am I supposed to change the contents properly if I can't read what's inside?
     
  2. Offline

    Minesuchtiiii

    Have you tried looping trough the contents of the dispenser and printing them out?
     
  3. Offline

    timtower Administrator Administrator Moderator

    @ZephaniahNoah Print the type and amount yourself, don't use the full itemstack in the println
     
  4. Offline

    ZephaniahNoah

    Yes.
    Show Spoiler
    [17:43:03 INFO]: SEARCHED SLOT0
    [17:43:03 INFO]: null
    [17:43:03 INFO]: SEARCHED SLOT1
    [17:43:03 INFO]: null
    [17:43:03 INFO]: SEARCHED SLOT2
    [17:43:03 INFO]: null
    [17:43:03 INFO]: SEARCHED SLOT3
    [17:43:03 INFO]: null
    [17:43:03 INFO]: SEARCHED SLOT4
    [17:43:03 INFO]: ItemStack{WORKBENCH x 12}
    [17:43:03 INFO]: SEARCHED SLOT5
    [17:43:03 INFO]: null
    [17:43:03 INFO]: SEARCHED SLOT6
    [17:43:03 INFO]: null
    [17:43:03 INFO]: SEARCHED SLOT7
    [17:43:03 INFO]: null
    [17:43:03 INFO]: SEARCHED SLOT8
    [17:43:03 INFO]: null
    Ok I'll try that.
    EDIT: Same thing,
    [17:18:13 INFO]: WORKBENCH 12
     
    Last edited: Oct 2, 2017
  5. Offline

    ipodtouch0218

    I'm guessing that the BlockDispenseEvent removes the item before canceling, and adds it back after.
     
Thread Status:
Not open for further replies.

Share This Page