Inventory update & sign update question

Discussion in 'Plugin Development' started by darknesschaos, Feb 20, 2011.

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

    darknesschaos

    This is a two parter.

    1) how could I update a sign after changing it's text via plugin?

    2)How could I update the player's inventory after changing it via plugin? Currently what I need people to do is open a chest after the change for players to see the changes.
     
  2. Offline

    Edward Hand

    1) I haven't tested this - just looked through the server code and I think I've found the right method:

    Code:
    ((CraftWorld)yourWorld).getHandle().g(x,y,z)
    where x,y,z are the coordinates of your sign.
    --- merged: Feb 20, 2011 2:46 PM ---
    and x,y,z should be of type int, so you might need to cast them.
     
  3. Offline

    darknesschaos

    and what about inventories?
    --- merged: Feb 21, 2011 3:03 AM ---
    thanks for all of the help.
    --- merged: Feb 21, 2011 3:24 AM ---
    the sign update code works great, thanks!
     
  4. Offline

    Edward Hand

    Oh! I feel a bit silly for missing this:

    There's an update function on all CraftSigns and CraftChests which should do the trick. (Make sure to cast them to the CraftBukkit equivalent because it doesn't exist on standard Signs and Chests)
     
  5. Offline

    darknesschaos

    what about player inventories?
     
  6. Offline

    Edward Hand

    I can't see a bukkit method for doing it.
    Give this a try:
    Code:
    ((CraftPlayer)thePlayer).getHandle().activeContainer.a()
     
  7. Offline

    darknesschaos

    will do, btw where do you find this information?
     
  8. Offline

    Edward Hand

    The caftbukkit source (decompiled and imported into eclipse for easy searching)
    I just found the packet for updating inventory slots, looked down the function call hierarchy until I found something that looked promising.
     
  9. Offline

    Zeroth

    There is an Player.updateInventory() method I think, but its deprecated.
    I recently had a similar problem where I wanted certain inventory items to be removed when a player right-clicked a special block, but that didn't work like you've figured out. For some reason a left click will update the inventory though!
    Try using a BlockDamageEvent and the statement:
    event.getDamageLevel().equals(BlockDamageLevel.STARTED)
    Which registers as a left click.
     
  10. Offline

    nossr50

    player.updateInventory() its deprecated, but it will do what you need it to
     
  11. Offline

    SteveE104

    I get errors in eclipse when I try this. I'm I missing something I need to import, or do I need the CraftBukkit source as well?
     
  12. Offline

    Edward Hand

    You need the CraftBukkit source too, yes.
     
  13. Offline

    SteveE104

    Ok, thanks. Turns out I don't need to use this anyways, but maybe in the future.
     
  14. Offline

    Nohup

    Just for future reference, you won't need the source per se, just the jar and add it to your referenced libraries.

    If you do need the source, as it is very handy to dig through at times, it can be found at:

    Bukkit Source
    CraftBukkit Source

    You can download the source there without having to decompile, and this also includes the pom files so you can look at any dependency definitions you may need as well.
     
  15. Offline

    SteveE104

    Hey! I just found a use for this! I put it in a for loop with a Thread.sleep delay, and it works, but I get a server overloaded warning.
     
  16. Offline

    Nohup

    Sounds like you have a synchronous sleep going on, basically blocking on the server. What code are you looping?
     
Thread Status:
Not open for further replies.

Share This Page