作者:PocketMine-PHP
项目:EconomyS-PHP
public function onEnable()
{
if (!file_exists($this->getDataFolder())) {
mkdir($this->getDataFolder());
}
$this->saveDefaultConfig();
$provider = $this->getConfig()->get("data-provider");
switch (strtolower($provider)) {
case "yaml":
$this->provider = new YamlDataProvider($this->getDataFolder() . "Shops.yml", $this->getConfig()->get("auto-save"));
break;
default:
$this->getLogger()->critical("Invalid data provider was given. EconomyShop will be terminated.");
return;
}
$this->getLogger()->notice("Data provider was set to: " . $this->provider->getProviderName());
$levels = [];
foreach ($this->provider->getAll() as $shop) {
if ($shop[9] !== -2) {
if (!isset($levels[$shop[3]])) {
$levels[$shop[3]] = $this->getServer()->getLevelByName($shop[3]);
}
$pos = new Position($shop[0], $shop[1], $shop[2], $levels[$shop[3]]);
$display = $pos;
if ($shop[9] !== -1) {
$display = $pos->getSide($shop[9]);
}
$this->items[$shop[3]][] = new ItemDisplayer($display, Item::get($shop[4], $shop[5]), $pos);
}
}
$this->getServer()->getPluginManager()->registerEvents($this, $this);
$this->lang = json_decode(stream_get_contents($rsc = $this->getResource("lang_en.json")), true);
// TODO: Language preferences
@fclose($rsc);
}
作者:iTXTec
项目:Genisy
public function execute(CommandSender $sender, $commandLabel, array $args)
{
if (!$this->testPermission($sender)) {
return true;
}
if (!$sender instanceof Player and count($args) < 4) {
$sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage]));
return false;
}
if ($sender instanceof Player and count($args) < 4) {
$pos = $sender->getPosition();
} else {
$level = $sender->getServer()->getLevelByName($args[3]);
if (!$level instanceof Level) {
$sender->sendMessage(TextFormat::RED . "Invalid level name");
return false;
}
$pos = new Position((int) $args[0], (int) $args[1], (int) $args[2], $level);
}
if (!isset($args[4]) or $args[0] != "regenerate") {
$chunk = $pos->getLevel()->getChunk($pos->x >> 4, $pos->z >> 4);
McRegion::getRegionIndex($chunk->getX(), $chunk->getZ(), $x, $z);
$sender->sendMessage("Region X: {$x} Region Z: {$z}");
} elseif ($args[4] == "regenerate") {
foreach ($sender->getServer()->getOnlinePlayers() as $p) {
if ($p->getLevel() == $pos->getLevel()) {
$p->kick(TextFormat::AQUA . "A chunk of this chunk is regenerating, please re-login.", false);
}
}
$pos->getLevel()->regenerateChunk($pos->x >> 4, $pos->z >> 4);
}
return true;
}
作者:dog19
项目:Economy
public function onEnable()
{
$this->saveDefaultConfig();
if (!$this->selectLang()) {
$this->getLogger()->warning("Invalid language option was given.");
}
$provider = $this->getConfig()->get("data-provider");
switch (strtolower($provider)) {
case "yaml":
$this->provider = new YamlDataProvider($this->getDataFolder() . "Sells.yml", $this->getConfig()->get("auto-save"));
break;
default:
$this->getLogger()->critical("Invalid data provider was given. EconomySell will be terminated.");
return;
}
$this->getLogger()->notice("Data provider was set to: " . $this->provider->getProviderName());
$levels = [];
foreach ($this->provider->getAll() as $sell) {
if ($sell[9] !== -2) {
if (!isset($levels[$sell[3]])) {
$levels[$sell[3]] = $this->getServer()->getLevelByName($sell[3]);
}
$pos = new Position($sell[0], $sell[1], $sell[2], $levels[$sell[3]]);
$display = $pos;
if ($sell[9] !== -1) {
$display = $pos->getSide($sell[9]);
}
$this->items[$sell[3]][] = new ItemDisplayer($display, Item::get($sell[4], $sell[5]), $pos);
}
}
$this->getServer()->getPluginManager()->registerEvents($this, $this);
}
作者:Ad500
项目:WorldEditAr
public function putPosition(Position $position)
{
$this->putLong($position->x);
$this->putShort($position->y);
$this->putLong($position->z);
$this->putString($position->isValid() ? $position->getLevel()->getName() : "");
}
作者:ken7773
项目:PocketMine-0.13.
public function __construct(Position $center, $size, $what = \null)
{
$this->level = $center->getLevel();
$this->source = $center;
$this->size = \max($size, 0);
$this->what = $what;
}
作者:TDMGamingM
项目:pocketmine-1vs1-plugi
/**
* Really starts the duel after countdown
*/
public function startDuel()
{
Server::getInstance()->getScheduler()->cancelTask($this->countdownTaskHandler->getTaskId());
$player1 = $this->players[0];
$player2 = $this->players[1];
$pos_player1 = Position::fromObject($this->position, $this->position->getLevel());
$pos_player1->x += self::PLAYER_1_OFFSET_X;
$pos_player2 = Position::fromObject($this->position, $this->position->getLevel());
$pos_player2->x += self::PLAYER_2_OFFSET_X;
$player1->teleport($pos_player1, 90, 0);
$player2->teleport($pos_player2, -90, 0);
// Fix start time
$this->startTime = new DateTime('now');
$player1->sendTip(TextFormat::RED . "You are strarting a duel !");
$player1->sendMessage(" ");
$player1->sendMessage(TextFormat::RED . TextFormat::BOLD . "++++++++=++++++++");
$player1->sendMessage(TextFormat::AQUA . ">" . TextFormat::RESET . " You're starting a duel against : " . $player2->getName() . " !");
$player1->sendMessage(TextFormat::AQUA . ">" . TextFormat::RESET . " You have 3min !");
$player1->sendMessage(TextFormat::AQUA . ">" . TextFormat::RESET . " Good luck :) !");
$player1->sendMessage(TextFormat::RED . TextFormat::BOLD . "++++++++=++++++++");
$player1->sendMessage(" ");
$player1->sendTip(TextFormat::RED . "You are strarting a duel !");
$player2->sendMessage(" ");
$player2->sendMessage(TextFormat::RED . TextFormat::BOLD . "++++++++=++++++++");
$player2->sendMessage(TextFormat::AQUA . ">" . TextFormat::RESET . " You're starting a duel against : " . $player1->getName() . " !");
$player2->sendMessage(TextFormat::AQUA . ">" . TextFormat::RESET . " You have 3min !");
$player2->sendMessage(TextFormat::AQUA . ">" . TextFormat::RESET . " Good luck :) !");
$player2->sendMessage(TextFormat::RED . TextFormat::BOLD . "++++++++=++++++++");
$player2->sendMessage(" ");
// Launch the end round task
$task = new RoundCheckTask(OneVsOne::getInstance());
$task->arena = $this;
$this->taskHandler = Server::getInstance()->getScheduler()->scheduleDelayedTask($task, self::ROUND_DURATION * 20);
}
作者:Supper
项目:pocketmine-1vs1-plugi
/**
* Really starts the duel after countdown
*/
public function startDuel()
{
Server::getInstance()->getScheduler()->cancelTask($this->countdownTaskHandler->getTaskId());
$player1 = $this->players[0];
$player2 = $this->players[1];
$pos_player1 = Position::fromObject($this->position, $this->position->getLevel());
$pos_player1->x += self::PLAYER_1_OFFSET_X;
$pos_player2 = Position::fromObject($this->position, $this->position->getLevel());
$pos_player2->x += self::PLAYER_2_OFFSET_X;
$player1->teleport($pos_player1, 90, 0);
$player2->teleport($pos_player2, -90, 0);
$this->sparyParticle($player1);
$this->sparyParticle($player2);
$player1->setGamemode(0);
$player2->setGamemode(0);
// Give kit
foreach ($this->players as $player) {
$this->giveKit($player);
}
// Fix start time
$this->startTime = new DateTime('now');
$player1->sendTip(OneVsOne::getMessage("duel_tip"));
$player1->sendMessage(OneVsOne::getMessage("duel_start"));
$player2->sendTip(OneVsOne::getMessage("duel_tip"));
$player2->sendMessage(OneVsOne::getMessage("duel_start"));
// Launch the end round task
$task = new RoundCheckTask(OneVsOne::getInstance());
$task->arena = $this;
$this->taskHandler = Server::getInstance()->getScheduler()->scheduleDelayedTask($task, self::ROUND_DURATION * 20);
}
作者:organizatio
项目:AddNoteBloc
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;
}
作者:0-DevMatthew-
项目:pocketmine-plugin
public function setHome(IPlayer $player, Position $pos)
{
$n = strtolower($player->getName());
$l = "l-" . strtolower($pos->getLevel()->getName());
$this->homes[$l][$n] = [$pos->getX(), $pos->getY(), $pos->getZ()];
$this->saveHomes();
}
作者:iTXTec
项目:Genisy
public function __construct(Position $center, $size, $what = null, bool $dropItem = true)
{
$this->level = $center->getLevel();
$this->source = $center;
$this->size = max($size, 0);
$this->what = $what;
$this->dropItem = $dropItem;
}
作者:barnseyminesu
项目:Small-ZC-Plugin
public function operate(Position $anchor)
{
if (is_int($this->delta)) {
throw new \BadMethodCallException("MacroOperation is of type TRUE (wait) not FALSE (operate) thus cannot be operated");
}
$anchor->getLevel()->setBlock($anchor->add($this->delta), $this->block, false, true);
// update
}
作者:JiangsNetworkAlph
项目:JiangsNeathe
public function savePosition(Position $pos, $pitch = 0, $yaw = 0)
{
$this->data["x"] = $pos->x;
$this->data["y"] = $pos->y;
$this->data["z"] = $pos->z;
$this->data["pitch"] = $pitch;
$this->data["yaw"] = $yaw;
$this->data["levelName"] = $pos->getLevel()->getFolderName();
}
作者:barnseyminesu
项目:Small-ZC-Plugin
/**
* @param Position $pos
* @return Area|null
*/
public function searchAreaByPosition(Position $pos)
{
foreach ($this->getAreas() as $area) {
$l = $area->getShape()->getLevelName();
if ($l !== $pos->getLevel()->getName()) {
continue;
}
if ($area->getShape()->isInside($pos)) {
return $area;
}
}
return null;
}
作者:Tee7eve
项目:iZon
/**
* @param Position $position
* @param $radius
*
* @return bool
*/
public function isOnRadius(Position $position, $radius)
{
if ($this->minX - $radius <= $position->x && $position->x <= $this->maxX + $radius) {
if ($this->minY - $radius <= $position->y && $position->y <= $this->maxY + $radius) {
if ($this->minZ - $radius <= $position->z && $position->z <= $this->maxZ + $radius) {
if ($position->getLevel()->getName() === $this->levelName) {
return true;
}
}
}
}
return false;
}
作者:bjorgu
项目:pocketmine-1vs1-plugi
/**
* Create arenas
*/
public function parseArenaPositions(array $arenaPositions)
{
foreach ($arenaPositions as $n => $arenaPosition) {
Server::getInstance()->loadLevel($arenaPosition[3]);
if (($level = Server::getInstance()->getLevelByName($arenaPosition[3])) === null) {
Server::getInstance()->getLogger()->error("[1vs1] - " . $arenaPosition[3] . " is not loaded. Arena " . $n . " is disabled.");
} else {
$newArenaPosition = new Position($arenaPosition[0], $arenaPosition[1], $arenaPosition[2], $level);
$newArena = new Arena($newArenaPosition, $this);
array_push($this->arenas, $newArena);
Server::getInstance()->getLogger()->debug("[1vs1] - Arena " . $n . " loaded at position " . $newArenaPosition->__toString());
}
}
}
作者:barnseyminesu
项目:Small-ZC-Plugin
public function getPosList()
{
$out = [];
for ($x = $this->centre->getX() - $this->radius; $x <= $this->centre->getX() + $this->radius; $x++) {
for ($y = $this->centre->getY() - $this->radius; $y <= $this->centre->getY() + $this->radius; $x++) {
for ($z = $this->centre->getZ() - $this->radius; $z <= $this->centre->getZ() + $this->radius; $x++) {
$v = new Position($x, $y, $z, $this->centre->getLevel());
if ($v->distance($this->centre) <= $this->radius) {
$out[] = $v;
}
}
}
}
return $out;
}
作者:thebigsmileX
项目:PocketMine-MP-Plugin
public function placeJail(Position $pos, $type = "default", $key = null)
{
$blocks = $this->getJailBlocks($type);
if ($blocks !== false) {
$x = (int) $pos->getX();
$y = (int) $pos->getY();
$z = (int) $pos->getZ();
$level = $pos->getLevel();
$log = array($level);
foreach ($blocks as $data) {
//data[0] x座標, data[1] y座標, data[2] z座標, data[3] blockid, data[4] meta値
$pos = new Vector3($x + $data[0], $y + $data[1], $z + $data[2]);
$block = Block::get($data[3], $data[4]);
if ($key !== null) {
$log[] = array($pos, $level->getBlock($pos));
}
$level->setBlock($pos, $block);
}
if ($key !== null) {
$this->logs[$key][] = $log;
}
return true;
}
return false;
}
作者:steveritte
项目:EntityManage
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();
}
}
}
作者:MCPEGamerJPatGitHu
项目:PocketFaction
protected function writePosition(Position $pos)
{
$this->buffer .= Bin::writeInt($pos->getX() >> 4);
$this->buffer .= Bin::writeInt($pos->getZ() >> 4);
$this->buffer .= Bin::writeByte(($pos->getX() & 0xf) << 4 & ($pos->getZ() & 0xf));
$this->buffer .= Bin::writeByte(strlen($pos->getLevel()->getName()));
$this->buffer .= $pos->getLevel()->getName();
}
作者:nesgohoo
项目:PMMP-Plugin
/**
* @priority high
*/
public function onDeath(PlayerRespawnEvent $event)
{
$level = $event->getPlayer()->getLevel();
$pillarPos = new Position($event->getPlayer()->x, $event->getPlayer()->y, $event->getPlayer()->z, $level);
for ($h = 1; $h <= 30; $h++) {
$pillarPos->setComponents($pillarPos->x, ++$pillarPos->y, $pillarPos->z);
$level->addParticle(new RedstoneParticle($pillarPos, 10));
}
$pillarPos->setComponents($pillarPos->x, $pillarPos->y - 10, $pillarPos->z);
$headPos = new Position($pillarPos->x, $pillarPos->y, $pillarPos->z, $level);
for ($r = -5; $r <= 5; $r++) {
$headPos->setComponents($pillarPos->x + $r, $pillarPos->y, $pillarPos->z);
$level->addParticle(new ExplodeParticle($headPos));
$p = new RedstoneParticle($headPos, 10);
$level->addParticle($p);
}
}