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

2 questions

Comments in 'Plugin Development' started by JonsMC, Sep 2, 2016.

  1. JonsMC
    Offline

    JonsMC Active Member

    Joined:
    Jul 26, 2016
    Posts:
    107
    Minecraft User:
    JonsMC
    i have some questions that need to be answer :p :

    1. how can i send to player all the vaules in an array as a list that i defined in my config?
    2. i created a task that send popup to players when they join, but i want to disable it for certain players, how would i do it?
  2. xBeastMode
    Offline

    xBeastMode Active Member

    Joined:
    Nov 27, 2015
    Posts:
    292
    1. Send what? {message, packet, love, kiss} or what?
    2. Who/what is "certain players"?
  3. JonsMC
    Offline

    JonsMC Active Member

    Joined:
    Jul 26, 2016
    Posts:
    107
    Minecraft User:
    JonsMC
    1. Send a list, example sending vaules in array Page:
    Page:
    1: ..
    2: ..

    2. Example: sending popup to all players except Steve, cause he used /disablepopup, and that command is an example command either :p
  4. xBeastMode
    Offline

    xBeastMode Active Member

    Joined:
    Nov 27, 2015
    Posts:
    292
    1. That still doesn't answer my question. What is "a list", use a specific word instead of "a list".

    2. This is an example, so don't copy and paste, then later come back saying it didn't work.

    PHP:
    //main class

    public $popup = [];
    //On command enable pop-up
    $this->popup[$sender->getName] = $sender;
    //On command disable pop-up
    if(isset($this->popup[$sender->getName())){
    unset(
    $this->popup[$sender->getName()]);
    }

    //onRun task
    foreach($this->getOwner()->popup as $name => $player){
    if(
    $player !== Null and $player InstanceOf Player){
    $player->sendTip("Tip enabled");
    }else{
    unset(
    $this->getOwner()->popup[$player]);
    }
    }



  5. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    From EconomyAPI Topmoney command
    PHP:
    $page array_shift($params);
        
         
    $moneyData $this->getPlugin()->getAllMoney();
        
         
    $server Server::getInstance();
         
    $banList $server->getNameBans(); // TODO TopMoney Command
         
    arsort($moneyData["money"]);
         
    $n 1;
         
    $max ceil((count($moneyData["money"]) - count($banList->getEntries()) - ($this->getPlugin()->getConfigurationValue("add-op-at-rank") ? count($server->getOPs()->getAll()))) / 5);
         
    $page max(1$page);
         
    $page min($max$page);
         
    $page = (int)$page;
        
         
    $output "- Showing top money list ($page of $max) -\n";
         
    $message = ($this->getPlugin()->getMessage("topmoney-format"$sender->getName(), array("%1""%2""%3""%4"))."\n");
        
         foreach(
    $moneyData["money"] as $player => $money){
           if(
    $banList->isBanned($player)) continue;
           if(
    $server->isOp(strtolower($player)) and ($this->getPlugin()->getConfigurationValue("add-op-at-rank") === false)) continue;
           
    $current = (int)ceil($n 5);
           if(
    $current === $page){
             
    $output .= str_replace(array("%1""%2""%3"), array($n$player$money), $message);
           }elseif(
    $current $page){
             break;
           }
           ++
    $n;
         }
         
    $sender->sendMessage($output);
    Or if its just 1 page
    PHP:
    $player->sendMessage("Page:\n".implode('\n',$yourArray));
  6. JonsMC
    Offline

    JonsMC Active Member

    Joined:
    Jul 26, 2016
    Posts:
    107
    Minecraft User:
    JonsMC
    Can you explain the foreach line? :p dont know what $name => $player mean :p
  7. Muqsit
    Offline

    Muqsit Active Member

    Joined:
    Sep 9, 2015
    Posts:
    175
    Minecraft User:
    Muqsit
    For (2):
    PHP:
    foreach($server->getOnlinePlayers() as $p){
    $dontSend = array("muqsit","jdjjdiwi");
    $name strtolower($p->getName());
    if(!
    in_array($name$dontSend)) $p->sendMessage("Hi, ....");
    }

    /*
    *
    * in_array() is the fastest way.
    * $x = array("name1","name2","name3");
    * $name = strtolower($p->getName());
    * if(in_array($name, $x)) //if $name is in array $x.
    *
    */
  8. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    1. use implode();
    PHP:
    $array = ["Steve""Alex""Notch"];
    $string implode(", "$array);
    $player->sendMessage("Popular MCPE usernames are ".$string);
    // Outputs: Popular MCPE usernames are Steve, Alex, Notch
    2. Please show us the code for your task! Otherwise I cant help you.

    When you dont know how:
    Start a scheduleRepeatingTask with the player as a __construct() parameter. Then call it every second and each call it should count up, so do $this->count++; at onRun(). When this->count has reached a special count (how long it should be displayed), cancel it with $this->plugin->getServer()->getScheduler()->cancelTask($this->getTaskId());
    And to set which players should not see the join message, just do if($player->getName() == "<name">){ on PlayerJoinEvent, to filter multiple people, just do
    PHP:
    $pl = ["Admin""Owner""Steve"];
    if(!
    in_array($p->getName(), $pl)) /* start task code here */
  9. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    I think that @shoghicp once mentioned that isset is faster than in_array but I might be wrong.

    isset()
    [​IMG]
    in_array()
    [​IMG]

    I was wrong after all :(
    Last edited: Sep 2, 2016
  10. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    Um, when you read properly it says "is_array()", not "in_array()".
    Primus likes this.
  11. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Ha ha :D wrong picture. Let me find the real one...
  12. Muqsit
    Offline

    Muqsit Active Member

    Joined:
    Sep 9, 2015
    Posts:
    175
    Minecraft User:
    Muqsit
    Lol. in_array() and isset() are good in different case scenarios.
  13. JonsMC
    Offline

    JonsMC Active Member

    Joined:
    Jul 26, 2016
    Posts:
    107
    Minecraft User:
    JonsMC
    PHP:
    foreach($this->plugin->getServer()->getOnlinePlayers() as $ps) {
      if(!
    in_array($ps->getName(), $this->plugin->banned_players)) {
             
    $ps->sendPopup("You are not banned ." $ps->getName());
          }
     }
    This would work? I put this in a task :p
  14. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    You're scaring away people :D

    If you are on server it's obvious that you're not banned.
  15. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Muqsit, MyNameIsTriXz and Primus like this.
  16. Muqsit
    Offline

    Muqsit Active Member

    Joined:
    Sep 9, 2015
    Posts:
    175
    Minecraft User:
    Muqsit
    isset > in_array so...
    PHP:
    foreach($this->plugin->getServer()->getOnlinePlayers() as $ps){
      if(!isset(
    $this->plugin->banned_players[$ps->getName()])){
        
    $ps->sendPopup("You are not banned "$ps->getName());
      }
    }
  17. Muqsit
    Offline

    Muqsit Active Member

    Joined:
    Sep 9, 2015
    Posts:
    175
    Minecraft User:
    Muqsit
  18. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    So for example, if you have an array with a structure like this: key => playerName
    You would have to use in_array. But you can change the structure to: playerName => boolean. Now you can use isset :)
  19. JonsMC
    Offline

    JonsMC Active Member

    Joined:
    Jul 26, 2016
    Posts:
    107
    Minecraft User:
    JonsMC
    Im trying to display a list of items that I set in my config:
    Items:
    - 32:0:1:2

    32 is the item id, 0 is damage, 1 is count and 2 is money(EconomyAPI)
    And i want that list as :
    Dead Bush(1): 2 coins
    But seems that i cannot find a way to do this :/
  20. Muqsit
    Offline

    Muqsit Active Member

    Joined:
    Sep 9, 2015
    Posts:
    175
    Minecraft User:
    Muqsit
    PHP:
    Use explode.
    $items $this->getConfig()->get("Items"){
    foreach(
    $items as $item){
    $itemDatas array_shift(explode(":"$item);
    $itemId $itemDatas[0];
    $itemDamage $itemDatas[1];
    $itemCount $itemDatas[2];
    $itemCost $itemDatas[3]; //EconomyAPI money.
    $itemName Item::get($itemId)->getName();
    }
    }
    ;)
    Offtopic
    Click bait tutorial:
    1. Set title to "2 questions".
    2. Ask > 2 questions.

Share This Page

Advertisement