Untitled

mail@pastecode.io avatar
unknown
php
a year ago
7.5 kB
2
Indexable
Never
<?php

declare(strict_types=1);

namespace v1arena\Listener;

use pocketmine\player\Player;
use pocketmine\item\VanillaItems;
use pocketmine\event\Listener;
use pocketmine\item\Axe;
use pocketmine\item\Sword;
use pocketmine\entity\effect\EffectInstance;
use pocketmine\entity\effect\VanillaEffects;
use pocketmine\world\sound\AnvilFallSound;
use pocketmine\event\player\{PlayerRespawnEvent, PlayerJoinEvent};
use pocketmine\event\entity\{EntityDamageEvent, EntityDamageByEntityEvent};
use v1arena\Main;
use pocketmine\event\player\PlayerMoveEvent;
use pocketmine\event\entity\EntityItemPickupEvent;

class redpvpListener implements Listener{
    public $plugin;
    public function __construct(Main $plugin)
    {
        $this->plugin = $plugin;
    }
    public function playerPickUpEvent(EntityItemPickupEvent $ev)
    {
      $entity = $ev->getEntity();
      $itemname = $ev->getItem()->getCustomName();
        if ($entity instanceof Player) {
          if ($itemname == "§aPoison §aAxe" or $itemname == "§0Wither §aAxe") {
          if (!$entity->hasPermission("vip.perm") or !$entity->hasPermission("supreme.perm")) {
            $ev->cancel();
          }
        }
        if ($itemname == "§dStrength §aAxe" or $itemname == "§dSlowness §aAxe") {
        if (!$entity->hasPermission("supreme.perm")) {
            $ev->cancel();
          }
        }
      }
    }
    public function safeSpawn(EntityDamageEvent $ev){
 $entity = $ev->getEntity();
  $worldguard = $this->plugin->getServer()->getPluginManager()->getPlugin("WorldGuard");
  if($worldguard == null){
      return;
  }
  $area = $worldguard->getRegionNameFromPosition($entity->getPosition());
  if($entity->getWorld() == $this->plugin->getServer()->getWorldManager()->getWorldByName($this->plugin->world)){
    if($ev->getCause() == EntityDamageEvent::CAUSE_FALL){
      $ev->cancel();
     }
     if ($entity instanceof Player) {
  if($worldguard->getRegionByPlayer($entity) !== ""){
    if($area == "redpvpsafe") {
      $ev->cancel();
   }if($area == "redvip") {
        $ev->cancel();
     }if($area == "redpvpsupreme") {
          $ev->cancel();
       }       

      }
  }
}
}
    public function onDamage(EntityDamageByEntityEvent $event): void{
        $entity = $event->getEntity();
        $damager = $event->getDamager();
        if ($damager instanceof Player and $entity instanceof Player) { 
        $iteminhand = $damager->getInventory()->getItemInHand();
        $itemname = $damager->getInventory()->getItemInHand()->getCustomName();

               if ($iteminhand instanceof Axe or $iteminhand instanceof Sword) {
                     if($this->plugin->getServer()->getPluginManager()->getPlugin("WorldGuard") == null){
      return;
  }
                  $area = $this->plugin->getServer()->getPluginManager()->getPlugin("WorldGuard")->getRegionNameFromPosition($entity->getPosition());
    if($this->plugin->getServer()->getPluginManager()->getPlugin("WorldGuard")->getRegionByPlayer($entity) !== "") {
      if ($area == "team1" or $area == "team2" or $area == "redpvpteam" or $area == "redpvp1v1") {
                            
        $entity->getWorld()->dropItem($entity->getPosition()->asVector3(), VanillaItems::REDSTONE_DUST());
                  
                            if ($itemname == "§aPoison §dAxe") {
                              $entity->getEffects()->add(new EffectInstance(VanillaEffects::POISON(), 60, 1));
                              $entity->getWorld()->addSound($entity->getPosition()->asVector3(), new AnvilFallSound());
                       
                            }
                          if (mt_rand(0,3) == 1) {
                           if ($itemname == "§dSlowness §aAxe") {
                             $entity->getEffects()->add(new EffectInstance(VanillaEffects::SLOWNESS(), 60, 1));
                             $entity->getWorld()->addSound($entity->getPosition()->asVector3(), new AnvilFallSound());
                           }
                          }
                          if (mt_rand(1, 1) == 1) {
                           if ($itemname == "§0Wither §aAxe") {
                           
                              $entity->getEffects()->add(new EffectInstance(VanillaEffects::WITHER(), 100, 2));  
                              $entity->getWorld()->addSound($entity->getPosition()->asVector3(), new AnvilFallSound());
                            }
                           }
                            if ($itemname == "§dStrength §aAxe") {
                              $damager->getEffects()->add(new EffectInstance(VanillaEffects::STRENGTH(), 60, 1));
                   }
                  } else {
                      $event->cancel();
                  }
                 } else {
                  $event->cancel();
                 }
               }
              }
             }
    public function onRespawn(PlayerRespawnEvent $event){
      $entity = $event->getPlayer();
      $world = $this->plugin->getServer()->getWorldManager()->getWorldByName($this->plugin->world);
        if ($entity->getWorld() == $world) {
          $event->setRespawnPosition($this->plugin->getServer()->getWorldManager()->getWorldByName($this->plugin->world)->getSafeSpawn());
    }
  }
public function onLogin(PlayerJoinEvent $ev){
    $ev->getPlayer()->teleport($this->plugin->getServer()->getWorldManager()->getDefaultWorld()->getSafeSpawn());
}
  public function onMove(PlayerMoveEvent $ev)
  {
    $player = $ev->getPlayer();
    $y = $player->getPosition()->getY();

    $world = $this->plugin->getServer()->getWorldManager()->getWorldByName($this->plugin->world);
 if($player->getWorld() == $world){
     if($y < 1){
         $player->teleport($world->getSafeSpawn());
     }
 }
    if($this->plugin->getServer()->getPluginManager()->getPlugin("WorldGuard") == null) {
        return;
    }
    $area = $this->plugin->getServer()->getPluginManager()->getPlugin("WorldGuard")->getRegionNameFromPosition($player->getPosition());
    if($this->plugin->getServer()->getPluginManager()->getPlugin("WorldGuard")->getRegionByPlayer($player) !== "") {
      switch ($area) {
       case 'redpvpsupreme':
        if (!$player->hasPermission("supreme.room")) {
         $ev->cancel();
         $player->sendTitle("§cyou can't join Supreme room!");
        }
         break;
       
       case 'redvip':
        if (!$player->hasPermission("vip.room")) {
          $ev->cancel();
          $player->sendTitle("§cyou can't join VIP room!");
         }
         break;
       }
     }
     if ($this->plugin->getServer()->getPluginManager()->getPlugin("CombatLogger") !== null) {
     $combat = $this->plugin->getServer()->getPluginManager()->getPlugin("CombatLogger");
     $area = $this->plugin->getServer()->getPluginManager()->getPlugin("WorldGuard")->getRegionNameFromPosition($player->getPosition());
        
     if($this->plugin->getServer()->getPluginManager()->getPlugin("WorldGuard")->getRegionByPlayer($player) !== "") {
       if($area == "redpvpteam" or $area == "redpvp1v1"){
        $player->setScale(1);   
       }
         if($area == "redpvpsafe" or $area == "redvip" or $area == "redsupreme"){
         if ($combat->isTagged($player)) {
             $combat->untagPlayer($player);
         }
       }
     }
    }
  }
}