/**
  * @param Event $event
  */
 public function callEvent(Event $event)
 {
     if ($event instanceof Cancellable and $event->isCancelled() and $this->isIgnoringCancelled()) {
         return;
     }
     $this->timings->startTiming();
     $this->executor->execute($this->listener, $event);
     $this->timings->stopTiming();
 }
 public function sendRedistribution(Event $event, $message)
 {
     if ($this->customPacketAvailable and $this->plugin->getConfig()->get("echo-enabled", false)) {
         if ($event instanceof PlayerCommandPreprocessEvent) {
             if ($event->getPlayer()->closed) {
                 return;
             }
         }
         $passcode = $this->plugin->getConfig()->get("echo-passcode", null);
         if ($passcode === null) {
             return;
         }
         $myName = $this->plugin->getConfig()->get("echo-my-name", "MAIN");
         $data = json_encode([$passcode, $myName, $message]);
         foreach ($this->plugin->getConfig()->get("echo-recipients", []) as $recipient) {
             $address = explode(":", $recipient);
             CPAPI::sendPacket(new DataPacket($address[0], $address[1], $data));
         }
     }
 }
 public function execute(Listener $listener, Event $event)
 {
     $module = null;
     if ($event instanceof PlayerEvent) {
         $player = $event->getPlayer();
         $gamer = $this->hub->getGamerForPlayer($player);
         if ($gamer !== null) {
             $module = $gamer->getModule();
         }
     } elseif ($event instanceof EntityEvent) {
         $entity = $event->getEntity();
         if ($entity instanceof Player) {
             $gamer = $this->hub->getGamerForPlayer($entity);
             if ($gamer !== null) {
                 $module = $gamer->getModule();
             }
         }
     } else {
         $callable = [$event, "getPlayer"];
         if (is_callable($callable)) {
             $player = $callable();
             if ($player instanceof Player) {
                 $gamer = $this->hub->getGamerForPlayer($player);
                 if ($gamer !== null) {
                     $module = $gamer->getModule();
                 }
             }
         }
     }
     if (isset($module)) {
         foreach ($this->handlers as $handler) {
             if ($handler->getModule() === $module) {
                 $handler->execute($event);
             }
         }
     }
 }
Пример #4
0
 public function permissionCheck(Event $event)
 {
     /** @var $player Player */
     $player = $event->getPlayer();
     if ($event instanceof PlayerInteractEvent) {
         $block = $event->getBlock()->getSide($event->getFace());
     } else {
         $block = $event->getBlock();
     }
     $x = $block->getX();
     $z = $block->getZ();
     $level = $block->getLevel()->getFolderName();
     if (in_array($level, $this->config->get("non-check-worlds"))) {
         return false;
     }
     //$exist = false;
     //$result = $this->land->query("SELECT owner,invitee FROM land WHERE level = '$level' AND endX > $x AND endZ > $z AND startX < $x AND startZ < $z");
     //if(!is_array($info)) goto checkLand;
     $info = $this->db->canTouch($x, $z, $level, $player);
     if ($info === -1) {
         if ($this->config->get("white-world-protection")) {
             if (in_array($level, $this->config->get("white-world-protection")) and !$player->hasPermission("economyland.land.modify.whiteland")) {
                 $player->sendMessage($this->getMessage("not-owned"));
                 $event->setCancelled();
                 if ($event->getItem()->isPlaceable()) {
                     $this->placeQueue[$player->getName()] = true;
                 }
                 return false;
             }
         }
     } elseif ($info !== true) {
         $player->sendMessage($this->getMessage("no-permission", array($info["owner"], "", "")));
         $event->setCancelled();
         if ($event instanceof PlayerInteractEvent) {
             if ($event->getItem()->isPlaceable()) {
                 $this->placeQueue[$player->getName()] = true;
             }
         }
         return false;
     }
     return true;
 }
Пример #5
0
 /**
  * Calls an event
  *
  * @param Event $event
  */
 public function callEvent(Event $event)
 {
     foreach ($event->getHandlers()->getRegisteredListeners() as $registration) {
         if (!$registration->getPlugin()->isEnabled()) {
             continue;
         }
         try {
             $registration->callEvent($event);
         } catch (\Exception $e) {
             $this->server->getLogger()->critical($this->server->getLanguage()->translateString("pocketmine.plugin.eventError", [$event->getEventName(), $registration->getPlugin()->getDescription()->getFullName(), $e->getMessage(), get_class($registration->getListener())]));
             $logger = $this->server->getLogger();
             if ($logger instanceof MainLogger) {
                 $logger->logException($e);
             }
         }
     }
 }
