Skip to content

Instantly share code, notes, and snippets.

@BEcraft
Last active January 27, 2018 00:59
Show Gist options
  • Save BEcraft/8f699c600f577a44873d83a120aa890e to your computer and use it in GitHub Desktop.
Save BEcraft/8f699c600f577a44873d83a120aa890e to your computer and use it in GitHub Desktop.
PocketMine
<?php
/**
* @name ChildTeleport
* @api 3.0.0
* @author BEcraft
* @version 1.0
* @main BEcraft\ChildTeleport\Loader
*/
namespace BEcraft\ChildTeleport;
use pocketmine\plugin\PluginBase;
use pocketmine\event\Listener;
use pocketmine\entity\Arrow;
use pocketmine\Player;
use pocketmine\entity\Entity;
use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\event\entity\EntityDamageByEntityChildEvent;
use pocketmine\level\particle\HeartParticle;
use pocketmine\event\entity\EntityShootBowEvent;
class Loader extends PluginBase implements Listener{
public function onEnable(){
$this->getServer()->getPluginManager()->registerEvents($this, $this);
}
public function onShoot(EntityShootBowEvent $event){
if(($player = $event->getEntity()) instanceof Player){
if(!$player->isSneaking()){
$event->setProjectile(new ChildArrow($player->getLevel(), $event->getProjectile()->namedtag, $player));
}
}
}
public function onDamage(EntityDamageEvent $event){
if($event->isCancelled()){
return;
}
if($event instanceof EntityDamageByEntityChildEvent and $event->getChild() instanceof ChildArrow){
$event->setCancelled();
}
}
}
class ChildArrow extends Arrow{
public function onUpdate($currentTick){
parent::onUpdate($currentTick);
if($this->onGround or $this->hadCollision){
$this->close();
}else{
if(!is_null($player = $this->getOwningEntity()) and $player instanceof Player){
$player->setMotion($this->getMotion());
$player->getLevel()->addParticle(new HeartParticle($player->add(0, 1)), $this->getViewers());
}
}
}
public function canCollideWith(Entity $entity){
return $entity !== $this->getOwningEntity();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment