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

Need help with an Code.

Comments in 'Plugin Development' started by M4nt0s, May 3, 2016.

  1. M4nt0s
    Offline

    M4nt0s Active Member

    Joined:
    Sep 15, 2015
    Posts:
    49
    Minecraft User:
    M4nt0s
    When a player walk on a block, it habe to activate an command.

    How to code it?
  2. korado531m7
    Offline

    korado531m7 Active Member

    Joined:
    Apr 4, 2015
    Posts:
    158
    Minecraft User:
    korado531m7
    PHP:
    function onMove(PlayerMoveEvent $ev){
        
    $player $ev->getPlayer();
        if(
    $player->getLevel()->getBlock(new Vector3($player->x,$player->y,$player->z)->getId() === Block::STONE){
            
    $this->getServer()->dispatchCommand($player,"say Player on the Stone");
    }
  3. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Won't work as it will return block from player's feet position. And there is no need to construct new Vector3 instance as Player already extends it.
    PHP:
    /**
     * @param \pocketmine\event\player\PlayerMoveEvent $e
     * @priority MONITOR
     * @ignoreCancelled false
     */
    public function onPlayerMove(PlayerMoveEvent $e){
        if(
    $e->getPlayer()->getLevel()->getBlockIdAt($e->getPlayer()->subtract(01)) === Block::STONE){
            
    // Server::dispatchCommand() is a bad practice
        
    }
    }
    Last edited: May 3, 2016
    korado531m7 and Survingo like this.
  4. M4nt0s
    Offline

    M4nt0s Active Member

    Joined:
    Sep 15, 2015
    Posts:
    49
    Minecraft User:
    M4nt0s
    Thanks. Very helpful. I have to use pocketmine\PlayerMoveEvent something else?
  5. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    +1 Like would be appreciated :p

    Look at code which I edited.
    Survingo likes this.
  6. M4nt0s
    Offline

    M4nt0s Active Member

    Joined:
    Sep 15, 2015
    Posts:
    49
    Minecraft User:
    M4nt0s
    Ok, NICE.
  7. _Neisufek_
    Offline

    _Neisufek_ New Member

    Joined:
    Apr 17, 2016
    Posts:
    16
    Minecraft User:
    xNaisu
    Don't use PlayerMoveEvent, it will check every player's movement, which is more work for the server. Use RepeatingTask to check if somebody is standing on stone.
  8. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Well that's exactly what I do when creating plugins (SpecialBlock) but as he asked me for simple code, I gave him one.
    ImagicalGamer likes this.
  9. M4nt0s
    Offline

    M4nt0s Active Member

    Joined:
    Sep 15, 2015
    Posts:
    49
    Minecraft User:
    M4nt0s
    Whaz is that for an Error. What I did wrong?

    Attached Files:

  10. Survingo
    Offline

    Survingo Active Member

    Joined:
    Dec 6, 2015
    Posts:
    221
    You're not using Pocketmine, that did you wrong
  11. M4nt0s
    Offline

    M4nt0s Active Member

    Joined:
    Sep 15, 2015
    Posts:
    49
    Minecraft User:
    M4nt0s
    Now i done it right. But now it don't find the Main class. What i have to chance? In the main.php? or where.
  12. HotFireyDeath
    Offline

    HotFireyDeath Notable Member Plugin Developer

    Joined:
    Mar 19, 2015
    Posts:
    328
    Plugins:
    1
    Minecraft User:
    HotFireyDeath
    Make sure that in the plugin.yml file, the 'Main' value is set to your Main class's namespace.
  13. Survingo
    Offline

    Survingo Active Member

    Joined:
    Dec 6, 2015
    Posts:
    221
    He's not using pocketmine
    ok
  14. M4nt0s
    Offline

    M4nt0s Active Member

    Joined:
    Sep 15, 2015
    Posts:
    49
    Minecraft User:
    M4nt0s
    Here! Show yourself. plugin.yml and main.php

    Attached Files:

  15. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Notice: This is PocketMine forum.

    Following issues found:
    • Plugin hasn't registered any listener
    • Functions onEnable(), onLoad() and onDisable() not found (It's not necessary but it's good to use them e.g. register listener onEnable())
    • Plugin doesn't contain any valid listener class
    • ClassNotFoundException on line 13 (Solution: Import \pocketmine\block\Block)
    • Syntax error on line 4
    • Unused import on line 5, 6, 7, 8.
    • (plugin.yml) Main class not found: You have to use backslash (\) instead of forward (/) for namespaces
    • Main class' file has to be same as class' name
    And show us your project tree.
    HotFireyDeath likes this.
  16. M4nt0s
    Offline

    M4nt0s Active Member

    Joined:
    Sep 15, 2015
    Posts:
    49
    Minecraft User:
    M4nt0s

    Attached Files:

Share This Page

Advertisement