Hey. I save player names in a config. But if I kick a player when a new one joins, the config saves wrong. onJoin: Add to players array in config OnQuit: Remove from players array Normally it saves it like this: players: - Steve - Steve2 But if I kick a player when a new one joins it looks like this: players: 1: Steve 2: Steve2 How can I fix that? It makes my plugin not work...
It's easy to fix, just modify the config directly. It's not like you have to have PMMP to modify a config. A config can easily be modified by hand. Before: PHP: players:1: Steve2: Steve2 After: PHP: players:- Steve- Steve2 It's very simple and doesn't require any special talent or skill at all, (just like the question :3)
I doubt that PHP: Example:$cfg->getAll(true); Fixes it, I went through this situation before - I might be wrong, correct me if I'm wrong
Can we see your full code so we can help? We can't be providing help as we don't know what you've done on your Main file.. You're not gonna lose anything if you share...
OnJoin: PHP: $players = $this->players; array_push($players, $name); $this->players = $players; $conf->set("players", $players); $conf->save(); OnQuit: PHP: $players = $this->players; if(in_array($player->getName(), $conf->get("players"))) { unset($players[array_search($player->getName(), $players)]); $this->players = $players; $conf->set("players", $players); $conf->save(); }
Wait what? $players = $this->players and $this->players = $players? Please tell us what $this->players is. Is it an array?
Your code is overcomplicated. Try this instead. PHP: private $players = [];public function onEnable(){ $config = yaml_parse_file($this->getDataFolder()."config.yml"); //Converts config to array. $this->players = $config["players"] ?? []; //If "players" exists in config, $this->players will be assigned that, or else a new array will be assigned to $this->players.}public function onJoin(PlayerJoinEvent $event){ $player = $event->getPlayer(); $this->players[$player->getId()] = $player->getName(); //In your post, you were trying to save Player::class in the config. This probably will give you some YAML parsing error. You should have serialized it instead. $this->saveConfig();}public function onQuit(PlayerQuitEvent $event){ $id = $event->getPlayer()->getId(); unset($this->players[$id]); $this->saveConfig();}public function saveConfig(){ $config = yaml_parse_file($dir = $this->getDataFolder()."config.yml"); $config["players"] = $this->players; //set "players" in config to the modified players global array. yaml_emit_file($dir, $config); //save config.} But what are you getting from this? The key "players" in the config is emptied when the server stops.