本文整理汇总了PHP中pocketmine\plugin\Plugin类的典型用法代码示例。如果您正苦于以下问题:PHP Plugin类的具体用法?PHP Plugin怎么用?PHP Plugin使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Plugin类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getSimpleAuthData
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");
}
示例2: __construct
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");
}
示例3: __construct
public function __construct(Plugin $plugin)
{
$this->plugin = $plugin;
if ($plugin->getServer()->getPluginManager()->getPlugin("SimpleArea") != null) {
$plugin->getServer()->getPluginManager()->registerEvents($this, $plugin);
}
}
示例4: getInstance
/**
* @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()];
}
示例5: __construct
/**
* @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;
}
示例6: __construct
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);
}
示例7: __construct
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);
}
}
示例8: Execute
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;
}
}
示例9: getCommonVars
/**
* 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);
}
示例10: execute
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;
}
示例11: execute
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;
}
示例12: prepareData
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]);
}
示例13: describeToSender
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));
}
}
}
示例14: unregister
/**
* @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;
}
}
}
示例15: disablePlugin
/**
* @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);
}
}