Skip to content
This repository was archived by the owner on Jul 11, 2018. It is now read-only.

Commit 520e3f1

Browse files
committed
Merge branch 'dev-autoheal'
* dev-autoheal: Make it work as permissions
2 parents 0c778aa + 1475ac4 commit 520e3f1

File tree

2 files changed

+26
-30
lines changed

2 files changed

+26
-30
lines changed

AutoHeal/plugin.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ load: POSTWORLD
44

55
name: AutoHeal
66
description: Basic Auto-Healing Plugin
7-
version: 1.0.0
7+
version: 1.0.1
88
author: aliuly
99

1010
permissions:

AutoHeal/src/aliuly/autoheal/Main.php

+25-29
Original file line numberDiff line numberDiff line change
@@ -5,64 +5,60 @@
55
use pocketmine\utils\Config;
66
use pocketmine\scheduler\CallbackTask;
77
use pocketmine\utils\TextFormat;
8+
use pocketmine\permission\Permission;
89

910
//use pocketmine\Player;
1011
//use pocketmine\Server;
1112
//use pocketmine\item\Item;
1213
//use pocketmine\network\protocol\SetHealthPacket;
1314

1415
class Main extends PluginBase{
15-
protected $players;
16-
1716
public function onEnable(){
1817
if (!is_dir($this->getDataFolder())) mkdir($this->getDataFolder());
1918
$defaults = [
2019
"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],
2923
],
3024
];
3125
if (file_exists($this->getDataFolder()."config.yml")) {
3226
unset($defaults["ranks"]);
33-
unset($defaults["players"]);
3427
}
3528
$cfg = (new Config($this->getDataFolder()."config.yml",
3629
Config::YAML,$defaults))->getAll();
37-
if (!isset($cfg["ranks"])) $cfg["ranks"] = 0;
30+
if (!isset($cfg["ranks"])) $cfg["ranks"] = [];
31+
3832
$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;
4543
}
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;
4649
}
4750
if ($cnt == 0) {
4851
$this->getLogger()->info(TextFormat::RED.
49-
"No ranks or players defined, disabling...");
52+
"No ranks defined, disabling...");
5053
return;
5154
}
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");
6156
}
6257
public function healTimer($rank,$amount) {
6358
$pls = $this->getServer()->getOnlinePlayers();
6459
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;
6662
// Yes, this is a vip!
6763
$new = $pl->getHealth() + $amount;
6864
if ($new > $pl->getMaxHealth()) $new = $pl->getMaxHealth();

0 commit comments

Comments
 (0)