Add more messages for (un/re)load actions
This commit is contained in:
parent
58a8e9304c
commit
9e8ac2d4fe
5 changed files with 61 additions and 49 deletions
|
|
@ -4,7 +4,7 @@ import co.aikar.commands.BaseCommand;
|
||||||
import co.aikar.commands.annotation.*;
|
import co.aikar.commands.annotation.*;
|
||||||
import net.frankheijden.serverutils.ServerUtils;
|
import net.frankheijden.serverutils.ServerUtils;
|
||||||
import net.frankheijden.serverutils.config.Messenger;
|
import net.frankheijden.serverutils.config.Messenger;
|
||||||
import net.frankheijden.serverutils.managers.PluginManager;
|
import net.frankheijden.serverutils.managers.*;
|
||||||
import net.frankheijden.serverutils.reflection.*;
|
import net.frankheijden.serverutils.reflection.*;
|
||||||
import net.frankheijden.serverutils.utils.*;
|
import net.frankheijden.serverutils.utils.*;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
|
@ -108,13 +108,13 @@ public class CommandServerUtils extends BaseCommand {
|
||||||
@CommandPermission("serverutils.loadplugin")
|
@CommandPermission("serverutils.loadplugin")
|
||||||
@Description("Loads the specified jar file as a plugin.")
|
@Description("Loads the specified jar file as a plugin.")
|
||||||
public void onLoadPlugin(CommandSender sender, String jarFile) {
|
public void onLoadPlugin(CommandSender sender, String jarFile) {
|
||||||
PluginManager.LoadResult loadResult = PluginManager.loadPlugin(jarFile);
|
LoadResult loadResult = PluginManager.loadPlugin(jarFile);
|
||||||
if (!loadResult.isSuccess()) {
|
if (!loadResult.isSuccess()) {
|
||||||
loadResult.getResult().sendTo(sender, "load", jarFile);
|
loadResult.getResult().sendTo(sender, "load", jarFile);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PluginManager.Result result = PluginManager.enablePlugin(loadResult.getPlugin());
|
Result result = PluginManager.enablePlugin(loadResult.getPlugin());
|
||||||
result.sendTo(sender, "load", jarFile);
|
result.sendTo(sender, "load", jarFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -123,7 +123,7 @@ public class CommandServerUtils extends BaseCommand {
|
||||||
@CommandPermission("serverutils.unloadplugin")
|
@CommandPermission("serverutils.unloadplugin")
|
||||||
@Description("Unloads the specified plugin.")
|
@Description("Unloads the specified plugin.")
|
||||||
public void onUnloadPlugin(CommandSender sender, String pluginName) {
|
public void onUnloadPlugin(CommandSender sender, String pluginName) {
|
||||||
PluginManager.Result result = PluginManager.disablePlugin(pluginName);
|
Result result = PluginManager.disablePlugin(pluginName);
|
||||||
result.sendTo(sender, "unload", pluginName);
|
result.sendTo(sender, "unload", pluginName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -132,7 +132,7 @@ public class CommandServerUtils extends BaseCommand {
|
||||||
@CommandPermission("serverutils.reloadplugin")
|
@CommandPermission("serverutils.reloadplugin")
|
||||||
@Description("Reloads a specified plugin.")
|
@Description("Reloads a specified plugin.")
|
||||||
public void onReloadPlugin(CommandSender sender, String pluginName) {
|
public void onReloadPlugin(CommandSender sender, String pluginName) {
|
||||||
PluginManager.Result result = PluginManager.reloadPlugin(pluginName);
|
Result result = PluginManager.reloadPlugin(pluginName);
|
||||||
result.sendTo(sender, "reload", pluginName);
|
result.sendTo(sender, "reload", pluginName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -143,7 +143,7 @@ public class CommandServerUtils extends BaseCommand {
|
||||||
public void onPluginInfo(CommandSender sender, String pluginName) {
|
public void onPluginInfo(CommandSender sender, String pluginName) {
|
||||||
Plugin plugin = Bukkit.getPluginManager().getPlugin(pluginName);
|
Plugin plugin = Bukkit.getPluginManager().getPlugin(pluginName);
|
||||||
if (plugin == null) {
|
if (plugin == null) {
|
||||||
PluginManager.Result.NOT_EXISTS.sendTo(sender, "fetch", pluginName);
|
Result.NOT_EXISTS.sendTo(sender, "fetch", pluginName);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,9 @@ public class Messenger {
|
||||||
"warning", "&3Successfully %action%ed &b%what%&3, but with warnings.",
|
"warning", "&3Successfully %action%ed &b%what%&3, but with warnings.",
|
||||||
"error", "&cAn error occurred while %action%ing &4%what%&c, please check the console!",
|
"error", "&cAn error occurred while %action%ing &4%what%&c, please check the console!",
|
||||||
"not_exists", "&cAn error occurred while %action%ing &4%what%&c, plugin does not exist!",
|
"not_exists", "&cAn error occurred while %action%ing &4%what%&c, plugin does not exist!",
|
||||||
|
"not_enabled", "&cAn error occurred while %action%ing &4%what%&c, plugin is not enabled!",
|
||||||
"already_enabled", "&cAn error occurred while %action%ing &4%what%&c, plugin is already enabled!",
|
"already_enabled", "&cAn error occurred while %action%ing &4%what%&c, plugin is already enabled!",
|
||||||
|
"file_changed", "&cAccessing the jar file while %action%ing &4%what%&c went wrong, please load the plugin manually!",
|
||||||
"help", Defaults.of(
|
"help", Defaults.of(
|
||||||
"header", "&8&m-------------=&r&8[ &b&lServerUtils Help&r &8]&m=---------------",
|
"header", "&8&m-------------=&r&8[ &b&lServerUtils Help&r &8]&m=---------------",
|
||||||
"format", "&8/&3%command%&b%subcommand% &f(&7%help%&f)",
|
"format", "&8/&3%command%&b%subcommand% &f(&7%help%&f)",
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
package net.frankheijden.serverutils.managers;
|
||||||
|
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
public class LoadResult {
|
||||||
|
private final Plugin plugin;
|
||||||
|
private final Result result;
|
||||||
|
|
||||||
|
public LoadResult(Plugin plugin, Result result) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.result = result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LoadResult(Result result) {
|
||||||
|
this(null, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Result getResult() {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Plugin getPlugin() {
|
||||||
|
return plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSuccess() {
|
||||||
|
return plugin != null && result == Result.SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,11 +1,9 @@
|
||||||
package net.frankheijden.serverutils.managers;
|
package net.frankheijden.serverutils.managers;
|
||||||
|
|
||||||
import net.frankheijden.serverutils.ServerUtils;
|
import net.frankheijden.serverutils.ServerUtils;
|
||||||
import net.frankheijden.serverutils.config.Messenger;
|
|
||||||
import net.frankheijden.serverutils.reflection.*;
|
import net.frankheijden.serverutils.reflection.*;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.plugin.InvalidPluginException;
|
import org.bukkit.plugin.InvalidPluginException;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
|
@ -42,7 +40,7 @@ public class PluginManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Result disablePlugin(Plugin plugin) {
|
public static Result disablePlugin(Plugin plugin) {
|
||||||
if (plugin == null) return Result.NOT_EXISTS;
|
if (plugin == null) return Result.NOT_ENABLED;
|
||||||
try {
|
try {
|
||||||
Bukkit.getPluginManager().disablePlugin(plugin);
|
Bukkit.getPluginManager().disablePlugin(plugin);
|
||||||
RSimplePluginManager.getPlugins(Bukkit.getPluginManager()).remove(plugin);
|
RSimplePluginManager.getPlugins(Bukkit.getPluginManager()).remove(plugin);
|
||||||
|
|
@ -85,7 +83,10 @@ public class PluginManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
LoadResult loadResult = loadPlugin(pluginFile);
|
LoadResult loadResult = loadPlugin(pluginFile);
|
||||||
if (!loadResult.isSuccess()) return loadResult.getResult();
|
if (!loadResult.isSuccess()) {
|
||||||
|
Result r = loadResult.getResult();
|
||||||
|
return (r == Result.NOT_EXISTS) ? Result.FILE_CHANGED : r;
|
||||||
|
}
|
||||||
return enablePlugin(loadResult.getPlugin());
|
return enablePlugin(loadResult.getPlugin());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -108,43 +109,4 @@ public class PluginManager {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class LoadResult {
|
|
||||||
private final Plugin plugin;
|
|
||||||
private final Result result;
|
|
||||||
|
|
||||||
public LoadResult(Plugin plugin, Result result) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
this.result = result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LoadResult(Result result) {
|
|
||||||
this(null, result);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Result getResult() {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Plugin getPlugin() {
|
|
||||||
return plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isSuccess() {
|
|
||||||
return plugin != null && result == Result.SUCCESS;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum Result {
|
|
||||||
NOT_EXISTS,
|
|
||||||
ALREADY_ENABLED,
|
|
||||||
ERROR,
|
|
||||||
SUCCESS;
|
|
||||||
|
|
||||||
public void sendTo(CommandSender sender, String action, String what) {
|
|
||||||
Messenger.sendMessage(sender, "serverutils." + this.name().toLowerCase(),
|
|
||||||
"%action%", action,
|
|
||||||
"%what%", what);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
package net.frankheijden.serverutils.managers;
|
||||||
|
|
||||||
|
import net.frankheijden.serverutils.config.Messenger;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
public enum Result {
|
||||||
|
NOT_EXISTS,
|
||||||
|
NOT_ENABLED,
|
||||||
|
ALREADY_ENABLED,
|
||||||
|
FILE_CHANGED,
|
||||||
|
ERROR,
|
||||||
|
SUCCESS;
|
||||||
|
|
||||||
|
public void sendTo(CommandSender sender, String action, String what) {
|
||||||
|
Messenger.sendMessage(sender, "serverutils." + this.name().toLowerCase(),
|
||||||
|
"%action%", action,
|
||||||
|
"%what%", what);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue