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

Warn plugin

Comments in 'Plugin Development' started by Tim // robske Büba, Feb 8, 2016.

  1. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    I'm stuck here
    Code:
    PHP:
            switch($command->getName())
            {
                case 
    "warn":
                if(isset(
    $args[2]))
                {
                    if(
    $this->getServer()->getPlayer($args[0]) instanceof Player)
                    {
                        
    $PlayerName $this->getServer()->getPlayer($args[0])->getName();
                        if(
    $this->warnsys->get($PlayerName == true))
                        {
                            
    //Now what?
                        
    }
                        else
                        {
                            
    $reasonsArray = array($args[1] => $args[2]);
                            
    $this->warnsys->set($PlayerName$reasonsArray);
                            
    $this->warnsys->save();
                        }
                        
    $tempMsgS "Der Spieler '".$PlayerName."' wurde mit dem Grund '".$args[1]."' mit ".$args[2]." Punkten gewarnt! Er hat insgesamt "."TODO"." Punkte.";
                        
    $tempMsgToP TF::RED."\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n DU WURDEST VON '".$sender->getName()."' MIT DEM GRUND '".$args[1]."' mit ".$args[2]." PUNKTEN GEWARNT! DU HAST "."TODO"." PUNKTE! MIT 10 PUNKTEN WIRST DU GEBANNT!";
                        
    $args[0]->getPlayer()->sendMessage($tempMsgToP);
                        
    $this->sendMsgToSender($sender$tempMsgS);
                    }
                }
                else
                {return 
    false;}     
            return 
    true;
            break;
    Some additional explanation:
    TF = TextFormat
    sendMsgToSender is an function made by me (It does send an msg to the player or the console)
    $this->warnsys is an instance of Config

    Ok, this is plugin should do:
    /warn <PlayerName> <Reason> <Warning-Points>
    It already can save that for ONE TIME
    But then the next time what should i do that i can have unlimited Reason-Points arrays per player?
    (//Now what?) in the code
    Last edited: Feb 8, 2016
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Before everything else, if($args[0]->getPlayer() instanceof Player) wtf is this?
  3. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    $this->getServer()->getPlayer($args[0])
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    $this->warnsys->get($PlayerName == true)

    I suppose you misplaced == true?
    Also, == true is as good as nothing. You can omit that.

    Now, would you mind telling us what $this->warnsys is about?
  5. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    Read my post please
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Yes, I saw. But you didn't explain the structure in your Config.
    HotFireyDeath likes this.
  7. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    The structure is only written by the code above
  8. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    Ok, it appears no one is understanding what i want to code and what my code does...
    What I want to code:
    Player executes /warn Player7373 Do_not_grief! 1
    and /warn Player7373 Do_not_grief_again! 3
    The warnsys.yml should now look like this:

    PHP:
    Player7373:
      
    "Do_not_grief!":
      - 
    1
      
    "Do_not_grief_again!":
      - 
    3
    The code I have written so far is only able to store one reason and point pack per player
    (For the code look above)
    For more info please read the initial post again!
  9. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    I need to so sth with Config::setNested()
  10. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    No one wants to help me?
  11. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    Bumping thread.
  12. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Explain what this line is supposed to do?

    PHP:
    if($this->warnsys->get($PlayerName == true))
    Now, I would just do it like this. I won't even make an if-else.

    PHP:
    $array $this->warnsys->get($playerName, []); // return an empty array if the player has no previous warnings
    $array[$args[1]] = $args[2];
    $this->warnsys->set($playerName$array);
    Vaivez66 likes this.
  13. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    Thanks!
    I have to learn so much...
    Will recode that tomorrow :)

Share This Page

Advertisement