Skip to content

Instantly share code, notes, and snippets.

@ifvictr
Last active June 12, 2016 00:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ifvictr/47b77cb79cac21ad6343cbe80d8fbbc4 to your computer and use it in GitHub Desktop.
Save ifvictr/47b77cb79cac21ad6343cbe80d8fbbc4 to your computer and use it in GitHub Desktop.
KillCMD for PocketMine-MP.
<?php
/**
* @name KillCMD
* @main killcmd\KillCMD
* @version 1.0.0
* @api 1.12.0
* @load POSTWORLD
* @author Gamecrafter
* @description Do stuff when a player kills another player!
* @link https://gist.github.com/Gamecrafter/47b77cb79cac21ad6343cbe80d8fbbc4
*/
namespace killcmd{
use pocketmine\event\entity\EntityDamageByEntityEvent;
use pocketmine\event\player\PlayerDeathEvent;
use pocketmine\event\Listener;
use pocketmine\plugin\PluginBase;
use pocketmine\utils\Config;
use pocketmine\Player;
class KillCMD extends PluginBase implements Listener{
public function onEnable(){
@mkdir($this->getDataFolder());
$this->config = new Config($this->getDataFolder()."config.yml", Config::YAML, [
"commands" => [
"give {PLAYER_KILLER} 264 1",
"say {PLAYER_KILLER} killed {PLAYER_VICTIM}!",
"tell {PLAYER_KILLER} Good job, keep it up!"
]
]);
$this->getServer()->getPluginManager()->registerEvents($this, $this);
}
/**
* @param PlayerDeathEvent $event
* @priority HIGHEST
*/
public function onPlayerDeath(PlayerDeathEvent $event){
if(($entity = $event->getEntity()) instanceof Player and ($cause = $event->getEntity()->getLastDamageCause()) instanceof EntityDamageByEntityEvent){
if(($damager = $cause->getDamager()) instanceof Player){
foreach($this->getConfig()->get("commands") as $command){
$this->getServer()->dispatchCommand(new ConsoleCommandSender(), str_replace(
["{PLAYER_KILLER}", "{PLAYER_VICTIM}"],
[$damager->getName(), $entity->getName()],
$command
));
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment