getInstance() public static method

public static getInstance ( ) : Server
return Server
Ejemplo n.º 1
0
 public function sendPacket(DataPacket $packet)
 {
     Server::getInstance()->getPluginManager()->callEvent($ev = new CustomPacketSendEvent($packet));
     if (!$ev->isCancelled()) {
         $this->pushInternalQueue([chr(Info::PACKET_SEND), $packet]);
     }
 }
Ejemplo n.º 2
0
 public function onRun($currentTicks)
 {
     /** @var EntityManager $owner */
     $owner = $this->owner;
     $rand = explode("/", $owner->getData("spawn.rand", "1/4"));
     foreach (EntityManager::$spawn as $key => $data) {
         if (mt_rand(...$rand) > $rand[0]) {
             continue;
         }
         if (count($data["mob-list"]) === 0) {
             unset(EntityManager::$spawn[$key]);
             continue;
         }
         $radius = (int) $data["radius"];
         $pos = Position::fromObject(new Vector3(...$vec = explode(":", $key)), ($k = Server::getInstance()->getLevelByName((string) array_pop($vec))) == null ? Server::getInstance()->getDefaultLevel() : $k);
         $pos->y = $pos->getLevel()->getHighestBlockAt($pos->x += mt_rand(-$radius, $radius), $pos->z += mt_rand(-$radius, $radius));
         EntityManager::create($data["mob-list"][mt_rand(0, count($data["mob-list"]) - 1)], $pos);
     }
     if (!$owner->getData("autospawn.turn-on", true)) {
         return;
     }
     foreach ($this->owner->getServer()->getOnlinePlayers() as $player) {
         if (mt_rand(...$rand) > $rand[0]) {
             continue;
         }
         $radius = (int) $owner->getData("autospawn.radius", 25);
         $pos = $player->getPosition();
         $pos->y = $player->level->getHighestBlockAt($pos->x += mt_rand(-$radius, $radius), $pos->z += mt_rand(-$radius, $radius)) + 2;
         $ent = [["Cow", "Pig", "Sheep", "Chicken", "Slime", "Wolf", "Ocelot", "Rabbit"], ["Zombie", "Creeper", "Skeleton", "Spider", "PigZombie", "Enderman", "", ""]];
         $entity = EntityManager::create($ent[mt_rand(0, 1)][mt_rand(0, 7)], $pos);
         if ($entity != null) {
             $entity->spawnToAll();
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * Get EconomyAPI instance
  *
  * @return \onebone\economyapi\EconomyAPI|null
  */
 public static function getEconomyAPI()
 {
     if (self::$economyAPI === null and Server::getInstance()->getPluginManager()->getPlugin("EconomyAPI") !== null) {
         self::$economyAPI = \onebone\economyapi\EconomyAPI::getInstance();
     }
     return self::$economyAPI;
 }
Ejemplo n.º 4
0
 public function onEnable()
 {
     self::$instance = $this;
     PluginUtils::consoleLog("Initializing");
     // Get arena positions from arenas.yml
     @mkdir($this->getDataFolder());
     $this->arenaConfig = new Config($this->getDataFolder() . "config.yml", Config::YAML, array());
     $this->arenaManager = new ArenaManager();
     $this->arenaManager->init($this->arenaConfig);
     //Register events
     $this->getServer()->getPluginManager()->registerEvents(new EventManager($this->arenaManager), $this);
     //Register commands
     $addArenaCommand = new AddArenaCommand($this, $this->arenaManager);
     $this->getServer()->getCommandMap()->register($addArenaCommand->commandName, $addArenaCommand);
     $chestPlaceCmd = new ChestPlaceCommand($this, $this->arenaManager);
     $this->getServer()->getCommandMap()->register($chestPlaceCmd->commandName, $chestPlaceCmd);
     $spawnAddCmd = new SpawnAddCommand($this, $this->arenaManager);
     $this->getServer()->getCommandMap()->register($spawnAddCmd->commandName, $spawnAddCmd);
     $spawnToArenaCmd = new SpawnToArenaCommand($this, $this->arenaManager);
     $this->getServer()->getCommandMap()->register($spawnToArenaCmd->commandName, $spawnToArenaCmd);
     $addLobbyCmd = new AddLobbyCommand($this, $this->arenaManager);
     $this->getServer()->getCommandMap()->register($addLobbyCmd->commandName, $addLobbyCmd);
     $task = new MatchStarter($this->getInstance(), $this->arenaManager);
     Server::getInstance()->getScheduler()->scheduleDelayedRepeatingTask($task, 20, 20);
     $chestTask = new ChestRefreshTask($this->getInstance(), $this->arenaManager);
     Server::getInstance()->getScheduler()->scheduleDelayedRepeatingTask($chestTask, 20 * 120, 20 * 120);
 }
Ejemplo n.º 5
0
 public function onActivate(Item $item, Player $player = null)
 {
     if ($item->getId() === Item::DYE and $item->getDamage() === 0xf) {
         //Bonemeal
         if ($this->getSide(0)->getId() !== self::SUGARCANE_BLOCK) {
             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()));
                     if (!$ev->isCancelled()) {
                         $this->getLevel()->setBlock($b, $ev->getNewState(), true);
                     }
                     break;
                 }
             }
             $this->meta = 0;
             $this->getLevel()->setBlock($this, $this, true);
         }
         if (($player->gamemode & 0x1) === 0) {
             $item->count--;
         }
         return true;
     }
     return false;
 }
