Пример #1
0
 public function execute(CommandSender $sender, $commandLabel, array $args)
 {
     $commands = [];
     $result = false;
     foreach ($this->formatStrings as $formatString) {
         try {
             $commands[] = $this->buildCommand($formatString, $args);
         } catch (\Exception $e) {
             if ($e instanceof \InvalidArgumentException) {
                 $sender->sendMessage(TextFormat::RED . $e->getMessage());
             } else {
                 $sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.exception"));
                 $logger = $sender->getServer()->getLogger();
                 if ($logger instanceof MainLogger) {
                     $logger->logException($e);
                 }
             }
             return false;
         }
     }
     foreach ($commands as $command) {
         $result |= Server::getInstance()->dispatchCommand($sender, $command);
     }
     return (bool) $result;
 }
Пример #2
0
 public function log($level, $message)
 {
     Server::getInstance()->getLogger()->log($level, $this->pluginName . $message);
     foreach ($this->attachments as $attachment) {
         $attachment->log($level, $message);
     }
 }
Пример #3
0
 public function onUpdate($type)
 {
     if ($type === Level::BLOCK_UPDATE_NORMAL) {
         $down = $this->getSide(0);
         if ($down->isTransparent() === true and $down->getId() !== self::SUGARCANE_BLOCK) {
             $this->getLevel()->scheduleUpdate($this, 0);
         }
     } elseif ($type === Level::BLOCK_UPDATE_RANDOM) {
         if ($this->getSide(0)->getId() !== self::SUGARCANE_BLOCK) {
             if ($this->meta === 0xf) {
                 for ($y = 1; $y < 3; ++$y) {
                     $b = $this->getLevel()->getBlock(new Vector3($this->x, $this->y + $y, $this->z));
                     if ($b->getId() === self::AIR) {
                         Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($b, new Sugarcane()));
                         $this->getLevel()->setBlock($b, new Sugarcane(), true);
                         break;
                     }
                 }
                 $this->meta = 0;
                 $this->getLevel()->setBlock($this, $this, true);
             } else {
                 ++$this->meta;
                 $this->getLevel()->setBlock($this, $this, true);
             }
             return Level::BLOCK_UPDATE_RANDOM;
         }
     } elseif ($type === Level::BLOCK_UPDATE_SCHEDULED) {
         $this->getLevel()->useBreakOn($this);
     }
     return false;
 }
Пример #4
0
 public function onUpdate($type)
 {
     if ($type === Level::BLOCK_UPDATE_NORMAL) {
         if ($this->getSide(0)->isTransparent() === true) {
             $this->getLevel()->useBreakOn($this);
             return Level::BLOCK_UPDATE_NORMAL;
         }
     } elseif ($type === Level::BLOCK_UPDATE_RANDOM) {
         if (mt_rand(0, 2) == 1) {
             if ($this->meta < 0x7) {
                 $block = clone $this;
                 ++$block->meta;
                 Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($this, $block));
                 if (!$ev->isCancelled()) {
                     $this->getLevel()->setBlock($this, $ev->getNewState(), true, true);
                 } else {
                     return Level::BLOCK_UPDATE_RANDOM;
                 }
             }
         } else {
             return Level::BLOCK_UPDATE_RANDOM;
         }
     }
     return false;
 }
Пример #5
0
 public function onEntityCollide(Entity $entity)
 {
     Server::getInstance()->getPluginManager()->callEvent($ev = new EntityEnterPortalEvent($entity, $this));
     if (!$ev->isCancelled()) {
         return true;
     }
     return false;
 }
Пример #6
0
 /**
  * @param Permission $perm
  * @param Permission $parent
  *
  * @return Permission
  */
 public static function registerPermission(Permission $perm, Permission $parent = null)
 {
     if ($parent instanceof Permission) {
         $parent->getChildren()[$perm->getName()] = true;
         return self::registerPermission($perm);
     }
     Server::getInstance()->getPluginManager()->addPermission($perm);
     return Server::getInstance()->getPluginManager()->getPermission($perm->getName());
 }
