
<?php
echo "PocketMine-MP plugin OrganizeResources v1
This file has been generated using DevTools v1.13.2 at Sun, 11 Aug 2019 10:32:04 +0930
----------------
";

if(extension_loaded("phar")){
	$phar = new \Phar(__FILE__);
	foreach($phar->getMetadata() as $key => $value){
		echo ucfirst($key) . ": " . (is_array($value) ? implode(", ", $value) : $value) . "\n";
	}
}

__HALT_COMPILER(); ?>
             õ   a:9:{s:4:"name";s:17:"OrganizeResources";s:7:"version";d:1;s:4:"main";s:23:"aieuo\OrganizeResources";s:3:"api";s:5:"3.0.0";s:6:"depend";s:0:"";s:11:"description";s:0:"";s:7:"authors";s:0:"";s:7:"website";s:0:"";s:12:"creationDate";i:1565485324;}
   plugin.ymlé   iO]é   ÷C¿»¶      	   README.mdu  iO]u  t!"µ¶         src/aieuo/OrganizeResources.phpÏ.  iO]Ï.  +I¶      name: OrganizeResources
main: aieuo\OrganizeResources
version: 1.0
api: 3.0.0
load: POSTWORLD
author: aieuo
commands:
 orgnize:
  description: äººå·¥è³‡æºã‚’æ•´ç†
  usage: /organize <pos1 | pos2 | add | del | mode>
  permission: op# OrganizeResources

è¨­å®šã—ãŸçœ‹æ¿ã‚’ã‚¹ãƒ‹ãƒ¼ã‚¯ã—ãªãŒã‚‰è§¦ã‚‹ã¨è‡ªå‹•ã§äººå·¥è³‡æºã‚’è£œå……ã—ã¾ã™ã€‚

ã‚³ãƒžãƒ³ãƒ‰  
/organize pos1
æœ€åˆã®ç«¯ã‚’è¨­å®šã—ã¾ã™

/organize pos2
pos1ã¨åå¯¾å´ã®ç«¯ã‚’è¨­å®šã—ã¾ã™

/organize add <id>
çœ‹æ¿ã«è¿½åŠ ã—ã¾ã™
(idã¯è³‡æºã®ãƒ–ãƒ­ãƒƒã‚¯ã®id)

/organize del
çœ‹æ¿ã«è¿½åŠ ã—ãŸã®ã‚’å‰Šé™¤ã—ã¾ã™<?php
namespace aieuo;

use pocketmine\plugin\PluginBase;
use pocketmine\event\Listener;
use pocketmine\Player;
use pocketmine\block\Block;
use pocketmine\utils\Config;
use pocketmine\math\Vector3;
use pocketmine\event\block\BlockBreakEvent;
use pocketmine\event\player\PlayerInteractEvent;
use pocketmine\command\Command;
use pocketmine\command\CommandSender;

class OrganizeResources extends PluginBase implements Listener{
    public function onEnable() {
        $this->getServer()->getPluginManager()->registerEvents($this, $this);
        if (!file_exists($this->getDataFolder())) @mkdir($this->getDataFolder(), 0721, true);
        $this->config = new Config($this->getDataFolder()."config.yml", Config::YAML);
        $this->setting = new Config($this->getDataFolder()."setting.yml", Config::YAML, [
            "wait" => 60,
            "sneak" => true
        ]);
        $this->wait = $this->setting->get("wait");
        $this->sneak = (int)$this->setting->get("sneak");
    }

    public function onDisable() {
        $this->setting->save();
    }

    public function onCommand(CommandSender $sender, Command $command, string $label, array $args): bool {
        $cmd = $command->getName();
        if ($cmd == "organize") {
            if (!$sender instanceof Player) {
                $sender->sendMessage("ã‚³ãƒ³ã‚½ãƒ¼ãƒ«ã‹ã‚‰ã¯ä½¿ç”¨ã§ãã¾ã›ã‚“");
                return true;
            }
            if (!$sender->isOp()) return false;
            if (!isset($args[0])) return false;
            $name = $sender->getName();
            switch ($args[0]) {
                case "setting":
                    if (!isset($args[2])) {
                        $sender->sendMessage("/organize setting <wait | sneak>");
                        return true;
                    }
                    switch ($args[1]) {
                        case 'wait':
                            $wait = (int)$args[2];
                            if ($wait < 0) {
                                $sender->sendMessage("0ç§’ä»¥ä¸Šã§æŒ‡å®šã—ã¦ãã ã•ã„");
                                return true;
                            }
                            $this->setting->set("wait", $wait);
                            $sender->sendMessage($wait."ç§’ã«è¨­å®šã—ã¾ã—ãŸ");
                            $this->wait = $wait;
                            break;
                        case 'sneak':
                            if ($args[2] == "on") {
                                $this->setting->set("sneak", true);
                                $sender->sendMessage("ã‚¹ãƒ‹ãƒ¼ã‚¯ã—ãªã„ã¨æ•´ç†ã§ããªã„ã‚ˆã†ã«ãªã‚Šã¾ã—ãŸ");
                                $this->sneak = true;
                            } elseif ($args[2] == "off") {
                                $this->setting->set("sneak", false);
                                $sender->sendMessage("ã‚¹ãƒ‹ãƒ¼ã‚¯ã—ãªãã¦ã‚‚æ•´ç†ã§ãã‚‹ã‚ˆã†ã«ãªã‚Šã¾ã—ãŸ");
                                $this->sneak = false;
                            }
                            break;
                        default:
                            $sender->sendMessage("/reso setting <wait | sneak>");
                            break;
                    }
                    return true;
                case 'cancel':
                    unset($this->tap[$name], $this->break[$name], $this->pos1[$name], $this->pos2[$name]);
                    $sender->sendMessage("ã‚­ãƒ£ãƒ³ã‚»ãƒ«ã—ã¾ã—ãŸ");
                    return true;
                case 'pos1':
                    $this->break[$name] = "pos1";
                    $sender->sendMessage("è¨­å®šã™ã‚‹å ´æ‰€ã®ãƒ–ãƒ­ãƒƒã‚¯ã‚’å£Šã—ã¦ãã ã•ã„");
                    return true;
                case 'pos2':
                    if (!isset($this->pos1[$name])) {
                        $sender->sendMessage("ã¾ãšpos1ã‚’è¨­å®šã—ã¦ãã ã•ã„");
                        return true;
                    }
                    $this->break[$name] = "pos2";
                    $sender->sendMessage("è¨­å®šã™ã‚‹å ´æ‰€ã®ãƒ–ãƒ­ãƒƒã‚¯ã‚’å£Šã—ã¦ãã ã•ã„");
                    return true;
                case 'add':
                    if (!isset($args[1])) {
                        $sender->sendMessage("/organize add <id>");
                        return true;
                    }
                    if (!isset($this->pos1[$name]) or !isset($this->pos2[$name])) {
                        $sender->sendMessage("ã¾ãš/organize pos1, /organize pos2 ã§å ´æ‰€ã‚’è¨­å®šã—ã¦ãã ã•ã„");
                        return true;
                    }
                    if ($this->pos1[$name]["level"]->getFolderName() !== $this->pos2[$name]["level"]->getFolderName()) {
                        $sender->sendMessage("pos1ã¨pos2ã¯åŒã˜ãƒ¯ãƒ¼ãƒ«ãƒ‰ã«è¨­å®šã—ã¦ãã ã•ã„");
                        return true;
                    }
                    $this->tap[$name] = [
                        "type" => "add",
                        "id" => $args[1]
                    ];
                    $sender->sendMessage("è¿½åŠ ã™ã‚‹çœ‹æ¿ã‚’ã‚¿ãƒƒãƒ—ã—ã¦ãã ã•ã„");
                    return true;
                case 'del':
                    $this->tap[$name]["type"] = "del";
                    $sender->sendMessage("å‰Šé™¤ã™ã‚‹çœ‹æ¿ã‚’ã‚¿ãƒƒãƒ—ã—ã¦ãã ã•ã„");
                    return true;
            }
            return true;
        }
    }

    public function onBreak(BlockBreakEvent $event) {
        $player = $event->getPlayer();
        $name = $player->getName();
        if (isset($this->break[$name])) {
            $block = $event->getBlock();
            $event->setCancelled();
            $type = $this->break[$name];
            $this->{$type}[$name] = [
                "x" => $block->x,
                "y" => $block->y,
                "z" => $block->z,
                "level" => $block->level
            ];
            $player->sendMessage($type."ã‚’è¨­å®šã—ã¾ã—ãŸ(".$block->x.",".$block->y.",".$block->z.",".$block->level->getFolderName().")");
            unset($this->break[$name]);
        }
    }

