Skip to content

Commit

Permalink
Add files to this repository
Browse files Browse the repository at this point in the history
  • Loading branch information
VeronicaDiazTaylor committed Apr 27, 2018
1 parent a828be7 commit fa88b83
Show file tree
Hide file tree
Showing 5 changed files with 551 additions and 0 deletions.
11 changes: 11 additions & 0 deletions plugin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: EconomySignBusiness
main: economysignbusiness\Main
version: 1.3
api:
- 3.0.0
- 3.0.0-ALPHA11
- 3.0.0-ALPHA12
depend: [EconomyAPI]
prefix: 看板ビジネス
load: POSTWORLD
author: OtorisanVardo
199 changes: 199 additions & 0 deletions src/economysignbusiness/EventListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
<?php

namespace economysignbusiness;

use pocketmine\event\Listener;
use pocketmine\event\player\PlayerInteractEvent;
use pocketmine\event\block\SignChangeEvent;
use pocketmine\event\block\BlockBreakEvent;
use pocketmine\item\Item;
use pocketmine\tile\Sign;

use economysignbusiness\utils\API;
use economysignbusiness\utils\NameManager;
use onebone\economyapi\EconomyAPI;

class EventListener implements Listener
{

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


public function onTap(PlayerInteractEvent $event)
{
$player = $event->getPlayer();
$block = $event->getBlock();
if (!in_array($block->getId(), API::BLOCK_SIGN)) return;
$tile = $player->getLevel()->getTile($block);
if ($tile instanceof Sign) {
$line = $tile->getText();
if (!isset($line[0])) return;
$tag = $line[0];
if ($tag !== API::PURCHASE_TAG && $tag !== API::SELL_TAG && $tag !== API::EXCHANGE_TAG) {
return;
}
$unit = EconomyAPI::getInstance()->getMonetaryUnit();

if (!isset($player->cooltime)) {
$this->getApi()->checkDoProgress($player, $block);
return;
}
if ($block->asVector3() != $player->cooltime) {
$this->getApi()->checkDoProgress($player, $block);
return;
}
unset($player->cooltime);
switch ($line[0]) {
case API::PURCHASE_TAG:
$this->getApi()->purchaseItem($player, $block);
break;

case API::SELL_TAG:
$this->getApi()->sellItem($player, $block);
break;

case API::EXCHANGE_TAG:
$this->getApi()->exchangeItem($player, $block);
break;
}
}
}


public function onBreak(BlockBreakEvent $event)
{
$player = $event->getPlayer();
$block = $event->getBlock();
if (!in_array($block->getId(), API::BLOCK_SIGN)) return;
$tile = $player->getLevel()->getTile($block);
if ($tile instanceof Sign) {
$line = $tile->getText();
if (!isset($line[0])) return;
$tag = $line[0];
if ($tag !== API::PURCHASE_TAG && $tag !== API::SELL_TAG && $tag !== API::EXCHANGE_TAG) {
return;
}
if (!$player->isOp()) return;
switch ($line[0]) {
case API::PURCHASE_TAG:
case API::SELL_TAG:
case API::EXCHANGE_TAG:
$this->getProvider()->removeShopData($block);
$player->sendMessage("§a> 削除しました");
break;
}
}
}


public function onChange(SignChangeEvent $event)
{
$player = $event->getPlayer();
$line = $event->getLines();
if (empty($line[0])) return;
if (empty($line[1])) return;
if (empty($line[2])) return;
if (!in_array($line[0], API::REQUIRE_FIRST_LINE)) return;
if (!$player->isOp()) {
$player->sendMessage("§c> 製作できる権限がありません");
return;
}
switch ($line[0]) {
case "buy":
case "purchase":
if (empty($line[3])) return;
$item = explode(":", $line[1]);
if (count($item) == 1) $item[1] = 0;
if (!ctype_digit($item[0])) {
$player->sendMessage("§c> ID(数字)を書き込んでください");
return;
}
$itemName = Item::get((int)$item[0], (int)$item[1])->getName();
if (!ctype_digit($line[2])) {
$player->sendMessage("§c> 数値を書き込んでください");
return;
}
$amount = (int) $line[2];
$unit = EconomyAPI::getInstance()->getMonetaryUnit();
if (!ctype_digit($line[3])) {
$player->sendMessage("§c> 数値を書き込んでください");
return;
}
$price = (int) $line[3];
$event->setLine(0, API::PURCHASE_TAG);
$event->setLine(1, "§l".$itemName);
$event->setLine(2, "§l".$amount);
$event->setLine(3, "§l".$unit.$price);
$this->getProvider()->setShopDataOfSellAndPurchase($event->getBlock(), $item[0], $item[1], $amount, $price);
$player->sendMessage("§a> 販売看板を作りました");
break;

case "sell":
if (empty($line[3])) return;
$item = explode(":", $line[1]);
if (count($item) == 1) $item[1] = 0;
if ($item[1] == null) {
$player->sendMessage("§c> しっかりとID:METAの形で書き込んでください");
return;
}
$itemName = Item::get((int)$item[0], (int)$item[1])->getName();
if (!ctype_digit($line[2])) {
$player->sendMessage("§c> 数値を書き込んでください");
return;
}
$amount = (int) $line[2];
$unit = EconomyAPI::getInstance()->getMonetaryUnit();
if (!ctype_digit($line[3])) {
$player->sendMessage("§c> 数値を書き込んでください");
return;
}
$price = (int) $line[3];
$event->setLine(0, API::SELL_TAG);
$event->setLine(1, "§l".$itemName);
$event->setLine(2, "§l".$amount);
$event->setLine(3, "§l".$unit.$price);
$this->getProvider()->setShopDataOfSellAndPurchase($event->getBlock(), $item[0], $item[1], $amount, $price);
$player->sendMessage("§a> 売却看板を作りました");
break;

case "exchange":
case "trade":
$material = explode(":", $line[1]);
$goods = explode(":", $line[2]);
if (count($material) < 3) return;
$materialItem = Item::get((int)$material[0], (int)$material[1])->getName();
if (count($goods) < 3) return;
$goodsItem = Item::get((int)$goods[0], (int)$goods[1])->getName();
$event->setLine(0, API::EXCHANGE_TAG);
$event->setLine(1, "§l送: ".$materialItem." ".$material[2]."");
$event->setLine(2, "§l受: ".$goodsItem." ".$goods[2]."");
if (!ctype_digit($goods[2])) return;
$this->getProvider()->setShopDataOfExchange($event->getBlock(), $material[0], $material[1], $material[2], $goods[0], $goods[1], $goods[2]);
$player->sendMessage("§a> トレード看板を作りました");
break;
}
}

public function getServer()
{
return $this->owner->getServer();
}

public function getOwner()
{
return $this->owner;
}

public function getApi()
{
return $this->owner->api;
}

public function getProvider()
{
return $this->owner->provider;
}
}
46 changes: 46 additions & 0 deletions src/economysignbusiness/Main.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace economysignbusiness;

