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