Skip to content
This repository has been archived by the owner on Oct 29, 2022. It is now read-only.

Commit

Permalink
added EssentialsPE support for #9
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonw4331 committed Dec 9, 2016
1 parent 9c3d299 commit d9411b3
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 16 deletions.
18 changes: 15 additions & 3 deletions src/MyPlot/MyPlot.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
<?php
namespace MyPlot;

use EssentialsPE\Loader;
use MyPlot\provider\EconomySProvider;
use MyPlot\provider\EssentialsPEProvider;
use MyPlot\provider\PocketMoneyProvider;
use MyPlot\provider\YAMLDataProvider;
use MyPlot\task\ClearPlotTask;
use MyPlot\provider\DataProvider;
use MyPlot\provider\SQLiteDataProvider;
use MyPlot\provider\EconomyProvider;

use onebone\economyapi\EconomyAPI;
use pocketmine\block\Air;
use pocketmine\event\level\LevelLoadEvent;
use pocketmine\lang\BaseLang;
Expand All @@ -21,6 +24,7 @@
use pocketmine\Player;
use pocketmine\level\Level;
use pocketmine\utils\TextFormat as TF;
use PocketMoney\PocketMoney;

class MyPlot extends PluginBase
{
Expand Down Expand Up @@ -500,10 +504,18 @@ public function onEnable() {

// Initialize EconomyProvider
if ($this->getConfig()->get("UseEconomy") == true) {
if ($this->getServer()->getPluginManager()->getPlugin("EconomyAPI") !== null) {
$this->economyProvider = new EconomySProvider();
if (($plugin = $this->getServer()->getPluginManager()->getPlugin("EconomyAPI")) !== null) {
if($plugin instanceof EconomyAPI) {
$this->economyProvider = new EconomySProvider($plugin);
}
} elseif (($plugin = $this->getServer()->getPluginManager()->getPlugin("EssentialsPE")) !== null) {
if($plugin instanceof Loader) {
$this->economyProvider = new EssentialsPEProvider($plugin);
}
} elseif (($plugin = $this->getServer()->getPluginManager()->getPlugin("PocketMoney")) !== null) {
$this->economyProvider = new PocketMoneyProvider($plugin);
if($plugin instanceof PocketMoney) {
$this->economyProvider = new PocketMoneyProvider($plugin);
}
}
}

Expand Down
10 changes: 2 additions & 8 deletions src/MyPlot/provider/EconomyProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@

use pocketmine\Player;

interface EconomyProvider
{
/**
* @param Player $player
* @param int $amount
* @return bool
*/
public function reduceMoney(Player $player, $amount);
interface EconomyProvider{
public function reduceMoney(Player $player, $amount);
}
16 changes: 11 additions & 5 deletions src/MyPlot/provider/EconomySProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,21 @@

class EconomySProvider implements EconomyProvider
{
public function reduceMoney(Player $player, $amount) {
/** @var EconomyAPI */
private $plugin;

public function __construct(EconomyAPI $plugin) {
$this->plugin = $plugin;
}

public function reduceMoney(Player $player, $amount) {
if ($amount == 0) {
return true;
} elseif ($amount < 0) {
$ret = EconomyAPI::getInstance()->addMoney($player, $amount, true);
$ret = $this->plugin->addMoney($player, $amount, true);
} else {
$ret = EconomyAPI::getInstance()->reduceMoney($player, $amount, true);
$ret = $this->plugin->reduceMoney($player, $amount, true);
}

return ($ret === EconomyAPI::RET_SUCCESS);
return ($ret == 1);
}
}
30 changes: 30 additions & 0 deletions src/MyPlot/provider/EssentialsPEProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
namespace MyPlot\provider;

use EssentialsPE\Loader;
use pocketmine\Player;

class EssentialsPEProvider implements EconomyProvider {
/** @var Loader */
private $plugin;

public function __construct(Loader $plugin) {
$this->plugin = $plugin;
}

public function reduceMoney(Player $player, $amount) {
if ($amount == 0) {
return true;
} elseif ($amount < 0) {
$pre = $this->plugin->getAPI()->getPlayerBalance($player);
$this->plugin->getAPI()->addToPlayerBalance($player, $amount);
} else {
$pre = $this->plugin->getAPI()->getPlayerBalance($player);
$this->plugin->getAPI()->addToPlayerBalance($player, -$amount);
}
if($this->plugin->getAPI()->getPlayerBalance($player) == $pre - $amount) {
return true;
}
return false;
}
}
1 change: 1 addition & 0 deletions src/MyPlot/provider/PocketMoneyProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

class PocketMoneyProvider implements EconomyProvider
{
/** @var PocketMoney */
private $plugin;

public function __construct(PocketMoney $plugin) {
Expand Down

0 comments on commit d9411b3

Please sign in to comment.