PlayerDropItemEvent & ItemSpawnEvent Listeners don't recognize every event

Discussion in 'Plugin Development' started by Regenwurm97, Jun 16, 2015.

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

    Regenwurm97

    Hey there!

    Sorry if this problem is already known - I've just been off from bukkit for some months and I'm not fully updated by now :D

    My problem is, that I have a listener for PlayerDropItemEvent or ItemSpawnEvent, but the listener sometimes skips some Events / the EventHandler method isn't always called.
    This happens especially often in case the server already has some work to do and you press your drop button faster. My question: Is there any way to solve this? I need to get all itemstacks the player drops but of course this doesn't work as long as bukkit doesn't recognize every time you drop something.

    Thx! Cedi
     
  2. Offline

    Zombie_Striker

    @Regenwurm97
    • Make a runnable (set it to either 2L or 5L)
    • Loop through all players
    • get their inventory and compare it to what it was be.
    • Loop through all entities in the world
    • Check for if its an DroppedItemEntitiy (I think it's called this)
    • If it is, get the itemstack and see if it's the same as what the player has lost.
    • If it is the same ItemStack as the one the player lost, remove that entitiy and give him back the itemstack.
     
  3. Offline

    Regenwurm97

    Um alright but this solution is a bit heavy I think for the server...
    Isn't there a better solution? :)
     
  4. Offline

    Zombie_Striker

    @Regenwurm97
    You said events don't always work on your server, so this is the only way the does not use events.
     
  5. Offline

    Konato_K

    @Regenwurm97 Are you using a different version of CraftBukkit or something? It works fine for me for thousands of items being drop per second.
     
  6. Offline

    Zombie_Striker

    @Konato_K @Regenwurm97
    Same here, but if it doesn't work for with with events, runnables would be the only way.
     
  7. Offline

    Regenwurm97

    @Konato_K @Zombie_Striker
    I've been struggling with this problem for several Versions now, I think since 1.6.4...
    I'm really not quite sure why this actually happens. Although, I have to say that I'm always testing on my localhost server, which means that I'm playing on the same PC my server runs on. maybe that's a problem?

    The same Thing happens with PlayerInteractionEvent btw. So when I click too frequently, some clicks are simply ignored :S

    In my case, when you drop an item the item is removed and a new itemstack with exactly the same Details (amoung, data, whatever...) is spawned. And the problem is that some of the items you drop simply become lost instead of new ones dropping (otherwise I would not end up with 58 items after having dropped 64 lol)
     
  8. Offline

    Konato_K

    @Regenwurm97 Ah, I think I know what the problem is, when you spawn multiple items in a row of the same type they "merge" into a single Item entity, this may be the issue, considering this then the problem is in the way you're comparing the items, try to just take care of the Material of the ItemStack rather than comparing the whole ItemStack (or basically, ignoring quantity)
     
  9. Offline

    Regenwurm97

    @Konato_K
    Thanks for your advice. I already thought about the thing with item merging but this isn't the Problem. It's actually a bug within bukkit itself i think by now. I quickly programmed a q-Spammer bot to find out if its a Problem of my PC or bukkit. Everything works totally fine and all drop Events are corrently recognized, as long as you are not in gamemode 1 and drop the items out of your opened inventory (so in inventory view). When this is the case (so gamemode 1 and directly out of the opened inventory view via q) then some Events get lost!

    Well, I'm glad my plugin is used under gamemode 0 conditions :D
     
Thread Status:
Not open for further replies.

Share This Page