Overview

Namespaces

  • aliuly
    • common
      • selectors
    • loader
  • xPaw

Classes

  • aliuly\common\ArmorItems
  • aliuly\common\BasicCli
  • aliuly\common\BasicHelp
  • aliuly\common\BasicPlugin
  • aliuly\common\ChatSession
  • aliuly\common\Cmd
  • aliuly\common\CmdSelector
  • aliuly\common\ExpandVars
  • aliuly\common\FastTransfer
  • aliuly\common\FileUtils
  • aliuly\common\FreezeSession
  • aliuly\common\GetMotd
  • aliuly\common\GetMotdAsyncTask
  • aliuly\common\InvisibleSession
  • aliuly\common\InvUtils
  • aliuly\common\ItemName
  • aliuly\common\mc
  • aliuly\common\mc2
  • aliuly\common\MoneyAPI
  • aliuly\common\MPMU
  • aliuly\common\Npc
  • aliuly\common\PermUtils
  • aliuly\common\PluginAsyncTask
  • aliuly\common\PluginCallbackTask
  • aliuly\common\PMScript
  • aliuly\common\QueryAsyncTask
  • aliuly\common\Rcon
  • aliuly\common\RconTask
  • aliuly\common\selectors\All
  • aliuly\common\selectors\AllEntity
  • aliuly\common\selectors\BaseSelector
  • aliuly\common\selectors\Random
  • aliuly\common\Session
  • aliuly\common\ShieldSession
  • aliuly\common\ShoppingCart
  • aliuly\common\SignUtils
  • aliuly\common\SkinUtils
  • aliuly\common\SpySession
  • aliuly\common\SubCommandMap
  • aliuly\common\TPUtils
  • aliuly\loader\Main
  • xPaw\MinecraftQuery

Exceptions

  • xPaw\MinecraftQueryException
  • Overview
  • Namespace
  • Class
  1: <?php
  2: //= api-features
  3: //: - Multiple money support
  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:  * This class allows you to use a number of miscellaneous Economy
 15:  * plugins.
 16:  */
 17: abstract class MoneyAPI {
 18:     /**
 19:      * Show a warning when the money API is missing
 20:      *
 21:      * @param PluginBase $plugin - current plugin
 22:      * @param LogLevel $level - optional log level
 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:      * Show a notice when the money API is found
 55:      *
 56:      * @param PluginBase $plugin - current plugin
 57:      * @param PluginBase $api - found plugin
 58:      * @param LogLevel $level - optional log level
 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:      * Find a supported *money* plugin
 72:      *
 73:      * @param var obj - Server or Plugin object
 74:      * @return null|Plugin
 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:      * Gives money to a player.
 93:      *
 94:      * @param Plugin api Economy plugin (from moneyPlugin)
 95:      * @param str|IPlayer p Player to pay
 96:      * @param int money Amount of money to play (can be negative)
 97:      *
 98:      * @return bool
 99:      */
100:     static public function grantMoney($api,$p,$money) {
101:         if(!$api) return false;
102:         switch($api->getName()){
103:             case "GoldStd": // takes IPlayer|str
104:                 $api->grantMoney($p, $money);
105:                 break;
106:             case "PocketMoney": // takes str
107:               if ($p instanceof IPlayer) $p = $p->getName();
108:                 $api->grantMoney($p, $money);
109:                 break;
110:             case "EconomyAPI": // Takes str
111:                 if ($p instanceof IPlayer) $p = $p->getName();
112:                 $api->setMoney($p,$api->mymoney($p)+$money);
113:                 break;
114:             case "MassiveEconomy": // Takes str
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:      * Gets player balance
125:      *
126:      * @param Plugin $api Economy plugin (from moneyPlugin)
127:      * @param str|IPlayer $player Player to lookup
128:      *
129:      * @return int
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: 
API documentation generated by ApiGen