mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2024-06-28 08:50:57 +00:00
Users are now loaded async, so we have a new internal structure where they are saved.
I also did some cleanup on the classes that I worked on. This needs testing, it might break, because it does not behave 100% identical like before. it's possible that /balancetop now needs more time to finish, if not all users are loaded into memory.
This commit is contained in:
parent
9a893f65fe
commit
a085503c84
|
@ -35,13 +35,13 @@ import java.math.BigInteger;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import org.bukkit.command.PluginCommand;
|
import org.bukkit.command.PluginCommand;
|
||||||
import org.bukkit.craftbukkit.scheduler.CraftScheduler;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
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.event.server.ServerListener;
|
import org.bukkit.event.server.ServerListener;
|
||||||
import org.bukkit.plugin.*;
|
import org.bukkit.plugin.*;
|
||||||
import org.bukkit.plugin.java.*;
|
import org.bukkit.plugin.java.*;
|
||||||
|
import org.bukkit.scheduler.BukkitScheduler;
|
||||||
|
|
||||||
|
|
||||||
public class Essentials extends JavaPlugin implements IEssentials
|
public class Essentials extends JavaPlugin implements IEssentials
|
||||||
|
@ -64,7 +64,9 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||||
private transient final static boolean enableErrorLogging = false;
|
private transient final static boolean enableErrorLogging = false;
|
||||||
private transient final EssentialsErrorHandler errorHandler = new EssentialsErrorHandler();
|
private transient final EssentialsErrorHandler errorHandler = new EssentialsErrorHandler();
|
||||||
private transient IPermissionsHandler permissionsHandler;
|
private transient IPermissionsHandler permissionsHandler;
|
||||||
|
private transient UserMap userMap;
|
||||||
|
|
||||||
|
@Override
|
||||||
public ISettings getSettings()
|
public ISettings getSettings()
|
||||||
{
|
{
|
||||||
return settings;
|
return settings;
|
||||||
|
@ -85,10 +87,12 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||||
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(this);
|
settings = new Settings(this);
|
||||||
|
userMap = new UserMap(this);
|
||||||
permissionsHandler = new ConfigPermissionsHandler(this);
|
permissionsHandler = new ConfigPermissionsHandler(this);
|
||||||
Economy.setEss(this);
|
Economy.setEss(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void onEnable()
|
public void onEnable()
|
||||||
{
|
{
|
||||||
final String[] javaversion = System.getProperty("java.version").split("\\.", 3);
|
final String[] javaversion = System.getProperty("java.version").split("\\.", 3);
|
||||||
|
@ -100,13 +104,15 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||||
{
|
{
|
||||||
LOGGER.addHandler(errorHandler);
|
LOGGER.addHandler(errorHandler);
|
||||||
}
|
}
|
||||||
EssentialsUpgrade upgrade = new EssentialsUpgrade(this.getDescription().getVersion(), this);
|
final EssentialsUpgrade upgrade = new EssentialsUpgrade(this);
|
||||||
upgrade.beforeSettings();
|
upgrade.beforeSettings();
|
||||||
confList = new ArrayList<IConf>();
|
confList = new ArrayList<IConf>();
|
||||||
settings = new Settings(this);
|
settings = new Settings(this);
|
||||||
confList.add(settings);
|
confList.add(settings);
|
||||||
upgrade.afterSettings();
|
upgrade.afterSettings();
|
||||||
Util.updateLocale(settings.getLocale(), this);
|
Util.updateLocale(settings.getLocale(), this);
|
||||||
|
userMap = new UserMap(this);
|
||||||
|
confList.add(userMap);
|
||||||
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());
|
||||||
|
@ -212,12 +218,14 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||||
LOGGER.info(Util.format("loadinfo", this.getDescription().getName(), this.getDescription().getVersion(), Util.joinList(this.getDescription().getAuthors())));
|
LOGGER.info(Util.format("loadinfo", this.getDescription().getName(), this.getDescription().getVersion(), Util.joinList(this.getDescription().getAuthors())));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void onDisable()
|
public void onDisable()
|
||||||
{
|
{
|
||||||
Trade.closeLog();
|
Trade.closeLog();
|
||||||
LOGGER.removeHandler(errorHandler);
|
LOGGER.removeHandler(errorHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void reload()
|
public void reload()
|
||||||
{
|
{
|
||||||
Trade.closeLog();
|
Trade.closeLog();
|
||||||
|
@ -238,12 +246,14 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||||
getConfiguration().load();
|
getConfiguration().load();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String[] getMotd(CommandSender sender, String def)
|
@Override
|
||||||
|
public String[] getMotd(final CommandSender sender, final String def)
|
||||||
{
|
{
|
||||||
return getLines(sender, "motd", def);
|
return getLines(sender, "motd", def);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String[] getLines(CommandSender sender, String node, String def)
|
@Override
|
||||||
|
public String[] getLines(final CommandSender sender, final String node, final String def)
|
||||||
{
|
{
|
||||||
List<String> lines = (List<String>)getConfiguration().getProperty(node);
|
List<String> lines = (List<String>)getConfiguration().getProperty(node);
|
||||||
if (lines == null)
|
if (lines == null)
|
||||||
|
@ -348,12 +358,13 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args)
|
public boolean onCommand(final CommandSender sender, final Command command, final String commandLabel, final String[] args)
|
||||||
{
|
{
|
||||||
return onCommandEssentials(sender, command, commandLabel, args, Essentials.class.getClassLoader(), "com.earth2me.essentials.commands.Command", "essentials.");
|
return onCommandEssentials(sender, command, commandLabel, args, Essentials.class.getClassLoader(), "com.earth2me.essentials.commands.Command", "essentials.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean onCommandEssentials(CommandSender sender, Command command, String commandLabel, String[] args, ClassLoader classLoader, String commandPath, String permissionPrefix)
|
@Override
|
||||||
|
public boolean onCommandEssentials(final CommandSender sender, final Command command, final String commandLabel, final String[] args, final ClassLoader classLoader, final String commandPath, final String permissionPrefix)
|
||||||
{
|
{
|
||||||
// Allow plugins to override the command via onCommand
|
// Allow plugins to override the command via onCommand
|
||||||
if (!getSettings().isCommandOverridden(command.getName()) && !commandLabel.startsWith("e"))
|
if (!getSettings().isCommandOverridden(command.getName()) && !commandLabel.startsWith("e"))
|
||||||
|
@ -365,7 +376,7 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
PluginDescriptionFile desc = p.getDescription();
|
final PluginDescriptionFile desc = p.getDescription();
|
||||||
if (desc == null)
|
if (desc == null)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
|
@ -376,7 +387,7 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
PluginCommand pc = getServer().getPluginCommand(desc.getName() + ":" + commandLabel);
|
final PluginCommand pc = getServer().getPluginCommand(desc.getName() + ":" + commandLabel);
|
||||||
if (pc != null)
|
if (pc != null)
|
||||||
{
|
{
|
||||||
return pc.execute(sender, commandLabel, args);
|
return pc.execute(sender, commandLabel, args);
|
||||||
|
@ -462,6 +473,7 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void showError(final CommandSender sender, final Throwable exception, final String commandLabel)
|
public void showError(final CommandSender sender, final Throwable exception, final String commandLabel)
|
||||||
{
|
{
|
||||||
sender.sendMessage(Util.format("errorWithMessage", exception.getMessage()));
|
sender.sendMessage(Util.format("errorWithMessage", exception.getMessage()));
|
||||||
|
@ -481,46 +493,64 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public CraftScheduler getScheduler()
|
@Override
|
||||||
|
public BukkitScheduler getScheduler()
|
||||||
{
|
{
|
||||||
return (CraftScheduler)this.getServer().getScheduler();
|
return this.getServer().getScheduler();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Jail getJail()
|
public Jail getJail()
|
||||||
{
|
{
|
||||||
return jail;
|
return jail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Warps getWarps()
|
public Warps getWarps()
|
||||||
{
|
{
|
||||||
return warps;
|
return warps;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Worth getWorth()
|
public Worth getWorth()
|
||||||
{
|
{
|
||||||
return worth;
|
return worth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Backup getBackup()
|
public Backup getBackup()
|
||||||
{
|
{
|
||||||
return backup;
|
return backup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Spawn getSpawn()
|
public Spawn getSpawn()
|
||||||
{
|
{
|
||||||
return spawn;
|
return spawn;
|
||||||
}
|
}
|
||||||
|
|
||||||
public User getUser(Object base)
|
@Override
|
||||||
|
public User getUser(final Object base)
|
||||||
{
|
{
|
||||||
if (base instanceof Player)
|
if (base instanceof Player)
|
||||||
{
|
{
|
||||||
return getUser((Player)base);
|
return getUser((Player)base);
|
||||||
}
|
}
|
||||||
|
if (base instanceof String)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return userMap.getUser((String)base);
|
||||||
|
}
|
||||||
|
catch (NullPointerException ex)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T extends Player> User getUser(T base)
|
private <T extends Player> User getUser(final T base)
|
||||||
{
|
{
|
||||||
if (base == null)
|
if (base == null)
|
||||||
{
|
{
|
||||||
|
@ -532,70 +562,57 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||||
return (User)base;
|
return (User)base;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (users.containsKey(base.getName().toLowerCase()))
|
return userMap.getUser(base.getName()).update(base);
|
||||||
{
|
|
||||||
return users.get(base.getName().toLowerCase()).update(base);
|
|
||||||
}
|
|
||||||
|
|
||||||
User u = new User(base, this);
|
|
||||||
users.put(u.getName().toLowerCase(), u);
|
|
||||||
return u;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, User> getAllUsers()
|
@Override
|
||||||
|
public User getOfflineUser(final String name)
|
||||||
{
|
{
|
||||||
return users;
|
try
|
||||||
}
|
|
||||||
|
|
||||||
public User getOfflineUser(String name)
|
|
||||||
{
|
|
||||||
// Don't create a new offline user, if we already have that user loaded.
|
|
||||||
User u = users.get(name.toLowerCase());
|
|
||||||
if (u != null)
|
|
||||||
{
|
{
|
||||||
return u;
|
return userMap.getUser(name);
|
||||||
}
|
}
|
||||||
File userFolder = new File(getDataFolder(), "userdata");
|
catch (NullPointerException ex)
|
||||||
File userFile = new File(userFolder, Util.sanitizeFileName(name) + ".yml");
|
{
|
||||||
if (userFile.exists())
|
return null;
|
||||||
{ //Users do not get offline changes saved without being reproccessed as Users! ~ Xeology :)
|
|
||||||
return getUser((Player)new OfflinePlayer(name, this));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public World getWorld(final String name)
|
public World getWorld(final String name)
|
||||||
{
|
{
|
||||||
if (name.matches("[0-9]+"))
|
if (name.matches("[0-9]+"))
|
||||||
{
|
{
|
||||||
final int id = Integer.parseInt(name);
|
final int worldId = Integer.parseInt(name);
|
||||||
if (id < getServer().getWorlds().size())
|
if (worldId < getServer().getWorlds().size())
|
||||||
{
|
{
|
||||||
return getServer().getWorlds().get(id);
|
return getServer().getWorlds().get(worldId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return getServer().getWorld(name);
|
return getServer().getWorld(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void addReloadListener(final IConf listener)
|
public void addReloadListener(final IConf listener)
|
||||||
{
|
{
|
||||||
confList.add(listener);
|
confList.add(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Methods getPaymentMethod()
|
public Methods getPaymentMethod()
|
||||||
{
|
{
|
||||||
return paymentMethod;
|
return paymentMethod;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int broadcastMessage(final String name, final String message)
|
public int broadcastMessage(final String name, final String message)
|
||||||
{
|
{
|
||||||
Player[] players = getServer().getOnlinePlayers();
|
final Player[] players = getServer().getOnlinePlayers();
|
||||||
|
|
||||||
for (Player player : players)
|
for (Player player : players)
|
||||||
{
|
{
|
||||||
User u = getUser(player);
|
final User user = getUser(player);
|
||||||
if (!u.isIgnoredPlayer(name))
|
if (!user.isIgnoredPlayer(name))
|
||||||
{
|
{
|
||||||
player.sendMessage(message);
|
player.sendMessage(message);
|
||||||
}
|
}
|
||||||
|
@ -609,48 +626,63 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||||
return errorHandler.getErrors();
|
return errorHandler.getErrors();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int scheduleAsyncDelayedTask(final Runnable run)
|
public int scheduleAsyncDelayedTask(final Runnable run)
|
||||||
{
|
{
|
||||||
return this.getScheduler().scheduleAsyncDelayedTask(this, run);
|
return this.getScheduler().scheduleAsyncDelayedTask(this, run);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int scheduleSyncDelayedTask(final Runnable run)
|
public int scheduleSyncDelayedTask(final Runnable run)
|
||||||
{
|
{
|
||||||
return this.getScheduler().scheduleSyncDelayedTask(this, run);
|
return this.getScheduler().scheduleSyncDelayedTask(this, run);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int scheduleSyncDelayedTask(final Runnable run, final long delay)
|
public int scheduleSyncDelayedTask(final Runnable run, final long delay)
|
||||||
{
|
{
|
||||||
return this.getScheduler().scheduleSyncDelayedTask(this, run, delay);
|
return this.getScheduler().scheduleSyncDelayedTask(this, run, delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int scheduleSyncRepeatingTask(final Runnable run, final long delay, final long period)
|
public int scheduleSyncRepeatingTask(final Runnable run, final long delay, final long period)
|
||||||
{
|
{
|
||||||
return this.getScheduler().scheduleSyncRepeatingTask(this, run, delay, period);
|
return this.getScheduler().scheduleSyncRepeatingTask(this, run, delay, period);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public TNTExplodeListener getTNTListener()
|
public TNTExplodeListener getTNTListener()
|
||||||
{
|
{
|
||||||
return tntListener;
|
return tntListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public IPermissionsHandler getPermissionsHandler()
|
public IPermissionsHandler getPermissionsHandler()
|
||||||
{
|
{
|
||||||
return permissionsHandler;
|
return permissionsHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPermissionsHandler(IPermissionsHandler handler)
|
@Override
|
||||||
|
public void setPermissionsHandler(final IPermissionsHandler handler)
|
||||||
{
|
{
|
||||||
this.permissionsHandler = handler;
|
this.permissionsHandler = handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public BanWorkaround getBans()
|
public BanWorkaround getBans()
|
||||||
{
|
{
|
||||||
return bans;
|
return bans;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public ItemDb getItemDb()
|
public ItemDb getItemDb()
|
||||||
{
|
{
|
||||||
return itemDb;
|
return itemDb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UserMap getUserMap()
|
||||||
|
{
|
||||||
|
return userMap;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
package com.earth2me.essentials;
|
package com.earth2me.essentials;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
@ -308,6 +306,11 @@ public class EssentialsPlayerListener extends PlayerListener
|
||||||
final User user = ess.getUser(event.getPlayer());
|
final User user = ess.getUser(event.getPlayer());
|
||||||
user.setNPC(false);
|
user.setNPC(false);
|
||||||
|
|
||||||
|
final long currentTime = System.currentTimeMillis();
|
||||||
|
user.checkBanTimeout(currentTime);
|
||||||
|
user.checkMuteTimeout(currentTime);
|
||||||
|
user.checkJailTimeout(currentTime);
|
||||||
|
|
||||||
if (user.isBanned())
|
if (user.isBanned())
|
||||||
{
|
{
|
||||||
final String banReason = user.getBanReason();
|
final String banReason = user.getBanReason();
|
||||||
|
|
|
@ -1,79 +1,44 @@
|
||||||
package com.earth2me.essentials;
|
package com.earth2me.essentials;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
|
||||||
public class EssentialsTimer implements Runnable, IConf
|
public class EssentialsTimer implements Runnable
|
||||||
{
|
{
|
||||||
private final IEssentials ess;
|
private final transient IEssentials ess;
|
||||||
private final Set<User> allUsers = new HashSet<User>();
|
private final transient Set<User> onlineUsers = new HashSet<User>();
|
||||||
|
|
||||||
EssentialsTimer(IEssentials ess)
|
EssentialsTimer(final IEssentials ess)
|
||||||
{
|
{
|
||||||
this.ess = ess;
|
this.ess = ess;
|
||||||
File userdir = new File(ess.getDataFolder(), "userdata");
|
|
||||||
if (!userdir.exists()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (String string : userdir.list())
|
|
||||||
{
|
|
||||||
if (!string.endsWith(".yml")) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
String name = string.substring(0, string.length()-4);
|
|
||||||
User u = ess.getUser(new OfflinePlayer(name, ess));
|
|
||||||
allUsers.add(u);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
long currentTime = System.currentTimeMillis();
|
final long currentTime = System.currentTimeMillis();
|
||||||
for (Player player : ess.getServer().getOnlinePlayers())
|
for (Player player : ess.getServer().getOnlinePlayers())
|
||||||
{
|
{
|
||||||
User u = ess.getUser(player);
|
final User user = ess.getUser(player);
|
||||||
allUsers.add(u);
|
onlineUsers.add(user);
|
||||||
u.setLastActivity(currentTime);
|
user.setLastActivity(currentTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (User user: allUsers) {
|
|
||||||
if (user.getBanTimeout() > 0 && user.getBanTimeout() < currentTime) {
|
|
||||||
user.setBanTimeout(0);
|
|
||||||
ess.getBans().unbanByName(user.getName());
|
|
||||||
}
|
|
||||||
if (user.getMuteTimeout() > 0 && user.getMuteTimeout() < currentTime && user.isMuted()) {
|
|
||||||
user.setMuteTimeout(0);
|
|
||||||
user.sendMessage(Util.i18n("canTalkAgain"));
|
|
||||||
user.setMuted(false);
|
|
||||||
}
|
|
||||||
if (user.getJailTimeout() > 0 && user.getJailTimeout() < currentTime && user.isJailed()) {
|
|
||||||
user.setJailTimeout(0);
|
|
||||||
user.setJailed(false);
|
|
||||||
user.sendMessage(Util.i18n("haveBeenReleased"));
|
|
||||||
user.setJail(null);
|
|
||||||
try
|
|
||||||
{
|
|
||||||
user.getTeleport().back();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (user.getLastActivity() < currentTime && user.getLastActivity() > user.getLastLogout()) {
|
|
||||||
user.setLastLogout(user.getLastActivity());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void reloadConfig()
|
final Iterator<User> iterator = onlineUsers.iterator();
|
||||||
{
|
while (iterator.hasNext())
|
||||||
for (User user : allUsers)
|
|
||||||
{
|
{
|
||||||
user.reloadConfig();
|
final User user = iterator.next();
|
||||||
|
if (user.getLastActivity() < currentTime && user.getLastActivity() > user.getLastLogout())
|
||||||
|
{
|
||||||
|
user.setLastLogout(user.getLastActivity());
|
||||||
|
iterator.remove();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
user.checkMuteTimeout(currentTime);
|
||||||
|
user.checkJailTimeout(currentTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,63 +16,70 @@ import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
public class EssentialsUpgrade
|
public class EssentialsUpgrade
|
||||||
{
|
{
|
||||||
private static boolean alreadyRun = false;
|
private final static Logger LOGGER = Logger.getLogger("Minecraft");
|
||||||
private final static Logger logger = Logger.getLogger("Minecraft");
|
private final transient IEssentials ess;
|
||||||
private final IEssentials ess;
|
private final transient EssentialsConf doneFile;
|
||||||
|
|
||||||
EssentialsUpgrade(String version, IEssentials essentials)
|
EssentialsUpgrade(final IEssentials essentials)
|
||||||
{
|
{
|
||||||
ess = essentials;
|
ess = essentials;
|
||||||
if (alreadyRun)
|
if (!ess.getDataFolder().exists())
|
||||||
{
|
{
|
||||||
return;
|
ess.getDataFolder().mkdirs();
|
||||||
}
|
}
|
||||||
alreadyRun = true;
|
doneFile = new EssentialsConf(new File(ess.getDataFolder(), "upgrades-done.yml"));
|
||||||
|
doneFile.load();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void moveWorthValuesToWorthYml()
|
private void moveWorthValuesToWorthYml()
|
||||||
{
|
{
|
||||||
|
if (doneFile.getBoolean("moveWorthValuesToWorthYml", false))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
File configFile = new File(ess.getDataFolder(), "config.yml");
|
final File configFile = new File(ess.getDataFolder(), "config.yml");
|
||||||
if (!configFile.exists())
|
if (!configFile.exists())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
EssentialsConf conf = new EssentialsConf(configFile);
|
final EssentialsConf conf = new EssentialsConf(configFile);
|
||||||
conf.load();
|
conf.load();
|
||||||
Worth w = new Worth(ess.getDataFolder());
|
final Worth worth = new Worth(ess.getDataFolder());
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
for (Material mat : Material.values())
|
for (Material mat : Material.values())
|
||||||
{
|
{
|
||||||
int id = mat.getId();
|
final int id = mat.getId();
|
||||||
double value = conf.getDouble("worth-" + id, Double.NaN);
|
final double value = conf.getDouble("worth-" + id, Double.NaN);
|
||||||
if (!Double.isNaN(value))
|
if (!Double.isNaN(value))
|
||||||
{
|
{
|
||||||
found = true;
|
found = true;
|
||||||
w.setPrice(new ItemStack(mat, 1, (short)0, (byte)0), value);
|
worth.setPrice(new ItemStack(mat, 1, (short)0, (byte)0), value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (found)
|
if (found)
|
||||||
{
|
{
|
||||||
removeLinesFromConfig(configFile, "\\s*#?\\s*worth-[0-9]+.*", "# Worth values have been moved to worth.yml");
|
removeLinesFromConfig(configFile, "\\s*#?\\s*worth-[0-9]+.*", "# Worth values have been moved to worth.yml");
|
||||||
}
|
}
|
||||||
|
doneFile.setProperty("moveWorthValuesToWorthYml", true);
|
||||||
|
doneFile.save();
|
||||||
}
|
}
|
||||||
catch (Throwable e)
|
catch (Throwable e)
|
||||||
{
|
{
|
||||||
logger.log(Level.SEVERE, Util.i18n("upgradingFilesError"), e);
|
LOGGER.log(Level.SEVERE, Util.i18n("upgradingFilesError"), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeLinesFromConfig(File file, String regex, String info) throws Exception
|
private void removeLinesFromConfig(File file, String regex, String info) throws Exception
|
||||||
{
|
{
|
||||||
boolean needUpdate = false;
|
boolean needUpdate = false;
|
||||||
BufferedReader br = new BufferedReader(new FileReader(file));
|
final BufferedReader bReader = new BufferedReader(new FileReader(file));
|
||||||
File tempFile = File.createTempFile("essentialsupgrade", ".tmp.yml", ess.getDataFolder());
|
final File tempFile = File.createTempFile("essentialsupgrade", ".tmp.yml", ess.getDataFolder());
|
||||||
BufferedWriter bw = new BufferedWriter(new FileWriter(tempFile));
|
final BufferedWriter bWriter = new BufferedWriter(new FileWriter(tempFile));
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
String line = br.readLine();
|
final String line = bReader.readLine();
|
||||||
if (line == null)
|
if (line == null)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
|
@ -81,8 +88,8 @@ public class EssentialsUpgrade
|
||||||
{
|
{
|
||||||
if (!needUpdate && info != null)
|
if (!needUpdate && info != null)
|
||||||
{
|
{
|
||||||
bw.write(info, 0, info.length());
|
bWriter.write(info, 0, info.length());
|
||||||
bw.newLine();
|
bWriter.newLine();
|
||||||
}
|
}
|
||||||
needUpdate = true;
|
needUpdate = true;
|
||||||
}
|
}
|
||||||
|
@ -90,22 +97,22 @@ public class EssentialsUpgrade
|
||||||
{
|
{
|
||||||
if (line.endsWith("\r\n"))
|
if (line.endsWith("\r\n"))
|
||||||
{
|
{
|
||||||
bw.write(line, 0, line.length() - 2);
|
bWriter.write(line, 0, line.length() - 2);
|
||||||
}
|
}
|
||||||
else if (line.endsWith("\r") || line.endsWith("\n"))
|
else if (line.endsWith("\r") || line.endsWith("\n"))
|
||||||
{
|
{
|
||||||
bw.write(line, 0, line.length() - 1);
|
bWriter.write(line, 0, line.length() - 1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
bw.write(line, 0, line.length());
|
bWriter.write(line, 0, line.length());
|
||||||
}
|
}
|
||||||
bw.newLine();
|
bWriter.newLine();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (true);
|
while (true);
|
||||||
br.close();
|
bReader.close();
|
||||||
bw.close();
|
bWriter.close();
|
||||||
if (needUpdate)
|
if (needUpdate)
|
||||||
{
|
{
|
||||||
if (!file.renameTo(new File(file.getParentFile(), file.getName().concat("." + System.currentTimeMillis() + ".upgradebackup"))))
|
if (!file.renameTo(new File(file.getParentFile(), file.getName().concat("." + System.currentTimeMillis() + ".upgradebackup"))))
|
||||||
|
@ -116,19 +123,25 @@ public class EssentialsUpgrade
|
||||||
{
|
{
|
||||||
throw new Exception(Util.i18n("configFileRenameError"));
|
throw new Exception(Util.i18n("configFileRenameError"));
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
tempFile.delete();
|
tempFile.delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateUsersToNewDefaultHome()
|
private void updateUsersToNewDefaultHome()
|
||||||
{
|
{
|
||||||
File userdataFolder = new File(ess.getDataFolder(), "userdata");
|
if (doneFile.getBoolean("updateUsersToNewDefaultHome", false))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final File userdataFolder = new File(ess.getDataFolder(), "userdata");
|
||||||
if (!userdataFolder.exists() || !userdataFolder.isDirectory())
|
if (!userdataFolder.exists() || !userdataFolder.isDirectory())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
File[] userFiles = userdataFolder.listFiles();
|
final File[] userFiles = userdataFolder.listFiles();
|
||||||
|
|
||||||
for (File file : userFiles)
|
for (File file : userFiles)
|
||||||
{
|
{
|
||||||
|
@ -136,15 +149,16 @@ public class EssentialsUpgrade
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
EssentialsConf config = new EssentialsConf(file);
|
final EssentialsConf config = new EssentialsConf(file);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
config.load();
|
config.load();
|
||||||
if (config.hasProperty("home") && !config.hasProperty("home.default"))
|
if (config.hasProperty("home") && !config.hasProperty("home.default"))
|
||||||
{
|
{
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
List<Object> vals = (List<Object>)config.getProperty("home");
|
final List<Object> vals = (List<Object>)config.getProperty("home");
|
||||||
if (vals == null) {
|
if (vals == null)
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
World world = ess.getServer().getWorlds().get(0);
|
World world = ess.getServer().getWorlds().get(0);
|
||||||
|
@ -154,7 +168,7 @@ public class EssentialsUpgrade
|
||||||
}
|
}
|
||||||
if (world != null)
|
if (world != null)
|
||||||
{
|
{
|
||||||
Location loc = new Location(
|
final Location loc = new Location(
|
||||||
world,
|
world,
|
||||||
((Number)vals.get(0)).doubleValue(),
|
((Number)vals.get(0)).doubleValue(),
|
||||||
((Number)vals.get(1)).doubleValue(),
|
((Number)vals.get(1)).doubleValue(),
|
||||||
|
@ -162,7 +176,7 @@ public class EssentialsUpgrade
|
||||||
((Number)vals.get(3)).floatValue(),
|
((Number)vals.get(3)).floatValue(),
|
||||||
((Number)vals.get(4)).floatValue());
|
((Number)vals.get(4)).floatValue());
|
||||||
|
|
||||||
String worldName = world.getName().toLowerCase();
|
final String worldName = world.getName().toLowerCase();
|
||||||
if (worldName != null && !worldName.isEmpty())
|
if (worldName != null && !worldName.isEmpty())
|
||||||
{
|
{
|
||||||
config.removeProperty("home");
|
config.removeProperty("home");
|
||||||
|
@ -175,30 +189,32 @@ public class EssentialsUpgrade
|
||||||
}
|
}
|
||||||
catch (RuntimeException ex)
|
catch (RuntimeException ex)
|
||||||
{
|
{
|
||||||
logger.log(Level.INFO, "File: "+file.toString());
|
LOGGER.log(Level.INFO, "File: " + file.toString());
|
||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
doneFile.setProperty("updateUsersToNewDefaultHome", true);
|
||||||
|
doneFile.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void moveUsersDataToUserdataFolder()
|
private void moveUsersDataToUserdataFolder()
|
||||||
{
|
{
|
||||||
File usersFile = new File(ess.getDataFolder(), "users.yml");
|
final File usersFile = new File(ess.getDataFolder(), "users.yml");
|
||||||
if (!usersFile.exists())
|
if (!usersFile.exists())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
EssentialsConf usersConfig = new EssentialsConf(usersFile);
|
final EssentialsConf usersConfig = new EssentialsConf(usersFile);
|
||||||
usersConfig.load();
|
usersConfig.load();
|
||||||
for (String username : usersConfig.getKeys(null))
|
for (String username : usersConfig.getKeys(null))
|
||||||
{
|
{
|
||||||
User user = new User(new OfflinePlayer(username, ess), ess);
|
final User user = new User(new OfflinePlayer(username, ess), ess);
|
||||||
String nickname = usersConfig.getString(username + ".nickname");
|
final String nickname = usersConfig.getString(username + ".nickname");
|
||||||
if (nickname != null && !nickname.isEmpty() && !nickname.equals(username))
|
if (nickname != null && !nickname.isEmpty() && !nickname.equals(username))
|
||||||
{
|
{
|
||||||
user.setNickname(nickname);
|
user.setNickname(nickname);
|
||||||
}
|
}
|
||||||
List<String> mails = usersConfig.getStringList(username + ".mail", null);
|
final List<String> mails = usersConfig.getStringList(username + ".mail", null);
|
||||||
if (mails != null && !mails.isEmpty())
|
if (mails != null && !mails.isEmpty())
|
||||||
{
|
{
|
||||||
user.setMails(mails);
|
user.setMails(mails);
|
||||||
|
@ -206,8 +222,9 @@ public class EssentialsUpgrade
|
||||||
if (!user.hasHome())
|
if (!user.hasHome())
|
||||||
{
|
{
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
List<Object> vals = (List<Object>)usersConfig.getProperty(username + ".home");
|
final List<Object> vals = (List<Object>)usersConfig.getProperty(username + ".home");
|
||||||
if (vals != null) {
|
if (vals != null)
|
||||||
|
{
|
||||||
World world = ess.getServer().getWorlds().get(0);
|
World world = ess.getServer().getWorlds().get(0);
|
||||||
if (vals.size() > 5)
|
if (vals.size() > 5)
|
||||||
{
|
{
|
||||||
|
@ -230,40 +247,56 @@ public class EssentialsUpgrade
|
||||||
|
|
||||||
private void convertWarps()
|
private void convertWarps()
|
||||||
{
|
{
|
||||||
File warpsFolder = new File(ess.getDataFolder(), "warps");
|
final File warpsFolder = new File(ess.getDataFolder(), "warps");
|
||||||
if (!warpsFolder.exists())
|
if (!warpsFolder.exists())
|
||||||
{
|
{
|
||||||
warpsFolder.mkdirs();
|
warpsFolder.mkdirs();
|
||||||
}
|
}
|
||||||
File[] listOfFiles = warpsFolder.listFiles();
|
final File[] listOfFiles = warpsFolder.listFiles();
|
||||||
if (listOfFiles.length >= 1)
|
if (listOfFiles.length >= 1)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < listOfFiles.length; i++)
|
for (int i = 0; i < listOfFiles.length; i++)
|
||||||
{
|
{
|
||||||
String filename = listOfFiles[i].getName();
|
final String filename = listOfFiles[i].getName();
|
||||||
if (listOfFiles[i].isFile() && filename.endsWith(".dat"))
|
if (listOfFiles[i].isFile() && filename.endsWith(".dat"))
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
BufferedReader rx = new BufferedReader(new FileReader(listOfFiles[i]));
|
final BufferedReader rx = new BufferedReader(new FileReader(listOfFiles[i]));
|
||||||
double x, y, z;
|
double x, y, z;
|
||||||
float yaw, pitch;
|
float yaw, pitch;
|
||||||
String worldName;
|
String worldName;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!rx.ready()) continue;
|
if (!rx.ready())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
x = Double.parseDouble(rx.readLine().trim());
|
x = Double.parseDouble(rx.readLine().trim());
|
||||||
if (!rx.ready()) continue;
|
if (!rx.ready())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
y = Double.parseDouble(rx.readLine().trim());
|
y = Double.parseDouble(rx.readLine().trim());
|
||||||
if (!rx.ready()) continue;
|
if (!rx.ready())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
z = Double.parseDouble(rx.readLine().trim());
|
z = Double.parseDouble(rx.readLine().trim());
|
||||||
if (!rx.ready()) continue;
|
if (!rx.ready())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
yaw = Float.parseFloat(rx.readLine().trim());
|
yaw = Float.parseFloat(rx.readLine().trim());
|
||||||
if (!rx.ready()) continue;
|
if (!rx.ready())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
pitch = Float.parseFloat(rx.readLine().trim());
|
pitch = Float.parseFloat(rx.readLine().trim());
|
||||||
worldName = rx.readLine();
|
worldName = rx.readLine();
|
||||||
}
|
}
|
||||||
finally {
|
finally
|
||||||
|
{
|
||||||
rx.close();
|
rx.close();
|
||||||
}
|
}
|
||||||
World w = null;
|
World w = null;
|
||||||
|
@ -285,7 +318,7 @@ public class EssentialsUpgrade
|
||||||
w = w1;
|
w = w1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Location loc = new Location(w, x, y, z, yaw, pitch);
|
final Location loc = new Location(w, x, y, z, yaw, pitch);
|
||||||
ess.getWarps().setWarp(filename.substring(0, filename.length() - 4), loc);
|
ess.getWarps().setWarp(filename.substring(0, filename.length() - 4), loc);
|
||||||
if (!listOfFiles[i].renameTo(new File(warpsFolder, filename + ".old")))
|
if (!listOfFiles[i].renameTo(new File(warpsFolder, filename + ".old")))
|
||||||
{
|
{
|
||||||
|
@ -294,52 +327,52 @@ public class EssentialsUpgrade
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
logger.log(Level.SEVERE, null, ex);
|
LOGGER.log(Level.SEVERE, null, ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
File warpFile = new File(ess.getDataFolder(), "warps.txt");
|
final File warpFile = new File(ess.getDataFolder(), "warps.txt");
|
||||||
if (warpFile.exists())
|
if (warpFile.exists())
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
BufferedReader rx = new BufferedReader(new FileReader(warpFile));
|
final BufferedReader rx = new BufferedReader(new FileReader(warpFile));
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
for (String[] parts = new String[0]; rx.ready(); parts = rx.readLine().split(":"))
|
for (String[] parts = new String[0]; rx.ready(); parts = rx.readLine().split(":"))
|
||||||
{
|
|
||||||
if (parts.length < 6)
|
|
||||||
{
|
{
|
||||||
continue;
|
if (parts.length < 6)
|
||||||
}
|
|
||||||
String name = parts[0];
|
|
||||||
double x = Double.parseDouble(parts[1].trim());
|
|
||||||
double y = Double.parseDouble(parts[2].trim());
|
|
||||||
double z = Double.parseDouble(parts[3].trim());
|
|
||||||
float yaw = Float.parseFloat(parts[4].trim());
|
|
||||||
float pitch = Float.parseFloat(parts[5].trim());
|
|
||||||
if (name.isEmpty())
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
World w = null;
|
|
||||||
for (World world : ess.getServer().getWorlds())
|
|
||||||
{
|
|
||||||
if (world.getEnvironment() != World.Environment.NETHER)
|
|
||||||
{
|
{
|
||||||
w = world;
|
continue;
|
||||||
break;
|
}
|
||||||
|
final String name = parts[0];
|
||||||
|
final double x = Double.parseDouble(parts[1].trim());
|
||||||
|
final double y = Double.parseDouble(parts[2].trim());
|
||||||
|
final double z = Double.parseDouble(parts[3].trim());
|
||||||
|
final float yaw = Float.parseFloat(parts[4].trim());
|
||||||
|
final float pitch = Float.parseFloat(parts[5].trim());
|
||||||
|
if (name.isEmpty())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
World w = null;
|
||||||
|
for (World world : ess.getServer().getWorlds())
|
||||||
|
{
|
||||||
|
if (world.getEnvironment() != World.Environment.NETHER)
|
||||||
|
{
|
||||||
|
w = world;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
final Location loc = new Location(w, x, y, z, yaw, pitch);
|
||||||
|
ess.getWarps().setWarp(name, loc);
|
||||||
|
if (!warpFile.renameTo(new File(ess.getDataFolder(), "warps.txt.old")))
|
||||||
|
{
|
||||||
|
throw new Exception(Util.format("fileRenameError", "warps.txt"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Location loc = new Location(w, x, y, z, yaw, pitch);
|
|
||||||
ess.getWarps().setWarp(name, loc);
|
|
||||||
if (!warpFile.renameTo(new File(ess.getDataFolder(), "warps.txt.old")))
|
|
||||||
{
|
|
||||||
throw new Exception(Util.format("fileRenameError", "warps.txt"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
@ -348,52 +381,60 @@ public class EssentialsUpgrade
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
logger.log(Level.SEVERE, null, ex);
|
LOGGER.log(Level.SEVERE, null, ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sanitizeAllUserFilenames()
|
private void sanitizeAllUserFilenames()
|
||||||
{
|
{
|
||||||
File usersFolder = new File(ess.getDataFolder(), "userdata");
|
if (doneFile.getBoolean("sanitizeAllUserFilenames", false))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final File usersFolder = new File(ess.getDataFolder(), "userdata");
|
||||||
if (!usersFolder.exists())
|
if (!usersFolder.exists())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
File[] listOfFiles = usersFolder.listFiles();
|
final File[] listOfFiles = usersFolder.listFiles();
|
||||||
for (int i = 0; i < listOfFiles.length; i++)
|
for (int i = 0; i < listOfFiles.length; i++)
|
||||||
{
|
{
|
||||||
String filename = listOfFiles[i].getName();
|
final String filename = listOfFiles[i].getName();
|
||||||
if (!listOfFiles[i].isFile() || !filename.endsWith(".yml"))
|
if (!listOfFiles[i].isFile() || !filename.endsWith(".yml"))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
String sanitizedFilename = Util.sanitizeFileName(filename.substring(0, filename.length() - 4)) + ".yml";
|
final String sanitizedFilename = Util.sanitizeFileName(filename.substring(0, filename.length() - 4)) + ".yml";
|
||||||
if (sanitizedFilename.equals(filename))
|
if (sanitizedFilename.equals(filename))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
File tmpFile = new File(listOfFiles[i].getParentFile(), sanitizedFilename + ".tmp");
|
final File tmpFile = new File(listOfFiles[i].getParentFile(), sanitizedFilename + ".tmp");
|
||||||
File newFile = new File(listOfFiles[i].getParentFile(), sanitizedFilename);
|
final File newFile = new File(listOfFiles[i].getParentFile(), sanitizedFilename);
|
||||||
if (!listOfFiles[i].renameTo(tmpFile)) {
|
if (!listOfFiles[i].renameTo(tmpFile))
|
||||||
logger.log(Level.WARNING, Util.format("userdataMoveError", filename, sanitizedFilename));
|
{
|
||||||
|
LOGGER.log(Level.WARNING, Util.format("userdataMoveError", filename, sanitizedFilename));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (newFile.exists())
|
if (newFile.exists())
|
||||||
{
|
{
|
||||||
logger.log(Level.WARNING, Util.format("duplicatedUserdata", filename, sanitizedFilename));
|
LOGGER.log(Level.WARNING, Util.format("duplicatedUserdata", filename, sanitizedFilename));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!tmpFile.renameTo(newFile)) {
|
if (!tmpFile.renameTo(newFile))
|
||||||
logger.log(Level.WARNING, Util.format("userdataMoveBackError", sanitizedFilename, sanitizedFilename));
|
{
|
||||||
|
LOGGER.log(Level.WARNING, Util.format("userdataMoveBackError", sanitizedFilename, sanitizedFilename));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
doneFile.setProperty("sanitizeAllUserFilenames", true);
|
||||||
|
doneFile.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
private World getFakeWorld(String name)
|
private World getFakeWorld(final String name)
|
||||||
{
|
{
|
||||||
File bukkitDirectory = ess.getDataFolder().getParentFile().getParentFile();
|
final File bukkitDirectory = ess.getDataFolder().getParentFile().getParentFile();
|
||||||
File worldDirectory = new File(bukkitDirectory, name);
|
final File worldDirectory = new File(bukkitDirectory, name);
|
||||||
if (worldDirectory.exists() && worldDirectory.isDirectory())
|
if (worldDirectory.exists() && worldDirectory.isDirectory())
|
||||||
{
|
{
|
||||||
return new FakeWorld(worldDirectory.getName(), World.Environment.NORMAL);
|
return new FakeWorld(worldDirectory.getName(), World.Environment.NORMAL);
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
package com.earth2me.essentials;
|
package com.earth2me.essentials;
|
||||||
|
|
||||||
import com.earth2me.essentials.register.payment.Methods;
|
import com.earth2me.essentials.register.payment.Methods;
|
||||||
import java.util.Map;
|
|
||||||
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.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import org.bukkit.scheduler.BukkitScheduler;
|
||||||
|
|
||||||
|
|
||||||
public interface IEssentials extends Plugin
|
public interface IEssentials extends Plugin
|
||||||
|
@ -27,7 +26,7 @@ public interface IEssentials extends Plugin
|
||||||
|
|
||||||
ISettings getSettings();
|
ISettings getSettings();
|
||||||
|
|
||||||
CraftScheduler getScheduler();
|
BukkitScheduler getScheduler();
|
||||||
|
|
||||||
String[] getMotd(CommandSender sender, String def);
|
String[] getMotd(CommandSender sender, String def);
|
||||||
|
|
||||||
|
@ -63,7 +62,7 @@ public interface IEssentials extends Plugin
|
||||||
|
|
||||||
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();
|
|
||||||
|
|
||||||
ItemDb getItemDb();
|
ItemDb getItemDb();
|
||||||
|
|
||||||
|
UserMap getUserMap();
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,44 +20,44 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
|
||||||
private final Teleport teleport;
|
private final Teleport teleport;
|
||||||
private long lastActivity;
|
private long lastActivity;
|
||||||
private boolean hidden = false;
|
private boolean hidden = false;
|
||||||
|
|
||||||
User(Player base, IEssentials ess)
|
User(Player base, IEssentials ess)
|
||||||
{
|
{
|
||||||
super(base, ess);
|
super(base, ess);
|
||||||
teleport = new Teleport(this, ess);
|
teleport = new Teleport(this, ess);
|
||||||
}
|
}
|
||||||
|
|
||||||
User update(Player base)
|
User update(Player base)
|
||||||
{
|
{
|
||||||
setBase(base);
|
setBase(base);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAuthorized(IEssentialsCommand cmd)
|
public boolean isAuthorized(IEssentialsCommand cmd)
|
||||||
{
|
{
|
||||||
return isAuthorized(cmd, "essentials.");
|
return isAuthorized(cmd, "essentials.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAuthorized(IEssentialsCommand cmd, String permissionPrefix)
|
public boolean isAuthorized(IEssentialsCommand cmd, String permissionPrefix)
|
||||||
{
|
{
|
||||||
return isAuthorized(permissionPrefix + (cmd.getName().equals("r") ? "msg" : cmd.getName()));
|
return isAuthorized(permissionPrefix + (cmd.getName().equals("r") ? "msg" : cmd.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAuthorized(String node)
|
public boolean isAuthorized(String node)
|
||||||
{
|
{
|
||||||
if (isOp())
|
if (isOp())
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isJailed())
|
if (isJailed())
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ess.getPermissionsHandler().hasPermission(this, node);
|
return ess.getPermissionsHandler().hasPermission(this, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void healCooldown() throws Exception
|
public void healCooldown() throws Exception
|
||||||
{
|
{
|
||||||
Calendar now = new GregorianCalendar();
|
Calendar now = new GregorianCalendar();
|
||||||
|
@ -75,12 +75,12 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
|
||||||
}
|
}
|
||||||
setLastHealTimestamp(now.getTimeInMillis());
|
setLastHealTimestamp(now.getTimeInMillis());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void giveMoney(double value)
|
public void giveMoney(double value)
|
||||||
{
|
{
|
||||||
giveMoney(value, null);
|
giveMoney(value, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void giveMoney(double value, CommandSender initiator)
|
public void giveMoney(double value, CommandSender initiator)
|
||||||
{
|
{
|
||||||
if (value == 0)
|
if (value == 0)
|
||||||
|
@ -94,7 +94,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
|
||||||
initiator.sendMessage((Util.format("addedToOthersAccount", Util.formatCurrency(value, ess), this.getDisplayName())));
|
initiator.sendMessage((Util.format("addedToOthersAccount", Util.formatCurrency(value, ess), this.getDisplayName())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void payUser(User reciever, double value) throws Exception
|
public void payUser(User reciever, double value) throws Exception
|
||||||
{
|
{
|
||||||
if (value == 0)
|
if (value == 0)
|
||||||
|
@ -113,12 +113,12 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
|
||||||
reciever.sendMessage(Util.format("moneyRecievedFrom", Util.formatCurrency(value, ess), getDisplayName()));
|
reciever.sendMessage(Util.format("moneyRecievedFrom", Util.formatCurrency(value, ess), getDisplayName()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void takeMoney(double value)
|
public void takeMoney(double value)
|
||||||
{
|
{
|
||||||
takeMoney(value, null);
|
takeMoney(value, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void takeMoney(double value, CommandSender initiator)
|
public void takeMoney(double value, CommandSender initiator)
|
||||||
{
|
{
|
||||||
if (value == 0)
|
if (value == 0)
|
||||||
|
@ -132,43 +132,43 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
|
||||||
initiator.sendMessage((Util.format("takenFromOthersAccount", Util.formatCurrency(value, ess), this.getDisplayName())));
|
initiator.sendMessage((Util.format("takenFromOthersAccount", Util.formatCurrency(value, ess), this.getDisplayName())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canAfford(double cost)
|
public boolean canAfford(double cost)
|
||||||
{
|
{
|
||||||
double mon = getMoney();
|
double mon = getMoney();
|
||||||
return mon >= cost || isAuthorized("essentials.eco.loan");
|
return mon >= cost || isAuthorized("essentials.eco.loan");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dispose()
|
public void dispose()
|
||||||
{
|
{
|
||||||
this.base = new OfflinePlayer(getName(), ess);
|
this.base = new OfflinePlayer(getName(), ess);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getJustPortaled()
|
public boolean getJustPortaled()
|
||||||
{
|
{
|
||||||
return justPortaled;
|
return justPortaled;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setJustPortaled(boolean value)
|
public void setJustPortaled(boolean value)
|
||||||
{
|
{
|
||||||
justPortaled = value;
|
justPortaled = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setReplyTo(CommandSender user)
|
public void setReplyTo(CommandSender user)
|
||||||
{
|
{
|
||||||
replyTo = user;
|
replyTo = user;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommandSender getReplyTo()
|
public CommandSender getReplyTo()
|
||||||
{
|
{
|
||||||
return replyTo;
|
return replyTo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int compareTo(User t)
|
public int compareTo(User t)
|
||||||
{
|
{
|
||||||
return ChatColor.stripColor(this.getDisplayName()).compareToIgnoreCase(ChatColor.stripColor(t.getDisplayName()));
|
return ChatColor.stripColor(this.getDisplayName()).compareToIgnoreCase(ChatColor.stripColor(t.getDisplayName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o)
|
public boolean equals(Object o)
|
||||||
{
|
{
|
||||||
|
@ -177,51 +177,51 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return ChatColor.stripColor(this.getDisplayName()).equalsIgnoreCase(ChatColor.stripColor(((User)o).getDisplayName()));
|
return ChatColor.stripColor(this.getDisplayName()).equalsIgnoreCase(ChatColor.stripColor(((User)o).getDisplayName()));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode()
|
public int hashCode()
|
||||||
{
|
{
|
||||||
return ChatColor.stripColor(this.getDisplayName()).hashCode();
|
return ChatColor.stripColor(this.getDisplayName()).hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean canSpawnItem(int itemId)
|
public Boolean canSpawnItem(int itemId)
|
||||||
{
|
{
|
||||||
return !ess.getSettings().itemSpawnBlacklist().contains(itemId);
|
return !ess.getSettings().itemSpawnBlacklist().contains(itemId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHome()
|
public void setHome()
|
||||||
{
|
{
|
||||||
setHome(getLocation(), true);
|
setHome(getLocation(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHome(boolean defaultHome)
|
public void setHome(boolean defaultHome)
|
||||||
{
|
{
|
||||||
setHome(getLocation(), defaultHome);
|
setHome(getLocation(), defaultHome);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLastLocation()
|
public void setLastLocation()
|
||||||
{
|
{
|
||||||
setLastLocation(getLocation());
|
setLastLocation(getLocation());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void requestTeleport(User player, boolean here)
|
public void requestTeleport(User player, boolean here)
|
||||||
{
|
{
|
||||||
teleportRequester = player;
|
teleportRequester = player;
|
||||||
teleportRequestHere = here;
|
teleportRequestHere = here;
|
||||||
}
|
}
|
||||||
|
|
||||||
public User getTeleportRequest()
|
public User getTeleportRequest()
|
||||||
{
|
{
|
||||||
return teleportRequester;
|
return teleportRequester;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isTeleportRequestHere()
|
public boolean isTeleportRequestHere()
|
||||||
{
|
{
|
||||||
return teleportRequestHere;
|
return teleportRequestHere;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getNick()
|
public String getNick()
|
||||||
{
|
{
|
||||||
final StringBuilder nickname = new StringBuilder();
|
final StringBuilder nickname = new StringBuilder();
|
||||||
|
@ -245,12 +245,12 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ess.getSettings().addPrefixSuffix())
|
if (ess.getSettings().addPrefixSuffix())
|
||||||
{
|
{
|
||||||
final String prefix = ess.getPermissionsHandler().getPrefix(this).replace('&', '§').replace("{WORLDNAME}", this.getWorld().getName());
|
final String prefix = ess.getPermissionsHandler().getPrefix(this).replace('&', '§').replace("{WORLDNAME}", this.getWorld().getName());
|
||||||
final String suffix = ess.getPermissionsHandler().getSuffix(this).replace('&', '§').replace("{WORLDNAME}", this.getWorld().getName());
|
final String suffix = ess.getPermissionsHandler().getSuffix(this).replace('&', '§').replace("{WORLDNAME}", this.getWorld().getName());
|
||||||
|
|
||||||
nickname.insert(0, prefix);
|
nickname.insert(0, prefix);
|
||||||
nickname.append(suffix);
|
nickname.append(suffix);
|
||||||
if (suffix.length() < 2 || !suffix.substring(suffix.length() - 2, suffix.length() - 1).equals("§"))
|
if (suffix.length() < 2 || !suffix.substring(suffix.length() - 2, suffix.length() - 1).equals("§"))
|
||||||
|
@ -258,25 +258,25 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
|
||||||
nickname.append("§f");
|
nickname.append("§f");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nickname.toString();
|
return nickname.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Teleport getTeleport()
|
public Teleport getTeleport()
|
||||||
{
|
{
|
||||||
return teleport;
|
return teleport;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getLastActivity()
|
public long getLastActivity()
|
||||||
{
|
{
|
||||||
return lastActivity;
|
return lastActivity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLastActivity(long timestamp)
|
public void setLastActivity(long timestamp)
|
||||||
{
|
{
|
||||||
lastActivity = timestamp;
|
lastActivity = timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getMoney()
|
public double getMoney()
|
||||||
{
|
{
|
||||||
|
@ -298,7 +298,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
|
||||||
}
|
}
|
||||||
return super.getMoney();
|
return super.getMoney();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setMoney(double value)
|
public void setMoney(double value)
|
||||||
{
|
{
|
||||||
|
@ -320,14 +320,14 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
|
||||||
}
|
}
|
||||||
super.setMoney(value);
|
super.setMoney(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setAfk(boolean set)
|
public void setAfk(boolean set)
|
||||||
{
|
{
|
||||||
this.setSleepingIgnored(this.isAuthorized("essentials.sleepingignored") ? true : set);
|
this.setSleepingIgnored(this.isAuthorized("essentials.sleepingignored") ? true : set);
|
||||||
super.setAfk(set);
|
super.setAfk(set);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean toggleAfk()
|
public boolean toggleAfk()
|
||||||
{
|
{
|
||||||
|
@ -335,14 +335,51 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
|
||||||
this.setSleepingIgnored(this.isAuthorized("essentials.sleepingignored") ? true : now);
|
this.setSleepingIgnored(this.isAuthorized("essentials.sleepingignored") ? true : now);
|
||||||
return now;
|
return now;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isHidden()
|
public boolean isHidden()
|
||||||
{
|
{
|
||||||
return hidden;
|
return hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHidden(boolean hidden)
|
public void setHidden(boolean hidden)
|
||||||
{
|
{
|
||||||
this.hidden = hidden;
|
this.hidden = hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void checkJailTimeout(final long currentTime)
|
||||||
|
{
|
||||||
|
if (getJailTimeout() > 0 && getJailTimeout() < currentTime && isJailed())
|
||||||
|
{
|
||||||
|
setJailTimeout(0);
|
||||||
|
setJailed(false);
|
||||||
|
sendMessage(Util.i18n("haveBeenReleased"));
|
||||||
|
setJail(null);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
getTeleport().back();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void checkMuteTimeout(final long currentTime)
|
||||||
|
{
|
||||||
|
if (getMuteTimeout() > 0 && getMuteTimeout() < currentTime && isMuted())
|
||||||
|
{
|
||||||
|
setMuteTimeout(0);
|
||||||
|
sendMessage(Util.i18n("canTalkAgain"));
|
||||||
|
setMuted(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void checkBanTimeout(final long currentTime)
|
||||||
|
{
|
||||||
|
if (getBanTimeout() > 0 && getBanTimeout() < currentTime && ess.getBans().isNameBanned(getName()))
|
||||||
|
{
|
||||||
|
setBanTimeout(0);
|
||||||
|
ess.getBans().unbanByName(getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
107
Essentials/src/com/earth2me/essentials/UserMap.java
Normal file
107
Essentials/src/com/earth2me/essentials/UserMap.java
Normal file
|
@ -0,0 +1,107 @@
|
||||||
|
package com.earth2me.essentials;
|
||||||
|
|
||||||
|
import com.google.common.base.Function;
|
||||||
|
import com.google.common.collect.MapMaker;
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.ConcurrentMap;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
|
||||||
|
public class UserMap implements Function<String, User>, IConf
|
||||||
|
{
|
||||||
|
private final transient IEssentials ess;
|
||||||
|
private final transient ConcurrentMap<String, User> users = new MapMaker().softValues().makeComputingMap(this);
|
||||||
|
|
||||||
|
public UserMap(final IEssentials ess)
|
||||||
|
{
|
||||||
|
this.ess = ess;
|
||||||
|
loadAllUsersAsync(ess);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadAllUsersAsync(final IEssentials ess)
|
||||||
|
{
|
||||||
|
ess.scheduleAsyncDelayedTask(new Runnable()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
final File userdir = new File(ess.getDataFolder(), "userdata");
|
||||||
|
if (!userdir.exists())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (String string : userdir.list())
|
||||||
|
{
|
||||||
|
if (!string.endsWith(".yml"))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
final String name = string.substring(0, string.length() - 4);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
users.get(name.toLowerCase());
|
||||||
|
}
|
||||||
|
catch (NullPointerException ex)
|
||||||
|
{
|
||||||
|
// Ignore these
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean userExists(final String name)
|
||||||
|
{
|
||||||
|
return users.containsKey(name.toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
public User getUser(final String name) throws NullPointerException
|
||||||
|
{
|
||||||
|
return users.get(name.toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public User apply(final String name)
|
||||||
|
{
|
||||||
|
for (Player player : ess.getServer().getOnlinePlayers())
|
||||||
|
{
|
||||||
|
if (player.getName().equalsIgnoreCase(name))
|
||||||
|
{
|
||||||
|
return new User(player, ess);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
final File userFolder = new File(ess.getDataFolder(), "userdata");
|
||||||
|
final File userFile = new File(userFolder, Util.sanitizeFileName(name) + ".yml");
|
||||||
|
if (userFile.exists())
|
||||||
|
{
|
||||||
|
return new User(new OfflinePlayer(name, ess), ess);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reloadConfig()
|
||||||
|
{
|
||||||
|
for (User user : users.values())
|
||||||
|
{
|
||||||
|
user.reloadConfig();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeUser(final String name)
|
||||||
|
{
|
||||||
|
users.remove(name.toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<User> getAllUsers()
|
||||||
|
{
|
||||||
|
final Set<User> userSet = new HashSet<User>();
|
||||||
|
for (String name : users.keySet())
|
||||||
|
{
|
||||||
|
userSet.add(users.get(name));
|
||||||
|
}
|
||||||
|
return userSet;
|
||||||
|
}
|
||||||
|
}
|
|
@ -60,7 +60,7 @@ public final class Economy
|
||||||
{
|
{
|
||||||
logger.log(Level.WARNING, Util.format("deleteFileError", config));
|
logger.log(Level.WARNING, Util.format("deleteFileError", config));
|
||||||
}
|
}
|
||||||
ess.getAllUsers().remove(name.toLowerCase());
|
ess.getUserMap().removeUser(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ public class Commandbalancetop extends EssentialsCommand
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final Map<User, Double> balances = new HashMap<User, Double>();
|
final Map<User, Double> balances = new HashMap<User, Double>();
|
||||||
for (User u : ess.getAllUsers().values())
|
for (User u : ess.getUserMap().getAllUsers())
|
||||||
{
|
{
|
||||||
balances.put(u, u.getMoney());
|
balances.put(u, u.getMoney());
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.earth2me.essentials.commands;
|
package com.earth2me.essentials.commands;
|
||||||
|
|
||||||
|
import com.earth2me.essentials.ChargeException;
|
||||||
import com.earth2me.essentials.Trade;
|
import com.earth2me.essentials.Trade;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
|
@ -15,16 +16,16 @@ import java.util.logging.Logger;
|
||||||
|
|
||||||
public abstract class EssentialsCommand implements IEssentialsCommand
|
public abstract class EssentialsCommand implements IEssentialsCommand
|
||||||
{
|
{
|
||||||
private final String name;
|
private final transient String name;
|
||||||
protected IEssentials ess;
|
protected transient IEssentials ess;
|
||||||
protected final static Logger logger = Logger.getLogger("Minecraft");
|
protected final static Logger logger = Logger.getLogger("Minecraft");
|
||||||
|
|
||||||
protected EssentialsCommand(String name)
|
protected EssentialsCommand(final String name)
|
||||||
{
|
{
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setEssentials(IEssentials ess)
|
public void setEssentials(final IEssentials ess)
|
||||||
{
|
{
|
||||||
this.ess = ess;
|
this.ess = ess;
|
||||||
}
|
}
|
||||||
|
@ -34,74 +35,72 @@ public abstract class EssentialsCommand implements IEssentialsCommand
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected User getPlayer(Server server, String[] args, int pos) throws NoSuchFieldException, NotEnoughArgumentsException
|
protected User getPlayer(final Server server, final String[] args, final int pos) throws NoSuchFieldException, NotEnoughArgumentsException
|
||||||
{
|
{
|
||||||
return getPlayer(server, args, pos, false);
|
return getPlayer(server, args, pos, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected User getPlayer(Server server, String[] args, int pos, boolean getOffline) throws NoSuchFieldException, NotEnoughArgumentsException
|
protected User getPlayer(final Server server, final String[] args, final int pos, final boolean getOffline) throws NoSuchFieldException, NotEnoughArgumentsException
|
||||||
{
|
{
|
||||||
if (args.length <= pos) throw new NotEnoughArgumentsException();
|
if (args.length <= pos)
|
||||||
User user = ess.getAllUsers().get(args[pos].toLowerCase());
|
{
|
||||||
|
throw new NotEnoughArgumentsException();
|
||||||
|
}
|
||||||
|
final User user = ess.getUser(args[pos]);
|
||||||
if (user != null)
|
if (user != null)
|
||||||
{
|
{
|
||||||
if(!getOffline && (user.getBase() instanceof OfflinePlayer || user.isHidden()))
|
if (!getOffline && (user.getBase() instanceof OfflinePlayer || user.isHidden()))
|
||||||
{
|
{
|
||||||
throw new NoSuchFieldException(Util.i18n("playerNotFound"));
|
throw new NoSuchFieldException(Util.i18n("playerNotFound"));
|
||||||
}
|
}
|
||||||
return user;
|
return user;
|
||||||
}
|
|
||||||
List<Player> matches = server.matchPlayer(args[pos]);
|
|
||||||
|
|
||||||
if (matches.size() < 1)
|
|
||||||
{
|
|
||||||
if (!getOffline) throw new NoSuchFieldException(Util.i18n("playerNotFound"));
|
|
||||||
User u = ess.getOfflineUser(args[pos]);
|
|
||||||
if (u == null) throw new NoSuchFieldException(Util.i18n("playerNotFound"));
|
|
||||||
return u;
|
|
||||||
}
|
}
|
||||||
|
final List<Player> matches = server.matchPlayer(args[pos]);
|
||||||
|
|
||||||
for (Player p : matches)
|
if (!matches.isEmpty())
|
||||||
{
|
{
|
||||||
final User u = ess.getUser(p);
|
for (Player player : matches)
|
||||||
if (u.getDisplayName().startsWith(args[pos]) && (getOffline || !u.isHidden()))
|
|
||||||
{
|
{
|
||||||
return u;
|
final User userMatch = ess.getUser(player);
|
||||||
|
if (userMatch.getDisplayName().startsWith(args[pos]) && (getOffline || !userMatch.isHidden()))
|
||||||
|
{
|
||||||
|
return userMatch;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
final User userMatch = ess.getUser(matches.get(0));
|
||||||
|
if (getOffline || !userMatch.isHidden())
|
||||||
|
{
|
||||||
|
return userMatch;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final User u = ess.getUser(matches.get(0));
|
throw new NoSuchFieldException(Util.i18n("playerNotFound"));
|
||||||
if (!getOffline && u.isHidden())
|
|
||||||
{
|
|
||||||
throw new NoSuchFieldException(Util.i18n("playerNotFound"));
|
|
||||||
}
|
|
||||||
return u;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void run(Server server, User user, String commandLabel, Command cmd, String[] args) throws Exception
|
public final void run(final Server server, final User user, final String commandLabel, final Command cmd, final String[] args) throws Exception
|
||||||
{
|
{
|
||||||
run(server, user, commandLabel, args);
|
run(server, user, commandLabel, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void run(Server server, User user, String commandLabel, String[] args) throws Exception
|
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
|
||||||
{
|
{
|
||||||
run(server, (CommandSender)user.getBase(), commandLabel, args);
|
run(server, (CommandSender)user.getBase(), commandLabel, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void run(Server server, CommandSender sender, String commandLabel, Command cmd, String[] args) throws Exception
|
public final void run(final Server server, final CommandSender sender, final String commandLabel, final Command cmd, final String[] args) throws Exception
|
||||||
{
|
{
|
||||||
run(server, sender, commandLabel, args);
|
run(server, sender, commandLabel, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception
|
protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
|
||||||
{
|
{
|
||||||
throw new Exception(Util.format("onlyPlayers", commandLabel));
|
throw new Exception(Util.format("onlyPlayers", commandLabel));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getFinalArg(String[] args, int start)
|
public static String getFinalArg(final String[] args, final int start)
|
||||||
{
|
{
|
||||||
StringBuilder bldr = new StringBuilder();
|
final StringBuilder bldr = new StringBuilder();
|
||||||
for (int i = start; i < args.length; i++)
|
for (int i = start; i < args.length; i++)
|
||||||
{
|
{
|
||||||
if (i != start)
|
if (i != start)
|
||||||
|
@ -113,11 +112,11 @@ public abstract class EssentialsCommand implements IEssentialsCommand
|
||||||
return bldr.toString();
|
return bldr.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void charge(CommandSender sender) throws Exception
|
protected void charge(final CommandSender sender) throws ChargeException
|
||||||
{
|
{
|
||||||
if (sender instanceof Player)
|
if (sender instanceof Player)
|
||||||
{
|
{
|
||||||
Trade charge = new Trade(this.getName(), ess);
|
final Trade charge = new Trade(this.getName(), ess);
|
||||||
charge.charge(ess.getUser((Player)sender));
|
charge.charge(ess.getUser((Player)sender));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,8 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
|
import java.util.concurrent.Future;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
|
@ -15,9 +17,12 @@ import org.bukkit.command.PluginCommand;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.generator.ChunkGenerator;
|
import org.bukkit.generator.ChunkGenerator;
|
||||||
import org.bukkit.inventory.Recipe;
|
import org.bukkit.inventory.Recipe;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.plugin.ServicesManager;
|
import org.bukkit.plugin.ServicesManager;
|
||||||
import org.bukkit.scheduler.BukkitScheduler;
|
import org.bukkit.scheduler.BukkitScheduler;
|
||||||
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
import org.bukkit.scheduler.BukkitWorker;
|
||||||
|
|
||||||
|
|
||||||
public class FakeServer implements Server
|
public class FakeServer implements Server
|
||||||
|
@ -118,7 +123,93 @@ public class FakeServer implements Server
|
||||||
|
|
||||||
public BukkitScheduler getScheduler()
|
public BukkitScheduler getScheduler()
|
||||||
{
|
{
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
return new BukkitScheduler() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int scheduleSyncDelayedTask(Plugin plugin, Runnable r, long l)
|
||||||
|
{
|
||||||
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int scheduleSyncDelayedTask(Plugin plugin, Runnable r)
|
||||||
|
{
|
||||||
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int scheduleSyncRepeatingTask(Plugin plugin, Runnable r, long l, long l1)
|
||||||
|
{
|
||||||
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int scheduleAsyncDelayedTask(Plugin plugin, Runnable r, long l)
|
||||||
|
{
|
||||||
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int scheduleAsyncDelayedTask(Plugin plugin, Runnable r)
|
||||||
|
{
|
||||||
|
r.run();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int scheduleAsyncRepeatingTask(Plugin plugin, Runnable r, long l, long l1)
|
||||||
|
{
|
||||||
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> Future<T> callSyncMethod(Plugin plugin, Callable<T> clbl)
|
||||||
|
{
|
||||||
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void cancelTask(int i)
|
||||||
|
{
|
||||||
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void cancelTasks(Plugin plugin)
|
||||||
|
{
|
||||||
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void cancelAllTasks()
|
||||||
|
{
|
||||||
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCurrentlyRunning(int i)
|
||||||
|
{
|
||||||
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isQueued(int i)
|
||||||
|
{
|
||||||
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<BukkitWorker> getActiveWorkers()
|
||||||
|
{
|
||||||
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<BukkitTask> getPendingTasks()
|
||||||
|
{
|
||||||
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public ServicesManager getServicesManager()
|
public ServicesManager getServicesManager()
|
||||||
|
|
|
@ -33,6 +33,7 @@ public class UserTest extends TestCase
|
||||||
}
|
}
|
||||||
base1 = server.createPlayer("testPlayer1", ess);
|
base1 = server.createPlayer("testPlayer1", ess);
|
||||||
server.addPlayer(base1);
|
server.addPlayer(base1);
|
||||||
|
ess.getUser(base1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void should(String what)
|
private void should(String what)
|
||||||
|
|
Loading…
Reference in a new issue