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

Solved Whats wrong?

Comments in 'Plugin Development' started by JackboyPlay, Mar 20, 2016.

  1. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    You use Config for temporary data? :eek:
  2. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
  3. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    better use arrays. like creating an empty array on the class and pushing the playername there.
    Primus likes this.
  4. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    @PocketKiller but all things are done for the config :oops: I want only a fix for that now
  5. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    PHP:
    if($c->get("m1s1") !== $event->getPlayer()->getName()){
        
    $this->getConfig()->set("m1s1"$event->getPlayer()->getName());
        
    $this->getConfig()->save();
    }
  6. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
  7. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
  8. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Sorry @JackboyPlay I'll try to do it.

    First you have to create a property in your Main
    PHP:
    # Under class decleration
    public $m1s1 = array(); // You can set here default values if you want
    Further help when you will how your plugin will work.
    JackboyPlay likes this.
  9. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    Okay how can I put the players in the array and how can I get the array in a another class like the task?
    And how to "clear" the array?
    And how can I send the player in the array a message?
  10. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    @Primus can I implement in your Ultra factions plugin Mysql? :D
  11. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    That class isn't finished. Actually good idea I have some spare time to do it :)
  12. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    @Primus but can you answer the question that I send?
  13. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Assuming we are saving player object under player's name
    PHP:
    if(isset($this->m1s1[$player->getName()])){ // If player is saved on array
        
    $playerInArray $this->m1s1[$player->getName()]; // Getting from array, this value will be same object as $player
    } else {
       
    $this->m1s1[$player->getName()] = $player// Saving on array
    }
    // Unsetting from array
    unset($this->m1s1[$player->getName()]);

    // Broadcasting message to all players in array
    foreach($this->m1s1 as $name => $player){
       if(
    $player instanceof Player){ // Check if player hasn't disconnected
          
    $player->sendMessage("You are in m1s1 array");
       } else {
          
    // It's a good idea to remove this player from array
       
    }
    }
  14. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    How can I remove an specified player like the player with the name "BErnd"
  15. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    How can I use the array in my task class?
  16. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    PHP:
    /**
     * @param string $player
     * @return bool
     */
    function removePlayer($player) : bool {
        if(!isset(
    $this->m1s1[$player])) return false// Actually this is not necessary. But I think this is a good think to do.
        
    unset($this->m1s1[$player]);
    }
  17. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    PHP:
    // Context of PluginTask
    $this->getOwner()->m1s1;
  18. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    @Primus how can I count how many players are on the array?
  19. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    PHP:
    count($this->ms1s);
    // or, this will count all valid players
    $i 0;
    foreach(
    $this->ms1s as $player){
        if(
    $player instanceof Player$i++;
    }
    echo 
    $i// Count of valid players in array
  20. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Using Config isn't an option. It is totally redundant.
    A Config file, if you don't save it, eventually goes to an internal array $config->data (private property). So why don't you manipulate the array yourself? It would give you a lot more freedom.
    Also, "m1s2" means something like "1st m, 2nd s", right? Then you should use a two-dimensional numeric array such that you access it with $array[0][1].

Share This Page

Advertisement