Search in sources :

Example 1 with PluginBase

use of org.bukkit.plugin.PluginBase in project DiscordSRV by Scarsz.

the class DiscordSRV method disablePlugin.

public void disablePlugin() {
    Bukkit.getScheduler().runTask(this, () -> Bukkit.getPluginManager().disablePlugin(this));
    PluginCommand pluginCommand = getCommand("discordsrv");
    if (pluginCommand != null && pluginCommand.getPlugin() == this) {
        try {
            Field owningPlugin = pluginCommand.getClass().getDeclaredField("owningPlugin");
            if (!owningPlugin.isAccessible())
                owningPlugin.setAccessible(true);
            // make the command's owning plugin always enabled (give a better error to the user)
            owningPlugin.set(pluginCommand, new PluginBase() {

                @Override
                @NotNull
                public File getDataFolder() {
                    return DiscordSRV.this.getDataFolder();
                }

                @Override
                @NotNull
                public PluginDescriptionFile getDescription() {
                    return DiscordSRV.this.getDescription();
                }

                @Override
                @NotNull
                public FileConfiguration getConfig() {
                    return DiscordSRV.this.getConfig();
                }

                @Override
                @Nullable
                public InputStream getResource(@NotNull String filename) {
                    return DiscordSRV.this.getResource(filename);
                }

                @Override
                public void saveConfig() {
                    DiscordSRV.this.saveConfig();
                }

                @Override
                public void saveDefaultConfig() {
                    DiscordSRV.this.saveDefaultConfig();
                }

                @Override
                public void saveResource(@NotNull String resourcePath, boolean replace) {
                    DiscordSRV.this.saveResource(resourcePath, replace);
                }

                @Override
                public void reloadConfig() {
                    DiscordSRV.this.reloadConfig();
                }

                @Override
                @NotNull
                public PluginLoader getPluginLoader() {
                    return DiscordSRV.this.getPluginLoader();
                }

                @Override
                @NotNull
                public Server getServer() {
                    return DiscordSRV.this.getServer();
                }

                @Override
                public boolean isEnabled() {
                    // otherwise PluginCommand throws a exception
                    return true;
                }

                @Override
                public void onDisable() {
                    DiscordSRV.this.onDisable();
                }

                @Override
                public void onLoad() {
                    DiscordSRV.this.onLoad();
                }

                @Override
                public void onEnable() {
                    DiscordSRV.this.onEnable();
                }

                @Override
                public boolean isNaggable() {
                    return DiscordSRV.this.isNaggable();
                }

                @Override
                public void setNaggable(boolean canNag) {
                    DiscordSRV.this.setNaggable(canNag);
                }

                @Override
                @Nullable
                public ChunkGenerator getDefaultWorldGenerator(@NotNull String worldName, @Nullable String id) {
                    return DiscordSRV.this.getDefaultWorldGenerator(worldName, id);
                }

                @Override
                @NotNull
                public Logger getLogger() {
                    return DiscordSRV.this.getLogger();
                }

                @Override
                public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
                    return DiscordSRV.this.onCommand(sender, command, label, args);
                }

                @Override
                @Nullable
                public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) {
                    return DiscordSRV.this.onTabComplete(sender, command, alias, args);
                }
            });
        } catch (Throwable ignored) {
        }
    }
}
Also used : PluginDescriptionFile(org.bukkit.plugin.PluginDescriptionFile) Logger(java.util.logging.Logger) NotNull(org.jetbrains.annotations.NotNull) FileConfiguration(org.bukkit.configuration.file.FileConfiguration) Field(java.lang.reflect.Field) PluginBase(org.bukkit.plugin.PluginBase) PluginCommand(org.bukkit.command.PluginCommand) Command(org.bukkit.command.Command) CommandSender(org.bukkit.command.CommandSender) HandlerList(org.bukkit.event.HandlerList) ImmutableList(com.google.common.collect.ImmutableList) ChunkGenerator(org.bukkit.generator.ChunkGenerator) PluginDescriptionFile(org.bukkit.plugin.PluginDescriptionFile) PluginLoader(org.bukkit.plugin.PluginLoader) Nullable(org.jetbrains.annotations.Nullable) PluginCommand(org.bukkit.command.PluginCommand)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 Field (java.lang.reflect.Field)1 Logger (java.util.logging.Logger)1 Command (org.bukkit.command.Command)1 CommandSender (org.bukkit.command.CommandSender)1 PluginCommand (org.bukkit.command.PluginCommand)1 FileConfiguration (org.bukkit.configuration.file.FileConfiguration)1 HandlerList (org.bukkit.event.HandlerList)1 ChunkGenerator (org.bukkit.generator.ChunkGenerator)1 PluginBase (org.bukkit.plugin.PluginBase)1 PluginDescriptionFile (org.bukkit.plugin.PluginDescriptionFile)1 PluginLoader (org.bukkit.plugin.PluginLoader)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1