Untitled
unknown
php
2 years ago
10 kB
8
Indexable
<?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;
use pocketmine\scheduler\ClosureTask;
use pocketmine\utils\TextFormat;
class redpvpListener implements Listener{
public $plugin;
public $inCombat = [];
public function __construct(Main $plugin)
{
$this->plugin = $plugin;
$this->plugin->getScheduler()->scheduleRepeatingTask(new ClosureTask(function() : void {
foreach ($this->inCombat as $playerName => $startTime) {
$player = $this->plugin->getServer()->getPlayerExact($playerName);
if ($player === null) {
// Player is not online, remove from combat
unset($this->inCombat[$playerName]);
} else {
// Check if the player has been in combat for 10 seconds (you can modify the duration as needed)
if (time() - $startTime >= 10) {
$this->removeFromCombat($player);
} else {
$this->inCombat[$player->getName()]--;
}
}
}
}), 20);
}
public function sendCombatMessage(Player $player, bool $statement) {
if ($statement) {
$red = TextFormat::RED;
$player->sendMessage("{$red}You are currently in combat.");
} else {
$green = TextFormat::GREEN;
$player->sendMessage("{$green}You are not currently in combat.");
}
}
public function removeFromCombat(Player $player): void {
unset($this->inCombat[$player->getName()]);
$this->sendCombatMessage($player, false); // You can implement a message informing the player they are no longer in combat
}
public function setInCombat(Player $player): void {
if (!isset($this->inCombat[$player->getName()])) {
$this->inCombat[$player->getName()] = time();
$this->sendCombatMessage($player, true);
} else {
$this->inCombat[$player->getName()]++;
}
}
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) {
$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") {
} else {
$event->cancel();
} } else {
$event->cancel();
}
$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") {
if (isset($this->inCombat[$entity->getName()])) {
$event->cancel();
return;
}
$this->setInCombat($entity);
$this->setInCombat($damager);
$entity->sendMessage("Hello entity");
$damager->sendMessage("Hi damager");
$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);
}
}
}
}
}
}Editor is loading...