Last active
September 5, 2018 20:27
-
-
Save BEcraft/7d08df59541e356848e95ccbc8e133fe to your computer and use it in GitHub Desktop.
PocketMine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @name PaintBall | |
* @author BEcraft | |
* @api 3.0.0 | |
* @main BEcraft\Paintball\Loader | |
* @version 1.0 | |
*/ | |
namespace BEcraft\PaintBall; | |
use pocketmine\plugin\PluginBase; | |
use pocketmine\event\Listener; | |
use pocketmine\block\Block; | |
use pocketmine\entity\Snowball; | |
use pocketmine\Player; | |
use pocketmine\math\Vector3; | |
use pocketmine\event\entity\ProjectileHitEvent; | |
class Loader extends PluginBase implements Listener{ | |
public function onEnable(){ | |
$this->getServer()->getPluginManager()->registerEvents($this, $this); | |
} | |
public function onHit(ProjectileHitEvent $event){ | |
if(($snowball = $event->getEntity()) instanceof Snowball){ | |
if(($player = $snowball->getOwningEntity()) instanceof Player){ | |
$block = $player->getLevel()->getBlock(new Vector3($snowball->getX(), $snowball->getY(), $snowball->getZ())); | |
$blocks = []; | |
if($block->getId() === Block::AIR){ | |
for($i = 0; $i < 6; ++$i){ | |
if(($block = $block->getSide($i))->getId() !== Block::AIR){ | |
break; | |
} | |
} | |
} | |
if($block->getId() === Block::AIR){ | |
return false; | |
} | |
for($x = $block->getX()-1; $x < $block->getX()+1; ++$x){ | |
for($y = $block->getY()-1; $y < $block->getY()+1; ++$y){ | |
for($z = $block->getZ()-1; $z < $block->getZ()+1; ++$z){ | |
if($this->rightBlock($newBlock = $player->getLevel()->getBlock(new Vector3($x, $y, $z)))){ | |
array_push($blocks, $newBlock); | |
} | |
} | |
} | |
} | |
if(!empty($blocks)){ | |
unset($block); | |
$wool = Block::get(Block::WOOL, mt_rand(0, 15)); | |
foreach($blocks as $block){ | |
$player->getLevel()->setBlock(new Vector3($block->getX(), $block->getY(), $block->getZ()), $wool); | |
} | |
unset($wool); | |
unset($blocks); | |
} | |
} | |
} | |
} | |
private function rightBlock(Block $block): bool{ | |
return in_array($block->getId(), [Block::GRASS, Block::DIRT, Block::SAND, Block::CLAY_BLOCK, Block::WOOL]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment