Hey guys. I have coded a something for my server and PlayerInteractEvent seems not to be working. It does not send any errors to console. Here is the code: PHP: public function execute(CommandSender $player, string $label, array $args) { if(!($player instanceof Player)) { $player->sendMessage("Please use this command in-game"); return true; } $gem = Item::get(399, 101, 1); $gem->setCustomName(TF::RESET . TF::AQUA . "Ancient" . TF::GRAY . " Gem"); $player->getInventory()->addItem($gem); } public function onInteract(PlayerInteractEvent $event){ $player = $event->getPlayer(); $item = $event->getItem(); $damage = $item->getDamage(); $ls = CustomEnchants::getEnchantment(100); switch ($damage) { case 101: $gem = Item::get(399, 101, 1); $sword = Item::get(276, 0, 1); $sword->addEnchantment(new CustomEnchants($ls, 1)); $things = [$sword]; $rand = mt_rand(0, 1); $player->getInventory()->addItem($things[$rand]); $player->getInventory()->removeItem($gem); break; } return true; }} When i hold the gem and tap the ground, it doesnt work. If anyone can help me, thank you.
I'm going to take great pleasure breaking this code in the future, because you hardcoded all the item IDs.
Why did someone put like on this post ^ ? This code breaks, unwanted behaviour occurs, to be exact, if Mojang decides to change item ids or you're adding the string ids to pocketmine, which I didn't consider as possibility when writing that post. If not, then method can't deny user input as it has no way to tell(as of now) if that input value came from constant.
This is exactly my point. I've been warning people for months there's going to be armageddon because I'm gunning for item magic numbers, and everyone is hardcoding them.
I have considered some ways to sabotage this kind of code (yes, there are ways), but it would be nice if people would just ... not hardcode them.