Пример #7
0
 public static function reload()
 {
     if (Server::getInstance()->getPluginManager()->useTimings()) {
         foreach (self::$HANDLERS as $timings) {
             $timings->reset();
         }
         TimingsCommand::$timingStart = microtime(true);
     }
 }
Пример #8
0
 public function onEntityCollide(Entity $entity)
 {
     if (!$entity->hasEffect(Effect::FIRE_RESISTANCE)) {
         $ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_FIRE, 1);
         $entity->attack($ev->getFinalDamage(), $ev);
     }
     $ev = new EntityCombustByBlockEvent($this, $entity, 8);
     Server::getInstance()->getPluginManager()->callEvent($ev);
     if (!$ev->isCancelled()) {
         $entity->setOnFire($ev->getDuration());
     }
 }
Пример #9
0
 public function __construct(Player $player, $message, $format = "chat.type.text", array $recipients = null)
 {
     $this->player = $player;
     $this->message = $message;
     //TODO: @deprecated (backwards-compativility)
     $i = 0;
     while (($pos = strpos($format, "%s")) !== false) {
         $format = substr($format, 0, $pos) . "{%{$i}}" . substr($format, $pos + 2);
         ++$i;
     }
     $this->format = $format;
     if ($recipients === null) {
         $this->recipients = Server::getInstance()->getPluginManager()->getPermissionSubscriptions(Server::BROADCAST_CHANNEL_USERS);
     } else {
         $this->recipients = $recipients;
     }
 }
Пример #10
0
 public function onUpdate($type)
 {
     if ($type === Level::BLOCK_UPDATE_RANDOM) {
         //TODO: light levels
         $x = mt_rand($this->x - 1, $this->x + 1);
         $y = mt_rand($this->y - 2, $this->y + 2);
         $z = mt_rand($this->z - 1, $this->z + 1);
         $block = $this->getLevel()->getBlock(new Vector3($x, $y, $z));
         if ($block->getId() === Block::DIRT) {
             if ($block->getSide(1) instanceof Transparent) {
                 Server::getInstance()->getPluginManager()->callEvent($ev = new BlockSpreadEvent($block, $this, new Mycelium()));
                 if (!$ev->isCancelled()) {
                     $this->getLevel()->setBlock($block, $ev->getNewState());
                 }
             }
         }
     }
 }
Пример #11
0
 public function __construct()
 {
     $this->server = Server::getInstance();
     $this->server->getLogger()->info($this->server->getLanguage()->translateString("BukkitPE.server.query.start"));
     $addr = ($ip = $this->server->getIp()) != "" ? $ip : "0.0.0.0";
     $port = $this->server->getPort();
     $this->server->getLogger()->info($this->server->getLanguage()->translateString("BukkitPE.server.query.info", [$port]));
     /*
     The Query protocol is built on top of the existing Minecraft PE UDP network stack.
     Because the 0xFE packet does not exist in the MCPE protocol,
     we can identify	Query packets and remove them from the packet queue.
     
     Then, the Query class handles itself sending the packets in raw form, because
     packets can conflict with the MCPE ones.
     */
     $this->regenerateToken();
     $this->lastToken = $this->token;
     $this->regenerateInfo();
     $this->server->getLogger()->info($this->server->getLanguage()->translateString("BukkitPE.server.query.running", [$addr, $port]));
 }
Пример #12
0
 public function onUpdate($type)
 {
     if ($type === Level::BLOCK_UPDATE_NORMAL) {
         $down = $this->getSide(0);
         $up = $this->getSide(1);
         if ($down->getId() !== self::SAND and $down->getId() !== self::CACTUS) {
             $this->getLevel()->scheduleUpdate($this, 0);
         } else {
             for ($side = 2; $side <= 5; ++$side) {
                 $b = $this->getSide($side);
                 if (!$b->canBeFlowedInto() && $b->getId() !== Block::SNOW_LAYER) {
                     // Snow can be stacked to a full block beside a cactus without destroying the cactus.
                     $this->getLevel()->useBreakOn($this);
                 }
             }
         }
     } elseif ($type === Level::BLOCK_UPDATE_RANDOM) {
         if ($this->getSide(0)->getId() !== self::CACTUS) {
             if ($this->meta == 0xf) {
                 for ($y = 1; $y < 3; ++$y) {
                     $b = $this->getLevel()->getBlock(new Vector3($this->x, $this->y + $y, $this->z));
                     if ($b->getId() === self::AIR) {
                         Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($b, new Cactus()));
                         if (!$ev->isCancelled()) {
                             $this->getLevel()->setBlock($b, $ev->getNewState(), true);
                         }
                     }
                 }
                 $this->meta = 0;
                 $this->getLevel()->setBlock($this, $this);
             } else {
                 ++$this->meta;
                 $this->getLevel()->setBlock($this, $this);
             }
         }
     } elseif ($type === Level::BLOCK_UPDATE_SCHEDULED) {
         $this->getLevel()->useBreakOn($this);
     }
     return false;
 }
Пример #13
0
 public function onUpdate($type)
 {
     if ($type === Level::BLOCK_UPDATE_NORMAL) {
         if ($this->getSide(0)->isTransparent() === true) {
             $this->getLevel()->useBreakOn($this);
             return Level::BLOCK_UPDATE_NORMAL;
         }
     } elseif ($type === Level::BLOCK_UPDATE_RANDOM) {
         if (mt_rand(0, 2) == 1) {
             if ($this->meta < 0x7) {
                 $block = clone $this;
                 ++$block->meta;
                 Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($this, $block));
                 if (!$ev->isCancelled()) {
                     $this->getLevel()->setBlock($this, $ev->getNewState(), true);
                 }
                 return Level::BLOCK_UPDATE_RANDOM;
             } else {
                 for ($side = 2; $side <= 5; ++$side) {
                     $b = $this->getSide($side);
                     if ($b->getId() === self::MELON_BLOCK) {
                         return Level::BLOCK_UPDATE_RANDOM;
                     }
                 }
                 $side = $this->getSide(mt_rand(2, 5));
                 $d = $side->getSide(0);
                 if ($side->getId() === self::AIR and ($d->getId() === self::FARMLAND or $d->getId() === self::GRASS or $d->getId() === self::DIRT)) {
                     Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($side, new Melon()));
                     if (!$ev->isCancelled()) {
                         $this->getLevel()->setBlock($side, $ev->getNewState(), true);
                     }
                 }
             }
         }
         return Level::BLOCK_UPDATE_RANDOM;
     }
     return false;
 }
Пример #14
0
 public function execute()
 {
     if ($this->hasExecuted() or !$this->canExecute()) {
         return false;
     }
     Server::getInstance()->getPluginManager()->callEvent($ev = new InventoryTransactionEvent($this));
     if ($ev->isCancelled()) {
         foreach ($this->inventories as $inventory) {
             if ($inventory instanceof PlayerInventory) {
                 $inventory->sendArmorContents($this->getSource());
             }
             $inventory->sendContents($this->getSource());
         }
         return false;
     }
     foreach ($this->transactions as $transaction) {
         $transaction->getInventory()->setItem($transaction->getSlot(), $transaction->getTargetItem());
     }
     $this->hasExecuted = true;
     return true;
 }
