Hello, I'm creating a give-kit with PlayerInteractEvent I realized that the function is repeated several times. Is it a bug or am I doing something wrong? PHP: public function onInteract(PlayerInteractEvent $event) {$event->getPlayer()->getInventory()->addItem(Item::get(30,0));}
can you explain more? when player interacts with something it will give that item with id 30, that is what i see in your code.. how it should really work for you?
is because you have to identify what you need to interact, there are several modes of interaction in this event and it must be why you receive 5 times the same item, another way would be by adding an array and blocking from receiving the item more than once
try to see if your error occurs on Item::get, maybe you forgot some part of the function: https://github.com/pmmp/PocketMine-...dfe4a6359e4/src/pocketmine/item/Item.php#L100
Yes it's a bug because the game doesn't provide a legitimate way for servers to find out whether the player right clicked a block.
Make a delay for the event to the player that has right clicked a block OR disable all right click block interact events that are being runned from the same player in a 100ms window(So the event runs once, and after that it gets ignored)(This doesn't fully work because a player can just look at air and look at blocks back and it counts as another interaction) You can't fully counter it because Mojang did a /f*** all EDIT: OH WAIT! This thread is 2 months old? Bruh
PHP: switch(mt_rand(1, 5)){ case 5: $event->setCancelled(false); break; default: $event->setCancelled(); break;}