Several bug fixes and cleanup.

Found using PMD and FindBugs.

git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1553 e251c2fe-e539-e718-e476-b85c1f46cddb
This commit is contained in:
snowleo 2011-06-01 10:40:12 +00:00
parent 2a614e53a7
commit 117d938ac5
74 changed files with 645 additions and 354 deletions

View File

@ -0,0 +1 @@
DoNotUseThreads

View File

@ -8,13 +8,15 @@ import org.bukkit.craftbukkit.CraftServer;
public class Backup implements Runnable {
private static final Logger logger = Logger.getLogger("Minecraft");
private CraftServer server;
private final CraftServer server;
private final IEssentials ess;
private boolean running = false;
private int taskId = -1;
private boolean active = false;
public Backup() {
server = (CraftServer)Essentials.getStatic().getServer();
public Backup(IEssentials ess) {
this.ess = ess;
server = (CraftServer)ess.getServer();
if (server.getOnlinePlayers().length > 0) {
startTask();
}
@ -26,11 +28,11 @@ public class Backup implements Runnable {
private void startTask() {
if (!running) {
long interval = Essentials.getStatic().getSettings().getBackupInterval()*1200; // minutes -> ticks
long interval = ess.getSettings().getBackupInterval()*1200; // minutes -> ticks
if (interval < 1200) {
return;
}
taskId = server.getScheduler().scheduleSyncRepeatingTask(Essentials.getStatic(), this, interval, interval);
taskId = ess.scheduleSyncRepeatingTask(this, interval, interval);
running = true;
}
}
@ -38,7 +40,7 @@ public class Backup implements Runnable {
public void run() {
if (active) return;
active = true;
final String command = Essentials.getStatic().getSettings().getBackupCommand();
final String command = ess.getSettings().getBackupCommand();
if (command == null || "".equals(command)) {
return;
}
@ -47,7 +49,7 @@ public class Backup implements Runnable {
server.dispatchCommand(cs, "save-all");
server.dispatchCommand(cs, "save-off");
server.getScheduler().scheduleAsyncDelayedTask(Essentials.getStatic(),
ess.scheduleAsyncDelayedTask(
new Runnable() {
public void run() {
@ -59,7 +61,7 @@ public class Backup implements Runnable {
} catch (IOException ex) {
logger.log(Level.SEVERE, null, ex);
} finally {
server.getScheduler().scheduleSyncDelayedTask(Essentials.getStatic(),
ess.scheduleSyncDelayedTask(
new Runnable() {
public void run() {

View File

@ -1,37 +1,39 @@
package com.earth2me.essentials;
import com.earth2me.essentials.commands.EssentialsCommand;
import org.bukkit.inventory.ItemStack;
public class Charge
{
private String command = null;
private Double costs = null;
private ItemStack items = null;
private Essentials ess = Essentials.getStatic();
private final String command;
private final Double costs;
private final ItemStack items;
private final IEssentials ess;
public Charge(String command)
public Charge(String command, IEssentials ess)
{
this(command, null, null, ess);
}
public Charge(double money, IEssentials ess)
{
this(null, money, null, ess);
}
public Charge(ItemStack items, IEssentials ess)
{
this(null, null, items, ess);
}
private Charge(String command, Double money, ItemStack item, IEssentials ess)
{
this.command = command;
}
public Charge(double money)
{
this.costs = money;
this.items = item;
this.ess = ess;
}
public Charge(ItemStack items)
{
this.items = items;
}
public Charge(EssentialsCommand command)
{
this.command = command.getName();
}
public void isAffordableFor(User user) throws Exception
public void isAffordableFor(IUser user) throws Exception
{
double mon = user.getMoney();
if (costs != null)
@ -63,7 +65,7 @@ public class Charge
}
}
public void charge(User user) throws Exception
public void charge(IUser user) throws Exception
{
double mon = user.getMoney();
if (costs != null)

View File

@ -4,7 +4,7 @@ import org.bukkit.Server;
import org.bukkit.command.CommandSender;
import org.bukkit.craftbukkit.CraftServer;
public class Console implements IReplyTo {
public final class Console implements IReplyTo {
private static Console instance = new Console();
private CommandSender replyTo;
public final static String NAME = "Console";

View File

@ -40,7 +40,7 @@ import org.bukkit.plugin.*;
import org.bukkit.plugin.java.*;
public class Essentials extends JavaPlugin
public class Essentials extends JavaPlugin implements IEssentials
{
public static final String AUTHORS = "Zenexer, ementalo, Aelux, Brettflan, KimKandor, snowleo, ceulemans and Xeology";
public static final int minBukkitBuildVersion = 818;
@ -59,19 +59,15 @@ public class Essentials extends JavaPlugin
public ArrayList bans = new ArrayList();
public ArrayList bannedIps = new ArrayList();
private Backup backup;
private Map<String, User> users = new HashMap<String, User>();
private final Map<String, User> users = new HashMap<String, User>();
private EssentialsTimer timer;
private EssentialsUpdateTimer updateTimer;
private boolean registerFallback = true;
private Methods paymentMethod = new Methods();
private boolean enableErrorLogging = false;
private EssentialsErrorHandler errorHandler = new EssentialsErrorHandler();
private final Methods paymentMethod = new Methods();
private final static boolean enableErrorLogging = false;
private final EssentialsErrorHandler errorHandler = new EssentialsErrorHandler();
public Essentials()
{
}
public static Essentials getStatic()
public static IEssentials getStatic()
{
return instance;
}
@ -119,7 +115,7 @@ public class Essentials extends JavaPlugin
worth = new Worth(this.getDataFolder());
confList.add(worth);
reload();
backup = new Backup();
backup = new Backup(this);
PluginManager pm = getServer().getPluginManager();
for (Plugin plugin : pm.getPlugins())
@ -349,7 +345,7 @@ public class Essentials extends JavaPlugin
public boolean onCommandEssentials(CommandSender sender, Command command, String commandLabel, String[] args, ClassLoader classLoader, String commandPath)
{
if ("msg".equals(commandLabel.toLowerCase()) || "r".equals(commandLabel.toLowerCase()) || "mail".equals(commandLabel.toLowerCase()) & sender instanceof CraftPlayer)
if ("msg".equals(commandLabel.toLowerCase()) || "r".equals(commandLabel.toLowerCase()) || "mail".equals(commandLabel.toLowerCase()) && sender instanceof CraftPlayer)
{
StringBuilder str = new StringBuilder();
str.append(commandLabel).append(" ");
@ -408,13 +404,10 @@ public class Essentials extends JavaPlugin
// New mail notification
if (user != null && !getSettings().isCommandDisabled("mail") && !commandLabel.equals("mail") && user.isAuthorized("essentials.mail"))
{
List<String> mail = user.getMails();
if (mail != null)
final List<String> mail = user.getMails();
if (mail != null && !mail.isEmpty())
{
if (mail.size() > 0)
{
user.sendMessage(Util.format("youHaveNewMail", mail.size()));
}
user.sendMessage(Util.format("youHaveNewMail", mail.size()));
}
}
@ -428,6 +421,7 @@ public class Essentials extends JavaPlugin
try
{
cmd = (IEssentialsCommand)classLoader.loadClass(commandPath + command.getName()).newInstance();
cmd.setEssentials(this);
}
catch (Exception ex)
{
@ -502,15 +496,15 @@ public class Essentials extends JavaPlugin
throw new FileNotFoundException(Util.i18n("bannedPlayersFileNotFound"));
}
BufferedReader rx = new BufferedReader(new FileReader(file));
bans.clear();
final BufferedReader bufferedReader = new BufferedReader(new FileReader(file));
try
{
for (int i = 0; rx.ready(); i++)
bans.clear();
while (bufferedReader.ready())
{
String line = rx.readLine().trim().toLowerCase();
if (line.startsWith("#"))
final String line = bufferedReader.readLine().trim().toLowerCase();
if (line.length() > 0 && line.charAt(0) == '#')
{
continue;
}
@ -522,6 +516,17 @@ public class Essentials extends JavaPlugin
{
logger.log(Level.SEVERE, Util.i18n("bannedPlayersFileError"), io);
}
finally
{
try
{
bufferedReader.close();
}
catch (IOException ex)
{
logger.log(Level.SEVERE, Util.i18n("bannedPlayersFileError"), ex);
}
}
}
catch (FileNotFoundException ex)
{
@ -535,15 +540,15 @@ public class Essentials extends JavaPlugin
throw new FileNotFoundException(Util.i18n("bannedIpsFileNotFound"));
}
BufferedReader rx = new BufferedReader(new FileReader(ipFile));
bannedIps.clear();
final BufferedReader bufferedReader = new BufferedReader(new FileReader(ipFile));
try
{
for (int i = 0; rx.ready(); i++)
bannedIps.clear();
while (bufferedReader.ready())
{
String line = rx.readLine().trim().toLowerCase();
if (line.startsWith("#"))
final String line = bufferedReader.readLine().trim().toLowerCase();
if (line.length() > 0 && line.charAt(0) == '#')
{
continue;
}
@ -555,6 +560,17 @@ public class Essentials extends JavaPlugin
{
logger.log(Level.SEVERE, Util.i18n("bannedIpsFileError"), io);
}
finally
{
try
{
bufferedReader.close();
}
catch (IOException ex)
{
logger.log(Level.SEVERE, Util.i18n("bannedIpsFileError"), ex);
}
}
}
catch (FileNotFoundException ex)
{
@ -577,32 +593,32 @@ public class Essentials extends JavaPlugin
return (CraftScheduler)this.getServer().getScheduler();
}
public static Jail getJail()
public Jail getJail()
{
return getStatic().jail;
return jail;
}
public static Warps getWarps()
public Warps getWarps()
{
return getStatic().warps;
return warps;
}
public static Worth getWorth()
public Worth getWorth()
{
return getStatic().worth;
return worth;
}
public static Backup getBackup()
public Backup getBackup()
{
return getStatic().backup;
return backup;
}
public static Spawn getSpawn()
public Spawn getSpawn()
{
return getStatic().spawn;
return spawn;
}
public <T> User getUser(T base)
public User getUser(Object base)
{
if (base instanceof Player)
{
@ -698,9 +714,34 @@ public class Essentials extends JavaPlugin
return players.length;
}
public Map<BigInteger, String> getErrors()
{
return errorHandler.errors;
return errorHandler.getErrors();
}
public int scheduleAsyncDelayedTask(final Runnable run)
{
return this.getScheduler().scheduleAsyncDelayedTask(this, run);
}
public int scheduleSyncDelayedTask(final Runnable run)
{
return this.getScheduler().scheduleSyncDelayedTask(this, run);
}
public int scheduleSyncRepeatingTask(final Runnable run, long delay, long period)
{
return this.getScheduler().scheduleSyncRepeatingTask(this, run, delay, period);
}
public List<String> getBans()
{
return bans;
}
public List<String> getBannedIps()
{
return bannedIps;
}
}

View File

@ -1,10 +1,13 @@
package com.earth2me.essentials;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.*;
import org.bukkit.block.*;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.Sign;
import org.bukkit.craftbukkit.block.CraftSign;
import org.bukkit.event.block.*;
import org.bukkit.inventory.ItemStack;
@ -12,9 +15,9 @@ import org.bukkit.inventory.ItemStack;
public class EssentialsBlockListener extends BlockListener
{
private final Essentials ess;
private final IEssentials ess;
private static final Logger logger = Logger.getLogger("Minecraft");
public final static ArrayList<Material> protectedBlocks = new ArrayList<Material>(4);
public final static List<Material> protectedBlocks = new ArrayList<Material>(4);
static
{
@ -24,7 +27,7 @@ public class EssentialsBlockListener extends BlockListener
protectedBlocks.add(Material.DISPENSER);
}
public EssentialsBlockListener(Essentials ess)
public EssentialsBlockListener(IEssentials ess)
{
this.ess = ess;
}
@ -144,7 +147,7 @@ public class EssentialsBlockListener extends BlockListener
event.setLine(1, "§dWarp name!");
return;
} else {
Essentials.getWarps().getWarp(event.getLine(1));
ess.getWarps().getWarp(event.getLine(1));
if (event.getLine(2).equalsIgnoreCase("Everyone")) {
event.setLine(2, "§2Everyone");
}
@ -243,7 +246,7 @@ public class EssentialsBlockListener extends BlockListener
}
boolean unlimitedForUser = user.hasUnlimited(is);
if (unlimitedForUser) {
ess.getScheduler().scheduleSyncDelayedTask(ess,
ess.scheduleSyncDelayedTask(
new Runnable() {
public void run() {

View File

@ -40,7 +40,10 @@ public class EssentialsConf extends Configuration
configFile = configFile.getAbsoluteFile();
if (!configFile.getParentFile().exists())
{
configFile.getParentFile().mkdirs();
if (!configFile.getParentFile().mkdirs())
{
logger.log(Level.SEVERE, Util.format("failedToCreateConfig", configFile.toString()));
}
}
if (!configFile.exists())
{
@ -54,7 +57,10 @@ public class EssentialsConf extends Configuration
try
{
logger.log(Level.INFO, Util.format("creatingEmptyConfig", configFile.toString()));
configFile.createNewFile();
if (!configFile.createNewFile())
{
logger.log(Level.SEVERE, Util.format("failedToCreateConfig", configFile.toString()));
}
}
catch (IOException ex)
{
@ -71,10 +77,11 @@ public class EssentialsConf extends Configuration
private void createFromTemplate()
{
InputStream istr = null;
OutputStream ostr = null;
try
{
InputStream istr = resourceClass.getResourceAsStream(templateName);
istr = resourceClass.getResourceAsStream(templateName);
if (istr == null)
{
logger.log(Level.SEVERE, Util.format("couldNotFindTemplate", templateName));
@ -89,7 +96,6 @@ public class EssentialsConf extends Configuration
ostr.write(buffer, 0, length);
length = istr.read(buffer);
}
istr.close();
}
catch (IOException ex)
{
@ -98,6 +104,17 @@ public class EssentialsConf extends Configuration
}
finally
{
try
{
if (istr != null)
{
istr.close();
}
}
catch (IOException ex)
{
Logger.getLogger(EssentialsConf.class.getName()).log(Level.SEVERE, null, ex);
}
try
{
if (ostr != null)
@ -108,7 +125,6 @@ public class EssentialsConf extends Configuration
catch (IOException ex)
{
logger.log(Level.SEVERE, Util.format("failedToCloseConfig", configFile.toString()), ex);
return;
}
}
}

View File

@ -14,7 +14,7 @@ import org.bukkit.inventory.ItemStack;
public class EssentialsEcoBlockListener extends BlockListener
{
Essentials ess;
private final IEssentials ess;
private static final Logger logger = Logger.getLogger("Minecraft");
public EssentialsEcoBlockListener(Essentials ess)

View File

@ -14,10 +14,10 @@ import org.bukkit.inventory.ItemStack;
public class EssentialsEcoPlayerListener extends PlayerListener
{
Essentials ess;
private final IEssentials ess;
private static final Logger logger = Logger.getLogger("Minecraft");
EssentialsEcoPlayerListener(Essentials ess)
EssentialsEcoPlayerListener(IEssentials ess)
{
this.ess = ess;
}

View File

@ -15,11 +15,11 @@ import org.bukkit.inventory.ItemStack;
public class EssentialsEntityListener extends EntityListener
{
private final Essentials ess;
private final IEssentials ess;
public EssentialsEntityListener(Essentials parent)
public EssentialsEntityListener(IEssentials ess)
{
this.ess = parent;
this.ess = ess;
}
@Override

View File

@ -4,6 +4,8 @@ import java.math.BigInteger;
import java.security.MessageDigest;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogRecord;
@ -11,8 +13,8 @@ import java.util.logging.LogRecord;
class EssentialsErrorHandler extends Handler
{
HashMap<BigInteger, String> errors = new HashMap<BigInteger, String>();
private final LinkedList<LogRecord> records = new LinkedList<LogRecord>();
private final Map<BigInteger, String> errors = new HashMap<BigInteger, String>();
private final List<LogRecord> records = new LinkedList<LogRecord>();
public EssentialsErrorHandler()
{
@ -74,7 +76,7 @@ class EssentialsErrorHandler extends Handler
break;
}
}
if (essentialsFound == false && tr.getCause() != null)
if (!essentialsFound && tr.getCause() != null)
{
Throwable cause = tr.getCause();
StackTraceElement[] elements2 = cause.getStackTrace();
@ -118,4 +120,9 @@ class EssentialsErrorHandler extends Handler
}
records.clear();
}
Map<BigInteger, String> getErrors()
{
return errors;
}
}

View File

@ -5,15 +5,30 @@ import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.minecraft.server.InventoryPlayer;
import org.bukkit.*;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.craftbukkit.block.CraftSign;
import org.bukkit.craftbukkit.inventory.CraftInventoryPlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.*;
import org.bukkit.event.player.PlayerAnimationEvent;
import org.bukkit.event.player.PlayerAnimationType;
import org.bukkit.event.player.PlayerBucketEmptyEvent;
import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.event.player.PlayerEggThrowEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerListener;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerLoginEvent.Result;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.inventory.ItemStack;
@ -21,10 +36,10 @@ public class EssentialsPlayerListener extends PlayerListener
{
private static final Logger logger = Logger.getLogger("Minecraft");
private final Server server;
private final Essentials ess;
private EssentialsBlockListener essBlockListener = null;
private final IEssentials ess;
private final EssentialsBlockListener essBlockListener;
public EssentialsPlayerListener(Essentials parent)
public EssentialsPlayerListener(IEssentials parent)
{
this.ess = parent;
this.server = parent.getServer();
@ -40,7 +55,7 @@ public class EssentialsPlayerListener extends PlayerListener
if (user.isJailed() && user.getJail() != null && !user.getJail().isEmpty()) {
try
{
event.setRespawnLocation(Essentials.getJail().getJail(user.getJail()));
event.setRespawnLocation(ess.getJail().getJail(user.getJail()));
}
catch (Exception ex)
{
@ -162,7 +177,7 @@ public class EssentialsPlayerListener extends PlayerListener
event.setTo(loc);
try
{
user.getTeleport().now(loc, new Charge("portal"));
user.getTeleport().now(loc, new Charge("portal", ess));
}
catch (Exception ex)
{
@ -221,7 +236,7 @@ public class EssentialsPlayerListener extends PlayerListener
@Override
public void onPlayerJoin(PlayerJoinEvent event)
{
Essentials.getBackup().onPlayerJoin();
ess.getBackup().onPlayerJoin();
User user = ess.getUser(event.getPlayer());
//we do not know the ip address on playerlogin so we need to do this here.
@ -312,7 +327,7 @@ public class EssentialsPlayerListener extends PlayerListener
}
try
{
event.setTo(Essentials.getJail().getJail(user.getJail()));
event.setTo(ess.getJail().getJail(user.getJail()));
}
catch (Exception ex)
{
@ -498,15 +513,15 @@ public class EssentialsPlayerListener extends PlayerListener
}
if (m1)
{
return new Charge(q1);
return new Charge(q1, ess);
}
else
{
ItemStack i = ItemDb.get(l1[1], (int)q1);
return new Charge(i);
return new Charge(i, ess);
}
}
return new Charge("warpsign");
return new Charge("warpsign", ess);
}
@Override
@ -528,8 +543,7 @@ public class EssentialsPlayerListener extends PlayerListener
if (user.hasUnlimited(new ItemStack(event.getBucket())))
{
event.getItemStack().setType(event.getBucket());
Essentials.getStatic().getScheduler().scheduleSyncDelayedTask(Essentials.getStatic(),
new Runnable()
ess.scheduleSyncDelayedTask(new Runnable()
{
public void run()
{

View File

@ -10,8 +10,8 @@ import org.bukkit.event.server.ServerListener;
public class EssentialsPluginListener extends ServerListener
{
Methods methods;
private final Logger logger = Logger.getLogger("Minecraft");
private final Methods methods;
private static final Logger logger = Logger.getLogger("Minecraft");
public EssentialsPluginListener(Methods methods)
{

View File

@ -9,13 +9,13 @@ import org.bukkit.entity.Player;
public class EssentialsTimer implements Runnable, IConf
{
private Essentials parent;
private Set<User> allUsers = new HashSet<User>();
private final IEssentials ess;
private final Set<User> allUsers = new HashSet<User>();
EssentialsTimer(Essentials parent)
EssentialsTimer(IEssentials ess)
{
this.parent = parent;
File userdir = new File(parent.getDataFolder(), "userdata");
this.ess = ess;
File userdir = new File(ess.getDataFolder(), "userdata");
if (!userdir.exists()) {
return;
}
@ -25,7 +25,7 @@ public class EssentialsTimer implements Runnable, IConf
continue;
}
String name = string.substring(0, string.length()-4);
User u = parent.getUser(new OfflinePlayer(name));
User u = ess.getUser(new OfflinePlayer(name));
allUsers.add(u);
}
}
@ -33,9 +33,9 @@ public class EssentialsTimer implements Runnable, IConf
public void run()
{
long currentTime = System.currentTimeMillis();
for (Player player : parent.getServer().getOnlinePlayers())
for (Player player : ess.getServer().getOnlinePlayers())
{
User u = parent.getUser(player);
User u = ess.getUser(player);
allUsers.add(u);
u.setLastActivity(currentTime);
}
@ -43,8 +43,8 @@ public class EssentialsTimer implements Runnable, IConf
for (User user: allUsers) {
if (user.getBanTimeout() > 0 && user.getBanTimeout() < currentTime) {
user.setBanTimeout(0);
((CraftServer)parent.getServer()).getHandle().b(user.getName());
Essentials.getStatic().loadBanList();
((CraftServer)ess.getServer()).getHandle().b(user.getName());
ess.loadBanList();
}
if (user.getMuteTimeout() > 0 && user.getMuteTimeout() < currentTime && user.isMuted()) {
user.setMuteTimeout(0);

View File

@ -16,7 +16,7 @@ import java.util.logging.Logger;
class EssentialsUpdateTimer implements Runnable
{
private URL url;
private Essentials ess;
private final Essentials ess;
private static final Logger logger = Logger.getLogger("Minecraft");
public EssentialsUpdateTimer(Essentials ess)
@ -40,7 +40,7 @@ class EssentialsUpdateTimer implements Runnable
sb.append("v=").append(URLEncoder.encode(ess.getDescription().getVersion(),"UTF-8"));
sb.append("&b=").append(URLEncoder.encode(ess.getServer().getVersion(),"UTF-8"));
sb.append("&jv=").append(URLEncoder.encode(System.getProperty("java.version"),"UTF-8"));
sb.append("&l=").append(URLEncoder.encode(Util.currentLocale.toString(),"UTF-8"));
sb.append("&l=").append(URLEncoder.encode(Util.getCurrentLocale().toString(),"UTF-8"));
sb.append("&on=").append(URLEncoder.encode(System.getProperty("os.name"),"UTF-8"));
sb.append("&ov=").append(URLEncoder.encode(System.getProperty("os.version"),"UTF-8"));
for (BigInteger bigInteger : ess.getErrors().keySet())

View File

@ -18,16 +18,16 @@ public class EssentialsUpgrade
{
private static boolean alreadyRun = false;
private final static Logger logger = Logger.getLogger("Minecraft");
private Essentials ess;
private final IEssentials ess;
EssentialsUpgrade(String version, Essentials essentials)
EssentialsUpgrade(String version, IEssentials essentials)
{
if (alreadyRun == true)
ess = essentials;
if (alreadyRun)
{
return;
}
alreadyRun = true;
ess = essentials;
}
private void moveWorthValuesToWorthYml()
@ -79,7 +79,7 @@ public class EssentialsUpgrade
}
if (line.matches(regex))
{
if (needUpdate == false && info != null)
if (!needUpdate && info != null)
{
bw.write(info, 0, info.length());
bw.newLine();
@ -246,13 +246,26 @@ public class EssentialsUpgrade
try
{
BufferedReader rx = new BufferedReader(new FileReader(listOfFiles[i]));
double x = Double.parseDouble(rx.readLine().trim());
double y = Double.parseDouble(rx.readLine().trim());
double z = Double.parseDouble(rx.readLine().trim());
float yaw = Float.parseFloat(rx.readLine().trim());
float pitch = Float.parseFloat(rx.readLine().trim());
String worldName = rx.readLine();
rx.close();
double x, y, z;
float yaw, pitch;
String worldName;
try
{
if (!rx.ready()) continue;
x = Double.parseDouble(rx.readLine().trim());
if (!rx.ready()) continue;
y = Double.parseDouble(rx.readLine().trim());
if (!rx.ready()) continue;
z = Double.parseDouble(rx.readLine().trim());
if (!rx.ready()) continue;
yaw = Float.parseFloat(rx.readLine().trim());
if (!rx.ready()) continue;
pitch = Float.parseFloat(rx.readLine().trim());
worldName = rx.readLine();
}
finally {
rx.close();
}
World w = null;
for (World world : ess.getServer().getWorlds())
{
@ -264,7 +277,7 @@ public class EssentialsUpgrade
}
if (worldName != null)
{
worldName.trim();
worldName = worldName.trim();
World w1 = null;
w1 = getFakeWorld(worldName);
if (w1 != null)
@ -273,7 +286,7 @@ public class EssentialsUpgrade
}
}
Location loc = new Location(w, x, y, z, yaw, pitch);
Essentials.getWarps().setWarp(filename.substring(0, filename.length() - 4), loc);
ess.getWarps().setWarp(filename.substring(0, filename.length() - 4), loc);
if (!listOfFiles[i].renameTo(new File(warpsFolder, filename + ".old")))
{
throw new Exception(Util.format("fileRenameError", filename));
@ -293,6 +306,8 @@ public class EssentialsUpgrade
try
{
BufferedReader rx = new BufferedReader(new FileReader(warpFile));
try
{
for (String[] parts = new String[0]; rx.ready(); parts = rx.readLine().split(":"))
{
if (parts.length < 6)
@ -319,12 +334,17 @@ public class EssentialsUpgrade
}
}
Location loc = new Location(w, x, y, z, yaw, pitch);
Essentials.getWarps().setWarp(name, loc);
ess.getWarps().setWarp(name, loc);
if (!warpFile.renameTo(new File(ess.getDataFolder(), "warps.txt.old")))
{
throw new Exception(Util.format("fileRenameError", "warps.txt"));
}
}
}
finally
{
rx.close();
}
}
catch (Exception ex)
{
@ -381,7 +401,7 @@ public class EssentialsUpgrade
return null;
}
void beforeSettings()
public void beforeSettings()
{
if (!ess.getDataFolder().exists())
{
@ -390,7 +410,7 @@ public class EssentialsUpgrade
moveWorthValuesToWorthYml();
}
void afterSettings()
public void afterSettings()
{
sanitizeAllUserFilenames();
updateUsersToNewDefaultHome();

View File

@ -25,8 +25,8 @@ import org.bukkit.util.Vector;
public class FakeWorld implements World
{
private String name;
private Environment env;
private final String name;
private final Environment env;
FakeWorld(String string, Environment environment)
{
this.name = string;

View File

@ -0,0 +1,68 @@
package com.earth2me.essentials;
import com.earth2me.essentials.register.payment.Methods;
import java.io.File;
import java.util.List;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.craftbukkit.scheduler.CraftScheduler;
import org.bukkit.plugin.PluginDescriptionFile;
public interface IEssentials
{
void addReloadListener(IConf listener);
void reload();
boolean onCommandEssentials(CommandSender sender, Command command, String commandLabel, String[] args, ClassLoader classLoader, String commandPath);
User getUser(Object base);
User getOfflineUser(String name);
World getWorld(String name);
int broadcastMessage(String name, String message);
Settings getSettings();
CraftScheduler getScheduler();
String[] getMotd(CommandSender sender, String def);
String[] getLines(CommandSender sender, String node, String def);
Jail getJail();
Warps getWarps();
Worth getWorth();
Backup getBackup();
Spawn getSpawn();
void loadBanList();
public boolean isRegisterFallbackEnabled();
public Methods getPaymentMethod();
Server getServer();
File getDataFolder();
PluginDescriptionFile getDescription();
int scheduleAsyncDelayedTask(Runnable run);
int scheduleSyncDelayedTask(Runnable run);
int scheduleSyncRepeatingTask(final Runnable run, long delay, long period);
List<String> getBans();
List<String> getBannedIps();
}

View File

@ -0,0 +1,51 @@
package com.earth2me.essentials;
import com.earth2me.essentials.commands.IEssentialsCommand;
import java.net.InetSocketAddress;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.inventory.PlayerInventory;
public interface IUser
{
int getHealth();
Location getLocation();
boolean isOnline();
void sendMessage(String string);
long getLastTeleportTimestamp();
boolean isAuthorized(String node);
boolean isAuthorized(IEssentialsCommand cmd);
void setLastTeleportTimestamp(long time);
Location getLastLocation();
Player getBase();
double getMoney();
void takeMoney(double value);
PlayerInventory getInventory();
void updateInventory();
String getGroup();
void setLastLocation();
Location getHome(Location location);
String getName();
InetSocketAddress getAddress();
String getDisplayName();
}

View File

@ -12,8 +12,12 @@ import org.bukkit.inventory.ItemStack;
* is accepted to CraftBukkit
*/
public class InventoryWorkaround
public final class InventoryWorkaround
{
private InventoryWorkaround()
{
}
public static int first(Inventory ci, ItemStack item, boolean forceDurability, boolean forceAmount)
{
return next(ci, item, 0, forceDurability, forceAmount);

View File

@ -12,8 +12,12 @@ import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
public class ItemDb
public final class ItemDb
{
private ItemDb()
{
}
private final static Logger logger = Logger.getLogger("Minecraft");
private static Map<String, Integer> items = new HashMap<String, Integer>();
private static Map<String, Short> durabilities = new HashMap<String, Short>();
@ -27,25 +31,35 @@ public class ItemDb
{
file.createNewFile();
InputStream res = ItemDb.class.getResourceAsStream("/items.csv");
FileWriter tx = new FileWriter(file);
FileWriter tx = null;
try
{
tx = new FileWriter(file);
for (int i = 0; (i = res.read()) > 0;)
{
tx.write(i);
}
tx.flush();
}
finally
{
try
{
tx.flush();
tx.close();
res.close();
}
catch (Exception ex)
{
}
try
{
if (tx != null)
{
tx.close();
}
}
catch (Exception ex)
{
}
}
}

View File

@ -13,10 +13,10 @@ import org.bukkit.event.block.BlockPlaceEvent;
public class Jail extends BlockListener implements IConf
{
private static final Logger logger = Logger.getLogger("Minecraft");
private EssentialsConf config;
private Essentials ess;
private final EssentialsConf config;
private final IEssentials ess;
public Jail(Essentials ess)
public Jail(IEssentials ess)
{
this.ess = ess;
config = new EssentialsConf(new File(ess.getDataFolder(), "jail.yml"));
@ -36,7 +36,7 @@ public class Jail extends BlockListener implements IConf
throw new Exception(Util.i18n("jailNotExist"));
}
Location loc = config.getLocation(jailName.toLowerCase(), Essentials.getStatic().getServer());
Location loc = config.getLocation(jailName.toLowerCase(), ess.getServer());
return loc;
}

View File

@ -6,9 +6,9 @@ import org.bukkit.event.player.PlayerListener;
public class JailPlayerListener extends PlayerListener
{
private final Essentials ess;
private final IEssentials ess;
public JailPlayerListener(Essentials parent)
public JailPlayerListener(IEssentials parent)
{
this.ess = parent;
}

View File

@ -2,6 +2,8 @@ package com.earth2me.essentials;
import java.lang.reflect.Constructor;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.minecraft.server.Entity;
import net.minecraft.server.WorldServer;
@ -68,7 +70,7 @@ public enum Mob
public Enemies type;
private String entityClass;
private String craftClass;
private static final HashMap<String, Mob> hashMap = new HashMap<String, Mob>();
private static final Map<String, Mob> hashMap = new HashMap<String, Mob>();
static
{
@ -93,9 +95,8 @@ public enum Mob
}
catch (Exception ex)
{
logger.warning(Util.i18n("unableToSpawnMob"));
ex.printStackTrace();
throw new MobException();
logger.log(Level.WARNING, Util.i18n("unableToSpawnMob"), ex);
throw new MobException(ex);
}
}
@ -114,9 +115,14 @@ public enum Mob
}
public class MobException extends Exception
public static class MobException extends Exception
{
private static final long serialVersionUID = 1L;
private MobException(Exception ex)
{
super(ex);
}
}
public static Mob fromName(String n)

View File

@ -4,24 +4,27 @@ import org.bukkit.craftbukkit.entity.CraftPlayer;
import net.minecraft.server.EntityPlayer;
import net.minecraft.server.IInventory;
import org.bukkit.craftbukkit.inventory.CraftInventoryPlayer;
import org.bukkit.entity.*;
import org.bukkit.entity.Player;
public class PlayerExtension extends PlayerWrapper
{
public PlayerExtension(Player base)
protected final IEssentials ess;
public PlayerExtension(Player base, IEssentials ess)
{
super(base);
this.ess = ess;
}
public boolean isBanned()
{
return Essentials.getStatic().bans.contains(getName());
return ess.getBans().contains(getName());
}
public boolean isIpBanned()
{
return Essentials.getStatic().bannedIps.contains(getAddress().getAddress().toString().replace("/", ""));
return ess.getBannedIps().contains(getAddress().getAddress().toString().replace("/", ""));
}
public float getCorrectedYaw()

View File

@ -1,19 +1,21 @@
package com.earth2me.essentials;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.ChatColor;
import com.earth2me.essentials.commands.IEssentialsCommand;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.bukkit.entity.CreatureType;
import org.bukkit.inventory.ItemStack;
public class Settings implements IConf
{
private EssentialsConf config;
private final EssentialsConf config;
private final static Logger logger = Logger.getLogger("Minecraft");
public Settings(File dataFolder)
@ -58,7 +60,7 @@ public class Settings implements IConf
return isNetherEnabled() && config.getBoolean("nether.portals-enabled", false);
}
public boolean isCommandDisabled(IEssentialsCommand cmd)
public boolean isCommandDisabled(final IEssentialsCommand cmd)
{
return isCommandDisabled(cmd.getName());
}
@ -121,7 +123,7 @@ public class Settings implements IConf
public String getNicknamePrefix()
{
return config.getString("nickname-prefix", "");
return config.getString("nickname-prefix", "~");
}
public double getTeleportCooldown()
@ -145,6 +147,11 @@ public class Settings implements IConf
}
return null;
}
public Map<String, Object> getKits()
{
return (Map<String, Object>)config.getProperty("kits");
}
public ChatColor getOperatorColor() throws Exception
{
@ -191,9 +198,9 @@ public class Settings implements IConf
return config.getBoolean("non-ess-in-help", true);
}
public HashMap<String, Boolean> getEpSettings()
public Map<String, Boolean> getEpSettings()
{
HashMap<String, Boolean> epSettings = new HashMap<String, Boolean>();
Map<String, Boolean> epSettings = new HashMap<String, Boolean>();
epSettings.put("protect.protect.signs", config.getBoolean("protect.protect.signs", true));
epSettings.put("protect.protect.rails", config.getBoolean("protect.protect.rails", true));
@ -202,9 +209,9 @@ public class Settings implements IConf
return epSettings;
}
public HashMap<String, String> getEpDBSettings()
public Map<String, String> getEpDBSettings()
{
HashMap<String, String> epSettings = new HashMap<String, String>();
Map<String, String> epSettings = new HashMap<String, String>();
epSettings.put("protect.datatype", config.getString("protect.datatype", "sqlite"));
epSettings.put("protect.username", config.getString("protect.username", "root"));
epSettings.put("protect.password", config.getString("protect.password", "root"));
@ -212,9 +219,9 @@ public class Settings implements IConf
return epSettings;
}
public ArrayList<Integer> getEpAlertOnPlacement()
public List<Integer> getEpAlertOnPlacement()
{
ArrayList<Integer> epAlertPlace = new ArrayList<Integer>();
final List<Integer> epAlertPlace = new ArrayList<Integer>();
for (String itemName : config.getString("protect.alert.on-placement", "").split(",")) {
itemName = itemName.trim();
if (itemName.isEmpty()) {
@ -231,9 +238,9 @@ public class Settings implements IConf
return epAlertPlace;
}
public ArrayList<Integer> getEpAlertOnUse()
public List<Integer> getEpAlertOnUse()
{
ArrayList<Integer> epAlertUse = new ArrayList<Integer>();
final List<Integer> epAlertUse = new ArrayList<Integer>();
for (String itemName : config.getString("protect.alert.on-use", "").split(",")) {
itemName = itemName.trim();
if (itemName.isEmpty()) {
@ -250,9 +257,9 @@ public class Settings implements IConf
return epAlertUse;
}
public ArrayList<Integer> getEpAlertOnBreak()
public List<Integer> getEpAlertOnBreak()
{
ArrayList<Integer> epAlertPlace = new ArrayList<Integer>();
final List<Integer> epAlertPlace = new ArrayList<Integer>();
for (String itemName : config.getString("protect.alert.on-break", "").split(",")) {
itemName = itemName.trim();
if (itemName.isEmpty()) {
@ -269,9 +276,9 @@ public class Settings implements IConf
return epAlertPlace;
}
public ArrayList<Integer> epBlackListPlacement()
public List<Integer> epBlackListPlacement()
{
ArrayList<Integer> epBlacklistPlacement = new ArrayList<Integer>();
final List<Integer> epBlacklistPlacement = new ArrayList<Integer>();
for (String itemName : config.getString("protect.blacklist.placement", "").split(",")) {
itemName = itemName.trim();
if (itemName.isEmpty()) {
@ -288,9 +295,9 @@ public class Settings implements IConf
return epBlacklistPlacement;
}
public ArrayList<Integer> epBlackListUsage()
public List<Integer> epBlackListUsage()
{
ArrayList<Integer> epBlackListUsage = new ArrayList<Integer>();
final List<Integer> epBlackListUsage = new ArrayList<Integer>();
for (String itemName : config.getString("protect.blacklist.usage", "").split(",")) {
itemName = itemName.trim();
if (itemName.isEmpty()) {
@ -307,9 +314,9 @@ public class Settings implements IConf
return epBlackListUsage;
}
public HashMap<String, Boolean> getEpGuardSettings()
public Map<String, Boolean> getEpGuardSettings()
{
HashMap<String, Boolean> epSettings = new HashMap<String, Boolean>();
final Map<String, Boolean> epSettings = new HashMap<String, Boolean>();
epSettings.put("protect.prevent.lava-flow", config.getBoolean("protect.prevent.lava-flow", false));
epSettings.put("protect.prevent.water-flow", config.getBoolean("protect.prevent.water-flow", false));
epSettings.put("protect.prevent.water-bucket-flow", config.getBoolean("protect.prevent.water-bucket-flow", false));
@ -323,16 +330,16 @@ public class Settings implements IConf
epSettings.put("protect.prevent.creeper-blockdamage", config.getBoolean("protect.prevent.creeper-blockdamage", false));
epSettings.put("protect.prevent.entitytarget", config.getBoolean("protect.prevent.entitytarget", false));
for (CreatureType ct : CreatureType.values()) {
String name = ct.toString().toLowerCase();
final String name = ct.toString().toLowerCase();
epSettings.put("protect.prevent.spawn."+name, config.getBoolean("protect.prevent.spawn."+name, false));
}
epSettings.put("protect.prevent.lightning-fire-spread", config.getBoolean("protect.prevent.lightning-fire-spread", true));
return epSettings;
}
public HashMap<String, Boolean> getEpPlayerSettings()
public Map<String, Boolean> getEpPlayerSettings()
{
HashMap<String, Boolean> epPlayerSettings = new HashMap<String, Boolean>();
final Map<String, Boolean> epPlayerSettings = new HashMap<String, Boolean>();
epPlayerSettings.put("protect.disable.fall", config.getBoolean("protect.disable.fall", false));
epPlayerSettings.put("protect.disable.pvp", config.getBoolean("protect.disable.pvp", false));
epPlayerSettings.put("protect.disable.drown", config.getBoolean("protect.disable.drown", false));
@ -386,12 +393,12 @@ public class Settings implements IConf
return !config.getString("newbies.announce-format", "-").isEmpty();
}
public String getAnnounceNewPlayerFormat(User user)
public String getAnnounceNewPlayerFormat(IUser user)
{
return format(config.getString("newbies.announce-format", "&dWelcome {DISPLAYNAME} to the server!"), user);
}
public String format(String format, User user)
public String format(String format, IUser user)
{
return format.replace('&', '§').replace("§§", "&").replace("{PLAYER}", user.getDisplayName()).replace("{DISPLAYNAME}", user.getDisplayName()).replace("{GROUP}", user.getGroup()).replace("{USERNAME}", user.getName()).replace("{ADDRESS}", user.getAddress().toString());
}
@ -499,4 +506,14 @@ public class Settings implements IConf
{
return config.getString("currency-symbol", "$").substring(0, 1).replaceAll("[0-9]", "$");
}
public boolean isTradeInStacks(int id)
{
return config.getBoolean("trade-in-stacks-" + id, false);
}
public boolean isEcoDisabled()
{
return config.getBoolean("disable-eco", false);
}
}

View File

@ -12,8 +12,8 @@ import org.bukkit.World.Environment;
public class Spawn implements IConf {
private static final Logger logger = Logger.getLogger("Minecraft");
private EssentialsConf config;
private Server server;
private final EssentialsConf config;
private final Server server;
public Spawn(Server server, File dataFolder) {
File configFile = new File(dataFolder, "spawn.yml");

View File

@ -21,7 +21,7 @@ public class TargetBlock {
private Vector targetPos = new Vector();
private Vector targetPosDouble = new Vector();
private Vector prevPos = new Vector();
private Vector offset = new Vector();
private final Vector offset = new Vector();
/**
* Constructor requiring a player, uses default values

View File

@ -12,17 +12,19 @@ public class Teleport implements Runnable
{
private static class Target
{
private Location location = null;
private Entity entity = null;
private final Location location;
private final Entity entity;
public Target(Location location)
{
this.location = location;
this.entity = null;
}
public Target(Entity entity)
{
this.entity = entity;
this.location = null;
}
public Location getLocation()
@ -34,7 +36,7 @@ public class Teleport implements Runnable
return location;
}
}
User user;
private IUser user;
private int teleTimer = -1;
private long started; // time this task was initiated
private long delay; // how long to delay the teleport
@ -47,7 +49,7 @@ public class Teleport implements Runnable
private long initZ;
private Target teleportTarget;
private Charge chargeFor;
private Essentials ess;
private final IEssentials ess;
private static final Logger logger = Logger.getLogger("Minecraft");
private void initTimer(long delay, Target target, Charge chargeFor)
@ -114,7 +116,7 @@ public class Teleport implements Runnable
}
}
public Teleport(User user, Essentials ess)
public Teleport(IUser user, IEssentials ess)
{
this.user = user;
this.ess = ess;
@ -127,7 +129,7 @@ public class Teleport implements Runnable
public void warp(String warp, Charge chargeFor) throws Exception
{
Location loc = Essentials.getWarps().getWarp(warp);
Location loc = ess.getWarps().getWarp(warp);
teleport(new Target(loc), chargeFor);
user.sendMessage(Util.format("warpingTo", warp));
}
@ -162,7 +164,7 @@ public class Teleport implements Runnable
}
try
{
user.getServer().getScheduler().cancelTask(teleTimer);
ess.getServer().getScheduler().cancelTask(teleTimer);
if (notifyUser)
{
user.sendMessage(Util.i18n("pendingTeleportCancelled"));
@ -193,7 +195,10 @@ public class Teleport implements Runnable
{
double delay = ess.getSettings().getTeleportDelay();
chargeFor.isAffordableFor(user);
if (chargeFor != null)
{
chargeFor.isAffordableFor(user);
}
cooldown(true);
if (delay <= 0 || user.isAuthorized("essentials.teleport.timer.bypass"))
{
@ -213,7 +218,7 @@ public class Teleport implements Runnable
user.sendMessage(Util.format("dontMoveMessage", Util.formatDateDiff(c.getTimeInMillis())));
initTimer((long)(delay * 1000.0), target, chargeFor);
teleTimer = user.getServer().getScheduler().scheduleSyncRepeatingTask(Essentials.getStatic(), this, 10, 10);
teleTimer = ess.scheduleSyncRepeatingTask(this, 10, 10);
}
private void now(Target target) throws Exception
@ -242,7 +247,7 @@ public class Teleport implements Runnable
now(new Target(entity));
}
public void back(final Charge chargeFor) throws Exception
public void back(Charge chargeFor) throws Exception
{
teleport(new Target(user.getLastLocation()), chargeFor);
}
@ -257,14 +262,14 @@ public class Teleport implements Runnable
home(user, chargeFor);
}
public void home(User user, Charge chargeFor) throws Exception
public void home(IUser user, Charge chargeFor) throws Exception
{
Location loc = user.getHome(this.user.getLocation());
if (loc == null)
{
if (ess.getSettings().spawnIfNoHome())
{
respawn(Essentials.getSpawn(), chargeFor);
respawn(ess.getSpawn(), chargeFor);
}
else
{

View File

@ -10,17 +10,17 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class User extends UserData implements Comparable<User>, IReplyTo
public class User extends UserData implements Comparable<User>, IReplyTo, IUser
{
private static final Logger logger = Logger.getLogger("Minecraft");
private boolean justPortaled = false;
private CommandSender replyTo = null;
private User teleportRequester;
private boolean teleportRequestHere;
private Teleport teleport;
private final Teleport teleport;
private long lastActivity;
User(Player base, Essentials ess)
User(Player base, IEssentials ess)
{
super(base, ess);
teleport = new Teleport(this, ess);
@ -120,14 +120,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo
public boolean canAfford(double cost)
{
double mon = getMoney();
if (mon < cost && !isAuthorized("essentials.eco.loan"))
{
return false;
}
else
{
return true;
}
return mon >= cost || isAuthorized("essentials.eco.loan");
}
public void dispose()
@ -160,6 +153,23 @@ public class User extends UserData implements Comparable<User>, IReplyTo
return ChatColor.stripColor(this.getDisplayName()).compareToIgnoreCase(ChatColor.stripColor(t.getDisplayName()));
}
@Override
public boolean equals(Object o)
{
if (!(o instanceof User))
{
return false;
}
return ChatColor.stripColor(this.getDisplayName()).equalsIgnoreCase(ChatColor.stripColor(((User) o).getDisplayName()));
}
@Override
public int hashCode()
{
return ChatColor.stripColor(this.getDisplayName()).hashCode();
}
public Boolean canSpawnItem(int itemId)
{
return !ess.getSettings().itemSpawnBlacklist().contains(itemId);

View File

@ -16,14 +16,12 @@ import org.bukkit.inventory.ItemStack;
public abstract class UserData extends PlayerExtension implements IConf
{
private EssentialsConf config;
private final EssentialsConf config;
private static final Logger logger = Logger.getLogger("Minecraft");
protected Essentials ess;
protected UserData(Player base, Essentials ess)
protected UserData(Player base, IEssentials ess)
{
super(base);
this.ess = ess;
super(base, ess);
File folder = new File(ess.getDataFolder(), "userdata");
if (!folder.exists())
{
@ -61,7 +59,7 @@ public abstract class UserData extends PlayerExtension implements IConf
isNPC = _isNPC();
}
double money;
private double money;
private double _getMoney() {
if (config.hasProperty("money"))
@ -175,7 +173,7 @@ public abstract class UserData extends PlayerExtension implements IConf
private Map<Integer, String> getPowertools()
{
Object o = config.getProperty("powertools");
if (o != null && o instanceof Map)
if (o instanceof Map)
{
return (Map<Integer, String>)o;
}
@ -702,7 +700,7 @@ public abstract class UserData extends PlayerExtension implements IConf
return isNPC;
}
void setNPC(boolean set)
public void setNPC(boolean set)
{
isNPC = set;
config.setProperty("npc", set);

View File

@ -29,8 +29,11 @@ import org.bukkit.block.Block;
public class Util
{
private Util()
{
}
private final static Logger logger = Logger.getLogger("Minecraft");
public static String sanitizeFileName(String name)
{
return name.toLowerCase().replaceAll("[^a-z0-9]", "_");
@ -97,7 +100,7 @@ public class Util
}
private static int dateDiff(int type, Calendar fromDate, Calendar toDate, boolean future)
{
{
int diff = 0;
long savedDate = fromDate.getTimeInMillis();
while ((future && !fromDate.after(toDate)) || (!future && !fromDate.before(toDate)))
@ -296,11 +299,16 @@ public class Util
return Math.round(d * 100.0) / 100.0;
}
public static Locale getCurrentLocale()
{
return currentLocale;
}
private static class ConfigClassLoader extends ClassLoader
{
private File dataFolder;
private ClassLoader cl;
private final File dataFolder;
private final ClassLoader cl;
public ConfigClassLoader(File dataFolder, ClassLoader cl)
{
@ -389,16 +397,17 @@ public class Util
}
}
private static final Locale defaultLocale = Locale.getDefault();
public static Locale currentLocale = defaultLocale;
private static Locale currentLocale = defaultLocale;
private static ResourceBundle bundle = ResourceBundle.getBundle("messages", defaultLocale);
private static ResourceBundle defaultBundle = ResourceBundle.getBundle("messages", Locale.US);
public static String i18n(String string)
{
try {
try
{
return bundle.getString(string);
}
catch (MissingResourceException ex)
catch (MissingResourceException ex)
{
logger.log(Level.WARNING, String.format("Missing translation key \"%s\" in translation file %s", ex.getKey(), bundle.getLocale().toString()), ex);
return defaultBundle.getString(string);
@ -432,7 +441,8 @@ public class Util
}
logger.log(Level.INFO, String.format("Using locale %s", currentLocale.toString()));
bundle = ResourceBundle.getBundle("messages", currentLocale, new ConfigClassLoader(dataFolder, Util.class.getClassLoader()));
if (!bundle.keySet().containsAll(defaultBundle.keySet())) {
if (!bundle.keySet().containsAll(defaultBundle.keySet()))
{
logger.log(Level.WARNING, String.format("Translation file %s does not contain all translation keys.", currentLocale.toString()));
}
}

View File

@ -15,9 +15,9 @@ import org.bukkit.Server;
public class Warps implements IConf
{
private static final Logger logger = Logger.getLogger("Minecraft");
Map<StringIgnoreCase, EssentialsConf> warpPoints = new HashMap<StringIgnoreCase, EssentialsConf>();
File warpsFolder;
Server server;
private final Map<StringIgnoreCase, EssentialsConf> warpPoints = new HashMap<StringIgnoreCase, EssentialsConf>();
private final File warpsFolder;
private final Server server;
public Warps(Server server, File dataFolder)
{
@ -40,7 +40,7 @@ public class Warps implements IConf
List<String> keys = new ArrayList<String>();
for (StringIgnoreCase stringIgnoreCase : warpPoints.keySet())
{
keys.add(stringIgnoreCase.string);
keys.add(stringIgnoreCase.getString());
}
Collections.sort(keys, String.CASE_INSENSITIVE_ORDER);
return keys;
@ -120,9 +120,9 @@ public class Warps implements IConf
}
private class StringIgnoreCase
private static class StringIgnoreCase
{
String string;
private final String string;
public StringIgnoreCase(String string)
{
@ -132,21 +132,22 @@ public class Warps implements IConf
@Override
public int hashCode()
{
return string.toLowerCase().hashCode();
return getString().toLowerCase().hashCode();
}
@Override
public boolean equals(Object o)
{
if (o instanceof String)
{
return string.equalsIgnoreCase((String)o);
}
if (o instanceof StringIgnoreCase)
{
return string.equalsIgnoreCase(((StringIgnoreCase)o).string);
return getString().equalsIgnoreCase(((StringIgnoreCase)o).getString());
}
return false;
}
public String getString()
{
return string;
}
}
}

View File

@ -8,7 +8,7 @@ import org.bukkit.inventory.ItemStack;
public class Worth implements IConf
{
private static final Logger logger = Logger.getLogger("Minecraft");
private EssentialsConf config;
private final EssentialsConf config;
public Worth(File dataFolder)
{

View File

@ -14,8 +14,11 @@ import org.bukkit.entity.Player;
* Instead of using this api directly, we recommend to use the register plugin:
* http://bit.ly/RegisterMethod
*/
public class Economy
public final class Economy
{
private Economy()
{
}
private static final Logger logger = Logger.getLogger("Minecraft");
private static void createNPCFile(String name)

View File

@ -16,7 +16,7 @@ public class Commandback extends EssentialsCommand
@Override
protected void run(Server server, User user, String commandLabel, String[] args) throws Exception
{
Charge charge = new Charge(this);
Charge charge = new Charge(this.getName(), ess);
charge.isAffordableFor(user);
user.sendMessage(Util.i18n("backUsageMsg"));
user.getTeleport().back(charge);

View File

@ -1,7 +1,6 @@
package com.earth2me.essentials.commands;
import com.earth2me.essentials.Backup;
import com.earth2me.essentials.Essentials;
import com.earth2me.essentials.Util;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
@ -17,7 +16,7 @@ public class Commandbackup extends EssentialsCommand
@Override
protected void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception
{
Backup backup = Essentials.getBackup();
Backup backup = ess.getBackup();
if (backup == null)
{
return;

View File

@ -17,7 +17,7 @@ public class Commandbigtree extends EssentialsCommand
@Override
public void run(Server server, User user, String commandLabel, String[] args) throws Exception
{
Object tree = new Object();
TreeType tree = TreeType.TREE;
if (args.length > 0 && args[0].equalsIgnoreCase("redwood"))
{
tree = TreeType.TALL_REDWOOD;

View File

@ -1,6 +1,5 @@
package com.earth2me.essentials.commands;
import com.earth2me.essentials.Essentials;
import com.earth2me.essentials.Util;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
@ -18,7 +17,7 @@ public class Commanddeljail extends EssentialsCommand {
throw new NotEnoughArgumentsException();
}
charge(sender);
Essentials.getJail().delJail(args[0]);
ess.getJail().delJail(args[0]);
sender.sendMessage(Util.format("deleteJail", args[0]));
}
}

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.Util;
@ -21,7 +20,7 @@ public class Commanddelwarp extends EssentialsCommand
throw new NotEnoughArgumentsException();
}
charge(sender);
Essentials.getWarps().delWarp(args[0]);
ess.getWarps().delWarp(args[0]);
sender.sendMessage(Util.format("deleteWarp", args[0]));
}
}

View File

@ -30,7 +30,7 @@ public class Commandeco extends EssentialsCommand
}
catch (Exception ex)
{
throw new NotEnoughArgumentsException();
throw new NotEnoughArgumentsException(ex);
}
if (args[1].contentEquals("*"))

View File

@ -14,6 +14,7 @@ import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.SafeConstructor;
import com.earth2me.essentials.User;
import com.earth2me.essentials.Util;
import java.util.Map.Entry;
import java.util.logging.Level;
@ -71,10 +72,18 @@ public class Commandhelp extends EssentialsCommand
}
if (helpFile.exists())
{
BufferedReader rx = new BufferedReader(new FileReader(helpFile));
for (String l = null; rx.ready() && (l = rx.readLine()) != null;)
final BufferedReader bufferedReader = new BufferedReader(new FileReader(helpFile));
try {
while (bufferedReader.ready())
{
final String line = bufferedReader.readLine();
retval.add(line.replace('&', '§'));
}
}
finally
{
retval.add(l.replace('&', '§'));
bufferedReader.close();
}
return retval;
}
@ -85,17 +94,16 @@ public class Commandhelp extends EssentialsCommand
{
try
{
PluginDescriptionFile desc = p.getDescription();
HashMap<String, HashMap<String, String>> cmds = (HashMap<String, HashMap<String, String>>)desc.getCommands();
for (String k : cmds.keySet())
final PluginDescriptionFile desc = p.getDescription();
final HashMap<String, HashMap<String, String>> cmds = (HashMap<String, HashMap<String, String>>)desc.getCommands();
for (Entry<String, HashMap<String, String>> k : cmds.entrySet())
{
if (p.getDescription().getName().toLowerCase().contains("essentials"))
{
String node = "essentials." + k;
if (!ess.getSettings().isCommandDisabled(k) && user.isAuthorized(node))
final String node = "essentials." + k.getKey();
if (!ess.getSettings().isCommandDisabled(k.getKey()) && user.isAuthorized(node))
{
HashMap<String, String> v = cmds.get(k);
retval.add("§c" + k + "§7: " + v.get("description"));
retval.add("§c" + k.getKey() + "§7: " + k.getValue().get("description"));
}
}
else
@ -103,17 +111,17 @@ public class Commandhelp extends EssentialsCommand
if (ess.getSettings().showNonEssCommandsInHelp())
{
pluginName = p.getDescription().getName();
HashMap<String, String> v = cmds.get(k);
if (v.containsKey("permission") && v.get("permission") != null && !(v.get("permission").equals("")))
final HashMap<String, String> value = k.getValue();
if (value.containsKey("permission") && value.get("permission") != null && !(value.get("permission").equals("")))
{
if (user.isAuthorized(v.get("permission")))
if (user.isAuthorized(value.get("permission")))
{
retval.add("§c" + k + "§7: " + v.get("description"));
retval.add("§c" + k.getKey() + "§7: " + value.get("description"));
}
}
else
{
retval.add("§c" + k + "§7: " + v.get("description"));
retval.add("§c" + k.getKey() + "§7: " + value.get("description"));
}
}
@ -128,10 +136,7 @@ public class Commandhelp extends EssentialsCommand
{
if (!reported)
{
logger.log(Level.WARNING, "Error getting help for:" + pluginName);
ex.printStackTrace();
logger.log(Level.WARNING, "Error getting help for:" + pluginName, ex);
}
reported = true;
continue;

View File

@ -16,7 +16,7 @@ public class Commandhome extends EssentialsCommand
@Override
public void run(Server server, User user, String commandLabel, String[] args) throws Exception
{
Charge charge = new Charge(this);
Charge charge = new Charge(this.getName(), ess);
charge.isAffordableFor(user);
if(args.length > 0 && user.isAuthorized("essentials.home.others"))
{

View File

@ -45,16 +45,25 @@ public class Commandinfo extends EssentialsCommand
}
if (file.exists())
{
BufferedReader rx = new BufferedReader(new FileReader(file));
int i = 0;
for (String l = null; rx.ready() && (l = rx.readLine()) != null; i++)
final BufferedReader bufferedReader = new BufferedReader(new FileReader(file));
try
{
if (l.startsWith("#"))
int lineNumber = 0;
while (bufferedReader.ready())
{
bookmarks.put(l.substring(1).toLowerCase().replaceAll("&[0-9a-f]", ""), i);
chapters.add(l.substring(1).replace('&', '§'));
final String line = bufferedReader.readLine();
if (line.length() > 0 && line.charAt(0) == '#')
{
bookmarks.put(line.substring(1).toLowerCase().replaceAll("&[0-9a-f]", ""), lineNumber);
chapters.add(line.substring(1).replace('&', '§'));
}
lines.add(line.replace('&', '§'));
lineNumber++;
}
lines.add(l.replace('&', '§'));
}
finally
{
bufferedReader.close();
}
}
else

View File

@ -1,6 +1,5 @@
package com.earth2me.essentials.commands;
import com.earth2me.essentials.Essentials;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
@ -16,7 +15,7 @@ public class Commandjails extends EssentialsCommand
protected void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception
{
StringBuilder jailList = new StringBuilder();
for (String j : Essentials.getJail().getJails())
for (String j : ess.getJail().getJails())
{
jailList.append(j);
jailList.append(' ');

View File

@ -36,7 +36,7 @@ public class Commandjump extends EssentialsCommand
throw new Exception(Util.i18n("jumpError"), ex);
}
Charge charge = new Charge(this);
Charge charge = new Charge(this.getName(), ess);
charge.isAffordableFor(user);
user.getTeleport().teleport(loc, charge);
}

View File

@ -22,14 +22,13 @@ public class Commandkit extends EssentialsCommand
}
@Override
@SuppressWarnings("unchecked")
public void run(Server server, User user, String commandLabel, String[] args) throws Exception
{
if (args.length < 1)
{
try
{
Map<String, Object> kits = (Map<String, Object>)ess.getConfiguration().getProperty("kits");
Map<String, Object> kits = ess.getSettings().getKits();
StringBuilder list = new StringBuilder();
for (String k : kits.keySet())
{
@ -110,7 +109,7 @@ public class Commandkit extends EssentialsCommand
items = (List<String>)kit;
}
Charge charge = new Charge("kit-" + kitName);
Charge charge = new Charge("kit-" + kitName, ess);
try
{
charge.isAffordableFor(user);

View File

@ -67,7 +67,7 @@ public class Commandnick extends EssentialsCommand
}
charge(user);
user.setDisplayName(ess.getConfiguration().getString("nickname-prefix", "~") + nick);
user.setDisplayName(ess.getSettings().getNicknamePrefix() + nick);
user.setNickname(nick);
user.sendMessage(Util.format("nickSet", user.getDisplayName() + "§7."));
}

View File

@ -22,6 +22,7 @@ public class Commandpowertool extends EssentialsCommand
if (is == null || is.getType() == Material.AIR)
{
user.sendMessage(Util.i18n("powerToolAir"));
return;
}
String command = getFinalArg(args, 0);
if (command != null && !command.isEmpty())

View File

@ -1,7 +1,6 @@
package com.earth2me.essentials.commands;
import com.earth2me.essentials.Util;
import com.earth2me.essentials.commands.EssentialsCommand;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;

View File

@ -89,9 +89,9 @@ public class Commandsell extends EssentialsCommand
amount = -amount;
}
}
double worth = Essentials.getWorth().getPrice(is);
double worth = ess.getWorth().getPrice(is);
boolean stack = args.length > 1 && args[1].endsWith("s");
boolean requireStack = ess.getConfiguration().getBoolean("trade-in-stacks-" + id, false);
boolean requireStack = ess.getSettings().isTradeInStacks(id);
if (Double.isNaN(worth))
{

View File

@ -21,7 +21,7 @@ public class Commandsetjail extends EssentialsCommand
throw new NotEnoughArgumentsException();
}
charge(user);
Essentials.getJail().setJail(user.getLocation(), args[0]);
ess.getJail().setJail(user.getLocation(), args[0]);
user.sendMessage(Util.format("jailSet",args[0]));
}

View File

@ -24,7 +24,7 @@ public class Commandsetwarp extends EssentialsCommand
charge(user);
Location loc = user.getLocation();
Essentials.getWarps().setWarp(args[0], loc);
ess.getWarps().setWarp(args[0], loc);
user.sendMessage(Util.format("warpSet", args[0]));
}
}

View File

@ -25,7 +25,7 @@ public class Commandsetworth extends EssentialsCommand
ItemStack stack = ItemDb.get(args[0]);
charge(user);
Essentials.getWorth().setPrice(stack, Double.parseDouble(args[1]));
ess.getWorth().setPrice(stack, Double.parseDouble(args[1]));
user.sendMessage(Util.i18n("worthSet"));
}
}

View File

@ -37,7 +37,7 @@ public class Commandspawner extends EssentialsCommand
}
catch (Throwable ex)
{
throw new Exception(Util.i18n("mobSpawnError"));
throw new Exception(Util.i18n("mobSpawnError"), ex);
}
}
}

View File

@ -173,15 +173,15 @@ public class Commandspawnmob extends EssentialsCommand
}
catch (MobException e1)
{
throw new Exception(Util.i18n("unableToSpawnMob"));
throw new Exception(Util.i18n("unableToSpawnMob"), e1);
}
catch (NumberFormatException e2)
{
throw new Exception(Util.i18n("numberRequired"));
throw new Exception(Util.i18n("numberRequired"), e2);
}
catch (NullPointerException np)
{
throw new Exception(Util.i18n("soloMob"));
throw new Exception(Util.i18n("soloMob"), np);
}
}
else
@ -205,7 +205,7 @@ public class Commandspawnmob extends EssentialsCommand
}
catch (Exception e)
{
throw new Exception(Util.i18n("slimeMalformedSize"));
throw new Exception(Util.i18n("slimeMalformedSize"), e);
}
}
if ("Sheep".equalsIgnoreCase(type))
@ -216,7 +216,7 @@ public class Commandspawnmob extends EssentialsCommand
}
catch (Exception e)
{
throw new Exception(Util.i18n("sheepMalformedColor"));
throw new Exception(Util.i18n("sheepMalformedColor"), e);
}
}
if ("Wolf".equalsIgnoreCase(type) && data.equalsIgnoreCase("tamed"))

View File

@ -36,7 +36,7 @@ public class Commandtogglejail extends EssentialsCommand
p.setJailed(true);
p.sendMessage(Util.i18n("userJailed"));
p.setJail(null);
Essentials.getJail().sendToJail(p, args[1]);
ess.getJail().sendToJail(p, args[1]);
p.setJail(args[1]);
long timeDiff = 0;
if (args.length > 2)

View File

@ -21,7 +21,7 @@ public class Commandtop extends EssentialsCommand
int topZ = user.getLocation().getBlockZ();
int topY = user.getWorld().getHighestBlockYAt(topX, topZ);
charge(user);
user.getTeleport().teleport(new Location(user.getWorld(), user.getLocation().getX(), topY + 1, user.getLocation().getZ()), new Charge(this));
user.getTeleport().teleport(new Location(user.getWorld(), user.getLocation().getX(), topY + 1, user.getLocation().getZ()), new Charge(this.getName(), ess));
user.sendMessage(Util.i18n("teleportTop"));
}
}

View File

@ -30,7 +30,7 @@ public class Commandtp extends EssentialsCommand
throw new Exception(Util.format("teleportDisabled", p.getDisplayName()));
}
user.sendMessage(Util.i18n("teleporting"));
Charge charge = new Charge(this);
Charge charge = new Charge(this.getName(), ess);
charge.isAffordableFor(user);
user.getTeleport().teleport(p, charge);
break;

View File

@ -23,7 +23,7 @@ public class Commandtpaccept extends EssentialsCommand
throw new Exception(Util.i18n("noPendingRequest"));
}
Charge charge = new Charge(this);
Charge charge = new Charge(this.getName(), ess);
if (user.isTeleportRequestHere())
{
charge.isAffordableFor(user);

View File

@ -21,7 +21,7 @@ public class Commandtphere extends EssentialsCommand
{
throw new Exception(Util.format("teleportDisabled", p.getDisplayName()));
}
p.getTeleport().teleport(user, new Charge(this));
p.getTeleport().teleport(user, new Charge(this.getName(), ess));
user.sendMessage(Util.i18n("teleporting"));
p.sendMessage(Util.i18n("teleporting"));
}

View File

@ -26,7 +26,7 @@ public class Commandtppos extends EssentialsCommand
int y = Integer.parseInt(args[1]);
int z = Integer.parseInt(args[2]);
Location l = new Location(user.getWorld(), x, y, z);
Charge charge = new Charge(this);
Charge charge = new Charge(this.getName(), ess);
charge.isAffordableFor(user);
user.sendMessage(Util.i18n("teleporting"));
user.getTeleport().teleport(l, charge);

View File

@ -2,7 +2,6 @@ package com.earth2me.essentials.commands;
import com.earth2me.essentials.Charge;
import org.bukkit.Server;
import com.earth2me.essentials.Essentials;
import com.earth2me.essentials.User;
import com.earth2me.essentials.Util;
import com.earth2me.essentials.Warps;
@ -27,7 +26,7 @@ public class Commandwarp extends EssentialsCommand
return;
}
Warps warps = Essentials.getWarps();
Warps warps = ess.getWarps();
if (warps.isEmpty())
{
throw new Exception(Util.i18n("noWarpsDefined"));
@ -74,7 +73,7 @@ public class Commandwarp extends EssentialsCommand
private void warpUser(User user, String name) throws Exception
{
Charge charge = new Charge(this);
Charge charge = new Charge(this.getName(), ess);
charge.isAffordableFor(user);
if (ess.getSettings().getPerWarpPermission())
{

View File

@ -39,7 +39,7 @@ public class Commandwhois extends EssentialsCommand
sender.sendMessage(Util.format("whoisIs", u.getDisplayName(), u.getName()));
sender.sendMessage(Util.format("whoisHealth", u.getHealth()));
sender.sendMessage(Util.format("whoisLocation", u.getLocation().getWorld().getName(), u.getLocation().getBlockX(), u.getLocation().getBlockY(), u.getLocation().getBlockZ()));
if (!ess.getConfiguration().getBoolean("disable-eco", false))
if (!ess.getSettings().isEcoDisabled())
{
sender.sendMessage(Util.format("whoisMoney", Util.formatCurrency(u.getMoney())));
}
@ -47,11 +47,11 @@ public class Commandwhois extends EssentialsCommand
? Util.i18n("whoisStatusAway")
: Util.i18n("whoisStatusAvailable"));
sender.sendMessage(Util.format("whoisIPAddress", u.getAddress().getAddress().toString()));
String location = u.getGeoLocation();
final String location = u.getGeoLocation();
if (location != null
&& (sender instanceof Player ? ess.getUser(sender).isAuthorized("essentials.geoip.show") : true))
{
sender.sendMessage(Util.format("whoisGeoLocation", location.toString()));
sender.sendMessage(Util.format("whoisGeoLocation", location));
}
}
}

View File

@ -5,7 +5,6 @@ import java.util.List;
import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.World;
import com.earth2me.essentials.Essentials;
import com.earth2me.essentials.User;
import com.earth2me.essentials.Util;
@ -69,7 +68,7 @@ public class Commandworld extends EssentialsCommand
Location loc = user.getLocation();
loc = new Location(world, loc.getBlockX() * factor + .5, loc.getBlockY(), loc.getBlockZ() * factor + .5);
Charge charge = new Charge(this);
Charge charge = new Charge(this.getName(), ess);
charge.isAffordableFor(user);
user.getTeleport().teleport(loc, charge);
}

View File

@ -1,7 +1,6 @@
package com.earth2me.essentials.commands;
import org.bukkit.Server;
import com.earth2me.essentials.Essentials;
import com.earth2me.essentials.ItemDb;
import com.earth2me.essentials.User;
import com.earth2me.essentials.Util;
@ -39,7 +38,7 @@ public class Commandworth extends EssentialsCommand
}
is.setAmount(amount);
double worth = Essentials.getWorth().getPrice(is);
double worth = ess.getWorth().getPrice(is);
if (Double.isNaN(worth))
{
throw new Exception(Util.i18n("itemCannotBeSold"));

View File

@ -6,6 +6,7 @@ import org.bukkit.Server;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import com.earth2me.essentials.Essentials;
import com.earth2me.essentials.IEssentials;
import org.bukkit.entity.Player;
import com.earth2me.essentials.User;
import com.earth2me.essentials.Util;
@ -15,13 +16,17 @@ import java.util.logging.Logger;
public abstract class EssentialsCommand implements IEssentialsCommand
{
private final String name;
protected Essentials ess;
protected IEssentials ess;
protected final static Logger logger = Logger.getLogger("Minecraft");
protected EssentialsCommand(String name)
{
this.name = name;
this.ess = Essentials.getStatic();
}
public void setEssentials(IEssentials ess)
{
this.ess = ess;
}
public String getName()
@ -84,7 +89,7 @@ public abstract class EssentialsCommand implements IEssentialsCommand
{
if (sender instanceof Player)
{
Charge charge = new Charge(this);
Charge charge = new Charge(this.getName(), ess);
charge.charge(ess.getUser((Player)sender));
}
}

View File

@ -1,9 +1,10 @@
package com.earth2me.essentials.commands;
import org.bukkit.*;
import com.earth2me.essentials.IEssentials;
import com.earth2me.essentials.User;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import com.earth2me.essentials.*;
import org.bukkit.Server;
public interface IEssentialsCommand
@ -15,4 +16,6 @@ public interface IEssentialsCommand
void run(Server server, CommandSender sender, String commandLabel, Command cmd, String[] args)
throws Exception;
void setEssentials(IEssentials ess);
}

View File

@ -2,4 +2,14 @@ package com.earth2me.essentials.commands;
public class NotEnoughArgumentsException extends Exception {
public NotEnoughArgumentsException()
{
super();
}
public NotEnoughArgumentsException(final Throwable ex)
{
super(ex);
}
}

View File

@ -12,8 +12,8 @@ import org.bukkit.plugin.InvalidDescriptionException;
public class EconomyTest extends TestCase
{
private OfflinePlayer base1;
private Essentials ess;
private final OfflinePlayer base1;
private final Essentials ess;
public EconomyTest(String testName)
{

View File

@ -15,18 +15,6 @@ public class EssentialsTest extends TestCase
System.out.println("Essentials should " + what);
}
@Override
protected void setUp() throws Exception
{
super.setUp();
}
@Override
protected void tearDown() throws Exception
{
super.tearDown();
}
public void testLoadClasses()
{
should("make all classes accessible");

View File

@ -20,7 +20,7 @@ import org.bukkit.scheduler.BukkitScheduler;
public class FakeServer implements Server
{
private List<Player> players = new ArrayList<Player>();
private List<World> worlds = new ArrayList<World>();
private final List<World> worlds = new ArrayList<World>();
public String getName()
{
@ -186,12 +186,12 @@ public class FakeServer implements Server
throw new UnsupportedOperationException("Not supported yet.");
}
void addPlayer(Player base1)
public void addPlayer(Player base1)
{
players.add(base1);
}
OfflinePlayer createPlayer(String name)
public OfflinePlayer createPlayer(String name)
{
OfflinePlayer player = new OfflinePlayer(name);
player.setLocation(new Location(worlds.get(0), 0, 0, 0, 0, 0));

View File

@ -1,17 +0,0 @@
package com.earth2me.essentials;
import junit.framework.TestCase;
public class PermissionsTest extends TestCase
{
@Override
protected void setUp() throws Exception
{
super.setUp();
}
public void test()
{
}
}

View File

@ -10,9 +10,9 @@ import org.bukkit.plugin.InvalidDescriptionException;
public class UserTest extends TestCase
{
private OfflinePlayer base1;
private Essentials ess;
private FakeServer server;
private final OfflinePlayer base1;
private final Essentials ess;
private final FakeServer server;
public UserTest(String testName)
{