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

Commit

Permalink
Merge pull request #38 from KenCir:KenCir/issue36
Browse files Browse the repository at this point in the history
プレイヤー同士で送金機能 #36
  • Loading branch information
KenCir authored Jul 26, 2021
2 parents e48dc03 + 0aec929 commit 1f64687
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 29 deletions.
6 changes: 0 additions & 6 deletions .idea/sqldialects.xml

This file was deleted.

3 changes: 1 addition & 2 deletions src/OutiServerPlugin/Announce.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
use ErrorException;
use Exception;
use InvalidArgumentException;
use jojoe77777\FormAPI\ModalForm;
use jojoe77777\FormAPI\SimpleForm;
use jojoe77777\FormAPI\{ModalForm, SimpleForm};
use pocketmine\Player;
use TypeError;

Expand Down
7 changes: 2 additions & 5 deletions src/OutiServerPlugin/EventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,7 @@ private function iPhone(Player $player)

switch ($data) {
case 0:
$name = $player->getName();
$playerdata = $this->plugin->db->GetMoney($name);
if (!$playerdata) break;
$player->sendMessage("あなたの現在の所持金: " . $playerdata["money"] . "");
$this->plugin->money->Form($player);
break;
case 1:
$this->plugin->adminshop->AdminShop($player);
Expand All @@ -232,7 +229,7 @@ private function iPhone(Player $player)
});

$form->setTitle("iPhone");
$form->addButton("所持金の確認");
$form->addButton("お金関連");
$form->addButton("AdminShop");
$form->addButton("土地");
$form->addButton("テレポート");
Expand Down
19 changes: 9 additions & 10 deletions src/OutiServerPlugin/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,19 @@
use Error;
use ErrorException;
use Exception;
use TypeError;
use InvalidArgumentException;
use OutiServerPlugin\Tasks\Discord;
use OutiServerPlugin\Utils\Database;
use OutiServerPlugin\Utils\AllItem;
use OutiServerPlugin\Utils\ErrorHandler;
use OutiServerPlugin\Tasks\discord;
use OutiServerPlugin\Utils\{Database, AllItem, ErrorHandler};
use pocketmine\plugin\PluginBase;
use pocketmine\utils\Config;
use pocketmine\utils\{Config, TextFormat};
use pocketmine\command\ConsoleCommandSender;
use pocketmine\Server;
use pocketmine\scheduler\ClosureTask;
use pocketmine\utils\TextFormat;
use TypeError;

class Main extends PluginBase
{
public Discord $client;
public discord $client;
public bool $started = false;
public Database $db;
public Config $config;
Expand All @@ -35,6 +32,7 @@ class Main extends PluginBase
public Admin $admin;
public Teleport $teleport;
public Announce $announce;
public Money $money;
public ErrorHandler $errorHandler;

public function onEnable()
Expand All @@ -50,6 +48,7 @@ public function onEnable()
$this->getServer()->getPluginManager()->disablePlugin($this);
return;
}
$this->errorHandler = new ErrorHandler($this);
$this->db = new Database($this, $this->getDataFolder() . 'outiserver.db', $this->config->get("Default_Item_Category", array()));
$this->allItem = new AllItem($this, $this->getDataFolder() . "allitemdata.json");
$this->land = new Land($this);
Expand All @@ -58,8 +57,8 @@ public function onEnable()
$this->admin = new Admin($this);
$this->teleport = new Teleport($this);
$this->announce = new Announce($this);
$this->errorHandler = new ErrorHandler($this);
$this->client = new Discord($this->getFile(), $this->getDataFolder(), $token, $this->config->get("Discord_Command_Prefix", "?unko"), $this->config->get('Discord_Guild_Id', '706452606918066237'), $this->config->get('DiscordChat_Channel_Id', '834317763769925632'), $this->config->get('DiscordLog_Channel_Id', '833626570270572584'), $this->config->get('DiscordDB_Channel_Id', '863124612429381699'), $this->config->get('DiscordErrorLog_Channel_id', '868787060394307604'));
$this->money = new Money($this);
$this->client = new discord($this->getFile(), $this->getDataFolder(), $token, $this->config->get("Discord_Command_Prefix", "?unko"), $this->config->get('Discord_Guild_Id', '706452606918066237'), $this->config->get('DiscordChat_Channel_Id', '834317763769925632'), $this->config->get('DiscordLog_Channel_Id', '833626570270572584'), $this->config->get('DiscordDB_Channel_Id', '863124612429381699'), $this->config->get('DiscordErrorLog_Channel_id', '868787060394307604'));
unset($token);

