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; }
/** * @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; }
/** * //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); } }