TFM-4.3-Reloaded/src/me/StevenLawson/TotalFreedomMod/Commands/Command_plugincontrol.java

130 lines
4.1 KiB
Java
Raw Normal View History

2013-03-24 19:55:34 +00:00
package me.StevenLawson.TotalFreedomMod.Commands;
2013-12-01 11:13:39 +00:00
import net.minecraft.util.org.apache.commons.lang3.StringUtils;
2013-03-24 19:55:34 +00:00
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
@CommandPermissions(level = AdminLevel.SENIOR, source = SourceType.BOTH)
@CommandParameters(description = "Enable / disable plugins.", usage = "/<command> < <enable | disable> <pluginname> | list >", aliases = "plc")
2013-03-24 19:55:34 +00:00
public class Command_plugincontrol extends TFM_Command
{
private enum CommandMode
{
ENABLE, DISABLE, LIST, RELOAD
}
@Override
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
CommandMode commandMode = null;
if (args.length == 1)
{
if (args[0].equalsIgnoreCase("list"))
{
commandMode = CommandMode.LIST;
}
else if (args[0].equalsIgnoreCase("reload"))
{
commandMode = CommandMode.RELOAD;
}
}
else if (args.length >= 2)
{
if (args[0].equalsIgnoreCase("enable"))
{
commandMode = CommandMode.ENABLE;
}
else if (args[0].equalsIgnoreCase("disable"))
{
commandMode = CommandMode.DISABLE;
}
}
if (commandMode == null)
{
return false;
}
PluginManager pluginManager = plugin.getServer().getPluginManager();
if (commandMode == CommandMode.LIST)
{
playerMsg("Plugins: " + StringUtils.join(pluginManager.getPlugins(), ", "));
}
else if (commandMode == CommandMode.RELOAD)
{
playerMsg("Disabling all plugins.");
2013-08-14 14:55:37 +00:00
for (Plugin targetPlugin : pluginManager.getPlugins())
2013-03-24 19:55:34 +00:00
{
2013-08-14 14:55:37 +00:00
if (!targetPlugin.getName().toLowerCase().startsWith("totalfreedommod"))
2013-03-24 19:55:34 +00:00
{
2013-08-14 14:55:37 +00:00
pluginManager.disablePlugin(targetPlugin);
2013-03-24 19:55:34 +00:00
}
}
playerMsg("Enabling all plugins.");
2013-08-14 14:55:37 +00:00
for (Plugin targetPlugin : pluginManager.getPlugins())
2013-03-24 19:55:34 +00:00
{
2013-08-14 14:55:37 +00:00
if (!targetPlugin.getName().toLowerCase().startsWith("totalfreedommod"))
2013-03-24 19:55:34 +00:00
{
2013-08-14 14:55:37 +00:00
pluginManager.enablePlugin(targetPlugin);
2013-03-24 19:55:34 +00:00
}
}
}
else
{
final String searchPluginName = args[1].toLowerCase().trim();
Plugin targetPlugin = null;
2013-08-14 14:55:37 +00:00
for (Plugin serverPlugin : pluginManager.getPlugins())
2013-03-24 19:55:34 +00:00
{
2013-08-14 14:55:37 +00:00
if (searchPluginName.equalsIgnoreCase(serverPlugin.getName().toLowerCase().trim()))
2013-03-24 19:55:34 +00:00
{
2013-08-14 14:55:37 +00:00
targetPlugin = serverPlugin;
2013-03-24 19:55:34 +00:00
break;
}
}
if (targetPlugin == null)
{
playerMsg("Plugin \"" + searchPluginName + "\" is not installed.");
return true;
}
else
{
if (commandMode == CommandMode.ENABLE)
{
pluginManager.enablePlugin(targetPlugin);
if (targetPlugin.isEnabled())
{
playerMsg("Plugin \"" + targetPlugin.getName() + "\" enabled.");
}
else
{
playerMsg("Error enabling plugin \"" + targetPlugin.getName() + "\".");
}
}
else
{
pluginManager.disablePlugin(targetPlugin);
if (!targetPlugin.isEnabled())
{
playerMsg("Plugin \"" + targetPlugin.getName() + "\" disabled.");
}
else
{
playerMsg("Error disabling plugin \"" + targetPlugin.getName() + "\".");
}
}
}
}
return true;
}
}