Skip to content

Commit

Permalink
Merge pull request #1 from AGTHARN/master
Browse files Browse the repository at this point in the history
  • Loading branch information
RKAbdul authored Sep 13, 2020
2 parents ec7d935 + 74f2fb0 commit 119fb9d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 40 deletions.
4 changes: 2 additions & 2 deletions plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: OreSpawners
version: 0.1
version: 0.2
main: RKAbdul\OreSpawners\Main
api: 3.0.0

Expand All @@ -8,4 +8,4 @@ commands:
description: Give ore spawner.
usage: "/orespawner [ore] [amount] [player]"
aliases: ["os"]
permission: "orespawner.give"
permission: "orespawner.give"
58 changes: 20 additions & 38 deletions src/RKAbdul/OreSpawners/EventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
use pocketmine\Server;
use pocketmine\utils\Config;
use pocketmine\item\Item;
use pocketmine\event\block\BlockBreakEvent;
use pocketmine\event\block\BlockPlaceEvent;
use pocketmine\event\block\BlockUpdateEvent;
use pocketmine\block\Block;

class EventListener implements Listener{
Expand All @@ -28,43 +27,27 @@ public function __construct(Main $plugin){
$this->plugin = $plugin;
$this->cfg = $this->plugin->getConfig()->getAll();
}
public function onBlockBreak(BlockBreakEvent $event){
public function onBlockUpdate(BlockUpdateEvent $event){
$block = $event->getBlock();
$bbelow = $event->getPlayer()->getLevel()->getBlock($event->getBlock()->floor()->down(1));
$bbelow = $block->getLevel()->getBlock($event->getBlock()->floor()->down(1));
$blocks = [];
foreach(array_values($this->plugin->getConfig()->get("ore-generator-blocks")) as $blockID){
array_push($blocks, $blockID);
};
if (in_array($bbelow->getId(), $blocks)) {
$ore = $this->checkBlock($bbelow);
if (!$event->isCancelled()) {
$this->plugin->getScheduler()->scheduleDelayedTask(new ClosureTask( function (int $currentTick) use ($event, $ore): void {
$event->getPlayer()->getLevel()->setBlock($event->getBlock()->floor(), $ore);
}), 20 * intval($this->cfg["delay"]));
}
}

}

public function onBlockPlace(BlockPlaceEvent $event){
$block = $event->getBlock();
$babove = $event->getPlayer()->getLevel()->getBlock($event->getBlock()->floor()->up(1));
if ($babove->getId() == 0) {
$blocks = [];
foreach(array_values($this->plugin->getConfig()->get("ore-generator-blocks")) as $blockID){
array_push($blocks, $blockID);
};
if (in_array($block->getId(), $blocks)) {
$ore = $this->checkBlock($block);
if (!$event->isCancelled()) {
$this->plugin->getScheduler()->scheduleDelayedTask(new ClosureTask( function (int $currentTick) use ($event, $ore): void {
$event->getPlayer()->getLevel()->setBlock($event->getBlock()->floor()->up(1), $ore);
}), 20 * intval($this->cfg["delay"]));
}
}
}
}

foreach(array_values($this->plugin->getConfig()->get("ore-generator-blocks")) as $blockID){
array_push($blocks, $blockID);
};
if (in_array($bbelow->getId(), $blocks)) {
$ore = $this->checkBlock($bbelow);
if (!$event->isCancelled()) {
if ($event->getBlock()->getId() == $ore->getId()) return;
$this->plugin->getScheduler()->scheduleDelayedTask(new ClosureTask( function (int $currentTick) use ($event, $ore): void {
if ($event->getBlock()->getLevel() !== null){
$event->getBlock()->getLevel()->setBlock($event->getBlock()->floor(), $ore, false, true);
}
}), 20 * intval($this->cfg["delay"]));
}
}
}

public function checkBlock(Block $bbelow) {
$bbid = $bbelow->getID();
Expand Down Expand Up @@ -101,4 +84,3 @@ public function checkBlock(Block $bbelow) {
return $ore;
}
}

0 comments on commit 119fb9d

Please sign in to comment.