It gives me this error: http://i.cubeupload.com/OFWvCo.png What is wrong here? PHP: <?phpnamespace ExtraProtector;use pocketmine\event\Listener;use pocketmine\Player;use pocketmine\plugin\PluginBase;use pocketmine\Server;use pocketmine\event\player\PlayerInteractEvent;use pocketmine\event\entity\EntityDamageEvent;use pocketmine\level\Level;class Main extends PluginBase implements Listener { public function onEnable() { $this->getServer()->getPluginManager()->registerEvents($this, $this); } public function onInteract(PlayerInteractEvent $event) { // I don't want players go break and touch the Glass Pane in front of the ItemFrame, that they cannot get the item out of it. $player = $event->getPlayer(); $block = $event->getBlock(); $level = $event->getLevel(); if($block->getId() === "102" && $level->getName() === "Shopp") { if(!$player->hasPermission("breakshop")) { $event->setCancelled(); } } } public function onDamage(EntityDamageEvent $event) { // I need to do this because my iProtector plugin doesn't allow me to set god mode on. $player = $event->getPlayer(); $level = $event->getLevel(); if($player instanceof Player) { if($level->getName() === "Plots" || $level->getName() === "Contest-Plots" || $level->getName() === "Roleplay") { $event->setCancelled(); } } }}
Why are you checking if $event->getPlayer() is an instance of a Player? Read the function name. The only thing it can return is a player object.
Please look at pocketmine's source code and learn the API before you attempt making plugins. Learning PHP would be a plus as well, if you knew PHP (you obviously don't) you would realize that "Error: call to undefined method" means that the method you are trying to call DOESN'T exist. #ReadTheDocs #LearnPHP
@ImagicalGamer I know what that error means, but I don't know why he says "unknown function" on the getPlayer() function. @TheDiamondYT But I don't think removing the "is instanceof" will fix the error...
EntityDamageEvent doesn't have a getPlayer function. It has a getEntity() function to get the entity that's being damaged. If you want the attacker, you have to check if the event is instanceof EntityDamageByEntityEvent. After that check if $event->getDamage instanceof Player.
I tried touching a Glass Pane Block, but the event doesn't get cancelled, there's still the breaking animation (before the blocks really gets broken). How can I stop people doing that? On another server, the player is in Adventure Mode, but cannot "touch" blocks. I tried switching to Adventure Mode on my server, but I can still "touch" blocks. Maybe there's a PlayerTouchEvent? Then I can cancel that?
Use this. PHP: <?phpnamespace ExtraProtector;use pocketmine\event\Listener;use pocketmine\Player;use pocketmine\plugin\PluginBase;use pocketmine\Server;use pocketmine\event\player\PlayerInteractEvent;use pocketmine\event\entity\EntityDamageEvent;use pocketmine\level\Level;class Main extends PluginBase implements Listener { public function onEnable() { $this->getServer()->getPluginManager()->registerEvents($this, $this); } public function onInteract(PlayerInteractEvent $event) { // I don't want players go break and touch the Glass Pane in front of the ItemFrame, that they cannot get the item out of it. $player = $event->getPlayer(); $block = $event->getBlock(); $level = $player->getLevel(); if($block->getId() == "102" && $level->getName() == "Shopp") { if(!$player->hasPermission("breakshop")) { $event->setCancelled(); } } } public function onDamage(EntityDamageEvent $event) { // I need to do this because my iProtector plugin doesn't allow me to set god mode on. $player = $event->getPlayer(); $level = $player->getLevel(); if($level->getName() == "Plots" || $level->getName() == "Contest-Plots" || $level->getName() == "Roleplay") { $event->setCancelled(); } }}
Change the PlayerInteractEvent to BlockBreakEvent if you don't want players to break a block and EntityDamageEvent doesn't have getPlayer() function, instead it has getEntity()!
Will it also stop the breaking "animation"? I want it to stop that too, or players can still get out the items.
That means, it is impossible to stop the person from touching? But it must be possible, I saw a server that blocks people from getting out the item of an Item Frame.
The problem is, that after the breaking-animation the Glass Pane disappears for 0.2 secs – this time can sometimes can be enough to take out the item of the Item Frame. This sounds complicated to stop, but I need to fix this, or all the items will be gone soon.