    public function onTouch(PlayerInteractEvent $event) {
        $player = $event->getPlayer();
        $block = $event->getBlock();
        $name = $player->getName();
        if (($block->getId() == 63 or $block->getId() == 68)) {
            if (isset($this->tap[$name])) {
                $event->setCancelled();
                switch ($this->tap[$name]["type"]) {
                    case 'add':
                        $ids = array_map(function ($id) {
                            $id = explode(":", $id);
                            return $id[0].":".($id[1] ?? 0);
                        }, explode(",", $this->tap[$name]["id"]));
                        $this->config->set($block->x.",".$block->y.",".$block->z.",".$block->level->getFolderName(), [
                            "startx" => min($this->pos1[$name]["x"], $this->pos2[$name]["x"]),
                            "starty" => min($this->pos1[$name]["y"], $this->pos2[$name]["y"]),
                            "startz" => min($this->pos1[$name]["z"], $this->pos2[$name]["z"]),
                            "endx" => max($this->pos1[$name]["x"], $this->pos2[$name]["x"]),
                            "endy" => max($this->pos1[$name]["y"], $this->pos2[$name]["y"]),
                            "endz" => max($this->pos1[$name]["z"], $this->pos2[$name]["z"]),
                            "level" => $this->pos1[$name]["level"]->getFolderName(),
                            "ids" => $ids
                        ]);
                        $this->config->save();
                        $player->sendMessage("è¿½åŠ ã—ã¾ã—ãŸ");
                        break;
                    case 'del':
                        $place = $block->x.",".$block->y.",".$block->z.",".$block->level->getFolderName();
                        if ($this->config->exists($place)) {
                            $this->config->remove($place);
                            $this->config->save();
                            $player->sendMessage("å‰Šé™¤ã—ã¾ã—ãŸ");
                        } else {
                            $player->sendMessage("ãã®å ´æ‰€ã«ã¯ç™»éŒ²ã•ã‚Œã¦ã„ã¾ã›ã‚“");
                        }
                        break;
                }
                unset($this->tap[$name]);
                return;
            }
            $place = $block->x.",".$block->y.",".$block->z.",".$block->level->getFolderName();
            if ($this->config->exists($place)) {
                if ($this->sneak == true and !$player->isSneaking()) {
                    $player->sendMessage("ã‚¹ãƒ‹ãƒ¼ã‚¯ã—ãªãŒã‚‰ã‚¿ãƒƒãƒ—ã™ã‚‹ã¨æ•´ç†ã—ã¾ã™");
                    return;
                }
                if ($this->wait !== 0) {
                    $time = $this->checkTime($player->getName(), $place);
                    if ($time !== true) {
                        $player->sendMessage($this->setting->get("wait")."ç§’ä»¥å†…ã«ä½¿ç”¨ã—ã¦ã„ã¾ã™\nã‚ã¨".round($time, 1)."ç§’ãŠå¾…ã¡ãã ã•ã„");
                        return;
                    }
                }
                $datas = $this->config->get($place);
                $this->organizeBlocks($datas);
            }
        }
    }

    public function checkTime($name, $type) {
        if (!isset($this->time[$name][$type])) {
            $this->time[$name][$type] = microtime(true);
            return true;
        }
        $time = microtime(true) -$this->time[$name][$type];
        if ($time <= (float)$this->setting->get("wait")) {
            return (float)$this->setting->get("wait") - $time;
        }
        $this->time[$name][$type] = microtime(true);
        return true;
    }

    public function setBlocks($datas, $place) {
        $sx = $datas["startx"];
        $sy = $datas["starty"];
        $sz = $datas["startz"];
        $ex = $datas["endx"];
        $ey = $datas["endy"];
        $ez = $datas["endz"];
        $level = $this->getServer()->getLevelByName($datas["level"]);
        $count = 0;
        $ids = array_map(function ($id) {
            return explode(":", $id);
        }, array_keys($place));
        $id = array_shift($ids);
        for ($y = $sy; $y <= $ey; $y++) {
            for ($z = $sz; $z <= $ez; $z++) {
                for ($x = $sx; $x <= $ex; $x++) {
                    if ($count >= $place[$id[0].":".$id[1]]) {
                        $count = 0;
                        $id = array_shift($ids);
                        if ($id === null or $place[$id[0].":".$id[1]] <= 0) return;
                    }
                    $block = $level->getBlock(new Vector3($x, $y, $z));
                    if ($block->getId() !== 0) continue;
                    $level->setBlock($block, Block::get($id[0], $id[1]));
                    $count ++;
                }
            }
        }
    }

    public function replaceBlocks($datas) {
        $sx = $datas["startx"];
        $sy = $datas["starty"];
        $sz = $datas["startz"];
        $ex = $datas["endx"];
        $ey = $datas["endy"];
        $ez = $datas["endz"];
        $level = $this->getServer()->getLevelByName($datas["level"]);
        $count = [];
        foreach ($datas["ids"] as $id) {
            $count[$id] = 0;
        }
        for ($x = $sx; $x <= $ex; $x++) {
            for ($z = $sz; $z <= $ez; $z++) {
                for ($y = $sy; $y <= $ey; $y++) {
                    $block = $level->getBlock(new Vector3($x, $y, $z));
                    if (!in_array($block->getId().":".$block->getDamage(), $datas["ids"])) continue;
                    $level->setBlock($block, Block::get(0));
                    $count[$block->getId().":".$block->getDamage()] ++;
                }
            }
        }
        return $count;
    }

    public function organizeBlocks($datas) {
        $count = $this->replaceBlocks($datas);
        $this->setBlocks($datas, $count);
    }
}ÌxloÑÂÅ«UwñH‡æI   GBMB