1: <?php
2:
3:
4:
5: namespace aliuly\common;
6: use pocketmine\Server;
7: use pocketmine\plugin\PluginBase;
8: use pocketmine\utils\TextFormat;
9: use pocketmine\IPlayer;
10: use LogLevel;
11:
12:
13: 14: 15: 16:
17: abstract class MoneyAPI {
18: 19: 20: 21: 22: 23:
24: static public function noMoney(PluginBase $plugin,$level = LogLevel::WARNING) {
25: if (class_exists(__NAMESPACE__."\\mc",false)) {
26: $plugin->getLogger()->error($level,TextFormat::RED.
27: mc::_("! MISSING MONEY API PLUGIN"));
28: $plugin->getLogger()->error(TextFormat::BLUE.
29: mc::_(". Please install one of the following:"));
30: $plugin->getLogger()->error(TextFormat::WHITE.
31: mc::_("* GoldStd"));
32: $plugin->getLogger()->error(TextFormat::WHITE.
33: mc::_("* PocketMoney"));
34: $plugin->getLogger()->error(TextFormat::WHITE.
35: mc::_("* EconomyAPI or"));
36: $plugin->getLogger()->error(TextFormat::WHITE.
37: mc::_("* MassiveEconomy"));
38: } else {
39: $plugin->getLogger()->error($level,TextFormat::RED.
40: "! MISSING MONEY API PLUGIN");
41: $plugin->getLogger()->error(TextFormat::BLUE.
42: ". Please install one of the following:");
43: $plugin->getLogger()->error(TextFormat::WHITE.
44: "* GoldStd");
45: $plugin->getLogger()->error(TextFormat::WHITE.
46: "* PocketMoney");
47: $plugin->getLogger()->error(TextFormat::WHITE.
48: "* EconomyAPI or");
49: $plugin->getLogger()->error(TextFormat::WHITE.
50: "* MassiveEconomy");
51: }
52: }
53: 54: 55: 56: 57: 58: 59:
60: static public function foundMoney(PluginBase $plugin,$api,$level = LogLevel::INFO) {
61: if (class_exists(__NAMESPACE__."\\mc",false)) {
62: $plugin->getLogger()->log($level,TextFormat::BLUE.
63: mc::_("Using money API from %1%",
64: $api->getFullName()));
65: } else {
66: $plugin->getLogger()->log($level,TextFormat::BLUE.
67: "Using money API from ".$api->getFullName());
68: }
69: }
70: 71: 72: 73: 74: 75:
76: static public function moneyPlugin($obj) {
77: if ($obj instanceof Server) {
78: $server = $obj;
79: } else {
80: $server = $obj->getServer();
81: }
82: $pm = $server->getPluginManager();
83: if(!($money = $pm->getPlugin("PocketMoney"))
84: && !($money = $pm->getPlugin("GoldStd"))
85: && !($money = $pm->getPlugin("EconomyAPI"))
86: && !($money = $pm->getPlugin("MassiveEconomy"))){
87: return null;
88: }
89: return $money;
90: }
91: 92: 93: 94: 95: 96: 97: 98: 99:
100: static public function grantMoney($api,$p,$money) {
101: if(!$api) return false;
102: switch($api->getName()){
103: case "GoldStd":
104: $api->grantMoney($p, $money);
105: break;
106: case "PocketMoney":
107: if ($p instanceof IPlayer) $p = $p->getName();
108: $api->grantMoney($p, $money);
109: break;
110: case "EconomyAPI":
111: if ($p instanceof IPlayer) $p = $p->getName();
112: $api->setMoney($p,$api->mymoney($p)+$money);
113: break;
114: case "MassiveEconomy":
115: if ($p instanceof IPlayer) $p = $p->getName();
116: $api->payPlayer($p->getName(),$money);
117: break;
118: default:
119: return false;
120: }
121: return true;
122: }
123: 124: 125: 126: 127: 128: 129: 130:
131: static public function getMoney($api,$player) {
132: if(!$api) return false;
133: switch($api->getName()){
134: case "GoldStd":
135: return $api->getMoney($player);
136: break;
137: case "PocketMoney":
138: case "MassiveEconomy":
139: if ($player instanceof IPlayer) $player = $player->getName();
140: return $api->getMoney($player);
141: case "EconomyAPI":
142: if ($player instanceof IPlayer) $player = $player->getName();
143: return $api->mymoney($player);
144: default:
145: return false;
146: break;
147: }
148: }
149: }
150: