summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsnowleo <snowleo@e251c2fe-e539-e718-e476-b85c1f46cddb>2011-06-01 10:40:12 +0000
committersnowleo <snowleo@e251c2fe-e539-e718-e476-b85c1f46cddb>2011-06-01 10:40:12 +0000
commit8acb65a5f80c7ae1a87c05bac24306cb5b834300 (patch)
tree0cfd2bd40562a6b7ec0dadf5dce895bfd78ac9ef
parent9e919b199e20d8b028beea5b3d303b7153035faa (diff)
downloadEssentials-8acb65a5f80c7ae1a87c05bac24306cb5b834300.tar
Essentials-8acb65a5f80c7ae1a87c05bac24306cb5b834300.tar.gz
Essentials-8acb65a5f80c7ae1a87c05bac24306cb5b834300.tar.lz
Essentials-8acb65a5f80c7ae1a87c05bac24306cb5b834300.tar.xz
Essentials-8acb65a5f80c7ae1a87c05bac24306cb5b834300.zip
Several bug fixes and cleanup.
Found using PMD and FindBugs. git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1553 e251c2fe-e539-e718-e476-b85c1f46cddb
-rw-r--r--Essentials/nbproject/pmd.settings1
-rw-r--r--Essentials/src/com/earth2me/essentials/Backup.java18
-rw-r--r--Essentials/src/com/earth2me/essentials/Charge.java34
-rw-r--r--Essentials/src/com/earth2me/essentials/Console.java2
-rw-r--r--Essentials/src/com/earth2me/essentials/Essentials.java123
-rw-r--r--Essentials/src/com/earth2me/essentials/EssentialsBlockListener.java17
-rw-r--r--Essentials/src/com/earth2me/essentials/EssentialsConf.java26
-rw-r--r--Essentials/src/com/earth2me/essentials/EssentialsEcoBlockListener.java2
-rw-r--r--Essentials/src/com/earth2me/essentials/EssentialsEcoPlayerListener.java4
-rw-r--r--Essentials/src/com/earth2me/essentials/EssentialsEntityListener.java6
-rw-r--r--Essentials/src/com/earth2me/essentials/EssentialsErrorHandler.java13
-rw-r--r--Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java42
-rw-r--r--Essentials/src/com/earth2me/essentials/EssentialsPluginListener.java4
-rw-r--r--Essentials/src/com/earth2me/essentials/EssentialsTimer.java20
-rw-r--r--Essentials/src/com/earth2me/essentials/EssentialsUpdateTimer.java4
-rw-r--r--Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java54
-rw-r--r--Essentials/src/com/earth2me/essentials/FakeWorld.java4
-rw-r--r--Essentials/src/com/earth2me/essentials/IEssentials.java68
-rw-r--r--Essentials/src/com/earth2me/essentials/IUser.java51
-rw-r--r--Essentials/src/com/earth2me/essentials/InventoryWorkaround.java6
-rw-r--r--Essentials/src/com/earth2me/essentials/ItemDb.java22
-rw-r--r--Essentials/src/com/earth2me/essentials/Jail.java8
-rw-r--r--Essentials/src/com/earth2me/essentials/JailPlayerListener.java4
-rw-r--r--Essentials/src/com/earth2me/essentials/Mob.java16
-rw-r--r--Essentials/src/com/earth2me/essentials/PlayerExtension.java11
-rw-r--r--Essentials/src/com/earth2me/essentials/Settings.java67
-rw-r--r--Essentials/src/com/earth2me/essentials/Spawn.java4
-rw-r--r--Essentials/src/com/earth2me/essentials/TargetBlock.java2
-rw-r--r--Essentials/src/com/earth2me/essentials/Teleport.java29
-rw-r--r--Essentials/src/com/earth2me/essentials/User.java32
-rw-r--r--Essentials/src/com/earth2me/essentials/UserData.java14
-rw-r--r--Essentials/src/com/earth2me/essentials/Util.java26
-rw-r--r--Essentials/src/com/earth2me/essentials/Warps.java25
-rw-r--r--Essentials/src/com/earth2me/essentials/Worth.java2
-rw-r--r--Essentials/src/com/earth2me/essentials/api/Economy.java5
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandback.java2
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandbackup.java3
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandbigtree.java2
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commanddeljail.java3
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commanddelwarp.java3
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandeco.java2
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandhelp.java43
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandhome.java2
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandinfo.java23
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandjails.java3
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandjump.java2
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandkit.java5
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandnick.java2
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java1
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandrules.java1
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandsell.java4
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandsetjail.java2
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandsetwarp.java2
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandsetworth.java2
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandspawner.java2
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java10
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandtogglejail.java2
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandtop.java2
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandtp.java2
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandtpaccept.java2
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandtphere.java2
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandtppos.java2
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandwarp.java5
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandwhois.java6
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandworld.java3
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandworth.java3
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java11
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/IEssentialsCommand.java7
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/NotEnoughArgumentsException.java10
-rw-r--r--Essentials/test/com/earth2me/essentials/EconomyTest.java4
-rw-r--r--Essentials/test/com/earth2me/essentials/EssentialsTest.java12
-rw-r--r--Essentials/test/com/earth2me/essentials/FakeServer.java6
-rw-r--r--Essentials/test/com/earth2me/essentials/PermissionsTest.java17
-rw-r--r--Essentials/test/com/earth2me/essentials/UserTest.java6
74 files changed, 639 insertions, 348 deletions
diff --git a/Essentials/nbproject/pmd.settings b/Essentials/nbproject/pmd.settings
new file mode 100644
index 000000000..6a34e356c
--- /dev/null
+++ b/Essentials/nbproject/pmd.settings
@@ -0,0 +1 @@
+DoNotUseThreads
diff --git a/Essentials/src/com/earth2me/essentials/Backup.java b/Essentials/src/com/earth2me/essentials/Backup.java
index 4261acf00..6b88eaef9 100644
--- a/Essentials/src/com/earth2me/essentials/Backup.java
+++ b/Essentials/src/com/earth2me/essentials/Backup.java
@@ -8,13 +8,15 @@ import org.bukkit.craftbukkit.CraftServer;
public class Backup implements Runnable {
private static final Logger logger = Logger.getLogger("Minecraft");
- private CraftServer server;
+ private final CraftServer server;
+ private final IEssentials ess;
private boolean running = false;
private int taskId = -1;
private boolean active = false;
- public Backup() {
- server = (CraftServer)Essentials.getStatic().getServer();
+ public Backup(IEssentials ess) {
+ this.ess = ess;
+ server = (CraftServer)ess.getServer();
if (server.getOnlinePlayers().length > 0) {
startTask();
}
@@ -26,11 +28,11 @@ public class Backup implements Runnable {
private void startTask() {
if (!running) {
- long interval = Essentials.getStatic().getSettings().getBackupInterval()*1200; // minutes -> ticks
+ long interval = ess.getSettings().getBackupInterval()*1200; // minutes -> ticks
if (interval < 1200) {
return;
}
- taskId = server.getScheduler().scheduleSyncRepeatingTask(Essentials.getStatic(), this, interval, interval);
+ taskId = ess.scheduleSyncRepeatingTask(this, interval, interval);
running = true;
}
}
@@ -38,7 +40,7 @@ public class Backup implements Runnable {
public void run() {
if (active) return;
active = true;
- final String command = Essentials.getStatic().getSettings().getBackupCommand();
+ final String command = ess.getSettings().getBackupCommand();
if (command == null || "".equals(command)) {
return;
}
@@ -47,7 +49,7 @@ public class Backup implements Runnable {
server.dispatchCommand(cs, "save-all");
server.dispatchCommand(cs, "save-off");
- server.getScheduler().scheduleAsyncDelayedTask(Essentials.getStatic(),
+ ess.scheduleAsyncDelayedTask(
new Runnable() {
public void run() {
@@ -59,7 +61,7 @@ public class Backup implements Runnable {
} catch (IOException ex) {
logger.log(Level.SEVERE, null, ex);
} finally {
- server.getScheduler().scheduleSyncDelayedTask(Essentials.getStatic(),
+ ess.scheduleSyncDelayedTask(
new Runnable() {
public void run() {
diff --git a/Essentials/src/com/earth2me/essentials/Charge.java b/Essentials/src/com/earth2me/essentials/Charge.java
index 0a4df82bd..5098b3b1f 100644
--- a/Essentials/src/com/earth2me/essentials/Charge.java
+++ b/Essentials/src/com/earth2me/essentials/Charge.java
@@ -1,37 +1,39 @@
package com.earth2me.essentials;
-import com.earth2me.essentials.commands.EssentialsCommand;
import org.bukkit.inventory.ItemStack;
public class Charge
{
- private String command = null;
- private Double costs = null;
- private ItemStack items = null;
- private Essentials ess = Essentials.getStatic();
+ private final String command;
+ private final Double costs;
+ private final ItemStack items;
+ private final IEssentials ess;
- public Charge(String command)
+ public Charge(String command, IEssentials ess)
{
- this.command = command;
+ this(command, null, null, ess);
}
- public Charge(double money)
+ public Charge(double money, IEssentials ess)
{
- this.costs = money;
+ this(null, money, null, ess);
}
- public Charge(ItemStack items)
+ public Charge(ItemStack items, IEssentials ess)
{
- this.items = items;
+ this(null, null, items, ess);
}
-
- public Charge(EssentialsCommand command)
+
+ private Charge(String command, Double money, ItemStack item, IEssentials ess)
{
- this.command = command.getName();
+ this.command = command;
+ this.costs = money;
+ this.items = item;
+ this.ess = ess;
}
- public void isAffordableFor(User user) throws Exception
+ public void isAffordableFor(IUser user) throws Exception
{
double mon = user.getMoney();
if (costs != null)
@@ -63,7 +65,7 @@ public class Charge
}
}
- public void charge(User user) throws Exception
+ public void charge(IUser user) throws Exception
{
double mon = user.getMoney();
if (costs != null)
diff --git a/Essentials/src/com/earth2me/essentials/Console.java b/Essentials/src/com/earth2me/essentials/Console.java
index 219587f23..882c4f2c8 100644
--- a/Essentials/src/com/earth2me/essentials/Console.java
+++ b/Essentials/src/com/earth2me/essentials/Console.java
@@ -4,7 +4,7 @@ import org.bukkit.Server;
import org.bukkit.command.CommandSender;
import org.bukkit.craftbukkit.CraftServer;
-public class Console implements IReplyTo {
+public final class Console implements IReplyTo {
private static Console instance = new Console();
private CommandSender replyTo;
public final static String NAME = "Console";
diff --git a/Essentials/src/com/earth2me/essentials/Essentials.java b/Essentials/src/com/earth2me/essentials/Essentials.java
index e5fac85c4..1d40f44d2 100644
--- a/Essentials/src/com/earth2me/essentials/Essentials.java
+++ b/Essentials/src/com/earth2me/essentials/Essentials.java
@@ -40,7 +40,7 @@ import org.bukkit.plugin.*;
import org.bukkit.plugin.java.*;
-public class Essentials extends JavaPlugin
+public class Essentials extends JavaPlugin implements IEssentials
{
public static final String AUTHORS = "Zenexer, ementalo, Aelux, Brettflan, KimKandor, snowleo, ceulemans and Xeology";
public static final int minBukkitBuildVersion = 818;
@@ -59,19 +59,15 @@ public class Essentials extends JavaPlugin
public ArrayList bans = new ArrayList();
public ArrayList bannedIps = new ArrayList();
private Backup backup;
- private Map<String, User> users = new HashMap<String, User>();
+ private final Map<String, User> users = new HashMap<String, User>();
private EssentialsTimer timer;
private EssentialsUpdateTimer updateTimer;
private boolean registerFallback = true;
- private Methods paymentMethod = new Methods();
- private boolean enableErrorLogging = false;
- private EssentialsErrorHandler errorHandler = new EssentialsErrorHandler();
+ private final Methods paymentMethod = new Methods();
+ private final static boolean enableErrorLogging = false;
+ private final EssentialsErrorHandler errorHandler = new EssentialsErrorHandler();
- public Essentials()
- {
- }
-
- public static Essentials getStatic()
+ public static IEssentials getStatic()
{
return instance;
}
@@ -119,7 +115,7 @@ public class Essentials extends JavaPlugin
worth = new Worth(this.getDataFolder());
confList.add(worth);
reload();
- backup = new Backup();
+ backup = new Backup(this);
PluginManager pm = getServer().getPluginManager();
for (Plugin plugin : pm.getPlugins())
@@ -349,7 +345,7 @@ public class Essentials extends JavaPlugin
public boolean onCommandEssentials(CommandSender sender, Command command, String commandLabel, String[] args, ClassLoader classLoader, String commandPath)
{
- if ("msg".equals(commandLabel.toLowerCase()) || "r".equals(commandLabel.toLowerCase()) || "mail".equals(commandLabel.toLowerCase()) & sender instanceof CraftPlayer)
+ if ("msg".equals(commandLabel.toLowerCase()) || "r".equals(commandLabel.toLowerCase()) || "mail".equals(commandLabel.toLowerCase()) && sender instanceof CraftPlayer)
{
StringBuilder str = new StringBuilder();
str.append(commandLabel).append(" ");
@@ -408,13 +404,10 @@ public class Essentials extends JavaPlugin
// New mail notification
if (user != null && !getSettings().isCommandDisabled("mail") && !commandLabel.equals("mail") && user.isAuthorized("essentials.mail"))
{
- List<String> mail = user.getMails();
- if (mail != null)
+ final List<String> mail = user.getMails();
+ if (mail != null && !mail.isEmpty())
{
- if (mail.size() > 0)
- {
- user.sendMessage(Util.format("youHaveNewMail", mail.size()));
- }
+ user.sendMessage(Util.format("youHaveNewMail", mail.size()));
}
}
@@ -428,6 +421,7 @@ public class Essentials extends JavaPlugin
try
{
cmd = (IEssentialsCommand)classLoader.loadClass(commandPath + command.getName()).newInstance();
+ cmd.setEssentials(this);
}
catch (Exception ex)
{
@@ -502,15 +496,15 @@ public class Essentials extends JavaPlugin
throw new FileNotFoundException(Util.i18n("bannedPlayersFileNotFound"));
}
- BufferedReader rx = new BufferedReader(new FileReader(file));
- bans.clear();
+ final BufferedReader bufferedReader = new BufferedReader(new FileReader(file));
try
{
- for (int i = 0; rx.ready(); i++)
+ bans.clear();
+ while (bufferedReader.ready())
{
- String line = rx.readLine().trim().toLowerCase();
- if (line.startsWith("#"))
+ final String line = bufferedReader.readLine().trim().toLowerCase();
+ if (line.length() > 0 && line.charAt(0) == '#')
{
continue;
}
@@ -522,6 +516,17 @@ public class Essentials extends JavaPlugin
{
logger.log(Level.SEVERE, Util.i18n("bannedPlayersFileError"), io);
}
+ finally
+ {
+ try
+ {
+ bufferedReader.close();
+ }
+ catch (IOException ex)
+ {
+ logger.log(Level.SEVERE, Util.i18n("bannedPlayersFileError"), ex);
+ }
+ }
}
catch (FileNotFoundException ex)
{
@@ -535,15 +540,15 @@ public class Essentials extends JavaPlugin
throw new FileNotFoundException(Util.i18n("bannedIpsFileNotFound"));
}
- BufferedReader rx = new BufferedReader(new FileReader(ipFile));
- bannedIps.clear();
+ final BufferedReader bufferedReader = new BufferedReader(new FileReader(ipFile));
try
{
- for (int i = 0; rx.ready(); i++)
+ bannedIps.clear();
+ while (bufferedReader.ready())
{
- String line = rx.readLine().trim().toLowerCase();
- if (line.startsWith("#"))
+ final String line = bufferedReader.readLine().trim().toLowerCase();
+ if (line.length() > 0 && line.charAt(0) == '#')
{
continue;
}
@@ -555,6 +560,17 @@ public class Essentials extends JavaPlugin
{
logger.log(Level.SEVERE, Util.i18n("bannedIpsFileError"), io);
}
+ finally
+ {
+ try
+ {
+ bufferedReader.close();
+ }
+ catch (IOException ex)
+ {
+ logger.log(Level.SEVERE, Util.i18n("bannedIpsFileError"), ex);
+ }
+ }
}
catch (FileNotFoundException ex)
{
@@ -577,32 +593,32 @@ public class Essentials extends JavaPlugin
return (CraftScheduler)this.getServer().getScheduler();
}
- public static Jail getJail()
+ public Jail getJail()
{
- return getStatic().jail;
+ return jail;
}
- public static Warps getWarps()
+ public Warps getWarps()
{
- return getStatic().warps;
+ return warps;
}
- public static Worth getWorth()
+ public Worth getWorth()
{
- return getStatic().worth;
+ return worth;
}
- public static Backup getBackup()
+ public Backup getBackup()
{
- return getStatic().backup;
+ return backup;
}
- public static Spawn getSpawn()
+ public Spawn getSpawn()
{
- return getStatic().spawn;
+ return spawn;
}
- public <T> User getUser(T base)
+ public User getUser(Object base)
{
if (base instanceof Player)
{
@@ -698,9 +714,34 @@ public class Essentials extends JavaPlugin
return players.length;
}
-
+
public Map<BigInteger, String> getErrors()
{
- return errorHandler.errors;
+ return errorHandler.getErrors();
+ }
+
+ public int scheduleAsyncDelayedTask(final Runnable run)
+ {
+ return this.getScheduler().scheduleAsyncDelayedTask(this, run);
+ }
+
+ public int scheduleSyncDelayedTask(final Runnable run)
+ {
+ return this.getScheduler().scheduleSyncDelayedTask(this, run);
+ }
+
+ public int scheduleSyncRepeatingTask(final Runnable run, long delay, long period)
+ {
+ return this.getScheduler().scheduleSyncRepeatingTask(this, run, delay, period);
+ }
+
+ public List<String> getBans()
+ {
+ return bans;
+ }
+
+ public List<String> getBannedIps()
+ {
+ return bannedIps;
}
}
diff --git a/Essentials/src/com/earth2me/essentials/EssentialsBlockListener.java b/Essentials/src/com/earth2me/essentials/EssentialsBlockListener.java
index 246a49116..8069d8f83 100644
--- a/Essentials/src/com/earth2me/essentials/EssentialsBlockListener.java
+++ b/Essentials/src/com/earth2me/essentials/EssentialsBlockListener.java
@@ -1,10 +1,13 @@
package com.earth2me.essentials;
import java.util.ArrayList;
+import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
-import org.bukkit.*;
-import org.bukkit.block.*;
+import org.bukkit.Material;
+import org.bukkit.block.Block;
+import org.bukkit.block.BlockFace;
+import org.bukkit.block.Sign;
import org.bukkit.craftbukkit.block.CraftSign;
import org.bukkit.event.block.*;
import org.bukkit.inventory.ItemStack;
@@ -12,9 +15,9 @@ import org.bukkit.inventory.ItemStack;
public class EssentialsBlockListener extends BlockListener
{
- private final Essentials ess;
+ private final IEssentials ess;
private static final Logger logger = Logger.getLogger("Minecraft");
- public final static ArrayList<Material> protectedBlocks = new ArrayList<Material>(4);
+ public final static List<Material> protectedBlocks = new ArrayList<Material>(4);
static
{
@@ -24,7 +27,7 @@ public class EssentialsBlockListener extends BlockListener
protectedBlocks.add(Material.DISPENSER);
}
- public EssentialsBlockListener(Essentials ess)
+ public EssentialsBlockListener(IEssentials ess)
{
this.ess = ess;
}
@@ -144,7 +147,7 @@ public class EssentialsBlockListener extends BlockListener
event.setLine(1, "§dWarp name!");
return;
} else {
- Essentials.getWarps().getWarp(event.getLine(1));
+ ess.getWarps().getWarp(event.getLine(1));
if (event.getLine(2).equalsIgnoreCase("Everyone")) {
event.setLine(2, "§2Everyone");
}
@@ -243,7 +246,7 @@ public class EssentialsBlockListener extends BlockListener
}
boolean unlimitedForUser = user.hasUnlimited(is);
if (unlimitedForUser) {
- ess.getScheduler().scheduleSyncDelayedTask(ess,
+ ess.scheduleSyncDelayedTask(
new Runnable() {
public void run() {
diff --git a/Essentials/src/com/earth2me/essentials/EssentialsConf.java b/Essentials/src/com/earth2me/essentials/EssentialsConf.java
index 351e463c1..eaf23b773 100644
--- a/Essentials/src/com/earth2me/essentials/EssentialsConf.java
+++ b/Essentials/src/com/earth2me/essentials/EssentialsConf.java
@@ -40,7 +40,10 @@ public class EssentialsConf extends Configuration
configFile = configFile.getAbsoluteFile();
if (!configFile.getParentFile().exists())
{
- configFile.getParentFile().mkdirs();
+ if (!configFile.getParentFile().mkdirs())
+ {
+ logger.log(Level.SEVERE, Util.format("failedToCreateConfig", configFile.toString()));
+ }
}
if (!configFile.exists())
{
@@ -54,7 +57,10 @@ public class EssentialsConf extends Configuration
try
{
logger.log(Level.INFO, Util.format("creatingEmptyConfig", configFile.toString()));
- configFile.createNewFile();
+ if (!configFile.createNewFile())
+ {
+ logger.log(Level.SEVERE, Util.format("failedToCreateConfig", configFile.toString()));
+ }
}
catch (IOException ex)
{
@@ -71,10 +77,11 @@ public class EssentialsConf extends Configuration
private void createFromTemplate()
{
+ InputStream istr = null;
OutputStream ostr = null;
try
{
- InputStream istr = resourceClass.getResourceAsStream(templateName);
+ istr = resourceClass.getResourceAsStream(templateName);
if (istr == null)
{
logger.log(Level.SEVERE, Util.format("couldNotFindTemplate", templateName));
@@ -89,7 +96,6 @@ public class EssentialsConf extends Configuration
ostr.write(buffer, 0, length);
length = istr.read(buffer);
}
- istr.close();
}
catch (IOException ex)
{
@@ -100,6 +106,17 @@ public class EssentialsConf extends Configuration
{
try
{
+ if (istr != null)
+ {
+ istr.close();
+ }
+ }
+ catch (IOException ex)
+ {
+ Logger.getLogger(EssentialsConf.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ try
+ {
if (ostr != null)
{
ostr.close();
@@ -108,7 +125,6 @@ public class EssentialsConf extends Configuration
catch (IOException ex)
{
logger.log(Level.SEVERE, Util.format("failedToCloseConfig", configFile.toString()), ex);
- return;
}
}
}
diff --git a/Essentials/src/com/earth2me/essentials/EssentialsEcoBlockListener.java b/Essentials/src/com/earth2me/essentials/EssentialsEcoBlockListener.java
index 39552925f..630b9b23d 100644
--- a/Essentials/src/com/earth2me/essentials/EssentialsEcoBlockListener.java
+++ b/Essentials/src/com/earth2me/essentials/EssentialsEcoBlockListener.java
@@ -14,7 +14,7 @@ import org.bukkit.inventory.ItemStack;
public class EssentialsEcoBlockListener extends BlockListener
{
- Essentials ess;
+ private final IEssentials ess;
private static final Logger logger = Logger.getLogger("Minecraft");
public EssentialsEcoBlockListener(Essentials ess)
diff --git a/Essentials/src/com/earth2me/essentials/EssentialsEcoPlayerListener.java b/Essentials/src/com/earth2me/essentials/EssentialsEcoPlayerListener.java
index 4c7b56d1c..f3e01bd83 100644
--- a/Essentials/src/com/earth2me/essentials/EssentialsEcoPlayerListener.java
+++ b/Essentials/src/com/earth2me/essentials/EssentialsEcoPlayerListener.java
@@ -14,10 +14,10 @@ import org.bukkit.inventory.ItemStack;
public class EssentialsEcoPlayerListener extends PlayerListener
{
- Essentials ess;
+ private final IEssentials ess;
private static final Logger logger = Logger.getLogger("Minecraft");
- EssentialsEcoPlayerListener(Essentials ess)
+ EssentialsEcoPlayerListener(IEssentials ess)
{
this.ess = ess;
}
diff --git a/Essentials/src/com/earth2me/essentials/EssentialsEntityListener.java b/Essentials/src/com/earth2me/essentials/EssentialsEntityListener.java
index 8e7a8389d..0d4759c64 100644
--- a/Essentials/src/com/earth2me/essentials/EssentialsEntityListener.java
+++ b/Essentials/src/com/earth2me/essentials/EssentialsEntityListener.java
@@ -15,11 +15,11 @@ import org.bukkit.inventory.ItemStack;
public class EssentialsEntityListener extends EntityListener
{
- private final Essentials ess;
+ private final IEssentials ess;
- public EssentialsEntityListener(Essentials parent)
+ public EssentialsEntityListener(IEssentials ess)
{
- this.ess = parent;
+ this.ess = ess;
}
@Override
diff --git a/Essentials/src/com/earth2me/essentials/EssentialsErrorHandler.java b/Essentials/src/com/earth2me/essentials/EssentialsErrorHandler.java
index 60512737b..68dc5fbce 100644
--- a/Essentials/src/com/earth2me/essentials/EssentialsErrorHandler.java
+++ b/Essentials/src/com/earth2me/essentials/EssentialsErrorHandler.java
@@ -4,6 +4,8 @@ import java.math.BigInteger;
import java.security.MessageDigest;
import java.util.HashMap;
import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogRecord;
@@ -11,8 +13,8 @@ import java.util.logging.LogRecord;
class EssentialsErrorHandler extends Handler
{
- HashMap<BigInteger, String> errors = new HashMap<BigInteger, String>();
- private final LinkedList<LogRecord> records = new LinkedList<LogRecord>();
+ private final Map<BigInteger, String> errors = new HashMap<BigInteger, String>();
+ private final List<LogRecord> records = new LinkedList<LogRecord>();
public EssentialsErrorHandler()
{
@@ -74,7 +76,7 @@ class EssentialsErrorHandler extends Handler
break;
}
}
- if (essentialsFound == false && tr.getCause() != null)
+ if (!essentialsFound && tr.getCause() != null)
{
Throwable cause = tr.getCause();
StackTraceElement[] elements2 = cause.getStackTrace();
@@ -118,4 +120,9 @@ class EssentialsErrorHandler extends Handler
}
records.clear();
}
+
+ Map<BigInteger, String> getErrors()
+ {
+ return errors;
+ }
}
diff --git a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java
index 818bc216b..81e24311d 100644
--- a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java
+++ b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java
@@ -5,15 +5,30 @@ import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.minecraft.server.InventoryPlayer;
-import org.bukkit.*;
+import org.bukkit.Location;
+import org.bukkit.Material;
+import org.bukkit.Server;
+import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.craftbukkit.block.CraftSign;
import org.bukkit.craftbukkit.inventory.CraftInventoryPlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.block.Action;
-import org.bukkit.event.player.*;
+import org.bukkit.event.player.PlayerAnimationEvent;
+import org.bukkit.event.player.PlayerAnimationType;
+import org.bukkit.event.player.PlayerBucketEmptyEvent;
+import org.bukkit.event.player.PlayerChatEvent;
+import org.bukkit.event.player.PlayerEggThrowEvent;
+import org.bukkit.event.player.PlayerInteractEvent;
+import org.bukkit.event.player.PlayerJoinEvent;
+import org.bukkit.event.player.PlayerListener;
+import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerLoginEvent.Result;
+import org.bukkit.event.player.PlayerMoveEvent;
+import org.bukkit.event.player.PlayerQuitEvent;
+import org.bukkit.event.player.PlayerRespawnEvent;
+import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.inventory.ItemStack;
@@ -21,10 +36,10 @@ public class EssentialsPlayerListener extends PlayerListener
{
private static final Logger logger = Logger.getLogger("Minecraft");
private final Server server;
- private final Essentials ess;
- private EssentialsBlockListener essBlockListener = null;
+ private final IEssentials ess;
+ private final EssentialsBlockListener essBlockListener;
- public EssentialsPlayerListener(Essentials parent)
+ public EssentialsPlayerListener(IEssentials parent)
{
this.ess = parent;
this.server = parent.getServer();
@@ -40,7 +55,7 @@ public class EssentialsPlayerListener extends PlayerListener
if (user.isJailed() && user.getJail() != null && !user.getJail().isEmpty()) {
try
{
- event.setRespawnLocation(Essentials.getJail().getJail(user.getJail()));
+ event.setRespawnLocation(ess.getJail().getJail(user.getJail()));
}
catch (Exception ex)
{
@@ -162,7 +177,7 @@ public class EssentialsPlayerListener extends PlayerListener
event.setTo(loc);
try
{
- user.getTeleport().now(loc, new Charge("portal"));
+ user.getTeleport().now(loc, new Charge("portal", ess));
}
catch (Exception ex)
{
@@ -221,7 +236,7 @@ public class EssentialsPlayerListener extends PlayerListener
@Override
public void onPlayerJoin(PlayerJoinEvent event)
{
- Essentials.getBackup().onPlayerJoin();
+ ess.getBackup().onPlayerJoin();
User user = ess.getUser(event.getPlayer());
//we do not know the ip address on playerlogin so we need to do this here.
@@ -312,7 +327,7 @@ public class EssentialsPlayerListener extends PlayerListener
}
try
{
- event.setTo(Essentials.getJail().getJail(user.getJail()));
+ event.setTo(ess.getJail().getJail(user.getJail()));
}
catch (Exception ex)
{
@@ -498,15 +513,15 @@ public class EssentialsPlayerListener extends PlayerListener
}
if (m1)
{
- return new Charge(q1);
+ return new Charge(q1, ess);
}
else
{
ItemStack i = ItemDb.get(l1[1], (int)q1);
- return new Charge(i);
+ return new Charge(i, ess);
}
}
- return new Charge("warpsign");
+ return new Charge("warpsign", ess);
}
@Override
@@ -528,8 +543,7 @@ public class EssentialsPlayerListener extends PlayerListener
if (user.hasUnlimited(new ItemStack(event.getBucket())))
{
event.getItemStack().setType(event.getBucket());
- Essentials.getStatic().getScheduler().scheduleSyncDelayedTask(Essentials.getStatic(),
- new Runnable()
+ ess.scheduleSyncDelayedTask(new Runnable()
{
public void run()
{
diff --git a/Essentials/src/com/earth2me/essentials/EssentialsPluginListener.java b/Essentials/src/com/earth2me/essentials/EssentialsPluginListener.java
index f1779beee..b3b5ff1c1 100644
--- a/Essentials/src/com/earth2me/essentials/EssentialsPluginListener.java
+++ b/Essentials/src/com/earth2me/essentials/EssentialsPluginListener.java
@@ -10,8 +10,8 @@ import org.bukkit.event.server.ServerListener;
public class EssentialsPluginListener extends ServerListener
{
- Methods methods;
- private final Logger logger = Logger.getLogger("Minecraft");
+ private final Methods methods;
+ private static final Logger logger = Logger.getLogger("Minecraft");
public EssentialsPluginListener(Methods methods)
{
diff --git a/Essentials/src/com/earth2me/essentials/EssentialsTimer.java b/Essentials/src/com/earth2me/essentials/EssentialsTimer.java
index f5f0acf03..db01619b5 100644
--- a/Essentials/src/com/earth2me/essentials/EssentialsTimer.java
+++ b/Essentials/src/com/earth2me/essentials/EssentialsTimer.java
@@ -9,13 +9,13 @@ import org.bukkit.entity.Player;
public class EssentialsTimer implements Runnable, IConf
{
- private Essentials parent;
- private Set<User> allUsers = new HashSet<User>();
+ private final IEssentials ess;
+ private final Set<User> allUsers = new HashSet<User>();
- EssentialsTimer(Essentials parent)
+ EssentialsTimer(IEssentials ess)
{
- this.parent = parent;
- File userdir = new File(parent.getDataFolder(), "userdata");
+ this.ess = ess;
+ File userdir = new File(ess.getDataFolder(), "userdata");
if (!userdir.exists()) {
return;
}
@@ -25,7 +25,7 @@ public class EssentialsTimer implements Runnable, IConf
continue;
}
String name = string.substring(0, string.length()-4);
- User u = parent.getUser(new OfflinePlayer(name));
+ User u = ess.getUser(new OfflinePlayer(name));
allUsers.add(u);
}
}
@@ -33,9 +33,9 @@ public class EssentialsTimer implements Runnable, IConf
public void run()
{
long currentTime = System.currentTimeMillis();
- for (Player player : parent.getServer().getOnlinePlayers())
+ for (Player player : ess.getServer().getOnlinePlayers())
{
- User u = parent.getUser(player);
+ User u = ess.getUser(player);
allUsers.add(u);
u.setLastActivity(currentTime);
}
@@ -43,8 +43,8 @@ public class EssentialsTimer implements Runnable, IConf
for (User user: allUsers) {
if (user.getBanTimeout() > 0 && user.getBanTimeout() < currentTime) {
user.setBanTimeout(0);
- ((CraftServer)parent.getServer()).getHandle().b(user.getName());
- Essentials.getStatic().loadBanList();
+ ((CraftServer)ess.getServer()).getHandle().b(user.getName());
+ ess.loadBanList();
}
if (user.getMuteTimeout() > 0 && user.getMuteTimeout() < currentTime && user.isMuted()) {
user.setMuteTimeout(0);
diff --git a/Essentials/src/com/earth2me/essentials/EssentialsUpdateTimer.java b/Essentials/src/com/earth2me/essentials/EssentialsUpdateTimer.java
index 1659bcc5c..f00f644cd 100644
--- a/Essentials/src/com/earth2me/essentials/EssentialsUpdateTimer.java
+++ b/Essentials/src/com/earth2me/essentials/EssentialsUpdateTimer.java
@@ -16,7 +16,7 @@ import java.util.logging.Logger;
class EssentialsUpdateTimer implements Runnable
{
private URL url;
- private Essentials ess;
+ private final Essentials ess;
private static final Logger logger = Logger.getLogger("Minecraft");
public EssentialsUpdateTimer(Essentials ess)
@@ -40,7 +40,7 @@ class EssentialsUpdateTimer implements Runnable
sb.append("v=").append(URLEncoder.encode(ess.getDescription().getVersion(),"UTF-8"));
sb.append("&b=").append(URLEncoder.encode(ess.getServer().getVersion(),"UTF-8"));
sb.append("&jv=").append(URLEncoder.encode(System.getProperty("java.version"),"UTF-8"));
- sb.append("&l=").append(URLEncoder.encode(Util.currentLocale.toString(),"UTF-8"));
+ sb.append("&l=").append(URLEncoder.encode(Util.getCurrentLocale().toString(),"UTF-8"));
sb.append("&on=").append(URLEncoder.encode(System.getProperty("os.name"),"UTF-8"));
sb.append("&ov=").append(URLEncoder.encode(System.getProperty("os.version"),"UTF-8"));
for (BigInteger bigInteger : ess.getErrors().keySet())
diff --git a/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java b/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java
index 59432e405..4d26d270f 100644
--- a/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java
+++ b/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java
@@ -18,16 +18,16 @@ public class EssentialsUpgrade
{
private static boolean alreadyRun = false;
private final static Logger logger = Logger.getLogger("Minecraft");
- private Essentials ess;
+ private final IEssentials ess;
- EssentialsUpgrade(String version, Essentials essentials)
+ EssentialsUpgrade(String version, IEssentials essentials)
{
- if (alreadyRun == true)
+ ess = essentials;
+ if (alreadyRun)
{
return;
}
alreadyRun = true;
- ess = essentials;
}
private void moveWorthValuesToWorthYml()
@@ -79,7 +79,7 @@ public class EssentialsUpgrade
}
if (line.matches(regex))
{
- if (needUpdate == false && info != null)
+ if (!needUpdate && info != null)
{
bw.write(info, 0, info.length());
bw.newLine();
@@ -246,13 +246,26 @@ public class EssentialsUpgrade
try
{
BufferedReader rx = new BufferedReader(new FileReader(listOfFiles[i]));
- double x = Double.parseDouble(rx.readLine().trim());
- double y = Double.parseDouble(rx.readLine().trim());
- double z = Double.parseDouble(rx.readLine().trim());
- float yaw = Float.parseFloat(rx.readLine().trim());
- float pitch = Float.parseFloat(rx.readLine().trim());
- String worldName = rx.readLine();
- rx.close();
+ double x, y, z;
+ float yaw, pitch;
+ String worldName;
+ try
+ {
+ if (!rx.ready()) continue;
+ x = Double.parseDouble(rx.readLine().trim());
+ if (!rx.ready()) continue;
+ y = Double.parseDouble(rx.readLine().trim());
+ if (!rx.ready()) continue;
+ z = Double.parseDouble(rx.readLine().trim());
+ if (!rx.ready()) continue;
+ yaw = Float.parseFloat(rx.readLine().trim());
+ if (!rx.ready()) continue;
+ pitch = Float.parseFloat(rx.readLine().trim());
+ worldName = rx.readLine();
+ }
+ finally {
+ rx.close();
+ }
World w = null;
for (World world : ess.getServer().getWorlds())
{
@@ -264,7 +277,7 @@ public class EssentialsUpgrade
}
if (worldName != null)
{
- worldName.trim();
+ worldName = worldName.trim();
World w1 = null;
w1 = getFakeWorld(worldName);
if (w1 != null)
@@ -273,7 +286,7 @@ public class EssentialsUpgrade
}
}
Location loc = new Location(w, x, y, z, yaw, pitch);
- Essentials.getWarps().setWarp(filename.substring(0, filename.length() - 4), loc);
+ ess.getWarps().setWarp(filename.substring(0, filename.length() - 4), loc);
if (!listOfFiles[i].renameTo(new File(warpsFolder, filename + ".old")))
{
throw new Exception(Util.format("fileRenameError", filename));
@@ -293,6 +306,8 @@ public class EssentialsUpgrade
try
{
BufferedReader rx = new BufferedReader(new FileReader(warpFile));
+ try
+ {
for (String[] parts = new String[0]; rx.ready(); parts = rx.readLine().split(":"))
{
if (parts.length < 6)
@@ -319,12 +334,17 @@ public class EssentialsUpgrade
}
}
Location loc = new Location(w, x, y, z, yaw, pitch);
- Essentials.getWarps().setWarp(name, loc);
+ ess.getWarps().setWarp(name, loc);
if (!warpFile.renameTo(new File(ess.getDataFolder(), "warps.txt.old")))
{
throw new Exception(Util.format("fileRenameError", "warps.txt"));
}
}
+ }
+ finally
+ {
+ rx.close();
+ }
}
catch (Exception ex)
{
@@ -381,7 +401,7 @@ public class EssentialsUpgrade
return null;
}
- void beforeSettings()
+ public void beforeSettings()
{
if (!ess.getDataFolder().exists())
{
@@ -390,7 +410,7 @@ public class EssentialsUpgrade
moveWorthValuesToWorthYml();
}
- void afterSettings()
+ public void afterSettings()
{
sanitizeAllUserFilenames();
updateUsersToNewDefaultHome();
diff --git a/Essentials/src/com/earth2me/essentials/FakeWorld.java b/Essentials/src/com/earth2me/essentials/FakeWorld.java
index 16472c56c..ef016d242 100644
--- a/Essentials/src/com/earth2me/essentials/FakeWorld.java
+++ b/Essentials/src/com/earth2me/essentials/FakeWorld.java
@@ -25,8 +25,8 @@ import org.bukkit.util.Vector;
public class FakeWorld implements World
{
- private String name;
- private Environment env;
+ private final String name;
+ private final Environment env;
FakeWorld(String string, Environment environment)
{
this.name = string;
diff --git a/Essentials/src/com/earth2me/essentials/IEssentials.java b/Essentials/src/com/earth2me/essentials/IEssentials.java
new file mode 100644
index 000000000..8cc905355
--- /dev/null
+++ b/Essentials/src/com/earth2me/essentials/IEssentials.java
@@ -0,0 +1,68 @@
+package com.earth2me.essentials;
+
+import com.earth2me.essentials.register.payment.Methods;
+import java.io.File;
+import java.util.List;
+import org.bukkit.Server;
+import org.bukkit.World;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.craftbukkit.scheduler.CraftScheduler;
+import org.bukkit.plugin.PluginDescriptionFile;
+
+public interface IEssentials
+{
+ void addReloadListener(IConf listener);
+
+ void reload();
+
+ boolean onCommandEssentials(CommandSender sender, Command command, String commandLabel, String[] args, ClassLoader classLoader, String commandPath);
+
+ User getUser(Object base);
+
+ User getOfflineUser(String name);
+
+ World getWorld(String name);
+
+ int broadcastMessage(String name, String message);
+
+ Settings getSettings();
+
+ CraftScheduler getScheduler();
+
+ String[] getMotd(CommandSender sender, String def);
+
+ String[] getLines(CommandSender sender, String node, String def);
+
+ Jail getJail();
+
+ Warps getWarps();
+
+ Worth getWorth();
+
+ Backup getBackup();
+
+ Spawn getSpawn();
+
+ void loadBanList();
+
+ public boolean isRegisterFallbackEnabled();
+
+ public Methods getPaymentMethod();
+
+ Server getServer();
+
+ File getDataFolder();
+
+ PluginDescriptionFile getDescription();
+
+ int scheduleAsyncDelayedTask(Runnable run);
+
+ int scheduleSyncDelayedTask(Runnable run);
+
+ int scheduleSyncRepeatingTask(final Runnable run, long delay, long period);
+
+ List<String> getBans();
+
+ List<String> getBannedIps();
+}
diff --git a/Essentials/src/com/earth2me/essentials/IUser.java b/Essentials/src/com/earth2me/essentials/IUser.java
new file mode 100644
index 000000000..4cb69d7d7
--- /dev/null
+++ b/Essentials/src/com/earth2me/essentials/IUser.java
@@ -0,0 +1,51 @@
+package com.earth2me.essentials;
+
+import com.earth2me.essentials.commands.IEssentialsCommand;
+import java.net.InetSocketAddress;
+import org.bukkit.Location;
+import org.bukkit.entity.Player;
+import org.bukkit.inventory.PlayerInventory;
+
+
+public interface IUser
+{
+ int getHealth();
+
+ Location getLocation();
+
+ boolean isOnline();
+
+ void sendMessage(String string);
+
+ long getLastTeleportTimestamp();
+
+ boolean isAuthorized(String node);
+
+ boolean isAuthorized(IEssentialsCommand cmd);
+
+ void setLastTeleportTimestamp(long time);
+
+ Location getLastLocation();
+
+ Player getBase();
+
+ double getMoney();
+
+ void takeMoney(double value);
+
+ PlayerInventory getInventory();
+
+ void updateInventory();
+
+ String getGroup();
+
+ void setLastLocation();
+
+ Location getHome(Location location);
+
+ String getName();
+
+ InetSocketAddress getAddress();
+
+ String getDisplayName();
+}
diff --git a/Essentials/src/com/earth2me/essentials/InventoryWorkaround.java b/Essentials/src/com/earth2me/essentials/InventoryWorkaround.java
index 2a5b8ce75..425113daf 100644
--- a/Essentials/src/com/earth2me/essentials/InventoryWorkaround.java
+++ b/Essentials/src/com/earth2me/essentials/InventoryWorkaround.java
@@ -12,8 +12,12 @@ import org.bukkit.inventory.ItemStack;
* is accepted to CraftBukkit
*/
-public class InventoryWorkaround
+public final class InventoryWorkaround
{
+ private InventoryWorkaround()
+ {
+ }
+
public static int first(Inventory ci, ItemStack item, boolean forceDurability, boolean forceAmount)
{
return next(ci, item, 0, forceDurability, forceAmount);
diff --git a/Essentials/src/com/earth2me/essentials/ItemDb.java b/Essentials/src/com/earth2me/essentials/ItemDb.java
index b1e39eaea..8e42f3cb6 100644
--- a/Essentials/src/com/earth2me/essentials/ItemDb.java
+++ b/Essentials/src/com/earth2me/essentials/ItemDb.java
@@ -12,8 +12,12 @@ import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
-public class ItemDb
+public final class ItemDb
{
+ private ItemDb()
+ {
+ }
+
private final static Logger logger = Logger.getLogger("Minecraft");
private static Map<String, Integer> items = new HashMap<String, Integer>();
private static Map<String, Short> durabilities = new HashMap<String, Short>();
@@ -27,25 +31,35 @@ public class ItemDb
{
file.createNewFile();
InputStream res = ItemDb.class.getResourceAsStream("/items.csv");
- FileWriter tx = new FileWriter(file);
+ FileWriter tx = null;
try
{
+ tx = new FileWriter(file);
for (int i = 0; (i = res.read()) > 0;)
{
tx.write(i);
}
+ tx.flush();
}
finally
{
try
{
- tx.flush();
- tx.close();
res.close();
}
catch (Exception ex)
{
}
+ try
+ {
+ if (tx != null)
+ {
+ tx.close();
+ }
+ }
+ catch (Exception ex)
+ {
+ }
}
}
diff --git a/Essentials/src/com/earth2me/essentials/Jail.java b/Essentials/src/com/earth2me/essentials/Jail.java
index d27593ada..a73bb0948 100644
--- a/Essentials/src/com/earth2me/essentials/Jail.java
+++ b/Essentials/src/com/earth2me/essentials/Jail.java
@@ -13,10 +13,10 @@ import org.bukkit.event.block.BlockPlaceEvent;
public class Jail extends BlockListener implements IConf
{
private static final Logger logger = Logger.getLogger("Minecraft");
- private EssentialsConf config;
- private Essentials ess;
+ private final EssentialsConf config;
+ private final IEssentials ess;
- public Jail(Essentials ess)
+ public Jail(IEssentials ess)
{
this.ess = ess;
config = new EssentialsConf(new File(ess.getDataFolder(), "jail.yml"));
@@ -36,7 +36,7 @@ public class Jail extends BlockListener implements IConf
throw new Exception(Util.i18n("jailNotExist"));
}
- Location loc = config.getLocation(jailName.toLowerCase(), Essentials.getStatic().getServer());
+ Location loc = config.getLocation(jailName.toLowerCase(), ess.getServer());
return loc;
}
diff --git a/Essentials/src/com/earth2me/essentials/JailPlayerListener.java b/Essentials/src/com/earth2me/essentials/JailPlayerListener.java
index 54f8d8c56..865485d8b 100644
--- a/Essentials/src/com/earth2me/essentials/JailPlayerListener.java
+++ b/Essentials/src/com/earth2me/essentials/JailPlayerListener.java
@@ -6,9 +6,9 @@ import org.bukkit.event.player.PlayerListener;
public class JailPlayerListener extends PlayerListener
{
- private final Essentials ess;
+ private final IEssentials ess;
- public JailPlayerListener(Essentials parent)
+ public JailPlayerListener(IEssentials parent)
{
this.ess = parent;
}
diff --git a/Essentials/src/com/earth2me/essentials/Mob.java b/Essentials/src/com/earth2me/essentials/Mob.java
index 960f52cca..771d54abe 100644
--- a/Essentials/src/com/earth2me/essentials/Mob.java
+++ b/Essentials/src/com/earth2me/essentials/Mob.java
@@ -2,6 +2,8 @@ package com.earth2me.essentials;
import java.lang.reflect.Constructor;
import java.util.HashMap;
+import java.util.Map;
+import java.util.logging.Level;
import java.util.logging.Logger;
import net.minecraft.server.Entity;
import net.minecraft.server.WorldServer;
@@ -68,7 +70,7 @@ public enum Mob
public Enemies type;
private String entityClass;
private String craftClass;
- private static final HashMap<String, Mob> hashMap = new HashMap<String, Mob>();
+ private static final Map<String, Mob> hashMap = new HashMap<String, Mob>();
static
{
@@ -93,9 +95,8 @@ public enum Mob
}
catch (Exception ex)
{
- logger.warning(Util.i18n("unableToSpawnMob"));
- ex.printStackTrace();
- throw new MobException();
+ logger.log(Level.WARNING, Util.i18n("unableToSpawnMob"), ex);
+ throw new MobException(ex);
}
}
@@ -114,9 +115,14 @@ public enum Mob
}
- public class MobException extends Exception
+ public static class MobException extends Exception
{
private static final long serialVersionUID = 1L;
+
+ private MobException(Exception ex)
+ {
+ super(ex);
+ }
}
public static Mob fromName(String n)
diff --git a/Essentials/src/com/earth2me/essentials/PlayerExtension.java b/Essentials/src/com/earth2me/essentials/PlayerExtension.java
index 7c784f4bc..901edd345 100644
--- a/Essentials/src/com/earth2me/essentials/PlayerExtension.java
+++ b/Essentials/src/com/earth2me/essentials/PlayerExtension.java
@@ -4,24 +4,27 @@ import org.bukkit.craftbukkit.entity.CraftPlayer;
import net.minecraft.server.EntityPlayer;
import net.minecraft.server.IInventory;
import org.bukkit.craftbukkit.inventory.CraftInventoryPlayer;
-import org.bukkit.entity.*;
+import org.bukkit.entity.Player;
public class PlayerExtension extends PlayerWrapper
{
- public PlayerExtension(Player base)
+ protected final IEssentials ess;
+
+ public PlayerExtension(Player base, IEssentials ess)
{
super(base);
+ this.ess = ess;
}
public boolean isBanned()
{
- return Essentials.getStatic().bans.contains(getName());
+ return ess.getBans().contains(getName());
}
public boolean isIpBanned()
{
- return Essentials.getStatic().bannedIps.contains(getAddress().getAddress().toString().replace("/", ""));
+ return ess.getBannedIps().contains(getAddress().getAddress().toString().replace("/", ""));
}
public float getCorrectedYaw()
diff --git a/Essentials/src/com/earth2me/essentials/Settings.java b/Essentials/src/com/earth2me/essentials/Settings.java
index 23ca6f3ba..461f8908f 100644
--- a/Essentials/src/com/earth2me/essentials/Settings.java
+++ b/Essentials/src/com/earth2me/essentials/Settings.java
@@ -1,19 +1,21 @@
package com.earth2me.essentials;
-import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.ChatColor;
import com.earth2me.essentials.commands.IEssentialsCommand;
import java.io.File;
import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import org.bukkit.entity.CreatureType;
import org.bukkit.inventory.ItemStack;
public class Settings implements IConf
{
- private EssentialsConf config;
+ private final EssentialsConf config;
private final static Logger logger = Logger.getLogger("Minecraft");
public Settings(File dataFolder)
@@ -58,7 +60,7 @@ public class Settings implements IConf
return isNetherEnabled() && config.getBoolean("nether.portals-enabled", false);
}
- public boolean isCommandDisabled(IEssentialsCommand cmd)
+ public boolean isCommandDisabled(final IEssentialsCommand cmd)
{
return isCommandDisabled(cmd.getName());
}
@@ -121,7 +123,7 @@ public class Settings implements IConf
public String getNicknamePrefix()
{
- return config.getString("nickname-prefix", "");
+ return config.getString("nickname-prefix", "~");
}
public double getTeleportCooldown()
@@ -145,6 +147,11 @@ public class Settings implements IConf
}
return null;
}
+
+ public Map<String, Object> getKits()
+ {
+ return (Map<String, Object>)config.getProperty("kits");
+ }
public ChatColor getOperatorColor() throws Exception
{
@@ -191,9 +198,9 @@ public class Settings implements IConf
return config.getBoolean("non-ess-in-help", true);
}
- public HashMap<String, Boolean> getEpSettings()
+ public Map<String, Boolean> getEpSettings()
{
- HashMap<String, Boolean> epSettings = new HashMap<String, Boolean>();
+ Map<String, Boolean> epSettings = new HashMap<String, Boolean>();
epSettings.put("protect.protect.signs", config.getBoolean("protect.protect.signs", true));
epSettings.put("protect.protect.rails", config.getBoolean("protect.protect.rails", true));
@@ -202,9 +209,9 @@ public class Settings implements IConf
return epSettings;
}
- public HashMap<String, String> getEpDBSettings()
+ public Map<String, String> getEpDBSettings()
{
- HashMap<String, String> epSettings = new HashMap<String, String>();
+ Map<String, String> epSettings = new HashMap<String, String>();
epSettings.put("protect.datatype", config.getString("protect.datatype", "sqlite"));
epSettings.put("protect.username", config.getString("protect.username", "root"));
epSettings.put("protect.password", config.getString("protect.password", "root"));
@@ -212,9 +219,9 @@ public class Settings implements IConf
return epSettings;
}
- public ArrayList<Integer> getEpAlertOnPlacement()
+ public List<Integer> getEpAlertOnPlacement()
{
- ArrayList<Integer> epAlertPlace = new ArrayList<Integer>();
+ final List<Integer> epAlertPlace = new ArrayList<Integer>();
for (String itemName : config.getString("protect.alert.on-placement", "").split(",")) {
itemName = itemName.trim();
if (itemName.isEmpty()) {
@@ -231,9 +238,9 @@ public class Settings implements IConf
return epAlertPlace;
}
- public ArrayList<Integer> getEpAlertOnUse()
+ public List<Integer> getEpAlertOnUse()
{
- ArrayList<Integer> epAlertUse = new ArrayList<Integer>();
+ final List<Integer> epAlertUse = new ArrayList<Integer>();
for (String itemName : config.getString("protect.alert.on-use", "").split(",")) {
itemName = itemName.trim();
if (itemName.isEmpty()) {
@@ -250,9 +257,9 @@ public class Settings implements IConf
return epAlertUse;
}
- public ArrayList<Integer> getEpAlertOnBreak()
+ public List<Integer> getEpAlertOnBreak()
{
- ArrayList<Integer> epAlertPlace = new ArrayList<Integer>();
+ final List<Integer> epAlertPlace = new ArrayList<Integer>();
for (String itemName : config.getString("protect.alert.on-break", "").split(",")) {
itemName = itemName.trim();
if (itemName.isEmpty()) {
@@ -269,9 +276,9 @@ public class Settings implements IConf
return epAlertPlace;
}
- public ArrayList<Integer> epBlackListPlacement()
+ public List<Integer> epBlackListPlacement()
{
- ArrayList<Integer> epBlacklistPlacement = new ArrayList<Integer>();
+ final List<Integer> epBlacklistPlacement = new ArrayList<Integer>();
for (String itemName : config.getString("protect.blacklist.placement", "").split(",")) {
itemName = itemName.trim();
if (itemName.isEmpty()) {
@@ -288,9 +295,9 @@ public class Settings implements IConf
return epBlacklistPlacement;
}
- public ArrayList<Integer> epBlackListUsage()
+ public List<Integer> epBlackListUsage()
{
- ArrayList<Integer> epBlackListUsage = new ArrayList<Integer>();
+ final List<Integer> epBlackListUsage = new ArrayList<Integer>();
for (String itemName : config.getString("protect.blacklist.usage", "").split(",")) {
itemName = itemName.trim();
if (itemName.isEmpty()) {
@@ -307,9 +314,9 @@ public class Settings implements IConf
return epBlackListUsage;
}
- public HashMap<String, Boolean> getEpGuardSettings()
+ public Map<String, Boolean> getEpGuardSettings()
{
- HashMap<String, Boolean> epSettings = new HashMap<String, Boolean>();
+ final Map<String, Boolean> epSettings = new HashMap<String, Boolean>();
epSettings.put("protect.prevent.lava-flow", config.getBoolean("protect.prevent.lava-flow", false));
epSettings.put("protect.prevent.water-flow", config.getBoolean("protect.prevent.water-flow", false));
epSettings.put("protect.prevent.water-bucket-flow", config.getBoolean("protect.prevent.water-bucket-flow", false));
@@ -323,16 +330,16 @@ public class Settings implements IConf
epSettings.put("protect.prevent.creeper-blockdamage", config.getBoolean("protect.prevent.creeper-blockdamage", false));
epSettings.put("protect.prevent.entitytarget", config.getBoolean("protect.prevent.entitytarget", false));
for (CreatureType ct : CreatureType.values()) {
- String name = ct.toString().toLowerCase();
+ final String name = ct.toString().toLowerCase();
epSettings.put("protect.prevent.spawn."+name, config.getBoolean("protect.prevent.spawn."+name, false));
}
epSettings.put("protect.prevent.lightning-fire-spread", config.getBoolean("protect.prevent.lightning-fire-spread", true));
return epSettings;
}
- public HashMap<String, Boolean> getEpPlayerSettings()
+ public Map<String, Boolean> getEpPlayerSettings()
{
- HashMap<String, Boolean> epPlayerSettings = new HashMap<String, Boolean>();
+ final Map<String, Boolean> epPlayerSettings = new HashMap<String, Boolean>();
epPlayerSettings.put("protect.disable.fall", config.getBoolean("protect.disable.fall", false));
epPlayerSettings.put("protect.disable.pvp", config.getBoolean("protect.disable.pvp", false));
epPlayerSettings.put("protect.disable.drown", config.getBoolean("protect.disable.drown", false));
@@ -386,12 +393,12 @@ public class Settings implements IConf
return !config.getString("newbies.announce-format", "-").isEmpty();
}
- public String getAnnounceNewPlayerFormat(User user)
+ public String getAnnounceNewPlayerFormat(IUser user)
{
return format(config.getString("newbies.announce-format", "&dWelcome {DISPLAYNAME} to the server!"), user);
}
- public String format(String format, User user)
+ public String format(String format, IUser user)
{
return format.replace('&', '§').replace("§§", "&").replace("{PLAYER}", user.getDisplayName()).replace("{DISPLAYNAME}", user.getDisplayName()).replace("{GROUP}", user.getGroup()).replace("{USERNAME}", user.getName()).replace("{ADDRESS}", user.getAddress().toString());
}
@@ -499,4 +506,14 @@ public class Settings implements IConf
{
return config.getString("currency-symbol", "$").substring(0, 1).replaceAll("[0-9]", "$");
}
+
+ public boolean isTradeInStacks(int id)
+ {
+ return config.getBoolean("trade-in-stacks-" + id, false);
+ }
+
+ public boolean isEcoDisabled()
+ {
+ return config.getBoolean("disable-eco", false);
+ }
}
diff --git a/Essentials/src/com/earth2me/essentials/Spawn.java b/Essentials/src/com/earth2me/essentials/Spawn.java
index f3c4de06a..283984231 100644
--- a/Essentials/src/com/earth2me/essentials/Spawn.java
+++ b/Essentials/src/com/earth2me/essentials/Spawn.java
@@ -12,8 +12,8 @@ import org.bukkit.World.Environment;
public class Spawn implements IConf {
private static final Logger logger = Logger.getLogger("Minecraft");
- private EssentialsConf config;
- private Server server;
+ private final EssentialsConf config;
+ private final Server server;
public Spawn(Server server, File dataFolder) {
File configFile = new File(dataFolder, "spawn.yml");
diff --git a/Essentials/src/com/earth2me/essentials/TargetBlock.java b/Essentials/src/com/earth2me/essentials/TargetBlock.java
index d3ac30d2d..ec9cd796e 100644
--- a/Essentials/src/com/earth2me/essentials/TargetBlock.java
+++ b/Essentials/src/com/earth2me/essentials/TargetBlock.java
@@ -21,7 +21,7 @@ public class TargetBlock {
private Vector targetPos = new Vector();
private Vector targetPosDouble = new Vector();
private Vector prevPos = new Vector();
- private Vector offset = new Vector();
+ private final Vector offset = new Vector();
/**
* Constructor requiring a player, uses default values
diff --git a/Essentials/src/com/earth2me/essentials/Teleport.java b/Essentials/src/com/earth2me/essentials/Teleport.java
index d0f137b9b..404319ca8 100644
--- a/Essentials/src/com/earth2me/essentials/Teleport.java
+++ b/Essentials/src/com/earth2me/essentials/Teleport.java
@@ -12,17 +12,19 @@ public class Teleport implements Runnable
{
private static class Target
{
- private Location location = null;
- private Entity entity = null;
+ private final Location location;
+ private final Entity entity;
public Target(Location location)
{
this.location = location;
+ this.entity = null;
}
public Target(Entity entity)
{
this.entity = entity;
+ this.location = null;
}
public Location getLocation()
@@ -34,7 +36,7 @@ public class Teleport implements Runnable
return location;
}
}
- User user;
+ private IUser user;
private int teleTimer = -1;
private long started; // time this task was initiated
private long delay; // how long to delay the teleport
@@ -47,7 +49,7 @@ public class Teleport implements Runnable
private long initZ;
private Target teleportTarget;
private Charge chargeFor;
- private Essentials ess;
+ private final IEssentials ess;
private static final Logger logger = Logger.getLogger("Minecraft");
private void initTimer(long delay, Target target, Charge chargeFor)
@@ -114,7 +116,7 @@ public class Teleport implements Runnable
}
}
- public Teleport(User user, Essentials ess)
+ public Teleport(IUser user, IEssentials ess)
{
this.user = user;
this.ess = ess;
@@ -127,7 +129,7 @@ public class Teleport implements Runnable
public void warp(String warp, Charge chargeFor) throws Exception
{
- Location loc = Essentials.getWarps().getWarp(warp);
+ Location loc = ess.getWarps().getWarp(warp);
teleport(new Target(loc), chargeFor);
user.sendMessage(Util.format("warpingTo", warp));
}
@@ -162,7 +164,7 @@ public class Teleport implements Runnable
}
try
{
- user.getServer().getScheduler().cancelTask(teleTimer);
+ ess.getServer().getScheduler().cancelTask(teleTimer);
if (notifyUser)
{
user.sendMessage(Util.i18n("pendingTeleportCancelled"));
@@ -193,7 +195,10 @@ public class Teleport implements Runnable
{
double delay = ess.getSettings().getTeleportDelay();
- chargeFor.isAffordableFor(user);
+ if (chargeFor != null)
+ {
+ chargeFor.isAffordableFor(user);
+ }
cooldown(true);
if (delay <= 0 || user.isAuthorized("essentials.teleport.timer.bypass"))
{
@@ -213,7 +218,7 @@ public class Teleport implements Runnable
user.sendMessage(Util.format("dontMoveMessage", Util.formatDateDiff(c.getTimeInMillis())));
initTimer((long)(delay * 1000.0), target, chargeFor);
- teleTimer = user.getServer().getScheduler().scheduleSyncRepeatingTask(Essentials.getStatic(), this, 10, 10);
+ teleTimer = ess.scheduleSyncRepeatingTask(this, 10, 10);
}
private void now(Target target) throws Exception
@@ -242,7 +247,7 @@ public class Teleport implements Runnable
now(new Target(entity));
}
- public void back(final Charge chargeFor) throws Exception
+ public void back(Charge chargeFor) throws Exception
{
teleport(new Target(user.getLastLocation()), chargeFor);
}
@@ -257,14 +262,14 @@ public class Teleport implements Runnable
home(user, chargeFor);
}
- public void home(User user, Charge chargeFor) throws Exception
+ public void home(IUser user, Charge chargeFor) throws Exception
{
Location loc = user.getHome(this.user.getLocation());
if (loc == null)
{
if (ess.getSettings().spawnIfNoHome())
{
- respawn(Essentials.getSpawn(), chargeFor);
+ respawn(ess.getSpawn(), chargeFor);
}
else
{
diff --git a/Essentials/src/com/earth2me/essentials/User.java b/Essentials/src/com/earth2me/essentials/User.java
index c8ef473c0..8365aabe3 100644
--- a/Essentials/src/com/earth2me/essentials/User.java
+++ b/Essentials/src/com/earth2me/essentials/User.java
@@ -10,17 +10,17 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
-public class User extends UserData implements Comparable<User>, IReplyTo
+public class User extends UserData implements Comparable<User>, IReplyTo, IUser
{
private static final Logger logger = Logger.getLogger("Minecraft");
private boolean justPortaled = false;
private CommandSender replyTo = null;
private User teleportRequester;
private boolean teleportRequestHere;
- private Teleport teleport;
+ private final Teleport teleport;
private long lastActivity;
- User(Player base, Essentials ess)
+ User(Player base, IEssentials ess)
{
super(base, ess);
teleport = new Teleport(this, ess);
@@ -120,14 +120,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo
public boolean canAfford(double cost)
{
double mon = getMoney();
- if (mon < cost && !isAuthorized("essentials.eco.loan"))
- {
- return false;
- }
- else
- {
- return true;
- }
+ return mon >= cost || isAuthorized("essentials.eco.loan");
}
public void dispose()
@@ -160,6 +153,23 @@ public class User extends UserData implements Comparable<User>, IReplyTo
return ChatColor.stripColor(this.getDisplayName()).compareToIgnoreCase(ChatColor.stripColor(t.getDisplayName()));
}
+ @Override
+ public boolean equals(Object o)
+ {
+ if (!(o instanceof User))
+ {
+ return false;
+ }
+ return ChatColor.stripColor(this.getDisplayName()).equalsIgnoreCase(ChatColor.stripColor(((User) o).getDisplayName()));
+
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return ChatColor.stripColor(this.getDisplayName()).hashCode();
+ }
+
public Boolean canSpawnItem(int itemId)
{
return !ess.getSettings().itemSpawnBlacklist().contains(itemId);
diff --git a/Essentials/src/com/earth2me/essentials/UserData.java b/Essentials/src/com/earth2me/essentials/UserData.java
index 782995159..e9f05b8bd 100644
--- a/Essentials/src/com/earth2me/essentials/UserData.java
+++ b/Essentials/src/com/earth2me/essentials/UserData.java
@@ -16,14 +16,12 @@ import org.bukkit.inventory.ItemStack;
public abstract class UserData extends PlayerExtension implements IConf
{
- private EssentialsConf config;
+ private final EssentialsConf config;
private static final Logger logger = Logger.getLogger("Minecraft");
- protected Essentials ess;
- protected UserData(Player base, Essentials ess)
+ protected UserData(Player base, IEssentials ess)
{
- super(base);
- this.ess = ess;
+ super(base, ess);
File folder = new File(ess.getDataFolder(), "userdata");
if (!folder.exists())
{
@@ -61,7 +59,7 @@ public abstract class UserData extends PlayerExtension implements IConf
isNPC = _isNPC();
}
- double money;
+ private double money;
private double _getMoney() {
if (config.hasProperty("money"))
@@ -175,7 +173,7 @@ public abstract class UserData extends PlayerExtension implements IConf
private Map<Integer, String> getPowertools()
{
Object o = config.getProperty("powertools");
- if (o != null && o instanceof Map)
+ if (o instanceof Map)
{
return (Map<Integer, String>)o;
}
@@ -702,7 +700,7 @@ public abstract class UserData extends PlayerExtension implements IConf
return isNPC;
}
- void setNPC(boolean set)
+ public void setNPC(boolean set)
{
isNPC = set;
config.setProperty("npc", set);
diff --git a/Essentials/src/com/earth2me/essentials/Util.java b/Essentials/src/com/earth2me/essentials/Util.java
index faed72ae6..442150fa3 100644
--- a/Essentials/src/com/earth2me/essentials/Util.java
+++ b/Essentials/src/com/earth2me/essentials/Util.java
@@ -29,8 +29,11 @@ import org.bukkit.block.Block;
public class Util
{
+ private Util()
+ {
+ }
private final static Logger logger = Logger.getLogger("Minecraft");
-
+
public static String sanitizeFileName(String name)
{
return name.toLowerCase().replaceAll("[^a-z0-9]", "_");
@@ -97,7 +100,7 @@ public class Util
}
private static int dateDiff(int type, Calendar fromDate, Calendar toDate, boolean future)
- {
+ {
int diff = 0;
long savedDate = fromDate.getTimeInMillis();
while ((future && !fromDate.after(toDate)) || (!future && !fromDate.before(toDate)))
@@ -296,11 +299,16 @@ public class Util
return Math.round(d * 100.0) / 100.0;
}
+ public static Locale getCurrentLocale()
+ {
+ return currentLocale;
+ }
+
private static class ConfigClassLoader extends ClassLoader
{
- private File dataFolder;
- private ClassLoader cl;
+ private final File dataFolder;
+ private final ClassLoader cl;
public ConfigClassLoader(File dataFolder, ClassLoader cl)
{
@@ -389,16 +397,17 @@ public class Util
}
}
private static final Locale defaultLocale = Locale.getDefault();
- public static Locale currentLocale = defaultLocale;
+ private static Locale currentLocale = defaultLocale;
private static ResourceBundle bundle = ResourceBundle.getBundle("messages", defaultLocale);
private static ResourceBundle defaultBundle = ResourceBundle.getBundle("messages", Locale.US);
public static String i18n(String string)
{
- try {
+ try
+ {
return bundle.getString(string);
}
- catch (MissingResourceException ex)
+ catch (MissingResourceException ex)
{
logger.log(Level.WARNING, String.format("Missing translation key \"%s\" in translation file %s", ex.getKey(), bundle.getLocale().toString()), ex);
return defaultBundle.getString(string);
@@ -432,7 +441,8 @@ public class Util
}
logger.log(Level.INFO, String.format("Using locale %s", currentLocale.toString()));
bundle = ResourceBundle.getBundle("messages", currentLocale, new ConfigClassLoader(dataFolder, Util.class.getClassLoader()));
- if (!bundle.keySet().containsAll(defaultBundle.keySet())) {
+ if (!bundle.keySet().containsAll(defaultBundle.keySet()))
+ {
logger.log(Level.WARNING, String.format("Translation file %s does not contain all translation keys.", currentLocale.toString()));
}
}
diff --git a/Essentials/src/com/earth2me/essentials/Warps.java b/Essentials/src/com/earth2me/essentials/Warps.java
index 4aed8213a..b1d27e0b2 100644
--- a/Essentials/src/com/earth2me/essentials/Warps.java
+++ b/Essentials/src/com/earth2me/essentials/Warps.java
@@ -15,9 +15,9 @@ import org.bukkit.Server;
public class Warps implements IConf
{
private static final Logger logger = Logger.getLogger("Minecraft");
- Map<StringIgnoreCase, EssentialsConf> warpPoints = new HashMap<StringIgnoreCase, EssentialsConf>();
- File warpsFolder;
- Server server;
+ private final Map<StringIgnoreCase, EssentialsConf> warpPoints = new HashMap<StringIgnoreCase, EssentialsConf>();
+ private final File warpsFolder;
+ private final Server server;
public Warps(Server server, File dataFolder)
{
@@ -40,7 +40,7 @@ public class Warps implements IConf
List<String> keys = new ArrayList<String>();
for (StringIgnoreCase stringIgnoreCase : warpPoints.keySet())
{
- keys.add(stringIgnoreCase.string);
+ keys.add(stringIgnoreCase.getString());
}
Collections.sort(keys, String.CASE_INSENSITIVE_ORDER);
return keys;
@@ -120,9 +120,9 @@ public class Warps implements IConf
}
- private class StringIgnoreCase
+ private static class StringIgnoreCase
{
- String string;
+ private final String string;
public StringIgnoreCase(String string)
{
@@ -132,21 +132,22 @@ public class Warps implements IConf
@Override
public int hashCode()
{
- return string.toLowerCase().hashCode();
+ return getString().toLowerCase().hashCode();
}
@Override
public boolean equals(Object o)
{
- if (o instanceof String)
- {
- return string.equalsIgnoreCase((String)o);
- }
if (o instanceof StringIgnoreCase)
{
- return string.equalsIgnoreCase(((StringIgnoreCase)o).string);
+ return getString().equalsIgnoreCase(((StringIgnoreCase)o).getString());
}
return false;
}
+
+ public String getString()
+ {
+ return string;
+ }
}
}
diff --git a/Essentials/src/com/earth2me/essentials/Worth.java b/Essentials/src/com/earth2me/essentials/Worth.java
index 470386544..66cdf1f9c 100644
--- a/Essentials/src/com/earth2me/essentials/Worth.java
+++ b/Essentials/src/com/earth2me/essentials/Worth.java
@@ -8,7 +8,7 @@ import org.bukkit.inventory.ItemStack;
public class Worth implements IConf
{
private static final Logger logger = Logger.getLogger("Minecraft");
- private EssentialsConf config;
+ private final EssentialsConf config;
public Worth(File dataFolder)
{
diff --git a/Essentials/src/com/earth2me/essentials/api/Economy.java b/Essentials/src/com/earth2me/essentials/api/Economy.java
index d609bac67..768168a24 100644
--- a/Essentials/src/com/earth2me/essentials/api/Economy.java
+++ b/Essentials/src/com/earth2me/essentials/api/Economy.java
@@ -14,8 +14,11 @@ import org.bukkit.entity.Player;
* Instead of using this api directly, we recommend to use the register plugin:
* http://bit.ly/RegisterMethod
*/
-public class Economy
+public final class Economy
{
+ private Economy()
+ {
+ }
private static final Logger logger = Logger.getLogger("Minecraft");
private static void createNPCFile(String name)
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandback.java b/Essentials/src/com/earth2me/essentials/commands/Commandback.java
index a244a4e3a..c852a7f99 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandback.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandback.java
@@ -16,7 +16,7 @@ public class Commandback extends EssentialsCommand
@Override
protected void run(Server server, User user, String commandLabel, String[] args) throws Exception
{
- Charge charge = new Charge(this);
+ Charge charge = new Charge(this.getName(), ess);
charge.isAffordableFor(user);
user.sendMessage(Util.i18n("backUsageMsg"));
user.getTeleport().back(charge);
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbackup.java b/Essentials/src/com/earth2me/essentials/commands/Commandbackup.java
index 7a1fe02c7..8f6e8e8bf 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandbackup.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandbackup.java
@@ -1,7 +1,6 @@
package com.earth2me.essentials.commands;
import com.earth2me.essentials.Backup;
-import com.earth2me.essentials.Essentials;
import com.earth2me.essentials.Util;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
@@ -17,7 +16,7 @@ public class Commandbackup extends EssentialsCommand
@Override
protected void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception
{
- Backup backup = Essentials.getBackup();
+ Backup backup = ess.getBackup();
if (backup == null)
{
return;
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbigtree.java b/Essentials/src/com/earth2me/essentials/commands/Commandbigtree.java
index 16c94793b..00686c9b7 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandbigtree.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandbigtree.java
@@ -17,7 +17,7 @@ public class Commandbigtree extends EssentialsCommand
@Override
public void run(Server server, User user, String commandLabel, String[] args) throws Exception
{
- Object tree = new Object();
+ TreeType tree = TreeType.TREE;
if (args.length > 0 && args[0].equalsIgnoreCase("redwood"))
{
tree = TreeType.TALL_REDWOOD;
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commanddeljail.java b/Essentials/src/com/earth2me/essentials/commands/Commanddeljail.java
index 63857ade8..7fb6f816c 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commanddeljail.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commanddeljail.java
@@ -1,6 +1,5 @@
package com.earth2me.essentials.commands;
-import com.earth2me.essentials.Essentials;
import com.earth2me.essentials.Util;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
@@ -18,7 +17,7 @@ public class Commanddeljail extends EssentialsCommand {
throw new NotEnoughArgumentsException();
}
charge(sender);
- Essentials.getJail().delJail(args[0]);
+ ess.getJail().delJail(args[0]);
sender.sendMessage(Util.format("deleteJail", args[0]));
}
}
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commanddelwarp.java b/Essentials/src/com/earth2me/essentials/commands/Commanddelwarp.java
index 0c1cee421..42a68dda8 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commanddelwarp.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commanddelwarp.java
@@ -2,7 +2,6 @@ package com.earth2me.essentials.commands;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
-import com.earth2me.essentials.Essentials;
import com.earth2me.essentials.Util;
@@ -21,7 +20,7 @@ public class Commanddelwarp extends EssentialsCommand
throw new NotEnoughArgumentsException();
}
charge(sender);
- Essentials.getWarps().delWarp(args[0]);
+ ess.getWarps().delWarp(args[0]);
sender.sendMessage(Util.format("deleteWarp", args[0]));
}
}
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandeco.java b/Essentials/src/com/earth2me/essentials/commands/Commandeco.java
index 3f93791e7..085fac900 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandeco.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandeco.java
@@ -30,7 +30,7 @@ public class Commandeco extends EssentialsCommand
}
catch (Exception ex)
{
- throw new NotEnoughArgumentsException();
+ throw new NotEnoughArgumentsException(ex);
}
if (args[1].contentEquals("*"))
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandhelp.java b/Essentials/src/com/earth2me/essentials/commands/Commandhelp.java
index 31ae0f395..52277b1fa 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandhelp.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandhelp.java
@@ -14,6 +14,7 @@ import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.SafeConstructor;
import com.earth2me.essentials.User;
import com.earth2me.essentials.Util;
+import java.util.Map.Entry;
import java.util.logging.Level;
@@ -71,10 +72,18 @@ public class Commandhelp extends EssentialsCommand
}
if (helpFile.exists())
{
- BufferedReader rx = new BufferedReader(new FileReader(helpFile));
- for (String l = null; rx.ready() && (l = rx.readLine()) != null;)
+ final BufferedReader bufferedReader = new BufferedReader(new FileReader(helpFile));
+ try {
+
+ while (bufferedReader.ready())
+ {
+ final String line = bufferedReader.readLine();
+ retval.add(line.replace('&', '§'));
+ }
+ }
+ finally
{
- retval.add(l.replace('&', '§'));
+ bufferedReader.close();
}
return retval;
}
@@ -85,17 +94,16 @@ public class Commandhelp extends EssentialsCommand
{
try
{
- PluginDescriptionFile desc = p.getDescription();
- HashMap<String, HashMap<String, String>> cmds = (HashMap<String, HashMap<String, String>>)desc.getCommands();
- for (String k : cmds.keySet())
+ final PluginDescriptionFile desc = p.getDescription();
+ final HashMap<String, HashMap<String, String>> cmds = (HashMap<String, HashMap<String, String>>)desc.getCommands();
+ for (Entry<String, HashMap<String, String>> k : cmds.entrySet())
{
if (p.getDescription().getName().toLowerCase().contains("essentials"))
{
- String node = "essentials." + k;
- if (!ess.getSettings().isCommandDisabled(k) && user.isAuthorized(node))
+ final String node = "essentials." + k.getKey();
+ if (!ess.getSettings().isCommandDisabled(k.getKey()) && user.isAuthorized(node))
{
- HashMap<String, String> v = cmds.get(k);
- retval.add("§c" + k + "§7: " + v.get("description"));
+ retval.add("§c" + k.getKey() + "§7: " + k.getValue().get("description"));
}
}
else
@@ -103,17 +111,17 @@ public class Commandhelp extends EssentialsCommand
if (ess.getSettings().showNonEssCommandsInHelp())
{
pluginName = p.getDescription().getName();
- HashMap<String, String> v = cmds.get(k);
- if (v.containsKey("permission") && v.get("permission") != null && !(v.get("permission").equals("")))
+ final HashMap<String, String> value = k.getValue();
+ if (value.containsKey("permission") && value.get("permission") != null && !(value.get("permission").equals("")))
{
- if (user.isAuthorized(v.get("permission")))
+ if (user.isAuthorized(value.get("permission")))
{
- retval.add("§c" + k + "§7: " + v.get("description"));
+ retval.add("§c" + k.getKey() + "§7: " + value.get("description"));
}
}
else
{
- retval.add("§c" + k + "§7: " + v.get("description"));
+ retval.add("§c" + k.getKey() + "§7: " + value.get("description"));
}
}
@@ -128,10 +136,7 @@ public class Commandhelp extends EssentialsCommand
{
if (!reported)
{
- logger.log(Level.WARNING, "Error getting help for:" + pluginName);
- ex.printStackTrace();
-
-
+ logger.log(Level.WARNING, "Error getting help for:" + pluginName, ex);
}
reported = true;
continue;
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandhome.java b/Essentials/src/com/earth2me/essentials/commands/Commandhome.java
index a5cde8d3f..c71ba4b0e 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandhome.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandhome.java
@@ -16,7 +16,7 @@ public class Commandhome extends EssentialsCommand
@Override
public void run(Server server, User user, String commandLabel, String[] args) throws Exception
{
- Charge charge = new Charge(this);
+ Charge charge = new Charge(this.getName(), ess);
charge.isAffordableFor(user);
if(args.length > 0 && user.isAuthorized("essentials.home.others"))
{
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandinfo.java b/Essentials/src/com/earth2me/essentials/commands/Commandinfo.java
index 664cfb67b..4db469b58 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandinfo.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandinfo.java
@@ -45,16 +45,25 @@ public class Commandinfo extends EssentialsCommand
}
if (file.exists())
{
- BufferedReader rx = new BufferedReader(new FileReader(file));
- int i = 0;
- for (String l = null; rx.ready() && (l = rx.readLine()) != null; i++)
+ final BufferedReader bufferedReader = new BufferedReader(new FileReader(file));
+ try
{
- if (l.startsWith("#"))
+ int lineNumber = 0;
+ while (bufferedReader.ready())
{
- bookmarks.put(l.substring(1).toLowerCase().replaceAll("&[0-9a-f]", ""), i);
- chapters.add(l.substring(1).replace('&', '§'));
+ final String line = bufferedReader.readLine();
+ if (line.length() > 0 && line.charAt(0) == '#')
+ {
+ bookmarks.put(line.substring(1).toLowerCase().replaceAll("&[0-9a-f]", ""), lineNumber);
+ chapters.add(line.substring(1).replace('&', '§'));
+ }
+ lines.add(line.replace('&', '§'));
+ lineNumber++;
}
- lines.add(l.replace('&', '§'));
+ }
+ finally
+ {
+ bufferedReader.close();
}
}
else
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandjails.java b/Essentials/src/com/earth2me/essentials/commands/Commandjails.java
index 73a2a9bfd..b91a1c985 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandjails.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandjails.java
@@ -1,6 +1,5 @@
package com.earth2me.essentials.commands;
-import com.earth2me.essentials.Essentials;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
@@ -16,7 +15,7 @@ public class Commandjails extends EssentialsCommand
protected void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception
{
StringBuilder jailList = new StringBuilder();
- for (String j : Essentials.getJail().getJails())
+ for (String j : ess.getJail().getJails())
{
jailList.append(j);
jailList.append(' ');
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandjump.java b/Essentials/src/com/earth2me/essentials/commands/Commandjump.java
index d1dd5c763..42ef0d424 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandjump.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandjump.java
@@ -36,7 +36,7 @@ public class Commandjump extends EssentialsCommand
throw new Exception(Util.i18n("jumpError"), ex);
}
- Charge charge = new Charge(this);
+ Charge charge = new Charge(this.getName(), ess);
charge.isAffordableFor(user);
user.getTeleport().teleport(loc, charge);
}
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandkit.java b/Essentials/src/com/earth2me/essentials/commands/Commandkit.java
index 2badf51fc..e02a6d766 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandkit.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandkit.java
@@ -22,14 +22,13 @@ public class Commandkit extends EssentialsCommand
}
@Override
- @SuppressWarnings("unchecked")
public void run(Server server, User user, String commandLabel, String[] args) throws Exception
{
if (args.length < 1)
{
try
{
- Map<String, Object> kits = (Map<String, Object>)ess.getConfiguration().getProperty("kits");
+ Map<String, Object> kits = ess.getSettings().getKits();
StringBuilder list = new StringBuilder();
for (String k : kits.keySet())
{
@@ -110,7 +109,7 @@ public class Commandkit extends EssentialsCommand
items = (List<String>)kit;
}
- Charge charge = new Charge("kit-" + kitName);
+ Charge charge = new Charge("kit-" + kitName, ess);
try
{
charge.isAffordableFor(user);
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandnick.java b/Essentials/src/com/earth2me/essentials/commands/Commandnick.java
index e9431ddf3..3731b24c5 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandnick.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandnick.java
@@ -67,7 +67,7 @@ public class Commandnick extends EssentialsCommand
}
charge(user);
- user.setDisplayName(ess.getConfiguration().getString("nickname-prefix", "~") + nick);
+ user.setDisplayName(ess.getSettings().getNicknamePrefix() + nick);
user.setNickname(nick);
user.sendMessage(Util.format("nickSet", user.getDisplayName() + "§7."));
}
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java b/Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java
index 893161d93..c7bd34705 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandpowertool.java
@@ -22,6 +22,7 @@ public class Commandpowertool extends EssentialsCommand
if (is == null || is.getType() == Material.AIR)
{
user.sendMessage(Util.i18n("powerToolAir"));
+ return;
}
String command = getFinalArg(args, 0);
if (command != null && !command.isEmpty())
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandrules.java b/Essentials/src/com/earth2me/essentials/commands/Commandrules.java
index 349e40115..1b00bea47 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandrules.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandrules.java
@@ -1,7 +1,6 @@
package com.earth2me.essentials.commands;
import com.earth2me.essentials.Util;
-import com.earth2me.essentials.commands.EssentialsCommand;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsell.java b/Essentials/src/com/earth2me/essentials/commands/Commandsell.java
index f23a415af..155ee695c 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandsell.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandsell.java
@@ -89,9 +89,9 @@ public class Commandsell extends EssentialsCommand
amount = -amount;
}
}
- double worth = Essentials.getWorth().getPrice(is);
+ double worth = ess.getWorth().getPrice(is);
boolean stack = args.length > 1 && args[1].endsWith("s");
- boolean requireStack = ess.getConfiguration().getBoolean("trade-in-stacks-" + id, false);
+ boolean requireStack = ess.getSettings().isTradeInStacks(id);
if (Double.isNaN(worth))
{
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsetjail.java b/Essentials/src/com/earth2me/essentials/commands/Commandsetjail.java
index 590979797..047f1d28b 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandsetjail.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandsetjail.java
@@ -21,7 +21,7 @@ public class Commandsetjail extends EssentialsCommand
throw new NotEnoughArgumentsException();
}
charge(user);
- Essentials.getJail().setJail(user.getLocation(), args[0]);
+ ess.getJail().setJail(user.getLocation(), args[0]);
user.sendMessage(Util.format("jailSet",args[0]));
}
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsetwarp.java b/Essentials/src/com/earth2me/essentials/commands/Commandsetwarp.java
index 2c404ec67..c62403292 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandsetwarp.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandsetwarp.java
@@ -24,7 +24,7 @@ public class Commandsetwarp extends EssentialsCommand
charge(user);
Location loc = user.getLocation();
- Essentials.getWarps().setWarp(args[0], loc);
+ ess.getWarps().setWarp(args[0], loc);
user.sendMessage(Util.format("warpSet", args[0]));
}
}
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsetworth.java b/Essentials/src/com/earth2me/essentials/commands/Commandsetworth.java
index 68686c77f..764198828 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandsetworth.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandsetworth.java
@@ -25,7 +25,7 @@ public class Commandsetworth extends EssentialsCommand
ItemStack stack = ItemDb.get(args[0]);
charge(user);
- Essentials.getWorth().setPrice(stack, Double.parseDouble(args[1]));
+ ess.getWorth().setPrice(stack, Double.parseDouble(args[1]));
user.sendMessage(Util.i18n("worthSet"));
}
}
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandspawner.java b/Essentials/src/com/earth2me/essentials/commands/Commandspawner.java
index dbf0e588f..f351019bc 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandspawner.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandspawner.java
@@ -37,7 +37,7 @@ public class Commandspawner extends EssentialsCommand
}
catch (Throwable ex)
{
- throw new Exception(Util.i18n("mobSpawnError"));
+ throw new Exception(Util.i18n("mobSpawnError"), ex);
}
}
}
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java b/Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java
index 433197c33..480e23aea 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java
@@ -173,15 +173,15 @@ public class Commandspawnmob extends EssentialsCommand
}
catch (MobException e1)
{
- throw new Exception(Util.i18n("unableToSpawnMob"));
+ throw new Exception(Util.i18n("unableToSpawnMob"), e1);
}
catch (NumberFormatException e2)
{
- throw new Exception(Util.i18n("numberRequired"));
+ throw new Exception(Util.i18n("numberRequired"), e2);
}
catch (NullPointerException np)
{
- throw new Exception(Util.i18n("soloMob"));
+ throw new Exception(Util.i18n("soloMob"), np);
}
}
else
@@ -205,7 +205,7 @@ public class Commandspawnmob extends EssentialsCommand
}
catch (Exception e)
{
- throw new Exception(Util.i18n("slimeMalformedSize"));
+ throw new Exception(Util.i18n("slimeMalformedSize"), e);
}
}
if ("Sheep".equalsIgnoreCase(type))
@@ -216,7 +216,7 @@ public class Commandspawnmob extends EssentialsCommand
}
catch (Exception e)
{
- throw new Exception(Util.i18n("sheepMalformedColor"));
+ throw new Exception(Util.i18n("sheepMalformedColor"), e);
}
}
if ("Wolf".equalsIgnoreCase(type) && data.equalsIgnoreCase("tamed"))
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtogglejail.java b/Essentials/src/com/earth2me/essentials/commands/Commandtogglejail.java
index 84541945d..acd06bf5a 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandtogglejail.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandtogglejail.java
@@ -36,7 +36,7 @@ public class Commandtogglejail extends EssentialsCommand
p.setJailed(true);
p.sendMessage(Util.i18n("userJailed"));
p.setJail(null);
- Essentials.getJail().sendToJail(p, args[1]);
+ ess.getJail().sendToJail(p, args[1]);
p.setJail(args[1]);
long timeDiff = 0;
if (args.length > 2)
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtop.java b/Essentials/src/com/earth2me/essentials/commands/Commandtop.java
index 22360753c..9704d4a59 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandtop.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandtop.java
@@ -21,7 +21,7 @@ public class Commandtop extends EssentialsCommand
int topZ = user.getLocation().getBlockZ();
int topY = user.getWorld().getHighestBlockYAt(topX, topZ);
charge(user);
- user.getTeleport().teleport(new Location(user.getWorld(), user.getLocation().getX(), topY + 1, user.getLocation().getZ()), new Charge(this));
+ user.getTeleport().teleport(new Location(user.getWorld(), user.getLocation().getX(), topY + 1, user.getLocation().getZ()), new Charge(this.getName(), ess));
user.sendMessage(Util.i18n("teleportTop"));
}
}
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtp.java b/Essentials/src/com/earth2me/essentials/commands/Commandtp.java
index 52b868da4..64f7f8d08 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandtp.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandtp.java
@@ -30,7 +30,7 @@ public class Commandtp extends EssentialsCommand
throw new Exception(Util.format("teleportDisabled", p.getDisplayName()));
}
user.sendMessage(Util.i18n("teleporting"));
- Charge charge = new Charge(this);
+ Charge charge = new Charge(this.getName(), ess);
charge.isAffordableFor(user);
user.getTeleport().teleport(p, charge);
break;
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpaccept.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpaccept.java
index 921b9bc89..1aab32cdf 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandtpaccept.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpaccept.java
@@ -23,7 +23,7 @@ public class Commandtpaccept extends EssentialsCommand
throw new Exception(Util.i18n("noPendingRequest"));
}
- Charge charge = new Charge(this);
+ Charge charge = new Charge(this.getName(), ess);
if (user.isTeleportRequestHere())
{
charge.isAffordableFor(user);
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtphere.java b/Essentials/src/com/earth2me/essentials/commands/Commandtphere.java
index d10ba4e78..3710b121b 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandtphere.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandtphere.java
@@ -21,7 +21,7 @@ public class Commandtphere extends EssentialsCommand
{
throw new Exception(Util.format("teleportDisabled", p.getDisplayName()));
}
- p.getTeleport().teleport(user, new Charge(this));
+ p.getTeleport().teleport(user, new Charge(this.getName(), ess));
user.sendMessage(Util.i18n("teleporting"));
p.sendMessage(Util.i18n("teleporting"));
}
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtppos.java b/Essentials/src/com/earth2me/essentials/commands/Commandtppos.java
index ee03479d1..05f95bc40 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandtppos.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandtppos.java
@@ -26,7 +26,7 @@ public class Commandtppos extends EssentialsCommand
int y = Integer.parseInt(args[1]);
int z = Integer.parseInt(args[2]);
Location l = new Location(user.getWorld(), x, y, z);
- Charge charge = new Charge(this);
+ Charge charge = new Charge(this.getName(), ess);
charge.isAffordableFor(user);
user.sendMessage(Util.i18n("teleporting"));
user.getTeleport().teleport(l, charge);
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandwarp.java b/Essentials/src/com/earth2me/essentials/commands/Commandwarp.java
index 6c3aef64d..f4e710aaf 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandwarp.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandwarp.java
@@ -2,7 +2,6 @@ package com.earth2me.essentials.commands;
import com.earth2me.essentials.Charge;
import org.bukkit.Server;
-import com.earth2me.essentials.Essentials;
import com.earth2me.essentials.User;
import com.earth2me.essentials.Util;
import com.earth2me.essentials.Warps;
@@ -27,7 +26,7 @@ public class Commandwarp extends EssentialsCommand
return;
}
- Warps warps = Essentials.getWarps();
+ Warps warps = ess.getWarps();
if (warps.isEmpty())
{
throw new Exception(Util.i18n("noWarpsDefined"));
@@ -74,7 +73,7 @@ public class Commandwarp extends EssentialsCommand
private void warpUser(User user, String name) throws Exception
{
- Charge charge = new Charge(this);
+ Charge charge = new Charge(this.getName(), ess);
charge.isAffordableFor(user);
if (ess.getSettings().getPerWarpPermission())
{
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java b/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java
index b9d99a682..e923bc70e 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java
@@ -39,7 +39,7 @@ public class Commandwhois extends EssentialsCommand
sender.sendMessage(Util.format("whoisIs", u.getDisplayName(), u.getName()));
sender.sendMessage(Util.format("whoisHealth", u.getHealth()));
sender.sendMessage(Util.format("whoisLocation", u.getLocation().getWorld().getName(), u.getLocation().getBlockX(), u.getLocation().getBlockY(), u.getLocation().getBlockZ()));
- if (!ess.getConfiguration().getBoolean("disable-eco", false))
+ if (!ess.getSettings().isEcoDisabled())
{
sender.sendMessage(Util.format("whoisMoney", Util.formatCurrency(u.getMoney())));
}
@@ -47,11 +47,11 @@ public class Commandwhois extends EssentialsCommand
? Util.i18n("whoisStatusAway")
: Util.i18n("whoisStatusAvailable"));
sender.sendMessage(Util.format("whoisIPAddress", u.getAddress().getAddress().toString()));
- String location = u.getGeoLocation();
+ final String location = u.getGeoLocation();
if (location != null
&& (sender instanceof Player ? ess.getUser(sender).isAuthorized("essentials.geoip.show") : true))
{
- sender.sendMessage(Util.format("whoisGeoLocation", location.toString()));
+ sender.sendMessage(Util.format("whoisGeoLocation", location));
}
}
}
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandworld.java b/Essentials/src/com/earth2me/essentials/commands/Commandworld.java
index fbd53da05..bdbe83798 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandworld.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandworld.java
@@ -5,7 +5,6 @@ import java.util.List;
import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.World;
-import com.earth2me.essentials.Essentials;
import com.earth2me.essentials.User;
import com.earth2me.essentials.Util;
@@ -69,7 +68,7 @@ public class Commandworld extends EssentialsCommand
Location loc = user.getLocation();
loc = new Location(world, loc.getBlockX() * factor + .5, loc.getBlockY(), loc.getBlockZ() * factor + .5);
- Charge charge = new Charge(this);
+ Charge charge = new Charge(this.getName(), ess);
charge.isAffordableFor(user);
user.getTeleport().teleport(loc, charge);
}
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandworth.java b/Essentials/src/com/earth2me/essentials/commands/Commandworth.java
index 02f915bb1..2ce428cfb 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandworth.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandworth.java
@@ -1,7 +1,6 @@
package com.earth2me.essentials.commands;
import org.bukkit.Server;
-import com.earth2me.essentials.Essentials;
import com.earth2me.essentials.ItemDb;
import com.earth2me.essentials.User;
import com.earth2me.essentials.Util;
@@ -39,7 +38,7 @@ public class Commandworth extends EssentialsCommand
}
is.setAmount(amount);
- double worth = Essentials.getWorth().getPrice(is);
+ double worth = ess.getWorth().getPrice(is);
if (Double.isNaN(worth))
{
throw new Exception(Util.i18n("itemCannotBeSold"));
diff --git a/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java b/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java
index d1c268c6d..12c9258c0 100644
--- a/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java
+++ b/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java
@@ -6,6 +6,7 @@ import org.bukkit.Server;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import com.earth2me.essentials.Essentials;
+import com.earth2me.essentials.IEssentials;
import org.bukkit.entity.Player;
import com.earth2me.essentials.User;
import com.earth2me.essentials.Util;
@@ -15,13 +16,17 @@ import java.util.logging.Logger;
public abstract class EssentialsCommand implements IEssentialsCommand
{
private final String name;
- protected Essentials ess;
+ protected IEssentials ess;
protected final static Logger logger = Logger.getLogger("Minecraft");
protected EssentialsCommand(String name)
{
this.name = name;
- this.ess = Essentials.getStatic();
+ }
+
+ public void setEssentials(IEssentials ess)
+ {
+ this.ess = ess;
}
public String getName()
@@ -84,7 +89,7 @@ public abstract class EssentialsCommand implements IEssentialsCommand
{
if (sender instanceof Player)
{
- Charge charge = new Charge(this);
+ Charge charge = new Charge(this.getName(), ess);
charge.charge(ess.getUser((Player)sender));
}
}
diff --git a/Essentials/src/com/earth2me/essentials/commands/IEssentialsCommand.java b/Essentials/src/com/earth2me/essentials/commands/IEssentialsCommand.java
index c7a63322c..a5192ba10 100644
--- a/Essentials/src/com/earth2me/essentials/commands/IEssentialsCommand.java
+++ b/Essentials/src/com/earth2me/essentials/commands/IEssentialsCommand.java
@@ -1,9 +1,10 @@
package com.earth2me.essentials.commands;
-import org.bukkit.*;
+import com.earth2me.essentials.IEssentials;
+import com.earth2me.essentials.User;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
-import com.earth2me.essentials.*;
+import org.bukkit.Server;
public interface IEssentialsCommand
@@ -15,4 +16,6 @@ public interface IEssentialsCommand
void run(Server server, CommandSender sender, String commandLabel, Command cmd, String[] args)
throws Exception;
+
+ void setEssentials(IEssentials ess);
}
diff --git a/Essentials/src/com/earth2me/essentials/commands/NotEnoughArgumentsException.java b/Essentials/src/com/earth2me/essentials/commands/NotEnoughArgumentsException.java
index 1de4b78dc..615a556b9 100644
--- a/Essentials/src/com/earth2me/essentials/commands/NotEnoughArgumentsException.java
+++ b/Essentials/src/com/earth2me/essentials/commands/NotEnoughArgumentsException.java
@@ -2,4 +2,14 @@ package com.earth2me.essentials.commands;
public class NotEnoughArgumentsException extends Exception {
+ public NotEnoughArgumentsException()
+ {
+ super();
+ }
+
+ public NotEnoughArgumentsException(final Throwable ex)
+ {
+ super(ex);
+ }
+
}
diff --git a/Essentials/test/com/earth2me/essentials/EconomyTest.java b/Essentials/test/com/earth2me/essentials/EconomyTest.java
index 511670cbb..74f5f11d2 100644
--- a/Essentials/test/com/earth2me/essentials/EconomyTest.java
+++ b/Essentials/test/com/earth2me/essentials/EconomyTest.java
@@ -12,8 +12,8 @@ import org.bukkit.plugin.InvalidDescriptionException;
public class EconomyTest extends TestCase
{
- private OfflinePlayer base1;
- private Essentials ess;
+ private final OfflinePlayer base1;
+ private final Essentials ess;
public EconomyTest(String testName)
{
diff --git a/Essentials/test/com/earth2me/essentials/EssentialsTest.java b/Essentials/test/com/earth2me/essentials/EssentialsTest.java
index b0bf95191..26c5c68e9 100644
--- a/Essentials/test/com/earth2me/essentials/EssentialsTest.java
+++ b/Essentials/test/com/earth2me/essentials/EssentialsTest.java
@@ -15,18 +15,6 @@ public class EssentialsTest extends TestCase
System.out.println("Essentials should " + what);
}
- @Override
- protected void setUp() throws Exception
- {
- super.setUp();
- }
-
- @Override
- protected void tearDown() throws Exception
- {
- super.tearDown();
- }
-
public void testLoadClasses()
{
should("make all classes accessible");
diff --git a/Essentials/test/com/earth2me/essentials/FakeServer.java b/Essentials/test/com/earth2me/essentials/FakeServer.java
index a867c116b..5594f36b1 100644
--- a/Essentials/test/com/earth2me/essentials/FakeServer.java
+++ b/Essentials/test/com/earth2me/essentials/FakeServer.java
@@ -20,7 +20,7 @@ import org.bukkit.scheduler.BukkitScheduler;
public class FakeServer implements Server
{
private List<Player> players = new ArrayList<Player>();
- private List<World> worlds = new ArrayList<World>();
+ private final List<World> worlds = new ArrayList<World>();
public String getName()
{
@@ -186,12 +186,12 @@ public class FakeServer implements Server
throw new UnsupportedOperationException("Not supported yet.");
}
- void addPlayer(Player base1)
+ public void addPlayer(Player base1)
{
players.add(base1);
}
- OfflinePlayer createPlayer(String name)
+ public OfflinePlayer createPlayer(String name)
{
OfflinePlayer player = new OfflinePlayer(name);
player.setLocation(new Location(worlds.get(0), 0, 0, 0, 0, 0));
diff --git a/Essentials/test/com/earth2me/essentials/PermissionsTest.java b/Essentials/test/com/earth2me/essentials/PermissionsTest.java
deleted file mode 100644
index a630edf85..000000000
--- a/Essentials/test/com/earth2me/essentials/PermissionsTest.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package com.earth2me.essentials;
-
-import junit.framework.TestCase;
-
-
-public class PermissionsTest extends TestCase
-{
- @Override
- protected void setUp() throws Exception
- {
- super.setUp();
- }
-
- public void test()
- {
- }
-}
diff --git a/Essentials/test/com/earth2me/essentials/UserTest.java b/Essentials/test/com/earth2me/essentials/UserTest.java
index d6e04cc17..3bfe0fad0 100644
--- a/Essentials/test/com/earth2me/essentials/UserTest.java
+++ b/Essentials/test/com/earth2me/essentials/UserTest.java
@@ -10,9 +10,9 @@ import org.bukkit.plugin.InvalidDescriptionException;
public class UserTest extends TestCase
{
- private OfflinePlayer base1;
- private Essentials ess;
- private FakeServer server;
+ private final OfflinePlayer base1;
+ private final Essentials ess;
+ private final FakeServer server;
public UserTest(String testName)
{