1
0
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:
snowleo
2011-12-12 22:31:19 +01:00
parent ecf72e27bb
commit 6e79302908
71 changed files with 579 additions and 620 deletions

View File

@@ -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;
}
}

View File

@@ -19,14 +19,14 @@ package com.earth2me.essentials;
import static com.earth2me.essentials.I18n._; import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.api.*; import com.earth2me.essentials.api.*;
import com.earth2me.essentials.commands.EssentialsCommand; import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.commands.IEssentialsCommand; import com.earth2me.essentials.api.ISettings;
import com.earth2me.essentials.commands.NoChargeException; import com.earth2me.essentials.user.UserMap;
import com.earth2me.essentials.commands.NotEnoughArgumentsException;
import com.earth2me.essentials.craftbukkit.ItemDupeFix; import com.earth2me.essentials.craftbukkit.ItemDupeFix;
import com.earth2me.essentials.listener.*; import com.earth2me.essentials.listener.*;
import com.earth2me.essentials.perm.PermissionsHandler; import com.earth2me.essentials.perm.PermissionsHandler;
import com.earth2me.essentials.register.payment.Methods; import com.earth2me.essentials.register.payment.Methods;
import com.earth2me.essentials.settings.SettingsHolder;
import com.earth2me.essentials.signs.SignBlockListener; import com.earth2me.essentials.signs.SignBlockListener;
import com.earth2me.essentials.signs.SignEntityListener; import com.earth2me.essentials.signs.SignEntityListener;
import com.earth2me.essentials.signs.SignPlayerListener; import com.earth2me.essentials.signs.SignPlayerListener;
@@ -43,7 +43,6 @@ import org.bukkit.Server;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginCommand;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Event.Priority; import org.bukkit.event.Event.Priority;
import org.bukkit.event.Event.Type; import org.bukkit.event.Event.Type;
@@ -54,7 +53,6 @@ import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitScheduler;
import org.yaml.snakeyaml.error.YAMLException; 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 static final Logger LOGGER = Logger.getLogger("Minecraft");
private transient ISettings settings; private transient ISettings settings;
private final transient TNTExplodeListener tntListener = new TNTExplodeListener(this); private final transient TNTExplodeListener tntListener = new TNTExplodeListener(this);
private transient Jails jails; private transient IJails jails;
private transient Warps warps; private transient IWarps warps;
private transient Worth worth; private transient IWorth worth;
private transient List<IConf> confList; private transient List<IReload> reloadList;
private transient Backup backup; private transient IBackup backup;
private transient ItemDb itemDb; private transient IItemDb itemDb;
private transient final Methods paymentMethod = new Methods(); private transient final Methods paymentMethod = new Methods();
private transient PermissionsHandler permissionsHandler; private transient PermissionsHandler permissionsHandler;
private transient AlternativeCommandsHandler alternativeCommandsHandler; private transient IUserMap userMap;
private transient UserMap userMap;
private transient ExecuteTimer execTimer; private transient ExecuteTimer execTimer;
private transient I18n i18n; private transient I18n i18n;
private transient ICommandHandler commandHandler;
@Override @Override
public ISettings getSettings() public ISettings getSettings()
@@ -147,24 +145,26 @@ public class Essentials extends JavaPlugin implements IEssentials
final EssentialsUpgrade upgrade = new EssentialsUpgrade(this); final EssentialsUpgrade upgrade = new EssentialsUpgrade(this);
upgrade.beforeSettings(); upgrade.beforeSettings();
execTimer.mark("Upgrade"); execTimer.mark("Upgrade");
confList = new ArrayList<IConf>(); reloadList = new ArrayList<IReload>();
settings = new Settings(this); settings = new SettingsHolder(this);
confList.add(settings); reloadList.add(settings);
execTimer.mark("Settings"); execTimer.mark("Settings");
upgrade.afterSettings(); upgrade.afterSettings();
execTimer.mark("Upgrade2"); execTimer.mark("Upgrade2");
i18n.updateLocale(settings.getLocale()); i18n.updateLocale(settings.getLocale());
userMap = new UserMap(this); userMap = new UserMap(this);
confList.add(userMap); reloadList.add(userMap);
execTimer.mark("Init(Usermap)"); execTimer.mark("Init(Usermap)");
warps = new Warps(getServer(), this.getDataFolder()); warps = new Warps(getServer(), this.getDataFolder());
confList.add(warps); reloadList.add(warps);
execTimer.mark("Init(Spawn/Warp)"); execTimer.mark("Init(Spawn/Warp)");
worth = new Worth(this.getDataFolder()); worth = new Worth(this.getDataFolder());
confList.add(worth); reloadList.add(worth);
itemDb = new ItemDb(this); itemDb = new ItemDb(this);
confList.add(itemDb); reloadList.add(itemDb);
execTimer.mark("Init(Worth/ItemDB)"); execTimer.mark("Init(Worth/ItemDB)");
commandHandler = new EssentialsCommandHandler(Essentials.class.getClassLoader(), "com.earth2me.essentials.commands.Command", "essentials.", this);
reloadList.add(commandHandler);
reload(); reload();
} }
catch (YAMLException exception) catch (YAMLException exception)
@@ -194,12 +194,11 @@ public class Essentials extends JavaPlugin implements IEssentials
return; return;
} }
backup = new Backup(this); backup = new Backup(this);
permissionsHandler = new PermissionsHandler(this, settings.useBukkitPermissions()); permissionsHandler = new PermissionsHandler(this);
alternativeCommandsHandler = new AlternativeCommandsHandler(this);
final EssentialsPluginListener serverListener = new EssentialsPluginListener(this); final EssentialsPluginListener serverListener = new EssentialsPluginListener(this);
pm.registerEvent(Type.PLUGIN_ENABLE, serverListener, Priority.Low, this); pm.registerEvent(Type.PLUGIN_ENABLE, serverListener, Priority.Low, this);
pm.registerEvent(Type.PLUGIN_DISABLE, 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); final EssentialsPlayerListener playerListener = new EssentialsPlayerListener(this);
pm.registerEvent(Type.PLAYER_JOIN, playerListener, Priority.Monitor, 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() //TODO: Check if this should be here, and not above before reload()
jails = new Jails(this); jails = new Jails(this);
confList.add(jails); reloadList.add(jails);
pm.registerEvent(Type.ENTITY_EXPLODE, tntListener, Priority.High, this); pm.registerEvent(Type.ENTITY_EXPLODE, tntListener, Priority.High, this);
final EssentialsTimer timer = new EssentialsTimer(this); final EssentialsTimer timer = new EssentialsTimer(this);
getScheduler().scheduleSyncRepeatingTask(this, timer, 1, 100); getServer().getScheduler().scheduleSyncRepeatingTask(this, timer, 1, 100);
Economy.setEss(this); Economy.setEss(this);
execTimer.mark("RegListeners"); execTimer.mark("RegListeners");
LOGGER.info(_("loadinfo", this.getDescription().getName(), this.getDescription().getVersion(), Util.joinList(this.getDescription().getAuthors()))); 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(); Trade.closeLog();
for (IConf iConf : confList) for (IReload iReload : reloadList)
{ {
iConf.reloadConfig(); iReload.onReload();
execTimer.mark("Reload(" + iConf.getClass().getSimpleName() + ")"); execTimer.mark("Reload(" + iReload.getClass().getSimpleName() + ")");
} }
i18n.updateLocale(settings.getLocale()); i18n.updateLocale(settings.getLocale());
@@ -286,132 +285,8 @@ public class Essentials extends JavaPlugin implements IEssentials
@Override @Override
public boolean onCommand(final CommandSender sender, final Command command, final String commandLabel, final String[] args) 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); return commandHandler.handleCommand(sender, command, commandLabel, 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();
} }
@Override @Override
@@ -421,65 +296,31 @@ public class Essentials extends JavaPlugin implements IEssentials
} }
@Override @Override
public Warps getWarps() public IWarps getWarps()
{ {
return warps; return warps;
} }
@Override @Override
public Worth getWorth() public IWorth getWorth()
{ {
return worth; return worth;
} }
@Override @Override
public Backup getBackup() public IBackup getBackup()
{ {
return backup; return backup;
} }
@Override public IUser getUser(final Player player)
public User getUser(final Object base)
{ {
if (base instanceof Player) return userMap.getUser(player);
{
return getUser((Player)base);
}
if (base instanceof String)
{
return userMap.getUser((String)base);
}
return null;
} }
private <T extends Player> User getUser(final T base) public IUser getUser(final String playerName)
{ {
if (base == null) return userMap.getUser(playerName);
{
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);
} }
@Override @Override
@@ -497,9 +338,9 @@ public class Essentials extends JavaPlugin implements IEssentials
} }
@Override @Override
public void addReloadListener(final IConf listener) public void addReloadListener(final IReload listener)
{ {
confList.add(listener); reloadList.add(listener);
} }
@Override @Override
@@ -523,8 +364,8 @@ public class Essentials extends JavaPlugin implements IEssentials
for (Player player : players) for (Player player : players)
{ {
final User user = getUser(player); final IUser user = getUser(player);
if (!user.isIgnoredPlayer(sender.getName())) if (!user.isIgnoringPlayer(sender.getName()))
{ {
player.sendMessage(message); player.sendMessage(message);
} }
@@ -536,25 +377,25 @@ public class Essentials extends JavaPlugin implements IEssentials
@Override @Override
public int scheduleAsyncDelayedTask(final Runnable run) public int scheduleAsyncDelayedTask(final Runnable run)
{ {
return this.getScheduler().scheduleAsyncDelayedTask(this, run); return this.getServer().getScheduler().scheduleAsyncDelayedTask(this, run);
} }
@Override @Override
public int scheduleSyncDelayedTask(final Runnable run) public int scheduleSyncDelayedTask(final Runnable run)
{ {
return this.getScheduler().scheduleSyncDelayedTask(this, run); return this.getServer().getScheduler().scheduleSyncDelayedTask(this, run);
} }
@Override @Override
public int scheduleSyncDelayedTask(final Runnable run, final long delay) 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 @Override
public int scheduleSyncRepeatingTask(final Runnable run, final long delay, final long period) 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 @Override
@@ -570,19 +411,13 @@ public class Essentials extends JavaPlugin implements IEssentials
} }
@Override @Override
public AlternativeCommandsHandler getAlternativeCommandsHandler() public IItemDb getItemDb()
{
return alternativeCommandsHandler;
}
@Override
public ItemDb getItemDb()
{ {
return itemDb; return itemDb;
} }
@Override @Override
public UserMap getUserMap() public IUserMap getUserMap()
{ {
return userMap; return userMap;
} }
@@ -593,30 +428,12 @@ public class Essentials extends JavaPlugin implements IEssentials
return i18n; 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 @Override
public IGroups getGroups() public IGroups getGroups()
{ {
throw new UnsupportedOperationException("Not supported yet."); throw new UnsupportedOperationException("Not supported yet.");
} }
@Override
public IWarps getWarps2()
{
throw new UnsupportedOperationException("Not supported yet.");
}
@Override @Override
public IEssentialsEconomy getEconomy() public IEssentialsEconomy getEconomy()
{ {
@@ -624,14 +441,8 @@ public class Essentials extends JavaPlugin implements IEssentials
} }
@Override @Override
public void showCommandError(CommandSender sender, String commandLabel, Throwable exception) public ICommandHandler getCommandHandler()
{ {
throw new UnsupportedOperationException("Not supported yet."); return commandHandler;
}
@Override
public void onReload()
{
throw new UnsupportedOperationException("Not supported yet.");
} }
} }