use pocketmine\Player;
use pocketmine\Server;
use pocketmine\utils\Config;
use pocketmine\plugin\PluginBase;

use economysignbusiness\utils\API;
use economysignbusiness\utils\Provider;
use economysignbusiness\EventListener;

class Main extends PluginBase
{
public function onEnable()
{
$this->api = new API($this);
$this->provider = new Provider($this);
$this->provider->openYaml();
$this->getServer()->getPluginManager()->registerEvents(new EventListener($this), $this);
$version = $this->getDescription()->getVersion();
$this->getLogger()->info("§6EconomySignBusiness §ev".$version);
$this->getLogger()->info("§a製作者§2: §aOtorisanVardo");
$this->getLogger()->info("§aTwitter§2: §ahttps://twitter.com/10ripon_obs");
$this->getLogger()->info("§aForum§2: §ahttps://forum.mcbe.jp/members/17/");
$this->getLogger()->info("§aLobi§2: §ahttps://web.lobi.co/user/ef7f70cd4c8c7e04dbf0f424d1f271a7ba68fc9f");
$this->getLogger()->info("§2このプラグインにおいて何らかの問題が発生した場合は");
$this->getLogger()->info("§2上記のツイッターかフォーラム、Lobiに連絡をお願いします。");
}

public function onDisable()
{
$this->provider->closeYaml();
}

public function getApi()
{
return $this->api;
}

public function getProvider()
{
return $this->provider;
}
}
Loading

0 comments on commit fa88b83

Please sign in to comment.