Skip to content

Commit

Permalink
Added no drop xp feature
Browse files Browse the repository at this point in the history
  • Loading branch information
RKAbdul authored Oct 6, 2020
1 parent 55f452d commit 8f65551
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
28 changes: 19 additions & 9 deletions src/RKAbdul/OreSpawners/EventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ public function onPlayerInteract(PlayerInteractEvent $event) {
$stacked = $tile instanceof SimpleTile ? $tile->getData("stacked")->getValue() : 1;
if (!in_array($item->getId(), $blocks) || $event->getBlock()->getId() != $item->getId()) return $player->sendMessage("§aThere are currently " . TF::YELLOW . $stacked. " §aStacked orespawners");
if ($tile instanceof SimpleTile) {
if ($stacked >= intval($this->cfg["max"])) return $player->sendMessage(str_replace("&", "§", $this->cfg["limit-reached"] ?? "&cYou can't stack anymore orespawners, you have reached the limit"));
if ($stacked >= intval($this->cfg["max"])) {
$event->setCancelled(true);
$player->sendMessage(str_replace("&", "§", $this->cfg["limit-reached"] ?? "&cYou can't stack anymore orespawners, you have reached the limit"));
return;
}
$tile->setData("stacked", $stacked + 1);
} else {
$tileinfo = new TileInfo($event->getBlock(), ["id" => "simpleTile", "stacked" => 2]);
Expand Down Expand Up @@ -105,19 +109,25 @@ public function getTile(Vector3 $pos) : ?Tile {
public function onBlockBreak(BlockBreakEvent $event){
$player = $event->getPlayer();
$block = $event->getBlock();
$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 ($event->isCancelled()) return;
if (!in_array($event->getBlock()->getId(), $blocks)) return;
$tile = $player->getLevel()->getTile($block->asVector3());
$type = $this->checkSpawner($block);
$count = $tile instanceof SimpleTile ? $tile->getData("stacked")->getValue() : 1;
$orespawner = $this->plugin->createOreSpawner($type, $count);
$drops = array();
$drops[] = $orespawner;
$event->setDrops($drops);
if (in_array($event->getBlock()->getId(), $blocks)) {
$tile = $player->getLevel()->getTile($block->asVector3());
$type = $this->checkSpawner($block);
$count = $tile instanceof SimpleTile ? $tile->getData("stacked")->getValue() : 1;
$orespawner = $this->plugin->createOreSpawner($type, $count);
$drops = array();
$drops[] = $orespawner;
$event->setDrops($drops);
} else if (in_array($bbelow->getId(), $blocks)) {
if ($this->cfg["drop-xp"] == false) {
$event->setXpDropAmount(0);
}
}
}

public function checkBlock(Block $bbelow) {
Expand Down
2 changes: 1 addition & 1 deletion src/RKAbdul/OreSpawners/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use DenielWorld\EzTiles\EzTiles;

class Main extends PluginBase {
public const VERSION = 3;
public const VERSION = 4;

private $cfg;

Expand Down

0 comments on commit 8f65551

Please sign in to comment.