public function __construct(Server $server, $type, $playerList = []) { $endpoint = "http://" . $server->getProperty("anonymous-statistics.host", "stats.BukkitPE.net") . "/"; $data = []; $data["uniqueServerId"] = $server->getServerUniqueId()->toString(); $data["uniqueMachineId"] = Utils::getMachineUniqueId()->toString(); $data["uniqueRequestId"] = UUID::fromData($server->getServerUniqueId(), microtime(true))->toString(); switch ($type) { case self::TYPE_OPEN: $data["event"] = "open"; $version = new VersionString(); $data["server"] = ["port" => $server->getPort(), "software" => $server->getName(), "fullVersion" => $version->get(true), "version" => $version->get(), "build" => $version->getBuild(), "api" => $server->getApiVersion(), "minecraftVersion" => $server->getVersion(), "protocol" => Info::CURRENT_PROTOCOL]; $data["system"] = ["operatingSystem" => Utils::getOS(), "cores" => Utils::getCoreCount(), "phpVersion" => PHP_VERSION, "machine" => php_uname("a"), "release" => php_uname("r"), "platform" => php_uname("i")]; $data["players"] = ["count" => 0, "limit" => $server->getMaxPlayers()]; $plugins = []; foreach ($server->getPluginManager()->getPlugins() as $p) { $d = $p->getDescription(); $plugins[$d->getName()] = ["name" => $d->getName(), "version" => $d->getVersion(), "enabled" => $p->isEnabled()]; } $data["plugins"] = $plugins; break; case self::TYPE_STATUS: $data["event"] = "status"; $data["server"] = ["ticksPerSecond" => $server->getTicksPerSecondAverage(), "tickUsage" => $server->getTickUsageAverage(), "ticks" => $server->getTick()]; //This anonymizes the user ids so they cannot be reversed to the original foreach ($playerList as $k => $v) { $playerList[$k] = md5($v); } $players = []; foreach ($server->getOnlinePlayers() as $p) { if ($p->isOnline()) { $players[] = md5($p->getUniqueId()->toBinary()); } } $data["players"] = ["count" => count($players), "limit" => $server->getMaxPlayers(), "currentList" => $players, "historyList" => array_values($playerList)]; $info = Utils::getMemoryUsage(true); $data["system"] = ["mainMemory" => $info[0], "totalMemory" => $info[1], "availableMemory" => $info[2], "threadCount" => Utils::getThreadCount()]; break; case self::TYPE_CLOSE: $data["event"] = "close"; $data["crashing"] = $server->isRunning(); break; } $this->endpoint = $endpoint . "api/post"; $this->data = json_encode($data); }
private function setDefaultCommands() { $this->register("BukkitPE", new VersionCommand("version")); $this->register("BukkitPE", new PluginsCommand("plugins")); $this->register("BukkitPE", new SeedCommand("seed")); $this->register("BukkitPE", new HelpCommand("help")); $this->register("BukkitPE", new StopCommand("stop")); $this->register("BukkitPE", new TellCommand("tell")); $this->register("BukkitPE", new DefaultGamemodeCommand("defaultgamemode")); $this->register("BukkitPE", new BanCommand("ban")); $this->register("BukkitPE", new BanIpCommand("ban-ip")); $this->register("BukkitPE", new BanListCommand("banlist")); $this->register("BukkitPE", new PardonCommand("pardon")); $this->register("BukkitPE", new PardonIpCommand("pardon-ip")); $this->register("BukkitPE", new SayCommand("say")); $this->register("BukkitPE", new MeCommand("me")); $this->register("BukkitPE", new ListCommand("list")); $this->register("BukkitPE", new DifficultyCommand("difficulty")); $this->register("BukkitPE", new KickCommand("kick")); $this->register("BukkitPE", new OpCommand("op")); $this->register("BukkitPE", new DeopCommand("deop")); $this->register("BukkitPE", new WhitelistCommand("whitelist")); $this->register("BukkitPE", new SaveOnCommand("save-on")); $this->register("BukkitPE", new SaveOffCommand("save-off")); $this->register("BukkitPE", new SaveCommand("save-all")); $this->register("BukkitPE", new GiveCommand("give")); $this->register("BukkitPE", new EffectCommand("effect")); $this->register("BukkitPE", new EnchantCommand("enchant")); $this->register("BukkitPE", new ExpCommand("xp")); $this->register("BukkitPE", new ParticleCommand("particle")); $this->register("BukkitPE", new GamemodeCommand("gamemode")); $this->register("BukkitPE", new KillCommand("kill")); $this->register("BukkitPE", new SpawnpointCommand("spawnpoint")); $this->register("BukkitPE", new SetWorldSpawnCommand("setworldspawn")); $this->register("BukkitPE", new TeleportCommand("tp")); $this->register("BukkitPE", new TimeCommand("time")); $this->register("BukkitPE", new TimingsCommand("timings")); $this->register("BukkitPE", new ReloadCommand("reload")); $this->register("BukkitPE", new WeatherCommand("weather")); if ($this->server->getProperty("debug.commands", false)) { $this->register("BukkitPE", new StatusCommand("status")); $this->register("BukkitPE", new GarbageCollectorCommand("gc")); $this->register("BukkitPE", new DumpMemoryCommand("dumpmemory")); } }
public function __construct(Server $server, $timeout = 5) { $this->timeout = $timeout; $this->serverName = $server->getServerName(); $this->listPlugins = $server->getProperty("settings.query-plugins", true); $this->plugins = $server->getPluginManager()->getPlugins(); $this->players = []; foreach ($server->getOnlinePlayers() as $player) { if ($player->isOnline()) { $this->players[] = $player; } } $this->gametype = ($server->getGamemode() & 0x1) === 0 ? "SMP" : "CMP"; $this->version = $server->getVersion(); $this->server_engine = $server->getName() . " " . $server->getBukkitPEVersion(); $this->map = $server->getDefaultLevel() === null ? "unknown" : $server->getDefaultLevel()->getName(); $this->numPlayers = count($this->players); $this->maxPlayers = $server->getMaxPlayers(); $this->whitelist = $server->hasWhitelist() ? "on" : "off"; $this->port = $server->getPort(); $this->ip = $server->getIp(); }
/** * Registers all the events in the given Listener class * * @param Listener $listener * @param Plugin $plugin * * @throws PluginException */ public function registerEvents(Listener $listener, Plugin $plugin) { if (!$plugin->isEnabled()) { throw new PluginException("Plugin attempted to register " . get_class($listener) . " while not enabled"); } $reflection = new \ReflectionClass(get_class($listener)); foreach ($reflection->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) { if (!$method->isStatic()) { $priority = EventPriority::NORMAL; $ignoreCancelled = false; if (preg_match("/^[\t ]*\\* @priority[\t ]{1,}([a-zA-Z]{1,})/m", (string) $method->getDocComment(), $matches) > 0) { $matches[1] = strtoupper($matches[1]); if (defined(EventPriority::class . "::" . $matches[1])) { $priority = constant(EventPriority::class . "::" . $matches[1]); } } if (preg_match("/^[\t ]*\\* @ignoreCancelled[\t ]{1,}([a-zA-Z]{1,})/m", (string) $method->getDocComment(), $matches) > 0) { $matches[1] = strtolower($matches[1]); if ($matches[1] === "false") { $ignoreCancelled = false; } elseif ($matches[1] === "true") { $ignoreCancelled = true; } } $parameters = $method->getParameters(); if (count($parameters) === 1 and $parameters[0]->getClass() instanceof \ReflectionClass and is_subclass_of($parameters[0]->getClass()->getName(), Event::class)) { $class = $parameters[0]->getClass()->getName(); $reflection = new \ReflectionClass($class); if (strpos((string) $reflection->getDocComment(), "@deprecated") !== false and $this->server->getProperty("settings.deprecated-verbose", true)) { $this->server->getLogger()->warning($this->server->getLanguage()->translateString("BukkitPE.plugin.deprecatedEvent", [$plugin->getName(), $class, get_class($listener) . "->" . $method->getName() . "()"])); } $this->registerEvent($class, $listener, $priority, new MethodEventExecutor($method->getName()), $plugin, $ignoreCancelled); } } } }
/** * Tries to break a block using a item, including Player time checks if available * It'll try to lower the durability if Item is a tool, and set it to Air if broken. * * @param Vector3 $vector * @param Item &$item (if null, can break anything) * @param Player $player * @param bool $createParticles * * @return boolean */ public function useBreakOn(Vector3 $vector, Item &$item = null, Player $player = null, $createParticles = false) { $target = $this->getBlock($vector); //TODO: Adventure mode checks if ($item === null) { $item = Item::get(Item::AIR, 0, 0); } if ($player !== null) { $ev = new BlockBreakEvent($player, $target, $item, $player->isCreative() ? true : false); if ($player->isSpectator() or !$player->isOp() and $player->isAdventure()) { $ev->setCancelled(); } if ($item instanceof Tool) { $item->setDamage($item->getDamage() + $item->getDamageStep($target)); $player->getInventory()->setItemInHand($item); } if ($player->isSurvival() and $item instanceof Item and !$target->isBreakable($item)) { $ev->setCancelled(); } if (!$player->isOp() and ($distance = $this->server->getSpawnRadius()) > -1) { $t = new Vector2($target->x, $target->z); $s = new Vector2($this->getSpawnLocation()->x, $this->getSpawnLocation()->z); if ($t->distance($s) <= $distance) { $ev->setCancelled(); } } $this->server->getPluginManager()->callEvent($ev); if ($ev->isCancelled()) { return false; } $breakTime = $target->getBreakTime($item); if ($player->isCreative() and $breakTime > 0.15) { $breakTime = 0.15; } if ($player->hasEffect(Effect::SWIFTNESS)) { $breakTime *= 1 - 0.2 * ($player->getEffect(Effect::SWIFTNESS)->getAmplifier() + 1); } if ($player->hasEffect(Effect::MINING_FATIGUE)) { $breakTime *= 1 + 0.3 * ($player->getEffect(Effect::MINING_FATIGUE)->getAmplifier() + 1); } $breakTime -= 0.05; //1 tick compensation if (!$ev->getInstaBreak() and $player->lastBreak + $breakTime > microtime(true)) { return false; } $player->lastBreak = microtime(true); $drops = $ev->getDrops(); if ($this->server->getProperty("experience.enable", true) and $this->server->getProperty("experience.break-drop", true) and $player->isSurvival()) { $exp = $target->getExperience(); $this->spawnExperienceOrb($vector->add(0, 1, 0), $exp); } } elseif ($item !== null and !$target->isBreakable($item)) { return false; } else { $drops = $target->getDrops($item); //Fixes tile entities being deleted before getting drops foreach ($drops as $k => $i) { $drops[$k] = Item::get($i[0], $i[1], $i[2]); } } $tag = $item->getNamedTagEntry("CanDestroy"); if ($tag instanceof Enum) { $canBreak = false; foreach ($tag as $v) { if ($v instanceof String) { $entry = Item::fromString($v->getValue()); if ($entry->getId() > 0 and $entry->getBlock() !== null and $entry->getBlock()->getId() === $target->getId()) { $canBreak = true; break; } } } if (!$canBreak) { return false; } } if ($createParticles) { $players = $this->getChunkPlayers($target->x >> 4, $target->z >> 4); if ($player !== null) { unset($players[$player->getLoaderId()]); } $this->addParticle(new DestroyBlockParticle($target->add(0.5), $target), $players); } $target->onBreak($item); $tile = $this->getTile($target); if ($tile !== null) { if ($tile instanceof InventoryHolder) { if ($tile instanceof Chest) { $tile->unpair(); } foreach ($tile->getInventory()->getContents() as $chestItem) { $this->dropItem($target, $chestItem); } } $tile->close(); } if ($item !== null) { $item->useOn($target); if ($item->isTool() and $item->getDamage() >= $item->getMaxDurability()) { $item = Item::get(Item::AIR, 0, 0); } } if ($player === null or $player->isSurvival()) { foreach ($drops as $drop) { if ($drop->getCount() > 0) { $this->dropItem($vector->add(0.5, 0.5, 0.5), $drop); } } } return true; }