public function getUniversalMysqliDatabase(Plugin $ctx, $disableOnFailure = true) { if (!$this->universalMysqli instanceof \mysqli) { $data = $this->getXEconConfiguration()->getUniMysqlDetails(); $this->universalMysqli = @new \mysqli($data["host"], $data["username"], $data["password"], $data["database"], $data["port"]); if ($this->universalMysqli->connect_error) { $ctx->getLogger()->critical("Failed to connect to the xEcon universal MySQL database! " . "Reason: {$this->universalMysqli->connect_error}"); if ($disableOnFailure) { if ($ctx !== $this) { $desc = $ctx->getDescription(); $this->getLogger()->critical("Disabling {$desc->getFullName()} by " . implode(", ", $desc->getAuthors()) . " because the required universal " . "MySQL database cannot be connected to."); } else { $this->getLogger()->critical("Disabling due to required universal MySQL database not connectable."); } $ctx->getPluginLoader()->disablePlugin($ctx); } $this->universalMysqli = null; } } return $this->universalMysqli; }
/** * @param Plugin $plugin * @param Permissible $permissible * * @throws PluginException */ public function __construct(Plugin $plugin, Permissible $permissible) { if (!$plugin->isEnabled()) { throw new PluginException("Plugin " . $plugin->getDescription()->getName() . " is disabled"); } $this->permissible = $permissible; $this->plugin = $plugin; }
private function prepareData(Plugin $plugin, \Exception $e, $event) { $desc = $plugin->getDescription(); $sha = false; $class = new \ReflectionClass($plugin); $file = $class->getProperty("file"); $file->setAccessible(true); $path = $file->getValue($plugin); $file->setAccessible(false); $path = realpath("{$path}/.git/refs/heads/master"); if (is_file($path)) { $sha = trim(file_get_contents($path)); } $this->payload = serialize(["repo" => "LegendOfMCPE/xEcon", "plugin" => ["name" => $desc->getName(), "version" => $desc->getVersion()], "event" => $event, "exception" => ["class" => get_class($e), "message" => $e->getMessage(), "trace" => $e->getTraceAsString(), "trace-array" => $e->getTrace(), "file" => $e->getFile(), "line" => $e->getLine(), "code" => $e->getCode()], "sha" => $sha]); }
private function describeToSender(Plugin $plugin, CommandSender $sender) { $desc = $plugin->getDescription(); $sender->sendMessage(TextFormat::DARK_GREEN . $desc->getName() . TextFormat::WHITE . " version " . TextFormat::DARK_GREEN . $desc->getVersion()); if ($desc->getDescription() != null) { $sender->sendMessage($desc->getDescription()); } if ($desc->getWebsite() != null) { $sender->sendMessage("Website: " . $desc->getWebsite()); } if (count($authors = $desc->getAuthors()) > 0) { if (count($authors) === 1) { $sender->sendMessage("Author: " . implode(", ", $authors)); } else { $sender->sendMessage("Authors: " . implode(", ", $authors)); } } }
/** * @param Plugin $plugin */ public function disablePlugin(Plugin $plugin) { if ($plugin instanceof PluginBase and $plugin->isEnabled()) { MainLogger::getLogger()->info("Disabling " . $plugin->getDescription()->getFullName()); Server::getInstance()->getPluginManager()->callEvent(new PluginDisableEvent($plugin)); $plugin->setEnabled(false); } }
/** * @param Plugin $plugin */ public function disablePlugin(Plugin $plugin) { if ($plugin instanceof PluginBase and $plugin->isEnabled()) { $this->server->getLogger()->info($this->server->getLanguage()->translateString("pocketmine.plugin.disable", [$plugin->getDescription()->getFullName()])); $this->server->getPluginManager()->callEvent(new PluginDisableEvent($plugin)); $plugin->setEnabled(false); } }
/** * @param Plugin $plugin */ public function disablePlugin(Plugin $plugin) { if ($plugin instanceof PluginBase and $plugin->isEnabled()) { $this->server->getKatana()->console->plugin("Disabling " . Terminal::$COLOR_WHITE . $plugin->getDescription()->getFullName()); $this->server->getPluginManager()->callEvent(new PluginDisableEvent($plugin)); $plugin->setEnabled(false); } }
/** * @param string $event Class name that extends Event * @param Listener $listener * @param int $priority * @param EventExecutor $executor * @param Plugin $plugin * @param bool $ignoreCancelled * * @throws PluginException */ public function registerEvent($event, Listener $listener, $priority, EventExecutor $executor, Plugin $plugin, $ignoreCancelled = false) { if (!is_subclass_of($event, Event::class) or (new \ReflectionClass($event))->isAbstract()) { throw new PluginException($event . " is not a valid Event"); } if (!$plugin->isEnabled()) { throw new PluginException("Plugin attempted to register " . $event . " while not enabled"); } $timings = new TimingsHandler("Plugin: " . $plugin->getDescription()->getFullName() . " Event: " . get_class($listener) . "::" . ($executor instanceof MethodEventExecutor ? $executor->getMethod() : "???") . "(" . (new \ReflectionClass($event))->getShortName() . ")", self::$pluginParentTimer); $this->getEventListeners($event)->register(new RegisteredListener($listener, $executor, $priority, $plugin, $ignoreCancelled, $timings)); }
/** * @param Plugin $context */ public function __construct(Plugin $context) { $prefix = $context->getDescription()->getPrefix(); $this->pluginName = $prefix != null ? "[{$prefix}] " : "[" . $context->getDescription()->getName() . "] "; }
/** * //TODO: tick scheduled attachments * * @param Plugin $plugin * @param string $name * @param bool $value * * @return PermissionAttachment * * @throws \Exception */ public function addAttachment(Plugin $plugin, $name = null, $value = null) { if ($plugin === null) { throw new \Exception("Plugin cannot be null"); } elseif (!$plugin->isEnabled()) { throw new \Exception("Plugin " . $plugin->getDescription()->getName() . " is disabled"); } $result = new PermissionAttachment($plugin, $this->parent); $this->attachments[spl_object_hash($result)] = $result; if ($name !== null and $value !== null) { $result->setPermission($name, $value); } $this->recalculatePermissions(); return $result; }
private function cmdInfo(CommandSender $c, Plugin $p, $pageNumber) { $txt = []; $desc = $p->getDescription(); $txt[] = TextFormat::AQUA . mc::_("Plugin: %1%", $desc->getFullName()); if ($desc->getDescription()) { $txt[] = TextFormat::GREEN . mc::_("Description: ") . TextFormat::WHITE . $desc->getDescription(); } if ($desc->getPrefix()) { $txt[] = TextFormat::GREEN . mc::_("Prefix: ") . ($txt[] = TextFormat::GREEN . mc::_("Main Class: ") . TextFormat::WHITE . $desc->getMain()); } if ($desc->getWebsite()) { $txt[] = TextFormat::GREEN . mc::_("WebSite: ") . TextFormat::WHITE . $desc->getWebsite(); } if (count($desc->getCompatibleApis())) { $txt[] = TextFormat::GREEN . mc::_("APIs: ") . TextFormat::WHITE . implode(TextFormat::BLUE . ", " . TextFormat::WHITE, $desc->getCompatibleApis()); } if (count($desc->getAuthors())) { $txt[] = TextFormat::GREEN . mc::_("Authors: ") . TextFormat::WHITE . implode(TextFormat::BLUE . ", " . TextFormat::WHITE, $desc->getAuthors()); } if (count($desc->getDepend())) { $txt[] = TextFormat::GREEN . mc::_("Dependancies: ") . TextFormat::WHITE . implode(TextFormat::BLUE . ", " . TextFormat::WHITE, $desc->getDepend()); } if (count($desc->getSoftDepend())) { $txt[] = TextFormat::GREEN . mc::_("Soft-Dependancies: ") . TextFormat::WHITE . implode(TextFormat::BLUE . ", " . TextFormat::WHITE, $desc->getSoftDepend()); } if (count($desc->getLoadBefore())) { $txt[] = TextFormat::GREEN . mc::_("Load Before: ") . TextFormat::WHITE . implode(TextFormat::BLUE . ", " . TextFormat::WHITE, $desc->getLoadBefore()); } if (($cnt = count($desc->getCommands())) > 0) { $txt[] = TextFormat::GREEN . mc::_("Commands: ") . TextFormat::WHITE . $cnt; } if (($cnt = count($desc->getPermissions())) > 0) { $txt[] = TextFormat::GREEN . mc::_("Permissions: ") . TextFormat::WHITE . $cnt; } $loader = explode("\\", get_class($p->getPluginLoader())); $txt[] = TextFormat::GREEN . mc::_("PluginLoader: ") . TextFormat::WHITE . array_pop($loader); $file = $this->getPluginFilePath($p); $txt[] = TextFormat::GREEN . mc::_("FileName: ") . TextFormat::WHITE . $file; return $this->paginateText($c, $pageNumber, $txt); }