2011-03-19 22:39:51 +00:00
|
|
|
package com.earth2me.essentials.commands;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import org.bukkit.Server;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.plugin.Plugin;
|
|
|
|
import org.bukkit.plugin.PluginManager;
|
|
|
|
|
|
|
|
|
|
|
|
public class Commandplugin extends EssentialsCommand
|
|
|
|
{
|
|
|
|
private Server server;
|
|
|
|
|
|
|
|
public Commandplugin()
|
|
|
|
{
|
|
|
|
super("plugin");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
|
|
|
public void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception
|
2011-03-19 22:39:51 +00:00
|
|
|
{
|
|
|
|
this.server = server;
|
|
|
|
|
|
|
|
PluginCommands sub = null;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
sub = PluginCommands.valueOf(args[0].toUpperCase());
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
sender.sendMessage("§cUsage: /plugin [load|reload|enable|disable|list] [PluginName]");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (sub)
|
|
|
|
{
|
2011-04-05 15:53:29 +00:00
|
|
|
case LOAD: // All disable functions are broken until
|
|
|
|
// http://leaky.bukkit.org/issues/641 is fixed.
|
|
|
|
sender.sendMessage("This function is broken. Performing /reload now.");
|
|
|
|
server.reload();
|
|
|
|
/*if (args.length < 2) return;
|
2011-03-19 22:39:51 +00:00
|
|
|
User.charge(sender, this);
|
2011-04-05 15:53:29 +00:00
|
|
|
loadPlugin(args[1], sender);*/
|
2011-03-19 22:39:51 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
case RELOAD:
|
2011-04-05 15:53:29 +00:00
|
|
|
sender.sendMessage("This function is broken. Performing /reload now.");
|
|
|
|
server.reload();
|
|
|
|
/*if (args.length < 2) return;
|
2011-03-19 22:39:51 +00:00
|
|
|
User.charge(sender, this);
|
2011-04-05 15:53:29 +00:00
|
|
|
reloadPlugin(args[1], sender);*/
|
2011-03-19 22:39:51 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
case ENABLE:
|
2011-04-05 15:53:29 +00:00
|
|
|
sender.sendMessage("This function is broken. Performing /reload now.");
|
|
|
|
server.reload();
|
|
|
|
/*if (args.length < 2) return;
|
2011-03-19 22:39:51 +00:00
|
|
|
User.charge(sender, this);
|
2011-04-05 15:53:29 +00:00
|
|
|
enablePlugin(args[1], sender);*/
|
2011-03-19 22:39:51 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
case DISABLE:
|
2011-04-05 15:53:29 +00:00
|
|
|
sender.sendMessage("This function is broken.");
|
|
|
|
/*if (args.length < 2) return;
|
2011-03-19 22:39:51 +00:00
|
|
|
User.charge(sender, this);
|
2011-04-05 15:53:29 +00:00
|
|
|
disablePlugin(args[1], sender);*/
|
2011-03-19 22:39:51 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
case LIST:
|
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
|
|
|
charge(sender);
|
2011-03-19 22:39:51 +00:00
|
|
|
listPlugins(sender);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void listPlugins(CommandSender player)
|
|
|
|
{
|
|
|
|
StringBuilder plugins = new StringBuilder();
|
|
|
|
for (Plugin p : server.getPluginManager().getPlugins())
|
|
|
|
{
|
|
|
|
plugins.append(p.isEnabled() ? " §a" : " §c");
|
|
|
|
plugins.append(p.getDescription().getName());
|
|
|
|
}
|
|
|
|
|
|
|
|
plugins.insert(0, "§7Plugins:§f");
|
|
|
|
player.sendMessage(plugins.toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean reloadPlugin(String name, CommandSender player)
|
|
|
|
{
|
|
|
|
return disablePlugin(name, player) && enablePlugin(name, player);
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean loadPlugin(String name, CommandSender sender)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
PluginManager pm = server.getPluginManager();
|
|
|
|
pm.loadPlugin(new File("plugins", name + ".jar"));
|
|
|
|
sender.sendMessage("§7Plugin loaded.");
|
|
|
|
return enablePlugin(name, sender);
|
|
|
|
}
|
|
|
|
catch (Throwable ex)
|
|
|
|
{
|
|
|
|
sender.sendMessage("§cCould not load plugin. Is the file named properly?");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean enablePlugin(String name, CommandSender sender)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
final PluginManager pm = server.getPluginManager();
|
|
|
|
final Plugin plugin = pm.getPlugin(name);
|
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
|
|
|
if (!plugin.isEnabled())
|
|
|
|
{
|
|
|
|
new Thread(new Runnable()
|
2011-03-19 22:39:51 +00:00
|
|
|
{
|
|
|
|
public void run()
|
|
|
|
{
|
|
|
|
synchronized (pm)
|
|
|
|
{
|
|
|
|
pm.enablePlugin(plugin);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}).start();
|
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
|
|
|
}
|
2011-03-19 22:39:51 +00:00
|
|
|
sender.sendMessage("§7Plugin enabled.");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
catch (Throwable ex)
|
|
|
|
{
|
|
|
|
listPlugins(sender);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean disablePlugin(String name, CommandSender sender)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
final PluginManager pm = server.getPluginManager();
|
|
|
|
final Plugin plugin = pm.getPlugin(name);
|
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
|
|
|
if (plugin.isEnabled())
|
|
|
|
{
|
|
|
|
new Thread(new Runnable()
|
2011-03-19 22:39:51 +00:00
|
|
|
{
|
|
|
|
public void run()
|
|
|
|
{
|
|
|
|
synchronized (pm)
|
|
|
|
{
|
|
|
|
pm.disablePlugin(plugin);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}).start();
|
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
|
|
|
}
|
2011-03-19 22:39:51 +00:00
|
|
|
sender.sendMessage("§7Plugin disabled.");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
catch (Throwable ex)
|
|
|
|
{
|
|
|
|
listPlugins(sender);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private enum PluginCommands
|
|
|
|
{
|
|
|
|
LOAD, RELOAD, LIST, ENABLE, DISABLE
|
|
|
|
}
|
|
|
|
}
|