$this->getServer()->getPluginManager()->registerEvents(new EventListener($this), $this);
Expand Down
80 changes: 80 additions & 0 deletions src/OutiServerPlugin/Money.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php

declare(strict_types=1);

namespace OutiServerPlugin;

use ArgumentCountError;
use Error;
use ErrorException;
use Exception;
use InvalidArgumentException;
use jojoe77777\FormAPI\{CustomForm, SimpleForm};
use pocketmine\Player;
use TypeError;

class Money
{
private Main $plugin;

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

public function Form(Player $player)
{
try {
$form = new SimpleForm(function (Player $player, $data) {
if ($data === null) return true;

switch ($data) {
case 0:
$name = $player->getName();
$playerdata = $this->plugin->db->GetMoney($name);
if (!$playerdata) break;
$player->sendMessage("あなたの現在の所持金: " . $playerdata["money"] . "");
break;
case 1:
$this->MoveMoney($player);
break;
}
return true;
});

$form->setTitle("iPhone-Money");
$form->addButton("所持金の確認");
$form->addButton("他playerにお金を転送");
$player->sendForm($form);
}
catch (Error | TypeError | Exception | ErrorException | InvalidArgumentException | ArgumentCountError $e) {
$this->plugin->errorHandler->onErrorNotPlayer($e);
}
}

private function MoveMoney(Player $player)
{
try {
$name = $player->getName();
$playermoney = $this->plugin->db->GetMoney($name);
$form = new CustomForm(function (Player $player, $data) {
if($data === null) return true;
else if(!isset($data[0]) or !is_numeric($data[1])) return true;

$name = $player->getName();
$this->plugin->db->AddMoney($data[0], (int)$data[1]);
$this->plugin->db->RemoveMoney($name, (int)$data[1]);
$player->sendMessage($data[0] . "" . $data[1] . "円転送しました");
return true;
});

$form->setTitle("Money-他プレイヤーに所持金を転送");
$form->addInput("転送先のプレイヤー名", "playername", "");
$form->addSlider("転送するお金", 1, $playermoney["money"]);
$player->sendForm($form);
}
catch (Error | TypeError | Exception | ErrorException | InvalidArgumentException | ArgumentCountError $e) {
$this->plugin->errorHandler->onError($e, $player);
}
}
}
4 changes: 1 addition & 3 deletions src/OutiServerPlugin/Tasks/discord.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@

use Discord\Exceptions\IntentException;
use Discord\Parts\Channel\{Channel, Message};
use Discord\Parts\Embed\Embed;
use Discord\Parts\User\Member;
use pocketmine\utils\TextFormat;
use React\EventLoop\Factory;
use Thread;
use Threaded;
use function RingCentral\Psr7\str;

class Discord extends Thread
class discord extends Thread
{
public string $file;
public bool $stopped = false;
Expand Down
3 changes: 1 addition & 2 deletions src/OutiServerPlugin/Teleport.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
use ErrorException;
use Exception;
use InvalidArgumentException;
use jojoe77777\FormAPI\ModalForm;
use jojoe77777\FormAPI\SimpleForm;
use jojoe77777\FormAPI\{ModalForm, SimpleForm};
use pocketmine\level\Position;
use pocketmine\Player;
use TypeError;
Expand Down
1 change: 0 additions & 1 deletion src/OutiServerPlugin/Utils/ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use OutiServerPlugin\Main;
use pocketmine\Player;
use pocketmine\utils\TextFormat;
use SQLiteException;
use TypeError;

class ErrorHandler
Expand Down

0 comments on commit 1f64687

Please sign in to comment.