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

Why doesn't this plugin work?

Comments in 'Plugin Development' started by myst02, May 17, 2015.

  1. myst02
    Offline

    myst02 Active Member

    Joined:
    Mar 23, 2015
    Posts:
    97
    Minecraft User:
    myst02
    Hello,

    I'm totally new to plugin coding and wrote my first plugin.
    It should teleport you to PVP world at specific position if [PVP] is on the sign, but only if there are not more than 2 players in PVP world.
    It just doesn't work, no error, nothing!

    My code:
    Code:
    <?php
    
    namespace kjjnetwork\TwinPVP;
    
    use pocketmine\plugin\PluginBase;
    use pocketmine\event\Listener;
    use pocketmine\Server;
    use pocketmine\command\Command;
    use pocketmine\command\CommandSender;
    use pocketmine\event\player\PlayerInteractEvent;
    use pocketmine\math\Vector3;
    use pocketmine\tile\Sign;
    use pocketmine\event\block\SignChangeEvent;
    use pocketmine\level\Position;
    use pocketmine\entity\Entity;
    use pocketmine\event\block\BlockPlaceEvent;
    use pocketmine\event\block\BlockBreakEvent;
    use pocketmine\item\Item;
    use pocketmine\tile\Tile;
    
    class Main extends PluginBase implements Listener{
      private $api, $server, $path;
    
      public function onEnable(){
      $this->getServer()->getPluginManager()->registerEvents($this, $this);
      }
    
      public function playerBlockTouch(PlayerInteractEvent $event){
      if($event->getBlock()->getID() == 323 || $event->getBlock()->getID() == 63 || $event->getBlock()->getID() == 68){
      $sign = $event->getPlayer()->getLevel()->getTile($event->getBlock());
      if(!($sign instanceof Sign)){
      return;
      }
      $sign = $sign->getText();
      $players = $event->getPlayer("PVP");
      $x = "107";
      $y = "76";
      $z = "128";
      if($sign[0]=='[PVP]'){
      if($players > 2 !== true){
      if(Server::getInstance()->loadLevel("PVP") != false){
      $event->getPlayer()->sendMessage("[server] teleporting you to arena...");
      $event->getPlayer()->teleport(new Position($x, $y, $z, $this->getServer()->getLevelByName("PVP")));
     
      }else{
      $event->getPlayer()->sendMessage("[server] There are already two people in the arena!");
      }
      }
      }
      }
      }
    }
    
    Please help me
    Thanks in advance!
  2. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    Do you get any errors?
    (Next time please use code instead of spoiler to write your codes :p)
  3. myst02
    Offline

    myst02 Active Member

    Joined:
    Mar 23, 2015
    Posts:
    97
    Minecraft User:
    myst02
    Yes, I looked into logs:

    2015-05-17 07:07:18 [NOTICE] ClassCastException: "Object of class pocketmine\Player could not be converted to int" (E_NOTICE) in "/TwinPVP/src/kjjnetwork/TwinPVP/Main" at line 41
    2015-05-17 07:07:18 [CRITICAL] Could not pass event pocketmine\event\player\PlayerInteractEvent to TwinPVP v0.105: Object of class pocketmine\Player could not be converted to int on kjjnetwork\TwinPVP\Main
  4. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    What!?
    $players = $event->getPlayer("PVP");
    You can't do this in this way. What did you want to do?
  5. myst02
    Offline

    myst02 Active Member

    Joined:
    Mar 23, 2015
    Posts:
    97
    Minecraft User:
    myst02
    I wanted to get all players from world PVP and if there are not more than 2 players teleport to PVP world.

    Thanks for your patience!

    Btw: LOVE MSpawns!
    EvolSoft and DunxandMinecraft like this.
  6. DunxandMinecraft
    Offline

    DunxandMinecraft Active Member

    Joined:
    Oct 26, 2014
    Posts:
    158
    Can I just say that sounds like a cool plugin you got there :)
  7. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    To count players in a world you can do:
    PHP:
    $count count($this->getServer()->getLevelByName("PVP")->getPlayers());
    Then
    PHP:
    if($count <= 2){
       
    //Do what you want
    }
  8. myst02
    Offline

    myst02 Active Member

    Joined:
    Mar 23, 2015
    Posts:
    97
    Minecraft User:
    myst02
    Thank you :)
    I am using that for special PVP mode where only 2 players can fight together.
  9. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    You are welcome :)
  10. DunxandMinecraft
    Offline

    DunxandMinecraft Active Member

    Joined:
    Oct 26, 2014
    Posts:
    158
    Could I also use this plugin but edit it a bit for my HG Server?
  11. myst02
    Offline

    myst02 Active Member

    Joined:
    Mar 23, 2015
    Posts:
    97
    Minecraft User:
    myst02
    Did that, now it gives me error for that line :(

    2015-05-17 07:47:58 [CRITICAL] Could not pass event pocketmine\event\player\PlayerInteractEvent to TwinPVP v0.105: Undefined property: kjjnetwork\TwinPVP\Main::$plugin on kjjnetwork\TwinPVP\Main
    2015-05-17 07:47:58 [NOTICE] UndefinedPropertyException: "Undefined property: kjjnetwork\TwinPVP\Main::$plugin" (E_NOTICE) in "/TwinPVP/src/kjjnetwork/TwinPVP/Main" at line 35

    @DunxandMinecraft sure, you can use it :)
    I have a question: can you give me a few tips for writing a hunger games plugin per PM?
    I have a minigame server and would LOVE to offer HG too ;)
    Legoboy0215 likes this.
  12. DunxandMinecraft
    Offline

    DunxandMinecraft Active Member

    Joined:
    Oct 26, 2014
    Posts:
    158
    We can DM
  13. myst02
    Offline

    myst02 Active Member

    Joined:
    Mar 23, 2015
    Posts:
    97
    Minecraft User:
    myst02
    Anyone has a clue why this doesn't work?
    DunxandMinecraft likes this.
  14. DunxandMinecraft
    Offline

    DunxandMinecraft Active Member

    Joined:
    Oct 26, 2014
    Posts:
    158
    Nope, Sorry not me :(
  15. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    It is best to use: [spoiler][php]
  16. myst02
    Offline

    myst02 Active Member

    Joined:
    Mar 23, 2015
    Posts:
    97
    Minecraft User:
    myst02
  17. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    What I know is, learn plugin development and PHP properly. I don't understand how come you got the private $api there.
    Oh also block IDs are never greater than 255. I guess @onebone gave that bad practice.
  18. myst02
    Offline

    myst02 Active Member

    Joined:
    Mar 23, 2015
    Posts:
    97
    Minecraft User:
    myst02
    The teleport + private api part is from @leonchang99 SignPortal plugin.
    Why is SignPortal working then?
  19. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    I didn't say it brings errors. It is just useless.
    #Blame99leonchang
  20. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Wow, really? I was making an almost same plugin!
    Just it is 2v2, not 1v1.

Share This Page

Advertisement