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) {
}
}
}
Aggregations