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

Add Plot buy/selling #343

Merged
merged 31 commits into from
Oct 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
4e4052e
Add Plot Selling and Buying
DerDevHD Oct 1, 2020
2d0cb0a
Update JSON-Provider and done some fixes
DerDevHD Oct 2, 2020
5dd030c
Sorry Jason
DerDevHD Oct 2, 2020
6cad1d8
Revert "Sorry Jason"
DerDevHD Oct 2, 2020
0748172
Add Plot-Popup
DerDevHD Oct 3, 2020
0afe72d
Add german translations
DerDevHD Oct 3, 2020
e6ef831
Fix the quotes
DerDevHD Oct 4, 2020
d2d6832
fix quotes
DerDevHD Oct 4, 2020
9c8db2d
Submit requested changes
DerDevHD Oct 4, 2020
d55ca82
fix missing '='
DerDevHD Oct 4, 2020
a855666
Remove stuff which was outside of current PR
DerDevHD Oct 4, 2020
2dbf752
Only load economy related commands if economy is loaded
jasonw4331 Oct 4, 2020
5f81f32
when buying a plot without economy, refer to claim command
jasonw4331 Oct 4, 2020
923de21
Buy command changes
jasonw4331 Oct 4, 2020
7a7d67b
Sell command changes
jasonw4331 Oct 4, 2020
7dfa09c
sold plot popup changes
jasonw4331 Oct 4, 2020
14fcd7a
We don't do hypotheticals here
jasonw4331 Oct 4, 2020
8e3bf1e
Command is not registered without economy
jasonw4331 Oct 4, 2020
1fc8c30
use events in new API
jasonw4331 Oct 4, 2020
5a80add
Better doc descriptions
jasonw4331 Oct 4, 2020
5c1cdee
forgot this earlier
jasonw4331 Oct 4, 2020
30ece71
cannot sell if price is less than 0
jasonw4331 Oct 5, 2020
8da354e
We don't import functions like PocketMine
jasonw4331 Oct 5, 2020
72f8aa1
Match to master branch
jasonw4331 Oct 5, 2020
876afed
Shrinking the diff
jasonw4331 Oct 5, 2020
6dd0610
translation changes
jasonw4331 Oct 5, 2020
41accef
Shrink the diff
jasonw4331 Oct 5, 2020
cc16fa6
Updated time stamps and credit DerDevHD
jasonw4331 Oct 5, 2020
2793e6e
Load economy before commands
jasonw4331 Oct 6, 2020
18d7aa3
Display for-sale message to all except owner
jasonw4331 Oct 6, 2020
cdf9784
Display fail message when something goes wrong
jasonw4331 Oct 6, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ permissions:
default: true
myplot.command.clone:
default: true
myplot.command.sell:
default: true
myplot.command.buy:
default: true
myplot.admin:
default: op
children:
Expand Down Expand Up @@ -114,6 +118,10 @@ permissions:
default: op
myplot.admin.clone:
default: op
myplot.admin.sell:
default: op
myplot.admin.buy:
default: op
myplot.claimplots:
default: op
children:
Expand Down
24 changes: 21 additions & 3 deletions resources/deu.ini
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
; German language pack for MyPlot
; Created by SalmonDE, morpheus132 and Wertzui123
; Updated time : 1/10/2020
; Created by DerDevHD, SalmonDE, morpheus132 and Wertzui123
; Updated time : 05/10/2020

; Popup when entering a plot
popup=Du hast das Grundstück {%0} betreten
popup.owner=Dieses Grundstück gehört {%0}
popup.forsale=Dieses Plot wurde von {%0} zum Verkauf erklärt. Mit /p buy kannst du dir dieses Grundstück für {%1}$ kaufen.
popup.available=Dieses Grundstück ist verfügbar! Benutze /p claim, um es zu beanspruchen.
popup.denied=Du darfst dieses Grundstück nicht betreten!

