Yep, I'd do it like that. How about cancelling PlayerInteractEvent when a player taps on an item frame?
For Player events Code: $player = $event->getPlayer(); $level = $player->getLevel(); For Entity events: Code: $entity = $event->getEntity(); $level = $entity->getLevel(); Also check how pocketmine uses it...
Yes, but protector plugins doesn't protect the Item Frames... I tried doing that, but that doesn't work. If it's impossible to stop the breaking-animation, what shall I do then? I saw on BuildMCPE around 5 months ago that it had an Item Frame protection. I tried getting out the item, but I can't – which Item Frame protector did they use? Or did they use one?
sorry to randomly jump into this chat (im bored) 1. The animation has no relationship with wheather the item drops or not. 2. Just cancel BlockBreak and PlayerInteract Event when the player interacts with a ItemFrame
It will work if you are using a pmmp version >= this commit: https://github.com/pmmp/PocketMine-MP/commit/11f35d28c2f58e4db4189d9038be5e97e3d5edf3
Code: [Server thread/CRITICAL]: ReflectionException: "Class ExtraProtector\BlockBreakEvent does not exist" (EXCEPTION) in "/src/pocketmine/plugin/PluginManager" at line 723 PHP: public function onBreak(BlockBreakEvent $event) { $block = $event->getPlayer(); $player = $event->getPlayer(); $level = $player->getLevel(); if($level->getName() === "Shopp") { if($block->getId() === 389 || $block->getId() === 102) { $event->setCancelled(); } } } Fix?
Oh, it's still popping out of the Item Frame. Sometimes it's a bit slow and I can easily take the Item out. What can I do? I think I saw I still better Item Frame protection...
Item frames don't call BlockBreakEvent when the item gets removed, did you even look at the commit link I sent? It calls PlayerInteractEvent, you may take a look at the code used in "Tests" here...
OK, is there anything wrong in my code here? I used BlockBreakEvent and PlayerInteractEvent for both blocks (Glass Panes and ItemFrames, just to be sure that both blocks are 'protected'): PHP: public function onTouch(PlayerInteractEvent $event) { $block = $event->getPlayer(); $player = $event->getPlayer(); $level = $player->getLevel(); if($level->getName() === "Shopp") { if($block->getId() === 389 || $block->getId() === 102) { $event->setCancelled(); } }} public function onBreak(\pocketmine\event\block\BlockBreakEvent $event) { $block = $event->getPlayer(); $player = $event->getPlayer(); $level = $player->getLevel(); if($level->getName() === "Shopp") { if($block->getId() === 389 || $block->getId() === 102) { $event->setCancelled(); } }}
PHP: $block->getId() === 389 // This is bad$block->getId() === 102 // This is bad Why? What if the id's change? Better use PHP: $block->getId() === Item::ITEM_FRAME$block->getId() === Item::GLASS_PANEL Easier to read and you don't have to lookup the id.
Since when is a player a block? Maybe you should learn how to debug your plugin! PHP: echovar_dump Learn how to use PHP before writing a plugin.
I can still take out the item! Plus, that mistake was a silly and stupid one, I didn't see it... PHP: public function onTouch(PlayerInteractEvent $event) { $block = $event->getBlock(); $player = $event->getPlayer(); $level = $player->getLevel(); if($level->getName() === "Shopp") { if($block->getId() === Item::ITEM_FRAME || $block->getId() === Item::GLASS_PANE) { $event->setCancelled(); } } } public function onBreak(\pocketmine\event\block\BlockBreakEvent $event) { $block = $event->getBlock(); $player = $event->getPlayer(); $level = $player->getLevel(); if($level->getName() === "Shopp") { if($block->getId() === Item::ITEM_FRAME || $block->getId() === Item::GLASS_PANE) { $event->setCancelled(); } } }
Do some research on item IDs vs block IDs (not being rude, though I might sound so). At times, item IDs aren't the same as their block IDs (this goes for most of the tile blocks such as Cauldrons, Enchantment tables, Brewing Stands...) PHP: //function onTouch()if($block->getId() === Block::ITEM_FRAME_BLOCK || $block->getId() === ITEM::GLASS_PANE){ $event->setCancelled();}