/** * @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 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; }
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 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; } } }
/** * //TODO: tick scheduled attachments * * @param Plugin $plugin * @param string $name * @param bool $value * * @return PermissionAttachment * * @throws PluginException */ public function addAttachment(Plugin $plugin, $name = null, $value = null) { if ($plugin === null) { throw new PluginException("Plugin cannot be null"); } elseif (!$plugin->isEnabled()) { throw new PluginException("Plugin " . $plugin->getDescription()->getName() . " is disabled"); } $result = new PermissionAttachment($plugin, $this->parent !== null ? $this->parent : $this); $this->attachments[spl_object_hash($result)] = $result; if ($name !== null and $value !== null) { $result->setPermission($name, $value); } $this->recalculatePermissions(); return $result; }
/** * @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)) { throw new PluginException($event . " is not an Event"); } $class = new \ReflectionClass($event); if ($class->isAbstract()) { throw new PluginException($event . " is an abstract Event"); } if ($class->getProperty("handlerList")->getDeclaringClass()->getName() !== $event) { throw new PluginException($event . " does not have a handler list"); } 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 $plugin */ public function disablePlugin(Plugin $plugin) { if ($plugin instanceof PluginBase and $plugin->isEnabled()) { $this->server->getLogger()->info($this->server->getLanguage()->translateString("BukkitPE.plugin.disable", [$plugin->getDescription()->getFullName()])); $this->server->getPluginManager()->callEvent(new PluginDisableEvent($plugin)); $plugin->setEnabled(false); } }
/** * @param Plugin $context */ public function __construct(Plugin $context) { $prefix = $context->getDescription()->getPrefix(); $this->pluginName = $prefix != null ? "[{$prefix}] " : "[" . $context->getDescription()->getName() . "] "; }