Expand Down Expand Up @@ -238,4 +239,21 @@ kick.notInPlot=Der angegebene Spieler befindet sich nicht in deinem Plot
kick.cannotkick=Du kannst diesen Spieler nicht kicken
kick.attemptkick=Der Spieler {%0} hat versucht, dich von seinem plot zu kicken
kick.success1=Du hast erfolgreich {%0} von dem Plot {%1} gekickt
kick.success2=Der Spieler {%0} hat dich von dem Plot {%1} gekickt
kick.success2=Der Spieler {%0} hat dich von dem Plot {%1} gekickt

; the /p sell Subcommand
sell.name=sell
sell.desc=Verkaufe dein Grundstück
sell.usage=/p sell <preis: float>
sell.unclaimed=Dieses Grundstück hat keinen Besitzer
sell.success=Du hast dein Grunstück zum Kauf freigegeben (${%0})

; the /p buy Subcommand
buy.name=buy
buy.desc=Kaufe ein Grunstück
buy.usage=/p buy
buy.noself=Du kannst nicht dein eigenes Grundstück kaufen
buy.notforsale=Dieses Grundstück wird nicht verkauft
buy.confirm=Möchtest du wirklich das Grundstück {%0} für ${%1} kaufen? Um es zu bestätigen, benutze /p buy confirm
buy.success=Du hast das Grundstück {%0} erfolgreich für ${%1} erworben
buy.sold=Der Spieler {%0} hat dein Gruundstück ({%1}) für ${%2} gekauft
21 changes: 19 additions & 2 deletions resources/eng.ini
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
; English language pack for MyPlot
; Created by Wiez, Exxarion, and jasonwynn10
; Updated time : 8/26/2020
; Updated time : 10/05/2020

; Popup when entering a plot
popup=You entered plot {%0}
popup.owner=Owned by {%0}
popup.forsale=This plot is for sale by {%0}. Use /p buy to claim the plot for ${%1}.
popup.available=This plot is open. Use /p claim to claim the plot for ${%0}.
popup.denied=You are denied access to this plot

Expand Down Expand Up @@ -291,4 +292,20 @@ kick.attemptkick=Player {%0} attempt to kick you
kick.success1=You successfully kicked {%0} from plot {%1}
kick.success2=Player {%0} kicked you from plot {%1}
kick.form=Kick
kick.dropdown=Player Name
kick.dropdown=Player Name

; the /p sell Subcommand
sell.name=sell
sell.desc=Sells a plot
sell.usage=/p sell <price: float>
sell.success=Your plot {%0} is now on sale for ${%1}

; the /p buy Subcommand
buy.name=buy
buy.desc=Buys a plot
buy.usage=/p buy
buy.noself="You can't buy a plot from yourself"
buy.notforsale=This plot is not for sale
buy.confirm=Are you sure to buy plot {%0} for ${%1}? To confirm, use /p buy confirm
buy.success=You successfully bought Plot {%0} for ${%1}
buy.sold={%0} bought your Plot ({%1}) for ${%2}
19 changes: 18 additions & 1 deletion resources/langtemplate.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
; Popup when entering a plot
popup=
popup.owner=
popup.forsale=
popup.available=
popup.denied=

Expand Down Expand Up @@ -285,4 +286,20 @@ kick.attemptkick=
kick.success1=
kick.success2=
kick.form=
kick.dropdown=
kick.dropdown=

; the /p sell Subcommand
sell.name=
sell.desc=
sell.usage=
sell.success=

