Hey, I want to optimize a minigame plugin as good as I can, I want to store everything in one Main.php file, the hardest thing is adding good multigame support, which is overviewable. Thats how the code should look like PHP: public $games = ["Game1" => ["Players" => [playerobject1,...], "Arena" => "MiniGameArena", "Phase" => "Startcountdown"]]; But I am not really sure if it is the best way to make that, and is that code right? And last: Is that code to foreach these games right? PHP: foreach($this->games as $game => $value){$players = $value["Players"];// and so on}
If you want to optimize things or to at least look easier to read, you should use objects rather than associative arrays for arrays with fixed keys. And use numeric keys like [0] [1] rather than string keys like ["Game1"] ["Game2"]. This is faster and gives you the ability to expand your number of games. I'm just going to tell you the opposite. You are saying this from a user's view, but from a programmer's view, something that works does not mean a lot compared to something that is designed well, because: It works now ≠ it will work after updates It works now ≠ it works efficiently It works now ≠ you can easily add stuff if you want to expand it in the future It works ≠ others can understand it and improve it It is like inventing medicine vs issuing medicine to the patient. Which one do you think is more important? This is the age of programming, where user interface is a small thing. Read more: http://t.co/PwPAB8L1q4
In your main class, you'll need to setup they first. PHP: private $game;public function OnEnable(){# ...$this->game = new Game($this, 1);# Now you're able to do stuff like $this->game->getStatement();# or $this->game->setStatement("Waiting for players");} And your Game class... PHP: class Game{private $owner, $name;private statement = "InGame";private $players = [];public function __construc(YourPlugin $owner, int $name /*Game number*/){$this->owner = $owner;$this->name = $name;}public function getName(){return $this->name;}public function setName(int $name){$this->name = $name;}public function addPlayer(Player $player){array_push($this->players, $player);}public function getStatement(){return $this->statement;}public function setStatement(string $statement){$this->statement = $statement;} This is PHP OOP, you'll have to learn it if you want understand this at all.
See also: https://github.com/LegionPE/LegionPE-Eta/blob/master/LegionPE-Core/src/legionpe/LegionPE.php#L264 https://github.com/LegionPE/LegionPE-Eta/blob/master/LegionPE-Core/src/legionpe/session/Session.php https://github.com/LegionPE/LegionPE-Eta/blob/master/LegionPE-Core/src/legionpe/games/Game.php This is the model for DynamicHub as well.
Ok, but my last question, if I want to check and set for each game a player when he touches a join sign, how it should look like?