Skip to content

Commit

Permalink
EconomyPShop now displays custom alert of unapplied plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
onebone committed Oct 6, 2015
1 parent 0388277 commit 09d9266
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
5 changes: 1 addition & 4 deletions EconomyPShop/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ author: onebone
main: onebone\economypshop\EconomyPShop

api: [1.12.0]
depend:
- EconomyAPI
- ItemCloud

permissions:
economypshop.*:
Expand All @@ -22,4 +19,4 @@ permissions:
description: Allows player to buy items from shop
default: true
economypshop.shop.destroy.others:
description: Allows player to destroy others' shop
description: Allows player to destroy others' shop
30 changes: 17 additions & 13 deletions EconomyPShop/src/onebone/economypshop/EconomyPShop.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,27 @@
use pocketmine\plugin\PluginBase;
use pocketmine\utils\Config;

use onebone\itemcloud\MainClass;
use onebone\itemcloud\ItemCloud;

use onebone\economyapi\EconomyAPI;

class EconomyPShop extends PluginBase implements Listener{
private $placeQueue, $shop, $shopText, $lang, $tap;

/**
* @var MainClass
* @var \onebone\itemcloud\MainClass
*/
private $itemcloud;

public function onEnable(){
if(!file_exists($this->getDataFolder())){
mkdir($this->getDataFolder());
}
if(!class_exists("\\onebone\\itemcloud\\MainClass", false)){
$this->getLogger()->critical("[DEPENDENCY] Please install ItemCloud plugin to use PShop plugin.");
return;
}
if(!class_exists("\\onebone\\economyapi\\EconomyAPI", false)){
$this->getLogger()->critical("[DEPENDENCY] Please install EconomyAPI plugin to use PShop plugin.");
return;
}

$this->saveResource("ShopText.yml");
$this->saveResource("language.properties");
$this->saveDefaultConfig();
Expand All @@ -55,7 +59,7 @@ public function onEnable(){
$this->lang = (new Config($this->getDataFolder()."language.properties", Config::PROPERTIES));

$this->getServer()->getPluginManager()->registerEvents($this, $this);
$this->itemcloud = MainClass::getInstance();
$this->itemcloud = \onebone\itemcloud\MainClass::getInstance();

$this->tap = [];
$this->placeQueue = [];
Expand All @@ -76,12 +80,12 @@ public function onSignChange(SignChangeEvent $event){
return;
}

$money = EconomyAPI::getInstance()->myMoney($player->getName());
$money = \onebone\economyapi\EconomyAPI::getInstance()->myMoney($player->getName());
if($money < $this->getConfig()->get("shop-tax")){
$player->sendMessage($this->getMessage("no-shop-tax"));
return;
}
EconomyAPI::getInstance()->reduceMoney($player->getName(), $this->getConfig()->get("shop-tax"), "EconomyPShop");
\onebone\economyapi\EconomyAPI::getInstance()->reduceMoney($player->getName(), $this->getConfig()->get("shop-tax"), "EconomyPShop");

$cost = $line[1];
$item = $line[2];
Expand Down Expand Up @@ -113,7 +117,7 @@ public function onSignChange(SignChangeEvent $event){
"amount" => (int) $line[3]
];

$mu = EconomyAPI::getInstance()->getMonetaryUnit();
$mu = \onebone\economyapi\EconomyAPI::getInstance()->getMonetaryUnit();
$event->setLine(0, str_replace("%MONETARY_UNIT%", $mu, $val[0]));
$event->setLine(1, str_replace(["%MONETARY_UNIT%", "%1"], [$mu, $cost], $val[1]));
$event->setLine(2, str_replace(["%MONETARY_UNIT%", "%2"], [$mu, $item->getName()], $val[2]));
Expand Down Expand Up @@ -170,14 +174,14 @@ public function onBlockTouch(PlayerInteractEvent $event){
unset($this->tap[$player->getName()]);
}

if(($cloud = $this->itemcloud->getCloudForPlayer($shop["owner"])) instanceof ItemCloud){
if(($cloud = $this->itemcloud->getCloudForPlayer($shop["owner"])) instanceof \onebone\itemcloud\ItemCloud){
if($shop["amount"] > $cloud->getCount($shop["item"], $shop["meta"])){
$player->sendMessage($this->getMessage("no-stock"));
}else{
if($player->getInventory()->canAddItem(($item = new Item($shop["item"], $shop["meta"], $shop["amount"]))) === false){
$player->sendMessage($this->getMessage("no-space"));
}else{
$api = EconomyAPI::getInstance();
$api = \onebone\economyapi\EconomyAPI::getInstance();
if($api->myMoney($player) > $shop["price"]){
$player->getInventory()->addItem($item);
$api->reduceMoney($player, $shop["price"], true, "EconomyPShop");
Expand All @@ -204,7 +208,7 @@ public function onBlockTouch(PlayerInteractEvent $event){

public function getMessage($key, $val = ["%1", "%2", "%3"]){
if($this->lang->exists($key)){
return str_replace(["%1", "%2", "%3", "%MONETARY_UNIT%"], [$val[0], $val[1], $val[2], EconomyAPI::getInstance()->getMonetaryUnit()], $this->lang->get($key));
return str_replace(["%1", "%2", "%3", "%MONETARY_UNIT%"], [$val[0], $val[1], $val[2], \onebone\economyapi\EconomyAPI::getInstance()->getMonetaryUnit()], $this->lang->get($key));
}
return "There's no message named \"$key\"";
}
Expand Down

0 comments on commit 09d9266

Please sign in to comment.