1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

BlockPlaceEvent

Discussion in 'Development' started by Teamblocket, May 3, 2017.

  1. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    hey , so am making this crate key plugin which has a bunch of features but theirs one error i can't seem to fix , when the player doesn't have op and places a crate chest the placement cancels but the message doesn't send. heres my code
    PHP:
    public function cratePlace(BlockPlaceEvent $event){
        
    $player $event->getPlayer();
        
    $block $event->getBlock();
            if(
    $block->getId() == 146 and $player->isOp()){
             
    $event->setCancelled(false);
                
    $player->sendMessage(" TheVortex >> Crate Chest placed!");
            } else {
                
    $player->sendMessage(" TheVortex >> Your not allowed to place a Crate Chest!");
                
    $event->setCancelled(true);
                    return;
            }
        }
     
  2. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    That formatting was seriously triggering my OCD...
    PHP:
    public function cratePlace(BlockPlaceEvent $event){
        
    $player $event->getPlayer();
        
    $block $event->getBlock();
        if(
    $block->getId() === 146 and $player->isOp()){ // try using a permission instead of checking for OP
            
    $player->sendMessage(" TheVortex >> Crate Chest placed!");
            
    $event->setCancelled(false);
        } else {
            
    $player->sendMessage(" TheVortex >> You're not allowed to place a Crate Chest!");
            
    $event->setCancelled(true);
        }
        return;
    }
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.