Пример #15
0
 private function generateWeather()
 {
     if ($this->getServer()->getProperty("weather.enable", true)) {
         if ($this->getWeather() === Level::WEATHER_CLEARSKY) {
             $random = mt_rand(1, 1000000);
             if ($random <= $this->rainprob) {
                 Server::getInstance()->getPluginManager()->callEvent($ev = new WeatherChangeEvent($this, Level::WEATHER_CLEARSKY));
                 if (!$ev->isCancelled()) {
                     $this->setWeatherExecTick(mt_rand($this->raintime[0], $this->raintime[1]));
                     $this->setWeather(Level::WEATHER_RAIN);
                 }
             }
             return;
         }
         if ($this->getWeather() === Level::WEATHER_RAIN) {
             if ($this->weatherexectick <= 0) {
                 Server::getInstance()->getPluginManager()->callEvent($ev = new WeatherChangeEvent($this, Level::WEATHER_RAIN));
                 if (!$ev->isCancelled()) {
                     $this->weatherexectick = 0;
                     $this->setWeather(Level::WEATHER_CLEARSKY);
                     return;
                 }
             }
             $this->weatherexectick--;
             return;
         }
     }
     // Weather TODO : Thunder
 }
Пример #16
0
 /**
  * @return \BukkitPE\Server
  */
 public function getServer()
 {
     return Server::getInstance();
 }
Пример #17
0
 /**
  * @param bool[]               $children
  * @param bool                 $invert
  * @param PermissionAttachment $attachment
  */
 private function calculateChildPermissions(array $children, $invert, $attachment)
 {
     foreach ($children as $name => $v) {
         $perm = Server::getInstance()->getPluginManager()->getPermission($name);
         $value = ($v xor $invert);
         $this->permissions[$name] = new PermissionAttachmentInfo($this->parent !== null ? $this->parent : $this, $name, $attachment, $value);
         Server::getInstance()->getPluginManager()->subscribeToPermission($name, $this->parent !== null ? $this->parent : $this);
         if ($perm instanceof Permission) {
             $this->calculateChildPermissions($perm->getChildren(), !$value, $attachment);
         }
     }
 }
Пример #18
0
 /**
  * @param Plugin $plugin
  */
 public function disablePlugin(Plugin $plugin)
 {
     if ($plugin->isEnabled()) {
         try {
             $plugin->getPluginLoader()->disablePlugin($plugin);
         } catch (\Exception $e) {
             $logger = Server::getInstance()->getLogger();
             if ($logger instanceof MainLogger) {
                 $logger->logException($e);
             }
         }
         $this->server->getScheduler()->cancelTasks($plugin);
         HandlerList::unregisterAll($plugin);
         foreach ($plugin->getDescription()->getPermissions() as $perm) {
             $this->removePermission($perm);
         }
     }
 }
Пример #19
0
 /**
  * @param int $currentTick
  */
 public function mainThreadHeartbeat($currentTick)
 {
     $this->currentTick = $currentTick;
     while ($this->isReady($this->currentTick)) {
         /** @var TaskHandler $task */
         $task = $this->queue->extract();
         if ($task->isCancelled()) {
             unset($this->tasks[$task->getTaskId()]);
             continue;
         } else {
             $task->timings->startTiming();
             try {
                 $task->run($this->currentTick);
             } catch (\Exception $e) {
                 Server::getInstance()->getLogger()->critical("Could not execute task " . $task->getTaskName() . ": " . $e->getMessage());
                 $logger = Server::getInstance()->getLogger();
                 if ($logger instanceof MainLogger) {
                     $logger->logException($e);
                 }
             }
             $task->timings->stopTiming();
         }
         if ($task->isRepeating()) {
             $task->setNextRun($this->currentTick + $task->getPeriod());
             $this->queue->insert($task, $this->currentTick + $task->getPeriod());
         } else {
             $task->remove();
             unset($this->tasks[$task->getTaskId()]);
         }
     }
     $this->asyncPool->collectTasks();
 }
