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

sendTo();

Comments in 'Plugin Development' started by LDX, Jan 11, 2014.

  1. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,397
    Plugins:
    14
    Goes against the typical rules, but I have no other choice. I have no pastebucket or what ever.

    # PocketMine-MP Error Dump Sat Jan 11 05:13:19 GMT 2014
    Error: array (
    'type' => 1,
    'message' => 'Call to a member function sendChat() on a non-object',
    'file' => '/mnt/sdcard/DroidPocketMine/plugins/ServerVote.php',
    'line' => 32,
    )

    Code:
    [23] console("[INFO] ServerVote Enabled!");
    [24] }
    [25] public function __destruct(){}
    [26] public function like($cmd,$args,$issuer) {
    [27] $configPath = $this->api->plugin->configPath($this);
    [28] $issuerlwr = strtolower($issuer->username);
    [29] $user = $issuer->username;
    [30] if(file_exists($configPath . $issuerlwr . ".txt")) {
    [31] $vote = file_get_contents($configPath . $issuerlwr . ".txt");
    [32] $issuer->sendChat("[ServerVote] You've already voted! (" . $vote . ")");
    [33] } else {
    [34] if(file_exists($configPath . "likes.txt")) {
    [35] $likes = file_get_contents($configPath . "likes.txt");
    [36] } else {
    [37] file_put_contents($configPath . "likes.txt","0");
    [38] $likes = "0";
    [39] }
    [40] $likes++;
    [41] file_put_contents($configPath . "likes.txt",$likes);
    [42] file_put_contents($configPath . $issuerlwr . ".txt","like");
  2. SuperChipsLP
    Offline

    SuperChipsLP Active Member Plugin Developer

    Joined:
    Sep 15, 2013
    Posts:
    204
    Plugins:
    5
    Minecraft User:
    Redmol
    I also have an issue with sendChat()...

    I got this:

    PHP:
    public function aFunction(){

            foreach(
    $this->api->player->getAll as $p){

                    
    $p->sendChat("Test");

    }
    }
    None of the online users recieve the message...
  3. SuperChipsLP
    Offline

    SuperChipsLP Active Member Plugin Developer

    Joined:
    Sep 15, 2013
    Posts:
    204
    Plugins:
    5
    Minecraft User:
    Redmol
    It seems there is an issue with sendChat in the latest Dev-Builds...
    LDX likes this.
  4. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,397
    Plugins:
    14
    WTH?? I'VE SPENT 5 HOURS TRYING TO DEBUG THIS.
  5. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,397
    Plugins:
    14
    (Not directed at anyone is specific.)
  6. Exxarion
    Offline

    Exxarion Active Member Plugin Developer

    Joined:
    Jan 5, 2014
    Posts:
    242
    Plugins:
    1
    Minecraft User:
    Notch
    PHP:
    public function send($issuer){

    $username $issuer->username;
    $this->api->chat->sendTo(false"IM TESTING THIS!");
    Try that
  7. DA_Swagnemite
    Offline

    DA_Swagnemite Notable Member Plugin Developer

    Joined:
    Nov 17, 2013
    Posts:
    386
    Plugins:
    7
    Minecraft User:
    DA_SWAGNEMITE
    Use this instead of $issuer->sendChat:
    PHP:
    $output "Message";
    return 
    $output;
    This will send it to either the console or the player issuing the command and shouldn't cause any errors or crashes.
    If you still get errors let me know and I'll see what I can do.
    LDX likes this.
  8. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,397
    Plugins:
    14
    @shoghicp helped me. I was using the command from the console and console isn't an object. XD
    PEMapModder and Comedyman937 like this.
  9. Exxarion
    Offline

    Exxarion Active Member Plugin Developer

    Joined:
    Jan 5, 2014
    Posts:
    242
    Plugins:
    1
    Minecraft User:
    Notch
    XD
    PEMapModder likes this.
  10. DA_Swagnemite
    Offline

    DA_Swagnemite Notable Member Plugin Developer

    Joined:
    Nov 17, 2013
    Posts:
    386
    Plugins:
    7
    Minecraft User:
    DA_SWAGNEMITE
    Lol well at least you figured out what you needed ;)
  11. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,397
    Plugins:
    14
    TOPIC CLOSED
  12. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    @Falk I am too lazy to find the thread, but UrbanDictionary has the same problem too. UrbanDictionary does not work with console either.
  13. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,397
    Plugins:
    14
    I can fix it. XD
  14. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    I think it is because getAll should be getAll()
  15. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,397
    Plugins:
    14
  16. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Anyway I know the topic is closed, but I think @LDX is very likely to forget about RCON.
    Therefore use "return" is better.
  17. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,397
    Plugins:
    14
    @Falk, here you go! I even updated it for API 11. XD

    Attached Files:

    PEMapModder likes this.
  18. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,397
    Plugins:
    14
    Define RCON past an abr. for remote control.
  19. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Some even better method: return
    PHP:
    <?php
    /*
    __PocketMine Plugin__
    name=UrbanDictionary
    description=Just because :-)
    version=0.2
    author=Falkirks
    class=UrbanDict
    apiversion=11
    */
    class UrbanDict implements Plugin{
    private 
    $api;
    public function 
    __construct(ServerAPI $api$server false){
    $this->api $api;
    }

    public function 
    init(){

    $this->api->console->register("ud""Look up urban dictionary", array($this"command"));
    }

    public function 
    __destruct(){}

    public function 
    command($cmd$params$issuer$alias$args$issuer){
    $term implode("%20"$params);
    $resp json_decode(file_get_contents("http://api.urbandictionary.com/v0/define?term=" $term))->list[0]->definition;
    $newtext wordwrap($resp35"<br>");
    //$newtext = explode("<br>", $newtext);
    // Console fixed by LDX
    /*if($issuer == "console") {
    console("---Definition---");
    foreach ($newtext as $item) {
      console($item);
    }
    } else {
    $issuer->sendChat("---Definition---");
    foreach($newtext as $item) {
      $issuer->sendChat($item);
    }
    }
    */
    //even better using return fixed by PEMapModder
    str_replace("<br>","\n",$newText);
    return 
    $newText;
    }
    }
    ?>
  20. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,397
    Plugins:
    14
    I can't see that. Code areas don't work right on mobile.

Share This Page

Advertisement