mirror of
https://github.com/essentials/Essentials.git
synced 2025-10-01 00:26:48 +02:00
More work done.
This commit is contained in:
@@ -1,138 +0,0 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import com.earth2me.essentials.api.IAlternativeCommandsHandler;
|
||||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.command.PluginCommandYamlParser;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
|
||||
public class AlternativeCommandsHandler implements IAlternativeCommandsHandler
|
||||
{
|
||||
private static final Logger LOGGER = Logger.getLogger("Minecraft");
|
||||
private final transient Map<String, List<PluginCommand>> altcommands = new HashMap<String, List<PluginCommand>>();
|
||||
private final transient Map<String, String> disabledList = new HashMap<String, String>();
|
||||
private final transient IEssentials ess;
|
||||
|
||||
public AlternativeCommandsHandler(final IEssentials ess)
|
||||
{
|
||||
this.ess = ess;
|
||||
for (Plugin plugin : ess.getServer().getPluginManager().getPlugins())
|
||||
{
|
||||
if (plugin.isEnabled())
|
||||
{
|
||||
addPlugin(plugin);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public final void addPlugin(final Plugin plugin)
|
||||
{
|
||||
if (plugin.getDescription().getMain().contains("com.earth2me.essentials"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
final List<Command> commands = PluginCommandYamlParser.parse(plugin);
|
||||
final String pluginName = plugin.getDescription().getName().toLowerCase(Locale.ENGLISH);
|
||||
|
||||
for (Command command : commands)
|
||||
{
|
||||
final PluginCommand pc = (PluginCommand)command;
|
||||
final List<String> labels = new ArrayList<String>(pc.getAliases());
|
||||
labels.add(pc.getName());
|
||||
|
||||
PluginCommand reg = ess.getServer().getPluginCommand(pluginName + ":" + pc.getName().toLowerCase(Locale.ENGLISH));
|
||||
if (reg == null)
|
||||
{
|
||||
reg = ess.getServer().getPluginCommand(pc.getName().toLowerCase(Locale.ENGLISH));
|
||||
}
|
||||
if (reg == null || !reg.getPlugin().equals(plugin))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
for (String label : labels)
|
||||
{
|
||||
List<PluginCommand> plugincommands = altcommands.get(label.toLowerCase(Locale.ENGLISH));
|
||||
if (plugincommands == null)
|
||||
{
|
||||
plugincommands = new ArrayList<PluginCommand>();
|
||||
altcommands.put(label.toLowerCase(Locale.ENGLISH), plugincommands);
|
||||
}
|
||||
boolean found = false;
|
||||
for (PluginCommand pc2 : plugincommands)
|
||||
{
|
||||
if (pc2.getPlugin().equals(plugin))
|
||||
{
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
{
|
||||
plugincommands.add(reg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void removePlugin(final Plugin plugin)
|
||||
{
|
||||
final Iterator<Map.Entry<String, List<PluginCommand>>> iterator = altcommands.entrySet().iterator();
|
||||
while (iterator.hasNext())
|
||||
{
|
||||
final Map.Entry<String, List<PluginCommand>> entry = iterator.next();
|
||||
final Iterator<PluginCommand> pcIterator = entry.getValue().iterator();
|
||||
while (pcIterator.hasNext())
|
||||
{
|
||||
final PluginCommand pc = pcIterator.next();
|
||||
if (pc.getPlugin() == null || pc.getPlugin().equals(plugin))
|
||||
{
|
||||
pcIterator.remove();
|
||||
}
|
||||
}
|
||||
if (entry.getValue().isEmpty())
|
||||
{
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public PluginCommand getAlternative(final String label)
|
||||
{
|
||||
final List<PluginCommand> commands = altcommands.get(label);
|
||||
if (commands == null || commands.isEmpty())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (commands.size() == 1)
|
||||
{
|
||||
return commands.get(0);
|
||||
}
|
||||
// return the first command that is not an alias
|
||||
for (PluginCommand command : commands)
|
||||
{
|
||||
if (command.getName().equalsIgnoreCase(label))
|
||||
{
|
||||
return command;
|
||||
}
|
||||
}
|
||||
// return the first alias
|
||||
return commands.get(0);
|
||||
}
|
||||
|
||||
public void executed(final String label, final String otherLabel)
|
||||
{
|
||||
if (ess.getSettings().isDebug())
|
||||
{
|
||||
LOGGER.log(Level.INFO, "Essentials: Alternative command " + label + " found, using " + otherLabel);
|
||||
}
|
||||
disabledList.put(label, otherLabel);
|
||||
}
|
||||
|
||||
public Map<String, String> disabledCommands()
|
||||
{
|
||||
return disabledList;
|
||||
}
|
||||
}
|
@@ -19,14 +19,14 @@ package com.earth2me.essentials;
|
||||
|
||||
import static com.earth2me.essentials.I18n._;
|
||||
import com.earth2me.essentials.api.*;
|
||||
import com.earth2me.essentials.commands.EssentialsCommand;
|
||||
import com.earth2me.essentials.commands.IEssentialsCommand;
|
||||
import com.earth2me.essentials.commands.NoChargeException;
|
||||
import com.earth2me.essentials.commands.NotEnoughArgumentsException;
|
||||
import com.earth2me.essentials.api.IUser;
|
||||
import com.earth2me.essentials.api.ISettings;
|
||||
import com.earth2me.essentials.user.UserMap;
|
||||
import com.earth2me.essentials.craftbukkit.ItemDupeFix;
|
||||
import com.earth2me.essentials.listener.*;
|
||||
import com.earth2me.essentials.perm.PermissionsHandler;
|
||||
import com.earth2me.essentials.register.payment.Methods;
|
||||
import com.earth2me.essentials.settings.SettingsHolder;
|
||||
import com.earth2me.essentials.signs.SignBlockListener;
|
||||
import com.earth2me.essentials.signs.SignEntityListener;
|
||||
import com.earth2me.essentials.signs.SignPlayerListener;
|
||||
@@ -43,7 +43,6 @@ import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event.Priority;
|
||||
import org.bukkit.event.Event.Type;
|
||||
@@ -54,7 +53,6 @@ import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.yaml.snakeyaml.error.YAMLException;
|
||||
|
||||
|
||||
@@ -64,18 +62,18 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||
private static final Logger LOGGER = Logger.getLogger("Minecraft");
|
||||
private transient ISettings settings;
|
||||
private final transient TNTExplodeListener tntListener = new TNTExplodeListener(this);
|
||||
private transient Jails jails;
|
||||
private transient Warps warps;
|
||||
private transient Worth worth;
|
||||
private transient List<IConf> confList;
|
||||
private transient Backup backup;
|
||||
private transient ItemDb itemDb;
|
||||
private transient IJails jails;
|
||||
private transient IWarps warps;
|
||||
private transient IWorth worth;
|
||||
private transient List<IReload> reloadList;
|
||||
private transient IBackup backup;
|
||||
private transient IItemDb itemDb;
|
||||
private transient final Methods paymentMethod = new Methods();
|
||||
private transient PermissionsHandler permissionsHandler;
|
||||
private transient AlternativeCommandsHandler alternativeCommandsHandler;
|
||||
private transient UserMap userMap;
|
||||
private transient IUserMap userMap;
|
||||
private transient ExecuteTimer execTimer;
|
||||
private transient I18n i18n;
|
||||
private transient ICommandHandler commandHandler;
|
||||
|
||||
@Override
|
||||
public ISettings getSettings()
|
||||
@@ -147,24 +145,26 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||
final EssentialsUpgrade upgrade = new EssentialsUpgrade(this);
|
||||
upgrade.beforeSettings();
|
||||
execTimer.mark("Upgrade");
|
||||
confList = new ArrayList<IConf>();
|
||||
settings = new Settings(this);
|
||||
confList.add(settings);
|
||||
reloadList = new ArrayList<IReload>();
|
||||
settings = new SettingsHolder(this);
|
||||
reloadList.add(settings);
|
||||
execTimer.mark("Settings");
|
||||
upgrade.afterSettings();
|
||||
execTimer.mark("Upgrade2");
|
||||
i18n.updateLocale(settings.getLocale());
|
||||
userMap = new UserMap(this);
|
||||
confList.add(userMap);
|
||||
reloadList.add(userMap);
|
||||
execTimer.mark("Init(Usermap)");
|
||||
warps = new Warps(getServer(), this.getDataFolder());
|
||||
confList.add(warps);
|
||||
reloadList.add(warps);
|
||||
execTimer.mark("Init(Spawn/Warp)");
|
||||
worth = new Worth(this.getDataFolder());
|
||||
confList.add(worth);
|
||||
reloadList.add(worth);
|
||||
itemDb = new ItemDb(this);
|
||||
confList.add(itemDb);
|
||||
reloadList.add(itemDb);
|
||||
execTimer.mark("Init(Worth/ItemDB)");
|
||||
commandHandler = new EssentialsCommandHandler(Essentials.class.getClassLoader(), "com.earth2me.essentials.commands.Command", "essentials.", this);
|
||||
reloadList.add(commandHandler);
|
||||
reload();
|
||||
}
|
||||
catch (YAMLException exception)
|
||||
@@ -194,12 +194,11 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||
return;
|
||||
}
|
||||
backup = new Backup(this);
|
||||
permissionsHandler = new PermissionsHandler(this, settings.useBukkitPermissions());
|
||||
alternativeCommandsHandler = new AlternativeCommandsHandler(this);
|
||||
permissionsHandler = new PermissionsHandler(this);
|
||||
final EssentialsPluginListener serverListener = new EssentialsPluginListener(this);
|
||||
pm.registerEvent(Type.PLUGIN_ENABLE, serverListener, Priority.Low, this);
|
||||
pm.registerEvent(Type.PLUGIN_DISABLE, serverListener, Priority.Low, this);
|
||||
confList.add(serverListener);
|
||||
reloadList.add(serverListener);
|
||||
|
||||
final EssentialsPlayerListener playerListener = new EssentialsPlayerListener(this);
|
||||
pm.registerEvent(Type.PLAYER_JOIN, playerListener, Priority.Monitor, this);
|
||||
@@ -245,12 +244,12 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||
|
||||
//TODO: Check if this should be here, and not above before reload()
|
||||
jails = new Jails(this);
|
||||
confList.add(jails);
|
||||
reloadList.add(jails);
|
||||
|
||||
pm.registerEvent(Type.ENTITY_EXPLODE, tntListener, Priority.High, this);
|
||||
|
||||
final EssentialsTimer timer = new EssentialsTimer(this);
|
||||
getScheduler().scheduleSyncRepeatingTask(this, timer, 1, 100);
|
||||
getServer().getScheduler().scheduleSyncRepeatingTask(this, timer, 1, 100);
|
||||
Economy.setEss(this);
|
||||
execTimer.mark("RegListeners");
|
||||
LOGGER.info(_("loadinfo", this.getDescription().getName(), this.getDescription().getVersion(), Util.joinList(this.getDescription().getAuthors())));
|
||||
@@ -274,10 +273,10 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||
{
|
||||
Trade.closeLog();
|
||||
|
||||
for (IConf iConf : confList)
|
||||
for (IReload iReload : reloadList)
|
||||
{
|
||||
iConf.reloadConfig();
|
||||
execTimer.mark("Reload(" + iConf.getClass().getSimpleName() + ")");
|
||||
iReload.onReload();
|
||||
execTimer.mark("Reload(" + iReload.getClass().getSimpleName() + ")");
|
||||
}
|
||||
|
||||
i18n.updateLocale(settings.getLocale());
|
||||
@@ -286,132 +285,8 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||
@Override
|
||||
public boolean onCommand(final CommandSender sender, final Command command, final String commandLabel, final String[] args)
|
||||
{
|
||||
return onCommandEssentials(sender, command, commandLabel, args, Essentials.class.getClassLoader(), "com.earth2me.essentials.commands.Command", "essentials.", null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommandEssentials(final CommandSender sender, final Command command, final String commandLabel, final String[] args, final ClassLoader classLoader, final String commandPath, final String permissionPrefix, final IEssentialsModule module)
|
||||
{
|
||||
// Allow plugins to override the command via onCommand
|
||||
if (!getSettings().isCommandOverridden(command.getName()) && !commandLabel.startsWith("e"))
|
||||
{
|
||||
final PluginCommand pc = alternativeCommandsHandler.getAlternative(commandLabel);
|
||||
if (pc != null)
|
||||
{
|
||||
alternativeCommandsHandler.executed(commandLabel, pc.getLabel());
|
||||
return pc.execute(sender, commandLabel, args);
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
User user = null;
|
||||
if (sender instanceof Player)
|
||||
{
|
||||
user = getUser(sender);
|
||||
LOGGER.log(Level.INFO, String.format("[PLAYER_COMMAND] %s: /%s %s ", ((Player)sender).getName(), commandLabel, EssentialsCommand.getFinalArg(args, 0)));
|
||||
}
|
||||
|
||||
// New mail notification
|
||||
if (user != null && !getSettings().isCommandDisabled("mail") && !commandLabel.equals("mail") && user.isAuthorized("essentials.mail"))
|
||||
{
|
||||
final List<String> mail = user.getMails();
|
||||
if (mail != null && !mail.isEmpty())
|
||||
{
|
||||
user.sendMessage(_("youHaveNewMail", mail.size()));
|
||||
}
|
||||
}
|
||||
|
||||
// Check for disabled commands
|
||||
if (getSettings().isCommandDisabled(commandLabel))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
IEssentialsCommand cmd;
|
||||
try
|
||||
{
|
||||
cmd = (IEssentialsCommand)classLoader.loadClass(commandPath + command.getName()).newInstance();
|
||||
cmd.setEssentials(this);
|
||||
cmd.setEssentialsModule(module);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
sender.sendMessage(_("commandNotLoaded", commandLabel));
|
||||
LOGGER.log(Level.SEVERE, _("commandNotLoaded", commandLabel), ex);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check authorization
|
||||
if (user != null && !user.isAuthorized(cmd, permissionPrefix))
|
||||
{
|
||||
LOGGER.log(Level.WARNING, _("deniedAccessCommand", user.getName()));
|
||||
user.sendMessage(_("noAccessCommand"));
|
||||
return true;
|
||||
}
|
||||
|
||||
// Run the command
|
||||
try
|
||||
{
|
||||
if (user == null)
|
||||
{
|
||||
cmd.run(getServer(), sender, commandLabel, command, args);
|
||||
}
|
||||
else
|
||||
{
|
||||
user.acquireReadLock();
|
||||
try
|
||||
{
|
||||
cmd.run(getServer(), user, commandLabel, command, args);
|
||||
}
|
||||
finally
|
||||
{
|
||||
user.unlock();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch (NoChargeException ex)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
catch (NotEnoughArgumentsException ex)
|
||||
{
|
||||
sender.sendMessage(command.getDescription());
|
||||
sender.sendMessage(command.getUsage().replaceAll("<command>", commandLabel));
|
||||
if (!ex.getMessage().isEmpty())
|
||||
{
|
||||
sender.sendMessage(ex.getMessage());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch (Throwable ex)
|
||||
{
|
||||
showError(sender, ex, commandLabel);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (Throwable ex)
|
||||
{
|
||||
LOGGER.log(Level.SEVERE, _("commandFailed", commandLabel), ex);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showError(final CommandSender sender, final Throwable exception, final String commandLabel)
|
||||
{
|
||||
sender.sendMessage(_("errorWithMessage", exception.getMessage()));
|
||||
if (getSettings().isDebug())
|
||||
{
|
||||
LOGGER.log(Level.WARNING, _("errorCallingCommand", commandLabel), exception);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BukkitScheduler getScheduler()
|
||||
{
|
||||
return this.getServer().getScheduler();
|
||||
return commandHandler.handleCommand(sender, command, commandLabel, args);
|
||||
//return onCommandEssentials(sender, command, commandLabel, args, Essentials.class.getClassLoader(), "com.earth2me.essentials.commands.Command", "essentials.", null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -421,65 +296,31 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||
}
|
||||
|
||||
@Override
|
||||
public Warps getWarps()
|
||||
public IWarps getWarps()
|
||||
{
|
||||
return warps;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Worth getWorth()
|
||||
public IWorth getWorth()
|
||||
{
|
||||
return worth;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Backup getBackup()
|
||||
public IBackup getBackup()
|
||||
{
|
||||
return backup;
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getUser(final Object base)
|
||||
public IUser getUser(final Player player)
|
||||
{
|
||||
if (base instanceof Player)
|
||||
{
|
||||
return getUser((Player)base);
|
||||
}
|
||||
if (base instanceof String)
|
||||
{
|
||||
return userMap.getUser((String)base);
|
||||
}
|
||||
return null;
|
||||
return userMap.getUser(player);
|
||||
}
|
||||
|
||||
private <T extends Player> User getUser(final T base)
|
||||
public IUser getUser(final String playerName)
|
||||
{
|
||||
if (base == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (base instanceof User)
|
||||
{
|
||||
return (User)base;
|
||||
}
|
||||
User user = userMap.getUser(base.getName());
|
||||
|
||||
if (user == null)
|
||||
{
|
||||
user = new User(base, this);
|
||||
}
|
||||
else
|
||||
{
|
||||
user.update(base);
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getOfflineUser(final String name)
|
||||
{
|
||||
return userMap.getUser(name);
|
||||
return userMap.getUser(playerName);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -497,9 +338,9 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addReloadListener(final IConf listener)
|
||||
public void addReloadListener(final IReload listener)
|
||||
{
|
||||
confList.add(listener);
|
||||
reloadList.add(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -523,8 +364,8 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||
|
||||
for (Player player : players)
|
||||
{
|
||||
final User user = getUser(player);
|
||||
if (!user.isIgnoredPlayer(sender.getName()))
|
||||
final IUser user = getUser(player);
|
||||
if (!user.isIgnoringPlayer(sender.getName()))
|
||||
{
|
||||
player.sendMessage(message);
|
||||
}
|
||||
@@ -536,25 +377,25 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||
@Override
|
||||
public int scheduleAsyncDelayedTask(final Runnable run)
|
||||
{
|
||||
return this.getScheduler().scheduleAsyncDelayedTask(this, run);
|
||||
return this.getServer().getScheduler().scheduleAsyncDelayedTask(this, run);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int scheduleSyncDelayedTask(final Runnable run)
|
||||
{
|
||||
return this.getScheduler().scheduleSyncDelayedTask(this, run);
|
||||
return this.getServer().getScheduler().scheduleSyncDelayedTask(this, run);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int scheduleSyncDelayedTask(final Runnable run, final long delay)
|
||||
{
|
||||
return this.getScheduler().scheduleSyncDelayedTask(this, run, delay);
|
||||
return this.getServer().getScheduler().scheduleSyncDelayedTask(this, run, delay);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int scheduleSyncRepeatingTask(final Runnable run, final long delay, final long period)
|
||||
{
|
||||
return this.getScheduler().scheduleSyncRepeatingTask(this, run, delay, period);
|
||||
return this.getServer().getScheduler().scheduleSyncRepeatingTask(this, run, delay, period);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -570,19 +411,13 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||
}
|
||||
|
||||
@Override
|
||||
public AlternativeCommandsHandler getAlternativeCommandsHandler()
|
||||
{
|
||||
return alternativeCommandsHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemDb getItemDb()
|
||||
public IItemDb getItemDb()
|
||||
{
|
||||
return itemDb;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserMap getUserMap()
|
||||
public IUserMap getUserMap()
|
||||
{
|
||||
return userMap;
|
||||
}
|
||||
@@ -593,30 +428,12 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||
return i18n;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addReloadListener(IReload listener)
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int broadcastMessage(com.earth2me.essentials.api.IUser sender, String message)
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGroups getGroups()
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IWarps getWarps2()
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEssentialsEconomy getEconomy()
|
||||
{
|
||||
@@ -624,14 +441,8 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showCommandError(CommandSender sender, String commandLabel, Throwable exception)
|
||||
public ICommandHandler getCommandHandler()
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReload()
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
return commandHandler;
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,292 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import com.earth2me.essentials.api.ICommandHandler;
|
||||
import static com.earth2me.essentials.I18n._;
|
||||
import com.earth2me.essentials.api.IEssentials;
|
||||
import com.earth2me.essentials.api.IEssentialsModule;
|
||||
import com.earth2me.essentials.api.IUser;
|
||||
import com.earth2me.essentials.commands.EssentialsCommand;
|
||||
import com.earth2me.essentials.commands.IEssentialsCommand;
|
||||
import com.earth2me.essentials.commands.NoChargeException;
|
||||
import com.earth2me.essentials.commands.NotEnoughArgumentsException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.command.PluginCommandYamlParser;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
|
||||
public class EssentialsCommandHandler implements ICommandHandler
|
||||
{
|
||||
private final transient ClassLoader classLoader;
|
||||
private final transient String commandPath;
|
||||
private final transient String permissionPrefix;
|
||||
private final transient IEssentialsModule module;
|
||||
private static final transient Logger LOGGER = Bukkit.getLogger();
|
||||
private final transient Map<String, List<PluginCommand>> altcommands = new HashMap<String, List<PluginCommand>>();
|
||||
private final transient Map<String, String> disabledList = new HashMap<String, String>();
|
||||
private final transient IEssentials ess;
|
||||
|
||||
public EssentialsCommandHandler(ClassLoader classLoader, String commandPath, String permissionPrefix, IEssentials ess)
|
||||
{
|
||||
this(classLoader, commandPath, permissionPrefix, null, ess);
|
||||
}
|
||||
|
||||
public EssentialsCommandHandler(ClassLoader classLoader, String commandPath, String permissionPrefix, IEssentialsModule module, IEssentials ess)
|
||||
{
|
||||
this.classLoader = classLoader;
|
||||
this.commandPath = commandPath;
|
||||
this.permissionPrefix = permissionPrefix;
|
||||
this.module = module;
|
||||
this.ess = ess;
|
||||
for (Plugin plugin : ess.getServer().getPluginManager().getPlugins())
|
||||
{
|
||||
if (plugin.isEnabled())
|
||||
{
|
||||
addPlugin(plugin);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleCommand(final CommandSender sender, final Command command, final String commandLabel, final String[] args)
|
||||
{
|
||||
// Allow plugins to override the command via onCommand
|
||||
if (!ess.getSettings().isCommandOverridden(command.getName()) && !commandLabel.startsWith("e"))
|
||||
{
|
||||
final PluginCommand pc = getAlternative(commandLabel);
|
||||
if (pc != null)
|
||||
{
|
||||
executed(commandLabel, pc.getLabel());
|
||||
return pc.execute(sender, commandLabel, args);
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
IUser user = null;
|
||||
if (sender instanceof Player)
|
||||
{
|
||||
user = ess.getUser((Player)sender);
|
||||
LOGGER.log(Level.INFO, String.format("[PLAYER_COMMAND] %s: /%s %s ", ((Player)sender).getName(), commandLabel, EssentialsCommand.getFinalArg(args, 0)));
|
||||
}
|
||||
|
||||
// New mail notification
|
||||
if (user != null && !ess.getSettings().isCommandDisabled("mail") && !commandLabel.equals("mail") && user.isAuthorized("essentials.mail"))
|
||||
{
|
||||
final List<String> mail = user.getMails();
|
||||
if (mail != null && !mail.isEmpty())
|
||||
{
|
||||
user.sendMessage(_("youHaveNewMail", mail.size()));
|
||||
}
|
||||
}
|
||||
|
||||
// Check for disabled commands
|
||||
if (ess.getSettings().isCommandDisabled(commandLabel))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
IEssentialsCommand cmd;
|
||||
try
|
||||
{
|
||||
cmd = (IEssentialsCommand)classLoader.loadClass(commandPath + command.getName()).newInstance();
|
||||
cmd.setEssentials(ess);
|
||||
cmd.setEssentialsModule(module);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
sender.sendMessage(_("commandNotLoaded", commandLabel));
|
||||
LOGGER.log(Level.SEVERE, _("commandNotLoaded", commandLabel), ex);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check authorization
|
||||
if (user != null && !user.isAuthorized(cmd, permissionPrefix))
|
||||
{
|
||||
LOGGER.log(Level.WARNING, _("deniedAccessCommand", user.getName()));
|
||||
user.sendMessage(_("noAccessCommand"));
|
||||
return true;
|
||||
}
|
||||
|
||||
// Run the command
|
||||
try
|
||||
{
|
||||
if (user == null)
|
||||
{
|
||||
cmd.run(ess.getServer(), sender, commandLabel, command, args);
|
||||
}
|
||||
else
|
||||
{
|
||||
user.acquireReadLock();
|
||||
try
|
||||
{
|
||||
cmd.run(ess.getServer(), user, commandLabel, command, args);
|
||||
}
|
||||
finally
|
||||
{
|
||||
user.unlock();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch (NoChargeException ex)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
catch (NotEnoughArgumentsException ex)
|
||||
{
|
||||
sender.sendMessage(command.getDescription());
|
||||
sender.sendMessage(command.getUsage().replaceAll("<command>", commandLabel));
|
||||
if (!ex.getMessage().isEmpty())
|
||||
{
|
||||
sender.sendMessage(ex.getMessage());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch (Throwable ex)
|
||||
{
|
||||
showCommandError(sender, commandLabel, ex);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (Throwable ex)
|
||||
{
|
||||
LOGGER.log(Level.SEVERE, _("commandFailed", commandLabel), ex);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showCommandError(final CommandSender sender, final String commandLabel, final Throwable exception)
|
||||
{
|
||||
sender.sendMessage(_("errorWithMessage", exception.getMessage()));
|
||||
if (ess.getSettings().isDebug())
|
||||
{
|
||||
LOGGER.log(Level.WARNING, _("errorCallingCommand", commandLabel), exception);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReload()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public final void addPlugin(final Plugin plugin)
|
||||
{
|
||||
if (plugin.getDescription().getMain().contains("com.earth2me.essentials"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
final List<Command> commands = PluginCommandYamlParser.parse(plugin);
|
||||
final String pluginName = plugin.getDescription().getName().toLowerCase(Locale.ENGLISH);
|
||||
|
||||
for (Command command : commands)
|
||||
{
|
||||
final PluginCommand pc = (PluginCommand)command;
|
||||
final List<String> labels = new ArrayList<String>(pc.getAliases());
|
||||
labels.add(pc.getName());
|
||||
|
||||
PluginCommand reg = ess.getServer().getPluginCommand(pluginName + ":" + pc.getName().toLowerCase(Locale.ENGLISH));
|
||||
if (reg == null)
|
||||
{
|
||||
reg = ess.getServer().getPluginCommand(pc.getName().toLowerCase(Locale.ENGLISH));
|
||||
}
|
||||
if (reg == null || !reg.getPlugin().equals(plugin))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
for (String label : labels)
|
||||
{
|
||||
List<PluginCommand> plugincommands = altcommands.get(label.toLowerCase(Locale.ENGLISH));
|
||||
if (plugincommands == null)
|
||||
{
|
||||
plugincommands = new ArrayList<PluginCommand>();
|
||||
altcommands.put(label.toLowerCase(Locale.ENGLISH), plugincommands);
|
||||
}
|
||||
boolean found = false;
|
||||
for (PluginCommand pc2 : plugincommands)
|
||||
{
|
||||
if (pc2.getPlugin().equals(plugin))
|
||||
{
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
{
|
||||
plugincommands.add(reg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void removePlugin(final Plugin plugin)
|
||||
{
|
||||
final Iterator<Map.Entry<String, List<PluginCommand>>> iterator = altcommands.entrySet().iterator();
|
||||
while (iterator.hasNext())
|
||||
{
|
||||
final Map.Entry<String, List<PluginCommand>> entry = iterator.next();
|
||||
final Iterator<PluginCommand> pcIterator = entry.getValue().iterator();
|
||||
while (pcIterator.hasNext())
|
||||
{
|
||||
final PluginCommand pc = pcIterator.next();
|
||||
if (pc.getPlugin() == null || pc.getPlugin().equals(plugin))
|
||||
{
|
||||
pcIterator.remove();
|
||||
}
|
||||
}
|
||||
if (entry.getValue().isEmpty())
|
||||
{
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public PluginCommand getAlternative(final String label)
|
||||
{
|
||||
final List<PluginCommand> commands = altcommands.get(label);
|
||||
if (commands == null || commands.isEmpty())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (commands.size() == 1)
|
||||
{
|
||||
return commands.get(0);
|
||||
}
|
||||
// return the first command that is not an alias
|
||||
for (PluginCommand command : commands)
|
||||
{
|
||||
if (command.getName().equalsIgnoreCase(label))
|
||||
{
|
||||
return command;
|
||||
}
|
||||
}
|
||||
// return the first alias
|
||||
return commands.get(0);
|
||||
}
|
||||
|
||||
public void executed(final String label, final String otherLabel)
|
||||
{
|
||||
if (ess.getSettings().isDebug())
|
||||
{
|
||||
LOGGER.log(Level.INFO, "Essentials: Alternative command " + label + " found, using " + otherLabel);
|
||||
}
|
||||
disabledList.put(label, otherLabel);
|
||||
}
|
||||
|
||||
public Map<String, String> disabledCommands()
|
||||
{
|
||||
return disabledList;
|
||||
}
|
||||
}
|
@@ -4,6 +4,7 @@ import com.earth2me.essentials.craftbukkit.FakeWorld;
|
||||
import com.earth2me.essentials.settings.Spawns;
|
||||
import com.earth2me.essentials.storage.YamlStorageWriter;
|
||||
import static com.earth2me.essentials.I18n._;
|
||||
import com.earth2me.essentials.api.IEssentials;
|
||||
import java.io.*;
|
||||
import java.math.BigInteger;
|
||||
import java.security.DigestInputStream;
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import com.earth2me.essentials.api.IEssentials;
|
||||
import com.earth2me.essentials.api.II18n;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
|
@@ -1,9 +0,0 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
/**
|
||||
* @deprecated New interface will be IReload in api package
|
||||
*/
|
||||
@Deprecated
|
||||
public interface IConf {
|
||||
public void reloadConfig();
|
||||
}
|
@@ -1,68 +0,0 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import com.earth2me.essentials.listener.TNTExplodeListener;
|
||||
import com.earth2me.essentials.api.IJails;
|
||||
import com.earth2me.essentials.perm.PermissionsHandler;
|
||||
import com.earth2me.essentials.register.payment.Methods;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
|
||||
/**
|
||||
* @deprecated This will be moved to the api package soon
|
||||
*/
|
||||
@Deprecated
|
||||
public interface IEssentials extends Plugin, com.earth2me.essentials.api.IEssentials
|
||||
{
|
||||
void addReloadListener(IConf listener);
|
||||
|
||||
void reload();
|
||||
|
||||
boolean onCommandEssentials(CommandSender sender, Command command, String commandLabel, String[] args, ClassLoader classLoader, String commandPath, String permissionPrefix, IEssentialsModule module);
|
||||
|
||||
User getUser(Object base);
|
||||
|
||||
I18n getI18n();
|
||||
|
||||
User getOfflineUser(String name);
|
||||
|
||||
World getWorld(String name);
|
||||
|
||||
int broadcastMessage(IUser sender, String message);
|
||||
|
||||
ISettings getSettings();
|
||||
|
||||
BukkitScheduler getScheduler();
|
||||
|
||||
IJails getJails();
|
||||
|
||||
Warps getWarps();
|
||||
|
||||
Worth getWorth();
|
||||
|
||||
Backup getBackup();
|
||||
|
||||
Methods getPaymentMethod();
|
||||
|
||||
int scheduleAsyncDelayedTask(Runnable run);
|
||||
|
||||
int scheduleSyncDelayedTask(Runnable run);
|
||||
|
||||
int scheduleSyncDelayedTask(Runnable run, long delay);
|
||||
|
||||
int scheduleSyncRepeatingTask(final Runnable run, long delay, long period);
|
||||
|
||||
TNTExplodeListener getTNTListener();
|
||||
|
||||
PermissionsHandler getPermissionsHandler();
|
||||
|
||||
AlternativeCommandsHandler getAlternativeCommandsHandler();
|
||||
|
||||
void showError(final CommandSender sender, final Throwable exception, final String commandLabel);
|
||||
|
||||
ItemDb getItemDb();
|
||||
|
||||
UserMap getUserMap();
|
||||
}
|
@@ -1,6 +0,0 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
@Deprecated
|
||||
public interface IEssentialsModule
|
||||
{
|
||||
}
|
@@ -1,10 +0,0 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
@Deprecated
|
||||
public interface IReplyTo {
|
||||
public void setReplyTo(CommandSender user);
|
||||
|
||||
public CommandSender getReplyTo();
|
||||
}
|
@@ -8,7 +8,7 @@ import org.bukkit.ChatColor;
|
||||
import org.bukkit.event.Event.Priority;
|
||||
|
||||
@Deprecated
|
||||
public interface ISettings extends IConf, com.earth2me.essentials.api.ISettings
|
||||
public interface ISettings extends com.earth2me.essentials.api.ISettings
|
||||
{
|
||||
boolean areSignsDisabled();
|
||||
|
||||
|
@@ -11,7 +11,7 @@ import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
|
||||
public class ItemDb implements IConf, IItemDb
|
||||
public class ItemDb implements IItemDb
|
||||
{
|
||||
private final transient IEssentials ess;
|
||||
|
||||
@@ -120,10 +120,4 @@ public class ItemDb implements IConf, IItemDb
|
||||
retval.setDurability(metaData);
|
||||
return retval;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reloadConfig()
|
||||
{
|
||||
onReload();
|
||||
}
|
||||
}
|
||||
|
@@ -27,7 +27,7 @@ public class Jails extends AsyncStorageObjectHolder<com.earth2me.essentials.sett
|
||||
public Jails(final IEssentials ess)
|
||||
{
|
||||
super(ess, com.earth2me.essentials.settings.Jails.class);
|
||||
reloadConfig();
|
||||
onReload();
|
||||
registerListeners();
|
||||
}
|
||||
|
||||
|
@@ -118,7 +118,7 @@ public class Teleport implements Runnable, ITeleport
|
||||
}
|
||||
catch (Throwable ex)
|
||||
{
|
||||
ess.showCommandError(user.getBase(), "teleport", ex);
|
||||
ess.getCommandHandler().showCommandError(user.getBase(), "teleport", ex);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -145,7 +145,7 @@ public class Teleport implements Runnable, ITeleport
|
||||
|
||||
public void warp(String warp, Trade chargeFor, TeleportCause cause) throws Exception
|
||||
{
|
||||
final Location loc = ess.getWarps2().getWarp(warp);
|
||||
final Location loc = ess.getWarps().getWarp(warp);
|
||||
teleport(new Target(loc), chargeFor, cause);
|
||||
user.sendMessage(_("warpingTo", warp));
|
||||
}
|
||||
|
@@ -21,7 +21,7 @@ import org.bukkit.permissions.PermissionDefault;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
|
||||
|
||||
public class Util
|
||||
public final class Util
|
||||
{
|
||||
private Util()
|
||||
{
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import com.earth2me.essentials.api.IWarps;
|
||||
import static com.earth2me.essentials.I18n._;
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
@@ -9,7 +10,7 @@ import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
|
||||
|
||||
public class Warps implements IConf
|
||||
public class Warps implements IWarps
|
||||
{
|
||||
private static final Logger logger = Logger.getLogger("Minecraft");
|
||||
private final Map<StringIgnoreCase, EssentialsConf> warpPoints = new HashMap<StringIgnoreCase, EssentialsConf>();
|
||||
|
@@ -7,7 +7,7 @@ import java.util.logging.Logger;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
|
||||
public class Worth implements IConf, IWorth
|
||||
public class Worth implements IWorth
|
||||
{
|
||||
private static final Logger logger = Logger.getLogger("Minecraft");
|
||||
private final EssentialsConf config;
|
||||
@@ -55,14 +55,8 @@ public class Worth implements IConf, IWorth
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reloadConfig()
|
||||
public void onReload()
|
||||
{
|
||||
config.load();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReload()
|
||||
{
|
||||
reloadConfig();
|
||||
}
|
||||
}
|
||||
|
@@ -2,8 +2,6 @@ package com.earth2me.essentials.api;
|
||||
|
||||
import com.earth2me.essentials.EssentialsConf;
|
||||
import static com.earth2me.essentials.I18n._;
|
||||
import com.earth2me.essentials.IEssentials;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.Util;
|
||||
import java.io.File;
|
||||
import java.util.logging.Level;
|
||||
@@ -66,13 +64,13 @@ public final class Economy
|
||||
}
|
||||
}
|
||||
|
||||
private static User getUserByName(String name)
|
||||
private static IUser getUserByName(String name)
|
||||
{
|
||||
if (ess == null)
|
||||
{
|
||||
throw new RuntimeException(noCallBeforeLoad);
|
||||
}
|
||||
User user;
|
||||
IUser user;
|
||||
Player player = ess.getServer().getPlayer(name);
|
||||
if (player != null)
|
||||
{
|
||||
@@ -93,7 +91,7 @@ public final class Economy
|
||||
*/
|
||||
public static double getMoney(String name) throws UserDoesNotExistException
|
||||
{
|
||||
User user = getUserByName(name);
|
||||
IUser user = getUserByName(name);
|
||||
if (user == null)
|
||||
{
|
||||
throw new UserDoesNotExistException(name);
|
||||
@@ -110,7 +108,7 @@ public final class Economy
|
||||
*/
|
||||
public static void setMoney(String name, double balance) throws UserDoesNotExistException, NoLoanPermittedException
|
||||
{
|
||||
User user = getUserByName(name);
|
||||
IUser user = getUserByName(name);
|
||||
if (user == null)
|
||||
{
|
||||
throw new UserDoesNotExistException(name);
|
||||
@@ -266,7 +264,7 @@ public final class Economy
|
||||
*/
|
||||
public static boolean isNPC(String name) throws UserDoesNotExistException
|
||||
{
|
||||
User user = getUserByName(name);
|
||||
IUser user = getUserByName(name);
|
||||
if (user == null)
|
||||
{
|
||||
throw new UserDoesNotExistException(name);
|
||||
@@ -281,7 +279,7 @@ public final class Economy
|
||||
*/
|
||||
public static boolean createNPC(String name)
|
||||
{
|
||||
User user = getUserByName(name);
|
||||
IUser user = getUserByName(name);
|
||||
if (user == null)
|
||||
{
|
||||
createNPCFile(name);
|
||||
@@ -297,7 +295,7 @@ public final class Economy
|
||||
*/
|
||||
public static void removeNPC(String name) throws UserDoesNotExistException
|
||||
{
|
||||
User user = getUserByName(name);
|
||||
IUser user = getUserByName(name);
|
||||
if (user == null)
|
||||
{
|
||||
throw new UserDoesNotExistException(name);
|
||||
|
@@ -0,0 +1,20 @@
|
||||
package com.earth2me.essentials.api;
|
||||
|
||||
import java.util.Map;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
|
||||
public interface ICommandHandler extends IReload
|
||||
{
|
||||
Map<String, String> disabledCommands();
|
||||
|
||||
public void removePlugin(Plugin plugin);
|
||||
|
||||
public void addPlugin(Plugin plugin);
|
||||
|
||||
boolean handleCommand(CommandSender sender, Command command, String commandLabel, String[] args);
|
||||
|
||||
void showCommandError(CommandSender sender, String commandLabel, Throwable exception);
|
||||
}
|
@@ -4,15 +4,19 @@ import com.earth2me.essentials.listener.TNTExplodeListener;
|
||||
import com.earth2me.essentials.perm.IPermissionsHandler;
|
||||
import com.earth2me.essentials.register.payment.Methods;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
|
||||
public interface IEssentials extends Plugin, IReload
|
||||
public interface IEssentials extends Plugin
|
||||
{
|
||||
void addReloadListener(IReload listener);
|
||||
|
||||
IUser getUser(Object base);
|
||||
IUser getUser(Player player);
|
||||
|
||||
IUser getUser(String playerName);
|
||||
|
||||
int broadcastMessage(IUser sender, String message);
|
||||
|
||||
@@ -24,7 +28,7 @@ public interface IEssentials extends Plugin, IReload
|
||||
|
||||
IJails getJails();
|
||||
|
||||
IWarps getWarps2();
|
||||
IWarps getWarps();
|
||||
|
||||
IWorth getWorth();
|
||||
|
||||
@@ -36,6 +40,8 @@ public interface IEssentials extends Plugin, IReload
|
||||
|
||||
IEssentialsEconomy getEconomy();
|
||||
|
||||
ICommandHandler getCommandHandler();
|
||||
|
||||
World getWorld(String name);
|
||||
|
||||
Methods getPaymentMethod();
|
||||
@@ -50,13 +56,7 @@ public interface IEssentials extends Plugin, IReload
|
||||
|
||||
IPermissionsHandler getPermissionsHandler();
|
||||
|
||||
IAlternativeCommandsHandler getAlternativeCommandsHandler();
|
||||
void reload();
|
||||
|
||||
void showCommandError(CommandSender sender, String commandLabel, Throwable exception);
|
||||
|
||||
public void reload();
|
||||
|
||||
public IUser getOfflineUser(String string);
|
||||
|
||||
public TNTExplodeListener getTNTListener();
|
||||
TNTExplodeListener getTNTListener();
|
||||
}
|
||||
|
@@ -7,4 +7,10 @@ import com.earth2me.essentials.storage.IStorageObjectHolder;
|
||||
public interface ISettings extends IStorageObjectHolder<Settings>
|
||||
{
|
||||
|
||||
public String getLocale();
|
||||
|
||||
public boolean isDebug();
|
||||
|
||||
public void setDebug(boolean b);
|
||||
|
||||
}
|
||||
|
@@ -2,13 +2,16 @@ package com.earth2me.essentials.api;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Set;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
public interface IUserMap extends IReload
|
||||
{
|
||||
boolean userExists(final String name);
|
||||
|
||||
IUser getUser(final String name);
|
||||
IUser getUser(final Player player);
|
||||
|
||||
IUser getUser(final String playerName);
|
||||
|
||||
void removeUser(final String name);
|
||||
|
||||
|
@@ -1,9 +1,9 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import static com.earth2me.essentials.I18n._;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.api.IUser;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
public class Commandafk extends EssentialsCommand
|
||||
@@ -18,7 +18,7 @@ public class Commandafk extends EssentialsCommand
|
||||
{
|
||||
if (args.length > 0 && user.isAuthorized("essentials.afk.others"))
|
||||
{
|
||||
IUser afkUser = ess.getUser(ess.getServer().matchPlayer(args[0]));
|
||||
IUser afkUser = ess.getUser((Player)ess.getServer().matchPlayer(args[0]));
|
||||
if (afkUser != null)
|
||||
{
|
||||
toggleAfk(afkUser);
|
||||
|
@@ -30,7 +30,7 @@ public class Commandban extends EssentialsCommand
|
||||
if (user.getBase() instanceof OfflinePlayer)
|
||||
{
|
||||
if (sender instanceof Player
|
||||
&& !ess.getUser(sender).isAuthorized("essentials.ban.offline"))
|
||||
&& !ess.getUser((Player)sender).isAuthorized("essentials.ban.offline"))
|
||||
{
|
||||
sender.sendMessage(_("banExempt"));
|
||||
return;
|
||||
|
@@ -6,6 +6,7 @@ import java.util.Locale;
|
||||
import lombok.Cleanup;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
public class Commanddelhome extends EssentialsCommand
|
||||
@@ -24,7 +25,7 @@ public class Commanddelhome extends EssentialsCommand
|
||||
}
|
||||
|
||||
@Cleanup
|
||||
IUser user = ess.getUser(sender);
|
||||
IUser user = sender instanceof Player ? ess.getUser((Player)sender) : null;
|
||||
String name;
|
||||
final String[] expandedArg = args[0].split(":");
|
||||
|
||||
|
@@ -19,7 +19,7 @@ public class Commanddelwarp extends EssentialsCommand
|
||||
{
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
ess.getWarps2().removeWarp(args[0]);
|
||||
ess.getWarps().removeWarp(args[0]);
|
||||
sender.sendMessage(_("deleteWarp", args[0]));
|
||||
}
|
||||
}
|
||||
|
@@ -47,7 +47,7 @@ public class Commandessentials extends EssentialsCommand
|
||||
sender.sendMessage("/<command> <reload/debug>");
|
||||
sender.sendMessage(_("blockList"));
|
||||
final StringBuilder disabledCommands = new StringBuilder();
|
||||
for (Map.Entry<String, String> entry : ess.getAlternativeCommandsHandler().disabledCommands().entrySet())
|
||||
for (Map.Entry<String, String> entry : ess.getCommandHandler().disabledCommands().entrySet())
|
||||
{
|
||||
if (disabledCommands.length() > 0) {
|
||||
disabledCommands.append(", ");
|
||||
@@ -59,11 +59,8 @@ public class Commandessentials extends EssentialsCommand
|
||||
|
||||
private void run_debug(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
|
||||
{
|
||||
@Cleanup
|
||||
ISettings settings = ess.getSettings();
|
||||
settings.acquireWriteLock();
|
||||
settings.getData().getGeneral().setDebug(!settings.getData().getGeneral().isDebug());
|
||||
sender.sendMessage("Essentials " + ess.getDescription().getVersion() + " debug mode " + (settings.getData().getGeneral().isDebug() ? "enabled" : "disabled"));
|
||||
ess.getSettings().setDebug(!ess.getSettings().isDebug());
|
||||
sender.sendMessage("Essentials " + ess.getDescription().getVersion() + " debug mode " + (ess.getSettings().isDebug() ? "enabled" : "disabled"));
|
||||
}
|
||||
|
||||
private void run_reload(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
|
||||
|
@@ -26,7 +26,7 @@ public class Commandignore extends EssentialsCommand
|
||||
}
|
||||
catch (NoSuchFieldException ex)
|
||||
{
|
||||
player = ess.getOfflineUser(args[0]);
|
||||
player = ess.getUser(args[0]);
|
||||
}
|
||||
if (player == null)
|
||||
{
|
||||
|
@@ -3,6 +3,7 @@ package com.earth2me.essentials.commands;
|
||||
import com.earth2me.essentials.craftbukkit.InventoryWorkaround;
|
||||
import static com.earth2me.essentials.I18n._;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.api.IUser;
|
||||
import java.util.Locale;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Server;
|
||||
@@ -18,7 +19,7 @@ public class Commanditem extends EssentialsCommand
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
|
||||
public void run(final Server server, final IUser user, final String commandLabel, final String[] args) throws Exception
|
||||
{
|
||||
if (args.length < 1)
|
||||
{
|
||||
|
@@ -21,7 +21,7 @@ public class Commandlist extends EssentialsCommand
|
||||
boolean showhidden = false;
|
||||
if (sender instanceof Player)
|
||||
{
|
||||
if (ess.getUser(sender).isAuthorized("essentials.list.hidden"))
|
||||
if (ess.getUser((Player)sender).isAuthorized("essentials.list.hidden"))
|
||||
{
|
||||
showhidden = true;
|
||||
}
|
||||
|
@@ -49,7 +49,7 @@ public class Commandmail extends EssentialsCommand
|
||||
}
|
||||
else
|
||||
{
|
||||
u = ess.getOfflineUser(args[1]);
|
||||
u = ess.getUser(args[1]);
|
||||
}
|
||||
if (u == null)
|
||||
{
|
||||
@@ -103,7 +103,7 @@ public class Commandmail extends EssentialsCommand
|
||||
}
|
||||
else
|
||||
{
|
||||
u = ess.getOfflineUser(args[1]);
|
||||
u = ess.getUser(args[1]);
|
||||
}
|
||||
if (u == null)
|
||||
{
|
||||
@@ -128,7 +128,7 @@ public class Commandmail extends EssentialsCommand
|
||||
}
|
||||
else
|
||||
{
|
||||
u = ess.getOfflineUser(args[0]);
|
||||
u = ess.getUser(args[0]);
|
||||
}
|
||||
if (u == null)
|
||||
{
|
||||
|
@@ -29,7 +29,7 @@ public class Commandmsg extends EssentialsCommand
|
||||
if (sender instanceof Player)
|
||||
{
|
||||
@Cleanup
|
||||
IUser user = ess.getUser(sender);
|
||||
IUser user = ess.getUser((Player)sender);
|
||||
user.acquireReadLock();
|
||||
if (user.getData().isMuted())
|
||||
{
|
||||
|
@@ -45,7 +45,7 @@ public class Commandptime extends EssentialsCommand
|
||||
return;
|
||||
}
|
||||
|
||||
IUser user = ess.getUser(sender);
|
||||
IUser user = sender instanceof Player ? ess.getUser((Player)sender) : null;
|
||||
if ((!users.contains(user) || users.size() > 1) && user != null && !user.isAuthorized("essentials.ptime.others"))
|
||||
{
|
||||
user.sendMessage(_("pTimeOthersPermission"));
|
||||
@@ -187,7 +187,7 @@ public class Commandptime extends EssentialsCommand
|
||||
// If there is no selector we want the sender itself. Or all users if sender isn't a user.
|
||||
if (selector == null)
|
||||
{
|
||||
final IUser user = ess.getUser(sender);
|
||||
final IUser user = sender instanceof Player ? ess.getUser((Player)sender) : null;
|
||||
if (user == null)
|
||||
{
|
||||
for (Player player : server.getOnlinePlayers())
|
||||
|
@@ -38,7 +38,7 @@ public class Commandr extends EssentialsCommand
|
||||
sender.sendMessage(_("msgFormat", _("me"), targetName, message));
|
||||
if (target instanceof Player)
|
||||
{
|
||||
IUser player = ess.getUser(target);
|
||||
IUser player = ess.getUser((Player)target);
|
||||
if (player.isIgnoringPlayer(sender instanceof Player ? ((Player)sender).getName() : Console.NAME))
|
||||
{
|
||||
return;
|
||||
|
@@ -29,7 +29,7 @@ public class Commandseen extends EssentialsCommand
|
||||
}
|
||||
catch (NoSuchFieldException e)
|
||||
{
|
||||
IUser u = ess.getOfflineUser(args[0]);
|
||||
IUser u = ess.getUser(args[0]);
|
||||
if (u == null)
|
||||
{
|
||||
throw new Exception(_("playerNotFound"));
|
||||
|
@@ -22,7 +22,7 @@ public class Commandsetwarp extends EssentialsCommand
|
||||
}
|
||||
|
||||
final Location loc = user.getLocation();
|
||||
ess.getWarps2().setWarp(args[0], loc);
|
||||
ess.getWarps().setWarp(args[0], loc);
|
||||
user.sendMessage(_("warpSet", args[0]));
|
||||
}
|
||||
}
|
||||
|
@@ -29,7 +29,7 @@ public class Commandtempban extends EssentialsCommand
|
||||
if (user.getBase() instanceof OfflinePlayer)
|
||||
{
|
||||
if (sender instanceof Player
|
||||
&& !ess.getUser(sender).isAuthorized("essentials.tempban.offline"))
|
||||
&& !ess.getUser((Player)sender).isAuthorized("essentials.tempban.offline"))
|
||||
{
|
||||
sender.sendMessage(_("tempbanExempt"));
|
||||
return;
|
||||
|
@@ -7,6 +7,7 @@ import java.util.*;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
public class Commandtime extends EssentialsCommand
|
||||
@@ -34,7 +35,7 @@ public class Commandtime extends EssentialsCommand
|
||||
return;
|
||||
}
|
||||
|
||||
final IUser user = ess.getUser(sender);
|
||||
final IUser user = sender instanceof Player ? ess.getUser((Player)sender) : null;
|
||||
if (user != null && !user.isAuthorized("essentials.time.set"))
|
||||
{
|
||||
user.sendMessage(_("timeSetPermission"));
|
||||
@@ -110,7 +111,7 @@ public class Commandtime extends EssentialsCommand
|
||||
// If there is no selector we want the world the user is currently in. Or all worlds if it isn't a user.
|
||||
if (selector == null)
|
||||
{
|
||||
final IUser user = ess.getUser(sender);
|
||||
final IUser user = sender instanceof Player ? ess.getUser((Player)sender) : null;
|
||||
if (user == null)
|
||||
{
|
||||
worlds.addAll(server.getWorlds());
|
||||
|
@@ -35,7 +35,7 @@ public class Commandtogglejail extends EssentialsCommand
|
||||
if (player.getBase() instanceof OfflinePlayer)
|
||||
{
|
||||
if (sender instanceof Player
|
||||
&& !ess.getUser(sender).isAuthorized("essentials.togglejail.offline"))
|
||||
&& !ess.getUser((Player)sender).isAuthorized("essentials.togglejail.offline"))
|
||||
{
|
||||
sender.sendMessage(_("mayNotJail"));
|
||||
return;
|
||||
|
@@ -73,7 +73,7 @@ public class Commandwarp extends EssentialsCommand
|
||||
//TODO: Use one of the new text classes, like /help ?
|
||||
private void warpList(final CommandSender sender, final String[] args) throws Exception
|
||||
{
|
||||
final IWarps warps = ess.getWarps2();
|
||||
final IWarps warps = ess.getWarps();
|
||||
if (warps.isEmpty())
|
||||
{
|
||||
throw new Exception(_("noWarpsDefined"));
|
||||
|
@@ -28,7 +28,7 @@ public class Commandwhois extends EssentialsCommand
|
||||
boolean showhidden = false;
|
||||
if (sender instanceof Player)
|
||||
{
|
||||
if (ess.getUser(sender).isAuthorized("essentials.list.hidden"))
|
||||
if (ess.getUser((Player)sender).isAuthorized("essentials.list.hidden"))
|
||||
{
|
||||
showhidden = true;
|
||||
}
|
||||
@@ -76,7 +76,7 @@ public class Commandwhois extends EssentialsCommand
|
||||
sender.sendMessage(_("whoisIPAddress", user.getAddress().getAddress().toString()));
|
||||
final String location = user.getData().getGeolocation();
|
||||
if (location != null
|
||||
&& (sender instanceof Player ? ess.getUser(sender).isAuthorized("essentials.geoip.show") : true))
|
||||
&& (sender instanceof Player ? ess.getUser((Player)sender).isAuthorized("essentials.geoip.show") : true))
|
||||
{
|
||||
sender.sendMessage(_("whoisGeoLocation", location));
|
||||
}
|
||||
|
@@ -92,7 +92,7 @@ public abstract class EssentialsCommand implements IEssentialsCommand
|
||||
@Override
|
||||
public final void run(final Server server, final IUser user, final String commandLabel, final Command cmd, final String[] args) throws Exception
|
||||
{
|
||||
final Trade charge = new Trade(this.getName(), (com.earth2me.essentials.IEssentials)ess);
|
||||
final Trade charge = new Trade(this.getName(), ess);
|
||||
charge.isAffordableFor(user);
|
||||
run(server, user, commandLabel, args);
|
||||
charge.charge(user);
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package com.earth2me.essentials.craftbukkit;
|
||||
|
||||
import com.earth2me.essentials.IEssentials;
|
||||
import com.earth2me.essentials.api.IEssentials;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import net.minecraft.server.NBTTagCompound;
|
||||
|
@@ -36,7 +36,7 @@ public class EssentialsEntityListener extends EntityListener
|
||||
if (eDefend instanceof Player && eAttack instanceof Player)
|
||||
{
|
||||
@Cleanup
|
||||
final IUser attacker = ess.getUser(eAttack);
|
||||
final IUser attacker = ess.getUser((Player)eAttack);
|
||||
attacker.acquireReadLock();
|
||||
attacker.updateActivity(true);
|
||||
final ItemStack itemstack = attacker.getItemInHand();
|
||||
@@ -48,7 +48,7 @@ public class EssentialsEntityListener extends EntityListener
|
||||
|
||||
if (command != null && !command.isEmpty())
|
||||
{
|
||||
final IUser defender = ess.getUser(eDefend);
|
||||
final IUser defender = ess.getUser((Player)eDefend);
|
||||
attacker.getServer().dispatchCommand(attacker, command.replaceAll("\\{player\\}", defender.getName()));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
@@ -58,7 +58,7 @@ public class EssentialsEntityListener extends EntityListener
|
||||
}
|
||||
if (eDefend instanceof Animals && eAttack instanceof Player)
|
||||
{
|
||||
final IUser player = ess.getUser(eAttack);
|
||||
final IUser player = ess.getUser((Player)eAttack);
|
||||
final ItemStack hand = player.getItemInHand();
|
||||
if (hand != null && hand.getType() == Material.MILK_BUCKET)
|
||||
{
|
||||
@@ -70,7 +70,7 @@ public class EssentialsEntityListener extends EntityListener
|
||||
}
|
||||
}
|
||||
}
|
||||
if (event.getEntity() instanceof Player && ess.getUser(event.getEntity()).isGodModeEnabled())
|
||||
if (event.getEntity() instanceof Player && ess.getUser((Player)event.getEntity()).isGodModeEnabled())
|
||||
{
|
||||
final Player player = (Player)event.getEntity();
|
||||
player.setFireTicks(0);
|
||||
@@ -82,7 +82,7 @@ public class EssentialsEntityListener extends EntityListener
|
||||
@Override
|
||||
public void onEntityCombust(final EntityCombustEvent event)
|
||||
{
|
||||
if (event.getEntity() instanceof Player && ess.getUser(event.getEntity()).isGodModeEnabled())
|
||||
if (event.getEntity() instanceof Player && ess.getUser((Player)event.getEntity()).isGodModeEnabled())
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
@@ -94,7 +94,7 @@ public class EssentialsEntityListener extends EntityListener
|
||||
if (event instanceof PlayerDeathEvent)
|
||||
{
|
||||
final PlayerDeathEvent pdevent = (PlayerDeathEvent)event;
|
||||
final IUser user = ess.getUser(pdevent.getEntity());
|
||||
final IUser user = ess.getUser((Player)pdevent.getEntity());
|
||||
@Cleanup
|
||||
final ISettings settings = ess.getSettings();
|
||||
settings.acquireReadLock();
|
||||
@@ -113,7 +113,7 @@ public class EssentialsEntityListener extends EntityListener
|
||||
@Override
|
||||
public void onFoodLevelChange(final FoodLevelChangeEvent event)
|
||||
{
|
||||
if (event.getEntity() instanceof Player && ess.getUser(event.getEntity()).isGodModeEnabled())
|
||||
if (event.getEntity() instanceof Player && ess.getUser((Player)event.getEntity()).isGodModeEnabled())
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
@@ -129,7 +129,7 @@ public class EssentialsEntityListener extends EntityListener
|
||||
final ISettings settings = ess.getSettings();
|
||||
settings.acquireReadLock();
|
||||
@Cleanup
|
||||
final IUser user = ess.getUser(event.getEntity());
|
||||
final IUser user = ess.getUser((Player)event.getEntity());
|
||||
user.acquireReadLock();
|
||||
if (user.getData().isAfk() && settings.getData().getCommands().getAfk().isFreezeAFKPlayers())
|
||||
{
|
||||
|
@@ -162,8 +162,8 @@ public class EssentialsPlayerListener extends PlayerListener
|
||||
{
|
||||
try
|
||||
{
|
||||
final IText input = new TextInput(user, "motd", true, (com.earth2me.essentials.IEssentials)ess);
|
||||
final IText output = new KeywordReplacer(input, user, (com.earth2me.essentials.IEssentials)ess);
|
||||
final IText input = new TextInput(user, "motd", true, ess);
|
||||
final IText output = new KeywordReplacer(input, user, ess);
|
||||
final TextPager pager = new TextPager(output, true);
|
||||
pager.showPage("1", null, "motd", user);
|
||||
}
|
||||
|
@@ -1,18 +1,15 @@
|
||||
package com.earth2me.essentials.listener;
|
||||
|
||||
import com.earth2me.essentials.IConf;
|
||||
import com.earth2me.essentials.api.IEssentials;
|
||||
import com.earth2me.essentials.api.IReload;
|
||||
import com.earth2me.essentials.api.ISettings;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import lombok.Cleanup;
|
||||
import org.bukkit.event.server.PluginDisableEvent;
|
||||
import org.bukkit.event.server.PluginEnableEvent;
|
||||
import org.bukkit.event.server.ServerListener;
|
||||
|
||||
|
||||
public class EssentialsPluginListener extends ServerListener implements IConf, IReload
|
||||
public class EssentialsPluginListener extends ServerListener implements IReload
|
||||
{
|
||||
private final transient IEssentials ess;
|
||||
private static final Logger LOGGER = Logger.getLogger("Minecraft");
|
||||
@@ -27,7 +24,7 @@ public class EssentialsPluginListener extends ServerListener implements IConf, I
|
||||
public void onPluginEnable(final PluginEnableEvent event)
|
||||
{
|
||||
ess.getPermissionsHandler().checkPermissions();
|
||||
ess.getAlternativeCommandsHandler().addPlugin(event.getPlugin());
|
||||
ess.getCommandHandler().addPlugin(event.getPlugin());
|
||||
if (!ess.getPaymentMethod().hasMethod() && ess.getPaymentMethod().setMethod(ess.getServer().getPluginManager()))
|
||||
{
|
||||
LOGGER.log(Level.INFO, "[Essentials] Payment method found ({0} version: {1})", new Object[]{ess.getPaymentMethod().getMethod().getName(), ess.getPaymentMethod().getMethod().getVersion()});
|
||||
@@ -38,7 +35,7 @@ public class EssentialsPluginListener extends ServerListener implements IConf, I
|
||||
public void onPluginDisable(final PluginDisableEvent event)
|
||||
{
|
||||
ess.getPermissionsHandler().checkPermissions();
|
||||
ess.getAlternativeCommandsHandler().removePlugin(event.getPlugin());
|
||||
ess.getCommandHandler().removePlugin(event.getPlugin());
|
||||
// Check to see if the plugin thats being disabled is the one we are using
|
||||
if (ess.getPaymentMethod() != null && ess.getPaymentMethod().hasMethod() && ess.getPaymentMethod().checkDisabled(event.getPlugin()))
|
||||
{
|
||||
@@ -48,13 +45,8 @@ public class EssentialsPluginListener extends ServerListener implements IConf, I
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reloadConfig()
|
||||
public void onReload()
|
||||
{
|
||||
//ess.getPermissionsHandler().setUseSuperperms(ess.getSettings().useBukkitPermissions());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReload()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,10 @@
|
||||
package com.earth2me.essentials.perm;
|
||||
|
||||
|
||||
public abstract class AbstractPermissionsHandler implements IPermissionsHandler
|
||||
{
|
||||
@Override
|
||||
public void checkPermissions()
|
||||
{
|
||||
}
|
||||
}
|
@@ -6,7 +6,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
|
||||
public class ConfigPermissionsHandler implements IPermissionsHandler
|
||||
public class ConfigPermissionsHandler extends AbstractPermissionsHandler
|
||||
{
|
||||
private final transient IEssentials ess;
|
||||
|
||||
|
@@ -8,7 +8,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
|
||||
public class GroupManagerHandler implements IPermissionsHandler
|
||||
public class GroupManagerHandler extends AbstractPermissionsHandler
|
||||
{
|
||||
private final transient GroupManager groupManager;
|
||||
|
||||
|
@@ -19,4 +19,6 @@ public interface IPermissionsHandler
|
||||
String getPrefix(Player base);
|
||||
|
||||
String getSuffix(Player base);
|
||||
|
||||
public void checkPermissions();
|
||||
}
|
||||
|
@@ -5,7 +5,7 @@ import java.util.List;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
public class NullPermissionsHandler implements IPermissionsHandler
|
||||
public class NullPermissionsHandler extends AbstractPermissionsHandler
|
||||
{
|
||||
@Override
|
||||
public String getGroup(final Player base)
|
||||
|
@@ -8,7 +8,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
|
||||
public class Permissions2Handler implements IPermissionsHandler
|
||||
public class Permissions2Handler extends AbstractPermissionsHandler
|
||||
{
|
||||
private final transient PermissionHandler permissionHandler;
|
||||
|
||||
|
@@ -8,7 +8,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
|
||||
public class Permissions3Handler implements IPermissionsHandler
|
||||
public class Permissions3Handler extends AbstractPermissionsHandler
|
||||
{
|
||||
private final transient PermissionHandler permissionHandler;
|
||||
|
||||
|
@@ -8,7 +8,7 @@ import ru.tehkode.permissions.PermissionUser;
|
||||
import ru.tehkode.permissions.bukkit.PermissionsEx;
|
||||
|
||||
|
||||
public class PermissionsExHandler implements IPermissionsHandler
|
||||
public class PermissionsExHandler extends AbstractPermissionsHandler
|
||||
{
|
||||
private final transient PermissionManager manager;
|
||||
|
||||
|
@@ -96,6 +96,7 @@ public class PermissionsHandler implements IPermissionsHandler
|
||||
return suffix;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkPermissions()
|
||||
{
|
||||
final PluginManager pluginManager = plugin.getServer().getPluginManager();
|
||||
|
@@ -4,7 +4,7 @@ import java.util.List;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
public class SuperpermsHandler implements IPermissionsHandler
|
||||
public class SuperpermsHandler extends AbstractPermissionsHandler
|
||||
{
|
||||
@Override
|
||||
public String getGroup(final Player base)
|
||||
|
@@ -36,7 +36,7 @@ public class GroupsHolder extends AsyncStorageObjectHolder<Groups> implements IG
|
||||
{
|
||||
return;
|
||||
}
|
||||
Util.registerPermissions("essentials.groups", groups.keySet(), true, (com.earth2me.essentials.IEssentials)ess);
|
||||
Util.registerPermissions("essentials.groups", groups.keySet(), true, ess);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
@@ -4,13 +4,28 @@ import com.earth2me.essentials.api.IEssentials;
|
||||
import com.earth2me.essentials.api.ISettings;
|
||||
import com.earth2me.essentials.storage.AsyncStorageObjectHolder;
|
||||
import java.io.File;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
|
||||
public class SettingsHolder extends AsyncStorageObjectHolder<Settings> implements ISettings
|
||||
{
|
||||
private final transient AtomicBoolean debug = new AtomicBoolean(false);
|
||||
public SettingsHolder(final IEssentials ess)
|
||||
{
|
||||
super(ess, Settings.class);
|
||||
onReload();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void onReload()
|
||||
{
|
||||
super.onReload();
|
||||
acquireReadLock();
|
||||
try {
|
||||
debug.set(getData().getGeneral().isDebug());
|
||||
} finally {
|
||||
unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -18,4 +33,32 @@ public class SettingsHolder extends AsyncStorageObjectHolder<Settings> implement
|
||||
{
|
||||
return new File(ess.getDataFolder(), "settings.yml");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLocale()
|
||||
{
|
||||
acquireReadLock();
|
||||
try {
|
||||
return getData().getGeneral().getLocale();
|
||||
} finally {
|
||||
unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDebug()
|
||||
{
|
||||
return debug.get();
|
||||
}
|
||||
|
||||
public void setDebug(final boolean set)
|
||||
{
|
||||
debug.set(set);
|
||||
acquireWriteLock();
|
||||
try {
|
||||
getData().getGeneral().setDebug(set);
|
||||
} finally {
|
||||
unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -49,11 +49,11 @@ public class EssentialsSign
|
||||
}
|
||||
catch (ChargeException ex)
|
||||
{
|
||||
ess.showCommandError(user, signName, ex);
|
||||
ess.getCommandHandler().showCommandError(user, signName, ex);
|
||||
}
|
||||
catch (SignException ex)
|
||||
{
|
||||
ess.showCommandError(user, signName, ex);
|
||||
ess.getCommandHandler().showCommandError(user, signName, ex);
|
||||
}
|
||||
// Return true, so the player sees the wrong sign.
|
||||
return true;
|
||||
@@ -86,12 +86,12 @@ public class EssentialsSign
|
||||
}
|
||||
catch (ChargeException ex)
|
||||
{
|
||||
ess.showCommandError(user,signName, ex);
|
||||
ess.getCommandHandler().showCommandError(user,signName, ex);
|
||||
return false;
|
||||
}
|
||||
catch (SignException ex)
|
||||
{
|
||||
ess.showCommandError(user, signName, ex);
|
||||
ess.getCommandHandler().showCommandError(user, signName, ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -108,7 +108,7 @@ public class EssentialsSign
|
||||
}
|
||||
catch (SignException ex)
|
||||
{
|
||||
ess.showCommandError(user, signName, ex);
|
||||
ess.getCommandHandler().showCommandError(user, signName, ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -137,11 +137,11 @@ public class EssentialsSign
|
||||
}
|
||||
catch (ChargeException ex)
|
||||
{
|
||||
ess.showCommandError(user, signName, ex);
|
||||
ess.getCommandHandler().showCommandError(user, signName, ex);
|
||||
}
|
||||
catch (SignException ex)
|
||||
{
|
||||
ess.showCommandError(user, signName, ex);
|
||||
ess.getCommandHandler().showCommandError(user, signName, ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -155,11 +155,11 @@ public class EssentialsSign
|
||||
}
|
||||
catch (ChargeException ex)
|
||||
{
|
||||
ess.showCommandError(user, signName, ex);
|
||||
ess.getCommandHandler().showCommandError(user, signName, ex);
|
||||
}
|
||||
catch (SignException ex)
|
||||
{
|
||||
ess.showCommandError(user, signName, ex);
|
||||
ess.getCommandHandler().showCommandError(user, signName, ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -173,7 +173,7 @@ public class EssentialsSign
|
||||
}
|
||||
catch (SignException ex)
|
||||
{
|
||||
ess.showCommandError(user, signName, ex);
|
||||
ess.getCommandHandler().showCommandError(user, signName, ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package com.earth2me.essentials.signs;
|
||||
|
||||
import com.earth2me.essentials.IEssentials;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.api.IEssentials;
|
||||
import com.earth2me.essentials.api.IUser;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.Material;
|
||||
@@ -16,7 +16,7 @@ public class SignBlockListener extends BlockListener
|
||||
private final transient IEssentials ess;
|
||||
private final static Logger LOGGER = Logger.getLogger("Minecraft");
|
||||
|
||||
public SignBlockListener(IEssentials ess)
|
||||
public SignBlockListener(final IEssentials ess)
|
||||
{
|
||||
this.ess = ess;
|
||||
}
|
||||
@@ -80,7 +80,7 @@ public class SignBlockListener extends BlockListener
|
||||
{
|
||||
return;
|
||||
}
|
||||
User user = ess.getUser(event.getPlayer());
|
||||
IUser user = ess.getUser(event.getPlayer());
|
||||
if (user.isAuthorized("essentials.signs.color"))
|
||||
{
|
||||
for (int i = 0; i < 4; i++)
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package com.earth2me.essentials.signs;
|
||||
|
||||
import com.earth2me.essentials.IEssentials;
|
||||
import com.earth2me.essentials.api.IEssentials;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.event.entity.EndermanPickupEvent;
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package com.earth2me.essentials.signs;
|
||||
|
||||
import com.earth2me.essentials.IEssentials;
|
||||
import com.earth2me.essentials.api.IEssentials;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Sign;
|
||||
|
@@ -29,7 +29,7 @@ public class SignWarp extends EssentialsSign
|
||||
{
|
||||
try
|
||||
{
|
||||
ess.getWarps2().getWarp(warpName);
|
||||
ess.getWarps().getWarp(warpName);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@@ -1,15 +1,13 @@
|
||||
package com.earth2me.essentials.storage;
|
||||
|
||||
import com.earth2me.essentials.IConf;
|
||||
import com.earth2me.essentials.api.IEssentials;
|
||||
import com.earth2me.essentials.api.IReload;
|
||||
import java.io.File;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
import java.util.logging.Level;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
|
||||
public abstract class AsyncStorageObjectHolder<T extends StorageObject> implements IConf, IStorageObjectHolder<T>, IReload
|
||||
public abstract class AsyncStorageObjectHolder<T extends StorageObject> implements IStorageObjectHolder<T>
|
||||
{
|
||||
private transient T data;
|
||||
private final transient ReentrantReadWriteLock rwl = new ReentrantReadWriteLock();
|
||||
@@ -74,12 +72,6 @@ public abstract class AsyncStorageObjectHolder<T extends StorageObject> implemen
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reloadConfig()
|
||||
{
|
||||
new StorageObjectDataReader();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReload()
|
||||
{
|
||||
|
@@ -1,9 +1,9 @@
|
||||
package com.earth2me.essentials.storage;
|
||||
|
||||
import com.earth2me.essentials.user.UserData;
|
||||
import com.earth2me.essentials.api.IReload;
|
||||
|
||||
|
||||
public interface IStorageObjectHolder<T extends StorageObject>
|
||||
public interface IStorageObjectHolder<T extends StorageObject> extends IReload
|
||||
{
|
||||
T getData();
|
||||
|
||||
|
@@ -35,7 +35,7 @@ public class KeywordReplacer implements IText
|
||||
if (sender instanceof Player)
|
||||
{
|
||||
@Cleanup
|
||||
final IUser user = ess.getUser(sender);
|
||||
final IUser user = ess.getUser((Player)sender);
|
||||
user.acquireReadLock();
|
||||
displayName = user.getDisplayName();
|
||||
ipAddress = user.getAddress().getAddress().toString();
|
||||
|
@@ -21,7 +21,7 @@ public class TextInput implements IText
|
||||
File file = null;
|
||||
if (sender instanceof Player)
|
||||
{
|
||||
final IUser user = ess.getUser(sender);
|
||||
final IUser user = ess.getUser((Player)sender);
|
||||
file = new File(ess.getDataFolder(), filename + "_" + Util.sanitizeFileName(user.getName()) + ".txt");
|
||||
if (!file.exists())
|
||||
{
|
||||
|
@@ -50,13 +50,13 @@ public class User extends UserBase implements IUser
|
||||
public User(final Player base, final IEssentials ess)
|
||||
{
|
||||
super(base, ess);
|
||||
teleport = new Teleport(this, (com.earth2me.essentials.IEssentials)ess);
|
||||
teleport = new Teleport(this, ess);
|
||||
}
|
||||
|
||||
public User(final OfflinePlayer offlinePlayer, final IEssentials ess)
|
||||
{
|
||||
super(offlinePlayer, ess);
|
||||
teleport = new Teleport(this, (com.earth2me.essentials.IEssentials)ess);
|
||||
teleport = new Teleport(this, ess);
|
||||
}
|
||||
|
||||
public void example()
|
||||
@@ -139,10 +139,10 @@ public class User extends UserBase implements IUser
|
||||
try
|
||||
{
|
||||
setMoney(getMoney() + value);
|
||||
sendMessage(_("addedToAccount", Util.formatCurrency(value, (com.earth2me.essentials.IEssentials)ess)));
|
||||
sendMessage(_("addedToAccount", Util.formatCurrency(value, ess)));
|
||||
if (initiator != null)
|
||||
{
|
||||
initiator.sendMessage(_("addedToOthersAccount", Util.formatCurrency(value, (com.earth2me.essentials.IEssentials)ess), this.getDisplayName()));
|
||||
initiator.sendMessage(_("addedToOthersAccount", Util.formatCurrency(value, ess), this.getDisplayName()));
|
||||
}
|
||||
}
|
||||
finally
|
||||
@@ -161,8 +161,8 @@ public class User extends UserBase implements IUser
|
||||
{
|
||||
setMoney(getMoney() - value);
|
||||
reciever.setMoney(reciever.getMoney() + value);
|
||||
sendMessage(_("moneySentTo", Util.formatCurrency(value, (com.earth2me.essentials.IEssentials)ess), reciever.getDisplayName()));
|
||||
reciever.sendMessage(_("moneyRecievedFrom", Util.formatCurrency(value, (com.earth2me.essentials.IEssentials)ess), getDisplayName()));
|
||||
sendMessage(_("moneySentTo", Util.formatCurrency(value, ess), reciever.getDisplayName()));
|
||||
reciever.sendMessage(_("moneyRecievedFrom", Util.formatCurrency(value, ess), getDisplayName()));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -183,10 +183,10 @@ public class User extends UserBase implements IUser
|
||||
return;
|
||||
}
|
||||
setMoney(getMoney() - value);
|
||||
sendMessage(_("takenFromAccount", Util.formatCurrency(value, (com.earth2me.essentials.IEssentials)ess)));
|
||||
sendMessage(_("takenFromAccount", Util.formatCurrency(value, ess)));
|
||||
if (initiator != null)
|
||||
{
|
||||
initiator.sendMessage(_("takenFromOthersAccount", Util.formatCurrency(value, (com.earth2me.essentials.IEssentials)ess), this.getDisplayName()));
|
||||
initiator.sendMessage(_("takenFromOthersAccount", Util.formatCurrency(value, ess), this.getDisplayName()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -2,6 +2,7 @@ package com.earth2me.essentials.user;
|
||||
|
||||
import com.earth2me.essentials.api.IEssentials;
|
||||
import com.earth2me.essentials.Util;
|
||||
import com.earth2me.essentials.api.IUser;
|
||||
import com.earth2me.essentials.api.IUserMap;
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
@@ -57,12 +58,14 @@ public class UserMap extends CacheLoader<String, User> implements IUserMap
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean userExists(final String name)
|
||||
{
|
||||
return keys.contains(name.toLowerCase(Locale.ENGLISH));
|
||||
}
|
||||
|
||||
public User getUser(final String name)
|
||||
@Override
|
||||
public IUser getUser(final String name)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -98,22 +101,26 @@ public class UserMap extends CacheLoader<String, User> implements IUserMap
|
||||
throw new Exception("User not found!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeUser(final String name)
|
||||
{
|
||||
keys.remove(name.toLowerCase(Locale.ENGLISH));
|
||||
users.invalidate(name.toLowerCase(Locale.ENGLISH));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getAllUniqueUsers()
|
||||
{
|
||||
return Collections.unmodifiableSet(keys);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getUniqueUsers()
|
||||
{
|
||||
return keys.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getUserFile(final String name)
|
||||
{
|
||||
final File userFolder = new File(ess.getDataFolder(), "userdata");
|
||||
@@ -125,4 +132,24 @@ public class UserMap extends CacheLoader<String, User> implements IUserMap
|
||||
{
|
||||
loadAllUsersAsync();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IUser getUser(final Player player)
|
||||
{
|
||||
if (player instanceof IUser)
|
||||
{
|
||||
return (IUser)player;
|
||||
}
|
||||
IUser user = getUser(player.getName());
|
||||
|
||||
if (user == null)
|
||||
{
|
||||
user = new User(player, ess);
|
||||
}
|
||||
else
|
||||
{
|
||||
((User)user).update(player);
|
||||
}
|
||||
return user;
|
||||
}
|
||||
}
|
||||
|
@@ -45,7 +45,7 @@ public class EconomyTest extends TestCase
|
||||
assertFalse("NPC does not exists", Economy.playerExists(NPCNAME));
|
||||
assertTrue("Create NPC", Economy.createNPC(NPCNAME));
|
||||
assertTrue("NPC exists", Economy.playerExists(NPCNAME));
|
||||
assertNotNull("NPC can be accessed", ess.getOfflineUser(NPCNAME));
|
||||
assertNotNull("NPC can be accessed", ess.getUser(NPCNAME));
|
||||
try
|
||||
{
|
||||
Economy.removeNPC(NPCNAME);
|
||||
|
@@ -2,6 +2,7 @@ package com.earth2me.essentials;
|
||||
|
||||
import com.earth2me.essentials.craftbukkit.FakeWorld;
|
||||
import com.avaje.ebean.config.ServerConfig;
|
||||
import com.earth2me.essentials.api.IEssentials;
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Callable;
|
||||
|
@@ -5,6 +5,7 @@ import junit.framework.TestCase;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World.Environment;
|
||||
import org.bukkit.plugin.InvalidDescriptionException;
|
||||
import com.earth2me.essentials.api.IUser;
|
||||
|
||||
|
||||
public class UserTest extends TestCase
|
||||
@@ -49,11 +50,11 @@ public class UserTest extends TestCase
|
||||
|
||||
public void testHome()
|
||||
{
|
||||
User user = ess.getUser(base1);
|
||||
IUser user = ess.getUser(base1);
|
||||
Location loc = base1.getLocation();
|
||||
user.setHome();
|
||||
OfflinePlayer base2 = server.createPlayer(base1.getName(), ess);
|
||||
User user2 = ess.getUser(base2);
|
||||
IUser user2 = ess.getUser(base2);
|
||||
|
||||
Location home = user2.getHome(loc);
|
||||
assertNotNull(home);
|
||||
@@ -68,7 +69,7 @@ public class UserTest extends TestCase
|
||||
public void testMoney()
|
||||
{
|
||||
should("properly set, take, give, and get money");
|
||||
User user = ess.getUser(base1);
|
||||
IUser user = ess.getUser(base1);
|
||||
double i;
|
||||
user.setMoney(i = 100.5);
|
||||
user.takeMoney(50);
|
||||
@@ -81,7 +82,7 @@ public class UserTest extends TestCase
|
||||
public void testGetGroup()
|
||||
{
|
||||
should("return the default group");
|
||||
User user = ess.getUser(base1);
|
||||
IUser user = ess.getUser(base1);
|
||||
assertEquals(user.getGroup(), "default");
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user