How to make a command that only excecuted when you step on certain block?

Discussion in 'Development' started by AmalCraft, May 31, 2021.

  1. AmalCraft

    AmalCraft Creeper

    Messages:
    3
    The title of this thread has self-explanatory. I am making a city roleplay server and I need a plugin that the command can only execute- when you step on a certain block, its for robbery plugin so the player can only use /startrob when they step on the bank floor (example gold block)
     
  2. minijaham

    minijaham Zombie Pigman

    Messages:
    514
    GitHub:
    minijaham
    PHP:
    // onCommand
    $block $player->getLevel()->getBlock($player->subtract(010));
    if(
    $block->getId() !== Block::GOLD_BLOCK) { // I'm not sure if it's golden or just gold
           
    $player->sendMessage("You may not execute this command here.");
           return;
    }
     
    NTT and ErikX like this.
  3. ErikX

    ErikX Baby Zombie

    Messages:
    116
    GitHub:
    ErikPDev
    Don't forget to make sure the player is on the bank's region! Otherwise players can just create gold blocks and defeat the system.
    Example:
    PHP:
    $x = [100200];
    $y = [2050];
    $z = [100200];
    $minY min($y);
    $minZ min($z);
    $maxX max($x);
    $maxY max($y);
    $maxZ max($z);
    $pos $player->getPosition();
    if(
        
    $pos->>= $minX and $pos-><= $maxX and
        
    $pos->>= $minY and $pos-><= $maxY and
        
    $pos->>= $minZ and $pos-><= $maxZ
    ){
     
    // Player is inside the region
    }
     
    NTT and minijaham like this.
  4. minijaham

    minijaham Zombie Pigman

    Messages:
    514
    GitHub:
    minijaham
    A very nice addition! Yes. This is definitely necessary @AmalCraft
     
    ErikX likes this.

Share This Page

  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.