I am making a plugin and I need some help... Is there a piece of code that can detect if someone places a specific block?
BlockPlaceEvent, if the block($e->getBlock()->getId()) is the block(Block::whatever) (or use instanceof without getId()), then do something
Are you still there?? can you make a piece of code that detected a user who places down TNT, then kicks them???
PHP: public function onBlockPlace(BlockPlaceEvent $e){ if ($block->getBlock()->getId(46)) {getPlayer(Player::kick) }} For reason add PHP: ( $reason = "Do not place TNT!")
What I've got so far: PHP: <?phpnamespace dc4code\cfxs;use pocketmine\plugin\PluginBase;use pocketmine\command\Command;use pocketmine\command\CommandSender;use pocketmine\command\ConsoleCommandSender;use pocketmine\event\block\BlockPlaceEvent;use pocketmine\Player;class cfxs extends PluginBase { public function onEnable(){ $this->getLogger()->info("HelpME Enabled"); return true; } public function onLoad(){ $this->getLogger()->info("HelpME Loaded Properly."); } public function onCommand(CommandSender $sender, Command $command, $label, array $args){ switch($command->getName()){ case "cfxsv": if($sender instanceof Player){ $sender->sendMessage("CFX Security Software Version 1.0.2 Build Register. #112SGND"); return true; } else{ $sender->sendMessage("This command only works in-game."); } } } public function onBlockPlace(BlockPlaceEvent $e){ if ($block->getBlock()->getId(46)) {getPlayer(Player::kick) $ExecuteAction = "say " + $player + " Tried to place a block of TNT!"; $this->getServer()->dispatchCommand(new ConsoleCommandSender(),$ExecuteAction); }} public function onDisable(){ $this->getLogger()->info("HelpME Disabled."); return true; }}
Awww my PHP Inspection results returned this: Classpath Inspection result: Passed Info Main class scanned: dc4code\cfxs\cfxs Main class file found at src/dc4code/cfxs/cfxs.php Bad practice Inspection result: Passed Syntax errors Inspection result: Error Errors PHP Parse error: syntax error, unexpected '$ExecuteAction' (T_VARIABLE) in /var/www/tmp/5/cfxs_v1.0.0/src/dc4code/cfxs/cfxs.php on line 43 Errors parsing /var/www/tmp/5/cfxs_v1.0.0/src/dc4code/cfxs/cfxs.php Info 0 good PHP file(s) and 1 bad PHP file(s) found. Checked with PHP 7.0.3-3+deb.sury.org~trusty+1
1. You can use [ PHP ] [/ PHP ] tags. 2. You don't need return true; in the onDisable and onEnable functions. 3. Dispatching Commands is bad practice, maybe try something like: PHP: $this->getServer()->broadcastMessage("Message!");
It should be PHP: $ExecuteAction = 'say ' . $e->getPlayer() . ' tried to place a block of TNT!'; Remember, this is PHP, not Java (or other)
Do NOT use whatever codes @Survingo says, they are severely incorrect. That's why you're getting errors.
Also, this would still crash because you're echoing a Player object, it should be: PHP: $ExecuteAction = 'say ' . $e->getPlayer()->getName() . ' tried to place a block of TNT!';
So... can I have a piece of code that detected if the player placed TNT, then Deopps them Puts them in Game mode Survival Warns the console Then kicks the person who placed TNT?
Why don't you just block TNT? And: What if they aren't OP and what if they are in Survival Mode? Then that wouldn't make sense
You Guys don't understand..... this is so i can learn PHP i dont really care of the other methods out there. I'm just trying to make a plugin. Thats it.