1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Spawning an DropBox

Discussion in 'Development' started by WylSmart, Dec 13, 2020.

  1. WylSmart

    WylSmart Slime

    Messages:
    93
    Is there a plugin for the spawn of a drop box, so that you can set the spawn of the box by coordinates at a certain time. Drop: Items, money, enchants?
     
  2. WylSmart

    WylSmart Slime

    Messages:
    93
    Please fix me plugin AirDrop for api 3.0.0 - 1.14x - 1.16x
    https://drive.google.com/file/d/1M5Q4oXy1wbQL3q6Ad5qHYG4jYqTVac14/view?usp=sharing

    error plugin my server pmmp-1.16.200

    Code:
    [13:04:47] [Server thread/CRITICAL]: Error: "Call to undefined method pocketmine\Server::getScheduler()" (EXCEPTION) in "plugins/AirDrop.phar/src/Bestaford/AirDrop/AirDrop" at line 28
    [13:04:47] [Server thread/CRITICAL]: #0 src/pocketmine/plugin/PluginBase(116): Bestaford\AirDrop\AirDrop->onEnable()
    [13:04:47] [Server thread/CRITICAL]: #1 src/pocketmine/plugin/PluginManager(552): pocketmine\plugin\PluginBase->setEnabled(boolean 1)
    [13:04:47] [Server thread/CRITICAL]: #2 src/pocketmine/Server(1787): pocketmine\plugin\PluginManager->enablePlugin(object Bestaford\AirDrop\AirDrop)
    [13:04:47] [Server thread/CRITICAL]: #3 src/pocketmine/Server(1773): pocketmine\Server->enablePlugin(object Bestaford\AirDrop\AirDrop)
    [13:04:47] [Server thread/CRITICAL]: #4 src/pocketmine/Server(1586): pocketmine\Server->enablePlugins(integer 1)
    [13:04:47] [Server thread/CRITICAL]: #5 src/pocketmine/PocketMine(273): pocketmine\Server->__construct(object BaseClassLoader, object pocketmine\utils\MainLogger, string[19] /home/mcserver1_16/, string[27] /home/mcserver1_16/plugins/)
    [13:04:47] [Server thread/CRITICAL]: #6 src/pocketmine/PocketMine(304): pocketmine\server()
    [13:04:47] [Server thread/CRITICAL]: #7 (11): require(string[74] phar:///home/mcserver1_16/PocketMine-MP.phar/src/pocketmine/PocketMine.php)
    
    line 28
    $this->getServer()->getScheduler()->scheduleRepeatingTask(new CallbackTask(array($this, "spawnChest")), 20 * 60 * $this->config["interval"]);

    plugin code = api 3.0.1
    Code:
    <?php
    
    namespace Bestaford\AirDrop;
    
    use pocketmine\plugin\PluginBase;
    use pocketmine\utils\Config;
    use pocketmine\scheduler\CallbackTask;
    use pocketmine\math\Vector3;
    use pocketmine\block\Block;
    use pocketmine\block\Chest as ChestBlock;
    use pocketmine\tile\Tile;
    use pocketmine\tile\Chest as ChestTile;
    use pocketmine\item\Item;
    use pocketmine\nbt\tag\CompoundTag;
    use pocketmine\nbt\tag\IntTag;
    use pocketmine\nbt\tag\ListTag;
    use pocketmine\nbt\tag\StringTag;
    
    class AirDrop extends PluginBase {
       
        public $config;
        public $position;
    
        public function onEnable() {
            @mkdir($this->getDataFolder());
             $this->saveDefaultConfig();
             $this->config = (new Config($this->getDataFolder()."config.yml", Config::YAML))->getAll();
           
           
            $this->getServer()->getScheduler()->scheduleRepeatingTask(new CallbackTask(array($this, "spawnChest")), 20 * 60 * $this->config["interval"]);
        }
    
        public function spawnChest() {
            if(empty($this->config["items"])) {
                return;
            }
            $level = $this->getServer()->getDefaultLevel();
            if($this->position !== null) {
                $block = $level->getBlock($this->position);
                if($block instanceof ChestBlock) {
                    $level->setBlock($this->position, Block::get(Block::AIR));
                }
                $tile = $level->getTile($this->position);
                if($tile instanceof ChestTile) {
                    $level->removeTile($tile);
                }
            }
            $x = rand($this->config["drop_x_min"], $this->config["drop_x_max"]);
            $z = rand($this->config["drop_z_min"], $this->config["drop_z_max"]);
            if(($x > $this->config["spawn_x_min"] && $x < $this->config["spawn_x_max"]) && ($z > $this->config["spawn_z_min"] && $z < $this->config["spawn_z_max"])) {
                $distanceX = 0;
                $minX = false;
                if(($x - $this->config["spawn_x_min"]) < ($this->config["spawn_x_max"] - $x)) {
                    $distanceX = ($x - $this->config["spawn_x_min"]);
                    $minX = true;
                } else {
                    $distanceX = ($this->config["spawn_x_max"] - $x);
                }
                $distanceZ = 0;
                $minZ = false;
                if(($z - $this->config["spawn_z_min"]) < ($this->config["spawn_z_max"] - $z)) {
                    $distanceZ = ($z - $this->config["spawn_z_min"]);
                    $minZ = true;
                } else {
                    $distanceZ = ($this->config["spawn_z_max"] - $z);
                }
                if($distanceX < $distanceZ) {
                    if($minX) {
                        $x = $this->config["spawn_x_min"];
                    } else {
                        $x = $this->config["spawn_x_max"];
                    }
                } else {
                    if($minZ) {
                        $z = $this->config["spawn_z_min"];
                    } else {
                        $z = $this->config["spawn_z_max"];
                    }
                }
            }
            $y = $level->getHighestBlockAt($x, $z) + 1;
            if($y > 0 && $y < 255) {
                $chest = Tile::createTile("Chest", $level, new CompoundTag(" ", [ new ListTag("Items", []), new StringTag("id", Tile::CHEST), new IntTag("x", $x), new IntTag("y", $y), new IntTag("z", $z) ]));
                 $position = new Vector3($x, $y, $z);
                $level->setBlock($position, Block::get(Block::CHEST));
                $this->position = $position;
                 $level->addTile($chest);
                foreach($this->config["items"] as $stringId => $chance) {
                    if($chance < 0) $chance = 0;
                    if($chance > 100) $chance = 100;
                    if(rand(0, 100) <= $chance) {
                        $id = $stringId;
                        $meta = 0;
                        if(strpos($stringId, ":") !== false) {
                            $stringId = explode(":", $stringId);
                            $id = $stringId[0];
                            $meta = $stringId[1];
                        }
                        $chest->getInventory()->addItem(Item::get($id, $meta));
                    }
                }
                $message = $this->config["message"];
                $message = str_replace("{x}", $x, $message);
                $message = str_replace("{y}", $y, $message);
                $message = str_replace("{z}", $z, $message);
                $this->getServer()->broadcastMessage($message);
            } else {
                $this->spawnChest();
            }
        }
    }
     
    Last edited: Dec 13, 2020
  3. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    PHP:
    $this->getScheduler()->scheduleRepeatingTask(new CallbackTask(array($this"spawnChest")), 20 60 $this->config["interval"]);
     
  4. WylSmart

    WylSmart Slime

    Messages:
    93
    This plugin is for
    GenisysPro, can I remake it somehow for PMMP?

    Code:
    [16:19:09] [Server thread/CRITICAL]: Error: "Class 'pocketmine\scheduler\CallbackTask' not found" (EXCEPTION) in "plugins/AirDrop/src/Bestaford/AirDrop/AirDrop" at line 28
    [16:19:09] [Server thread/CRITICAL]: #0 src/pocketmine/plugin/PluginBase(116): Bestaford\AirDrop\AirDrop->onEnable()
    [16:19:09] [Server thread/CRITICAL]: #1 src/pocketmine/plugin/PluginManager(552): pocketmine\plugin\PluginBase->setEnabled(boolean 1)
    [16:19:09] [Server thread/CRITICAL]: #2 src/pocketmine/Server(1787): pocketmine\plugin\PluginManager->enablePlugin(object Bestaford\AirDrop\AirDrop)
    [16:19:09] [Server thread/CRITICAL]: #3 src/pocketmine/Server(1773): pocketmine\Server->enablePlugin(object Bestaford\AirDrop\AirDrop)
    [16:19:09] [Server thread/CRITICAL]: #4 src/pocketmine/Server(1586): pocketmine\Server->enablePlugins(integer 1)
    [16:19:09] [Server thread/CRITICAL]: #5 src/pocketmine/PocketMine(273): pocketmine\Server->__construct(object BaseClassLoader, object pocketmine\utils\MainLogger, string[19] /home/mcserver1_16/, string[27] /home/mcserver1_16/plugins/)
    [16:19:09] [Server thread/CRITICAL]: #6 src/pocketmine/PocketMine(304): pocketmine\server()
    [16:19:09] [Server thread/CRITICAL]: #7 (11): require(string[74] phar:///home/mcserver1_16/PocketMine-MP.phar/src/pocketmine/PocketMine.php)
    
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.