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

checking

Discussion in 'Development' started by DogTheBlock, May 23, 2017.

  1. DogTheBlock

    DogTheBlock Spider Jockey

    Messages:
    29
    is their anyway to check if a player is in Creative Mode? this code doesn't work
    PHP:
        public function preventPlace(BlockPlaceEvent $event){
            
    $player $event->getPlayer();
            
    $bedrock Item::get(701);
            if(
    $player->getInventory()->getItemInHand()->getId() === 7){
                
    $event->setCancelled(true);
                
    $player->sendMessage(" §l§cTheVortex §7>> §r§f§4Your not allowed to use Bedrock!");
            }
            if(
    $player->getId() === 46 and $player->isCreative() === true){
                
    $event->setCancelled(true);
                
    $player->sendMessage(" §l§cTheVortex §7>> §r§f§4Your not allowed to use TNT in Creative!");
            }
        }
     
  2. Marabou

    Marabou Baby Zombie

    Messages:
    137
    GitHub:
    wiligangster
    $player->isCreative === true and $player->getId() === 46 WTF ?
    Just use

    if($player->getGamemode () == 1 and $event->getBlock()->getId() === 46){
     
    DogTheBlock and Michael like this.
  3. Michael

    Michael Baby Zombie

    Messages:
    113
    GitHub:
    michaelm04
    $player->isCreative() will work, the "=== true" also isn't needed. Where you put "if($player->getId() == X" did you mean "if($event->getBlock()->getId() == X"? $player->getId() will return the entity id of the player in the world. $event->getBlock()->getId() will return the id of the block the player is attempting to place.

    Edit:
    Sorry, whenever I started composing my message you hadn't posted yours yet.
     
    Last edited: May 23, 2017
  4. DogTheBlock

    DogTheBlock Spider Jockey

    Messages:
    29
    thanks
     
  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.