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

How do it correctly?

Comments in 'Plugin Development' started by Primus, Jul 3, 2015.

  1. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,472
    Minecraft User:
    PrimusLV
    What i am trying to do is: execute code when step on specified block.
    I want to get that block from config:

    Config:
    Code:
    block: GLOWING_OBSIDIAN
    
    Currently using this!
    PHP:
    if($blockId->getId() === Block::GLOWING_OBSIDIAN){
    But needs this (Does'nt work)
    PHP:
    if($blockId->getId() === Block::$this->getConfig()->get('block')){
  2. Guillaume351
    Offline

    Guillaume351 Active Member Plugin Developer

    Joined:
    Oct 11, 2013
    Posts:
    150
    Plugins:
    1
    Minecraft User:
    Guillaume351
    Because in the config it's a string, you can't use this. Why not put the ID in the config ?
    iksaku likes this.
  3. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,472
    Minecraft User:
    PrimusLV
    Fatal error: Access to undeclared static property: pocketmine\block\Block::$this in /home/primus/Pocketmine/plugins/BlockHeat_v2.0.0/src/Primus/Main.php on line 48
  4. Guillaume351
    Offline

    Guillaume351 Active Member Plugin Developer

    Joined:
    Oct 11, 2013
    Posts:
    150
    Plugins:
    1
    Minecraft User:
    Guillaume351
    If you put ID in config, remove Block:: and use == instead of ===
  5. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    What is fromString?
    Get a ?? from a string?
  6. luca28pet
    Offline

    luca28pet Active Member

    Joined:
    Feb 20, 2014
    Posts:
    251
    Minecraft User:
    luca28pet
    I would do:
    PHP:
    if($block->getId() === constant("Block::"$this->getConfig()->get("block"))){
    Guillaume351 and Primus like this.
  7. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,472
    Minecraft User:
    PrimusLV
    Yup fixed.
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    No, use === and cast config value to int.
    CrazedMiner and HotFireyDeath like this.
  9. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    No. Aliases aren't compiled into strings.
    PHP:
    $path Block::class . "::" strtoupper($this->getConfig()->get("block") );
    if(
    defiene($path)) {
      
    // do spemtiong
    }
    HotFireyDeath likes this.

Share This Page

Advertisement