You can use the PlayerMoveEvent and check if the player is standing on grass: PHP: public function onMove(PlayerMoveEvent $event) { $player = $event->getPlayer(); $blockunderneath = $this->getLevel()->getServer()->getBlock($player->subtract(0, 1, 0)); if($blockunderneath->getId() === 2) { $player->sendMessage("Message here"); }}
PHP: if($item->getId() == 369 && $item->getCustomName() == "TRAP"){$player->sendMessage("You step on traps!");}
Just write a code to set blocks as traps: PHP: public $trapblocks = [];public function onInteract(PlayerInteractEvent $event) { $block = $event->getBlock(); $this->trapblocks[] = $block->getX() . ":" . $block->getY() . ":" . $block->getZ() . ":" . $block->getLevel()->getName(); // saves the block's position to an array $sender->sendMessage("Set block as trap!");}public function onMove(PlayerMoveEvent $event) { $player = $event->getPlayer(); $block = $this->getLevel()->getServer()->getBlock($player->subtract(0, 1, 0)); // gets block player's standing on if(in_array($block->getX() . ":" . $block->getY() . ":" . $block->getZ() . ":" . $block->getLevel()->getName(), $this->trapblocks)) { $player->sendMessage("You stepped on a trap!"); }}
Thanks but im planning to give a player a specific block with a CustomName for traps. Is it possible to detect when player step on a block with a CustomName? If not i'll make it using the code you gave
I'm not sure if it's possible, but I think there's a way with NBT. I don't know anything about NBT (and don't even know what NBT is...), I cannot help you. I would just save the block to an array and check if the player is standing on a block marked as a trap.
Wait, do blocks even have custom names? Maybe your item has a custom name, but once you place the block, the item name shouldn't exist anymore.
Checking PMMP source verifies this, Block::getName() returns the actual name of the block or "Unknown" if it doesn't have a fallback name.
The fallbackName field is not used anywhere. In particular, Grass->getName() always returns "Grass". So unless you are working on custom block types, custom names won't help you at all.