<?php
namespace main;
use pocketmine\plugin\PluginBase;
use pocketmine\Player;
use pocketmine\Server;
use pocketmine\event\Listener;
use pocketmine\utils\TextFormat;
use pocketmine\utils\Config;
use pocketmine\event\player\PlayerJoinEvent;
class SimpleCoins extends PluginBase implements Listener{
public function onEnable(){
$this->getServer()->getPluginManager()->registerEvents($this,$this);
$this->getLogger()->info(TextFormat::YELLOW."シンプルコイン");
if(!file_exists($this->getDataFolder())){
mkdir($this->getDataFolder(), 0744, true);
}
$this->config = new Config($this->getDataFolder() . "coin.yml", Config::YAML,array());//Config
}
public function onjoin(PlayerJoinEvent $event){
$username = $event->getPlayer()->getName();
$this->config = new Config($this->getDataFolder() . "coin.yml", Config::YAML,array());//Config
if($this->config->exists($username)){
}else{
$this->config->set($username,0);
$this->config->save();
}
}
public function get($username){
$this->config = new Config($this->getDataFolder() . "coin.yml", Config::YAML,array());//Config
if($this->config->exists($username)){
return $this->config->get($username);
}else{
$this->config->set($username,0);
$this->config->save();
return 0;
}
}
public function set($username,$coin){
$this->config = new Config($this->getDataFolder() . "coin.yml", Config::YAML,array());//Config
if($this->config->exists($username)){
$this->config->set($username,$coin);
$this->config->save();
}else{
$this->config->set($username,$coin);
$this->config->save();
}
}
}