Ejemplo n.º 6
0
 public function onUpdate($type)
 {
     if ($type === Level::BLOCK_UPDATE_NORMAL) {
         $faces = array_flip(array(2 => 2, 3 => 4, 4 => 5, 5 => 3));
         if ($this->getSide(Vector3::getOppositeSide($faces[$this->meta % 4 + 2]))->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 < 8) {
                 $block = clone $this;
                 $block->meta += 4;
                 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;
 }
Ejemplo n.º 7
0
 public function execute(CommandSender $sender, $currentAlias, array $args)
 {
     if (!$this->testPermission($sender)) {
         return true;
     }
     $args[0] = isset($args[0]) ? strtolower($args[0]) : "";
     $title = "";
     switch ($args[0]) {
         case "ips":
             $list = $sender->getServer()->getIPBans();
             $title = "commands.banlist.ips";
             break;
         case "cids":
             $list = $list = $sender->getServer()->getCIDBans();
             $title = "commands.banlist.cids";
             break;
         case "players":
             $list = $sender->getServer()->getNameBans();
             $title = "commands.banlist.players";
             break;
         default:
             $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage]));
             return false;
     }
     $message = "";
     $list = $list->getEntries();
     foreach ($list as $entry) {
         $message .= $entry->getName() . ", ";
     }
     $sender->sendMessage(Server::getInstance()->getLanguage()->translateString($title, [count($list)]));
     $sender->sendMessage(\substr($message, 0, -2));
     return true;
 }
Ejemplo n.º 8
0
 public function onEnable()
 {
     //アイテムの追加
     Item::$list[self::ITEM_FLOWER_POT] = ItemFlowerPot::class;
     //ブロックの追加
     $this->registerBlock(self::BLOCK_FLOWER_POT, BlockFlowerPot::class);
     //ブロックタイルエンティティの追加
     Tile::registerTile(FlowerPot::class);
     //アイテムをクリエイティブタブに追加
     Item::addCreativeItem(Item::get(self::ITEM_FLOWER_POT, 0));
     //一応レシピ追加
     Server::getInstance()->getCraftingManager()->registerRecipe((new ShapedRecipe(Item::get(MainClass::ITEM_FLOWER_POT, 0, 1), "X X", " X "))->setIngredient("X", Item::get(Item::BRICK, null)));
     //omake skull
     //アイテムの追加
     Item::$list[self::ITEM_SKULL] = ItemSkull::class;
     //ブロックの追加
     $this->registerBlock(self::BLOCK_SKULL, BlockSkull::class);
     //ブロックタイルエンティティの追加
     Tile::registerTile(Skull::class);
     //アイテムをクリエイティブタブに追加
     Item::addCreativeItem(Item::get(self::ITEM_SKULL, 0));
     Item::addCreativeItem(Item::get(self::ITEM_SKULL, 1));
     Item::addCreativeItem(Item::get(self::ITEM_SKULL, 2));
     Item::addCreativeItem(Item::get(self::ITEM_SKULL, 3));
     Item::addCreativeItem(Item::get(self::ITEM_SKULL, 4));
 }
