|
5 | 5 | use pocketmine\utils\Config;
|
6 | 6 | use pocketmine\scheduler\CallbackTask;
|
7 | 7 | use pocketmine\utils\TextFormat;
|
| 8 | +use pocketmine\permission\Permission; |
8 | 9 |
|
9 | 10 | //use pocketmine\Player;
|
10 | 11 | //use pocketmine\Server;
|
11 | 12 | //use pocketmine\item\Item;
|
12 | 13 | //use pocketmine\network\protocol\SetHealthPacket;
|
13 | 14 |
|
14 | 15 | class Main extends PluginBase{
|
15 |
| - protected $players; |
16 |
| - |
17 | 16 | public function onEnable(){
|
18 | 17 | if (!is_dir($this->getDataFolder())) mkdir($this->getDataFolder());
|
19 | 18 | $defaults = [
|
20 | 19 | "ranks" => [
|
21 |
| - "vip1" => [40, 1], |
22 |
| - "vip2" => [80, 2], |
23 |
| - "vip3" => [800, 1], |
24 |
| - ], |
25 |
| - "players" => [ |
26 |
| - "joe" => "vip1", |
27 |
| - "tom" => "vip2", |
28 |
| - "smith" => "vip3", |
| 20 | + "vip1" => [40, 1, false], |
| 21 | + "vip2" => [80, 2, false], |
| 22 | + "vip3" => [800, 1, false], |
29 | 23 | ],
|
30 | 24 | ];
|
31 | 25 | if (file_exists($this->getDataFolder()."config.yml")) {
|
32 | 26 | unset($defaults["ranks"]);
|
33 |
| - unset($defaults["players"]); |
34 | 27 | }
|
35 | 28 | $cfg = (new Config($this->getDataFolder()."config.yml",
|
36 | 29 | Config::YAML,$defaults))->getAll();
|
37 |
| - if (!isset($cfg["ranks"])) $cfg["ranks"] = 0; |
| 30 | + if (!isset($cfg["ranks"])) $cfg["ranks"] = []; |
| 31 | + |
38 | 32 | $cnt = 0;
|
39 |
| - $this->players = []; |
40 |
| - if (isset($cfg["players"])) { |
41 |
| - foreach ($cfg["players"] as $name => $rank) { |
42 |
| - if (!isset($cfg["ranks"][$rank])) continue; |
43 |
| - ++$cnt; |
44 |
| - $this->players[$rank][$name] = $name; |
| 33 | + foreach ($cfg["ranks"] as $rank=>$dat) { |
| 34 | + if (count($dat) == 3) { |
| 35 | + list($rate,$amount,$perms) = $dat; |
| 36 | + } elseif (count($dat) == 2) { |
| 37 | + list($rate,$amount) = $dat; |
| 38 | + $perms = false; |
| 39 | + } else { |
| 40 | + $this->getLogger()->info(TextFormat::RED. |
| 41 | + "Skipping rank: ".$rank); |
| 42 | + continue; |
45 | 43 | }
|
| 44 | + $p = new Permission("autoheal.".$rank,"Enables auto heal for ".$rank, |
| 45 | + $perms); |
| 46 | + $this->getServer()->getPluginManager()->addPermission($p); |
| 47 | + $this->getServer()->getScheduler()->scheduleRepeatingTask(new CallbackTask([$this,"healTimer"],[$rank,$amount]),$rate); |
| 48 | + ++$cnt; |
46 | 49 | }
|
47 | 50 | if ($cnt == 0) {
|
48 | 51 | $this->getLogger()->info(TextFormat::RED.
|
49 |
| - "No ranks or players defined, disabling..."); |
| 52 | + "No ranks defined, disabling..."); |
50 | 53 | return;
|
51 | 54 | }
|
52 |
| - $rcnt = 0; |
53 |
| - foreach ($cfg["ranks"] as $rank=>$det) { |
54 |
| - if (!isset($this->players[$rank])) continue; |
55 |
| - ++$rcnt; |
56 |
| - list($rate,$amount) = $det; |
57 |
| - $this->getServer()->getScheduler()->scheduleRepeatingTask(new CallbackTask([$this,"healTimer"],[$rank,$amount]),$rate); |
58 |
| - } |
59 |
| - $this->getLogger()->info($rcnt." ranks defined"); |
60 |
| - $this->getLogger()->info($cnt." players registered"); |
| 55 | + $this->getLogger()->info($cnt." ranks configured"); |
61 | 56 | }
|
62 | 57 | public function healTimer($rank,$amount) {
|
63 | 58 | $pls = $this->getServer()->getOnlinePlayers();
|
64 | 59 | foreach($pls as $pl) {
|
65 |
| - if (!isset($this->players[$rank][$pl->getName()])) continue; |
| 60 | + if (!$pl->hasPermission("autoheal")) continue; |
| 61 | + if (!$pl->hasPermission("autoheal.".$rank)) continue; |
66 | 62 | // Yes, this is a vip!
|
67 | 63 | $new = $pl->getHealth() + $amount;
|
68 | 64 | if ($new > $pl->getMaxHealth()) $new = $pl->getMaxHealth();
|
|
0 commit comments