public static function getSimpleAuthData(Plugin $plugin, $db = null) { if (!file_exists($plugin->getDataFolder() . "SimpleAuth/players")) { return; } $config = (new Config($plugin->getDataFolder() . "SimpleAuth/config.yml", Config::YAML))->getAll(); $provider = $config["dataProvider"]; switch (strtolower($provider)) { case "yaml": $plugin->getLogger()->debug("Using YAML data provider"); $provider = new YAMLDataProvider($plugin); break; case "sqlite3": $plugin->getLogger()->debug("Using SQLite3 data provider"); $provider = new SQLite3DataProvider($plugin); break; case "mysql": $plugin->getLogger()->debug("Using MySQL data provider"); $provider = new MySQLDataProvider($plugin); break; case "none": default: $provider = new DummyDataProvider($plugin); break; } $folderList = self::getFolderList($plugin->getDataFolder() . "SimpleAuth/players", "folder"); foreach ($folderList as $alphabet) { $ymlList = self::getFolderList($plugin->getDataFolder() . "SimpleAuth/players/" . $alphabet, "file"); foreach ($ymlList as $ymlName) { $yml = (new Config($plugin->getDataFolder() . "SimpleAuth/players/" . $alphabet . "/" . $ymlName, Config::YAML))->getAll(); $name = explode(".", $ymlName)[0]; if ($db instanceof PluginData) { $db->addAuthReady(mb_convert_encoding($name, "UTF-8"), $yml["hash"]); } } } self::rmdirAll($plugin->getDataFolder() . "SimpleAuth"); }
public function __construct(Plugin $plugin) { $this->plugin = $plugin; $config = $this->plugin->getConfig()->get("dataProviderSettings"); if (!isset($config["host"]) or !isset($config["user"]) or !isset($config["password"]) or !isset($config["database"])) { $this->plugin->getLogger()->critical("Invalid MySQL settings"); $this->plugin->setDataProvider(new DummyDataProvider($this->plugin)); return; } $this->database = new \mysqli($config["host"], $config["user"], $config["password"], $config["database"], isset($config["port"]) ? $config["port"] : 3306); if ($this->database->connect_error) { $this->plugin->getLogger()->critical("Couldn't connect to MySQL: " . $this->database->connect_error); $this->plugin->setDataProvider(new DummyDataProvider($this->plugin)); return; } $resource = $this->plugin->getResource("mysql.sql"); $this->database->query(stream_get_contents($resource)); fclose($resource); $this->plugin->getServer()->getScheduler()->scheduleRepeatingTask(new MySQLPingTask($this->plugin, $this->database), 600); // Each 30 seconds $this->plugin->getLogger()->info("Connected to MySQL server"); }
public function __construct(Plugin $plugin) { $this->plugin = $plugin; if ($plugin->getServer()->getPluginManager()->getPlugin("SimpleArea") != null) { $plugin->getServer()->getPluginManager()->registerEvents($this, $plugin); } }
/** * @param Plugin $plugin * * @return EconomyAPIListener */ public static function getInstance(Plugin $plugin) { if (!isset(self::$instance[$plugin->getName()])) { self::$instance[$plugin->getName()] = new EconomyAPIListener($plugin); } return self::$instance[$plugin->getName()]; }
public function savePlayer(IPlayer $player, array $config) { $name = trim(strtolower($player->getName())); $data = new Config($this->plugin->getDataFolder() . "players/" . $name[0] . "/{$name}.yml", Config::YAML); $data->setAll($config); $data->save(); }
/** * @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; }
public function __construct(Plugin $plugin) { if ($this->getResultType() !== self::TYPE_RAW and $this->getExpectedColumns() === null) { echo "Fatal: Plugin error. ", static::class . " must override getExpectedColumns(), but it didn't. Committing suicide."; sleep(604800); die; } $plugin->getServer()->getScheduler()->scheduleAsyncTask($this); }
public function __construct(Plugin $plugin) { $this->plugin = $plugin; if ($plugin->getServer()->getPluginManager()->getPlugin("EDGE") != null) { $plugin->getServer()->getPluginManager()->registerEvents($this, $plugin); // $this->edge = EDGE::getInstance (); $this->edge = $plugin->getServer()->getPluginManager()->getPlugin("EDGE"); $this->callback = $this->plugin->getServer()->getScheduler()->scheduleRepeatingTask(new EDGEControlTask($this), 20); } }
static function Execute(Plugin $owner, $callback, $delay = 1, $mode = 0) { switch ($mode) { case 0: return $owner->getServer()->getScheduler()->scheduleDelayedTask(new ExecuteTask($owner, $callback), $delay); break; case 1: return $owner->getServer()->getScheduler()->scheduleRepeatingTask(new ExecuteTask($owner, $callback), $delay); break; } }
/** * If GrabBag is available, try to get a single shared instance of * ExpandVars */ public static function getCommonVars(Plugin $owner) { $pm = $owner->getServer()->getPluginManager(); if (($gb = $pm->getPlugin("GrabBag")) !== null) { if ($gb->isEnabled() && MPMU::apiCheck($gb->getDescription()->getVersion(), "2.3")) { $vars = $gb->api->getVars(); if ($vars instanceof ExpandVars) { return $vars; } } } return new ExpandVars($owner); }
public function execute(CommandSender $sender, $commandLabel, array $args) { if (!$this->owningPlugin->isEnabled()) { return false; } if (!$this->testPermission($sender)) { return false; } $success = $this->executor->onCommand($sender, $this, $commandLabel, $args); if (!$success and $this->usageMessage !== "") { $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage])); } return $success; }
public function execute(CommandSender $sender, $commandLabel, array $args) { if (!$this->owningPlugin->isEnabled()) { return \false; } if (!$this->testPermission($sender)) { return \false; } $success = $this->executor->onCommand($sender, $this, $commandLabel, $args); if (!$success and $this->usageMessage !== "") { $sender->sendMessage(TextFormat::RED . "Usage: " . $this->usageMessage); } return $success; }
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]); }
public function onLogin(PlayerLoginEvent $event) { $player = $event->getPlayer()->getName(); $this->plugin->getServer()->getScheduler()->scheduleDelayedTask(new timeoutKickTask($this->plugin, $this, $event->getPlayer()), 20 * $this->db->config["kick-time"]); if (strtolower($player) == "config") { $event->setKickMessage(TextFormat::RED . $this->db->get("cant-use-this-name")); $event->setCancelled(); } if ($this->isLogin($this->getServer()->getPlayer($player))) { $event->setKickMessage(TextFormat::RED . $this->db->get("already-login")); $event->setCancelled(); return true; } if ($this->db->db["config"]["allowsubaccount"] == false) { $puuid = $event->getPlayer()->getClientId(); foreach ($this->db->db as $playername => $key) { if (!isset($this->db->db[$playername]["uuid"])) { continue; } if ($this->db->db[$playername]["uuid"] == $puuid && strtolower($playername) != strtolower($player)) { $event->setKickMessage(TextFormat::RED . str_replace("%player%", $playername, $this->db->get("already-have-account"))); $event->setCancelled(); break; } } } }
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)); } } }
/** * resources 폴더 안에 있는 파일을 읽어서 문자열로 가져옵니다. * * @param string $filename * @return string */ public function getResourceToReadable($filename) { $string = ""; $resource = $this->plugin->getResource($filename); if ($resource === null) { return null; } while (!feof($resource)) { $string .= fgets($resource, 1024); } fclose($resource); return $string; }
/** * @param RegisteredListener|Listener|Plugin $object */ public function unregister($object) { if ($object instanceof Plugin or $object instanceof Listener) { $changed = false; foreach ($this->handlerSlots as $priority => $list) { foreach ($list as $hash => $listener) { if ($object instanceof Plugin and $listener->getPlugin() === $object or $object instanceof Listener and $listener->getListener() === $object) { unset($this->handlerSlots[$priority][$hash]); $changed = true; } } } if ($changed === true) { $this->handlers = null; } } elseif ($object instanceof RegisteredListener) { if (isset($this->handlerSlots[$object->getPriority()][spl_object_hash($object)])) { unset($this->handlerSlots[$object->getPriority()][spl_object_hash($object)]); $this->handlers = null; } } }
/** * @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 $owner * @param str $callable method from $owner to call * @param array $args arguments to pass to callback method */ public function __construct(Plugin $owner, $callable, array $args = []) { $this->owner = $owner->getName(); $this->callable = $callable; $this->args = $args; }
/** * @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); } }
/** * Register a permission on the fly... * @param Plugin $plugin - owning plugin * @param str $name - permission name * @param str $desc - permission description * @param str $default - one of true,false,op,notop */ public static function add(Plugin $plugin, $name, $desc, $default) { $perm = new Permission($name, $desc, $default); $plugin->getServer()->getPluginManager()->addPermission($perm); }
public static function breakSignLater(Plugin $plugin, Sign $tile, $ticks = 5) { $plugin->getServer()->getScheduler()->scheduleDelayedTask(new PluginCallbackTask($this, [self::class, "breakSign"], [$tile]), $ticks); }
static function TP(Plugin $owner, Player $Target, Position $Position, $delay = 1) { return $owner->getServer()->getScheduler()->scheduleDelayedTask(new TPTask($owner, $Target, $Position), $delay); }
public function registerExtension(Plugin $extension) { array_push($this->extensions, $extension->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; }
public function __construct(Plugin $owner, $Level, $Mode) { $this->Task = new PopupInfoTask($owner, $Level, $this, $Mode); $owner->getServer()->getScheduler()->scheduleRepeatingTask($this->Task, 7); }
/** * @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)); }
public function LoadConfig() { $this->plugin->saveResource("config.yml"); $this->config = (new Config($this->plugin->getDataFolder() . "config.yml", Config::YAML))->getAll(); }
/** * @param Plugin $context */ public function __construct(Plugin $context) { $prefix = $context->getDescription()->getPrefix(); $this->pluginName = $prefix != null ? "[{$prefix}] " : "[" . $context->getDescription()->getName() . "] "; }