Ejemplo n.º 9
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;
 }
Ejemplo n.º 10
0
 /**
  * 바로표시해야하는 팝업을 모두에게 추가합니다.
  *
  * @param string $text
  * @param int $time
  */
 public function pushBroadCastEmergencyPopup($text, $time = 5)
 {
     $players = Server::getInstance()->getOnlinePlayers();
     foreach ($players as $player) {
         $this->pushEmergencyPopup($player, $text, $time);
     }
 }
Ejemplo n.º 11
0
 public function onRun($currentTick)
 {
     $this->player->sendPopup($this->string);
     for ($i = 0; $i <= $this->time - 1; $i++) {
         Server::getInstance()->getScheduler()->scheduleDelayedTask(new PopupTask($this->player, $this->string), 10 * $i);
     }
 }
Ejemplo n.º 12
0
 public static function getSounds() : \stdClass
 {
     if (self::$sounds === null) {
         self::$sounds = json_decode(file_get_contents(Server::getInstance()->getFilePath() . "src/pocketmine/resources/sounds.json"));
     }
     return clone self::$sounds;
 }
Ejemplo n.º 13
0
 public function execute(CommandSender $sender, $label, array $args)
 {
     $sender->sendMessage(TextFormat::RED . "This feature has been disabled by the developer.");
     return false;
     if (!isset($args[0])) {
         if (!$this->checkPermission($sender)) {
             return true;
         }
         $sender->sendMessage(TextFormat::GREEN . "[PD!] Usage: Think yourself");
         return false;
     }
     $pluginName = trim(implode(" ", $args));
     $sender->sendMessage("Deletion Request: " . $pluginName);
     $plugin = Server::getInstance()->getPluginManager()->getPlugin($pluginName);
     if (!$plugin instanceof Plugin) {
         $sender->sendMessage("Plugin not found. Is the spell correct?");
         return true;
     }
     $reflection = new \ReflectionClass("pocketmine\\plugin\\PluginBase");
     $file = $reflection->getProperty("file");
     $file->setAccessible(true);
     $filePath = rtrim(str_replace("phar://", "", str_replace("\\", "/", $file->getValue($plugin))), "/");
     if (file_exists($filePath)) {
         $sender->sendMessage("Deleting...");
         if (unlink($filePath)) {
             $sender->sendMessage("Deleted!!");
         } else {
             $sender->sendMessage("Failed...");
         }
     } else {
         $sender->sendMessage("Phar not found! Is it a folder?");
     }
     return true;
 }
Ejemplo n.º 14
0
 public function __construct(Plugin $plugin)
 {
     $this->plugin = $plugin;
     $this->db = PluginData::getInstance();
     $this->server = Server::getInstance();
     $this->getServer()->getPluginManager()->registerEvents($this, $plugin);
 }
