summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsnowleo <schneeleo@gmail.com>2011-07-16 01:33:22 +0200
committersnowleo <schneeleo@gmail.com>2011-07-16 01:33:22 +0200
commita38fe6acd4f5f6d7143c818653e9e02209f312db (patch)
tree7a993bdc1260364b8fad6a2d811fd608cb24c70c
parent25c9557c594a065308dbd6dd4835f83c5028c54d (diff)
downloadEssentials-a38fe6acd4f5f6d7143c818653e9e02209f312db.tar
Essentials-a38fe6acd4f5f6d7143c818653e9e02209f312db.tar.gz
Essentials-a38fe6acd4f5f6d7143c818653e9e02209f312db.tar.lz
Essentials-a38fe6acd4f5f6d7143c818653e9e02209f312db.tar.xz
Essentials-a38fe6acd4f5f6d7143c818653e9e02209f312db.zip
Heavy cleanup of all classes
ItemDb is not static anymore Essentials.getStatic() removed
-rw-r--r--Essentials/src/com/earth2me/essentials/Essentials.java49
-rw-r--r--Essentials/src/com/earth2me/essentials/EssentialsTimer.java3
-rw-r--r--Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java2
-rw-r--r--Essentials/src/com/earth2me/essentials/IEssentials.java15
-rw-r--r--Essentials/src/com/earth2me/essentials/ItemDb.java71
-rw-r--r--Essentials/src/com/earth2me/essentials/OfflinePlayer.java5
-rw-r--r--Essentials/src/com/earth2me/essentials/Settings.java12
-rw-r--r--Essentials/src/com/earth2me/essentials/Teleport.java1
-rw-r--r--Essentials/src/com/earth2me/essentials/User.java14
-rw-r--r--Essentials/src/com/earth2me/essentials/Util.java81
-rw-r--r--Essentials/src/com/earth2me/essentials/api/Economy.java64
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandbalance.java4
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java2
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandclearinventory.java1
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandgive.java3
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commanditem.java4
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandkick.java1
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandlist.java1
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandsell.java8
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandsetjail.java1
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandsetwarp.java1
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandsetworth.java4
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandspawner.java1
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java2
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandtogglejail.java1
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandunlimited.java3
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandwhois.java2
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandworth.java11
-rw-r--r--Essentials/src/com/earth2me/essentials/register/payment/methods/BOSE.java1
-rw-r--r--Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java11
-rw-r--r--Essentials/src/com/earth2me/essentials/signs/SignEntityListener.java1
-rw-r--r--Essentials/src/com/earth2me/essentials/signs/SignFree.java4
-rw-r--r--Essentials/src/com/earth2me/essentials/signs/SignTrade.java38
-rw-r--r--Essentials/test/com/earth2me/essentials/EconomyTest.java2
-rw-r--r--Essentials/test/com/earth2me/essentials/FakeServer.java4
-rw-r--r--Essentials/test/com/earth2me/essentials/UserTest.java7
-rw-r--r--Essentials/test/com/earth2me/essentials/UtilTest.java40
-rw-r--r--EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChat.java10
-rw-r--r--EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListener.java13
-rw-r--r--EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIP.java10
-rw-r--r--EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIPPlayerListener.java6
-rw-r--r--EssentialsPermissionsCommands/src/com/earth2me/essentials/permissions/EssentialsPermissionsCommands.java16
-rw-r--r--EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java5
-rw-r--r--EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandsetspawn.java3
-rw-r--r--EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandspawn.java3
-rw-r--r--EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawn.java43
-rw-r--r--EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java10
-rw-r--r--EssentialsXMPP/src/com/earth2me/essentials/xmpp/EssentialsXMPP.java26
48 files changed, 328 insertions, 292 deletions
diff --git a/Essentials/src/com/earth2me/essentials/Essentials.java b/Essentials/src/com/earth2me/essentials/Essentials.java
index 0117daf77..e7a57f9b5 100644
--- a/Essentials/src/com/earth2me/essentials/Essentials.java
+++ b/Essentials/src/com/earth2me/essentials/Essentials.java
@@ -17,6 +17,7 @@
*/
package com.earth2me.essentials;
+import com.earth2me.essentials.api.Economy;
import com.earth2me.essentials.commands.EssentialsCommand;
import java.io.*;
import java.util.*;
@@ -45,12 +46,10 @@ import org.bukkit.plugin.java.*;
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 BUKKIT_VERSION = 974;
private static final Logger LOGGER = Logger.getLogger("Minecraft");
private transient Settings settings;
private final transient TNTExplodeListener tntListener = new TNTExplodeListener(this);
- private static Essentials instance = null;
private transient Spawn spawn;
private transient Jail jail;
private transient Warps warps;
@@ -58,6 +57,7 @@ public class Essentials extends JavaPlugin implements IEssentials
private transient List<IConf> confList;
private transient Backup backup;
private transient BanWorkaround bans;
+ private transient ItemDb itemDb;
private transient final Map<String, User> users = new HashMap<String, User>();
private transient EssentialsUpdateTimer updateTimer;
private transient final Methods paymentMethod = new Methods();
@@ -65,11 +65,6 @@ public class Essentials extends JavaPlugin implements IEssentials
private transient final EssentialsErrorHandler errorHandler = new EssentialsErrorHandler();
private transient IPermissionsHandler permissionsHandler;
- public static IEssentials getStatic()
- {
- return instance;
- }
-
public Settings getSettings()
{
return settings;
@@ -89,14 +84,9 @@ public class Essentials extends JavaPlugin implements IEssentials
LOGGER.log(Level.INFO, Util.i18n("usingTempFolderForTesting"));
LOGGER.log(Level.INFO, dataFolder.toString());
this.initialize(null, server, new PluginDescriptionFile(new FileReader(new File("src" + File.separator + "plugin.yml"))), dataFolder, null, null);
- settings = new Settings(dataFolder);
+ settings = new Settings(this);
permissionsHandler = new ConfigPermissionsHandler(this);
- setStatic();
- }
-
- public void setStatic()
- {
- instance = this;
+ Economy.setEss(this);
}
public void onEnable()
@@ -110,14 +100,13 @@ public class Essentials extends JavaPlugin implements IEssentials
{
LOGGER.addHandler(errorHandler);
}
- setStatic();
EssentialsUpgrade upgrade = new EssentialsUpgrade(this.getDescription().getVersion(), this);
upgrade.beforeSettings();
confList = new ArrayList<IConf>();
- settings = new Settings(this.getDataFolder());
+ settings = new Settings(this);
confList.add(settings);
upgrade.afterSettings();
- Util.updateLocale(settings.getLocale(), this.getDataFolder());
+ Util.updateLocale(settings.getLocale(), this);
spawn = new Spawn(getServer(), this.getDataFolder());
confList.add(spawn);
warps = new Warps(getServer(), this.getDataFolder());
@@ -126,6 +115,8 @@ public class Essentials extends JavaPlugin implements IEssentials
confList.add(worth);
bans = new BanWorkaround(this);
confList.add(bans);
+ itemDb = new ItemDb(this);
+ confList.add(itemDb);
reload();
backup = new Backup(this);
@@ -230,17 +221,17 @@ public class Essentials extends JavaPlugin implements IEssentials
final EssentialsTimer timer = new EssentialsTimer(this);
getScheduler().scheduleSyncRepeatingTask(this, timer, 1, 50);
+ Economy.setEss(this);
if (enableErrorLogging)
{
updateTimer = new EssentialsUpdateTimer(this);
getScheduler().scheduleAsyncRepeatingTask(this, updateTimer, 50, 50 * 60 * (this.getDescription().getVersion().startsWith("Dev") ? 60 : 360));
}
- LOGGER.info(Util.format("loadinfo", this.getDescription().getName(), this.getDescription().getVersion(), AUTHORS));
+ LOGGER.info(Util.format("loadinfo", this.getDescription().getName(), this.getDescription().getVersion(), Util.joinList(this.getDescription().getAuthors())));
}
public void onDisable()
{
- instance = null;
Trade.closeLog();
LOGGER.removeHandler(errorHandler);
}
@@ -254,7 +245,7 @@ public class Essentials extends JavaPlugin implements IEssentials
iConf.reloadConfig();
}
- Util.updateLocale(settings.getLocale(), this.getDataFolder());
+ Util.updateLocale(settings.getLocale(), this);
for (User user : users.values())
{
@@ -263,15 +254,6 @@ public class Essentials extends JavaPlugin implements IEssentials
// for motd
getConfiguration().load();
-
- try
- {
- ItemDb.load(getDataFolder(), "items.csv");
- }
- catch (Exception ex)
- {
- LOGGER.log(Level.WARNING, Util.i18n("itemsCsvNotLoaded"), ex);
- }
}
public String[] getMotd(CommandSender sender, String def)
@@ -373,7 +355,7 @@ public class Essentials extends JavaPlugin implements IEssentials
@Override
public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args)
{
- return onCommandEssentials(sender, command, commandLabel, args, Essentials.class.getClassLoader(), "com.earth2me.essentials.commands.Command", "essentials.");
+ return onCommandEssentials(sender, command, commandLabel, args, Thread.currentThread().getContextClassLoader(), "com.earth2me.essentials.commands.Command", "essentials.");
}
public boolean onCommandEssentials(CommandSender sender, Command command, String commandLabel, String[] args, ClassLoader classLoader, String commandPath, String permissionPrefix)
@@ -576,7 +558,7 @@ public class Essentials extends JavaPlugin implements IEssentials
File userFile = new File(userFolder, Util.sanitizeFileName(name) + ".yml");
if (userFile.exists())
{ //Users do not get offline changes saved without being reproccessed as Users! ~ Xeology :)
- return getUser((Player)new OfflinePlayer(name));
+ return getUser((Player)new OfflinePlayer(name, this));
}
return null;
@@ -660,4 +642,9 @@ public class Essentials extends JavaPlugin implements IEssentials
{
return bans;
}
+
+ public ItemDb getItemDb()
+ {
+ return itemDb;
+ }
}
diff --git a/Essentials/src/com/earth2me/essentials/EssentialsTimer.java b/Essentials/src/com/earth2me/essentials/EssentialsTimer.java
index e2d5de6fd..320c86cfe 100644
--- a/Essentials/src/com/earth2me/essentials/EssentialsTimer.java
+++ b/Essentials/src/com/earth2me/essentials/EssentialsTimer.java
@@ -3,7 +3,6 @@ package com.earth2me.essentials;
import java.io.File;
import java.util.HashSet;
import java.util.Set;
-import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.entity.Player;
@@ -25,7 +24,7 @@ public class EssentialsTimer implements Runnable, IConf
continue;
}
String name = string.substring(0, string.length()-4);
- User u = ess.getUser(new OfflinePlayer(name));
+ User u = ess.getUser(new OfflinePlayer(name, ess));
allUsers.add(u);
}
}
diff --git a/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java b/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java
index 4d26d270f..31a4f8492 100644
--- a/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java
+++ b/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java
@@ -192,7 +192,7 @@ public class EssentialsUpgrade
usersConfig.load();
for (String username : usersConfig.getKeys(null))
{
- User user = new User(new OfflinePlayer(username), ess);
+ User user = new User(new OfflinePlayer(username, ess), ess);
String nickname = usersConfig.getString(username + ".nickname");
if (nickname != null && !nickname.isEmpty() && !nickname.equals(username))
{
diff --git a/Essentials/src/com/earth2me/essentials/IEssentials.java b/Essentials/src/com/earth2me/essentials/IEssentials.java
index 3d4e82267..3e5dbbbd3 100644
--- a/Essentials/src/com/earth2me/essentials/IEssentials.java
+++ b/Essentials/src/com/earth2me/essentials/IEssentials.java
@@ -1,18 +1,15 @@
package com.earth2me.essentials;
import com.earth2me.essentials.register.payment.Methods;
-import java.io.File;
-import java.util.List;
import java.util.Map;
-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;
+import org.bukkit.plugin.Plugin;
-public interface IEssentials
+public interface IEssentials extends Plugin
{
void addReloadListener(IConf listener);
@@ -47,12 +44,6 @@ public interface IEssentials
Spawn getSpawn();
Methods getPaymentMethod();
-
- Server getServer();
-
- File getDataFolder();
-
- PluginDescriptionFile getDescription();
int scheduleAsyncDelayedTask(Runnable run);
@@ -71,4 +62,6 @@ public interface IEssentials
void showError(final CommandSender sender, final Throwable exception, final String commandLabel);
Map<String, User> getAllUsers();
+
+ ItemDb getItemDb();
}
diff --git a/Essentials/src/com/earth2me/essentials/ItemDb.java b/Essentials/src/com/earth2me/essentials/ItemDb.java
index 8e42f3cb6..d7e534341 100644
--- a/Essentials/src/com/earth2me/essentials/ItemDb.java
+++ b/Essentials/src/com/earth2me/essentials/ItemDb.java
@@ -7,30 +7,31 @@ import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
+import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
-public final class ItemDb
+public class ItemDb implements IConf
{
- private ItemDb()
+ private final transient IEssentials ess;
+
+ public ItemDb(IEssentials ess)
{
+ this.ess = ess;
}
-
- 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>();
+ private final static Logger LOGGER = Logger.getLogger("Minecraft");
+ private final transient Map<String, Integer> items = new HashMap<String, Integer>();
+ private final transient Map<String, Short> durabilities = new HashMap<String, Short>();
- public static void load(File folder, String fname) throws IOException
+ public void reloadConfig()
{
- folder.mkdirs();
- File file = new File(folder, fname);
+ final File file = new File(ess.getDataFolder(), "items.csv");
if (!file.exists())
{
- file.createNewFile();
- InputStream res = ItemDb.class.getResourceAsStream("/items.csv");
+ final InputStream res = ItemDb.class.getResourceAsStream("/items.csv");
FileWriter tx = null;
try
{
@@ -41,6 +42,11 @@ public final class ItemDb
}
tx.flush();
}
+ catch (IOException ex)
+ {
+ LOGGER.log(Level.SEVERE, Util.i18n("itemsCsvNotLoaded"), ex);
+ return;
+ }
finally
{
try
@@ -63,52 +69,67 @@ public final class ItemDb
}
}
- BufferedReader rx = new BufferedReader(new FileReader(file));
+ BufferedReader rx = null;
try
{
+ rx = new BufferedReader(new FileReader(file));
+ durabilities.clear();
items.clear();
for (int i = 0; rx.ready(); i++)
{
try
{
- String line = rx.readLine().trim().toLowerCase();
+ final String line = rx.readLine().trim().toLowerCase();
if (line.startsWith("#"))
{
continue;
}
- String[] parts = line.split("[^a-z0-9]");
+ final String[] parts = line.split("[^a-z0-9]");
if (parts.length < 2)
{
continue;
}
- int numeric = Integer.parseInt(parts[1]);
+ final int numeric = Integer.parseInt(parts[1]);
durabilities.put(parts[0].toLowerCase(), parts.length > 2 && !parts[2].equals("0") ? Short.parseShort(parts[2]) : 0);
items.put(parts[0].toLowerCase(), numeric);
}
catch (Exception ex)
{
- logger.warning(Util.format("parseError", fname, i));
+ LOGGER.warning(Util.format("parseError", "items.csv", i));
}
}
}
+ catch (IOException ex)
+ {
+ LOGGER.log(Level.SEVERE, Util.i18n("itemsCsvNotLoaded"), ex);
+ }
finally
{
- rx.close();
+ if (rx != null) {
+ try
+ {
+ rx.close();
+ }
+ catch (IOException ex)
+ {
+ LOGGER.log(Level.SEVERE, ex.getMessage(), ex);
+ }
+ }
}
}
- public static ItemStack get(String id, int quantity) throws Exception
+ public ItemStack get(final String id, final int quantity) throws Exception
{
- ItemStack retval = get(id.toLowerCase());
+ final ItemStack retval = get(id.toLowerCase());
retval.setAmount(quantity);
return retval;
}
- public static ItemStack get(String id) throws Exception
+ public ItemStack get(final String id) throws Exception
{
int itemid = 0;
String itemname = null;
@@ -127,11 +148,11 @@ public final class ItemDb
itemname = id.split("[:+',;.]")[0].toLowerCase();
metaData = Short.parseShort(id.split("[:+',;.]")[1]);
}
- else
+ else
{
itemname = id.toLowerCase();
}
-
+
if (itemname != null)
{
if (items.containsKey(itemname))
@@ -148,13 +169,13 @@ public final class ItemDb
}
}
- Material mat = Material.getMaterial(itemid);
+ final Material mat = Material.getMaterial(itemid);
if (mat == null)
{
throw new Exception(Util.format("unknownItemId", itemid));
}
- ItemStack retval = new ItemStack(mat);
- retval.setAmount(Essentials.getStatic().getSettings().getDefaultStackSize());
+ final ItemStack retval = new ItemStack(mat);
+ retval.setAmount(ess.getSettings().getDefaultStackSize());
retval.setDurability(metaData);
return retval;
}
diff --git a/Essentials/src/com/earth2me/essentials/OfflinePlayer.java b/Essentials/src/com/earth2me/essentials/OfflinePlayer.java
index 8427e2996..32f45a377 100644
--- a/Essentials/src/com/earth2me/essentials/OfflinePlayer.java
+++ b/Essentials/src/com/earth2me/essentials/OfflinePlayer.java
@@ -29,14 +29,15 @@ import org.bukkit.util.Vector;
public class OfflinePlayer implements Player
{
private final String name;
- final IEssentials ess = Essentials.getStatic();
+ final transient IEssentials ess;
private Location location = new Location(null, 0, 0, 0, 0, 0);
private World world = null;
private UUID uniqueId = UUID.randomUUID();
- public OfflinePlayer(String name)
+ public OfflinePlayer(String name, IEssentials ess)
{
this.name = name;
+ this.ess = ess;
}
public boolean isOnline()
diff --git a/Essentials/src/com/earth2me/essentials/Settings.java b/Essentials/src/com/earth2me/essentials/Settings.java
index 25222deb1..17248a6cc 100644
--- a/Essentials/src/com/earth2me/essentials/Settings.java
+++ b/Essentials/src/com/earth2me/essentials/Settings.java
@@ -13,12 +13,14 @@ import org.bukkit.inventory.ItemStack;
public class Settings implements IConf
{
- private final EssentialsConf config;
+ private final transient EssentialsConf config;
private final static Logger logger = Logger.getLogger("Minecraft");
+ private final transient IEssentials ess;
- public Settings(File dataFolder)
+ public Settings(IEssentials ess)
{
- config = new EssentialsConf(new File(dataFolder, "config.yml"));
+ this.ess = ess;
+ config = new EssentialsConf(new File(ess.getDataFolder(), "config.yml"));
config.setTemplateName("/config.yml");
config.load();
}
@@ -275,7 +277,7 @@ public class Settings implements IConf
}
ItemStack is;
try {
- is = ItemDb.get(itemName);
+ is = ess.getItemDb().get(itemName);
epItemSpwn.add(is.getTypeId());
} catch (Exception ex) {
logger.log(Level.SEVERE, Util.format("unknownItemInList", itemName, "item-spawn-blacklist"));
@@ -357,7 +359,7 @@ public class Settings implements IConf
}
ItemStack itemStack;
try {
- itemStack = ItemDb.get(itemName);
+ itemStack = ess.getItemDb().get(itemName);
list.add(itemStack.getTypeId());
} catch (Exception ex) {
logger.log(Level.SEVERE, Util.format("unknownItemInList", itemName, configName));
diff --git a/Essentials/src/com/earth2me/essentials/Teleport.java b/Essentials/src/com/earth2me/essentials/Teleport.java
index 429834b02..9fb9b7433 100644
--- a/Essentials/src/com/earth2me/essentials/Teleport.java
+++ b/Essentials/src/com/earth2me/essentials/Teleport.java
@@ -2,7 +2,6 @@ package com.earth2me.essentials;
import java.util.Calendar;
import java.util.GregorianCalendar;
-import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
diff --git a/Essentials/src/com/earth2me/essentials/User.java b/Essentials/src/com/earth2me/essentials/User.java
index bcd7f12a1..22d8a5705 100644
--- a/Essentials/src/com/earth2me/essentials/User.java
+++ b/Essentials/src/com/earth2me/essentials/User.java
@@ -87,10 +87,10 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
return;
}
setMoney(getMoney() + value);
- sendMessage(Util.format("addedToAccount", Util.formatCurrency(value)));
+ sendMessage(Util.format("addedToAccount", Util.formatCurrency(value, ess)));
if (initiator != null)
{
- initiator.sendMessage((Util.format("addedToOthersAccount", Util.formatCurrency(value), this.getDisplayName())));
+ initiator.sendMessage((Util.format("addedToOthersAccount", Util.formatCurrency(value, ess), this.getDisplayName())));
}
}
@@ -108,8 +108,8 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
{
setMoney(getMoney() - value);
reciever.setMoney(reciever.getMoney() + value);
- sendMessage(Util.format("moneySentTo", Util.formatCurrency(value), reciever.getDisplayName()));
- reciever.sendMessage(Util.format("moneyRecievedFrom", Util.formatCurrency(value), getDisplayName()));
+ sendMessage(Util.format("moneySentTo", Util.formatCurrency(value, ess), reciever.getDisplayName()));
+ reciever.sendMessage(Util.format("moneyRecievedFrom", Util.formatCurrency(value, ess), getDisplayName()));
}
}
@@ -125,10 +125,10 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
return;
}
setMoney(getMoney() - value);
- sendMessage(Util.format("takenFromAccount", Util.formatCurrency(value)));
+ sendMessage(Util.format("takenFromAccount", Util.formatCurrency(value, ess)));
if (initiator != null)
{
- initiator.sendMessage((Util.format("takenFromOthersAccount", Util.formatCurrency(value), this.getDisplayName())));
+ initiator.sendMessage((Util.format("takenFromOthersAccount", Util.formatCurrency(value, ess), this.getDisplayName())));
}
}
@@ -140,7 +140,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
public void dispose()
{
- this.base = new OfflinePlayer(getName());
+ this.base = new OfflinePlayer(getName(), ess);
}
public boolean getJustPortaled()
diff --git a/Essentials/src/com/earth2me/essentials/Util.java b/Essentials/src/com/earth2me/essentials/Util.java
index 7ba0c4b56..515ef83a5 100644
--- a/Essentials/src/com/earth2me/essentials/Util.java
+++ b/Essentials/src/com/earth2me/essentials/Util.java
@@ -11,15 +11,10 @@ import java.net.URL;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.MessageFormat;
-import java.util.ArrayList;
import java.util.Calendar;
-import java.util.Collections;
-import java.util.Comparator;
import java.util.Enumeration;
import java.util.GregorianCalendar;
-import java.util.List;
import java.util.Locale;
-import java.util.Map;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import java.util.logging.Level;
@@ -289,9 +284,9 @@ public class Util
}
private static DecimalFormat df = new DecimalFormat("#0.00", DecimalFormatSymbols.getInstance(Locale.US));
- public static String formatCurrency(double value)
+ public static String formatCurrency(final double value, final IEssentials ess)
{
- String str = Essentials.getStatic().getSettings().getCurrencySymbol() + df.format(value);
+ String str = ess.getSettings().getCurrencySymbol() + df.format(value);
if (str.endsWith(".00"))
{
str = str.substring(0, str.length() - 3);
@@ -312,19 +307,21 @@ public class Util
private static class ConfigClassLoader extends ClassLoader
{
- private final File dataFolder;
- private final ClassLoader cl;
+ private final transient File dataFolder;
+ private final transient ClassLoader cl;
+ private final transient IEssentials ess;
- public ConfigClassLoader(File dataFolder, ClassLoader cl)
+ public ConfigClassLoader(final ClassLoader cl, final IEssentials ess)
{
- this.dataFolder = dataFolder;
+ this.ess = ess;
+ this.dataFolder = ess.getDataFolder();
this.cl = cl;
}
@Override
- public URL getResource(String string)
+ public URL getResource(final String string)
{
- File file = new File(dataFolder, string);
+ final File file = new File(dataFolder, string);
if (file.exists())
{
try
@@ -346,17 +343,18 @@ public class Util
}
@Override
- public InputStream getResourceAsStream(String string)
+ public InputStream getResourceAsStream(final String string)
{
- File file = new File(dataFolder, string);
+ final File file = new File(dataFolder, string);
if (file.exists())
{
+ BufferedReader br = null;
try
{
- BufferedReader br = new BufferedReader(new FileReader(file));
- String version = br.readLine();
- br.close();
- if (version == null || !version.equals("#version: " + Essentials.getStatic().getDescription().getVersion()))
+ br = new BufferedReader(new FileReader(file));
+ final String version = br.readLine();
+
+ if (version == null || !version.equals("#version: " + ess.getDescription().getVersion()))
{
logger.log(Level.WARNING, String.format("Translation file %s is not updated for Essentials version. Will use default.", file));
return cl.getResourceAsStream(string);
@@ -367,36 +365,50 @@ public class Util
{
return cl.getResourceAsStream(string);
}
+ finally
+ {
+ if (br != null)
+ {
+ try
+ {
+ br.close();
+ }
+ catch (IOException ex)
+ {
+ return cl.getResourceAsStream(string);
+ }
+ }
+ }
}
return cl.getResourceAsStream(string);
}
@Override
- public Enumeration<URL> getResources(String string) throws IOException
+ public Enumeration<URL> getResources(final String string) throws IOException
{
return cl.getResources(string);
}
@Override
- public Class<?> loadClass(String string) throws ClassNotFoundException
+ public Class<?> loadClass(final String string) throws ClassNotFoundException
{
return cl.loadClass(string);
}
@Override
- public synchronized void setClassAssertionStatus(String string, boolean bln)
+ public synchronized void setClassAssertionStatus(final String string, final boolean bln)
{
cl.setClassAssertionStatus(string, bln);
}
@Override
- public synchronized void setDefaultAssertionStatus(boolean bln)
+ public synchronized void setDefaultAssertionStatus(final boolean bln)
{
cl.setDefaultAssertionStatus(bln);
}
@Override
- public synchronized void setPackageAssertionStatus(String string, boolean bln)
+ public synchronized void setPackageAssertionStatus(final String string, final boolean bln)
{
cl.setPackageAssertionStatus(string, bln);
}
@@ -425,7 +437,7 @@ public class Util
return mf.format(objects);
}
- public static void updateLocale(String loc, File dataFolder)
+ public static void updateLocale(String loc, IEssentials ess)
{
if (loc == null || loc.isEmpty())
{
@@ -445,10 +457,27 @@ public class Util
currentLocale = new Locale(parts[0], parts[1], parts[2]);
}
logger.log(Level.INFO, String.format("Using locale %s", currentLocale.toString()));
- bundle = ResourceBundle.getBundle("messages", currentLocale, new ConfigClassLoader(dataFolder, Util.class.getClassLoader()));
+ bundle = ResourceBundle.getBundle("messages", currentLocale, new ConfigClassLoader(Util.class.getClassLoader(), ess));
if (!bundle.keySet().containsAll(defaultBundle.keySet()))
{
logger.log(Level.WARNING, String.format("Translation file %s does not contain all translation keys.", currentLocale.toString()));
}
}
+
+ public static String joinList(Object... list)
+ {
+ final StringBuilder buf = new StringBuilder();
+ boolean first = true;
+ for (Object each : list)
+ {
+ if (!first)
+ {
+ buf.append(", ");
+
+ }
+ first = false;
+ buf.append(each);
+ }
+ return buf.toString();
+ }
}
diff --git a/Essentials/src/com/earth2me/essentials/api/Economy.java b/Essentials/src/com/earth2me/essentials/api/Economy.java
index bf071b733..fcab616be 100644
--- a/Essentials/src/com/earth2me/essentials/api/Economy.java
+++ b/Essentials/src/com/earth2me/essentials/api/Economy.java
@@ -1,7 +1,7 @@
package com.earth2me.essentials.api;
-import com.earth2me.essentials.Essentials;
import com.earth2me.essentials.EssentialsConf;
+import com.earth2me.essentials.IEssentials;
import com.earth2me.essentials.User;
import com.earth2me.essentials.Util;
import java.io.File;
@@ -9,6 +9,7 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.entity.Player;
+
/**
* Instead of using this api directly, we recommend to use the register plugin:
* http://bit.ly/RegisterMethod
@@ -19,10 +20,19 @@ public final class Economy
{
}
private static final Logger logger = Logger.getLogger("Minecraft");
+ private static IEssentials ess;
+
+ /**
+ * @param aEss the ess to set
+ */
+ public static void setEss(IEssentials aEss)
+ {
+ ess = aEss;
+ }
private static void createNPCFile(String name)
{
- File folder = new File(Essentials.getStatic().getDataFolder(), "userdata");
+ File folder = new File(ess.getDataFolder(), "userdata");
if (!folder.exists())
{
folder.mkdirs();
@@ -30,13 +40,13 @@ public final class Economy
EssentialsConf npcConfig = new EssentialsConf(new File(folder, Util.sanitizeFileName(name) + ".yml"));
npcConfig.load();
npcConfig.setProperty("npc", true);
- npcConfig.setProperty("money", Essentials.getStatic().getSettings().getStartingBalance());
+ npcConfig.setProperty("money", ess.getSettings().getStartingBalance());
npcConfig.save();
}
-
+
private static void deleteNPC(String name)
{
- File folder = new File(Essentials.getStatic().getDataFolder(), "userdata");
+ File folder = new File(ess.getDataFolder(), "userdata");
if (!folder.exists())
{
folder.mkdirs();
@@ -44,24 +54,26 @@ public final class Economy
File config = new File(folder, Util.sanitizeFileName(name) + ".yml");
EssentialsConf npcConfig = new EssentialsConf(config);
npcConfig.load();
- if (npcConfig.hasProperty("npc") && npcConfig.getBoolean("npc", false)) {
- if (!config.delete()) {
+ if (npcConfig.hasProperty("npc") && npcConfig.getBoolean("npc", false))
+ {
+ if (!config.delete())
+ {
logger.log(Level.WARNING, Util.format("deleteFileError", config));
}
}
}
-
+
private static User getUserByName(String name)
{
User user;
- Player player = Essentials.getStatic().getServer().getPlayer(name);
+ Player player = ess.getServer().getPlayer(name);
if (player != null)
{
- user = Essentials.getStatic().getUser(player);
+ user = ess.getUser(player);
}
else
{
- user = Essentials.getStatic().getOfflineUser(name);
+ user = ess.getOfflineUser(name);
}
return user;
}
@@ -75,7 +87,8 @@ public final class Economy
public static double getMoney(String name) throws UserDoesNotExistException
{
User user = getUserByName(name);
- if (user == null) {
+ if (user == null)
+ {
throw new UserDoesNotExistException(name);
}
return user.getMoney();
@@ -91,7 +104,8 @@ public final class Economy
public static void setMoney(String name, double balance) throws UserDoesNotExistException, NoLoanPermittedException
{
User user = getUserByName(name);
- if (user == null) {
+ if (user == null)
+ {
throw new UserDoesNotExistException(name);
}
if (balance < 0.0 && !user.isAuthorized("essentials.eco.loan"))
@@ -113,7 +127,7 @@ public final class Economy
double result = getMoney(name) + amount;
setMoney(name, result);
}
-
+
/**
* Substracts money from the balance of a user
* @param name Name of the user
@@ -161,7 +175,7 @@ public final class Economy
*/
public static void resetBalance(String name) throws UserDoesNotExistException, NoLoanPermittedException
{
- setMoney(name, Essentials.getStatic().getSettings().getStartingBalance());
+ setMoney(name, ess.getSettings().getStartingBalance());
}
/**
@@ -216,18 +230,19 @@ public final class Economy
*/
public static String format(double amount)
{
- return Util.formatCurrency(amount);
+ return Util.formatCurrency(amount, ess);
}
-
+
/**
* Test if a player exists to avoid the UserDoesNotExistException
* @param name Name of the user
* @return true, if the user exists
*/
- public static boolean playerExists(String name) {
+ public static boolean playerExists(String name)
+ {
return getUserByName(name) != null;
}
-
+
/**
* Test if a player is a npc
* @param name Name of the player
@@ -237,12 +252,13 @@ public final class Economy
public static boolean isNPC(String name) throws UserDoesNotExistException
{
User user = getUserByName(name);
- if (user == null) {
+ if (user == null)
+ {
throw new UserDoesNotExistException(name);
}
return user.isNPC();
}
-
+
/**
* Creates dummy files for a npc, if there is no player yet with that name.
* @param name Name of the player
@@ -251,7 +267,8 @@ public final class Economy
public static boolean createNPC(String name)
{
User user = getUserByName(name);
- if (user == null) {
+ if (user == null)
+ {
createNPCFile(name);
return true;
}
@@ -266,7 +283,8 @@ public final class Economy
public static void removeNPC(String name) throws UserDoesNotExistException
{
User user = getUserByName(name);
- if (user == null) {
+ if (user == null)
+ {
throw new UserDoesNotExistException(name);
}
deleteNPC(name);
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbalance.java b/Essentials/src/com/earth2me/essentials/commands/Commandbalance.java
index ec525fab8..7dd1fb449 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandbalance.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandbalance.java
@@ -20,7 +20,7 @@ public class Commandbalance extends EssentialsCommand
{
throw new NotEnoughArgumentsException();
}
- sender.sendMessage(Util.format("balance", Util.formatCurrency(getPlayer(server, args, 0, true).getMoney())));
+ sender.sendMessage(Util.format("balance", Util.formatCurrency(getPlayer(server, args, 0, true).getMoney(), ess)));
}
@Override
@@ -32,6 +32,6 @@ public class Commandbalance extends EssentialsCommand
|| user.isAuthorized("essentials.balance.other"))
? user
: getPlayer(server, args, 0, true)).getMoney();
- user.sendMessage(Util.format("balance", Util.formatCurrency(bal)));
+ user.sendMessage(Util.format("balance", Util.formatCurrency(bal, ess)));
}
}
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java b/Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java
index c251f5bb9..1d8b2e619 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandbalancetop.java
@@ -60,7 +60,7 @@ public class Commandbalancetop extends EssentialsCommand
{
break;
}
- sender.sendMessage(entry.getKey().getDisplayName() + ", " + Util.formatCurrency(entry.getValue()));
+ sender.sendMessage(entry.getKey().getDisplayName() + ", " + Util.formatCurrency(entry.getValue(), ess));
count++;
}
}
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandclearinventory.java b/Essentials/src/com/earth2me/essentials/commands/Commandclearinventory.java
index 1fd974691..df9ff6a59 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandclearinventory.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandclearinventory.java
@@ -6,7 +6,6 @@ import org.bukkit.entity.Player;
import com.earth2me.essentials.User;
import com.earth2me.essentials.Util;
import java.util.List;
-import org.bukkit.ChatColor;
public class Commandclearinventory extends EssentialsCommand
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandgive.java b/Essentials/src/com/earth2me/essentials/commands/Commandgive.java
index eeba116e3..b029df098 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandgive.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandgive.java
@@ -2,7 +2,6 @@ package com.earth2me.essentials.commands;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
-import com.earth2me.essentials.ItemDb;
import com.earth2me.essentials.User;
import org.bukkit.ChatColor;
import org.bukkit.Material;
@@ -25,7 +24,7 @@ public class Commandgive extends EssentialsCommand
throw new NotEnoughArgumentsException();
}
- ItemStack stack = ItemDb.get(args[1]);
+ ItemStack stack = ess.getItemDb().get(args[1]);
String itemname = stack.getType().toString().toLowerCase().replace("_", "");
if (sender instanceof Player
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commanditem.java b/Essentials/src/com/earth2me/essentials/commands/Commanditem.java
index 0bcf25ac3..4961f714d 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commanditem.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commanditem.java
@@ -1,10 +1,8 @@
package com.earth2me.essentials.commands;
import org.bukkit.Server;
-import com.earth2me.essentials.ItemDb;
import com.earth2me.essentials.User;
import com.earth2me.essentials.Util;
-import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
@@ -23,7 +21,7 @@ public class Commanditem extends EssentialsCommand
{
throw new NotEnoughArgumentsException();
}
- ItemStack stack = ItemDb.get(args[0]);
+ ItemStack stack = ess.getItemDb().get(args[0]);
String itemname = stack.getType().toString().toLowerCase().replace("_", "");
if (ess.getSettings().permissionBasedItemSpawn()
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandkick.java b/Essentials/src/com/earth2me/essentials/commands/Commandkick.java
index a20f654da..5d3ad4c49 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandkick.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandkick.java
@@ -4,7 +4,6 @@ import org.bukkit.Server;
import org.bukkit.command.CommandSender;
import com.earth2me.essentials.User;
import com.earth2me.essentials.Util;
-import org.bukkit.ChatColor;
public class Commandkick extends EssentialsCommand
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandlist.java b/Essentials/src/com/earth2me/essentials/commands/Commandlist.java
index 39b0723fc..b14136070 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandlist.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandlist.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 org.bukkit.entity.Player;
import com.earth2me.essentials.User;
import com.earth2me.essentials.Util;
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsell.java b/Essentials/src/com/earth2me/essentials/commands/Commandsell.java
index 4a20968b7..66b838051 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandsell.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandsell.java
@@ -1,9 +1,7 @@
package com.earth2me.essentials.commands;
import org.bukkit.Server;
-import com.earth2me.essentials.Essentials;
import com.earth2me.essentials.InventoryWorkaround;
-import com.earth2me.essentials.ItemDb;
import com.earth2me.essentials.Trade;
import com.earth2me.essentials.User;
import com.earth2me.essentials.Util;
@@ -69,7 +67,7 @@ public class Commandsell extends EssentialsCommand
}
if (is == null)
{
- is = ItemDb.get(args[0]);
+ is = ess.getItemDb().get(args[0]);
}
sellItem(user, is, args, false);
}
@@ -157,8 +155,8 @@ public class Commandsell extends EssentialsCommand
user.updateInventory();
Trade.log("Command", "Sell", "Item", user.getName(), new Trade(ris, ess), user.getName(), new Trade(worth*amount, ess), ess);
user.giveMoney(worth * amount);
- user.sendMessage(Util.format("itemSold", Util.formatCurrency(worth * amount), amount, Util.formatCurrency(worth)));
- logger.log(Level.INFO, Util.format("itemSoldConsole", user.getDisplayName(), is.getType().toString().toLowerCase(), Util.formatCurrency(worth * amount), amount, Util.formatCurrency(worth)));
+ user.sendMessage(Util.format("itemSold", Util.formatCurrency(worth * amount, ess), amount, Util.formatCurrency(worth, ess)));
+ logger.log(Level.INFO, Util.format("itemSoldConsole", user.getDisplayName(), is.getType().toString().toLowerCase(), Util.formatCurrency(worth * amount, ess), amount, Util.formatCurrency(worth, ess)));
}
}
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsetjail.java b/Essentials/src/com/earth2me/essentials/commands/Commandsetjail.java
index 047f1d28b..42b5a1953 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandsetjail.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandsetjail.java
@@ -1,7 +1,6 @@
package com.earth2me.essentials.commands;
import org.bukkit.Server;
-import com.earth2me.essentials.Essentials;
import com.earth2me.essentials.User;
import com.earth2me.essentials.Util;
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsetwarp.java b/Essentials/src/com/earth2me/essentials/commands/Commandsetwarp.java
index c62403292..4e799d6c0 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandsetwarp.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandsetwarp.java
@@ -2,7 +2,6 @@ package com.earth2me.essentials.commands;
import org.bukkit.Location;
import org.bukkit.Server;
-import com.earth2me.essentials.Essentials;
import com.earth2me.essentials.User;
import com.earth2me.essentials.Util;
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsetworth.java b/Essentials/src/com/earth2me/essentials/commands/Commandsetworth.java
index 764198828..e6b741c43 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandsetworth.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandsetworth.java
@@ -1,8 +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;
import org.bukkit.inventory.ItemStack;
@@ -23,7 +21,7 @@ public class Commandsetworth extends EssentialsCommand
throw new NotEnoughArgumentsException();
}
- ItemStack stack = ItemDb.get(args[0]);
+ ItemStack stack = ess.getItemDb().get(args[0]);
charge(user);
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 df2f7f954..5e95bad65 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandspawner.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandspawner.java
@@ -5,7 +5,6 @@ import com.earth2me.essentials.Util;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.block.Block;
-import org.bukkit.block.CreatureSpawner;
import org.bukkit.craftbukkit.block.CraftCreatureSpawner;
import org.bukkit.entity.CreatureType;
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java b/Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java
index 33eeb7db7..c15fd6656 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java
@@ -1,6 +1,5 @@
package com.earth2me.essentials.commands;
-import net.minecraft.server.WorldServer;
import org.bukkit.Location;
import org.bukkit.Server;
import com.earth2me.essentials.User;
@@ -13,7 +12,6 @@ import net.minecraft.server.PathEntity;
import org.bukkit.DyeColor;
import org.bukkit.Material;
import org.bukkit.block.Block;
-import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.entity.CraftCreeper;
import org.bukkit.craftbukkit.entity.CraftSheep;
import org.bukkit.craftbukkit.entity.CraftSlime;
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtogglejail.java b/Essentials/src/com/earth2me/essentials/commands/Commandtogglejail.java
index c6b4abee1..899ac37dd 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandtogglejail.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandtogglejail.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.User;
import com.earth2me.essentials.Util;
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandunlimited.java b/Essentials/src/com/earth2me/essentials/commands/Commandunlimited.java
index b6941d5e6..cc519113c 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandunlimited.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandunlimited.java
@@ -1,7 +1,6 @@
package com.earth2me.essentials.commands;
import com.earth2me.essentials.InventoryWorkaround;
-import com.earth2me.essentials.ItemDb;
import com.earth2me.essentials.User;
import com.earth2me.essentials.Util;
import java.util.List;
@@ -56,7 +55,7 @@ public class Commandunlimited extends EssentialsCommand
return;
}
- ItemStack stack = ItemDb.get(args[0], 1);
+ ItemStack stack = ess.getItemDb().get(args[0], 1);
String itemname = stack.getType().toString().toLowerCase().replace("_", "");
if (!user.isAuthorized("essentials.unlimited.item-all")
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java b/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java
index e923bc70e..1dcd59131 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java
@@ -41,7 +41,7 @@ public class Commandwhois extends EssentialsCommand
sender.sendMessage(Util.format("whoisLocation", u.getLocation().getWorld().getName(), u.getLocation().getBlockX(), u.getLocation().getBlockY(), u.getLocation().getBlockZ()));
if (!ess.getSettings().isEcoDisabled())
{
- sender.sendMessage(Util.format("whoisMoney", Util.formatCurrency(u.getMoney())));
+ sender.sendMessage(Util.format("whoisMoney", Util.formatCurrency(u.getMoney(), ess)));
}
sender.sendMessage(u.isAfk()
? Util.i18n("whoisStatusAway")
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandworth.java b/Essentials/src/com/earth2me/essentials/commands/Commandworth.java
index 2ce428cfb..f2d6ed954 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.ItemDb;
import com.earth2me.essentials.User;
import com.earth2me.essentials.Util;
import org.bukkit.inventory.ItemStack;
@@ -22,7 +21,7 @@ public class Commandworth extends EssentialsCommand
if (args.length > 0)
{
- is = ItemDb.get(args[0]);
+ is = ess.getItemDb().get(args[0]);
}
try
@@ -49,13 +48,13 @@ public class Commandworth extends EssentialsCommand
? Util.format("worthMeta",
is.getType().toString().toLowerCase().replace("_", ""),
is.getDurability(),
- Util.formatCurrency(worth * amount),
+ Util.formatCurrency(worth * amount, ess),
amount,
- Util.formatCurrency(worth))
+ Util.formatCurrency(worth, ess))
: Util.format("worth",
is.getType().toString().toLowerCase().replace("_", ""),
- Util.formatCurrency(worth * amount),
+ Util.formatCurrency(worth * amount, ess),
amount,
- Util.formatCurrency(worth)));
+ Util.formatCurrency(worth, ess)));
}
}
diff --git a/Essentials/src/com/earth2me/essentials/register/payment/methods/BOSE.java b/Essentials/src/com/earth2me/essentials/register/payment/methods/BOSE.java
index 444735b65..cce5691b9 100644
--- a/Essentials/src/com/earth2me/essentials/register/payment/methods/BOSE.java
+++ b/Essentials/src/com/earth2me/essentials/register/payment/methods/BOSE.java
@@ -78,7 +78,6 @@ public class BOSE implements Method {
public boolean add(double amount) {
int IntAmount = (int)Math.ceil(amount);
- int balance = (int)this.balance();
return this.BOSEconomy.addPlayerMoney(this.name, IntAmount, false);
}
diff --git a/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java b/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java
index 42f6cc1de..c4853c31e 100644
--- a/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java
+++ b/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java
@@ -3,7 +3,6 @@ package com.earth2me.essentials.signs;
import com.earth2me.essentials.Trade;
import com.earth2me.essentials.ChargeException;
import com.earth2me.essentials.IEssentials;
-import com.earth2me.essentials.ItemDb;
import com.earth2me.essentials.User;
import com.earth2me.essentials.Util;
import java.util.HashSet;
@@ -249,7 +248,7 @@ public class EssentialsSign
final Double money = trade.getMoney();
if (money != null)
{
- sign.setLine(index, Util.formatCurrency(money));
+ sign.setLine(index, Util.formatCurrency(money, ess));
}
}
@@ -266,7 +265,7 @@ public class EssentialsSign
final User player, final IEssentials ess) throws SignException
{
- final ItemStack item = getItemStack(sign.getLine(itemIndex), 1);
+ final ItemStack item = getItemStack(sign.getLine(itemIndex), 1, ess);
final int amount = Math.min(getIntegerPositive(sign.getLine(amountIndex)), item.getType().getMaxStackSize() * player.getInventory().getSize());
if (item.getTypeId() == 0 || amount < 1)
{
@@ -311,11 +310,11 @@ public class EssentialsSign
}
}
- protected final ItemStack getItemStack(final String itemName, final int quantity) throws SignException
+ protected final ItemStack getItemStack(final String itemName, final int quantity, final IEssentials ess) throws SignException
{
try
{
- final ItemStack item = ItemDb.get(itemName);
+ final ItemStack item = ess.getItemDb().get(itemName);
item.setAmount(quantity);
return item;
}
@@ -384,7 +383,7 @@ public class EssentialsSign
}
else
{
- final ItemStack stack = getItemStack(item, quantity);
+ final ItemStack stack = getItemStack(item, quantity, ess);
sign.setLine(index, quantity + " " + item);
return new Trade(stack, ess);
}
diff --git a/Essentials/src/com/earth2me/essentials/signs/SignEntityListener.java b/Essentials/src/com/earth2me/essentials/signs/SignEntityListener.java
index 8b59c7aba..4528c040d 100644
--- a/Essentials/src/com/earth2me/essentials/signs/SignEntityListener.java
+++ b/Essentials/src/com/earth2me/essentials/signs/SignEntityListener.java
@@ -3,7 +3,6 @@ package com.earth2me.essentials.signs;
import com.earth2me.essentials.IEssentials;
import org.bukkit.Material;
import org.bukkit.block.Block;
-import org.bukkit.block.BlockFace;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntityListener;
diff --git a/Essentials/src/com/earth2me/essentials/signs/SignFree.java b/Essentials/src/com/earth2me/essentials/signs/SignFree.java
index 51d232b5d..46c5a0f6e 100644
--- a/Essentials/src/com/earth2me/essentials/signs/SignFree.java
+++ b/Essentials/src/com/earth2me/essentials/signs/SignFree.java
@@ -17,14 +17,14 @@ public class SignFree extends EssentialsSign
@Override
protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException
{
- getItemStack(sign.getLine(1), 9 * 4 * 64);
+ getItemStack(sign.getLine(1), 9 * 4 * 64, ess);
return true;
}
@Override
protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException
{
- final ItemStack item = getItemStack(sign.getLine(1), 9 * 4 * 64);
+ final ItemStack item = getItemStack(sign.getLine(1), 9 * 4 * 64, ess);
final CraftInventoryPlayer inv = new CraftInventoryPlayer(new InventoryPlayer(player.getHandle()));
inv.clear();
inv.addItem(item);
diff --git a/Essentials/src/com/earth2me/essentials/signs/SignTrade.java b/Essentials/src/com/earth2me/essentials/signs/SignTrade.java
index 1b5d72356..544c3216e 100644
--- a/Essentials/src/com/earth2me/essentials/signs/SignTrade.java
+++ b/Essentials/src/com/earth2me/essentials/signs/SignTrade.java
@@ -34,7 +34,7 @@ public class SignTrade extends EssentialsSign
if (sign.getLine(3).substring(2).equalsIgnoreCase(username))
{
final Trade stored = getTrade(sign, 1, true, true, ess);
- substractAmount(sign, 1, stored);
+ substractAmount(sign, 1, stored, ess);
stored.pay(player);
Trade.log("Sign", "Trade", "OwnerInteract", username, null, username, stored, ess);
}
@@ -43,9 +43,9 @@ public class SignTrade extends EssentialsSign
final Trade charge = getTrade(sign, 1, false, false, ess);
final Trade trade = getTrade(sign, 2, false, true, ess);
charge.isAffordableFor(player);
- substractAmount(sign, 2, trade);
+ substractAmount(sign, 2, trade, ess);
trade.pay(player);
- addAmount(sign, 1, charge);
+ addAmount(sign, 1, charge, ess);
charge.charge(player);
Trade.log("Sign", "Trade", "Interact", sign.getLine(3), charge, username, trade, ess);
}
@@ -86,11 +86,11 @@ public class SignTrade extends EssentialsSign
final Double money = getMoney(split[0]);
if (money != null)
{
- if (Util.formatCurrency(money).length() * 2 > 15)
+ if (Util.formatCurrency(money, ess).length() * 2 > 15)
{
throw new SignException("Line can be too long!");
}
- sign.setLine(index, Util.formatCurrency(money) + ":0");
+ sign.setLine(index, Util.formatCurrency(money, ess) + ":0");
return;
}
}
@@ -101,7 +101,7 @@ public class SignTrade extends EssentialsSign
final Double amount = getDoublePositive(split[1]);
if (money != null && amount != null)
{
- sign.setLine(index, Util.formatCurrency(money) + ":" + Util.formatCurrency(amount).substring(1));
+ sign.setLine(index, Util.formatCurrency(money, ess) + ":" + Util.formatCurrency(amount, ess).substring(1));
return;
}
}
@@ -109,7 +109,7 @@ public class SignTrade extends EssentialsSign
if (split.length == 2 && !amountNeeded)
{
final int amount = getIntegerPositive(split[0]);
- final ItemStack item = getItemStack(split[1], amount);
+ final ItemStack item = getItemStack(split[1], amount, ess);
if (amount < 1 || item.getTypeId() == 0)
{
throw new SignException(Util.i18n("moreThanZero"));
@@ -126,7 +126,7 @@ public class SignTrade extends EssentialsSign
if (split.length == 3 && amountNeeded)
{
final int stackamount = getIntegerPositive(split[0]);
- final ItemStack item = getItemStack(split[1], stackamount);
+ final ItemStack item = getItemStack(split[1], stackamount, ess);
int amount = getIntegerPositive(split[2]);
amount -= amount % stackamount;
if (amount < 1 || stackamount < 1 || item.getTypeId() == 0)
@@ -161,7 +161,7 @@ public class SignTrade extends EssentialsSign
if (split.length == 3)
{
final int stackamount = getIntegerPositive(split[0]);
- final ItemStack item = getItemStack(split[1], stackamount);
+ final ItemStack item = getItemStack(split[1], stackamount, ess);
int amount = getInteger(split[2]);
amount -= amount % stackamount;
if (notEmpty && (amount < 1 || stackamount < 1 || item.getTypeId() == 0))
@@ -174,35 +174,35 @@ public class SignTrade extends EssentialsSign
throw new SignException(Util.format("invalidSignLine", index+1));
}
- protected final void substractAmount(final ISign sign, final int index, final Trade trade) throws SignException
+ protected final void substractAmount(final ISign sign, final int index, final Trade trade, final IEssentials ess) throws SignException
{
final Double money = trade.getMoney();
if (money != null)
{
- changeAmount(sign, index, -money);
+ changeAmount(sign, index, -money, ess);
}
final ItemStack item = trade.getItemStack();
if (item != null)
{
- changeAmount(sign, index, -item.getAmount());
+ changeAmount(sign, index, -item.getAmount(), ess);
}
}
- protected final void addAmount(final ISign sign, final int index, final Trade trade) throws SignException
+ protected final void addAmount(final ISign sign, final int index, final Trade trade, final IEssentials ess) throws SignException
{
final Double money = trade.getMoney();
if (money != null)
{
- changeAmount(sign, index, money);
+ changeAmount(sign, index, money, ess);
}
final ItemStack item = trade.getItemStack();
if (item != null)
{
- changeAmount(sign, index, item.getAmount());
+ changeAmount(sign, index, item.getAmount(), ess);
}
}
- private void changeAmount(final ISign sign, final int index, final double value) throws SignException
+ private void changeAmount(final ISign sign, final int index, final double value, final IEssentials ess) throws SignException
{
final String line = sign.getLine(index).trim();
if (line.isEmpty())
@@ -217,7 +217,7 @@ public class SignTrade extends EssentialsSign
final Double amount = getDouble(split[1]);
if (money != null && amount != null)
{
- sign.setLine(index, Util.formatCurrency(money) + ":" + Util.formatCurrency(amount + value).substring(1));
+ sign.setLine(index, Util.formatCurrency(money, ess) + ":" + Util.formatCurrency(amount + value, ess).substring(1));
return;
}
}
@@ -225,8 +225,8 @@ public class SignTrade extends EssentialsSign
if (split.length == 3)
{
final int stackamount = getIntegerPositive(split[0]);
- final ItemStack item = getItemStack(split[1], stackamount);
- int amount = getInteger(split[2]);
+ final ItemStack item = getItemStack(split[1], stackamount, ess);
+ final int amount = getInteger(split[2]);
sign.setLine(index, stackamount + " " + split[1] + ":" + (amount + Math.round(value)));
return;
}
diff --git a/Essentials/test/com/earth2me/essentials/EconomyTest.java b/Essentials/test/com/earth2me/essentials/EconomyTest.java
index 9677c9dd5..ff9a6b6b7 100644
--- a/Essentials/test/com/earth2me/essentials/EconomyTest.java
+++ b/Essentials/test/com/earth2me/essentials/EconomyTest.java
@@ -32,7 +32,7 @@ public class EconomyTest extends TestCase
{
fail("IOException");
}
- server.addPlayer(new OfflinePlayer(PLAYERNAME));
+ server.addPlayer(new OfflinePlayer(PLAYERNAME, ess));
}
// only one big test, since we use static instances
diff --git a/Essentials/test/com/earth2me/essentials/FakeServer.java b/Essentials/test/com/earth2me/essentials/FakeServer.java
index cd30631f7..1d2ddd9c1 100644
--- a/Essentials/test/com/earth2me/essentials/FakeServer.java
+++ b/Essentials/test/com/earth2me/essentials/FakeServer.java
@@ -193,9 +193,9 @@ public class FakeServer implements Server
players.add(base1);
}
- public OfflinePlayer createPlayer(String name)
+ public OfflinePlayer createPlayer(String name, IEssentials ess)
{
- OfflinePlayer player = new OfflinePlayer(name);
+ OfflinePlayer player = new OfflinePlayer(name, ess);
player.setLocation(new Location(worlds.get(0), 0, 0, 0, 0, 0));
return player;
}
diff --git a/Essentials/test/com/earth2me/essentials/UserTest.java b/Essentials/test/com/earth2me/essentials/UserTest.java
index 3bfe0fad0..2b138d687 100644
--- a/Essentials/test/com/earth2me/essentials/UserTest.java
+++ b/Essentials/test/com/earth2me/essentials/UserTest.java
@@ -3,7 +3,6 @@ package com.earth2me.essentials;
import java.io.IOException;
import junit.framework.TestCase;
import org.bukkit.Location;
-import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.plugin.InvalidDescriptionException;
@@ -32,7 +31,7 @@ public class UserTest extends TestCase
{
fail("IOException");
}
- base1 = server.createPlayer("testPlayer1");
+ base1 = server.createPlayer("testPlayer1", ess);
server.addPlayer(base1);
}
@@ -43,7 +42,7 @@ public class UserTest extends TestCase
public void testUpdate()
{
- OfflinePlayer base1alt = server.createPlayer(base1.getName());
+ OfflinePlayer base1alt = server.createPlayer(base1.getName(), ess);
assertEquals(base1alt, ess.getUser(base1alt).getBase());
}
@@ -52,7 +51,7 @@ public class UserTest extends TestCase
User user = ess.getUser(base1);
Location loc = base1.getLocation();
user.setHome();
- OfflinePlayer base2 = server.createPlayer(base1.getName());
+ OfflinePlayer base2 = server.createPlayer(base1.getName(), ess);
User user2 = ess.getUser(base2);
Location home = user2.getHome(loc);
assertEquals(loc.getWorld().getName(), home.getWorld().getName());
diff --git a/Essentials/test/com/earth2me/essentials/UtilTest.java b/Essentials/test/com/earth2me/essentials/UtilTest.java
index 4e7949448..4772b4923 100644
--- a/Essentials/test/com/earth2me/essentials/UtilTest.java
+++ b/Essentials/test/com/earth2me/essentials/UtilTest.java
@@ -1,37 +1,45 @@
package com.earth2me.essentials;
-import java.io.File;
import java.io.IOException;
import java.util.Calendar;
import java.util.GregorianCalendar;
import junit.framework.TestCase;
+import org.bukkit.World.Environment;
+import org.bukkit.plugin.InvalidDescriptionException;
public class UtilTest extends TestCase
{
- public void testFDDnow() {
+ private final Essentials ess;
+ private final FakeServer server;
+
+ public UtilTest()
+ {
+ ess = new Essentials();
+ server = new FakeServer();
+ server.createWorld("testWorld", Environment.NORMAL);
try
{
- Util.updateLocale("en_US", File.createTempFile("test1", "").getParentFile());
+ ess.setupForTesting(server);
+ }
+ catch (InvalidDescriptionException ex)
+ {
+ fail("InvalidDescriptionException");
}
catch (IOException ex)
{
- fail(ex.getMessage());
+ fail("IOException");
}
+ Util.updateLocale("en_US", ess);
+ }
+
+ public void testFDDnow() {
Calendar c = new GregorianCalendar();
String resp = Util.formatDateDiff(c, c);
assertEquals(resp, "now");
}
public void testFDDfuture() {
- try
- {
- Util.updateLocale("en_US", File.createTempFile("test2", "").getParentFile());
- }
- catch (IOException ex)
- {
- fail(ex.getMessage());
- }
Calendar a, b;
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
b = new GregorianCalendar(2010, 1, 1, 10, 0, 1);
@@ -99,14 +107,6 @@ public class UtilTest extends TestCase
}
public void testFDDpast() {
- try
- {
- Util.updateLocale("en_US", File.createTempFile("test3", "").getParentFile());
- }
- catch (IOException ex)
- {
- fail(ex.getMessage());
- }
Calendar a, b;
a = new GregorianCalendar(2010, 1, 1, 10, 0, 0);
b = new GregorianCalendar(2010, 1, 1, 9, 59, 59);
diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChat.java b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChat.java
index 5fb8e9842..fcc734de2 100644
--- a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChat.java
+++ b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChat.java
@@ -1,6 +1,6 @@
package com.earth2me.essentials.chat;
-import com.earth2me.essentials.Essentials;
+import com.earth2me.essentials.IEssentials;
import com.earth2me.essentials.Util;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -17,17 +17,17 @@ public class EssentialsChat extends JavaPlugin
public void onEnable()
{
final PluginManager pluginManager = getServer().getPluginManager();
+ final IEssentials ess = (IEssentials)pluginManager.getPlugin("Essentials");
EssentialsChatPlayerListener.checkFactions(pluginManager);
- final EssentialsChatPlayerListener playerListener = new EssentialsChatPlayerListener(getServer());
- pluginManager.registerEvent(Type.PLAYER_JOIN, playerListener, Priority.Lowest, this);
+ final EssentialsChatPlayerListener playerListener = new EssentialsChatPlayerListener(getServer(), ess);
pluginManager.registerEvent(Type.PLAYER_CHAT, playerListener, Priority.Highest, this);
- if (!this.getDescription().getVersion().equals(Essentials.getStatic().getDescription().getVersion()))
+ if (!this.getDescription().getVersion().equals(ess.getDescription().getVersion()))
{
LOGGER.log(Level.WARNING, Util.i18n("versionMismatchAll"));
}
- LOGGER.info(Util.format("loadinfo", this.getDescription().getName(), this.getDescription().getVersion(), Essentials.AUTHORS));
+ LOGGER.info(Util.format("loadinfo", this.getDescription().getName(), this.getDescription().getVersion(), "essentials team"));
}
public void onDisable()
diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListener.java b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListener.java
index 466641e32..60af127ad 100644
--- a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListener.java
+++ b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListener.java
@@ -1,6 +1,5 @@
package com.earth2me.essentials.chat;
-import com.earth2me.essentials.Essentials;
import com.earth2me.essentials.IEssentials;
import com.earth2me.essentials.User;
import com.earth2me.essentials.Util;
@@ -12,7 +11,6 @@ import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerListener;
-import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
@@ -22,19 +20,14 @@ import org.mcteam.factions.Factions;
public class EssentialsChatPlayerListener extends PlayerListener
{
private static final Logger LOGGER = Logger.getLogger("Minecraft");
- private final transient IEssentials ess = Essentials.getStatic();
+ private final transient IEssentials ess;
private final transient Server server;
private static Factions factions = null;
- public EssentialsChatPlayerListener(final Server server)
+ public EssentialsChatPlayerListener(final Server server, final IEssentials ess)
{
this.server = server;
- }
-
- @Override
- public void onPlayerJoin(final PlayerJoinEvent event)
- {
- final User user = ess.getUser(event.getPlayer());
+ this.ess = ess;
}
@Override
diff --git a/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIP.java b/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIP.java
index ef9d9af27..aa919f44b 100644
--- a/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIP.java
+++ b/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIP.java
@@ -1,6 +1,7 @@
package com.earth2me.essentials.geoip;
import com.earth2me.essentials.Essentials;
+import com.earth2me.essentials.IEssentials;
import com.earth2me.essentials.Util;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -26,14 +27,15 @@ public class EssentialsGeoIP extends JavaPlugin
@Override
public void onEnable()
{
- PluginManager pm = getServer().getPluginManager();
- EssentialsGeoIPPlayerListener playerListener = new EssentialsGeoIPPlayerListener(getDataFolder());
+ final PluginManager pm = getServer().getPluginManager();
+ final IEssentials ess = (IEssentials)pm.getPlugin("Essentials");
+ final EssentialsGeoIPPlayerListener playerListener = new EssentialsGeoIPPlayerListener(getDataFolder(), ess);
pm.registerEvent(Type.PLAYER_JOIN, playerListener, Priority.Monitor, this);
- if (!this.getDescription().getVersion().equals(Essentials.getStatic().getDescription().getVersion())) {
+ if (!this.getDescription().getVersion().equals(ess.getDescription().getVersion())) {
logger.log(Level.WARNING, Util.i18n("versionMismatchAll"));
}
- logger.info(Util.format("loadinfo", this.getDescription().getName(), this.getDescription().getVersion(), Essentials.AUTHORS));
+ logger.info(Util.format("loadinfo", this.getDescription().getName(), this.getDescription().getVersion(), "essentials team"));
logger.log(Level.INFO, "This product includes GeoLite data created by MaxMind, available from http://www.maxmind.com/.");
}
diff --git a/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIPPlayerListener.java b/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIPPlayerListener.java
index a9dd9ad3d..5a6553f0e 100644
--- a/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIPPlayerListener.java
+++ b/EssentialsGeoIP/src/com/earth2me/essentials/geoip/EssentialsGeoIPPlayerListener.java
@@ -1,6 +1,5 @@
package com.earth2me.essentials.geoip;
-import com.earth2me.essentials.Essentials;
import com.earth2me.essentials.EssentialsConf;
import com.earth2me.essentials.IConf;
import com.earth2me.essentials.IEssentials;
@@ -33,9 +32,11 @@ public class EssentialsGeoIPPlayerListener extends PlayerListener implements ICo
File databaseFile;
File dataFolder;
EssentialsConf config;
+ private final transient IEssentials ess;
- public EssentialsGeoIPPlayerListener(File dataFolder)
+ public EssentialsGeoIPPlayerListener(File dataFolder, IEssentials ess)
{
+ this.ess = ess;
this.dataFolder = dataFolder;
this.config = new EssentialsConf(new File(dataFolder, "config.yml"));
config.setTemplateName("/config.yml", EssentialsGeoIP.class);
@@ -45,7 +46,6 @@ public class EssentialsGeoIPPlayerListener extends PlayerListener implements ICo
@Override
public void onPlayerJoin(PlayerJoinEvent event)
{
- IEssentials ess = Essentials.getStatic();
User u = ess.getUser(event.getPlayer());
if (u.isAuthorized("essentials.geoip.hide"))
{
diff --git a/EssentialsPermissionsCommands/src/com/earth2me/essentials/permissions/EssentialsPermissionsCommands.java b/EssentialsPermissionsCommands/src/com/earth2me/essentials/permissions/EssentialsPermissionsCommands.java
index a9651cd31..0f126afb6 100644
--- a/EssentialsPermissionsCommands/src/com/earth2me/essentials/permissions/EssentialsPermissionsCommands.java
+++ b/EssentialsPermissionsCommands/src/com/earth2me/essentials/permissions/EssentialsPermissionsCommands.java
@@ -1,8 +1,11 @@
package com.earth2me.essentials.permissions;
-import com.earth2me.essentials.Essentials;
+import com.earth2me.essentials.IEssentials;
+import com.earth2me.essentials.Util;
import com.nijiko.permissions.PermissionHandler;
import com.nijikokun.bukkit.Permissions.Permissions;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.Plugin;
@@ -13,6 +16,8 @@ import org.bukkit.plugin.java.JavaPlugin;
public class EssentialsPermissionsCommands extends JavaPlugin
{
private static PermissionHandler permissionHandler = null;
+ private static final Logger LOGGER = Logger.getLogger("Minecraft");
+ private IEssentials ess;
public static PermissionHandler getPermissionHandler()
{
@@ -30,12 +35,19 @@ public class EssentialsPermissionsCommands extends JavaPlugin
{
permissionHandler = ((Permissions)permissionsPlugin).getHandler();
}
+ ess = (IEssentials)pluginManager.getPlugin("Essentials");
+
+ if (!this.getDescription().getVersion().equals(ess.getDescription().getVersion())) {
+ LOGGER.log(Level.WARNING, Util.i18n("versionMismatchAll"));
+ }
+ LOGGER.info(Util.format("loadinfo", this.getDescription().getName(), this.getDescription().getVersion(), "essentials team"));
+
}
@Override
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args)
{
- return Essentials.getStatic().onCommandEssentials(sender, command, label, args, EssentialsPermissionsCommands.class.getClassLoader(), "com.earth2me.essentials.permissions.Command", "groupmanager.");
+ return ess.onCommandEssentials(sender, command, label, args, Thread.currentThread().getContextClassLoader(), "com.earth2me.essentials.permissions.Command", "groupmanager.");
}
@Override
diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java
index a8f6a3530..18acd9be3 100644
--- a/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java
+++ b/EssentialsProtect/src/com/earth2me/essentials/protect/EssentialsProtect.java
@@ -1,6 +1,5 @@
package com.earth2me.essentials.protect;
-import com.earth2me.essentials.Essentials;
import com.earth2me.essentials.IConf;
import com.earth2me.essentials.IEssentials;
import com.earth2me.essentials.User;
@@ -34,8 +33,8 @@ public class EssentialsProtect extends JavaPlugin implements IConf, IProtect
public void onEnable()
{
- ess = Essentials.getStatic();
final PluginManager pm = this.getServer().getPluginManager();
+ ess = (IEssentials)pm.getPlugin("Essentials");
final EssentialsProtectPlayerListener playerListener = new EssentialsProtectPlayerListener(this);
pm.registerEvent(Type.PLAYER_INTERACT, playerListener, Priority.Low, this);
@@ -64,7 +63,7 @@ public class EssentialsProtect extends JavaPlugin implements IConf, IProtect
{
LOGGER.log(Level.WARNING, Util.i18n("versionMismatchAll"));
}
- LOGGER.info(Util.format("loadinfo", this.getDescription().getName(), this.getDescription().getVersion(), Essentials.AUTHORS));
+ LOGGER.info(Util.format("loadinfo", this.getDescription().getName(), this.getDescription().getVersion(), "essentials team"));
}
@Override
diff --git a/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandsetspawn.java b/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandsetspawn.java
index 4f997a14e..6f538ac92 100644
--- a/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandsetspawn.java
+++ b/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandsetspawn.java
@@ -1,8 +1,6 @@
package com.earth2me.essentials.spawn;
import org.bukkit.Server;
-import com.earth2me.essentials.Essentials;
-import com.earth2me.essentials.IEssentials;
import com.earth2me.essentials.User;
import com.earth2me.essentials.Util;
import com.earth2me.essentials.commands.EssentialsCommand;
@@ -18,7 +16,6 @@ public class Commandsetspawn extends EssentialsCommand
@Override
public void run(Server server, User user, String commandLabel, String[] args) throws Exception
{
- final IEssentials ess = Essentials.getStatic();
charge(user);
final String group = args.length > 0 ? getFinalArg(args, 0) : "default";
ess.getSpawn().setSpawn(user.getLocation(), group);
diff --git a/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandspawn.java b/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandspawn.java
index 5660c3778..b3ade7634 100644
--- a/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandspawn.java
+++ b/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandspawn.java
@@ -2,8 +2,6 @@ package com.earth2me.essentials.spawn;
import com.earth2me.essentials.Trade;
import org.bukkit.Server;
-import com.earth2me.essentials.Essentials;
-import com.earth2me.essentials.IEssentials;
import com.earth2me.essentials.User;
import com.earth2me.essentials.commands.EssentialsCommand;
@@ -18,7 +16,6 @@ public class Commandspawn extends EssentialsCommand
@Override
public void run(Server server, User user, String commandLabel, String[] args) throws Exception
{
- final IEssentials ess = Essentials.getStatic();
final Trade charge = new Trade(this.getName(), ess);
charge.isAffordableFor(user);
user.getTeleport().respawn(ess.getSpawn(), charge);
diff --git a/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawn.java b/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawn.java
index 77cb9a3cb..fcc8f6276 100644
--- a/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawn.java
+++ b/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawn.java
@@ -1,34 +1,37 @@
package com.earth2me.essentials.spawn;
-import java.io.*;
-import java.util.logging.*;
-import com.earth2me.essentials.*;
-import org.bukkit.command.*;
+
+import com.earth2me.essentials.IEssentials;
+import com.earth2me.essentials.Util;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.Event.Type;
-import org.bukkit.plugin.java.*;
+import org.bukkit.plugin.PluginManager;
+import org.bukkit.plugin.java.JavaPlugin;
public class EssentialsSpawn extends JavaPlugin
{
- public static final String AUTHORS = Essentials.AUTHORS;
- private static final Logger logger = Logger.getLogger("Minecraft");
-
- public EssentialsSpawn() throws IOException
- {
-
- }
+ private static final Logger LOGGER = Logger.getLogger("Minecraft");
+ private transient IEssentials ess;
public void onEnable()
{
- EssentialsSpawnPlayerListener playerListener = new EssentialsSpawnPlayerListener();
- getServer().getPluginManager().registerEvent(Type.PLAYER_RESPAWN, playerListener, Priority.Low, this);
- getServer().getPluginManager().registerEvent(Type.PLAYER_JOIN, playerListener, Priority.Low, this);
-
- if (!this.getDescription().getVersion().equals(Essentials.getStatic().getDescription().getVersion())) {
- logger.log(Level.WARNING, Util.i18n("versionMismatchAll"));
+ final PluginManager pluginManager = getServer().getPluginManager();
+ ess = (IEssentials)pluginManager.getPlugin("Essentials");
+ final EssentialsSpawnPlayerListener playerListener = new EssentialsSpawnPlayerListener(ess);
+ pluginManager.registerEvent(Type.PLAYER_RESPAWN, playerListener, Priority.Low, this);
+ pluginManager.registerEvent(Type.PLAYER_JOIN, playerListener, Priority.Low, this);
+
+
+ if (!this.getDescription().getVersion().equals(ess.getDescription().getVersion()))
+ {
+ LOGGER.log(Level.WARNING, Util.i18n("versionMismatchAll"));
}
- logger.info(Util.format("loadinfo", this.getDescription().getName(), this.getDescription().getVersion(), Essentials.AUTHORS));
+ LOGGER.info(Util.format("loadinfo", this.getDescription().getName(), this.getDescription().getVersion(), "essentials team"));
}
public void onDisable()
@@ -38,6 +41,6 @@ public class EssentialsSpawn extends JavaPlugin
@Override
public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args)
{
- return Essentials.getStatic().onCommandEssentials(sender, command, commandLabel, args, EssentialsSpawn.class.getClassLoader(), "com.earth2me.essentials.spawn.Command", "essentials.");
+ return ess.onCommandEssentials(sender, command, commandLabel, args, Thread.currentThread().getContextClassLoader(), "com.earth2me.essentials.spawn.Command", "essentials.");
}
}
diff --git a/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java b/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java
index 96915bd89..f7395b49f 100644
--- a/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java
+++ b/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java
@@ -1,6 +1,5 @@
package com.earth2me.essentials.spawn;
-import com.earth2me.essentials.Essentials;
import com.earth2me.essentials.IEssentials;
import com.earth2me.essentials.User;
import com.earth2me.essentials.Util;
@@ -14,10 +13,16 @@ import org.bukkit.event.player.PlayerRespawnEvent;
public class EssentialsSpawnPlayerListener extends PlayerListener
{
+ private final transient IEssentials ess;
+
+ public EssentialsSpawnPlayerListener(IEssentials ess)
+ {
+ this.ess = ess;
+ }
+
@Override
public void onPlayerRespawn(final PlayerRespawnEvent event)
{
- final IEssentials ess = Essentials.getStatic();
final User user = ess.getUser(event.getPlayer());
try
@@ -47,7 +52,6 @@ public class EssentialsSpawnPlayerListener extends PlayerListener
@Override
public void onPlayerJoin(final PlayerJoinEvent event)
{
- final IEssentials ess = Essentials.getStatic();
final User user = ess.getUser(event.getPlayer());
if (!user.isNew())
diff --git a/EssentialsXMPP/src/com/earth2me/essentials/xmpp/EssentialsXMPP.java b/EssentialsXMPP/src/com/earth2me/essentials/xmpp/EssentialsXMPP.java
index 04fe1be94..c0e56507c 100644
--- a/EssentialsXMPP/src/com/earth2me/essentials/xmpp/EssentialsXMPP.java
+++ b/EssentialsXMPP/src/com/earth2me/essentials/xmpp/EssentialsXMPP.java
@@ -21,24 +21,25 @@ public class EssentialsXMPP extends JavaPlugin implements IEssentialsXMPP
private static EssentialsXMPP instance = null;
private transient UserManager users;
private transient XMPPManager xmpp;
-
+ private transient IEssentials ess;
+
public static IEssentialsXMPP getInstance()
{
return instance;
}
-
+
@Override
public void onEnable()
{
instance = this;
- final IEssentials ess = Essentials.getStatic();
+ final PluginManager pluginManager = getServer().getPluginManager();
+ ess = (IEssentials)pluginManager.getPlugin("Essentials");
if (ess == null)
{
LOGGER.log(Level.SEVERE, "Failed to load Essentials before EssentialsXMPP");
}
-
- final PluginManager pluginManager = getServer().getPluginManager();
+
final EssentialsXMPPPlayerListener playerListener = new EssentialsXMPPPlayerListener(ess);
pluginManager.registerEvent(Type.PLAYER_JOIN, playerListener, Priority.Monitor, this);
pluginManager.registerEvent(Type.PLAYER_CHAT, playerListener, Priority.Monitor, this);
@@ -46,14 +47,15 @@ public class EssentialsXMPP extends JavaPlugin implements IEssentialsXMPP
users = new UserManager(this.getDataFolder());
xmpp = new XMPPManager(this);
-
+
ess.addReloadListener(users);
ess.addReloadListener(xmpp);
-
- if (!this.getDescription().getVersion().equals(Essentials.getStatic().getDescription().getVersion())) {
+
+ if (!this.getDescription().getVersion().equals(ess.getDescription().getVersion()))
+ {
LOGGER.log(Level.WARNING, Util.i18n("versionMismatchAll"));
}
- LOGGER.info(Util.format("loadinfo", this.getDescription().getName(), this.getDescription().getVersion(), Essentials.AUTHORS));
+ LOGGER.info(Util.format("loadinfo", this.getDescription().getName(), this.getDescription().getVersion(), "essentials team"));
}
@Override
@@ -65,9 +67,9 @@ public class EssentialsXMPP extends JavaPlugin implements IEssentialsXMPP
@Override
public boolean onCommand(final CommandSender sender, final Command command, final String commandLabel, final String[] args)
{
- return Essentials.getStatic().onCommandEssentials(sender, command, commandLabel, args, EssentialsXMPP.class.getClassLoader(), "com.earth2me.essentials.xmpp.Command", "essentials.");
+ return ess.onCommandEssentials(sender, command, commandLabel, args, EssentialsXMPP.class.getClassLoader(), "com.earth2me.essentials.xmpp.Command", "essentials.");
}
-
+
@Override
public void setAddress(final Player user, final String address)
{
@@ -80,7 +82,7 @@ public class EssentialsXMPP extends JavaPlugin implements IEssentialsXMPP
{
return instance.users.getAddress(name);
}
-
+
@Override
public String getUserByAddress(final String address)
{