<?php

namespace DeathParticle;

use pocketmine\plugin\PluginBase;
use pocketmine\event\player\PlayerDeathEvent as death;
use pocketmine\Player;
use pocketmine\utils\Config;
use pocketmine\event\Listener;
use pocketmine\command\Command;
use pocketmine\command\CommandSender;
use pocketmine\level\particle\FlameParticle;
use pocketmine\level\particle\WaterParticle;
use pocketmine\level\particle\PortalParticle;
use pocketmine\math\Vector3;

class Scrimer extends PluginBase implements Listener{
	
	public function onEnable(){
     $this->getServer()->getPluginManager()->registerEvents($this, $this);
	}

public function cfg(){
$p = $this->getDataFolder();
@mkdir($p);
$cfg = new Config("{$p}config.yml", Config::YAML);
return $cfg;
}

public function onCommand(CommandSender $p, Command $cmd, $label, array $args){
if($cmd == "d"){
if(!($p instanceof Player)) return $p->sendMessage("§c» §fOnly in game!");
$pr = "§a»";
if(count($args) != 1) return $p->sendMessage("§a» §fDeath effects: §ewater, flame, portal\n§7- §fUsage: §e/d <Effect>");
$n = strtolower($p->getName());
$cfg = $this->cfg();
if($args[0] == "water" or $args[0] == "flame" or $args[0] == "portal"){
$cfg->set($n, $args[0]);
$cfg->save();
return $p->sendMessage("§a» §fDeath effect §eactivated§f!");
}
return $p->sendMessage("§c» §fEffect not §efound§f!");
}
}


public function onDeath(death $e){
$p = $e->getPlayer();
if(!$p->hasPermission("use.effects")) return;
$n = strtolower($p->getName());
$cfg = $this->cfg();
if(!$cfg->exists($n)) return;
$g = $cfg->get($n);
$x = $p->getX();
$y = $p->getY() + 1;
$z = $p->getZ();
if($g == "portal"){
$pp1 = new PortalParticle(new Vector3($x, $y, $z));
$pp2 = new PortalParticle(new Vector3($x + 1, $y, $z));
$pp3 = new PortalParticle(new Vector3($x, $y, $z + 1));
$pp4 = new PortalParticle(new Vector3($x - 1, $y, $z));
$pp5 = new PortalParticle(new Vector3($x, $y, $z - 1));
$pp6 = new PortalParticle(new Vector3($x - 1, $y, $z + 1));
$pp7 = new PortalParticle(new Vector3($x + 1, $y, $z - 1));
}
if($g == "flame"){
$pp1 = new FlameParticle(new Vector3($x, $y, $z));
$pp2 = new FlameParticle(new Vector3($x + 1, $y, $z));
$pp3 = new FlameParticle(new Vector3($x, $y, $z + 1));
$pp4 = new FlameParticle(new Vector3($x - 1, $y, $z));
$pp5 = new FlameParticle(new Vector3($x, $y, $z - 1));
$pp6 = new FlameParticle(new Vector3($x - 1, $y, $z + 1));
$pp7 = new FlameParticle(new Vector3($x + 1, $y, $z - 1));
}
if($g == "water"){
$pp1 = new WaterParticle(new Vector3($x, $y, $z));
$pp2 = new WaterParticle(new Vector3($x + 1, $y, $z));
$pp3 = new WaterParticle(new Vector3($x, $y, $z + 1));
$pp4 = new WaterParticle(new Vector3($x - 1, $y, $z));
$pp5 = new WaterParticle(new Vector3($x, $y, $z - 1));
$pp6 = new WaterParticle(new Vector3($x - 1, $y, $z + 1));
$pp7 = new WaterParticle(new Vector3($x + 1, $y, $z - 1));
}
$p->getLevel()->addParticle($pp1);
$p->getLevel()->addParticle($pp2);
$p->getLevel()->addParticle($pp3);
$p->getLevel()->addParticle($pp4);
$p->getLevel()->addParticle($pp5);
$p->getLevel()->addParticle($pp6);
$p->getLevel()->addParticle($pp7);
}

}