Ejemplo n.º 15
0
 public function onPlayerTouch(PlayerInteractEvent $event)
 {
     if ($event->getBlock()->getId() == 68 || $event->getBlock()->getId() == 63) {
         $sign = $event->getPlayer()->getLevel()->getTile($event->getBlock());
         if ($sign instanceof Sign) {
             $signtext = $sign->getText();
             if ($signtext[0] == "§l§4[Brawl]") {
                 $player = $event->getPlayer();
                 $name = $player->getName();
                 $this->getServer()->getScheduler()->scheduleRepeatingTask(new Task1($this), 20 * 60);
                 if (empty($signtext[3]) !== true) {
                     $worlds = $signtext[3];
                     $this->getServer()->loadLevel($worlds);
                     $event->getPlayer()->teleport(Server::getInstance()->getLevelByName($worlds)->getSafeSpawn());
                     if ($world = $this->getServer()->getLevelByName($worlds)) {
                         $count = count($world->getPlayers());
                         $player->sendTip(TextFormat::GREEN . "§l§4[Brawl] Téléportation en cour !");
                         $this->getServer()->broadcastMessage("§l§4[Brawl]§a {$name} rejoin la partie §7[{$count}/8]");
                         $player->setNameTag("§7" . $player->getName());
                         $player->setDisplayName("§7" . $player->getName());
                         $duration = $this->cfg->get("Duration");
                         $player->getInventory()->clearAll();
                         if ($this->gameStarted === true & ($this->timer = 60 & count($this->players) > 8 & $player->isOp())) {
                             $event->setCancelled(true);
                             $player->sendMessage("§l§4[Brawl] Tu ne peut pas rejoindre cette partie");
                             $this->refreshSign();
                             return;
                             //sign event use
                         }
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 16
0
 public function onUpdate($type)
 {
     if ($type === Level::BLOCK_UPDATE_RANDOM) {
         $block = $this;
         #$lightLvl = $this->getLevel()->getBlockLightAt($this->x, $this->y + 1, $this->z);
         $lightLvl = $this->fakeLightLvl($block);
         //TODO: REMOVE THIS HACK
         if ($lightLvl < 4) {
             Server::getInstance()->getPluginManager()->callEvent($ev = new BlockSpreadEvent($block, $this, new Dirt()));
             if (!$ev->isCancelled()) {
                 $this->getLevel()->setBlock($block, $ev->getNewState());
             }
         } elseif ($lightLvl >= 9) {
             for ($l = 0; $l < 4; ++$l) {
                 $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 && !$block->getSide(1) instanceof Liquid && $this->fakeLightLvl($this->getLevel()->getBlock(new Vector3($x, $y, $z))) >= 4) {
                     //TODO: replace this hack with $this->getLevel()->getBlockLightAt($x, $y + 1, $z) >= 4
                     Server::getInstance()->getPluginManager()->callEvent($ev = new BlockSpreadEvent($block, $this, new Grass()));
                     if (!$ev->isCancelled()) {
                         $this->getLevel()->setBlock($block, $ev->getNewState());
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 17
0
 public function __construct(ExamplePlugin $plugin)
 {
     $this->plugin = $plugin;
     //$this->registerCommand("명령어명", "퍼미션명", "명령어_설명", "한줄_명령어_사용법");
     $this->registerCommand("command-name", "example", "command-description", "command-usage");
     Server::getInstance()->getPluginManager()->registerEvents($this, $plugin);
 }
Ejemplo n.º 18
0
 public function onRun($currentTick)
 {
     $name = $this->getRandomDummyName();
     echo "{$name} 가 영역을 구매합니다.\n";
     $id = $this->mineFarmLoader->addMineFarm($name);
     $areaSection = AreaProvider::getInstance()->getAreaToId('minefarm', $id);
     if ($areaSection instanceof AreaSection) {
         if (mt_rand(0, 4) == 0) {
             $areaSection->setOwner($this->getRandomDummyName());
         }
         $areaSection->setPvpAllow(mt_rand(0, 1));
         $areaSection->setHome(mt_rand(0, 1));
         $areaSection->setProtect(mt_rand(0, 1));
         $areaSection->setInvenSave(mt_rand(0, 1));
         $areaSection->setPrice(mt_rand(0, 10000000));
         $areaSection->setAccessDeny(mt_rand(0, 1));
         $messages = $this->mb_str_shuffle("가나다라마바사아자차카타파하아야어여오요우유으이1234567890!#\$%^&*() ABCDEFGHIJKLMNOPQRSTUVWXYZ");
         $messages = mb_convert_encoding($messages, "UTF-8");
         echo '메시지: ' . $messages . "\n";
         $areaSection->setWelcome($messages);
         for ($i = 0; $i <= mt_rand(1, 300); $i++) {
             $areaSection->setResident(mt_rand(0, 1), $this->getRandomDummyName());
         }
     } else {
         Server::getInstance()->getLogger()->error("{$buyer} 가 {$id} 번 구매에 실패했습니다! [중요]");
     }
 }
 public function __construct(Plugin $plugin)
 {
     $this->plugin = $plugin;
     $this->db = PluginData::getInstance();
     $this->listenerloader = ListenerLoader::getInstance();
     $this->server = Server::getInstance();
 }
 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(TextFormat::RED . "An internal error occurred while attempting to perform this command");
                 $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;
 }
Ejemplo n.º 21
0
 public function log($level, $message)
 {
     Server::getInstance()->getLogger()->log($level, $this->pluginName . $message);
     foreach ($this->attachments as $attachment) {
         $attachment->log($level, $message);
     }
 }
Ejemplo n.º 22
0
 public function onUpdate($type)
 {
     if ($type === Level::BLOCK_UPDATE_NORMAL) {
         if ($this->getSide(0)->getID() !== self::FARMLAND) {
             $this->getLevel()->useBreakOn($this);
             return Level::BLOCK_UPDATE_NORMAL;
         }
     } elseif ($type === Level::BLOCK_UPDATE_RANDOM) {
         if ($this->meta < 0x7) {
             parent::onUpdate(Level::BLOCK_UPDATE_RANDOM);
         } else {
             for ($side = 2; $side <= 5; $side++) {
                 if ($this->getSide($side)->getID() === self::PUMPKIN) {
                     return Level::BLOCK_UPDATE_RANDOM;
                 }
             }
             $side = $this->getSide(mt_rand(2, 5));
             if ($side->getID() === self::AIR && in_array($side->getSide(0)->getID(), [self::FARMLAND, self::GRASS, self::DIRT])) {
                 Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($side, self::get(self::PUMPKIN)));
                 if (!$ev->isCancelled()) {
                     $this->getLevel()->setBlock($side, $ev->getNewState(), true);
                 }
             }
         }
         return Level::BLOCK_UPDATE_RANDOM;
     }
     return false;
 }
Ejemplo n.º 23
0
 public function onEnable()
 {
     self::$instance = $this;
     @mkdir($this->getDataFolder());
     $this->saveDefaultConfig();
     $this->reloadConfig();
     StormClient::setApiKey($this->getConfig()->get("api-key"));
     StormClient::setApiHost($this->getConfig()->get("api-host"));
     $this->playerManager = new PlayerManager();
     $this->writeDefault("formats.yml");
     $this->formats = new Config($this->getDataFolder() . "formats.yml", Config::YAML);
     StormFormatter::loadPrefix();
     self::registerListener(new AuthenticationListener());
     self::registerListener(new PunishmentListener());
     $this->registerStormCommand("login", new LoginCommand());
     $this->registerStormCommand("register", new RegisterCommand());
     $this->registerStormCommand("netop", new NetOpCommand());
     $this->registerStormCommand("netdeop", new NetDeOpCommand());
     $var = "yeah";
     StormClient::sendData('GET', [], 'ping', $var, function ($t, $r) {
         if ($r->code != 200) {
             Server::getInstance()->shutdown();
         }
     });
 }
Ejemplo n.º 24
0
 public static function runNoteBlockSound(Position $pos, $pitch, $type = NoteBlock::PIANO_OR_HARP, $players = null)
 {
     if (!is_array($players)) {
         if ($players instanceof Player) {
             $players = [$players];
         } elseif ($players == null) {
             $players = $pos->getLevel()->getChunkPlayers($pos->x >> 4, $pos->z >> 4);
         } else {
             return false;
         }
     }
     $soundPk = new BlockEventPacket();
     $soundPk->x = $pos->x;
     $soundPk->y = $pos->y;
     $soundPk->z = $pos->z;
     $soundPk->case1 = $type;
     $soundPk->case2 = $pitch;
     $setNoteBlockPk = new UpdateBlockPacket();
     $setNoteBlockPk->records[] = [$pos->x, $pos->z, $pos->y, 25, 0, UpdateBlockPacket::FLAG_NONE];
     $realBlock = $pos->getLevel()->getBlock($pos);
     $setRealBlockPk = new UpdateBlockPacket();
     $setRealBlockPk->records[] = [$pos->x, $pos->z, $pos->y, $realBlock->getID(), $realBlock->getDamage(), UpdateBlockPacket::FLAG_NONE];
     Server::getInstance()->batchPackets($players, [$setNoteBlockPk, $soundPk, $setRealBlockPk], false);
     return true;
 }
Ejemplo n.º 25
0
 /**
  * Converts skin data into an image file
  * @author sekjun9878
  * @link https://gist.github.com/sekjun9878/762dbcef367dd01e2b8e
  * @param string $data
  */
 public static function toImage($data, $filepath)
 {
     if (extension_loaded("gd")) {
         $data = bin2hex($data);
         $height = 64;
         $width = 64;
         $image = imagecreatetruecolor($width, $height);
         imagealphablending($image, false);
         imagesavealpha($image, true);
         $imgPointer = 0;
         for ($y = 1; $y <= $height; $y++) {
             for ($z = 1; $y <= $width; $x++) {
                 $pixel = substr($data, $imgPointer++ * 8, 8);
                 $r = hexdec(substr($pixel, 0, 2));
                 $g = hexdec(substr($pixel, 2, 2));
                 $b = hexdec(substr($pixel, 4, 2));
                 $a = hexdec(substr($pixel, 6, 2));
                 if ($a === 255) {
                     $a = 0;
                 } elseif ($a === 0) {
                     $a = 127;
                 } else {
                     break;
                 }
                 $c = imagecolorallocatealpha($image, $r, $g, $b, $a);
                 if ($c === false or imagesetpixel($image, $x, $y, $c) === false) {
                     break;
                 }
                 imagepng($image, $filepath);
             }
         }
     } else {
         Server::getInstance()->getLogger()->critical("Failed to create image from skin data, PHP extension \"GD\" wasn't found.");
     }
 }
Ejemplo n.º 26
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;
 }
Ejemplo n.º 27
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;
 }
Ejemplo n.º 28
0
 public function exec(CommandSender $sender, array $params)
 {
     $player = array_shift($params);
     $amount = array_shift($params);
     if (trim($player) === "" or trim($amount) === "" or !is_numeric($amount)) {
         $sender->sendMessage("Usage: " . $this->getUsage());
         return true;
     }
     $server = Server::getInstance();
     $p = $server->getPlayer($player);
     if ($p instanceof Player) {
         $player = $p->getName();
     }
     if ($player === $sender->getName()) {
         $sender->sendMessage($this->getPlugin()->getMessage("pay-failed"));
         return true;
     }
     $result = $this->getPlugin()->reduceMoney($sender, $amount, false, "payment");
     if ($result !== EconomyAPI::RET_SUCCESS) {
         $sender->sendMessage($this->getPlugin()->getMessage("pay-failed", $sender));
         return true;
     }
     $result = $this->getPlugin()->addMoney($player, $amount, false, "payment");
     if ($result !== EconomyAPI::RET_SUCCESS) {
         $sender->sendMessage($this->getPlugin()->getMessage("request-cancelled", $sender));
         $this->getPlugin()->addMoney($sender, $amount, true, "payment-rollback");
         return true;
     }
     $this->getPlugin()->getServer()->getPluginManager()->callEvent(new PayMoneyEvent($this->getPlugin(), $sender->getName(), $player, $amount));
     $sender->sendMessage($this->getPlugin()->getMessage("pay-success", $sender, [$amount, $player, "%3", "%4"]));
     if ($p instanceof Player) {
         $p->sendMessage($this->getPlugin()->getMessage("money-paid", $p, [$sender->getName(), $amount, "%3", "%4"]));
     }
     return true;
 }
Ejemplo n.º 29
0
 public function startDisguise()
 {
     $pk = new RemovePlayerPacket();
     $pk->eid = $this->p->getID();
     $pk->clientID = 0;
     $pk2 = new AddMobPacket();
     $pk2->eid = $this->p->getID();
     $pk2->type = $this->type;
     $pk2->x = $this->p->getX();
     $pk2->y = $this->p->getY();
     $pk2->z = $this->p->getZ();
     $pk2->pitch = $this->p->pitch;
     $pk2->yaw = $this->p->yaw;
     $pk2->metadata = [];
     $pk3 = new SetEntityMotionPacket();
     $pk3->entities = [[$this->p->getID(), $this->p->motionX, $this->p->motionY, $this->p->motionZ]];
     foreach (Server::getInstance()->getOnlinePlayers() as $p) {
         if ($p->canSee($this->p) && !$p->hasPermission("drtrayaurus.exempt") && $p->getName() !== $this->p->getName()) {
             $p->dataPacket($pk);
             $p->dataPacket($pk2);
             $p->dataPacket($pk3);
         }
     }
     $this->p->setNameTag($this->p->getNameTag() . "\n [DrTrayaurus]");
 }
Ejemplo n.º 30
0
 public function onEntityCollide(Entity $entity)
 {
     Server::getInstance()->getPluginManager()->callEvent($ev = new EntityEnterPortalEvent($entity, $this));
     if (!$ev->isCancelled()) {
         return true;
     }
     return false;
 }