Пример #20
0
 /**
  * @param bool $async
  *
  * @return boolean
  */
 public function save($async = false)
 {
     if ($this->correct === true) {
         try {
             $content = null;
             switch ($this->type) {
                 case Config::PROPERTIES:
                 case Config::CNF:
                     $content = $this->writeProperties();
                     break;
                 case Config::JSON:
                     $content = json_encode($this->config, JSON_PRETTY_PRINT | JSON_BIGINT_AS_STRING);
                     break;
                 case Config::YAML:
                     $content = yaml_emit($this->config, YAML_UTF8_ENCODING);
                     break;
                 case Config::SERIALIZED:
                     $content = serialize($this->config);
                     break;
                 case Config::ENUM:
                     $content = implode("\r\n", array_keys($this->config));
                     break;
             }
             if ($async) {
                 Server::getInstance()->getScheduler()->scheduleAsyncTask(new FileWriteTask($this->file, $content));
             } else {
                 file_put_contents($this->file, $content);
             }
         } catch (\Exception $e) {
             $logger = Server::getInstance()->getLogger();
             $logger->critical("Could not save Config " . $this->file . ": " . $e->getMessage());
             if (\BukkitPE\DEBUG > 1 and $logger instanceof MainLogger) {
                 $logger->logException($e);
             }
         }
         return true;
     } else {
         return false;
     }
 }
Пример #21
0
 public function clear($index)
 {
     if (isset($this->slots[$index])) {
         $item = Item::get(Item::AIR, null, 0);
         $old = $this->slots[$index];
         $holder = $this->getHolder();
         if ($holder instanceof Entity) {
             Server::getInstance()->getPluginManager()->callEvent($ev = new EntityInventoryChangeEvent($holder, $old, $item, $index));
             if ($ev->isCancelled()) {
                 $this->sendSlot($index, $this->getViewers());
                 return false;
             }
             $item = $ev->getNewItem();
         }
         if ($item->getId() !== Item::AIR) {
             $this->slots[$index] = clone $item;
         } else {
             unset($this->slots[$index]);
         }
         $this->onSlotChange($index, $old);
     }
     return true;
 }
Пример #22
0
 public function save($flag = true)
 {
     $this->removeExpired();
     $fp = @fopen($this->file, "w");
     if (is_resource($fp)) {
         if ($flag === true) {
             fwrite($fp, "# Updated " . strftime("%x %H:%M", time()) . " by " . Server::getInstance()->getName() . " " . Server::getInstance()->getBukkitPEVersion() . "\n");
             fwrite($fp, "# victim name | ban date | banned by | banned until | reason\n\n");
         }
         foreach ($this->list as $entry) {
             fwrite($fp, $entry->getString() . "\n");
         }
         fclose($fp);
     } else {
         MainLogger::getLogger()->error("Could not save ban list");
     }
 }
Пример #23
0
 /**
  * @param string|Permission $name
  * @param                   $value
  *
  * @return Permission|void Permission if $name is a string, void if it's a Permission
  */
 public function addParent($name, $value)
 {
     if ($name instanceof Permission) {
         $name->getChildren()[$this->getName()] = $value;
         $name->recalculatePermissibles();
         return;
     } else {
         $perm = Server::getInstance()->getPluginManager()->getPermission($name);
         if ($perm === null) {
             $perm = new Permission($name);
             Server::getInstance()->getPluginManager()->addPermission($perm);
         }
         $this->addParent($perm, $value);
         return $perm;
     }
 }
Пример #24
0
 public function onUpdate($type)
 {
     if ($type === Level::BLOCK_UPDATE_NORMAL) {
         if (($this->meta & 0b1100) === 0) {
             $this->meta |= 0x8;
             $this->getLevel()->setBlock($this, $this, false, false, true);
         }
     } elseif ($type === Level::BLOCK_UPDATE_RANDOM) {
         if (($this->meta & 0b1100) === 0x8) {
             $this->meta &= 0x3;
             $visited = [];
             $check = 0;
             Server::getInstance()->getPluginManager()->callEvent($ev = new LeavesDecayEvent($this));
             if ($ev->isCancelled() or $this->findLog($this, $visited, 0, $check) === true) {
                 $this->getLevel()->setBlock($this, $this, false, false);
             } else {
                 $this->getLevel()->useBreakOn($this);
                 return Level::BLOCK_UPDATE_NORMAL;
             }
         }
     }
     return false;
 }
Пример #25
0
 public function registerToCraftingManager()
 {
     Server::getInstance()->getCraftingManager()->registerBrewingRecipe($this);
 }