diff --git a/BuildAll/build.xml b/BuildAll/build.xml
index d41b561fd..496f85c34 100644
--- a/BuildAll/build.xml
+++ b/BuildAll/build.xml
@@ -1,74 +1,74 @@
-
-
-
-
-
-
-
-
-
-
- Builds, tests, and runs the project BuildAll.
-
-
-
+
+
+
+
+
+
+
+
+
+
+ Builds, tests, and runs the project BuildAll.
+
+
+
diff --git a/BuildAll/nbproject/project.properties b/BuildAll/nbproject/project.properties
index 3a4db66ed..9cd71952c 100644
--- a/BuildAll/nbproject/project.properties
+++ b/BuildAll/nbproject/project.properties
@@ -1,96 +1,96 @@
-annotation.processing.enabled=true
-annotation.processing.enabled.in.editor=false
-annotation.processing.run.all.processors=true
-annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
-application.title=BuildAll
-application.vendor=Paul
-build.classes.dir=${build.dir}/classes
-build.classes.excludes=**/*.java,**/*.form
-# This directory is removed when the project is cleaned:
-build.dir=build
-build.generated.dir=${build.dir}/generated
-build.generated.sources.dir=${build.dir}/generated-sources
-# Only compile against the classpath explicitly listed here:
-build.sysclasspath=ignore
-build.test.classes.dir=${build.dir}/test/classes
-build.test.results.dir=${build.dir}/test/results
-# Uncomment to specify the preferred debugger connection transport:
-#debug.transport=dt_socket
-debug.classpath=\
- ${run.classpath}
-debug.test.classpath=\
- ${run.test.classpath}
-# This directory is removed when the project is cleaned:
-dist.dir=dist
-dist.jar=${dist.dir}/BuildAll.jar
-dist.javadoc.dir=${dist.dir}/javadoc
-endorsed.classpath=
-excludes=
-includes=**
-jar.compress=false
-javac.classpath=\
- ${reference.Essentials.jar}:\
- ${reference.EssentialsChat.jar}:\
- ${reference.EssentialsGroupBridge.jar}:\
- ${reference.EssentialsGroupManager.jar}:\
- ${reference.EssentialsProtect.jar}:\
- ${reference.EssentialsSpawn.jar}:\
- ${reference.EssentialsGeoIP.jar}:\
- ${reference.EssentialsiConomyBridge.jar}
-# Space-separated list of extra javac options
-javac.compilerargs=
-javac.deprecation=false
-javac.processorpath=\
- ${javac.classpath}
-javac.source=1.5
-javac.target=1.5
-javac.test.classpath=\
- ${javac.classpath}:\
- ${build.classes.dir}:\
- ${libs.junit.classpath}:\
- ${libs.junit_4.classpath}
-javac.test.processorpath=\
- ${javac.test.classpath}
-javadoc.additionalparam=
-javadoc.author=false
-javadoc.encoding=${source.encoding}
-javadoc.noindex=false
-javadoc.nonavbar=false
-javadoc.notree=false
-javadoc.private=false
-javadoc.splitindex=true
-javadoc.use=true
-javadoc.version=false
-javadoc.windowtitle=
-meta.inf.dir=${src.dir}/META-INF
-mkdist.disabled=false
-platform.active=default_platform
-project.Essentials=../Essentials
-project.EssentialsChat=../EssentialsChat
-project.EssentialsGeoIP=../EssentialsGeoIP
-project.EssentialsGroupBridge=../EssentialsGroupBridge
-project.EssentialsGroupManager=../EssentialsGroupManager
-project.EssentialsiConomyBridge=../EssentialsiConomyBridge
-project.EssentialsProtect=../EssentialsProtect
-project.EssentialsSpawn=../EssentialsSpawn
-reference.Essentials.jar=${project.Essentials}/dist/Essentials.jar
-reference.EssentialsChat.jar=${project.EssentialsChat}/dist/EssentialsChat.jar
-reference.EssentialsGeoIP.jar=${project.EssentialsGeoIP}/dist/EssentialsGeoIP.jar
-reference.EssentialsGroupBridge.jar=${project.EssentialsGroupBridge}/dist/EssentialsGroupBridge.jar
-reference.EssentialsGroupManager.jar=${project.EssentialsGroupManager}/dist/EssentialsGroupManager.jar
-reference.EssentialsiConomyBridge.jar=${project.EssentialsiConomyBridge}/dist/EssentialsiConomyBridge.jar
-reference.EssentialsProtect.jar=${project.EssentialsProtect}/dist/original-EssentialsProtect.jar
-reference.EssentialsSpawn.jar=${project.EssentialsSpawn}/dist/EssentialsSpawn.jar
-run.classpath=\
- ${javac.classpath}:\
- ${build.classes.dir}
-# Space-separated list of JVM arguments used when running the project
-# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value
-# or test-sys-prop.name=value to set system properties for unit tests):
-run.jvmargs=
-run.test.classpath=\
- ${javac.test.classpath}:\
- ${build.test.classes.dir}
-source.encoding=UTF-8
-src.dir=src
-test.src.dir=test
+annotation.processing.enabled=true
+annotation.processing.enabled.in.editor=false
+annotation.processing.run.all.processors=true
+annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
+application.title=BuildAll
+application.vendor=Paul
+build.classes.dir=${build.dir}/classes
+build.classes.excludes=**/*.java,**/*.form
+# This directory is removed when the project is cleaned:
+build.dir=build
+build.generated.dir=${build.dir}/generated
+build.generated.sources.dir=${build.dir}/generated-sources
+# Only compile against the classpath explicitly listed here:
+build.sysclasspath=ignore
+build.test.classes.dir=${build.dir}/test/classes
+build.test.results.dir=${build.dir}/test/results
+# Uncomment to specify the preferred debugger connection transport:
+#debug.transport=dt_socket
+debug.classpath=\
+ ${run.classpath}
+debug.test.classpath=\
+ ${run.test.classpath}
+# This directory is removed when the project is cleaned:
+dist.dir=dist
+dist.jar=${dist.dir}/BuildAll.jar
+dist.javadoc.dir=${dist.dir}/javadoc
+endorsed.classpath=
+excludes=
+includes=**
+jar.compress=false
+javac.classpath=\
+ ${reference.Essentials.jar}:\
+ ${reference.EssentialsChat.jar}:\
+ ${reference.EssentialsGroupBridge.jar}:\
+ ${reference.EssentialsGroupManager.jar}:\
+ ${reference.EssentialsProtect.jar}:\
+ ${reference.EssentialsSpawn.jar}:\
+ ${reference.EssentialsGeoIP.jar}:\
+ ${reference.EssentialsiConomyBridge.jar}
+# Space-separated list of extra javac options
+javac.compilerargs=
+javac.deprecation=false
+javac.processorpath=\
+ ${javac.classpath}
+javac.source=1.5
+javac.target=1.5
+javac.test.classpath=\
+ ${javac.classpath}:\
+ ${build.classes.dir}:\
+ ${libs.junit.classpath}:\
+ ${libs.junit_4.classpath}
+javac.test.processorpath=\
+ ${javac.test.classpath}
+javadoc.additionalparam=
+javadoc.author=false
+javadoc.encoding=${source.encoding}
+javadoc.noindex=false
+javadoc.nonavbar=false
+javadoc.notree=false
+javadoc.private=false
+javadoc.splitindex=true
+javadoc.use=true
+javadoc.version=false
+javadoc.windowtitle=
+meta.inf.dir=${src.dir}/META-INF
+mkdist.disabled=false
+platform.active=default_platform
+project.Essentials=../Essentials
+project.EssentialsChat=../EssentialsChat
+project.EssentialsGeoIP=../EssentialsGeoIP
+project.EssentialsGroupBridge=../EssentialsGroupBridge
+project.EssentialsGroupManager=../EssentialsGroupManager
+project.EssentialsiConomyBridge=../EssentialsiConomyBridge
+project.EssentialsProtect=../EssentialsProtect
+project.EssentialsSpawn=../EssentialsSpawn
+reference.Essentials.jar=${project.Essentials}/dist/Essentials.jar
+reference.EssentialsChat.jar=${project.EssentialsChat}/dist/EssentialsChat.jar
+reference.EssentialsGeoIP.jar=${project.EssentialsGeoIP}/dist/EssentialsGeoIP.jar
+reference.EssentialsGroupBridge.jar=${project.EssentialsGroupBridge}/dist/EssentialsGroupBridge.jar
+reference.EssentialsGroupManager.jar=${project.EssentialsGroupManager}/dist/EssentialsGroupManager.jar
+reference.EssentialsiConomyBridge.jar=${project.EssentialsiConomyBridge}/dist/EssentialsiConomyBridge.jar
+reference.EssentialsProtect.jar=${project.EssentialsProtect}/dist/EssentialsProtect.jar
+reference.EssentialsSpawn.jar=${project.EssentialsSpawn}/dist/EssentialsSpawn.jar
+run.classpath=\
+ ${javac.classpath}:\
+ ${build.classes.dir}
+# Space-separated list of JVM arguments used when running the project
+# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value
+# or test-sys-prop.name=value to set system properties for unit tests):
+run.jvmargs=
+run.test.classpath=\
+ ${javac.test.classpath}:\
+ ${build.test.classes.dir}
+source.encoding=UTF-8
+src.dir=src
+test.src.dir=test
diff --git a/BuildAll/nbproject/project.xml b/BuildAll/nbproject/project.xml
index 4193b92ee..1d2c75eef 100644
--- a/BuildAll/nbproject/project.xml
+++ b/BuildAll/nbproject/project.xml
@@ -1,84 +1,84 @@
-
-
- org.netbeans.modules.java.j2seproject
-
-
- BuildAll
-
-
-
-
-
-
-
-
- ..\lib\nblibraries.properties
-
-
-
- Essentials
- jar
-
- jar
- clean
- jar
-
-
- EssentialsChat
- jar
-
- jar
- clean
- jar
-
-
- EssentialsGeoIP
- jar
-
- jar
- clean
- jar
-
-
- EssentialsGroupBridge
- jar
-
- jar
- clean
- jar
-
-
- EssentialsGroupManager
- jar
-
- jar
- clean
- jar
-
-
- EssentialsProtect
- jar
-
- jar
- clean
- jar
-
-
- EssentialsSpawn
- jar
-
- jar
- clean
- jar
-
-
- EssentialsiConomyBridge
- jar
-
- jar
- clean
- jar
-
-
-
-
+
+
+ org.netbeans.modules.java.j2seproject
+
+
+ BuildAll
+
+
+
+
+
+
+
+
+ ..\lib\nblibraries.properties
+
+
+
+ Essentials
+ jar
+
+ jar
+ clean
+ jar
+
+
+ EssentialsChat
+ jar
+
+ jar
+ clean
+ jar
+
+
+ EssentialsGeoIP
+ jar
+
+ jar
+ clean
+ jar
+
+
+ EssentialsGroupBridge
+ jar
+
+ jar
+ clean
+ jar
+
+
+ EssentialsGroupManager
+ jar
+
+ jar
+ clean
+ jar
+
+
+ EssentialsProtect
+ jar
+
+ jar
+ clean
+ jar
+
+
+ EssentialsSpawn
+ jar
+
+ jar
+ clean
+ jar
+
+
+ EssentialsiConomyBridge
+ jar
+
+ jar
+ clean
+ jar
+
+
+
+
diff --git a/Essentials/src/com/earth2me/essentials/Backup.java b/Essentials/src/com/earth2me/essentials/Backup.java
index aa0cb1476..ef55dfc1a 100644
--- a/Essentials/src/com/earth2me/essentials/Backup.java
+++ b/Essentials/src/com/earth2me/essentials/Backup.java
@@ -26,7 +26,7 @@ public class Backup implements Runnable {
private void startTask() {
if (!running) {
- long interval = Essentials.getSettings().getBackupInterval()*1200; // minutes -> ticks
+ long interval = Essentials.getStatic().getSettings().getBackupInterval()*1200; // minutes -> ticks
if (interval < 1200) {
return;
}
@@ -38,7 +38,7 @@ public class Backup implements Runnable {
public void run() {
if (active) return;
active = true;
- final String command = Essentials.getSettings().getBackupCommand();
+ final String command = Essentials.getStatic().getSettings().getBackupCommand();
if (command == null || "".equals(command)) {
return;
}
diff --git a/Essentials/src/com/earth2me/essentials/Essentials.java b/Essentials/src/com/earth2me/essentials/Essentials.java
index 0abdc79eb..3f51c75d5 100644
--- a/Essentials/src/com/earth2me/essentials/Essentials.java
+++ b/Essentials/src/com/earth2me/essentials/Essentials.java
@@ -8,6 +8,7 @@ import org.bukkit.*;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import com.earth2me.essentials.commands.IEssentialsCommand;
+import com.earth2me.essentials.commands.NotEnoughArgumentsException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.bukkit.command.PluginCommand;
@@ -17,9 +18,6 @@ import org.bukkit.event.Event.Priority;
import org.bukkit.event.Event.Type;
import org.bukkit.plugin.*;
import org.bukkit.plugin.java.*;
-import org.yaml.snakeyaml.*;
-import org.yaml.snakeyaml.constructor.SafeConstructor;
-import org.yaml.snakeyaml.reader.UnicodeReader;
public class Essentials extends JavaPlugin
@@ -27,112 +25,108 @@ public class Essentials extends JavaPlugin
public static final String AUTHORS = "Zenexer, ementalo, Aelux, Brettflan, KimKandor, snowleo and ceulemans.";
public static final int minBukkitBuildVersion = 733;
private static final Logger logger = Logger.getLogger("Minecraft");
- private static final Yaml yaml = new Yaml(new SafeConstructor());
- private static Map users;
- private static Settings settings;
- private static final Object usersLock = new Object();
- public static Object permissions = null;
- public final Map tpcRequests = new HashMap();
- public final Map tpcHere = new HashMap();
- public final List away = new ArrayList();
+ private Settings settings;
private EssentialsPlayerListener playerListener;
private EssentialsBlockListener blockListener;
private EssentialsEntityListener entityListener;
private JailPlayerListener jailPlayerListener;
- private static Essentials staticThis = null;
- public Spawn spawn;
+ private static Essentials instance = null;
+ private Spawn spawn;
private Jail jail;
private Warps warps;
private Worth worth;
private List confList;
public ArrayList bans = new ArrayList();
public ArrayList bannedIps = new ArrayList();
- public Backup backup;
+ private Backup backup;
+ private Map users = new HashMap();
+ private EssentialsTimer timer;
- public Essentials() throws IOException
+ public Essentials()
{
}
- public static void ensureEnabled(Server server)
- {
- PluginManager pm = server.getPluginManager();
- Essentials ess = (Essentials)pm.getPlugin("Essentials");
- if (!ess.isEnabled())
- pm.enablePlugin(ess);
- }
-
public static Essentials getStatic()
{
- return staticThis;
+ return instance;
}
- public static Settings getSettings()
+ public Settings getSettings()
{
return settings;
}
-
- public void setupPermissions()
+
+ public void setupForTesting() throws IOException, InvalidDescriptionException
{
- Plugin permPlugin = this.getServer().getPluginManager().getPlugin("Permissions");
- if (permissions == null && permPlugin != null) permissions = permPlugin;
- }
-
- public Player getPlayer(String[] args, int pos)
- throws IndexOutOfBoundsException, NoSuchFieldException
- {
- if (args.length <= pos) throw new IndexOutOfBoundsException("§cInvalid command syntax. Did you forget an argument?");
- List matches = getServer().matchPlayer(args[0]);
- if (matches.size() < 1) throw new NoSuchFieldException("§cNo matching players could be found.");
- return matches.get(0);
+ File dataFolder = File.createTempFile("essentialstest", "");
+ dataFolder.delete();
+ dataFolder.mkdir();
+ logger.log(Level.INFO,"Using temp folder for testing:");
+ logger.log(Level.INFO,dataFolder.toString());
+ this.initialize(null, null, new PluginDescriptionFile(new FileReader(new File("src"+File.separator+"plugin.yml"))), dataFolder, null, null);
+ settings = new Settings(dataFolder);
}
public void setStatic()
{
- staticThis = this;
+ instance = this;
}
@SuppressWarnings("LoggerStringConcat")
public void onEnable()
{
setStatic();
- new EssentialsUpgrade(this.getDescription().getVersion(), this.getDataFolder());
+ EssentialsUpgrade upgrade = new EssentialsUpgrade(this.getDescription().getVersion(), this);
+ if (newWorldsLoaded) {
+ logger.log(Level.SEVERE, "New worlds have been loaded while upgrading files. Will reload the server.");
+ getServer().reload();
+ }
confList = new ArrayList();
settings = new Settings(this.getDataFolder());
confList.add(settings);
- this.spawn = new Spawn(getServer(), this.getDataFolder());
+ spawn = new Spawn(getServer(), this.getDataFolder());
confList.add(spawn);
warps = new Warps(getServer(), this.getDataFolder());
confList.add(warps);
worth = new Worth(this.getDataFolder());
confList.add(worth);
reload();
- this.backup = new Backup();
+ backup = new Backup();
PluginManager pm = getServer().getPluginManager();
- for (Plugin plugin : pm.getPlugins()) {
- if (plugin.getDescription().getName().startsWith("Essentials")) {
- if (!plugin.getDescription().getVersion().equals(this.getDescription().getVersion())) {
- logger.log(Level.WARNING, "Version mismatch! Please update "+plugin.getDescription().getName()+" to the same version.");
+ for (Plugin plugin : pm.getPlugins())
+ {
+ if (plugin.getDescription().getName().startsWith("Essentials"))
+ {
+ if (!plugin.getDescription().getVersion().equals(this.getDescription().getVersion()))
+ {
+ logger.log(Level.WARNING, "Version mismatch! Please update " + plugin.getDescription().getName() + " to the same version.");
}
}
}
Matcher versionMatch = Pattern.compile("git-Bukkit-([0-9]+).([0-9]+).([0-9]+)-[0-9]+-[0-9a-z]+-b([0-9]+)jnks.*").matcher(getServer().getVersion());
- if (versionMatch.matches()) {
+ if (versionMatch.matches())
+ {
int versionNumber = Integer.parseInt(versionMatch.group(4));
- if (versionNumber < minBukkitBuildVersion) {
+ if (versionNumber < minBukkitBuildVersion)
+ {
logger.log(Level.WARNING, "Bukkit version is not the recommended build for Essentials.");
}
- } else {
+ }
+ else
+ {
logger.log(Level.INFO, "Bukkit version format changed. Version not checked.");
}
-
+
playerListener = new EssentialsPlayerListener(this);
pm.registerEvent(Type.PLAYER_JOIN, playerListener, Priority.Monitor, this);
pm.registerEvent(Type.PLAYER_QUIT, playerListener, Priority.Monitor, this);
pm.registerEvent(Type.PLAYER_CHAT, playerListener, Priority.Lowest, this);
if (getSettings().getNetherPortalsEnabled())
+ {
pm.registerEvent(Type.PLAYER_MOVE, playerListener, Priority.High, this);
+ }
pm.registerEvent(Type.PLAYER_LOGIN, playerListener, Priority.High, this);
pm.registerEvent(Type.PLAYER_TELEPORT, playerListener, Priority.High, this);
pm.registerEvent(Type.PLAYER_INTERACT, playerListener, Priority.High, this);
@@ -150,7 +144,7 @@ public class Essentials extends JavaPlugin
pm.registerEvent(Type.ENTITY_COMBUST, entityListener, Priority.Lowest, this);
pm.registerEvent(Type.ENTITY_DEATH, entityListener, Priority.Lowest, this);
- jail = new Jail(this.getDataFolder());
+ jail = new Jail(this);
jailPlayerListener = new JailPlayerListener(this);
confList.add(jail);
pm.registerEvent(Type.BLOCK_BREAK, jail, Priority.High, this);
@@ -164,17 +158,19 @@ public class Essentials extends JavaPlugin
getServer().createWorld(settings.getNetherName(), World.Environment.NETHER);
}
+ timer = new EssentialsTimer(this);
+ getScheduler().scheduleSyncRepeatingTask(this, timer, 1, 50);
+
logger.info("Loaded " + this.getDescription().getName() + " build " + this.getDescription().getVersion() + " maintained by " + AUTHORS);
}
public void onDisable()
{
- staticThis = null;
+ instance = null;
}
public void reload()
{
- loadData();
loadBanList();
for (IConf iConf : confList)
@@ -192,190 +188,6 @@ public class Essentials extends JavaPlugin
}
}
- public static Map getData(User player)
- {
- return getData(player.getName());
- }
-
- public static Map getData(String player)
- {
- try
- {
- Map retval;
- synchronized (usersLock)
- {
- retval = (Map)users.get(player.toLowerCase());
- }
- return retval == null ? new HashMap() : retval;
- }
- catch (Throwable ex)
- {
- return new HashMap();
- }
- }
-
- public static void flushData()
- {
- Thread run = new Thread(new Runnable()
- {
- @Override
- public void run()
- {
- try
- {
- if (!Essentials.getStatic().getDataFolder().exists())
- Essentials.getStatic().getDataFolder().mkdirs();
- File file = new File(Essentials.getStatic().getDataFolder(), "users.yml");
- if (!file.exists())
- file.createNewFile();
-
- FileWriter tx = new FileWriter(file);
- synchronized (usersLock)
- {
- tx.write(yaml.dump(users));
- }
- tx.flush();
- tx.close();
- }
- catch (Throwable ex)
- {
- Logger.getLogger(Essentials.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- });
- run.setDaemon(false);
- run.start();
- }
-
- public static void loadData()
- {
- try
- {
- if (!Essentials.getStatic().getDataFolder().exists()) Essentials.getStatic().getDataFolder().mkdirs();
- File file = new File(Essentials.getStatic().getDataFolder(), "users.yml");
- if (!file.exists()) file.createNewFile();
-
- FileInputStream rx = new FileInputStream(file);
- synchronized (usersLock)
- {
- users = (Map)yaml.load(new UnicodeReader(rx));
- }
- rx.close();
- }
- catch (Exception ex)
- {
- Logger.getLogger(Essentials.class.getName()).log(Level.SEVERE, null, ex);
- synchronized (usersLock)
- {
- users = new HashMap();
- }
- }
- finally
- {
- synchronized (usersLock)
- {
- if (users == null) users = new HashMap();
- }
- }
- }
-
- public static void setData(User player, Map data)
- {
- setData(player.getName(), data);
- }
-
- public static void setData(String player, Map data)
- {
- synchronized (usersLock)
- {
- users.put(player.toLowerCase(), data);
- }
- }
-
- public static List readMail(User player)
- {
- return readMail(player.getName());
- }
-
- public static List readMail(String player)
- {
- try
- {
- Map data = getData(player);
- List retval = (List)data.get("mail");
- return retval == null ? new ArrayList() : retval;
- }
- catch (Throwable ex)
- {
- return new ArrayList();
- }
- }
-
- public static void clearMail(User player)
- {
- try
- {
- Map data = getData(player);
- data.put("mail", new ArrayList());
- setData(player, data);
- flushData();
- }
- catch (Throwable ex)
- {
- }
- }
-
- public static void sendMail(User from, String to, String message)
- throws Exception
- {
- try
- {
- Map data = getData(ChatColor.stripColor(to));
- List mail = readMail(to);
- mail.add(ChatColor.stripColor(from.getDisplayName()) + ": " + message);
- data.put("mail", mail);
- setData(to, data);
- flushData();
- }
- catch (Throwable ex)
- {
- throw new Exception("An error was encountered while sending the mail.", ex);
- }
- }
-
- public String readNickname(User player)
- {
- try
- {
- Map data = getData(player);
- String nick = (String)data.get("nickname");
- if (nick == null)
- return player.getName();
- if (nick.equals(player.getName()))
- return player.getName();
- return getSettings().getNicknamePrefix() + nick;
- }
- catch (Exception ex)
- {
- return player.getName();
- }
- }
-
- public void saveNickname(User player, String nickname) throws Exception
- {
- try
- {
- Map data = getData(player);
- data.put("nickname", nickname);
- setData(player, data);
- flushData();
- }
- catch (Throwable ex)
- {
- throw new Exception("An error was encountered while saving the nickname.", ex);
- }
- }
-
public String[] getMotd(CommandSender sender, String def)
{
return getLines(sender, "motd", def);
@@ -384,7 +196,10 @@ public class Essentials extends JavaPlugin
public String[] getLines(CommandSender sender, String node, String def)
{
List lines = (List)getConfiguration().getProperty(node);
- if (lines == null) return new String[0];
+ if (lines == null)
+ {
+ return new String[0];
+ }
String[] retval = new String[lines.size()];
if (lines == null || lines.isEmpty() || lines.get(0) == null)
@@ -408,18 +223,22 @@ public class Essentials extends JavaPlugin
// if still empty, call it a day
if (lines == null || lines.isEmpty() || lines.get(0) == null)
+ {
return new String[0];
+ }
for (int i = 0; i < lines.size(); i++)
{
String m = lines.get(i);
if (m == null)
+ {
continue;
+ }
m = m.replace('&', '§').replace("§§", "&");
if (sender instanceof User || sender instanceof Player)
{
- User user = User.get(sender);
+ User user = getUser(sender);
m = m.replace("{PLAYER}", user.getDisplayName());
m = m.replace("{IP}", user.getAddress().toString());
m = m.replace("{BALANCE}", Double.toString(user.getMoney()));
@@ -433,7 +252,9 @@ public class Essentials extends JavaPlugin
for (Player p : getServer().getOnlinePlayers())
{
if (online.length() > 0)
+ {
online.append(", ");
+ }
online.append(p.getDisplayName());
}
m = m.replace("{PLAYERLIST}", online.toString());
@@ -462,36 +283,16 @@ public class Essentials extends JavaPlugin
return retval;
}
- public static String FormatTime(long Milliseconds)
- { // format time into a string showing hours, minutes, or seconds
- if (Milliseconds > 3600000)
- {
- double val = Math.round((double)Milliseconds / 360000D) / 10D;
- return val + " hour" + (val > 1 ? "s" : "");
- }
- else if (Milliseconds > 60000)
- {
- double val = Math.round((double)Milliseconds / 6000D) / 10D;
- return val + " minute" + (val > 1 ? "s" : "");
- }
- else if (Milliseconds <= 1000)
- return "1 second";
- else
- return (Milliseconds / 1000L) + " seconds";
- }
-
@SuppressWarnings("LoggerStringConcat")
public static void previewCommand(CommandSender sender, Command command, String commandLabel, String[] args)
{
if (sender instanceof Player)
+ {
logger.info(ChatColor.BLUE + "[PLAYER_COMMAND] " + ((Player)sender).getName() + ": /" + commandLabel + " " + EssentialsCommand.getFinalArg(args, 0));
+ }
}
@Override
- @SuppressWarnings(
- {
- "LoggerStringConcat", "CallToThreadDumpStack"
- })
public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args)
{
// Allow plugins to override the command via onCommand
@@ -500,26 +301,38 @@ public class Essentials extends JavaPlugin
for (Plugin p : getServer().getPluginManager().getPlugins())
{
if (p == this)
+ {
continue;
+ }
PluginDescriptionFile desc = p.getDescription();
if (desc == null)
+ {
continue;
+ }
if (desc.getName() == null)
+ {
continue;
+ }
if (!(desc.getCommands() instanceof Map))
+ {
continue;
+ }
Map cmds = (Map)desc.getCommands();
if (!cmds.containsKey(command.getName()))
+ {
continue;
+ }
PluginCommand pcmd = getServer().getPluginCommand(desc.getName() + ":" + commandLabel);
if (pcmd == null)
+ {
continue;
+ }
return getServer().getPluginCommand(p.getDescription().getName() + ":" + commandLabel).execute(sender, commandLabel, args);
}
@@ -528,17 +341,23 @@ public class Essentials extends JavaPlugin
try
{
previewCommand(sender, command, commandLabel, args);
- User user = sender instanceof Player ? User.get(sender) : null;
+ User user = sender instanceof Player ? getUser(sender) : null;
// New mail notification
- if (user != null && !Essentials.getSettings().isCommandDisabled("mail") && !commandLabel.equals("mail"))
+ if (user != null && !getSettings().isCommandDisabled("mail") && !commandLabel.equals("mail") && user.isAuthorized("essentials.mail"))
{
- List mail = Essentials.readMail(user);
- if (!mail.isEmpty()) user.sendMessage(ChatColor.RED + "You have " + mail.size() + " messages!§f Type §7/mail read§f to view your mail.");
+ List mail = user.getMails();
+ if (!mail.isEmpty())
+ {
+ user.sendMessage(ChatColor.RED + "You have " + mail.size() + " messages!§f Type §7/mail read§f to view your mail.");
+ }
}
// Check for disabled commands
- if (Essentials.getSettings().isCommandDisabled(commandLabel)) return true;
+ if (getSettings().isCommandDisabled(commandLabel))
+ {
+ return true;
+ }
IEssentialsCommand cmd;
try
@@ -548,14 +367,14 @@ public class Essentials extends JavaPlugin
catch (Exception ex)
{
sender.sendMessage(ChatColor.RED + "That command is improperly loaded.");
- ex.printStackTrace();
+ logger.log(Level.SEVERE, "Command " + commandLabel + " is improperly loaded.", ex);
return true;
}
// Check authorization
if (user != null && !user.isAuthorized(cmd))
{
- logger.warning(user.getName() + " was denied access to command.");
+ logger.log(Level.WARNING, user.getName() + " was denied access to command.");
user.sendMessage(ChatColor.RED + "You do not have access to that command.");
return true;
}
@@ -564,23 +383,34 @@ public class Essentials extends JavaPlugin
try
{
if (user == null)
- cmd.run(getServer(), this, sender, commandLabel, command, args);
+ {
+ cmd.run(getServer(), sender, commandLabel, command, args);
+ }
else
- cmd.run(getServer(), this, user, commandLabel, command, args);
+ {
+ cmd.run(getServer(), user, commandLabel, command, args);
+ }
+ return true;
+ }
+ catch (NotEnoughArgumentsException ex)
+ {
+ sender.sendMessage(command.getDescription());
+ sender.sendMessage(command.getUsage());
return true;
}
catch (Throwable ex)
{
sender.sendMessage(ChatColor.RED + "Error: " + ex.getMessage());
- if (getSettings().isDebug()) {
- logger.log(Level.WARNING, "Error calling command /"+commandLabel, ex);
+ if (getSettings().isDebug())
+ {
+ logger.log(Level.WARNING, "Error calling command /" + commandLabel, ex);
}
return true;
}
}
catch (Throwable ex)
{
- ex.printStackTrace();
+ logger.log(Level.SEVERE, "Command " + commandLabel + " failed: ", ex);
return true;
}
}
@@ -592,7 +422,10 @@ public class Essentials extends JavaPlugin
File ipFile = new File("banned-ips.txt");
try
{
- if (!file.exists()) throw new FileNotFoundException("banned-players.txt not found");
+ if (!file.exists())
+ {
+ throw new FileNotFoundException("banned-players.txt not found");
+ }
BufferedReader rx = new BufferedReader(new FileReader(file));
bans.clear();
@@ -602,7 +435,10 @@ public class Essentials extends JavaPlugin
{
String line = rx.readLine().trim().toLowerCase();
- if (line.startsWith("#")) continue;
+ if (line.startsWith("#"))
+ {
+ continue;
+ }
bans.add(line);
}
@@ -619,7 +455,10 @@ public class Essentials extends JavaPlugin
try
{
- if (!ipFile.exists()) throw new FileNotFoundException("banned-ips.txt not found");
+ if (!ipFile.exists())
+ {
+ throw new FileNotFoundException("banned-ips.txt not found");
+ }
BufferedReader rx = new BufferedReader(new FileReader(ipFile));
bannedIps.clear();
@@ -629,7 +468,10 @@ public class Essentials extends JavaPlugin
{
String line = rx.readLine().trim().toLowerCase();
- if (line.startsWith("#")) continue;
+ if (line.startsWith("#"))
+ {
+ continue;
+ }
bannedIps.add(line);
}
@@ -648,8 +490,8 @@ public class Essentials extends JavaPlugin
private void attachEcoListeners()
{
PluginManager pm = getServer().getPluginManager();
- EssentialsEcoBlockListener ecoBlockListener = new EssentialsEcoBlockListener();
- EssentialsEcoPlayerListener ecoPlayerListener = new EssentialsEcoPlayerListener();
+ EssentialsEcoBlockListener ecoBlockListener = new EssentialsEcoBlockListener(this);
+ EssentialsEcoPlayerListener ecoPlayerListener = new EssentialsEcoPlayerListener(this);
pm.registerEvent(Type.PLAYER_INTERACT, ecoPlayerListener, Priority.High, this);
pm.registerEvent(Type.BLOCK_BREAK, ecoBlockListener, Priority.High, this);
pm.registerEvent(Type.SIGN_CHANGE, ecoBlockListener, Priority.Monitor, this);
@@ -674,4 +516,86 @@ public class Essentials extends JavaPlugin
{
return getStatic().worth;
}
+
+ public static Backup getBackup()
+ {
+ return getStatic().backup;
+ }
+
+ public static Spawn getSpawn()
+ {
+ return getStatic().spawn;
+ }
+
+ public User getUser(T base)
+ {
+ if (base instanceof Player)
+ {
+ return getUser((Player)base);
+ }
+ return null;
+ }
+
+ private User getUser(T base)
+ {
+ if (base == null)
+ {
+ return null;
+ }
+
+ if (base instanceof User)
+ {
+ return (User)base;
+ }
+
+ if (users.containsKey(base.getName()))
+ {
+ return users.get(base.getName()).update(base);
+ }
+
+ User u = new User(base, this);
+ users.put(u.getName(), u);
+ return u;
+ }
+
+ public User getOfflineUser(String name)
+ {
+ File userFolder = new File(getDataFolder(), "userdata");
+ File userFile = new File(userFolder, Util.sanitizeFileName(name) + ".yml");
+ if (userFile.exists())
+ {
+ return new User(new OfflinePlayer(name), this);
+ }
+ return null;
+ }
+ private boolean newWorldsLoaded = false;
+
+ public World getWorld(String name)
+ {
+ if (name.matches("[0-9]+"))
+ {
+ int id = Integer.parseInt(name);
+ if (id < getServer().getWorlds().size())
+ {
+ return getServer().getWorlds().get(id);
+ }
+ }
+ World w = getServer().getWorld(name);
+ if (w != null)
+ {
+ return w;
+ }
+ File bukkitDirectory = getStatic().getDataFolder().getParentFile().getParentFile();
+ File worldDirectory = new File(bukkitDirectory, name);
+ if (worldDirectory.exists() && worldDirectory.isDirectory())
+ {
+ w = getServer().createWorld(name, World.Environment.NORMAL);
+ if (w != null)
+ {
+ newWorldsLoaded = true;
+ }
+ return w;
+ }
+ return null;
+ }
}
diff --git a/Essentials/src/com/earth2me/essentials/EssentialsBlockListener.java b/Essentials/src/com/earth2me/essentials/EssentialsBlockListener.java
index 5ffce45e1..bfb95b9a7 100644
--- a/Essentials/src/com/earth2me/essentials/EssentialsBlockListener.java
+++ b/Essentials/src/com/earth2me/essentials/EssentialsBlockListener.java
@@ -1,20 +1,16 @@
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.craftbukkit.block.CraftSign;
import org.bukkit.event.block.*;
import org.bukkit.inventory.ItemStack;
-import org.bukkit.material.MaterialData;
public class EssentialsBlockListener extends BlockListener
{
- private final Essentials parent;
+ private final Essentials ess;
public final static ArrayList protectedBlocks = new ArrayList(4);
static
@@ -25,17 +21,17 @@ public class EssentialsBlockListener extends BlockListener
protectedBlocks.add(Material.DISPENSER);
}
- public EssentialsBlockListener(Essentials parent)
+ public EssentialsBlockListener(Essentials ess)
{
- this.parent = parent;
+ this.ess = ess;
}
@Override
public void onBlockBreak(BlockBreakEvent event)
{
if (event.isCancelled()) return;
- if (Essentials.getSettings().areSignsDisabled()) return;
- User user = User.get(event.getPlayer());
+ if (ess.getSettings().areSignsDisabled()) return;
+ User user = ess.getUser(event.getPlayer());
if (protectedBlocks.contains(event.getBlock().getType()) && !user.isAuthorized("essentials.signs.protection.override"))
{
if (isBlockProtected(event.getBlock(), user))
@@ -58,8 +54,8 @@ public class EssentialsBlockListener extends BlockListener
public void onSignChange(SignChangeEvent event)
{
if (event.isCancelled()) return;
- if (Essentials.getSettings().areSignsDisabled()) return;
- User user = User.get(event.getPlayer());
+ if (ess.getSettings().areSignsDisabled()) return;
+ User user = ess.getUser(event.getPlayer());
String username = user.getName().substring(0, user.getName().length() > 14 ? 14 : user.getName().length());
try
@@ -171,7 +167,7 @@ public class EssentialsBlockListener extends BlockListener
return;
}
}
- final User user = User.get(event.getPlayer());
+ final User user = ess.getUser(event.getPlayer());
// Do not rely on getItemInHand();
// http://leaky.bukkit.org/issues/663
final ItemStack is = new ItemStack(event.getBlockPlaced().getType(), 1, (short)0, event.getBlockPlaced().getData());
@@ -236,7 +232,7 @@ public class EssentialsBlockListener extends BlockListener
}
boolean unlimitedForUser = user.hasUnlimited(is);
if (unlimitedForUser) {
- Essentials.getStatic().getScheduler().scheduleSyncDelayedTask(Essentials.getStatic(),
+ ess.getScheduler().scheduleSyncDelayedTask(ess,
new Runnable() {
public void run() {
diff --git a/Essentials/src/com/earth2me/essentials/EssentialsConf.java b/Essentials/src/com/earth2me/essentials/EssentialsConf.java
index 0f47f8471..097d02ce8 100644
--- a/Essentials/src/com/earth2me/essentials/EssentialsConf.java
+++ b/Essentials/src/com/earth2me/essentials/EssentialsConf.java
@@ -28,7 +28,8 @@ public class EssentialsConf extends Configuration
{
super(configFile);
this.configFile = configFile;
- if (this.root == null) {
+ if (this.root == null)
+ {
this.root = new HashMap();
}
}
@@ -62,7 +63,8 @@ public class EssentialsConf extends Configuration
}
}
super.load();
- if (this.root == null) {
+ if (this.root == null)
+ {
this.root = new HashMap();
}
}
@@ -98,7 +100,8 @@ public class EssentialsConf extends Configuration
{
try
{
- if (ostr != null) {
+ if (ostr != null)
+ {
ostr.close();
}
}
@@ -120,73 +123,83 @@ public class EssentialsConf extends Configuration
return configFile;
}
- public void setTemplateName(String templateName, Class> resClass) {
+ public void setTemplateName(String templateName, Class> resClass)
+ {
this.templateName = templateName;
this.resourceClass = resClass;
}
-
- public boolean hasProperty(String path) {
+
+ public boolean hasProperty(String path)
+ {
return getProperty(path) != null;
}
-
- public Location getLocation(String path, Server server) {
- String worldName = getString(path+".world");
- if (worldName == null || worldName.isEmpty()) {
+
+ public Location getLocation(String path, Server server)
+ {
+ String worldName = getString((path != null ? path + "." : "") + "world");
+ if (worldName == null || worldName.isEmpty())
+ {
return null;
}
World world = server.getWorld(worldName);
- if (world == null) {
+ if (world == null)
+ {
return null;
}
- return new Location(world,
- getDouble(path+".x", 0),
- getDouble(path+".y", 0),
- getDouble(path+".z", 0),
- (float)getDouble(path+".paw", 0),
- (float)getDouble(path+".pitch", 0));
+ return new Location(world,
+ getDouble((path != null ? path + "." : "") + "x", 0),
+ getDouble((path != null ? path + "." : "") + "y", 0),
+ getDouble((path != null ? path + "." : "") + "z", 0),
+ (float)getDouble((path != null ? path + "." : "") + "yaw", 0),
+ (float)getDouble((path != null ? path + "." : "") + "pitch", 0));
}
-
- public void setProperty(String path, Location loc) {
- Map map = new HashMap();
- map.put("world", loc.getWorld().getName());
- map.put("x", loc.getX());
- map.put("y", loc.getY());
- map.put("z", loc.getZ());
- map.put("yaw", loc.getYaw());
- map.put("pitch", loc.getPitch());
- setProperty(path, map);
+
+ public void setProperty(String path, Location loc)
+ {
+ setProperty((path != null ? path + "." : "") + "world", loc.getWorld().getName());
+ setProperty((path != null ? path + "." : "") + "x", loc.getX());
+ setProperty((path != null ? path + "." : "") + "y", loc.getY());
+ setProperty((path != null ? path + "." : "") + "z", loc.getZ());
+ setProperty((path != null ? path + "." : "") + "yaw", loc.getYaw());
+ setProperty((path != null ? path + "." : "") + "pitch", loc.getPitch());
}
-
- public ItemStack getItemStack(String path) {
+
+ public ItemStack getItemStack(String path)
+ {
return new ItemStack(
- Material.valueOf(getString(path+".type", "AIR")),
- getInt(path+".amount", 1),
- (short)getInt(path+".damage", 0),
- (byte)getInt(path+".data", 0));
+ Material.valueOf(getString(path + ".type", "AIR")),
+ getInt(path + ".amount", 1),
+ (short)getInt(path + ".damage", 0)/*,
+ (byte)getInt(path + ".data", 0)*/);
}
-
- public void setProperty(String path, ItemStack stack) {
+
+ public void setProperty(String path, ItemStack stack)
+ {
Map map = new HashMap();
map.put("type", stack.getType().toString());
map.put("amount", stack.getAmount());
map.put("damage", stack.getDurability());
// getData().getData() is broken
- map.put("data", stack.getDurability());
+ //map.put("data", stack.getDurability());
setProperty(path, map);
}
-
- public long getLong(String path, long def) {
+
+ public long getLong(String path, long def)
+ {
Number num = (Number)getProperty(path);
- if (num == null) {
+ if (num == null)
+ {
return def;
}
return num.longValue();
}
-
+
@Override
- public double getDouble(String path, double def) {
+ public double getDouble(String path, double def)
+ {
Number num = (Number)getProperty(path);
- if (num == null) {
+ if (num == null)
+ {
return def;
}
return num.doubleValue();
diff --git a/Essentials/src/com/earth2me/essentials/EssentialsEcoBlockListener.java b/Essentials/src/com/earth2me/essentials/EssentialsEcoBlockListener.java
index d11c06a24..e0dcb66be 100644
--- a/Essentials/src/com/earth2me/essentials/EssentialsEcoBlockListener.java
+++ b/Essentials/src/com/earth2me/essentials/EssentialsEcoBlockListener.java
@@ -11,21 +11,37 @@ import org.bukkit.inventory.ItemStack;
public class EssentialsEcoBlockListener extends BlockListener
{
+ Essentials ess;
+ public EssentialsEcoBlockListener(Essentials ess)
+ {
+ this.ess = ess;
+ }
+
@Override
public void onBlockBreak(BlockBreakEvent event)
{
- if (event.isCancelled()) return;
- if (Essentials.getSettings().areSignsDisabled()) return;
- User user = User.get(event.getPlayer());
+ if (event.isCancelled())
+ {
+ return;
+ }
+ if (ess.getSettings().areSignsDisabled())
+ {
+ return;
+ }
+ User user = ess.getUser(event.getPlayer());
String username = user.getName().substring(0, user.getName().length() > 14 ? 14 : user.getName().length());
if (event.getBlock().getType() != Material.WALL_SIGN && event.getBlock().getType() != Material.SIGN_POST)
+ {
return;
+ }
Sign sign = new CraftSign(event.getBlock());
if (sign.getLine(0).equals("§1[Trade]"))
{
- if (!sign.getLine(3).substring(2).equals(username)) {
- if (!user.isOp()) {
+ if (!sign.getLine(3).substring(2).equals(username))
+ {
+ if (!user.isOp())
+ {
event.setCancelled(true);
}
return;
@@ -40,20 +56,31 @@ public class EssentialsEcoBlockListener extends BlockListener
int q2 = Integer.parseInt(m2 ? l2[0].substring(1) : l2[0]);
int r1 = Integer.parseInt(l1[m1 ? 1 : 2]);
int r2 = Integer.parseInt(l2[m2 ? 1 : 2]);
- if (q1 < 1 || q2 < 1) throw new Exception("Quantities must be greater than 0.");
+ if (q1 < 1 || q2 < 1)
+ {
+ throw new Exception("Quantities must be greater than 0.");
+ }
ItemStack i1 = m1 || r1 <= 0 ? null : ItemDb.get(l1[1], r1);
ItemStack i2 = m2 || r2 <= 0 ? null : ItemDb.get(l2[1], r2);
if (m1)
+ {
user.giveMoney(r1);
+ }
else if (i1 != null)
+ {
user.getWorld().dropItem(user.getLocation(), i1);
+ }
if (m2)
+ {
user.giveMoney(r2);
+ }
else if (i2 != null)
+ {
user.getWorld().dropItem(user.getLocation(), i2);
+ }
sign.setType(Material.AIR);
}
@@ -65,12 +92,14 @@ public class EssentialsEcoBlockListener extends BlockListener
}
}
-
@Override
public void onSignChange(SignChangeEvent event)
{
- if (Essentials.getSettings().areSignsDisabled()) return;
- User user = User.get(event.getPlayer());
+ if (ess.getSettings().areSignsDisabled())
+ {
+ return;
+ }
+ User user = ess.getUser(event.getPlayer());
String username = user.getName().substring(0, user.getName().length() > 14 ? 14 : user.getName().length());
if (event.getLine(0).equalsIgnoreCase("[Buy]") && user.isAuthorized("essentials.signs.buy.create"))
@@ -80,7 +109,8 @@ public class EssentialsEcoBlockListener extends BlockListener
event.setLine(0, "§1[Buy]");
event.setLine(1, "" + Math.abs(Integer.parseInt(event.getLine(1))));
ItemStack is = ItemDb.get(event.getLine(2));
- if (is.getTypeId() == 0 || Math.abs(Integer.parseInt(event.getLine(1))) == 0) {
+ if (is.getTypeId() == 0 || Math.abs(Integer.parseInt(event.getLine(1))) == 0)
+ {
throw new Exception("Don't sell air.");
}
event.setLine(3, "$" + Integer.parseInt(event.getLine(3).replaceAll("[^0-9]", "")));
@@ -103,7 +133,8 @@ public class EssentialsEcoBlockListener extends BlockListener
event.setLine(0, "§1[Sell]");
event.setLine(1, "" + Math.abs(Integer.parseInt(event.getLine(1))));
ItemStack is = ItemDb.get(event.getLine(2));
- if (is.getTypeId() == 0 || Math.abs(Integer.parseInt(event.getLine(1))) == 0) {
+ if (is.getTypeId() == 0 || Math.abs(Integer.parseInt(event.getLine(1))) == 0)
+ {
throw new Exception("Don't buy air.");
}
event.setLine(3, "$" + Integer.parseInt(event.getLine(3).replaceAll("[^0-9]", "")));
@@ -131,19 +162,31 @@ public class EssentialsEcoBlockListener extends BlockListener
int q2 = Integer.parseInt(m2 ? l2[0].substring(1) : l2[0]);
int r2 = Integer.parseInt(l2[m2 ? 1 : 2]);
r2 = r2 - r2 % q2;
- if (q1 < 1 || q2 < 1 || r2 < 1) throw new Exception("Quantities must be greater than 0.");
- if (!m1) ItemDb.get(l1[1]);
+ if (q1 < 1 || q2 < 1 || r2 < 1)
+ {
+ throw new Exception("Quantities must be greater than 0.");
+ }
+ if (!m1)
+ {
+ ItemDb.get(l1[1]);
+ }
if (m2)
{
- if (user.getMoney() < r2) throw new Exception("You do not have sufficient funds.");
+ if (user.getMoney() < r2)
+ {
+ throw new Exception("You do not have sufficient funds.");
+ }
user.takeMoney(r2);
user.sendMessage("r2: " + r2 + " q2: " + q2);
}
else
{
ItemStack i2 = ItemDb.get(l2[1], r2);
- if (!InventoryWorkaround.containsItem(user.getInventory(), true, i2)) throw new Exception("You do not have " + r2 + "x " + l2[1] + ".");
+ if (!InventoryWorkaround.containsItem(user.getInventory(), true, i2))
+ {
+ throw new Exception("You do not have " + r2 + "x " + l2[1] + ".");
+ }
InventoryWorkaround.removeItem(user.getInventory(), true, i2);
user.updateInventory();
}
diff --git a/Essentials/src/com/earth2me/essentials/EssentialsEcoPlayerListener.java b/Essentials/src/com/earth2me/essentials/EssentialsEcoPlayerListener.java
index 528b27d83..9e6d8fd19 100644
--- a/Essentials/src/com/earth2me/essentials/EssentialsEcoPlayerListener.java
+++ b/Essentials/src/com/earth2me/essentials/EssentialsEcoPlayerListener.java
@@ -12,17 +12,30 @@ import org.bukkit.inventory.ItemStack;
public class EssentialsEcoPlayerListener extends PlayerListener
{
-
-@Override
+ Essentials ess;
+
+ EssentialsEcoPlayerListener(Essentials ess)
+ {
+ this.ess = ess;
+ }
+
+ @Override
public void onPlayerInteract(PlayerInteractEvent event)
{
-
- if (Essentials.getSettings().areSignsDisabled()) return;
- if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
- User user = User.get(event.getPlayer());
+ if (ess.getSettings().areSignsDisabled())
+ {
+ return;
+ }
+ if (event.getAction() != Action.RIGHT_CLICK_BLOCK)
+ {
+ return;
+ }
+ User user = ess.getUser(event.getPlayer());
String username = user.getName().substring(0, user.getName().length() > 14 ? 14 : user.getName().length());
if (event.getClickedBlock().getType() != Material.WALL_SIGN && event.getClickedBlock().getType() != Material.SIGN_POST)
+ {
return;
+ }
Sign sign = new CraftSign(event.getClickedBlock());
if (sign.getLine(0).equals("§1[Buy]") && user.isAuthorized("essentials.signs.buy.use"))
@@ -32,10 +45,14 @@ public class EssentialsEcoPlayerListener extends PlayerListener
int amount = Integer.parseInt(sign.getLine(1));
ItemStack item = ItemDb.get(sign.getLine(2), amount);
int cost = Integer.parseInt(sign.getLine(3).substring(1));
- if (user.getMoney() < cost) throw new Exception("You do not have sufficient funds.");
+ if (user.getMoney() < cost)
+ {
+ throw new Exception("You do not have sufficient funds.");
+ }
user.takeMoney(cost);
Map leftOver = user.getInventory().addItem(item);
- for (ItemStack itemStack : leftOver.values()) {
+ for (ItemStack itemStack : leftOver.values())
+ {
user.getWorld().dropItem(user.getLocation(), itemStack);
}
user.updateInventory();
@@ -54,7 +71,10 @@ public class EssentialsEcoPlayerListener extends PlayerListener
int amount = Integer.parseInt(sign.getLine(1));
ItemStack item = ItemDb.get(sign.getLine(2), amount);
int cost = Integer.parseInt(sign.getLine(3).substring(1));
- if (!InventoryWorkaround.containsItem(user.getInventory(), true, item)) throw new Exception("You do not have enough items to sell.");
+ if (!InventoryWorkaround.containsItem(user.getInventory(), true, item))
+ {
+ throw new Exception("You do not have enough items to sell.");
+ }
user.giveMoney(cost);
InventoryWorkaround.removeItem(user.getInventory(), true, item);
user.updateInventory();
@@ -80,9 +100,12 @@ public class EssentialsEcoPlayerListener extends PlayerListener
int r2 = Integer.parseInt(l2[m2 ? 1 : 2]);
r1 = r1 - r1 % q1;
r2 = r2 - r2 % q2;
- if (q1 < 1 || q2 < 1) throw new Exception("Quantities must be greater than 0.");
+ if (q1 < 1 || q2 < 1)
+ {
+ throw new Exception("Quantities must be greater than 0.");
+ }
- ItemStack i1 = m1 || r1 <= 0? null : ItemDb.get(l1[1], r1);
+ ItemStack i1 = m1 || r1 <= 0 ? null : ItemDb.get(l1[1], r1);
ItemStack qi1 = m1 ? null : ItemDb.get(l1[1], q1);
ItemStack qi2 = m2 ? null : ItemDb.get(l2[1], q2);
@@ -95,7 +118,8 @@ public class EssentialsEcoPlayerListener extends PlayerListener
else if (i1 != null)
{
Map leftOver = user.getInventory().addItem(i1);
- for (ItemStack itemStack : leftOver.values()) {
+ for (ItemStack itemStack : leftOver.values())
+ {
user.getWorld().dropItem(user.getLocation(), itemStack);
}
user.updateInventory();
@@ -108,26 +132,41 @@ public class EssentialsEcoPlayerListener extends PlayerListener
if (m1)
{
if (user.getMoney() < q1)
+ {
throw new Exception("You do not have sufficient funds.");
+ }
}
else
{
if (!InventoryWorkaround.containsItem(user.getInventory(), true, qi1))
+ {
throw new Exception("You do not have " + q1 + "x " + l1[1] + ".");
+ }
}
- if (r2 < q2) throw new Exception("The trade sign does not have enough supply left.");
+ if (r2 < q2)
+ {
+ throw new Exception("The trade sign does not have enough supply left.");
+ }
if (m1)
+ {
user.takeMoney(q1);
+ }
else
+ {
InventoryWorkaround.removeItem(user.getInventory(), true, qi1);
+ }
if (m2)
+ {
user.giveMoney(q2);
- else {
+ }
+ else
+ {
Map leftOver = user.getInventory().addItem(qi2);
- for (ItemStack itemStack : leftOver.values()) {
+ for (ItemStack itemStack : leftOver.values())
+ {
user.getWorld().dropItem(user.getLocation(), itemStack);
}
}
diff --git a/Essentials/src/com/earth2me/essentials/EssentialsEntityListener.java b/Essentials/src/com/earth2me/essentials/EssentialsEntityListener.java
index 7aa78703d..1d7a9e433 100644
--- a/Essentials/src/com/earth2me/essentials/EssentialsEntityListener.java
+++ b/Essentials/src/com/earth2me/essentials/EssentialsEntityListener.java
@@ -16,13 +16,11 @@ import org.bukkit.inventory.ItemStack;
public class EssentialsEntityListener extends EntityListener
{
- private final Server server;
- private final Essentials parent;
+ private final Essentials ess;
public EssentialsEntityListener(Essentials parent)
{
- this.parent = parent;
- this.server = parent.getServer();
+ this.ess = parent;
}
@Override
@@ -35,11 +33,12 @@ public class EssentialsEntityListener extends EntityListener
Entity eDefend = edEvent.getEntity();
if (eDefend instanceof Player && eAttack instanceof Player)
{
- User defender = User.get(eDefend);
- User attacker = User.get(eAttack);
+ User defender = ess.getUser(eDefend);
+ User attacker = ess.getUser(eAttack);
ItemStack is = attacker.getItemInHand();
String command = attacker.getPowertool(is);
- if (command != null && !command.isEmpty()) {
+ if (command != null && !command.isEmpty())
+ {
attacker.getServer().dispatchCommand(attacker, command.replaceAll("\\{player\\}", defender.getName()));
event.setCancelled(true);
return;
@@ -49,7 +48,7 @@ public class EssentialsEntityListener extends EntityListener
if (event instanceof EntityDamageEvent || event instanceof EntityDamageByBlockEvent || event instanceof EntityDamageByProjectileEvent)
{
- if (event.getEntity() instanceof Player && User.get(event.getEntity()).isGodModeEnabled())
+ if (event.getEntity() instanceof Player && ess.getUser(event.getEntity()).isGodModeEnabled())
{
CraftPlayer player = (CraftPlayer)event.getEntity();
player.getHandle().fireTicks = 0;
@@ -59,11 +58,10 @@ public class EssentialsEntityListener extends EntityListener
}
}
-
@Override
public void onEntityCombust(EntityCombustEvent event)
{
- if (event.getEntity() instanceof Player && User.get(event.getEntity()).isGodModeEnabled())
+ if (event.getEntity() instanceof Player && ess.getUser(event.getEntity()).isGodModeEnabled())
{
event.setCancelled(true);
}
@@ -74,13 +72,12 @@ public class EssentialsEntityListener extends EntityListener
{
if (event.getEntity() instanceof Player)
{
- User user = User.get(event.getEntity());
- if(user.isAuthorized("essentials.back.ondeath"))
+ User user = ess.getUser(event.getEntity());
+ if (user.isAuthorized("essentials.back.ondeath"))
{
- user.lastLocation = user.getLocation();
- user.sendMessage("§7Use the /back command to return to your death point");
+ user.setLastLocation();
+ user.sendMessage("§7Use the /back command to return to your death point");
}
}
}
-
}
diff --git a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java
index 9cf94bd85..df6b013d1 100644
--- a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java
+++ b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java
@@ -20,12 +20,12 @@ public class EssentialsPlayerListener extends PlayerListener
{
private static final Logger logger = Logger.getLogger("Minecraft");
private final Server server;
- private final Essentials parent;
+ private final Essentials ess;
private EssentialsBlockListener essBlockListener = null;
public EssentialsPlayerListener(Essentials parent)
{
- this.parent = parent;
+ this.ess = parent;
this.server = parent.getServer();
essBlockListener = new EssentialsBlockListener(parent);
}
@@ -33,15 +33,24 @@ public class EssentialsPlayerListener extends PlayerListener
@Override
public void onPlayerRespawn(PlayerRespawnEvent event)
{
- User user = User.get(event.getPlayer());
+ User user = ess.getUser(event.getPlayer());
user.setDisplayName(user.getNick());
updateCompass(user);
+ if (user.isJailed() && user.getJail() != null && !user.getJail().isEmpty()) {
+ try
+ {
+ event.setRespawnLocation(Essentials.getJail().getJail(user.getJail()));
+ }
+ catch (Exception ex)
+ {
+ }
+ }
}
@Override
public void onPlayerChat(PlayerChatEvent event)
{
- User user = User.get(event.getPlayer());
+ User user = ess.getUser(event.getPlayer());
if (user.isMuted())
{
event.setCancelled(true);
@@ -52,20 +61,29 @@ public class EssentialsPlayerListener extends PlayerListener
@Override
public void onPlayerMove(PlayerMoveEvent event)
{
- if (event.isCancelled()) return;
- final User user = User.get(event.getPlayer());
+ if (event.isCancelled())
+ {
+ return;
+ }
+ final User user = ess.getUser(event.getPlayer());
- if (!Essentials.getSettings().getNetherPortalsEnabled()) return;
+ if (!ess.getSettings().getNetherPortalsEnabled())
+ {
+ return;
+ }
final Block block = event.getPlayer().getWorld().getBlockAt(event.getTo().getBlockX(), event.getTo().getBlockY(), event.getTo().getBlockZ());
List worlds = server.getWorlds();
if (block.getType() == Material.PORTAL && worlds.size() > 1 && user.isAuthorized("essentials.portal"))
{
- if (user.getJustPortaled()) return;
+ if (user.getJustPortaled())
+ {
+ return;
+ }
Location loc = event.getTo();
- World nether = server.getWorld(Essentials.getSettings().getNetherName());
+ World nether = server.getWorld(ess.getSettings().getNetherName());
if (nether == null) {
for (World world : worlds)
{
@@ -81,8 +99,9 @@ public class EssentialsPlayerListener extends PlayerListener
final World world = user.getWorld() == nether ? worlds.get(0) : nether;
double factor;
- if (user.getWorld().getEnvironment() == World.Environment.NETHER && world.getEnvironment() == World.Environment.NORMAL) {
- if (Essentials.getSettings().use1to1RatioInNether())
+ if (user.getWorld().getEnvironment() == World.Environment.NETHER && world.getEnvironment() == World.Environment.NORMAL)
+ {
+ if (ess.getSettings().use1to1RatioInNether())
{
factor = 1.0;
}
@@ -91,8 +110,9 @@ public class EssentialsPlayerListener extends PlayerListener
factor = 16.0;
}
}
- else if (user.getWorld().getEnvironment() != world.getEnvironment()) {
- if (Essentials.getSettings().use1to1RatioInNether())
+ else if (user.getWorld().getEnvironment() != world.getEnvironment())
+ {
+ if (ess.getSettings().use1to1RatioInNether())
{
factor = 1.0;
}
@@ -101,7 +121,8 @@ public class EssentialsPlayerListener extends PlayerListener
factor = 1.0 / 16.0;
}
}
- else {
+ else
+ {
factor = 1.0;
}
@@ -110,9 +131,13 @@ public class EssentialsPlayerListener extends PlayerListener
int z = loc.getBlockZ();
if (user.getWorld().getBlockAt(x, y, z - 1).getType() == Material.PORTAL)
+ {
z--;
+ }
if (user.getWorld().getBlockAt(x - 1, y, z).getType() == Material.PORTAL)
+ {
x--;
+ }
x = (int)(x * factor);
z = (int)(z * factor);
@@ -122,7 +147,7 @@ public class EssentialsPlayerListener extends PlayerListener
NetherPortal portal = NetherPortal.findPortal(dest);
if (portal == null)
{
- if (world.getEnvironment() == World.Environment.NETHER || Essentials.getSettings().getGenerateExitPortals())
+ if (world.getEnvironment() == World.Environment.NETHER || ess.getSettings().getGenerateExitPortals())
{
portal = NetherPortal.createPortal(dest);
logger.info(event.getPlayer().getName() + " used a portal and generated an exit portal.");
@@ -141,7 +166,7 @@ public class EssentialsPlayerListener extends PlayerListener
event.setTo(loc);
try
{
- user.teleportToNow(loc);
+ user.getTeleport().teleport(loc, "portal");
}
catch (Exception ex)
{
@@ -160,14 +185,14 @@ public class EssentialsPlayerListener extends PlayerListener
@Override
public void onPlayerQuit(PlayerQuitEvent event)
{
- User user = User.get(event.getPlayer());
-
- if(user.savedInventory != null)
+ User user = ess.getUser(event.getPlayer());
+
+ if (user.getSavedInventory() != null)
{
- user.getInventory().setContents(user.savedInventory);
- user.savedInventory = null;
+ user.getInventory().setContents(user.getSavedInventory());
+ user.setSavedInventory(null);
}
- if (!Essentials.getSettings().getReclaimSetting())
+ if (!ess.getSettings().getReclaimSetting())
{
return;
}
@@ -201,54 +226,68 @@ public class EssentialsPlayerListener extends PlayerListener
@Override
public void onPlayerJoin(PlayerJoinEvent event)
{
- Essentials.getStatic().backup.onPlayerJoin();
- User user = User.get(event.getPlayer());
+ Essentials.getBackup().onPlayerJoin();
+ User user = ess.getUser(event.getPlayer());
//we do not know the ip address on playerlogin so we need to do this here.
if (user.isIpBanned())
{
- user.kickPlayer("The Ban Hammer has spoken!");
+ String banReason = user.getBanReason();
+ user.kickPlayer(banReason != null && !banReason.isEmpty() ? banReason : "The Ban Hammer has spoken!");
return;
}
user.setDisplayName(user.getNick());
- if (!Essentials.getSettings().isCommandDisabled("motd") && user.isAuthorized("essentials.motd"))
+ if (!ess.getSettings().isCommandDisabled("motd") && user.isAuthorized("essentials.motd"))
{
- for (String m : parent.getMotd(user, null))
+ for (String m : ess.getMotd(user, null))
{
- if (m == null) continue;
+ if (m == null)
+ {
+ continue;
+ }
user.sendMessage(m);
}
}
- if (!Essentials.getSettings().isCommandDisabled("mail"))
+ if (!ess.getSettings().isCommandDisabled("mail") && user.isAuthorized("essentials.mail"))
{
- List mail = Essentials.readMail(user);
- if (mail.isEmpty()) user.sendMessage("§7You have no new mail.");
- else user.sendMessage("§cYou have " + mail.size() + " messages!§f Type §7/mail read§f to view your mail.");
+ List mail = user.getMails();
+ if (mail.isEmpty())
+ {
+ user.sendMessage("§7You have no new mail.");
+ }
+ else
+ {
+ user.sendMessage("§cYou have " + mail.size() + " messages!§f Type §7/mail read§f to view your mail.");
+ }
}
}
@Override
public void onPlayerLogin(PlayerLoginEvent event)
{
- User user = User.get(event.getPlayer());
+ User user = ess.getUser(event.getPlayer());
if (event.getResult() != Result.ALLOWED)
- return;
-
- if (user.isBanned())
{
- event.disallow(Result.KICK_BANNED, "The Ban Hammer has spoken!");
return;
}
- if (server.getOnlinePlayers().length >= server.getMaxPlayers() && !user.isOp())
+ if (user.isBanned())
+ {
+ String banReason = user.getBanReason();
+ event.disallow(Result.KICK_BANNED, banReason != null && !banReason.isEmpty() ? banReason : "The Ban Hammer has spoken!");
+ return;
+ }
+
+ if (server.getOnlinePlayers().length >= server.getMaxPlayers() && !user.isAuthorized("essentials.joinfullserver"))
{
event.disallow(Result.KICK_FULL, "Server is full");
return;
}
+ user.setLastLogin(System.currentTimeMillis());
updateCompass(user);
}
@@ -266,13 +305,18 @@ public class EssentialsPlayerListener extends PlayerListener
@Override
public void onPlayerTeleport(PlayerTeleportEvent event)
{
- if (event.isCancelled()) return;
- User user = User.get(event.getPlayer());
- if (user.currentJail == null || user.currentJail.isEmpty())
+ if (event.isCancelled())
+ {
return;
+ }
+ User user = ess.getUser(event.getPlayer());
+ if (!user.isJailed() || user.getJail() == null || user.getJail().isEmpty())
+ {
+ return;
+ }
try
{
- event.setTo(Essentials.getJail().getJail(user.currentJail));
+ event.setTo(Essentials.getJail().getJail(user.getJail()));
}
catch (Exception ex)
{
@@ -284,11 +328,21 @@ public class EssentialsPlayerListener extends PlayerListener
@Override
public void onPlayerInteract(PlayerInteractEvent event)
{
- if (event.isCancelled()) return;
- if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
- User user = User.get(event.getPlayer());
- if (user.isJailed()) return;
- if (!Essentials.getSettings().areSignsDisabled() && EssentialsBlockListener.protectedBlocks.contains(event.getClickedBlock().getType()))
+ if (event.isCancelled())
+ {
+ return;
+ }
+ if (event.getAction() != Action.RIGHT_CLICK_BLOCK)
+ {
+ return;
+ }
+ User user = ess.getUser(event.getPlayer());
+ if (user.isJailed())
+ {
+ event.setCancelled(true);
+ return;
+ }
+ if (!ess.getSettings().areSignsDisabled() && EssentialsBlockListener.protectedBlocks.contains(event.getClickedBlock().getType()))
{
if (!user.isAuthorized("essentials.signs.protection.override"))
{
@@ -301,7 +355,7 @@ public class EssentialsPlayerListener extends PlayerListener
}
}
- if (Essentials.getSettings().getBedSetsHome() && event.getClickedBlock().getType() == Material.BED_BLOCK)
+ if (ess.getSettings().getBedSetsHome() && event.getClickedBlock().getType() == Material.BED_BLOCK)
{
try
{
@@ -314,9 +368,14 @@ public class EssentialsPlayerListener extends PlayerListener
}
- if (Essentials.getSettings().areSignsDisabled()) return;
- if (event.getClickedBlock().getType() != Material.WALL_SIGN && event.getClickedBlock().getType() != Material.SIGN_POST)
+ if (ess.getSettings().areSignsDisabled())
+ {
return;
+ }
+ if (event.getClickedBlock().getType() != Material.WALL_SIGN && event.getClickedBlock().getType() != Material.SIGN_POST)
+ {
+ return;
+ }
Sign sign = new CraftSign(event.getClickedBlock());
try
@@ -375,13 +434,16 @@ public class EssentialsPlayerListener extends PlayerListener
}
if (sign.getLine(0).equals("§1[Mail]") && user.isAuthorized("essentials.signs.mail.use") && user.isAuthorized("essentials.mail"))
{
- List mail = Essentials.readMail(user);
+ List mail = user.getMails();
if (mail.isEmpty())
{
user.sendMessage("§cYou do not have any mail!");
return;
}
- for (String s : mail) user.sendMessage(s);
+ for (String s : mail)
+ {
+ user.sendMessage(s);
+ }
user.sendMessage("§cTo mark your mail as read, type §c/mail clear");
return;
}
@@ -425,22 +487,19 @@ public class EssentialsPlayerListener extends PlayerListener
{
if (sign.getLine(2).equals("§2Everyone"))
{
- user.teleportCooldown();
- user.warpTo(sign.getLine(1));
+ user.getTeleport().warp(sign.getLine(1), "warpsign");
return;
}
if (user.inGroup(sign.getLine(2)))
{
- user.teleportCooldown();
- user.warpTo(sign.getLine(1));
+ user.getTeleport().warp(sign.getLine(1), "warpsign");
return;
}
}
if (user.isAuthorized("essentials.signs.warp.use")
- && (!Essentials.getSettings().getPerWarpPermission() || user.isAuthorized("essentials.warp." + sign.getLine(1))))
+ && (!ess.getSettings().getPerWarpPermission() || user.isAuthorized("essentials.warp." + sign.getLine(1))))
{
- user.teleportCooldown();
- user.warpTo(sign.getLine(1));
+ user.getTeleport().warp(sign.getLine(1), "warpsign");
}
return;
}
@@ -454,7 +513,7 @@ public class EssentialsPlayerListener extends PlayerListener
@Override
public void onPlayerEggThrow(PlayerEggThrowEvent event)
{
- User user = User.get(event.getPlayer());
+ User user = ess.getUser(event.getPlayer());
ItemStack is = new ItemStack(Material.EGG, 1);
if (user.hasUnlimited(is))
{
@@ -466,7 +525,7 @@ public class EssentialsPlayerListener extends PlayerListener
@Override
public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event)
{
- final User user = User.get(event.getPlayer());
+ final User user = ess.getUser(event.getPlayer());
if (user.hasUnlimited(new ItemStack(event.getBucket())))
{
event.getItemStack().setType(event.getBucket());
@@ -493,7 +552,7 @@ public class EssentialsPlayerListener extends PlayerListener
{
return;
}
- User user = User.get(event.getPlayer());
+ User user = ess.getUser(event.getPlayer());
ItemStack is = user.getItemInHand();
if (is == null || is.getType() == Material.AIR)
{
diff --git a/Essentials/src/com/earth2me/essentials/EssentialsTimer.java b/Essentials/src/com/earth2me/essentials/EssentialsTimer.java
new file mode 100644
index 000000000..009a4ffd4
--- /dev/null
+++ b/Essentials/src/com/earth2me/essentials/EssentialsTimer.java
@@ -0,0 +1,81 @@
+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;
+
+
+public class EssentialsTimer implements Runnable, IConf
+{
+ private Essentials parent;
+ private Set allUsers = new HashSet();
+
+ EssentialsTimer(Essentials parent)
+ {
+ this.parent = parent;
+ File userdir = new File(parent.getDataFolder(), "userdata");
+ if (!userdir.exists()) {
+ return;
+ }
+ for (String string : userdir.list())
+ {
+ if (!string.endsWith(".yml")) {
+ continue;
+ }
+ String name = string.substring(0, string.length()-4);
+ User u = parent.getUser(new OfflinePlayer(name));
+ allUsers.add(u);
+ }
+ }
+
+ public void run()
+ {
+ long currentTime = System.currentTimeMillis();
+ for (Player player : parent.getServer().getOnlinePlayers())
+ {
+ User u = parent.getUser(player);
+ allUsers.add(u);
+ u.setLastActivity(currentTime);
+ }
+
+ for (User user: allUsers) {
+ if (user.getBanTimeout() > 0 && user.getBanTimeout() < currentTime) {
+ user.setBanTimeout(0);
+ ((CraftServer)parent.getServer()).getHandle().b(user.getName());
+ Essentials.getStatic().loadBanList();
+ }
+ if (user.getMuteTimeout() > 0 && user.getMuteTimeout() < currentTime && user.isMuted()) {
+ user.setMuteTimeout(0);
+ user.sendMessage("§7You can talk again");
+ user.setMuted(false);
+ }
+ if (user.getJailTimeout() > 0 && user.getJailTimeout() < currentTime && user.isJailed()) {
+ user.setJailTimeout(0);
+ user.setJailed(false);
+ user.sendMessage("§7You have been released");
+ user.setJail(null);
+ try
+ {
+ user.getTeleport().back();
+ }
+ catch (Exception ex)
+ {
+ }
+ }
+
+ if (user.getLastActivity() < currentTime && user.getLastActivity() > user.getLastLogout()) {
+ user.setLastLogout(user.getLastActivity());
+ }
+ }
+ }
+
+ public void reloadConfig()
+ {
+ for (User user : allUsers)
+ {
+ user.reloadConfig();
+ }
+ }
+}
diff --git a/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java b/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java
index e345a3839..cba23d301 100644
--- a/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java
+++ b/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java
@@ -5,77 +5,351 @@ import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
+import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
+import org.bukkit.Location;
import org.bukkit.Material;
+import org.bukkit.World;
import org.bukkit.inventory.ItemStack;
-public class EssentialsUpgrade {
- private static boolean alreadyRun = false;
- private final static Logger logger = Logger.getLogger("Minecraft");
- EssentialsUpgrade(String version, File dataFolder) {
- if (alreadyRun == true) return;
+public class EssentialsUpgrade
+{
+ private static boolean alreadyRun = false;
+ private final static Logger logger = Logger.getLogger("Minecraft");
+ private Essentials ess;
+
+ EssentialsUpgrade(String version, Essentials essentials)
+ {
+ if (alreadyRun == true)
+ {
+ return;
+ }
alreadyRun = true;
- moveWorthValuesToWorthYml(dataFolder);
+ ess = essentials;
+ if (!ess.getDataFolder().exists())
+ {
+ ess.getDataFolder().mkdirs();
+ }
+ moveWorthValuesToWorthYml();
+ sanitizeAllUserFilenames();
+ updateUsersToNewDefaultHome();
+ moveUsersDataToUserdataFolder();
+ convertWarps();
}
- private void moveWorthValuesToWorthYml(File dataFolder) {
- try {
- File configFile = new File(dataFolder, "config.yml");
- if (!configFile.exists()) {
+ private void moveWorthValuesToWorthYml()
+ {
+ try
+ {
+ File configFile = new File(ess.getDataFolder(), "config.yml");
+ if (!configFile.exists())
+ {
return;
}
EssentialsConf conf = new EssentialsConf(configFile);
conf.load();
- Worth w = new Worth(dataFolder);
- for (Material mat : Material.values()) {
+ Worth w = new Worth(ess.getDataFolder());
+ for (Material mat : Material.values())
+ {
int id = mat.getId();
- double value = conf.getDouble("worth-"+id, Double.NaN);
- if (!Double.isNaN(value)) {
+ double value = conf.getDouble("worth-" + id, Double.NaN);
+ if (!Double.isNaN(value))
+ {
w.setPrice(new ItemStack(mat, 1, (short)0, (byte)0), value);
}
}
- removeLinesFromConfig(configFile,"\\s*#?\\s*worth-[0-9]+.*", "# Worth values have been moved to worth.yml");
- } catch (Throwable e) {
+ removeLinesFromConfig(configFile, "\\s*#?\\s*worth-[0-9]+.*", "# Worth values have been moved to worth.yml");
+ }
+ catch (Throwable e)
+ {
logger.log(Level.SEVERE, "Error while upgrading the files", e);
}
}
- private void removeLinesFromConfig(File file, String regex, String info) throws Exception {
+ private void removeLinesFromConfig(File file, String regex, String info) throws Exception
+ {
boolean needUpdate = false;
BufferedReader br = new BufferedReader(new FileReader(file));
- File tempFile = File.createTempFile("essentialsupgrade", ".yml");
+ File tempFile = File.createTempFile("essentialsupgrade", ".tmp.yml", ess.getDataFolder());
BufferedWriter bw = new BufferedWriter(new FileWriter(tempFile));
- do {
+ do
+ {
String line = br.readLine();
- if (line == null) break;
- if (line.matches(regex)) {
- if (needUpdate == false && info != null) {
+ if (line == null)
+ {
+ break;
+ }
+ if (line.matches(regex))
+ {
+ if (needUpdate == false && info != null)
+ {
bw.write(info, 0, info.length());
bw.newLine();
}
needUpdate = true;
- } else {
- if (line.endsWith("\r\n")) {
+ }
+ else
+ {
+ if (line.endsWith("\r\n"))
+ {
bw.write(line, 0, line.length() - 2);
- } else if (line.endsWith("\r") || line.endsWith("\n")) {
+ }
+ else if (line.endsWith("\r") || line.endsWith("\n"))
+ {
bw.write(line, 0, line.length() - 1);
- } else {
+ }
+ else
+ {
bw.write(line, 0, line.length());
}
bw.newLine();
}
- } while(true);
+ }
+ while (true);
br.close();
bw.close();
- if (needUpdate) {
- if (!file.renameTo(new File(file.getParentFile(), file.getName().concat("."+System.currentTimeMillis()+".upgradebackup")))) {
+ if (needUpdate)
+ {
+ if (!file.renameTo(new File(file.getParentFile(), file.getName().concat("." + System.currentTimeMillis() + ".upgradebackup"))))
+ {
throw new Exception("Failed to move config.yml to backup location.");
}
- if (!tempFile.renameTo(file)) {
+ if (!tempFile.renameTo(file))
+ {
throw new Exception("Failed to rename temp file to config.yml");
}
}
}
+
+ private void updateUsersToNewDefaultHome()
+ {
+ File userdataFolder = new File(ess.getDataFolder(), "userdata");
+ if (!userdataFolder.exists() || !userdataFolder.isDirectory())
+ {
+ return;
+ }
+ File[] userFiles = userdataFolder.listFiles();
+
+ for (File file : userFiles)
+ {
+ if (!file.isFile() || !file.getName().endsWith(".yml"))
+ {
+ continue;
+ }
+ EssentialsConf config = new EssentialsConf(file);
+ if (config.hasProperty("home") && !config.hasProperty("home.default"))
+ {
+ @SuppressWarnings("unchecked")
+ List