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. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Do you know about arrays? The Sign looks like this:
    Code:
    [Hello]
    I am
    Line3
    Click me!
    The whole text of the sign is saved as an array. As you (mostly) count from 0 in IT, an array does that too. So, the array of the sign looks like this:
    Code:
    array(
      0 => "[Hello]",
      1 => "I am",
      2 => "Line3",
      3 => "Click me!"
    );
    PHP:
    $text Sign::getText();

    $line1 $text[0];
    As written in the squared brackets, you want to get the content of "0" in the array, which would return you "[Hello]".
  2. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    Now tried out this:
    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) {
      
    $text Sign::getText();
      if (
    $text[0] == "Status" || $text[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();
      }
      }
      }
      }
      }
      }
      }
    }
    Still does throw this:
    "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 [19:38:27] [WARNING]: InvalidArgumentException: "trim() expects parameter 1 to be string, array given" (E_WARNING) in "/SignStatusV2.2.2/src/SignStatus/SignStatus" at line 145
  3. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    First of all, there's no trim() in your code you showed us, the problem isn't in there. But please, just go and learn PHP.. You don't even know how to implement my code(Sign::getText()). Go and learn, then come back.
  4. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    Understood. Adding fake SOLVED now
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Please use the nonstatic method call syntax if you are writing code rather than speaking in English.
  6. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    Ah, that's why on the last code it says deprectaed function

Share This Page

Advertisement