; the /p buy Subcommand
buy.name=
buy.desc=
buy.usage=
buy.noself=
buy.notforsale=
buy.confirm=
buy.success=
buy.sold=
6 changes: 6 additions & 0 deletions src/MyPlot/Commands.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use MyPlot\subcommand\AddHelperSubCommand;
use MyPlot\subcommand\AutoSubCommand;
use MyPlot\subcommand\BiomeSubCommand;
use MyPlot\subcommand\BuySubCommand;
use MyPlot\subcommand\ClaimSubCommand;
use MyPlot\subcommand\ClearSubCommand;
use MyPlot\subcommand\CloneSubCommand;
Expand All @@ -25,6 +26,7 @@
use MyPlot\subcommand\PvpSubCommand;
use MyPlot\subcommand\RemoveHelperSubCommand;
use MyPlot\subcommand\ResetSubCommand;
use MyPlot\subcommand\SellSubCommand;
use MyPlot\subcommand\SetOwnerSubCommand;
use MyPlot\subcommand\SubCommand;
use MyPlot\subcommand\UnDenySubCommand;
Expand Down Expand Up @@ -79,6 +81,10 @@ public function __construct(MyPlot $plugin) {
$this->loadSubCommand(new ListSubCommand($plugin, "list"));
$this->loadSubCommand(new PvpSubCommand($plugin, "pvp"));
$this->loadSubCommand(new KickSubCommand($plugin, "kick"));
if($plugin->getEconomyProvider() !== null) {
$this->loadSubCommand(new SellSubCommand($plugin, "sell"));
$this->loadSubCommand(new BuySubCommand($plugin, "buy"));
}
$styler = $this->getPlugin()->getServer()->getPluginManager()->getPlugin("WorldStyler");
if($styler !== null) {
$this->loadSubCommand(new CloneSubCommand($plugin, "clone"));
Expand Down
6 changes: 5 additions & 1 deletion src/MyPlot/EventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,11 @@ private function onEventOnMove(Player $player, $event) : void {
$popup = $this->plugin->getLanguage()->translateString("popup", [TextFormat::GREEN . $plot]);
if(!empty($plot->owner)) {
$owner = TextFormat::GREEN . $plot->owner;
$ownerPopup = $this->plugin->getLanguage()->translateString("popup.owner", [$owner]);
if($plot->price > 0 and $plot->owner !== $player->getName()) {
$ownerPopup = $this->plugin->getLanguage()->translateString("popup.forsale", [$owner.TextFormat::RESET, $plot->price]);
}else{
$ownerPopup = $this->plugin->getLanguage()->translateString("popup.owner", [$owner]);
}
}else{
$ownerPopup = $this->plugin->getLanguage()->translateString("popup.available", [$plot->price]);
}
Expand Down
83 changes: 68 additions & 15 deletions src/MyPlot/MyPlot.php
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,59 @@ public function removePlotDenied(Plot $plot, string $player) : bool {
return $this->savePlot($ev->getPlot());
}

/**
* Assigns a price to a plot
*
* @api
*
* @param Plot $plot
* @param float $price
*
* @return bool
*/
public function sellPlot(Plot $plot, float $price) : bool {
if($this->getEconomyProvider() === null or $price < 0)
return false;

$newPlot = clone $plot;
$newPlot->price = $price;
$ev = new MyPlotSettingEvent($plot, $newPlot);
$ev->call();
if($ev->isCancelled()) {
return false;
}
$plot = $ev->getPlot();
return $this->savePlot($plot);
}

/**
* Resets the price and claims a plot in a players name
*
* @api
*
* @param Plot $plot
* @param Player $player
*
* @return bool
*/
public function buyPlot(Plot $plot, Player $player) : bool {
if($this->getEconomyProvider() === null or !$this->getEconomyProvider()->reduceMoney($player, $plot->price))
return false;

$newPlot = clone $plot;
$newPlot->owner = $player->getName();
$newPlot->helpers = [];
$newPlot->denied = [];
$newPlot->price = 0.0;
$ev = new MyPlotSettingEvent($plot, $newPlot);
$ev->call();
if($ev->isCancelled()) {
return false;
}
$plot = $ev->getPlot();
return $this->savePlot($plot);
}

/**
* Returns the PlotLevelSettings of all the loaded levels
*
Expand Down Expand Up @@ -1039,20 +1092,6 @@ public function onLoad() : void {
$this->getConfig()->set("FastClearing", false);
$this->getLogger()->info(TF::BOLD . "WorldStyler not found. Legacy clearing will be used.");
}
$this->getLogger()->debug(TF::BOLD . "Loading MyPlot Commands");
// Register command
$this->getServer()->getCommandMap()->register("myplot", new Commands($this));
}

public function onEnable() : void {
if (!\class_exists(SpoonDetector::class)) {
$this->getServer()->getPluginManager()->disablePlugin($this);
return;
}
SpoonDetector::printSpoon($this, "spoon.txt");
if($this->isDisabled()) {
return;
}
$this->getLogger()->debug(TF::BOLD . "Loading economy settings");
// Initialize EconomyProvider
if($this->getConfig()->get("UseEconomy", false) === true) {
Expand All @@ -1061,14 +1100,28 @@ public function onEnable() : void {
$this->economyProvider = new EconomySProvider($plugin);
$this->getLogger()->debug("Eco set to EconomySProvider");
}else
$this->getLogger()->debug("Eco not instance of EconomyAPI");
$this->getLogger()->debug("Eco not instance of EconomyAPI");
}
if(!isset($this->economyProvider)) {
$this->getLogger()->info("No supported economy plugin found!");
$this->getConfig()->set("UseEconomy", false);
//$this->getConfig()->save();
}
}
$this->getLogger()->debug(TF::BOLD . "Loading MyPlot Commands");
// Register command
$this->getServer()->getCommandMap()->register("myplot", new Commands($this));
}

public function onEnable() : void {
if (!\class_exists(SpoonDetector::class)) {
$this->getServer()->getPluginManager()->disablePlugin($this);
return;
}
SpoonDetector::printSpoon($this, "spoon.txt");
if($this->isDisabled()) {
return;
}
$this->getLogger()->debug(TF::BOLD . "Loading Events");
$eventListener = new EventListener($this);
$this->getServer()->getPluginManager()->registerEvents($eventListener, $this);
Expand Down
7 changes: 6 additions & 1 deletion src/MyPlot/provider/SQLiteDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ public function __construct(MyPlot $plugin, int $cacheSize = 0) {
(id INTEGER PRIMARY KEY AUTOINCREMENT, level TEXT, X INTEGER, Z INTEGER, name TEXT,
owner TEXT, helpers TEXT, denied TEXT, biome TEXT, pvp INTEGER, price FLOAT);");
try{
$this->db->exec("ALTER TABLE plots ADD (pvp INTEGER, price FLOAT);");
$this->db->exec("ALTER TABLE plots ADD pvp INTEGER;");
}catch(\Exception $e) {
// nothing :P
}
try{
$this->db->exec("ALTER TABLE plots ADD price FLOAT;");
}catch(\Exception $e) {
// nothing :P
}
Expand Down
65 changes: 65 additions & 0 deletions src/MyPlot/subcommand/BuySubCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php
declare(strict_types=1);
namespace MyPlot\subcommand;

use MyPlot\forms\MyPlotForm;
use pocketmine\command\CommandSender;
use pocketmine\Player;
use pocketmine\utils\TextFormat;

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){
$command = new ClaimSubCommand($this->getPlugin(), "claim");
return $command->execute($sender, []);
}
$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->price <= 0){
$sender->sendMessage(TextFormat::RED . $this->translateString("buy.notforsale"));
return true;
}
$price = $plot->price;
if(strtolower($args[0] ?? "") !== $this->translateString("confirm")){
$sender->sendMessage($this->translateString("buy.confirm", ["{$plot->X};{$plot->Z}", $price]));
return true;
}
$oldOwner = $this->getPlugin()->getServer()->getPlayer($plot->owner);
if($this->getPlugin()->buyPlot($plot, $sender)) {
$sender->sendMessage($this->translateString("buy.success", ["{$plot->X};{$plot->Z}", $price]));
if($oldOwner !== null)
$oldOwner->sendMessage($this->translateString("buy.sold", [$sender->getName(), "{$plot->X};{$plot->Z}", $price]));
}else{
$sender->sendMessage(TextFormat::RED . $this->translateString("error"));
}
return true;
}

public function getForm(?Player $player = null) : ?MyPlotForm {
// TODO: Implement getForm() method.
return null;
}
}
Loading