Solved Event for when an item is added to a user's inventory?

Discussion in 'Plugin Development' started by OffLuffy, Oct 30, 2014.

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

    OffLuffy

    Before this is misinterpreted, I don't mean when a user picks up a drop or places an item into their inventory!

    I'm looking for an event which is triggered when an item is added to a user's inventory, but not via the player's own actions, but rather more like when they receive an item via command, and it's inserted directly into their inventory (not necessarily dropped in front of them like vanilla spawn commands seem to do). Searched for this a bit, but only got events like the click events, and I'm not sure those will work. Maybe an InventoryModify event if one exists? JavaDocs are appreciated if this is a thing already!

    I ask because I want to dispatch a server command to give a player an item using the JSON data, then to listen to when they receive the item so I can handle the item further.

    Too complicated? I'm willing to listen to alternative ideas!

    What am I trying to do? I want to put a certain series of colored player heads on a players head as they enter an arena. The head textures are hosted on imgur. Using a post on reddit (yes I'm aware this isn't a future-proof method), my current idea is to dispatch a server command to give a user a head with one of these imgur skins on it, dependent on a color decided when they join an arena, then upon receiving the head, put it on their head. It takes a moment for it to presumably parse the fake UUID, so I'm not sure if a simple delayed event will suffice.

    I've considered using 'safe' player heads of actual Mojang accounts, but I haven't found a very complete or consistent set of colored heads corresponding to the 16 ChatColors (only colors, not the formats/magic), and it's somewhat important they correspond to the ChatColors. If you have a reliable list of these, I'd greatly appreciate it, would simplify what I'm doing considerably.

    I'm aware I can just color leather armor instead, but this is mostly experimental, and I'd just like to see if I can do it :D If this gets to be too complicated however, then I will likely do that. I was hoping to use player heads as I'm changing the name of the user via packets, and I'd rather not have random skins showing up, and the head covers the face better than a helmet. Very minor detail, but I'm a bit anal about those things at times.
     
  2. OffLuffy There is no event for this, couldn't you just use a delayed task?
     
  3. Offline

    OffLuffy

    Mentioned that a bit down: "It takes a moment for it to presumably parse the fake UUID, so I'm not sure if a simple delayed event will suffice."

    I'm not entirely sure what would be a safe delay to use to give the server time to parse the UUID, or if it has issues contacting the resolving server, if that'd cause additional issues. I suppose I could have a repeating task continuously check if the skull is there, but then I'd have to cancel it after some iterations to make sure it didn't loop indefinitely.
     
  4. OffLuffy From what I understand you're saying that when adding the item to the inventory, it takes some time before the item actually appears? If I'm right in that, then there wouldn't be another solution. An event would be fired when the instruction to add an item to the inventory occurs, not when it's actually added.

    As it currently stands, your checking idea may or may not work. The server may think that the item is there, even if it doesn't appear so to the client... I'm still not sure why exactly you need to wait for the head to appear in the inventory, though.
     
    OffLuffy likes this.
  5. Offline

    OffLuffy

    Thanks. I had suspected that may be the case (in the event that it's a client-side delay rather than server side). If that is the case, then I can likely still handle the item and place it on the player's head before it displays for the player. Maybe if there's even a short delay on it.
     
Thread Status:
Not open for further replies.

Share This Page