View File

@@ -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;
}
}

View File

@@ -4,6 +4,7 @@ import com.earth2me.essentials.craftbukkit.FakeWorld;
import com.earth2me.essentials.settings.Spawns; import com.earth2me.essentials.settings.Spawns;
import com.earth2me.essentials.storage.YamlStorageWriter; import com.earth2me.essentials.storage.YamlStorageWriter;
import static com.earth2me.essentials.I18n._; import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.api.IEssentials;
import java.io.*; import java.io.*;
import java.math.BigInteger; import java.math.BigInteger;
import java.security.DigestInputStream; import java.security.DigestInputStream;

View File

@@ -1,5 +1,6 @@
package com.earth2me.essentials; package com.earth2me.essentials;
import com.earth2me.essentials.api.IEssentials;
import com.earth2me.essentials.api.II18n; import com.earth2me.essentials.api.II18n;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;

View File

@@ -1,9 +0,0 @@
package com.earth2me.essentials;
/**
* @deprecated New interface will be IReload in api package
*/
@Deprecated
public interface IConf {
public void reloadConfig();
}

View File

@@ -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();
}

View File

@@ -1,6 +0,0 @@
package com.earth2me.essentials;
@Deprecated
public interface IEssentialsModule
{
}

View File

@@ -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();
}

View File

@@ -8,7 +8,7 @@ import org.bukkit.ChatColor;
import org.bukkit.event.Event.Priority; import org.bukkit.event.Event.Priority;
@Deprecated @Deprecated
public interface ISettings extends IConf, com.earth2me.essentials.api.ISettings public interface ISettings extends com.earth2me.essentials.api.ISettings
{ {
boolean areSignsDisabled(); boolean areSignsDisabled();

View File

@@ -11,7 +11,7 @@ import org.bukkit.Material;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
public class ItemDb implements IConf, IItemDb public class ItemDb implements IItemDb
{ {
private final transient IEssentials ess; private final transient IEssentials ess;
@@ -120,10 +120,4 @@ public class ItemDb implements IConf, IItemDb
retval.setDurability(metaData); retval.setDurability(metaData);
return retval; return retval;
} }
@Override
public void reloadConfig()
{
onReload();
}
} }