Пример #6
0
 /**
  * Calls an event
  *
  * @param Event $event
  */
 public function callEvent(Event $event)
 {
     foreach ($event->getHandlers()->getRegisteredListeners() as $registration) {
         if (!$registration->getPlugin()->isEnabled()) {
             continue;
         }
         try {
             $registration->callEvent($event);
         } catch (\Exception $e) {
             $this->server->getLogger()->critical("Could not pass event " . $event->getEventName() . " to " . $registration->getPlugin()->getDescription()->getFullName() . ": " . $e->getMessage() . " on " . get_class($registration->getListener()));
             $logger = $this->server->getLogger();
             if ($logger instanceof MainLogger) {
                 $logger->logException($e);
             }
         }
     }
 }
Пример #7
0
 public function removeArrow(Event $event)
 {
     if ($event->isCancelled()) {
         return;
     }
     $arrow = $event->getEntity();
     $murder = $event->getEntity()->shootingEntity;
     $this->getServer()->getPluginManager()->callEvent($ev = new ExplosionPrimeEvent($arrow, 3.2));
     if (!$ev->isCancelled()) {
         $explosion = new Explosion($arrow, $ev->getForce(), $murder);
         $explosion->explodeB();
     }
     $reflection_class = new \ReflectionClass($arrow);
     $property = $reflection_class->getProperty('age');
     $property->setAccessible(true);
     $property->setValue($arrow, 7000);
 }
Пример #8
0
 /**
  * Calls an event
  *
  * @param Event $event
  */
 public function callEvent(Event $event)
 {
     foreach ($event->getHandlers()->getRegisteredListeners() as $registration) {
         if (!$registration->getPlugin()->isEnabled()) {
             continue;
         }
         try {
             $registration->callEvent($event);
         } catch (\Throwable $e) {
             $this->server->getLogger()->critical($this->server->getLanguage()->translateString("pocketmine.plugin.eventError", [$event->getEventName(), $registration->getPlugin()->getDescription()->getFullName(), $e->getMessage(), get_class($registration->getListener())]));
             $this->server->getLogger()->logException($e);
         }
     }
     if ($this->server->getAIHolder() != null) {
         if ($event instanceof EntityDeathEvent) {
             $this->server->getAIHolder()->MobDeath($event);
         }
         if ($event instanceof EntityDamageByEntityEvent) {
             $this->server->getAIHolder()->EntityDamage($event);
         }
     }
 }
Пример #9
0
 public function permissionCheck(Event $event)
 {
     /** @var $player Player */
     $player = $event->getPlayer();
     if ($event instanceof PlayerInteractEvent) {
         $block = $event->getBlock()->getSide($event->getFace());
     } else {
         $block = $event->getBlock();
     }
     $x = $block->getX();
     $z = $block->getZ();
     $level = $block->getLevel()->getFolderName();
     if (in_array($level, $this->config->get("non-check-worlds"))) {
         return false;
     }
     $info = $this->db->canTouch($x, $z, $level, $player);
     if ($info === -1) {
         if ($this->config->get("white-world-protection")) {
             if (in_array($level, $this->config->get("white-world-protection")) and !$player->hasPermission("economyland.land.modify.whiteland")) {
                 $player->sendMessage($this->getMessage("not-owned"));
                 $event->setCancelled();
                 if ($event->getItem()->canBePlaced()) {
                     $this->placeQueue[$player->getName()] = true;
                 }
                 return false;
             }
         }
     } elseif ($info !== true) {
         $player->sendMessage($this->getMessage("no-permission", array($info["owner"], "", "")));
         $event->setCancelled();
         if ($event instanceof PlayerInteractEvent) {
             if ($event->getItem()->canBePlaced()) {
                 $this->placeQueue[$player->getName()] = true;
             }
         }
         return false;
     }
     return true;
 }
Пример #10
0
 public function trace(Event $ev)
 {
     if ($ev instanceof PlayerQuitEvent) {
         // Remove registered listener
         $n = strtolower($ev->getPlayer()->getName());
         foreach (array_keys($this->tracers) as $type) {
             $this->rmTrace($type, $n);
         }
     }
     $type = explode("\\", get_class($ev));
     $type = $type[count($type) - 1];
     if (!isset($this->tracers[$type])) {
         return;
     }
     $now = microtime(true);
     if (isset($this->tracers[$type]["history"])) {
         if ($now - $this->tracers[$type]["history"]["last"] > $this->timer_short) {
             $this->broadcastEvent($type, mc::_("repeated %1% times since %2% seconds ago", $this->tracers[$type]["history"]["count"] + 1, intval($now - $this->tracers[$type]["history"]["first"])));
             $this->tracers[$type]["history"]["first"] = $now;
             $this->tracers[$type]["history"]["last"] = $now;
             $this->tracers[$type]["history"]["count"] = 0;
         } else {
             $this->tracers[$type]["history"]["last"] = $now;
             ++$this->tracers[$type]["history"]["count"];
         }
     } else {
         $this->tracers[$type]["history"] = ["count" => 0, "first" => $now, "last" => $now];
         $this->broadcastEvent($type, mc::_("triggered"));
     }
 }
 private function signBuy(Event $event)
 {
     if (!$event instanceof SignChangeEvent) {
         return;
     }
     $line1 = trim($event->getLine(1));
     $line2 = trim($event->getLine(2));
     $line3 = trim($event->getLine(3));
     $player = $event->getPlayer();
     $error = "";
     if ($player->getGamemode() == 1) {
         if ($this->SignShop->getProvider()->getPlayer($player->getName())["authorized"] != "root") {
             $this->SignShop->messageManager()->send($player, "You_can_not_create_the_Signs_from_the_creative_mode");
             return;
         }
     }
     if ($this->SignShop->getProvider()->getPlayer($player->getName())["authorized"] != "denied") {
         if (is_numeric($line1) && $line1 > 0) {
             $id = $line1;
             $damage = 0;
         } elseif (count(explode(":", $line1)) == 2) {
             $line1 = explode(":", $line1);
             $id = $line1[0];
             $damage = $line1[1];
             if (!is_numeric($id) || !is_numeric($damage)) {
                 $error = "Item Not_Numeric";
             }
         } else {
             $item = Item::fromString($line1);
             $id = $item->getID();
             $damage = $item->getDamage();
             if ($id == 0) {
                 $error = "Item Invalid";
             }
         }
         $amount = 0;
         if (count(explode("x", $line2)) == 2 || count(explode(" ", $line2)) == 2) {
             if (count(explode("x", $line2)) == 2) {
                 $line2 = explode("x", $line2);
             } else {
                 $line2 = explode(" ", $line2);
             }
             if (is_numeric($line2[0]) && is_numeric($line2[1])) {
                 $amount = $line2[0];
                 $cost = $line2[1];
                 if ($cost < 0 || $amount < 0 || $amount > 45 * 64) {
                     $error = "Invalid Amount_Or_Cost";
                 }
             } else {
                 $error = "Amount_Or_Cost NotNumeric";
             }
         } else {
             $error = "Invalid Amount_Or_Cost";
         }
         if ($amount > Item::get($id, $damage)->getMaxStackSize()) {
             $error = "Amount_Must_Be Less_Than_" . Item::get($id)->getMaxStackSize();
         }
         $count = $line3;
         if (is_numeric($line3)) {
             if ($line3 < $amount) {
                 $error = "Invalid Available";
             }
         } else {
             if ($line3 == "unlimited") {
                 if ($this->SignShop->getProvider()->getPlayer($player->getName())["authorized"] == "root") {
                     $count = 0;
                 } else {
                     $error = "Player Not_Authorized";
                 }
             } else {
                 $error = "Available Not_Numeric";
             }
         }
         if ($error == "") {
             $item = Item::get($id, $damage, $count);
             if ($player->getGamemode() == 1 || $this->hasItemPlayer($player, $item) && $this->removeItemPlayer($player, $item)) {
                 $this->SignShop->getSignManager()->setSign($event->getBlock(), ["id" => $id, "damage" => $damage, "amount" => $amount, "available" => $line3, "cost" => $cost, "need" => 0, "maker" => $player->getName(), "time" => time(), "sold" => 0, "earned" => 0, "type" => "buy", "direction" => $event->getBlock()->getDamage()]);
                 $this->SignShop->messageManager()->send($player, "Sign_successfully_created");
                 $event->setLine(0, TextFormat::GOLD . "[SignBuy]");
                 $event->setLine(1, TextFormat::ITALIC . str_replace(" ", "", Item::get($id, $damage)->getName()));
                 $event->setLine(2, "Amount: x" . $amount);
                 $event->setLine(3, "Price: " . $cost . $this->SignShop->getMoneyManager()->getValue());
             } else {
                 $this->SignShop->messageManager()->send($player, "The_item_was_not_found_or_does_not_have_enough_items");
                 $error = "Player Error";
             }
         }
         if ($error != "") {
             $error = explode(" ", $error);
             $event->setLine(0, TextFormat::GOLD . "[SignShop]");
             $event->setLine(1, TextFormat::DARK_RED . ":ERROR:");
             $event->setLine(2, $error[0]);
             $event->setLine(3, $error[1]);
             $this->SignShop->messageManager()->send($player, "There_is_a_problem_with_the_creation_of_the_Sign");
         }
     } else {
         $this->SignShop->messageManager()->send($player, "You_are_not_authorized_to_run_this_command");
         $event->setLine(0, TextFormat::GOLD . "[SignShop]");
         $event->setLine(1, TextFormat::DARK_RED . "Error:");
         $event->setLine(2, "PlayerNot");
         $event->setLine(3, "Authorized");
     }
 }
Пример #12
0
 private function fireEvent(Event $event)
 {
     $handlers = $event->getHandlers();
     $listeners = $handlers->getRegisteredListeners();
     foreach ($listeners as $registration) {
         if (!$registration->getPlugin()->isEnabled()) {
             continue;
         }
         $registration->callEvent($event);
     }
 }