Forcing a Chest to close OR updating inventory

Discussion in 'Plugin Development' started by Zeroth, Feb 16, 2011.

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

    Zeroth

    Hey guys, I'm starting a new plugin (my first) and I've just got a question.

    Is it possible to close a Chest on someone; AKA take them out of the inventory screen?
    The reason I ask is because I'm having trouble getting removed items from the inventory to update. My goal is to remove all of a certain type of material from a player inventory when they right click a special block. Well I got that much down, but as I learned, the inventory still shows the items are there.
    My work around for this was to make the block you click on a chest. This does work, but I want the chest to instantly close if the items are removed.

    Is there either a way to force close the chest or (preferably) just update the inventory on item removal?
     
  2. Offline

    fullwall

    inventory.update(). But be careful - it's deprecated, so fix it up when the proper fix is made available.
     
  3. Offline

    Zeroth

    Any idea on how to enable deprecated methods? I couldn't find an inventory.update, but I did find player.updateInventory() which is deprecated.

    Here's another idea: What if I go through the inventory of the player and replace each slot that has, for instance, ironore with air. Would that update properly instead of just removing the items from the inventory?

    Code:
    SEVERE: Could not pass event BLOCK_RIGHTCLICKED to Infinimod
    java.lang.NoSuchMethodError: org.bukkit.entity.Player.updateInventory()V
        at com.bukkit.zeroth.Infinimod.InfinimodBlockListener.onBlockRightClick(InfinimodBlockListener.java:53)
        at org.bukkit.plugin.java.JavaPluginLoader.callEvent(JavaPluginLoader.java:170)
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:201)
        at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:450)
        at net.minecraft.server.Packet15Place.a(SourceFile:57)
        at net.minecraft.server.NetworkManager.a(SourceFile:232)
        at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:65)
        at net.minecraft.server.NetworkListenThread.a(SourceFile:104)
        at net.minecraft.server.MinecraftServer.h(MinecraftServer.java:261)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:197)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:512)
    
    --- merged: Feb 18, 2011 2:36 AM ---
    Never mind, I found an alternate solution!
    Instead of a right click, I check for left clicks by using a BlockDamageEvent. For some reason, that updates the inventory.
     
  4. Offline

    fullwall

    It is player.updateInventory().
     
  5. Offline

    Zeroth

    Right, I tried that, but bukkit throws noSuchMethod errors!

    Anyway, I figured out a way using left-click:
    event.getDamageLevel().equals(BlockDamageLevel.STARTED)
     
Thread Status:
Not open for further replies.

Share This Page