This repository has been archived by the owner on Oct 29, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
9 changed files
with
269 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
declare(strict_types=1); | ||
namespace MyPlot\subcommand; | ||
|
||
use MyPlot\forms\MyPlotForm; | ||
use pocketmine\command\CommandSender; | ||
use pocketmine\Player; | ||
use pocketmine\utils\TextFormat; | ||
use function count; | ||
use function explode; | ||
use function is_numeric; | ||
use function strtolower; | ||
|
||
class BuySubCommand extends SubCommand | ||
{ | ||
/** | ||
* @param CommandSender $sender | ||
* | ||
* @return bool | ||
*/ | ||
public function canUse(CommandSender $sender) : bool { | ||
return ($sender instanceof Player) and $sender->hasPermission("myplot.command.buy"); | ||
} | ||
|
||
/** | ||
* @param Player $sender | ||
* @param string[] $args | ||
* | ||
* @return bool | ||
*/ | ||
public function execute(CommandSender $sender, array $args) : bool { | ||
if($this->getPlugin()->getEconomyProvider() === null){ | ||
$sender->sendMessage("NO-ECONOMY-PLUGIN"); | ||
return true; | ||
} | ||
$plot = $this->getPlugin()->getPlotByPosition($sender->asPosition()); | ||
if($plot === null){ | ||
$sender->sendMessage(TextFormat::RED . $this->translateString("notinplot")); | ||
return true; | ||
} | ||
if($plot->name === $sender->getName() and !$sender->hasPermission("myplot.admin.buy")){ | ||
$sender->sendMessage(TextFormat::RED . $this->translateString("buy.noself")); | ||
return true; | ||
} | ||
if(!$plot->isForSale()){ | ||
$sender->sendMessage(TextFormat::RED . $this->translateString("buy.notinsale")); | ||
return true; | ||
} | ||
if(!$this->getPlugin()->canBuyPlot($plot, $sender)){ | ||
$sender->sendMessage(TextFormat::RED . $this->translateString("buy.nomoney")); | ||
return true; | ||
} | ||
if(strtolower($args[0] ?? "") != $this->translateString("confirm")){ | ||
$sender->sendMessage($this->translateString("buy.confirm", [TextFormat::GREEN . "{$plot->X};{$plot->Z}" . TextFormat::RESET, TextFormat::GREEN . $plot->price . TextFormat::RESET])); | ||
return true; | ||
} | ||
$oldOwner = $this->getPlugin()->getServer()->getPlayer($plot->owner); | ||
$clone = clone $plot; | ||
$this->getPlugin()->buyPlot($plot, $sender); | ||
$sender->sendMessage($this->translateString("buy.success", [TextFormat::GREEN . "{$plot->X};{$plot->Z}" . TextFormat::RESET, TextFormat::GREEN . $clone->price . TextFormat::RESET])); | ||
if($oldOwner instanceof Player) | ||
$oldOwner->sendMessage($this->translateString("buy.sold", [TextFormat::GREEN . $sender->getName() . TextFormat::RESET, TextFormat::GREEN . "{$plot->X};{$plot->Z}" . TextFormat::RESET, TextFormat::GREEN . $clone->price . TextFormat::RESET])); | ||
return true; | ||
} | ||
|
||
public function getForm(?Player $player = null) : ?MyPlotForm { | ||
// TODO: Implement getForm() method. | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
declare(strict_types=1); | ||
namespace MyPlot\subcommand; | ||
|
||
use MyPlot\forms\MyPlotForm; | ||
use pocketmine\command\CommandSender; | ||
use pocketmine\Player; | ||
use pocketmine\utils\TextFormat; | ||
use function count; | ||
use function explode; | ||
use function is_numeric; | ||
|
||
class SellSubCommand extends SubCommand | ||
{ | ||
/** | ||
* @param CommandSender $sender | ||
* | ||
* @return bool | ||
*/ | ||
public function canUse(CommandSender $sender) : bool { | ||
return ($sender instanceof Player) and $sender->hasPermission("myplot.command.sell"); | ||
} | ||
|
||
/** | ||
* @param Player $sender | ||
* @param string[] $args | ||
* | ||
* @return bool | ||
*/ | ||
public function execute(CommandSender $sender, array $args) : bool { | ||
if($this->getPlugin()->getEconomyProvider() === null){ | ||
$sender->sendMessage("NO-ECONOMY-PLUGIN"); | ||
return true; | ||
} | ||
if(empty($args)) | ||
return false; | ||
$plot = $this->getPlugin()->getPlotByPosition($sender->asPosition()); | ||
if($plot === null){ | ||
$sender->sendMessage(TextFormat::RED . $this->translateString("notinplot")); | ||
return true; | ||
} | ||
if($plot->owner == ""){ | ||
$sender->sendMessage(TextFormat::RED . "sell.unclaimed"); | ||
return true; | ||
} | ||
if($plot->name !== $sender->getName() and !$sender->hasPermission("myplot.admin.sell")){ | ||
$sender->sendMessage(TextFormat::RED . $this->translateString("notowner")); | ||
return true; | ||
} | ||
if($plot->isForSale()){ | ||
$sender->sendMessage(TextFormat::RED . $this->translateString("sell.already")); | ||
return true; | ||
} | ||
if(!is_numeric($price = $args[0])) | ||
return false; | ||
if((float) $price <= 0){ | ||
$sender->sendMessage(TextFormat::RED . $this->translateString("sell.minprice")); | ||
return true; | ||
} | ||
$this->getPlugin()->sellPlot($plot, (float) $price); | ||
$sender->sendMessage($this->translateString("sell.success", [TextFormat::GREEN . $price . TextFormat::RESET])); | ||
return true; | ||
} | ||
|
||
public function getForm(?Player $player = null) : ?MyPlotForm { | ||
// TODO: Implement getForm() method. | ||
return null; | ||
} | ||
} |