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

Why does that not work

Comments in 'Plugin Development' started by Tim // robske Büba, Dec 18, 2015.

  1. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    PHP:
    /**
      * @param BlockBreakEvent $event
      */
      
    public function onPlayerBreakBlock(BlockBreakEvent $event){
      if (
    $event->getBlock()->getID() == Item::SIGN || $event->getBlock()->getID() == Item::WALL_SIGN || $event->getBlock()->getID() == Item::SIGN_POST) {
      
    $signt $event->getBlock();
      if ((
    $tile $signt->getLevel()->getTile($signt))){
      if(
    $tile instanceof Sign) {
      if(
    strtolower(trim($signt->getLine(0))) == "status" || strtolower(trim($signt->getLine(0))) == "[status]"){
      if (
    $event->getBlock()->getX() == $this->sign->getNested("sign.x") || $event->getBlock()->getY() == $this->sign->getNested("sign.y") || $event->getBlock()->getZ() == $this->sign->getNested("sign.z")) {
      if(
    $event->getPlayer()->hasPermission("signstatus.break")) {
      
    $this->sign->setNested("sign.x"$event->getBlock()->getX());
      
    $this->sign->setNested("sign.y"$event->getBlock()->getY());
      
    $this->sign->setNested("sign.z"$event->getBlock()->getZ());
      
    $this->sign->setNested("sign.enabled"false);
      
    $this->sign->setNested("sign.level""world");
      
    $this->sign->save();
      
    $this->sign->reload();
      
    $event->getPlayer()->sendMessage($this->prefix.$this->translation->get("sign_destroyed"));
      }else{
      
    $event->getPlayer()->sendMessage($this->prefix.$this->translation->get("sign_no_perms"));
      
    $event->setCancelled();
      }
      }
      }
      }
      }
      }
      }
    Error: Call to undefined method pocketmine\block\WallSign::getLine()
    The error is on if(strtolower(trim($signt->getLine(0))) == "status" || strtolower(trim($signt->getLine(0))) == "[status]"){
  2. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    $signt must be a tile, so use
    PHP:
    $this->getServer()->getLevelByName("level")->getTile(new Vector3($event->getBlock()->getX(), $event->getBlock()->getY(), $event->getBlock()->getZ()));
    Last edited: Dec 18, 2015
  3. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Who told you to use Server::getInstance()??
  4. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    Now it's
    Fatal error: Call to undefined method pocketmine\tile\Sign::getLine() in G:\Daten_Schnell\Tim\PocketServerTest\plugins\SignStatusV2.2.1-FIXload9099\src\SignStatus\SignStatus.php on line 145
  5. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    OK
  6. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    Fatal error: Call to undefined method pocketmine\tile\Sign::getLine() in G:\Daten_Schnell\Tim\PocketServerTest\plugins\SignStatusV2.2.1-FIXload9099\src\SignStatus\SignStatus.php on line 145
    when using
    it as tile
  7. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    PHP:
    $text Sign::getText();
    $text[0]; // Line1 etc.
    Tim // robske Büba likes this.
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Why do you search a level by name while you already have the level object from the block?
    hoyinm14mc and CraftYourBukkit like this.
  9. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    PHP:
      public function onPlayerBreakBlock(BlockBreakEvent $event){
      if (
    $event->getBlock()->getID() == Item::SIGN || $event->getBlock()->getID() == Item::WALL_SIGN || $event->getBlock()->getID() == Item::SIGN_POST) {
      
    $signt $event->getBlock();
      if ((
    $tile $signt->getLevel()->getTile($signt))){
      if(
    $tile instanceof Sign) {
      if(
    strtolower(trim($signt->getLevel()->getTile($signt)->getText(0))) == "status" || strtolower(trim($signt->getLevel()->getTile($signt)->getText(0))) == "[status]"){
      if (
    $event->getBlock()->getX() == $this->sign->getNested("sign.x") || $event->getBlock()->getY() == $this->sign->getNested("sign.y") || $event->getBlock()->getZ() == $this->sign->getNested("sign.z")) {
      if(
    $event->getPlayer()->hasPermission("signstatus.break")) {
      
    $this->sign->setNested("sign.x"$event->getBlock()->getX());
      
    $this->sign->setNested("sign.y"$event->getBlock()->getY());
      
    $this->sign->setNested("sign.z"$event->getBlock()->getZ());
      
    $this->sign->setNested("sign.enabled"false);
      
    $this->sign->setNested("sign.level""world");
      
    $this->sign->save();
      
    $this->sign->reload();
      
    $event->getPlayer()->sendMessage($this->prefix.$this->translation->get("sign_destroyed"));
      }else{
      
    $event->getPlayer()->sendMessage($this->prefix.$this->translation->get("sign_no_perms"));
      
    $event->setCancelled();
      }
      }
      }
      }
      }
      }
      }
    That doesn't work, too:
    2015-12-19 [08:32:26] [CRITICAL]: "Could not pass event 'pocketmine\event\block\BlockBreakEvent' to 'SignStatus v2.1': trim() expects parameter 1 to be string, array given on SignStatus\SignStatus
    2015-12-19 [08:32:26] [WARNING]: InvalidArgumentException: "trim() expects parameter 1 to be string, array given" (E_WARNING) in "/SignStatusV2.2.2/src/SignStatus/SignStatus" at line 145
  10. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    Still need help here...
  11. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Sign::getText() returns an array, you can't do Sign::getText(0)! Learn something about arrays.
    Vaivez66 and hoyinm14mc like this.
  12. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    Did never understand arrays
    Can anyone show me a code of that if function?
  13. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    I did show you a code, and you liked it.
  14. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    HTTPS://PHP.net/arrays
    CraftYourBukkit and hoyinm14mc like this.
  15. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Excuse me:
    1. What sense are you trying to make? It is the return value not the parameter that is array. The function has void parameters.
    2. Block::Sign? Excuse me, are you speaking in PHP?
    Vaivez66 likes this.
  16. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    That code still still not works...
    I am getting more and more confused...
  17. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    What code do you use now?
  18. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    That:
    PHP:
      /**
      * @param BlockBreakEvent $event
      */
      
    public function onPlayerBreakBlock(BlockBreakEvent $event){
      if (
    $event->getBlock()->getID() == Item::SIGN || $event->getBlock()->getID() == Item::WALL_SIGN || $event->getBlock()->getID() == Item::SIGN_POST) {
      
    $signt $event->getBlock();
      if ((
    $tile $signt->getLevel()->getTile($signt))){
      if(
    $tile instanceof Sign) {
      if(
    strtolower(trim($signt->getLevel()->getTile($signt)->getText(0))) == "status" || strtolower(trim($signt->getLevel()->getTile($signt)->getText(0))) == "[status]"){
      if (
    $event->getBlock()->getX() == $this->sign->getNested("sign.x") || $event->getBlock()->getY() == $this->sign->getNested("sign.y") || $event->getBlock()->getZ() == $this->sign->getNested("sign.z")) {
      if(
    $event->getPlayer()->hasPermission("signstatus.break")) {
      
    $this->sign->setNested("sign.x"$event->getBlock()->getX());
      
    $this->sign->setNested("sign.y"$event->getBlock()->getY());
      
    $this->sign->setNested("sign.z"$event->getBlock()->getZ());
      
    $this->sign->setNested("sign.enabled"false);
      
    $this->sign->setNested("sign.level""world");
      
    $this->sign->save();
      
    $this->sign->reload();
      
    $event->getPlayer()->sendMessage($this->prefix.$this->translation->get("sign_destroyed"));
      }else{
      
    $event->getPlayer()->sendMessage($this->prefix.$this->translation->get("sign_no_perms"));
      
    $event->setCancelled();
      }
      }
      }
      }
      }
      }
      }
    It crashes...
  19. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Did you even read my code and my reply?!
  20. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    so $text[0] holds the contents of the line1 on sign?

Share This Page

Advertisement