Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Block Events??

Comments in 'Plugin Development' started by DC4CODE, Mar 4, 2016.

  1. DC4CODE
    Offline

    DC4CODE Active Member

    Joined:
    Nov 19, 2015
    Posts:
    64
    Minecraft User:
    dxdsc9349
    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?
  2. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    BlockPlaceEvent, if the block($e->getBlock()->getId()) is the block(Block::whatever) (or use instanceof without getId()), then do something
    applqpak likes this.
  3. DC4CODE
    Offline

    DC4CODE Active Member

    Joined:
    Nov 19, 2015
    Posts:
    64
    Minecraft User:
    dxdsc9349
    Are you still there??
    can you make a piece of code that detected a user who places down TNT, then
    kicks them???
  4. DC4CODE
    Offline

    DC4CODE Active Member

    Joined:
    Nov 19, 2015
    Posts:
    64
    Minecraft User:
    dxdsc9349
    Sorry i am VERY NEW to plugin development i made my first plugin 2 days ago.. :D
  5. Survingo
    Offline

    Survingo Active Member

    Joined:
    Dec 6, 2015
    Posts:
    221
    PHP:
    public function onBlockPlace(BlockPlaceEvent $e){
            if (
    $block->getBlock()->getId(46)) {getPlayer(Player::kick)
        }
    }
    For reason add
    PHP:
    $reason "Do not place TNT!")
    Last edited: Mar 4, 2016
  6. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    402
    Plugins:
    2
    What is this? Java?
    applqpak likes this.
  7. applqpak
    Offline

    applqpak Active Member Plugin Developer

    Joined:
    Dec 16, 2015
    Posts:
    284
    Plugins:
    1
    Minecraft User:
    applqpak
    What. The...
    jojoe77777 likes this.
  8. DC4CODE
    Offline

    DC4CODE Active Member

    Joined:
    Nov 19, 2015
    Posts:
    64
    Minecraft User:
    dxdsc9349
    I am going to run this I'll be back with the testing results. P.S i am making a AntiGreafing plugin :D
  9. DC4CODE
    Offline

    DC4CODE Active Member

    Joined:
    Nov 19, 2015
    Posts:
    64
    Minecraft User:
    dxdsc9349
    What I've got so far:


    PHP:
    <?php

    namespace 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 $senderCommand $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;
        }
    }
    Last edited by a moderator: Mar 7, 2016
  10. DC4CODE
    Offline

    DC4CODE Active Member

    Joined:
    Nov 19, 2015
    Posts:
    64
    Minecraft User:
    dxdsc9349
    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
  11. applqpak
    Offline

    applqpak Active Member Plugin Developer

    Joined:
    Dec 16, 2015
    Posts:
    284
    Plugins:
    1
    Minecraft User:
    applqpak
    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!");
  12. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    402
    Plugins:
    2
    It should be
    PHP:
    $ExecuteAction 'say ' $e->getPlayer() . ' tried to place a block of TNT!';
    Remember, this is PHP, not Java (or other)
    applqpak likes this.
  13. applqpak
    Offline

    applqpak Active Member Plugin Developer

    Joined:
    Dec 16, 2015
    Posts:
    284
    Plugins:
    1
    Minecraft User:
    applqpak
    Do NOT use whatever codes @Survingo says, they are severely incorrect. That's why you're getting errors.
    Oneeb likes this.
  14. applqpak
    Offline

    applqpak Active Member Plugin Developer

    Joined:
    Dec 16, 2015
    Posts:
    284
    Plugins:
    1
    Minecraft User:
    applqpak
    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!';
    Vaivez66 likes this.
  15. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    402
    Plugins:
    2
    I completely forgot about that :D
    applqpak likes this.
  16. applqpak
    Offline

    applqpak Active Member Plugin Developer

    Joined:
    Dec 16, 2015
    Posts:
    284
    Plugins:
    1
    Minecraft User:
    applqpak
    No worries :)
    Vaivez66 likes this.
  17. DC4CODE
    Offline

    DC4CODE Active Member

    Joined:
    Nov 19, 2015
    Posts:
    64
    Minecraft User:
    dxdsc9349
    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?
  18. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    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
    applqpak likes this.
  19. jasonwynn10
    Offline

    jasonwynn10 Active Member

    Joined:
    Dec 20, 2015
    Posts:
    87
    Minecraft User:
    jasonwynn10
    he makes a valid point...
    applqpak likes this.
  20. DC4CODE
    Offline

    DC4CODE Active Member

    Joined:
    Nov 19, 2015
    Posts:
    64
    Minecraft User:
    dxdsc9349
    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.
    Smarticles101 and Falk like this.

Share This Page

Advertisement