View File

@@ -27,7 +27,7 @@ public class Jails extends AsyncStorageObjectHolder<com.earth2me.essentials.sett
public Jails(final IEssentials ess) public Jails(final IEssentials ess)
{ {
super(ess, com.earth2me.essentials.settings.Jails.class); super(ess, com.earth2me.essentials.settings.Jails.class);
reloadConfig(); onReload();
registerListeners(); registerListeners();
} }

View File

@@ -118,7 +118,7 @@ public class Teleport implements Runnable, ITeleport
} }
catch (Throwable ex) catch (Throwable ex)
{ {
ess.showCommandError(user.getBase(), "teleport", ex); ess.getCommandHandler().showCommandError(user.getBase(), "teleport", ex);
} }
} }
catch (Exception 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 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); teleport(new Target(loc), chargeFor, cause);
user.sendMessage(_("warpingTo", warp)); user.sendMessage(_("warpingTo", warp));
} }

View File

@@ -21,7 +21,7 @@ import org.bukkit.permissions.PermissionDefault;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
public class Util public final class Util
{ {
private Util() private Util()
{ {

View File

@@ -1,5 +1,6 @@
package com.earth2me.essentials; package com.earth2me.essentials;
import com.earth2me.essentials.api.IWarps;
import static com.earth2me.essentials.I18n._; import static com.earth2me.essentials.I18n._;
import java.io.File; import java.io.File;
import java.util.*; import java.util.*;
@@ -9,7 +10,7 @@ import org.bukkit.Location;
import org.bukkit.Server; import org.bukkit.Server;
public class Warps implements IConf public class Warps implements IWarps
{ {
private static final Logger logger = Logger.getLogger("Minecraft"); private static final Logger logger = Logger.getLogger("Minecraft");
private final Map<StringIgnoreCase, EssentialsConf> warpPoints = new HashMap<StringIgnoreCase, EssentialsConf>(); private final Map<StringIgnoreCase, EssentialsConf> warpPoints = new HashMap<StringIgnoreCase, EssentialsConf>();

View File

@@ -7,7 +7,7 @@ import java.util.logging.Logger;
import org.bukkit.inventory.ItemStack; 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 static final Logger logger = Logger.getLogger("Minecraft");
private final EssentialsConf config; private final EssentialsConf config;
@@ -55,14 +55,8 @@ public class Worth implements IConf, IWorth
} }
@Override @Override
public void reloadConfig() public void onReload()
{ {
config.load(); config.load();
} }
@Override
public void onReload()
{
reloadConfig();
}
} }

View File

@@ -2,8 +2,6 @@ package com.earth2me.essentials.api;
import com.earth2me.essentials.EssentialsConf; import com.earth2me.essentials.EssentialsConf;
import static com.earth2me.essentials.I18n._; import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.IEssentials;
import com.earth2me.essentials.User;
import com.earth2me.essentials.Util; import com.earth2me.essentials.Util;
import java.io.File; import java.io.File;
import java.util.logging.Level; 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) if (ess == null)
{ {
throw new RuntimeException(noCallBeforeLoad); throw new RuntimeException(noCallBeforeLoad);
} }
User user; IUser user;
Player player = ess.getServer().getPlayer(name); Player player = ess.getServer().getPlayer(name);
if (player != null) if (player != null)
{ {
@@ -93,7 +91,7 @@ public final class Economy
*/ */
public static double getMoney(String name) throws UserDoesNotExistException public static double getMoney(String name) throws UserDoesNotExistException
{ {
User user = getUserByName(name); IUser user = getUserByName(name);
if (user == null) if (user == null)
{ {
throw new UserDoesNotExistException(name); throw new UserDoesNotExistException(name);
@@ -110,7 +108,7 @@ public final class Economy
*/ */
public static void setMoney(String name, double balance) throws UserDoesNotExistException, NoLoanPermittedException public static void setMoney(String name, double balance) throws UserDoesNotExistException, NoLoanPermittedException
{ {
User user = getUserByName(name); IUser user = getUserByName(name);
if (user == null) if (user == null)
{ {
throw new UserDoesNotExistException(name); throw new UserDoesNotExistException(name);
@@ -266,7 +264,7 @@ public final class Economy
*/ */
public static boolean isNPC(String name) throws UserDoesNotExistException public static boolean isNPC(String name) throws UserDoesNotExistException
{ {
User user = getUserByName(name); IUser user = getUserByName(name);
if (user == null) if (user == null)
{ {
throw new UserDoesNotExistException(name); throw new UserDoesNotExistException(name);
@@ -281,7 +279,7 @@ public final class Economy
*/ */
public static boolean createNPC(String name) public static boolean createNPC(String name)
{ {
User user = getUserByName(name); IUser user = getUserByName(name);
if (user == null) if (user == null)
{ {
createNPCFile(name); createNPCFile(name);
@@ -297,7 +295,7 @@ public final class Economy
*/ */
public static void removeNPC(String name) throws UserDoesNotExistException public static void removeNPC(String name) throws UserDoesNotExistException
{ {
User user = getUserByName(name); IUser user = getUserByName(name);
if (user == null) if (user == null)
{ {
throw new UserDoesNotExistException(name); throw new UserDoesNotExistException(name);

View File

@@ -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);
}

View File

@@ -4,15 +4,19 @@ import com.earth2me.essentials.listener.TNTExplodeListener;
import com.earth2me.essentials.perm.IPermissionsHandler; import com.earth2me.essentials.perm.IPermissionsHandler;
import com.earth2me.essentials.register.payment.Methods; import com.earth2me.essentials.register.payment.Methods;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
public interface IEssentials extends Plugin, IReload public interface IEssentials extends Plugin
{ {
void addReloadListener(IReload listener); void addReloadListener(IReload listener);
IUser getUser(Object base); IUser getUser(Player player);
IUser getUser(String playerName);
int broadcastMessage(IUser sender, String message); int broadcastMessage(IUser sender, String message);
@@ -24,7 +28,7 @@ public interface IEssentials extends Plugin, IReload
IJails getJails(); IJails getJails();
IWarps getWarps2(); IWarps getWarps();
IWorth getWorth(); IWorth getWorth();
@@ -36,6 +40,8 @@ public interface IEssentials extends Plugin, IReload
IEssentialsEconomy getEconomy(); IEssentialsEconomy getEconomy();
ICommandHandler getCommandHandler();
World getWorld(String name); World getWorld(String name);
Methods getPaymentMethod(); Methods getPaymentMethod();
@@ -50,13 +56,7 @@ public interface IEssentials extends Plugin, IReload
IPermissionsHandler getPermissionsHandler(); IPermissionsHandler getPermissionsHandler();
IAlternativeCommandsHandler getAlternativeCommandsHandler(); void reload();
void showCommandError(CommandSender sender, String commandLabel, Throwable exception); TNTExplodeListener getTNTListener();
public void reload();
public IUser getOfflineUser(String string);
public TNTExplodeListener getTNTListener();
} }

View File

@@ -7,4 +7,10 @@ import com.earth2me.essentials.storage.IStorageObjectHolder;
public interface ISettings extends IStorageObjectHolder<Settings> public interface ISettings extends IStorageObjectHolder<Settings>
{ {
public String getLocale();
public boolean isDebug();
public void setDebug(boolean b);
} }

View File

@@ -2,13 +2,16 @@ package com.earth2me.essentials.api;
import java.io.File; import java.io.File;
import java.util.Set; import java.util.Set;
import org.bukkit.entity.Player;
public interface IUserMap extends IReload public interface IUserMap extends IReload
{ {
boolean userExists(final String name); 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); void removeUser(final String name);

View File

@@ -1,9 +1,9 @@
package com.earth2me.essentials.commands; package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._; import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.User;
import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.api.IUser;
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.entity.Player;
public class Commandafk extends EssentialsCommand public class Commandafk extends EssentialsCommand
@@ -18,7 +18,7 @@ public class Commandafk extends EssentialsCommand
{ {
if (args.length > 0 && user.isAuthorized("essentials.afk.others")) 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) if (afkUser != null)
{ {
toggleAfk(afkUser); toggleAfk(afkUser);

View File

@@ -30,7 +30,7 @@ public class Commandban extends EssentialsCommand
if (user.getBase() instanceof OfflinePlayer) if (user.getBase() instanceof OfflinePlayer)
{ {
if (sender instanceof Player if (sender instanceof Player
&& !ess.getUser(sender).isAuthorized("essentials.ban.offline")) && !ess.getUser((Player)sender).isAuthorized("essentials.ban.offline"))
{ {
sender.sendMessage(_("banExempt")); sender.sendMessage(_("banExempt"));
return; return;

View File

@@ -6,6 +6,7 @@ import java.util.Locale;
import lombok.Cleanup; import lombok.Cleanup;
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class Commanddelhome extends EssentialsCommand public class Commanddelhome extends EssentialsCommand
@@ -24,7 +25,7 @@ public class Commanddelhome extends EssentialsCommand
} }
@Cleanup @Cleanup
IUser user = ess.getUser(sender); IUser user = sender instanceof Player ? ess.getUser((Player)sender) : null;
String name; String name;
final String[] expandedArg = args[0].split(":"); final String[] expandedArg = args[0].split(":");

View File

@@ -19,7 +19,7 @@ public class Commanddelwarp extends EssentialsCommand
{ {
throw new NotEnoughArgumentsException(); throw new NotEnoughArgumentsException();
} }
ess.getWarps2().removeWarp(args[0]); ess.getWarps().removeWarp(args[0]);
sender.sendMessage(_("deleteWarp", args[0])); sender.sendMessage(_("deleteWarp", args[0]));
} }
} }

View File

@@ -47,7 +47,7 @@ public class Commandessentials extends EssentialsCommand
sender.sendMessage("/<command> <reload/debug>"); sender.sendMessage("/<command> <reload/debug>");
sender.sendMessage(_("blockList")); sender.sendMessage(_("blockList"));
final StringBuilder disabledCommands = new StringBuilder(); 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) { if (disabledCommands.length() > 0) {
disabledCommands.append(", "); 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 private void run_debug(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
{ {
@Cleanup ess.getSettings().setDebug(!ess.getSettings().isDebug());
ISettings settings = ess.getSettings(); sender.sendMessage("Essentials " + ess.getDescription().getVersion() + " debug mode " + (ess.getSettings().isDebug() ? "enabled" : "disabled"));
settings.acquireWriteLock();
settings.getData().getGeneral().setDebug(!settings.getData().getGeneral().isDebug());
sender.sendMessage("Essentials " + ess.getDescription().getVersion() + " debug mode " + (settings.getData().getGeneral().isDebug() ? "enabled" : "disabled"));
} }
private void run_reload(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception private void run_reload(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception

View File

@@ -26,7 +26,7 @@ public class Commandignore extends EssentialsCommand
} }
catch (NoSuchFieldException ex) catch (NoSuchFieldException ex)
{ {
player = ess.getOfflineUser(args[0]); player = ess.getUser(args[0]);
} }
if (player == null) if (player == null)
{ {

View File

@@ -3,6 +3,7 @@ package com.earth2me.essentials.commands;
import com.earth2me.essentials.craftbukkit.InventoryWorkaround; import com.earth2me.essentials.craftbukkit.InventoryWorkaround;
import static com.earth2me.essentials.I18n._; import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.User; import com.earth2me.essentials.User;
import com.earth2me.essentials.api.IUser;
import java.util.Locale; import java.util.Locale;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.Server; import org.bukkit.Server;
@@ -18,7 +19,7 @@ public class Commanditem extends EssentialsCommand
} }
@Override @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) if (args.length < 1)
{ {

View File

@@ -21,7 +21,7 @@ public class Commandlist extends EssentialsCommand
boolean showhidden = false; boolean showhidden = false;
if (sender instanceof Player) if (sender instanceof Player)
{ {
if (ess.getUser(sender).isAuthorized("essentials.list.hidden")) if (ess.getUser((Player)sender).isAuthorized("essentials.list.hidden"))
{ {
showhidden = true; showhidden = true;
} }

View File

@@ -49,7 +49,7 @@ public class Commandmail extends EssentialsCommand
} }
else else
{ {
u = ess.getOfflineUser(args[1]); u = ess.getUser(args[1]);
} }
if (u == null) if (u == null)
{ {
@@ -103,7 +103,7 @@ public class Commandmail extends EssentialsCommand
} }
else else
{ {
u = ess.getOfflineUser(args[1]); u = ess.getUser(args[1]);
} }
if (u == null) if (u == null)
{ {
@@ -128,7 +128,7 @@ public class Commandmail extends EssentialsCommand
} }
else else
{ {
u = ess.getOfflineUser(args[0]); u = ess.getUser(args[0]);
} }
if (u == null) if (u == null)
{ {

View File

@@ -29,7 +29,7 @@ public class Commandmsg extends EssentialsCommand
if (sender instanceof Player) if (sender instanceof Player)
{ {
@Cleanup @Cleanup
IUser user = ess.getUser(sender); IUser user = ess.getUser((Player)sender);
user.acquireReadLock(); user.acquireReadLock();
if (user.getData().isMuted()) if (user.getData().isMuted())
{ {

View File

@@ -45,7 +45,7 @@ public class Commandptime extends EssentialsCommand
return; 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")) if ((!users.contains(user) || users.size() > 1) && user != null && !user.isAuthorized("essentials.ptime.others"))
{ {
user.sendMessage(_("pTimeOthersPermission")); 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 there is no selector we want the sender itself. Or all users if sender isn't a user.
if (selector == null) if (selector == null)
{ {
final IUser user = ess.getUser(sender); final IUser user = sender instanceof Player ? ess.getUser((Player)sender) : null;
if (user == null) if (user == null)
{ {
for (Player player : server.getOnlinePlayers()) for (Player player : server.getOnlinePlayers())

View File

@@ -38,7 +38,7 @@ public class Commandr extends EssentialsCommand
sender.sendMessage(_("msgFormat", _("me"), targetName, message)); sender.sendMessage(_("msgFormat", _("me"), targetName, message));
if (target instanceof Player) 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)) if (player.isIgnoringPlayer(sender instanceof Player ? ((Player)sender).getName() : Console.NAME))
{ {
return; return;

View File

@@ -29,7 +29,7 @@ public class Commandseen extends EssentialsCommand
} }
catch (NoSuchFieldException e) catch (NoSuchFieldException e)
{ {
IUser u = ess.getOfflineUser(args[0]); IUser u = ess.getUser(args[0]);
if (u == null) if (u == null)
{ {
throw new Exception(_("playerNotFound")); throw new Exception(_("playerNotFound"));

View File

@@ -22,7 +22,7 @@ public class Commandsetwarp extends EssentialsCommand
} }
final Location loc = user.getLocation(); final Location loc = user.getLocation();
ess.getWarps2().setWarp(args[0], loc); ess.getWarps().setWarp(args[0], loc);
user.sendMessage(_("warpSet", args[0])); user.sendMessage(_("warpSet", args[0]));
} }
} }

View File

@@ -29,7 +29,7 @@ public class Commandtempban extends EssentialsCommand
if (user.getBase() instanceof OfflinePlayer) if (user.getBase() instanceof OfflinePlayer)
{ {
if (sender instanceof Player if (sender instanceof Player
&& !ess.getUser(sender).isAuthorized("essentials.tempban.offline")) && !ess.getUser((Player)sender).isAuthorized("essentials.tempban.offline"))
{ {
sender.sendMessage(_("tempbanExempt")); sender.sendMessage(_("tempbanExempt"));
return; return;

View File

@@ -7,6 +7,7 @@ import java.util.*;
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class Commandtime extends EssentialsCommand public class Commandtime extends EssentialsCommand
@@ -34,7 +35,7 @@ public class Commandtime extends EssentialsCommand
return; 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")) if (user != null && !user.isAuthorized("essentials.time.set"))
{ {
user.sendMessage(_("timeSetPermission")); 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 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) if (selector == null)
{ {
final IUser user = ess.getUser(sender); final IUser user = sender instanceof Player ? ess.getUser((Player)sender) : null;
if (user == null) if (user == null)
{ {
worlds.addAll(server.getWorlds()); worlds.addAll(server.getWorlds());

View File

@@ -35,7 +35,7 @@ public class Commandtogglejail extends EssentialsCommand
if (player.getBase() instanceof OfflinePlayer) if (player.getBase() instanceof OfflinePlayer)
{ {
if (sender instanceof Player if (sender instanceof Player
&& !ess.getUser(sender).isAuthorized("essentials.togglejail.offline")) && !ess.getUser((Player)sender).isAuthorized("essentials.togglejail.offline"))
{ {
sender.sendMessage(_("mayNotJail")); sender.sendMessage(_("mayNotJail"));
return; return;

View File

@@ -73,7 +73,7 @@ public class Commandwarp extends EssentialsCommand
//TODO: Use one of the new text classes, like /help ? //TODO: Use one of the new text classes, like /help ?
private void warpList(final CommandSender sender, final String[] args) throws Exception private void warpList(final CommandSender sender, final String[] args) throws Exception
{ {
final IWarps warps = ess.getWarps2(); final IWarps warps = ess.getWarps();
if (warps.isEmpty()) if (warps.isEmpty())
{ {
throw new Exception(_("noWarpsDefined")); throw new Exception(_("noWarpsDefined"));

View File

@@ -28,7 +28,7 @@ public class Commandwhois extends EssentialsCommand
boolean showhidden = false; boolean showhidden = false;
if (sender instanceof Player) if (sender instanceof Player)
{ {
if (ess.getUser(sender).isAuthorized("essentials.list.hidden")) if (ess.getUser((Player)sender).isAuthorized("essentials.list.hidden"))
{ {
showhidden = true; showhidden = true;
} }
@@ -76,7 +76,7 @@ public class Commandwhois extends EssentialsCommand
sender.sendMessage(_("whoisIPAddress", user.getAddress().getAddress().toString())); sender.sendMessage(_("whoisIPAddress", user.getAddress().getAddress().toString()));
final String location = user.getData().getGeolocation(); final String location = user.getData().getGeolocation();
if (location != null 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)); sender.sendMessage(_("whoisGeoLocation", location));
} }

View File

@@ -92,7 +92,7 @@ public abstract class EssentialsCommand implements IEssentialsCommand
@Override @Override
public final void run(final Server server, final IUser user, final String commandLabel, final Command cmd, final String[] args) throws Exception 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); charge.isAffordableFor(user);
run(server, user, commandLabel, args); run(server, user, commandLabel, args);
charge.charge(user); charge.charge(user);

View File

@@ -1,6 +1,6 @@
package com.earth2me.essentials.craftbukkit; 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.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import net.minecraft.server.NBTTagCompound; import net.minecraft.server.NBTTagCompound;

View File

@@ -36,7 +36,7 @@ public class EssentialsEntityListener extends EntityListener
if (eDefend instanceof Player && eAttack instanceof Player) if (eDefend instanceof Player && eAttack instanceof Player)
{ {
@Cleanup @Cleanup
final IUser attacker = ess.getUser(eAttack); final IUser attacker = ess.getUser((Player)eAttack);
attacker.acquireReadLock(); attacker.acquireReadLock();
attacker.updateActivity(true); attacker.updateActivity(true);
final ItemStack itemstack = attacker.getItemInHand(); final ItemStack itemstack = attacker.getItemInHand();
@@ -48,7 +48,7 @@ public class EssentialsEntityListener extends EntityListener
if (command != null && !command.isEmpty()) 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())); attacker.getServer().dispatchCommand(attacker, command.replaceAll("\\{player\\}", defender.getName()));
event.setCancelled(true); event.setCancelled(true);
return; return;
@@ -58,7 +58,7 @@ public class EssentialsEntityListener extends EntityListener
} }
if (eDefend instanceof Animals && eAttack instanceof Player) 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(); final ItemStack hand = player.getItemInHand();
if (hand != null && hand.getType() == Material.MILK_BUCKET) 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(); final Player player = (Player)event.getEntity();
player.setFireTicks(0); player.setFireTicks(0);
@@ -82,7 +82,7 @@ public class EssentialsEntityListener extends EntityListener
@Override @Override
public void onEntityCombust(final EntityCombustEvent event) 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); event.setCancelled(true);
} }
@@ -94,7 +94,7 @@ public class EssentialsEntityListener extends EntityListener
if (event instanceof PlayerDeathEvent) if (event instanceof PlayerDeathEvent)
{ {
final PlayerDeathEvent pdevent = (PlayerDeathEvent)event; final PlayerDeathEvent pdevent = (PlayerDeathEvent)event;
final IUser user = ess.getUser(pdevent.getEntity()); final IUser user = ess.getUser((Player)pdevent.getEntity());
@Cleanup @Cleanup
final ISettings settings = ess.getSettings(); final ISettings settings = ess.getSettings();
settings.acquireReadLock(); settings.acquireReadLock();
@@ -113,7 +113,7 @@ public class EssentialsEntityListener extends EntityListener
@Override @Override
public void onFoodLevelChange(final FoodLevelChangeEvent event) 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); event.setCancelled(true);
} }
@@ -129,7 +129,7 @@ public class EssentialsEntityListener extends EntityListener
final ISettings settings = ess.getSettings(); final ISettings settings = ess.getSettings();
settings.acquireReadLock(); settings.acquireReadLock();
@Cleanup @Cleanup
final IUser user = ess.getUser(event.getEntity()); final IUser user = ess.getUser((Player)event.getEntity());
user.acquireReadLock(); user.acquireReadLock();
if (user.getData().isAfk() && settings.getData().getCommands().getAfk().isFreezeAFKPlayers()) if (user.getData().isAfk() && settings.getData().getCommands().getAfk().isFreezeAFKPlayers())
{ {

View File

@@ -162,8 +162,8 @@ public class EssentialsPlayerListener extends PlayerListener
{ {
try try
{ {
final IText input = new TextInput(user, "motd", true, (com.earth2me.essentials.IEssentials)ess); final IText input = new TextInput(user, "motd", true, ess);
final IText output = new KeywordReplacer(input, user, (com.earth2me.essentials.IEssentials)ess); final IText output = new KeywordReplacer(input, user, ess);
final TextPager pager = new TextPager(output, true); final TextPager pager = new TextPager(output, true);
pager.showPage("1", null, "motd", user); pager.showPage("1", null, "motd", user);
} }

View File

@@ -1,18 +1,15 @@
package com.earth2me.essentials.listener; package com.earth2me.essentials.listener;
import com.earth2me.essentials.IConf;
import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.api.IEssentials;
import com.earth2me.essentials.api.IReload; import com.earth2me.essentials.api.IReload;
import com.earth2me.essentials.api.ISettings;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import lombok.Cleanup;
import org.bukkit.event.server.PluginDisableEvent; import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.event.server.PluginEnableEvent;
import org.bukkit.event.server.ServerListener; 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 final transient IEssentials ess;
private static final Logger LOGGER = Logger.getLogger("Minecraft"); 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) public void onPluginEnable(final PluginEnableEvent event)
{ {
ess.getPermissionsHandler().checkPermissions(); ess.getPermissionsHandler().checkPermissions();
ess.getAlternativeCommandsHandler().addPlugin(event.getPlugin()); ess.getCommandHandler().addPlugin(event.getPlugin());
if (!ess.getPaymentMethod().hasMethod() && ess.getPaymentMethod().setMethod(ess.getServer().getPluginManager())) 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()}); 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) public void onPluginDisable(final PluginDisableEvent event)
{ {
ess.getPermissionsHandler().checkPermissions(); 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 // 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())) 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 @Override
public void reloadConfig() public void onReload()
{ {
//ess.getPermissionsHandler().setUseSuperperms(ess.getSettings().useBukkitPermissions()); //ess.getPermissionsHandler().setUseSuperperms(ess.getSettings().useBukkitPermissions());
} }
@Override
public void onReload()
{
}
} }

View File

@@ -0,0 +1,10 @@
package com.earth2me.essentials.perm;
public abstract class AbstractPermissionsHandler implements IPermissionsHandler
{
@Override
public void checkPermissions()
{
}
}

View File

@@ -6,7 +6,7 @@ import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
public class ConfigPermissionsHandler implements IPermissionsHandler public class ConfigPermissionsHandler extends AbstractPermissionsHandler
{ {
private final transient IEssentials ess; private final transient IEssentials ess;

View File

@@ -8,7 +8,7 @@ import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
public class GroupManagerHandler implements IPermissionsHandler public class GroupManagerHandler extends AbstractPermissionsHandler
{ {
private final transient GroupManager groupManager; private final transient GroupManager groupManager;

View File

@@ -19,4 +19,6 @@ public interface IPermissionsHandler
String getPrefix(Player base); String getPrefix(Player base);
String getSuffix(Player base); String getSuffix(Player base);
public void checkPermissions();
} }

View File

@@ -5,7 +5,7 @@ import java.util.List;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class NullPermissionsHandler implements IPermissionsHandler public class NullPermissionsHandler extends AbstractPermissionsHandler
{ {
@Override @Override
public String getGroup(final Player base) public String getGroup(final Player base)

View File

@@ -8,7 +8,7 @@ import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
public class Permissions2Handler implements IPermissionsHandler public class Permissions2Handler extends AbstractPermissionsHandler
{ {
private final transient PermissionHandler permissionHandler; private final transient PermissionHandler permissionHandler;

View File

@@ -8,7 +8,7 @@ import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
public class Permissions3Handler implements IPermissionsHandler public class Permissions3Handler extends AbstractPermissionsHandler
{ {
private final transient PermissionHandler permissionHandler; private final transient PermissionHandler permissionHandler;

View File

@@ -8,7 +8,7 @@ import ru.tehkode.permissions.PermissionUser;
import ru.tehkode.permissions.bukkit.PermissionsEx; import ru.tehkode.permissions.bukkit.PermissionsEx;
public class PermissionsExHandler implements IPermissionsHandler public class PermissionsExHandler extends AbstractPermissionsHandler
{ {
private final transient PermissionManager manager; private final transient PermissionManager manager;

View File

@@ -96,6 +96,7 @@ public class PermissionsHandler implements IPermissionsHandler
return suffix; return suffix;
} }
@Override
public void checkPermissions() public void checkPermissions()
{ {
final PluginManager pluginManager = plugin.getServer().getPluginManager(); final PluginManager pluginManager = plugin.getServer().getPluginManager();

View File

@@ -4,7 +4,7 @@ import java.util.List;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class SuperpermsHandler implements IPermissionsHandler public class SuperpermsHandler extends AbstractPermissionsHandler
{ {
@Override @Override
public String getGroup(final Player base) public String getGroup(final Player base)

View File

@@ -36,7 +36,7 @@ public class GroupsHolder extends AsyncStorageObjectHolder<Groups> implements IG
{ {
return; return;
} }
Util.registerPermissions("essentials.groups", groups.keySet(), true, (com.earth2me.essentials.IEssentials)ess); Util.registerPermissions("essentials.groups", groups.keySet(), true, ess);
} }
finally finally
{ {

View File

@@ -4,13 +4,28 @@ import com.earth2me.essentials.api.IEssentials;
import com.earth2me.essentials.api.ISettings; import com.earth2me.essentials.api.ISettings;
import com.earth2me.essentials.storage.AsyncStorageObjectHolder; import com.earth2me.essentials.storage.AsyncStorageObjectHolder;
import java.io.File; import java.io.File;
import java.util.concurrent.atomic.AtomicBoolean;
public class SettingsHolder extends AsyncStorageObjectHolder<Settings> implements ISettings public class SettingsHolder extends AsyncStorageObjectHolder<Settings> implements ISettings
{ {
private final transient AtomicBoolean debug = new AtomicBoolean(false);
public SettingsHolder(final IEssentials ess) public SettingsHolder(final IEssentials ess)
{ {
super(ess, Settings.class); super(ess, Settings.class);
onReload();
}
@Override
public final void onReload()
{
super.onReload();
acquireReadLock();
try {
debug.set(getData().getGeneral().isDebug());
} finally {
unlock();
}
} }
@Override @Override
@@ -18,4 +33,32 @@ public class SettingsHolder extends AsyncStorageObjectHolder<Settings> implement
{ {
return new File(ess.getDataFolder(), "settings.yml"); 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();
}
}
} }

View File

@@ -49,11 +49,11 @@ public class EssentialsSign
} }
catch (ChargeException ex) catch (ChargeException ex)
{ {
ess.showCommandError(user, signName, ex); ess.getCommandHandler().showCommandError(user, signName, ex);
} }
catch (SignException 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, so the player sees the wrong sign.
return true; return true;
@@ -86,12 +86,12 @@ public class EssentialsSign
} }
catch (ChargeException ex) catch (ChargeException ex)
{ {
ess.showCommandError(user,signName, ex); ess.getCommandHandler().showCommandError(user,signName, ex);
return false; return false;
} }
catch (SignException ex) catch (SignException ex)
{ {
ess.showCommandError(user, signName, ex); ess.getCommandHandler().showCommandError(user, signName, ex);
return false; return false;
} }
} }
@@ -108,7 +108,7 @@ public class EssentialsSign
} }
catch (SignException ex) catch (SignException ex)
{ {
ess.showCommandError(user, signName, ex); ess.getCommandHandler().showCommandError(user, signName, ex);
return false; return false;
} }
} }
@@ -137,11 +137,11 @@ public class EssentialsSign
} }
catch (ChargeException ex) catch (ChargeException ex)
{ {
ess.showCommandError(user, signName, ex); ess.getCommandHandler().showCommandError(user, signName, ex);
} }
catch (SignException ex) catch (SignException ex)
{ {
ess.showCommandError(user, signName, ex); ess.getCommandHandler().showCommandError(user, signName, ex);
} }
return false; return false;
} }
@@ -155,11 +155,11 @@ public class EssentialsSign
} }
catch (ChargeException ex) catch (ChargeException ex)
{ {
ess.showCommandError(user, signName, ex); ess.getCommandHandler().showCommandError(user, signName, ex);
} }
catch (SignException ex) catch (SignException ex)
{ {
ess.showCommandError(user, signName, ex); ess.getCommandHandler().showCommandError(user, signName, ex);
} }
return false; return false;
} }
@@ -173,7 +173,7 @@ public class EssentialsSign
} }
catch (SignException ex) catch (SignException ex)
{ {
ess.showCommandError(user, signName, ex); ess.getCommandHandler().showCommandError(user, signName, ex);
} }
return false; return false;
} }

View File

@@ -1,7 +1,7 @@
package com.earth2me.essentials.signs; package com.earth2me.essentials.signs;
import com.earth2me.essentials.IEssentials; import com.earth2me.essentials.api.IEssentials;
import com.earth2me.essentials.User; import com.earth2me.essentials.api.IUser;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.bukkit.Material; import org.bukkit.Material;
@@ -16,7 +16,7 @@ public class SignBlockListener extends BlockListener
private final transient IEssentials ess; private final transient IEssentials ess;
private final static Logger LOGGER = Logger.getLogger("Minecraft"); private final static Logger LOGGER = Logger.getLogger("Minecraft");
public SignBlockListener(IEssentials ess) public SignBlockListener(final IEssentials ess)
{ {
this.ess = ess; this.ess = ess;
} }
@@ -80,7 +80,7 @@ public class SignBlockListener extends BlockListener
{ {
return; return;
} }
User user = ess.getUser(event.getPlayer()); IUser user = ess.getUser(event.getPlayer());
if (user.isAuthorized("essentials.signs.color")) if (user.isAuthorized("essentials.signs.color"))
{ {
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)

View File

@@ -1,6 +1,6 @@
package com.earth2me.essentials.signs; package com.earth2me.essentials.signs;
import com.earth2me.essentials.IEssentials; import com.earth2me.essentials.api.IEssentials;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.event.entity.EndermanPickupEvent; import org.bukkit.event.entity.EndermanPickupEvent;

View File

@@ -1,6 +1,6 @@
package com.earth2me.essentials.signs; package com.earth2me.essentials.signs;
import com.earth2me.essentials.IEssentials; import com.earth2me.essentials.api.IEssentials;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.Sign; import org.bukkit.block.Sign;

View File

@@ -29,7 +29,7 @@ public class SignWarp extends EssentialsSign
{ {
try try
{ {
ess.getWarps2().getWarp(warpName); ess.getWarps().getWarp(warpName);
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@@ -1,15 +1,13 @@
package com.earth2me.essentials.storage; package com.earth2me.essentials.storage;
import com.earth2me.essentials.IConf;
import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.api.IEssentials;
import com.earth2me.essentials.api.IReload;
import java.io.File; import java.io.File;
import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.logging.Level; import java.util.logging.Level;
import org.bukkit.Bukkit; 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 transient T data;
private final transient ReentrantReadWriteLock rwl = new ReentrantReadWriteLock(); 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 @Override
public void onReload() public void onReload()
{ {

View File

@@ -1,9 +1,9 @@
package com.earth2me.essentials.storage; 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(); T getData();

View File

@@ -35,7 +35,7 @@ public class KeywordReplacer implements IText
if (sender instanceof Player) if (sender instanceof Player)
{ {
@Cleanup @Cleanup
final IUser user = ess.getUser(sender); final IUser user = ess.getUser((Player)sender);
user.acquireReadLock(); user.acquireReadLock();
displayName = user.getDisplayName(); displayName = user.getDisplayName();
ipAddress = user.getAddress().getAddress().toString(); ipAddress = user.getAddress().getAddress().toString();

View File

@@ -21,7 +21,7 @@ public class TextInput implements IText
File file = null; File file = null;
if (sender instanceof Player) 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"); file = new File(ess.getDataFolder(), filename + "_" + Util.sanitizeFileName(user.getName()) + ".txt");
if (!file.exists()) if (!file.exists())
{ {

View File

@@ -50,13 +50,13 @@ public class User extends UserBase implements IUser
public User(final Player base, final IEssentials ess) public User(final Player base, final IEssentials ess)
{ {
super(base, 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) public User(final OfflinePlayer offlinePlayer, final IEssentials ess)
{ {
super(offlinePlayer, ess); super(offlinePlayer, ess);
teleport = new Teleport(this, (com.earth2me.essentials.IEssentials)ess); teleport = new Teleport(this, ess);
} }
public void example() public void example()
@@ -139,10 +139,10 @@ public class User extends UserBase implements IUser
try try
{ {
setMoney(getMoney() + value); setMoney(getMoney() + value);
sendMessage(_("addedToAccount", Util.formatCurrency(value, (com.earth2me.essentials.IEssentials)ess))); sendMessage(_("addedToAccount", Util.formatCurrency(value, ess)));
if (initiator != null) 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 finally
@@ -161,8 +161,8 @@ public class User extends UserBase implements IUser
{ {
setMoney(getMoney() - value); setMoney(getMoney() - value);
reciever.setMoney(reciever.getMoney() + value); reciever.setMoney(reciever.getMoney() + value);
sendMessage(_("moneySentTo", Util.formatCurrency(value, (com.earth2me.essentials.IEssentials)ess), reciever.getDisplayName())); sendMessage(_("moneySentTo", Util.formatCurrency(value, ess), reciever.getDisplayName()));
reciever.sendMessage(_("moneyRecievedFrom", Util.formatCurrency(value, (com.earth2me.essentials.IEssentials)ess), getDisplayName())); reciever.sendMessage(_("moneyRecievedFrom", Util.formatCurrency(value, ess), getDisplayName()));
} }
else else
{ {
@@ -183,10 +183,10 @@ public class User extends UserBase implements IUser
return; return;
} }
setMoney(getMoney() - value); setMoney(getMoney() - value);
sendMessage(_("takenFromAccount", Util.formatCurrency(value, (com.earth2me.essentials.IEssentials)ess))); sendMessage(_("takenFromAccount", Util.formatCurrency(value, ess)));
if (initiator != null) 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()));
} }
} }

View File

@@ -2,6 +2,7 @@ package com.earth2me.essentials.user;
import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.api.IEssentials;
import com.earth2me.essentials.Util; import com.earth2me.essentials.Util;
import com.earth2me.essentials.api.IUser;
import com.earth2me.essentials.api.IUserMap; import com.earth2me.essentials.api.IUserMap;
import com.google.common.cache.Cache; import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder; 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) public boolean userExists(final String name)
{ {
return keys.contains(name.toLowerCase(Locale.ENGLISH)); return keys.contains(name.toLowerCase(Locale.ENGLISH));
} }
public User getUser(final String name) @Override
public IUser getUser(final String name)
{ {
try try
{ {
@@ -98,22 +101,26 @@ public class UserMap extends CacheLoader<String, User> implements IUserMap
throw new Exception("User not found!"); throw new Exception("User not found!");
} }
@Override
public void removeUser(final String name) public void removeUser(final String name)
{ {
keys.remove(name.toLowerCase(Locale.ENGLISH)); keys.remove(name.toLowerCase(Locale.ENGLISH));
users.invalidate(name.toLowerCase(Locale.ENGLISH)); users.invalidate(name.toLowerCase(Locale.ENGLISH));
} }
@Override
public Set<String> getAllUniqueUsers() public Set<String> getAllUniqueUsers()
{ {
return Collections.unmodifiableSet(keys); return Collections.unmodifiableSet(keys);
} }
@Override
public int getUniqueUsers() public int getUniqueUsers()
{ {
return keys.size(); return keys.size();
} }
@Override
public File getUserFile(final String name) public File getUserFile(final String name)
{ {
final File userFolder = new File(ess.getDataFolder(), "userdata"); final File userFolder = new File(ess.getDataFolder(), "userdata");
@@ -125,4 +132,24 @@ public class UserMap extends CacheLoader<String, User> implements IUserMap
{ {
loadAllUsersAsync(); 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;
}
} }

View File

@@ -45,7 +45,7 @@ public class EconomyTest extends TestCase
assertFalse("NPC does not exists", Economy.playerExists(NPCNAME)); assertFalse("NPC does not exists", Economy.playerExists(NPCNAME));
assertTrue("Create NPC", Economy.createNPC(NPCNAME)); assertTrue("Create NPC", Economy.createNPC(NPCNAME));
assertTrue("NPC exists", Economy.playerExists(NPCNAME)); assertTrue("NPC exists", Economy.playerExists(NPCNAME));
assertNotNull("NPC can be accessed", ess.getOfflineUser(NPCNAME)); assertNotNull("NPC can be accessed", ess.getUser(NPCNAME));
try try
{ {
Economy.removeNPC(NPCNAME); Economy.removeNPC(NPCNAME);

View File

@@ -2,6 +2,7 @@ package com.earth2me.essentials;
import com.earth2me.essentials.craftbukkit.FakeWorld; import com.earth2me.essentials.craftbukkit.FakeWorld;
import com.avaje.ebean.config.ServerConfig; import com.avaje.ebean.config.ServerConfig;
import com.earth2me.essentials.api.IEssentials;
import java.io.File; import java.io.File;
import java.util.*; import java.util.*;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;

View File

@@ -5,6 +5,7 @@ import junit.framework.TestCase;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World.Environment; import org.bukkit.World.Environment;
import org.bukkit.plugin.InvalidDescriptionException; import org.bukkit.plugin.InvalidDescriptionException;
import com.earth2me.essentials.api.IUser;
public class UserTest extends TestCase public class UserTest extends TestCase
@@ -49,11 +50,11 @@ public class UserTest extends TestCase
public void testHome() public void testHome()
{ {
User user = ess.getUser(base1); IUser user = ess.getUser(base1);
Location loc = base1.getLocation(); Location loc = base1.getLocation();
user.setHome(); user.setHome();
OfflinePlayer base2 = server.createPlayer(base1.getName(), ess); OfflinePlayer base2 = server.createPlayer(base1.getName(), ess);
User user2 = ess.getUser(base2); IUser user2 = ess.getUser(base2);
Location home = user2.getHome(loc); Location home = user2.getHome(loc);
assertNotNull(home); assertNotNull(home);
@@ -68,7 +69,7 @@ public class UserTest extends TestCase
public void testMoney() public void testMoney()
{ {
should("properly set, take, give, and get money"); should("properly set, take, give, and get money");
User user = ess.getUser(base1); IUser user = ess.getUser(base1);
double i; double i;
user.setMoney(i = 100.5); user.setMoney(i = 100.5);
user.takeMoney(50); user.takeMoney(50);
@@ -81,7 +82,7 @@ public class UserTest extends TestCase
public void testGetGroup() public void testGetGroup()
{ {
should("return the default group"); should("return the default group");
User user = ess.getUser(base1); IUser user = ess.getUser(base1);
assertEquals(user.getGroup(), "default"); assertEquals(user.getGroup(), "default");
} }
} }