Heavy cleanup of all classes

ItemDb is not static anymore
Essentials.getStatic() removed
This commit is contained in:
snowleo 2011-07-16 01:33:22 +02:00
parent 25c9557c59
commit a38fe6acd4
48 changed files with 330 additions and 294 deletions

View File

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

View File

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

View File

@ -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))
{

View File

@ -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);
@ -48,12 +45,6 @@ public interface IEssentials
Methods getPaymentMethod();
Server getServer();
File getDataFolder();
PluginDescriptionFile getDescription();
int scheduleAsyncDelayedTask(Runnable run);
int scheduleSyncDelayedTask(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();
}

View File

@ -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 final transient Map<String, Integer> items = new HashMap<String, Integer>();
private final transient Map<String, Short> durabilities = new HashMap<String, Short>();
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>();
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
{
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;
@ -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;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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,8 +54,10 @@ 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));
}
}
@ -54,14 +66,14 @@ public final class Economy
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"))
@ -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,7 +230,7 @@ public final class Economy
*/
public static String format(double amount)
{
return Util.formatCurrency(amount);
return Util.formatCurrency(amount, ess);
}
/**
@ -224,7 +238,8 @@ public final class Economy
* @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;
}
@ -237,7 +252,8 @@ 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();
@ -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);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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")

View File

@ -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")

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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"))
{

View File

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

View File

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

View File

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

View File

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

View File

@ -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);
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(Essentials.getStatic().getDescription().getVersion())) {
logger.log(Level.WARNING, Util.i18n("versionMismatchAll"));
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.");
}
}

View File

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

View File

@ -21,6 +21,7 @@ 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()
{
@ -32,13 +33,13 @@ public class EssentialsXMPP extends JavaPlugin implements IEssentialsXMPP
{
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);
@ -50,10 +51,11 @@ public class EssentialsXMPP extends JavaPlugin implements IEssentialsXMPP
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,7 +67,7 @@ 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