mirror of
https://github.com/essentials/Essentials.git
synced 2025-09-27 22:59:18 +02:00
More work done on the 3.0 branch
This commit is contained in:
@@ -19,17 +19,12 @@ package com.earth2me.essentials;
|
|||||||
|
|
||||||
import static com.earth2me.essentials.I18n._;
|
import static com.earth2me.essentials.I18n._;
|
||||||
import com.earth2me.essentials.api.*;
|
import com.earth2me.essentials.api.*;
|
||||||
import com.earth2me.essentials.api.IUser;
|
|
||||||
import com.earth2me.essentials.api.ISettings;
|
|
||||||
import com.earth2me.essentials.user.UserMap;
|
|
||||||
import com.earth2me.essentials.craftbukkit.ItemDupeFix;
|
import com.earth2me.essentials.craftbukkit.ItemDupeFix;
|
||||||
import com.earth2me.essentials.listener.*;
|
import com.earth2me.essentials.listener.*;
|
||||||
import com.earth2me.essentials.perm.PermissionsHandler;
|
import com.earth2me.essentials.perm.PermissionsHandler;
|
||||||
import com.earth2me.essentials.register.payment.Methods;
|
import com.earth2me.essentials.register.payment.Methods;
|
||||||
import com.earth2me.essentials.settings.SettingsHolder;
|
import com.earth2me.essentials.settings.SettingsHolder;
|
||||||
import com.earth2me.essentials.signs.SignBlockListener;
|
import com.earth2me.essentials.user.UserMap;
|
||||||
import com.earth2me.essentials.signs.SignEntityListener;
|
|
||||||
import com.earth2me.essentials.signs.SignPlayerListener;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -97,10 +92,10 @@ public class Essentials extends JavaPlugin implements IEssentials
|
|||||||
LOGGER.log(Level.INFO, _("usingTempFolderForTesting"));
|
LOGGER.log(Level.INFO, _("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(this);
|
settings = new SettingsHolder(this);
|
||||||
i18n.updateLocale("en");
|
i18n.updateLocale("en");
|
||||||
userMap = new UserMap(this);
|
userMap = new UserMap(this);
|
||||||
permissionsHandler = new PermissionsHandler(this, false);
|
permissionsHandler = new PermissionsHandler(this);
|
||||||
Economy.setEss(this);
|
Economy.setEss(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,7 +150,7 @@ public class Essentials extends JavaPlugin implements IEssentials
|
|||||||
userMap = new UserMap(this);
|
userMap = new UserMap(this);
|
||||||
reloadList.add(userMap);
|
reloadList.add(userMap);
|
||||||
execTimer.mark("Init(Usermap)");
|
execTimer.mark("Init(Usermap)");
|
||||||
warps = new Warps(getServer(), this.getDataFolder());
|
warps = new Warps(this);
|
||||||
reloadList.add(warps);
|
reloadList.add(warps);
|
||||||
execTimer.mark("Init(Spawn/Warp)");
|
execTimer.mark("Init(Spawn/Warp)");
|
||||||
worth = new Worth(this.getDataFolder());
|
worth = new Worth(this.getDataFolder());
|
||||||
@@ -306,12 +301,7 @@ public class Essentials extends JavaPlugin implements IEssentials
|
|||||||
@Override
|
@Override
|
||||||
public IUser getUser(final String playerName)
|
public IUser getUser(final String playerName)
|
||||||
{
|
{
|
||||||
final User user = userMap.getUser(playerName);
|
return userMap.getUser(playerName);
|
||||||
if (user != null && user.getBase() instanceof OfflinePlayer)
|
|
||||||
{
|
|
||||||
((OfflinePlayer)user.getBase()).setName(name);
|
|
||||||
}
|
|
||||||
return user;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
package com.earth2me.essentials;
|
package com.earth2me.essentials;
|
||||||
|
|
||||||
import com.earth2me.essentials.api.ICommandHandler;
|
import com.earth2me.essentials.api.ICommandHandler;
|
||||||
|
import com.earth2me.essentials.api.ISettings;
|
||||||
import static com.earth2me.essentials.I18n._;
|
import static com.earth2me.essentials.I18n._;
|
||||||
import com.earth2me.essentials.api.IEssentials;
|
import com.earth2me.essentials.api.IEssentials;
|
||||||
import com.earth2me.essentials.api.IEssentialsModule;
|
import com.earth2me.essentials.api.IEssentialsModule;
|
||||||
@@ -61,8 +62,18 @@ public class EssentialsCommandHandler implements ICommandHandler
|
|||||||
@Override
|
@Override
|
||||||
public boolean handleCommand(final CommandSender sender, final Command command, final String commandLabel, final String[] args)
|
public boolean handleCommand(final CommandSender sender, final Command command, final String commandLabel, final String[] args)
|
||||||
{
|
{
|
||||||
|
boolean disabled = false;
|
||||||
|
boolean overridden = false;
|
||||||
|
ISettings settings = ess.getSettings();
|
||||||
|
settings.acquireReadLock();
|
||||||
|
try {
|
||||||
|
disabled = settings.getData().getCommands().isDisabled(command.getName());
|
||||||
|
overridden = !disabled || settings.getData().getCommands().isOverridden(command.getName());
|
||||||
|
} finally {
|
||||||
|
settings.unlock();
|
||||||
|
}
|
||||||
// Allow plugins to override the command via onCommand
|
// Allow plugins to override the command via onCommand
|
||||||
if (!ess.getSettings().isCommandOverridden(command.getName()) && (!commandLabel.startsWith("e") || commandLabel.equalsIgnoreCase(command.getName()))
|
if (!overridden && (!commandLabel.startsWith("e") || commandLabel.equalsIgnoreCase(command.getName())))
|
||||||
{
|
{
|
||||||
final PluginCommand pc = getAlternative(commandLabel);
|
final PluginCommand pc = getAlternative(commandLabel);
|
||||||
if (pc != null)
|
if (pc != null)
|
||||||
@@ -81,18 +92,8 @@ public class EssentialsCommandHandler implements ICommandHandler
|
|||||||
LOGGER.log(Level.INFO, String.format("[PLAYER_COMMAND] %s: /%s %s ", ((Player)sender).getName(), commandLabel, EssentialsCommand.getFinalArg(args, 0)));
|
LOGGER.log(Level.INFO, String.format("[PLAYER_COMMAND] %s: /%s %s ", ((Player)sender).getName(), commandLabel, EssentialsCommand.getFinalArg(args, 0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// New mail notification
|
|
||||||
if (user != null && !ess.getSettings().isCommandDisabled("mail") && !commandLabel.equals("mail") && user.isAuthorized("essentials.mail"))
|
|
||||||
{
|
|
||||||
final List<String> mail = user.getMails();
|
|
||||||
if (mail != null && !mail.isEmpty())
|
|
||||||
{
|
|
||||||
user.sendMessage(_("youHaveNewMail", mail.size()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for disabled commands
|
// Check for disabled commands
|
||||||
if (ess.getSettings().isCommandDisabled(commandLabel))
|
if (disabled)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@@ -1,11 +1,14 @@
|
|||||||
package com.earth2me.essentials;
|
package com.earth2me.essentials;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import static com.earth2me.essentials.I18n._;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Set;
|
|
||||||
import com.earth2me.essentials.api.IEssentials;
|
import com.earth2me.essentials.api.IEssentials;
|
||||||
|
import com.earth2me.essentials.api.ISettings;
|
||||||
import com.earth2me.essentials.api.IUser;
|
import com.earth2me.essentials.api.IUser;
|
||||||
import com.earth2me.essentials.user.UserData.TimestampType;
|
import com.earth2me.essentials.user.UserData.TimestampType;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
|
||||||
@@ -29,6 +32,24 @@ public class EssentialsTimer implements Runnable
|
|||||||
onlineUsers.add(user);
|
onlineUsers.add(user);
|
||||||
user.setLastOnlineActivity(currentTime);
|
user.setLastOnlineActivity(currentTime);
|
||||||
user.checkActivity();
|
user.checkActivity();
|
||||||
|
|
||||||
|
boolean mailDisabled = false;
|
||||||
|
ISettings settings = ess.getSettings();
|
||||||
|
settings.acquireReadLock();
|
||||||
|
try {
|
||||||
|
mailDisabled = settings.getData().getCommands().isDisabled("mail");
|
||||||
|
} finally {
|
||||||
|
settings.unlock();
|
||||||
|
}
|
||||||
|
// New mail notification
|
||||||
|
if (user != null && !mailDisabled && user.isAuthorized("essentials.mail") && !user.gotMailInfo())
|
||||||
|
{
|
||||||
|
final List<String> mail = user.getMails();
|
||||||
|
if (mail != null && !mail.isEmpty())
|
||||||
|
{
|
||||||
|
user.sendMessage(_("youHaveNewMail", mail.size()));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final Iterator<IUser> iterator = onlineUsers.iterator();
|
final Iterator<IUser> iterator = onlineUsers.iterator();
|
||||||
|
@@ -373,7 +373,7 @@ public class EssentialsUpgrade
|
|||||||
doneFile.save();
|
doneFile.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void moveUsersDataToUserdataFolder()
|
/*private void moveUsersDataToUserdataFolder()
|
||||||
{
|
{
|
||||||
final File usersFile = new File(ess.getDataFolder(), "users.yml");
|
final File usersFile = new File(ess.getDataFolder(), "users.yml");
|
||||||
if (!usersFile.exists())
|
if (!usersFile.exists())
|
||||||
@@ -419,7 +419,7 @@ public class EssentialsUpgrade
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
usersFile.renameTo(new File(usersFile.getAbsolutePath() + ".old"));
|
usersFile.renameTo(new File(usersFile.getAbsolutePath() + ".old"));
|
||||||
}
|
}*/
|
||||||
|
|
||||||
private void convertWarps()
|
private void convertWarps()
|
||||||
{
|
{
|
||||||
@@ -562,7 +562,7 @@ public class EssentialsUpgrade
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sanitizeAllUserFilenames()
|
/*private void sanitizeAllUserFilenames()
|
||||||
{
|
{
|
||||||
if (doneFile.getBoolean("sanitizeAllUserFilenames", false))
|
if (doneFile.getBoolean("sanitizeAllUserFilenames", false))
|
||||||
{
|
{
|
||||||
@@ -605,7 +605,7 @@ public class EssentialsUpgrade
|
|||||||
}
|
}
|
||||||
doneFile.setProperty("sanitizeAllUserFilenames", true);
|
doneFile.setProperty("sanitizeAllUserFilenames", true);
|
||||||
doneFile.save();
|
doneFile.save();
|
||||||
}
|
}*/
|
||||||
|
|
||||||
private World getFakeWorld(final String name)
|
private World getFakeWorld(final String name)
|
||||||
{
|
{
|
||||||
@@ -792,9 +792,10 @@ public class EssentialsUpgrade
|
|||||||
|
|
||||||
public void afterSettings()
|
public void afterSettings()
|
||||||
{
|
{
|
||||||
sanitizeAllUserFilenames();
|
//TODO?
|
||||||
|
//sanitizeAllUserFilenames();
|
||||||
updateUsersToNewDefaultHome();
|
updateUsersToNewDefaultHome();
|
||||||
moveUsersDataToUserdataFolder();
|
//moveUsersDataToUserdataFolder();
|
||||||
convertWarps();
|
convertWarps();
|
||||||
updateUsersPowerToolsFormat();
|
updateUsersPowerToolsFormat();
|
||||||
updateUsersHomesFormat();
|
updateUsersHomesFormat();
|
||||||
|
@@ -7,7 +7,7 @@ import java.util.Set;
|
|||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.event.Event.Priority;
|
import org.bukkit.event.Event.Priority;
|
||||||
|
|
||||||
@Deprecated
|
/*@Deprecated
|
||||||
public interface ISettings extends com.earth2me.essentials.api.ISettings
|
public interface ISettings extends com.earth2me.essentials.api.ISettings
|
||||||
{
|
{
|
||||||
boolean areSignsDisabled();
|
boolean areSignsDisabled();
|
||||||
@@ -153,4 +153,4 @@ public interface ISettings extends com.earth2me.essentials.api.ISettings
|
|||||||
public Priority getRespawnPriority();
|
public Priority getRespawnPriority();
|
||||||
|
|
||||||
long getTpaAcceptCancellation();
|
long getTpaAcceptCancellation();
|
||||||
}
|
}*/
|
||||||
|
@@ -10,7 +10,7 @@ import org.bukkit.inventory.PlayerInventory;
|
|||||||
/**
|
/**
|
||||||
* @deprecated This will be moved to the api package soon
|
* @deprecated This will be moved to the api package soon
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
/*@Deprecated
|
||||||
public interface IUser extends Player, com.earth2me.essentials.api.IUser
|
public interface IUser extends Player, com.earth2me.essentials.api.IUser
|
||||||
{
|
{
|
||||||
long getLastTeleportTimestamp();
|
long getLastTeleportTimestamp();
|
||||||
@@ -46,4 +46,4 @@ public interface IUser extends Player, com.earth2me.essentials.api.IUser
|
|||||||
Teleport getTeleport();
|
Teleport getTeleport();
|
||||||
|
|
||||||
void setJail(String jail);
|
void setJail(String jail);
|
||||||
}
|
}*/
|
||||||
|
@@ -23,7 +23,7 @@ import org.bukkit.plugin.Plugin;
|
|||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
|
||||||
public class OfflinePlayer implements Player
|
/*public class OfflinePlayer implements Player
|
||||||
{
|
{
|
||||||
private final transient IEssentials ess;
|
private final transient IEssentials ess;
|
||||||
private transient Location location = new Location(null, 0, 0, 0, 0, 0);
|
private transient Location location = new Location(null, 0, 0, 0, 0, 0);
|
||||||
@@ -830,3 +830,4 @@ public class OfflinePlayer implements Player
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
@@ -11,7 +11,7 @@ import org.bukkit.permissions.Permissible;
|
|||||||
import org.bukkit.permissions.ServerOperator;
|
import org.bukkit.permissions.ServerOperator;
|
||||||
|
|
||||||
|
|
||||||
public class PlayerExtension implements Player
|
/*public class PlayerExtension implements Player
|
||||||
{
|
{
|
||||||
@Delegate(types =
|
@Delegate(types =
|
||||||
{
|
{
|
||||||
@@ -35,4 +35,4 @@ public class PlayerExtension implements Player
|
|||||||
{
|
{
|
||||||
return this.base = base;
|
return this.base = base;
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
@@ -11,7 +11,7 @@ import org.bukkit.event.Event.Priority;
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
|
||||||
public class Settings implements ISettings
|
/*public class Settings implements ISettings
|
||||||
{
|
{
|
||||||
private final transient EssentialsConf config;
|
private final transient EssentialsConf config;
|
||||||
private final static Logger logger = Logger.getLogger("Minecraft");
|
private final static Logger logger = Logger.getLogger("Minecraft");
|
||||||
@@ -643,3 +643,4 @@ public class Settings implements ISettings
|
|||||||
throw new UnsupportedOperationException("Not supported yet.");
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
@@ -14,7 +14,7 @@ import org.bukkit.Location;
|
|||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@Deprecated
|
/*@Deprecated
|
||||||
public class User extends UserData implements Comparable<User>, IReplyTo, IUser
|
public class User extends UserData implements Comparable<User>, IReplyTo, IUser
|
||||||
{
|
{
|
||||||
private CommandSender replyTo = null;
|
private CommandSender replyTo = null;
|
||||||
@@ -594,4 +594,4 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
|
|||||||
{
|
{
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
@@ -8,7 +8,7 @@ import org.bukkit.Material;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
@Deprecated
|
/*@Deprecated
|
||||||
public abstract class UserData extends PlayerExtension implements IConf
|
public abstract class UserData extends PlayerExtension implements IConf
|
||||||
{
|
{
|
||||||
protected final transient IEssentials ess;
|
protected final transient IEssentials ess;
|
||||||
@@ -872,4 +872,4 @@ public abstract class UserData extends PlayerExtension implements IConf
|
|||||||
{
|
{
|
||||||
config.save();
|
config.save();
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
@@ -13,7 +13,7 @@ import java.util.concurrent.ConcurrentSkipListSet;
|
|||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@Deprecated
|
/*@Deprecated
|
||||||
public class UserMap extends CacheLoader<String, User> implements IConf, IUserMap
|
public class UserMap extends CacheLoader<String, User> implements IConf, IUserMap
|
||||||
{
|
{
|
||||||
private final transient IEssentials ess;
|
private final transient IEssentials ess;
|
||||||
@@ -128,4 +128,4 @@ public class UserMap extends CacheLoader<String, User> implements IConf, IUserMa
|
|||||||
{
|
{
|
||||||
loadAllUsersAsync(ess);
|
loadAllUsersAsync(ess);
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
@@ -3,9 +3,13 @@ package com.earth2me.essentials;
|
|||||||
import static com.earth2me.essentials.I18n._;
|
import static com.earth2me.essentials.I18n._;
|
||||||
import com.earth2me.essentials.api.IEssentials;
|
import com.earth2me.essentials.api.IEssentials;
|
||||||
import com.earth2me.essentials.api.ISettings;
|
import com.earth2me.essentials.api.ISettings;
|
||||||
|
import com.earth2me.essentials.api.InvalidNameException;
|
||||||
|
import com.earth2me.essentials.external.gnu.inet.encoding.Punycode;
|
||||||
|
import com.earth2me.essentials.external.gnu.inet.encoding.PunycodeException;
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
import java.text.DecimalFormatSymbols;
|
import java.text.DecimalFormatSymbols;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
@@ -28,10 +32,55 @@ public final class Util
|
|||||||
}
|
}
|
||||||
private final static Logger logger = Logger.getLogger("Minecraft");
|
private final static Logger logger = Logger.getLogger("Minecraft");
|
||||||
private static Pattern unsafeChars = Pattern.compile("[^a-z0-9]");
|
private static Pattern unsafeChars = Pattern.compile("[^a-z0-9]");
|
||||||
|
private static Pattern unsafeFileChars = Pattern.compile("[\u0000-\u001f]+");
|
||||||
|
|
||||||
public static String sanitizeFileName(String name)
|
public static String sanitizeFileName(String name) throws InvalidNameException
|
||||||
{
|
{
|
||||||
return unsafeChars.matcher(name.toLowerCase(Locale.ENGLISH)).replaceAll("_");
|
try
|
||||||
|
{
|
||||||
|
String r = name.toLowerCase(Locale.ENGLISH);
|
||||||
|
r = r.replace('.', (char)('\ue200'+'.'));
|
||||||
|
r = r.replace('\\', (char)('\ue200'+'\\'));
|
||||||
|
r = r.replace('/', (char)('\ue200'+'/'));
|
||||||
|
r = r.replace('"', (char)('\ue200'+'"'));
|
||||||
|
r = r.replace('<', (char)('\ue200'+'<'));
|
||||||
|
r = r.replace('>', (char)('\ue200'+'>'));
|
||||||
|
r = r.replace('|', (char)('\ue200'+'|'));
|
||||||
|
r = r.replace('?', (char)('\ue200'+'?'));
|
||||||
|
r = r.replace('*', (char)('\ue200'+'*'));
|
||||||
|
r = r.replace(':', (char)('\ue200'+':'));
|
||||||
|
r = r.replace('-', (char)('\ue200'+'-'));
|
||||||
|
r = unsafeFileChars.matcher(r).replaceAll("");
|
||||||
|
return Punycode.encode(r);
|
||||||
|
}
|
||||||
|
catch (PunycodeException ex)
|
||||||
|
{
|
||||||
|
throw new InvalidNameException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String decodeFileName(String name) throws InvalidNameException
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
String r = Punycode.decode(name);
|
||||||
|
r = r.replace((char)('\ue200'+'.'), '.');
|
||||||
|
r = r.replace((char)('\ue200'+'\\'), '\\');
|
||||||
|
r = r.replace((char)('\ue200'+'/'), '/');
|
||||||
|
r = r.replace((char)('\ue200'+'"'), '"');
|
||||||
|
r = r.replace((char)('\ue200'+'<'), '<');
|
||||||
|
r = r.replace((char)('\ue200'+'>'), '>');
|
||||||
|
r = r.replace((char)('\ue200'+'|'), '|');
|
||||||
|
r = r.replace((char)('\ue200'+'?'), '?');
|
||||||
|
r = r.replace((char)('\ue200'+'*'), '*');
|
||||||
|
r = r.replace((char)('\ue200'+':'), ':');
|
||||||
|
r = r.replace((char)('\ue200'+'-'), '-');
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
catch (PunycodeException ex)
|
||||||
|
{
|
||||||
|
throw new InvalidNameException(ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String sanitizeKey(String name)
|
public static String sanitizeKey(String name)
|
||||||
|
@@ -1,121 +1,115 @@
|
|||||||
package com.earth2me.essentials;
|
package com.earth2me.essentials;
|
||||||
|
|
||||||
import com.earth2me.essentials.api.IWarps;
|
|
||||||
import static com.earth2me.essentials.I18n._;
|
import static com.earth2me.essentials.I18n._;
|
||||||
|
import com.earth2me.essentials.api.IEssentials;
|
||||||
|
import com.earth2me.essentials.api.IWarp;
|
||||||
|
import com.earth2me.essentials.api.IWarps;
|
||||||
|
import com.earth2me.essentials.api.InvalidNameException;
|
||||||
|
import com.earth2me.essentials.settings.WarpHolder;
|
||||||
|
import com.earth2me.essentials.storage.StorageObjectMap;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Server;
|
|
||||||
|
|
||||||
|
|
||||||
public class Warps implements IWarps
|
public class Warps extends StorageObjectMap<IWarp> implements IWarps
|
||||||
{
|
{
|
||||||
private static final Logger logger = Logger.getLogger("Minecraft");
|
private static final Logger logger = Bukkit.getLogger();
|
||||||
private final Map<StringIgnoreCase, EssentialsConf> warpPoints = new HashMap<StringIgnoreCase, EssentialsConf>();
|
|
||||||
private final File warpsFolder;
|
|
||||||
private final Server server;
|
|
||||||
|
|
||||||
public Warps(Server server, File dataFolder)
|
public Warps(IEssentials ess)
|
||||||
{
|
{
|
||||||
this.server = server;
|
super(ess, "warps");
|
||||||
warpsFolder = new File(dataFolder, "warps");
|
|
||||||
if (!warpsFolder.exists())
|
|
||||||
{
|
|
||||||
warpsFolder.mkdirs();
|
|
||||||
}
|
|
||||||
reloadConfig();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isEmpty()
|
|
||||||
{
|
|
||||||
return warpPoints.isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Collection<String> getWarpNames()
|
|
||||||
{
|
|
||||||
final List<String> keys = new ArrayList<String>();
|
|
||||||
for (StringIgnoreCase stringIgnoreCase : warpPoints.keySet())
|
|
||||||
{
|
|
||||||
keys.add(stringIgnoreCase.getString());
|
|
||||||
}
|
|
||||||
Collections.sort(keys, String.CASE_INSENSITIVE_ORDER);
|
|
||||||
return keys;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Location getWarp(String warp) throws Exception
|
|
||||||
{
|
|
||||||
EssentialsConf conf = warpPoints.get(new StringIgnoreCase(warp));
|
|
||||||
if (conf == null)
|
|
||||||
{
|
|
||||||
throw new Exception(_("warpNotExist"));
|
|
||||||
}
|
|
||||||
return conf.getLocation(null, server);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setWarp(String name, Location loc) throws Exception
|
|
||||||
{
|
|
||||||
String filename = Util.sanitizeFileName(name);
|
|
||||||
EssentialsConf conf = warpPoints.get(new StringIgnoreCase(name));
|
|
||||||
if (conf == null)
|
|
||||||
{
|
|
||||||
File confFile = new File(warpsFolder, filename + ".yml");
|
|
||||||
if (confFile.exists())
|
|
||||||
{
|
|
||||||
throw new Exception(_("similarWarpExist"));
|
|
||||||
}
|
|
||||||
conf = new EssentialsConf(confFile);
|
|
||||||
warpPoints.put(new StringIgnoreCase(name), conf);
|
|
||||||
}
|
|
||||||
conf.setProperty(null, loc);
|
|
||||||
conf.setProperty("name", name);
|
|
||||||
conf.save();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void delWarp(String name) throws Exception
|
|
||||||
{
|
|
||||||
EssentialsConf conf = warpPoints.get(new StringIgnoreCase(name));
|
|
||||||
if (conf == null)
|
|
||||||
{
|
|
||||||
throw new Exception(_("warpNotExist"));
|
|
||||||
}
|
|
||||||
if (!conf.getFile().delete())
|
|
||||||
{
|
|
||||||
throw new Exception(_("warpDeleteError"));
|
|
||||||
}
|
|
||||||
warpPoints.remove(new StringIgnoreCase(name));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void reloadConfig()
|
public boolean isEmpty()
|
||||||
{
|
{
|
||||||
warpPoints.clear();
|
return getKeySize() == 0;
|
||||||
File[] listOfFiles = warpsFolder.listFiles();
|
}
|
||||||
if (listOfFiles.length >= 1)
|
|
||||||
|
@Override
|
||||||
|
public Collection<String> getList()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < listOfFiles.length; i++)
|
final List<String> names = new ArrayList<String>();
|
||||||
|
for (String key : getAllKeys())
|
||||||
{
|
{
|
||||||
String filename = listOfFiles[i].getName();
|
IWarp warp = getObject(key);
|
||||||
if (listOfFiles[i].isFile() && filename.endsWith(".yml"))
|
if (warp == null)
|
||||||
{
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
warp.acquireReadLock();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
EssentialsConf conf = new EssentialsConf(listOfFiles[i]);
|
names.add(warp.getData().getName());
|
||||||
conf.load();
|
}
|
||||||
String name = conf.getString("name");
|
finally
|
||||||
if (name != null)
|
|
||||||
{
|
{
|
||||||
warpPoints.put(new StringIgnoreCase(name), conf);
|
warp.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
Collections.sort(names, String.CASE_INSENSITIVE_ORDER);
|
||||||
|
return names;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Location getWarp(final String name) throws Exception
|
||||||
{
|
{
|
||||||
logger.log(Level.WARNING, _("loadWarpError", filename), ex);
|
IWarp warp = getObject(name);
|
||||||
|
if (warp == null)
|
||||||
|
{
|
||||||
|
throw new Exception(_("warpNotExist"));
|
||||||
|
}
|
||||||
|
warp.acquireReadLock();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return warp.getData().getLocation();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
warp.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setWarp(final String name, final Location loc) throws Exception
|
||||||
|
{
|
||||||
|
IWarp warp = getObject(name);
|
||||||
|
if (warp == null)
|
||||||
|
{
|
||||||
|
warp = new WarpHolder(name, ess);
|
||||||
|
}
|
||||||
|
warp.acquireWriteLock();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
warp.getData().setLocation(loc);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
warp.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeWarp(final String name) throws Exception
|
||||||
|
{
|
||||||
|
removeObject(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public File getWarpFile(String name) throws InvalidNameException
|
||||||
|
{
|
||||||
|
return getStorageFile(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IWarp load(String name) throws Exception
|
||||||
|
{
|
||||||
|
final IWarp warp = new WarpHolder(name, ess);
|
||||||
|
warp.onReload();
|
||||||
|
return warp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -3,9 +3,13 @@ package com.earth2me.essentials.api;
|
|||||||
import com.earth2me.essentials.EssentialsConf;
|
import com.earth2me.essentials.EssentialsConf;
|
||||||
import static com.earth2me.essentials.I18n._;
|
import static com.earth2me.essentials.I18n._;
|
||||||
import com.earth2me.essentials.Util;
|
import com.earth2me.essentials.Util;
|
||||||
|
import com.earth2me.essentials.craftbukkit.DummyOfflinePlayer;
|
||||||
|
import com.earth2me.essentials.user.User;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
import lombok.Cleanup;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
|
||||||
@@ -37,11 +41,28 @@ public final class Economy
|
|||||||
{
|
{
|
||||||
folder.mkdirs();
|
folder.mkdirs();
|
||||||
}
|
}
|
||||||
EssentialsConf npcConfig = new EssentialsConf(new File(folder, Util.sanitizeFileName(name) + ".yml"));
|
double startingBalance = 0;
|
||||||
|
ISettings settings = ess.getSettings();
|
||||||
|
settings.acquireReadLock();
|
||||||
|
try {
|
||||||
|
startingBalance = settings.getData().getEconomy().getStartingBalance();
|
||||||
|
} finally {
|
||||||
|
settings.unlock();
|
||||||
|
}
|
||||||
|
IUser npc = new User(new DummyOfflinePlayer(name), ess);
|
||||||
|
npc.acquireWriteLock();
|
||||||
|
try {
|
||||||
|
npc.getData().setNpc(true);
|
||||||
|
npc.setMoney(startingBalance);
|
||||||
|
} finally {
|
||||||
|
npc.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*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", ess.getSettings().getStartingBalance());
|
npcConfig.setProperty("money", ess.getSettings().getStartingBalance());
|
||||||
npcConfig.save();
|
npcConfig.save();*/
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void deleteNPC(String name)
|
private static void deleteNPC(String name)
|
||||||
@@ -51,17 +72,26 @@ public final class Economy
|
|||||||
{
|
{
|
||||||
folder.mkdirs();
|
folder.mkdirs();
|
||||||
}
|
}
|
||||||
File config = new File(folder, Util.sanitizeFileName(name) + ".yml");
|
IUser user = ess.getUser(name);
|
||||||
EssentialsConf npcConfig = new EssentialsConf(config);
|
if (user != null) {
|
||||||
npcConfig.load();
|
boolean npc = false;
|
||||||
if (npcConfig.hasProperty("npc") && npcConfig.getBoolean("npc", false))
|
user.acquireReadLock();
|
||||||
{
|
try {
|
||||||
if (!config.delete())
|
npc = user.getData().isNpc();
|
||||||
{
|
} finally {
|
||||||
logger.log(Level.WARNING, _("deleteFileError", config));
|
user.unlock();
|
||||||
}
|
}
|
||||||
|
if (npc) {
|
||||||
|
try
|
||||||
|
{
|
||||||
ess.getUserMap().removeUser(name);
|
ess.getUserMap().removeUser(name);
|
||||||
}
|
}
|
||||||
|
catch (InvalidNameException ex)
|
||||||
|
{
|
||||||
|
Bukkit.getLogger().log(Level.INFO, name, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IUser getUserByName(String name)
|
private static IUser getUserByName(String name)
|
||||||
@@ -78,7 +108,7 @@ public final class Economy
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
user = ess.getOfflineUser(name);
|
user = ess.getUser(name);
|
||||||
}
|
}
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
@@ -184,7 +214,15 @@ public final class Economy
|
|||||||
{
|
{
|
||||||
throw new RuntimeException(noCallBeforeLoad);
|
throw new RuntimeException(noCallBeforeLoad);
|
||||||
}
|
}
|
||||||
setMoney(name, ess.getSettings().getStartingBalance());
|
double startingBalance = 0;
|
||||||
|
ISettings settings = ess.getSettings();
|
||||||
|
settings.acquireReadLock();
|
||||||
|
try {
|
||||||
|
startingBalance = settings.getData().getEconomy().getStartingBalance();
|
||||||
|
} finally {
|
||||||
|
settings.unlock();
|
||||||
|
}
|
||||||
|
setMoney(name, startingBalance);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -264,12 +302,14 @@ public final class Economy
|
|||||||
*/
|
*/
|
||||||
public static boolean isNPC(String name) throws UserDoesNotExistException
|
public static boolean isNPC(String name) throws UserDoesNotExistException
|
||||||
{
|
{
|
||||||
|
@Cleanup
|
||||||
IUser user = getUserByName(name);
|
IUser user = getUserByName(name);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
throw new UserDoesNotExistException(name);
|
throw new UserDoesNotExistException(name);
|
||||||
}
|
}
|
||||||
return user.isNPC();
|
user.acquireReadLock();
|
||||||
|
return user.getData().isNpc();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -10,9 +10,11 @@ public interface IGroups extends IStorageObjectHolder<Groups>
|
|||||||
|
|
||||||
double getTeleportCooldown(IUser player);
|
double getTeleportCooldown(IUser player);
|
||||||
|
|
||||||
double getTeleportDelay(final IUser player);
|
double getTeleportDelay(IUser player);
|
||||||
|
|
||||||
String getPrefix(IUser player);
|
String getPrefix(IUser player);
|
||||||
|
|
||||||
String getSuffix(IUser player);
|
String getSuffix(IUser player);
|
||||||
|
|
||||||
|
int getHomeLimit(IUser player);
|
||||||
}
|
}
|
||||||
|
@@ -99,4 +99,8 @@ public interface IUser extends Player, IStorageObjectHolder<UserData>, IReload,
|
|||||||
IUser getTeleportRequester();
|
IUser getTeleportRequester();
|
||||||
|
|
||||||
boolean toggleTeleportEnabled();
|
boolean toggleTeleportEnabled();
|
||||||
|
|
||||||
|
public boolean gotMailInfo();
|
||||||
|
|
||||||
|
public List<String> getMails();
|
||||||
}
|
}
|
||||||
|
@@ -13,11 +13,11 @@ public interface IUserMap extends IReload
|
|||||||
|
|
||||||
IUser getUser(final String playerName);
|
IUser getUser(final String playerName);
|
||||||
|
|
||||||
void removeUser(final String name);
|
void removeUser(final String name) throws InvalidNameException;
|
||||||
|
|
||||||
Set<String> getAllUniqueUsers();
|
Set<String> getAllUniqueUsers();
|
||||||
|
|
||||||
int getUniqueUsers();
|
int getUniqueUsers();
|
||||||
|
|
||||||
File getUserFile(final String name);
|
File getUserFile(final String name) throws InvalidNameException;
|
||||||
}
|
}
|
||||||
|
10
Essentials/src/com/earth2me/essentials/api/IWarp.java
Normal file
10
Essentials/src/com/earth2me/essentials/api/IWarp.java
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package com.earth2me.essentials.api;
|
||||||
|
|
||||||
|
import com.earth2me.essentials.settings.Warp;
|
||||||
|
import com.earth2me.essentials.storage.IStorageObjectHolder;
|
||||||
|
|
||||||
|
|
||||||
|
public interface IWarp extends IStorageObjectHolder<Warp>
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
@@ -1,5 +1,6 @@
|
|||||||
package com.earth2me.essentials.api;
|
package com.earth2me.essentials.api;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
|
||||||
@@ -15,4 +16,6 @@ public interface IWarps extends IReload
|
|||||||
void setWarp(String name, Location loc) throws Exception;
|
void setWarp(String name, Location loc) throws Exception;
|
||||||
|
|
||||||
public boolean isEmpty();
|
public boolean isEmpty();
|
||||||
|
|
||||||
|
public File getWarpFile(String name) throws InvalidNameException;
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,11 @@
|
|||||||
|
package com.earth2me.essentials.api;
|
||||||
|
|
||||||
|
|
||||||
|
public class InvalidNameException extends Exception
|
||||||
|
{
|
||||||
|
|
||||||
|
public InvalidNameException(Throwable thrwbl)
|
||||||
|
{
|
||||||
|
super(thrwbl);
|
||||||
|
}
|
||||||
|
}
|
@@ -1,7 +1,8 @@
|
|||||||
package com.earth2me.essentials.commands;
|
package com.earth2me.essentials.commands;
|
||||||
|
|
||||||
import com.earth2me.essentials.craftbukkit.InventoryWorkaround;
|
import com.earth2me.essentials.api.ISettings;
|
||||||
import com.earth2me.essentials.api.IUser;
|
import com.earth2me.essentials.api.IUser;
|
||||||
|
import com.earth2me.essentials.craftbukkit.InventoryWorkaround;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@@ -32,29 +33,38 @@ public class Commandgive extends EssentialsCommand
|
|||||||
|
|
||||||
final String itemname = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", "");
|
final String itemname = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", "");
|
||||||
if (sender instanceof Player
|
if (sender instanceof Player
|
||||||
&& (ess.getSettings().permissionBasedItemSpawn()
|
&& (!ess.getUser((Player)sender).isAuthorized("essentials.give.item-" + itemname)
|
||||||
? (!ess.getUser(sender).isAuthorized("essentials.give.item-all")
|
&& !ess.getUser((Player)sender).isAuthorized("essentials.give.item-" + stack.getTypeId())))
|
||||||
&& !ess.getUser(sender).isAuthorized("essentials.give.item-" + itemname)
|
|
||||||
&& !ess.getUser(sender).isAuthorized("essentials.give.item-" + stack.getTypeId()))
|
|
||||||
: (!ess.getUser(sender).isAuthorized("essentials.itemspawn.exempt")
|
|
||||||
&& !ess.getUser(sender).canSpawnItem(stack.getTypeId()))))
|
|
||||||
{
|
{
|
||||||
throw new Exception(ChatColor.RED + "You are not allowed to spawn the item " + itemname);
|
throw new Exception(ChatColor.RED + "You are not allowed to spawn the item " + itemname);
|
||||||
}
|
}
|
||||||
|
|
||||||
final User giveTo = getPlayer(server, args, 0);
|
final IUser giveTo = getPlayer(server, args, 0);
|
||||||
|
|
||||||
|
int defaultStackSize = 0;
|
||||||
|
int oversizedStackSize = 0;
|
||||||
|
ISettings settings = ess.getSettings();
|
||||||
|
settings.acquireReadLock();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
defaultStackSize = settings.getData().getGeneral().getDefaultStacksize();
|
||||||
|
oversizedStackSize = settings.getData().getGeneral().getOversizedStacksize();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
settings.unlock();
|
||||||
|
}
|
||||||
if (args.length > 2 && Integer.parseInt(args[2]) > 0)
|
if (args.length > 2 && Integer.parseInt(args[2]) > 0)
|
||||||
{
|
{
|
||||||
stack.setAmount(Integer.parseInt(args[2]));
|
stack.setAmount(Integer.parseInt(args[2]));
|
||||||
}
|
}
|
||||||
else if (ess.getSettings().getDefaultStackSize() > 0)
|
else if (defaultStackSize > 0)
|
||||||
{
|
{
|
||||||
stack.setAmount(ess.getSettings().getDefaultStackSize());
|
stack.setAmount(defaultStackSize);
|
||||||
}
|
}
|
||||||
else if (ess.getSettings().getOversizedStackSize() > 0 && giveTo.isAuthorized("essentials.oversizedstacks"))
|
else if (oversizedStackSize > 0 && giveTo.isAuthorized("essentials.oversizedstacks"))
|
||||||
{
|
{
|
||||||
stack.setAmount(ess.getSettings().getOversizedStackSize());
|
stack.setAmount(oversizedStackSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.length > 3)
|
if (args.length > 3)
|
||||||
@@ -66,7 +76,7 @@ public class Commandgive extends EssentialsCommand
|
|||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final Enchantment enchantment = Commandenchant.getEnchantment(split[0], sender instanceof Player ? ess.getUser(sender) : null);
|
final Enchantment enchantment = Commandenchant.getEnchantment(split[0], sender instanceof Player ? ess.getUser((Player)sender) : null);
|
||||||
int level;
|
int level;
|
||||||
if (split.length > 1)
|
if (split.length > 1)
|
||||||
{
|
{
|
||||||
@@ -89,7 +99,7 @@ public class Commandgive extends EssentialsCommand
|
|||||||
sender.sendMessage(ChatColor.BLUE + "Giving " + stack.getAmount() + " of " + itemName + " to " + giveTo.getDisplayName() + ".");
|
sender.sendMessage(ChatColor.BLUE + "Giving " + stack.getAmount() + " of " + itemName + " to " + giveTo.getDisplayName() + ".");
|
||||||
if (giveTo.isAuthorized("essentials.oversizedstacks"))
|
if (giveTo.isAuthorized("essentials.oversizedstacks"))
|
||||||
{
|
{
|
||||||
InventoryWorkaround.addItem(giveTo.getInventory(), true, ess.getSettings().getOversizedStackSize(), stack);
|
InventoryWorkaround.addItem(giveTo.getInventory(), true, oversizedStackSize, stack);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@@ -1,9 +1,9 @@
|
|||||||
package com.earth2me.essentials.commands;
|
package com.earth2me.essentials.commands;
|
||||||
|
|
||||||
import com.earth2me.essentials.craftbukkit.InventoryWorkaround;
|
|
||||||
import static com.earth2me.essentials.I18n._;
|
import static com.earth2me.essentials.I18n._;
|
||||||
import com.earth2me.essentials.User;
|
import com.earth2me.essentials.api.ISettings;
|
||||||
import com.earth2me.essentials.api.IUser;
|
import com.earth2me.essentials.api.IUser;
|
||||||
|
import com.earth2me.essentials.craftbukkit.InventoryWorkaround;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
@@ -28,27 +28,36 @@ public class Commanditem extends EssentialsCommand
|
|||||||
final ItemStack stack = ess.getItemDb().get(args[0]);
|
final ItemStack stack = ess.getItemDb().get(args[0]);
|
||||||
|
|
||||||
final String itemname = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", "");
|
final String itemname = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", "");
|
||||||
if (ess.getSettings().permissionBasedItemSpawn()
|
if (!user.isAuthorized("essentials.itemspawn.item-" + itemname)
|
||||||
? (!user.isAuthorized("essentials.itemspawn.item-all")
|
|
||||||
&& !user.isAuthorized("essentials.itemspawn.item-" + itemname)
|
|
||||||
&& !user.isAuthorized("essentials.itemspawn.item-" + stack.getTypeId()))
|
&& !user.isAuthorized("essentials.itemspawn.item-" + stack.getTypeId()))
|
||||||
: (!user.isAuthorized("essentials.itemspawn.exempt")
|
|
||||||
&& !user.canSpawnItem(stack.getTypeId())))
|
|
||||||
{
|
{
|
||||||
throw new Exception(_("cantSpawnItem", itemname));
|
throw new Exception(_("cantSpawnItem", itemname));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int defaultStackSize = 0;
|
||||||
|
int oversizedStackSize = 0;
|
||||||
|
ISettings settings = ess.getSettings();
|
||||||
|
settings.acquireReadLock();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
defaultStackSize = settings.getData().getGeneral().getDefaultStacksize();
|
||||||
|
oversizedStackSize = settings.getData().getGeneral().getOversizedStacksize();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
settings.unlock();
|
||||||
|
}
|
||||||
if (args.length > 1 && Integer.parseInt(args[1]) > 0)
|
if (args.length > 1 && Integer.parseInt(args[1]) > 0)
|
||||||
{
|
{
|
||||||
stack.setAmount(Integer.parseInt(args[1]));
|
stack.setAmount(Integer.parseInt(args[1]));
|
||||||
}
|
}
|
||||||
else if (ess.getSettings().getDefaultStackSize() > 0)
|
else if (defaultStackSize > 0)
|
||||||
{
|
{
|
||||||
stack.setAmount(ess.getSettings().getDefaultStackSize());
|
stack.setAmount(defaultStackSize);
|
||||||
}
|
}
|
||||||
else if (ess.getSettings().getOversizedStackSize() > 0 && user.isAuthorized("essentials.oversizedstacks"))
|
else if (oversizedStackSize > 0 && user.isAuthorized("essentials.oversizedstacks"))
|
||||||
{
|
{
|
||||||
stack.setAmount(ess.getSettings().getOversizedStackSize());
|
stack.setAmount(oversizedStackSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.length > 2)
|
if (args.length > 2)
|
||||||
@@ -83,7 +92,7 @@ public class Commanditem extends EssentialsCommand
|
|||||||
user.sendMessage(_("itemSpawn", stack.getAmount(), displayName));
|
user.sendMessage(_("itemSpawn", stack.getAmount(), displayName));
|
||||||
if (user.isAuthorized("essentials.oversizedstacks"))
|
if (user.isAuthorized("essentials.oversizedstacks"))
|
||||||
{
|
{
|
||||||
InventoryWorkaround.addItem(user.getInventory(), true, ess.getSettings().getOversizedStackSize(), stack);
|
InventoryWorkaround.addItem(user.getInventory(), true, oversizedStackSize, stack);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
package com.earth2me.essentials.commands;
|
package com.earth2me.essentials.commands;
|
||||||
|
|
||||||
import static com.earth2me.essentials.I18n._;
|
import static com.earth2me.essentials.I18n._;
|
||||||
|
import com.earth2me.essentials.api.ISettings;
|
||||||
import com.earth2me.essentials.api.IUser;
|
import com.earth2me.essentials.api.IUser;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
@@ -50,7 +51,16 @@ public class Commandlist extends EssentialsCommand
|
|||||||
}
|
}
|
||||||
sender.sendMessage(online);
|
sender.sendMessage(online);
|
||||||
|
|
||||||
if (ess.getSettings().getSortListByGroups())
|
boolean sortListByGroups = false;
|
||||||
|
ISettings settings = ess.getSettings();
|
||||||
|
settings.acquireReadLock();
|
||||||
|
try {
|
||||||
|
sortListByGroups = settings.getData().getCommands().getList().isSortByGroups();
|
||||||
|
} finally {
|
||||||
|
settings.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sortListByGroups)
|
||||||
{
|
{
|
||||||
Map<String, List<IUser>> sort = new HashMap<String, List<IUser>>();
|
Map<String, List<IUser>> sort = new HashMap<String, List<IUser>>();
|
||||||
for (Player OnlinePlayer : server.getOnlinePlayers())
|
for (Player OnlinePlayer : server.getOnlinePlayers())
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
package com.earth2me.essentials.commands;
|
package com.earth2me.essentials.commands;
|
||||||
|
|
||||||
import static com.earth2me.essentials.I18n._;
|
import static com.earth2me.essentials.I18n._;
|
||||||
|
import com.earth2me.essentials.api.ISettings;
|
||||||
import com.earth2me.essentials.api.IUser;
|
import com.earth2me.essentials.api.IUser;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
@@ -22,28 +23,38 @@ public class Commandmore extends EssentialsCommand
|
|||||||
{
|
{
|
||||||
throw new Exception(_("cantSpawnItem", "Air"));
|
throw new Exception(_("cantSpawnItem", "Air"));
|
||||||
}
|
}
|
||||||
|
int defaultStackSize = 0;
|
||||||
|
int oversizedStackSize = 0;
|
||||||
|
ISettings settings = ess.getSettings();
|
||||||
|
settings.acquireReadLock();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
defaultStackSize = settings.getData().getGeneral().getDefaultStacksize();
|
||||||
|
oversizedStackSize = settings.getData().getGeneral().getOversizedStacksize();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
settings.unlock();
|
||||||
|
}
|
||||||
if (stack.getAmount() >= ((user.isAuthorized("essentials.oversizedstacks"))
|
if (stack.getAmount() >= ((user.isAuthorized("essentials.oversizedstacks"))
|
||||||
? ess.getSettings().getOversizedStackSize() : stack.getMaxStackSize()))
|
? oversizedStackSize
|
||||||
|
: defaultStackSize > 0 ? defaultStackSize : stack.getMaxStackSize()))
|
||||||
{
|
{
|
||||||
throw new NoChargeException();
|
throw new NoChargeException();
|
||||||
}
|
}
|
||||||
final String itemname = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", "");
|
final String itemname = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", "");
|
||||||
if (ess.getSettings().permissionBasedItemSpawn()
|
if (!user.isAuthorized("essentials.itemspawn.item-" + itemname)
|
||||||
? (!user.isAuthorized("essentials.itemspawn.item-all")
|
|
||||||
&& !user.isAuthorized("essentials.itemspawn.item-" + itemname)
|
|
||||||
&& !user.isAuthorized("essentials.itemspawn.item-" + stack.getTypeId()))
|
&& !user.isAuthorized("essentials.itemspawn.item-" + stack.getTypeId()))
|
||||||
: (!user.isAuthorized("essentials.itemspawn.exempt")
|
|
||||||
&& !user.canSpawnItem(stack.getTypeId())))
|
|
||||||
{
|
{
|
||||||
throw new Exception(_("cantSpawnItem", itemname));
|
throw new Exception(_("cantSpawnItem", itemname));
|
||||||
}
|
}
|
||||||
if (user.isAuthorized("essentials.oversizedstacks"))
|
if (user.isAuthorized("essentials.oversizedstacks"))
|
||||||
{
|
{
|
||||||
stack.setAmount(ess.getSettings().getOversizedStackSize());
|
stack.setAmount(oversizedStackSize);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
stack.setAmount(stack.getMaxStackSize());
|
stack.setAmount(defaultStackSize > 0 ? defaultStackSize : stack.getMaxStackSize());
|
||||||
}
|
}
|
||||||
user.updateInventory();
|
user.updateInventory();
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
package com.earth2me.essentials.commands;
|
package com.earth2me.essentials.commands;
|
||||||
|
|
||||||
import com.earth2me.essentials.api.ISettings;
|
|
||||||
import static com.earth2me.essentials.I18n._;
|
import static com.earth2me.essentials.I18n._;
|
||||||
|
import com.earth2me.essentials.api.ISettings;
|
||||||
import com.earth2me.essentials.api.IUser;
|
import com.earth2me.essentials.api.IUser;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import lombok.Cleanup;
|
import lombok.Cleanup;
|
||||||
|
@@ -35,7 +35,6 @@ public class Commandrepair extends EssentialsCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!item.getEnchantments().isEmpty()
|
if (!item.getEnchantments().isEmpty()
|
||||||
&& !ess.getSettings().getRepairEnchanted()
|
|
||||||
&& !user.isAuthorized("essentials.repair.enchanted"))
|
&& !user.isAuthorized("essentials.repair.enchanted"))
|
||||||
{
|
{
|
||||||
throw new Exception(_("repairEnchanted"));
|
throw new Exception(_("repairEnchanted"));
|
||||||
@@ -114,7 +113,6 @@ public class Commandrepair extends EssentialsCommand
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!item.getEnchantments().isEmpty()
|
if (!item.getEnchantments().isEmpty()
|
||||||
&& !ess.getSettings().getRepairEnchanted()
|
|
||||||
&& !user.isAuthorized("essentials.repair.enchanted"))
|
&& !user.isAuthorized("essentials.repair.enchanted"))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
|
@@ -1,10 +1,10 @@
|
|||||||
package com.earth2me.essentials.commands;
|
package com.earth2me.essentials.commands;
|
||||||
|
|
||||||
import static com.earth2me.essentials.I18n._;
|
import static com.earth2me.essentials.I18n._;
|
||||||
import com.earth2me.essentials.craftbukkit.InventoryWorkaround;
|
|
||||||
import com.earth2me.essentials.Trade;
|
import com.earth2me.essentials.Trade;
|
||||||
import com.earth2me.essentials.api.IUser;
|
|
||||||
import com.earth2me.essentials.Util;
|
import com.earth2me.essentials.Util;
|
||||||
|
import com.earth2me.essentials.api.IUser;
|
||||||
|
import com.earth2me.essentials.craftbukkit.InventoryWorkaround;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@@ -92,16 +92,11 @@ public class Commandsell extends EssentialsCommand
|
|||||||
}
|
}
|
||||||
double worth = ess.getWorth().getPrice(is);
|
double worth = ess.getWorth().getPrice(is);
|
||||||
boolean stack = args.length > 1 && args[1].endsWith("s");
|
boolean stack = args.length > 1 && args[1].endsWith("s");
|
||||||
boolean requireStack = ess.getSettings().isTradeInStacks(id);
|
|
||||||
|
|
||||||
if (Double.isNaN(worth))
|
if (Double.isNaN(worth))
|
||||||
{
|
{
|
||||||
throw new Exception(_("itemCannotBeSold"));
|
throw new Exception(_("itemCannotBeSold"));
|
||||||
}
|
}
|
||||||
if (requireStack && !stack)
|
|
||||||
{
|
|
||||||
throw new Exception(_("itemMustBeStacked"));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int max = 0;
|
int max = 0;
|
||||||
@@ -135,10 +130,6 @@ public class Commandsell extends EssentialsCommand
|
|||||||
amount += max;
|
amount += max;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (requireStack)
|
|
||||||
{
|
|
||||||
amount -= amount % is.getType().getMaxStackSize();
|
|
||||||
}
|
|
||||||
if (amount > max || amount < 1)
|
if (amount > max || amount < 1)
|
||||||
{
|
{
|
||||||
if (!isBulkSell)
|
if (!isBulkSell)
|
||||||
|
@@ -2,7 +2,10 @@ package com.earth2me.essentials.commands;
|
|||||||
|
|
||||||
import static com.earth2me.essentials.I18n._;
|
import static com.earth2me.essentials.I18n._;
|
||||||
import com.earth2me.essentials.api.IUser;
|
import com.earth2me.essentials.api.IUser;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import lombok.Cleanup;
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
|
|
||||||
|
|
||||||
@@ -29,14 +32,19 @@ public class Commandsethome extends EssentialsCommand
|
|||||||
{
|
{
|
||||||
if (user.isAuthorized("essentials.sethome.multiple"))
|
if (user.isAuthorized("essentials.sethome.multiple"))
|
||||||
{
|
{
|
||||||
if ((user.isAuthorized("essentials.sethome.multiple.unlimited")) || (user.getHomes().size() < ess.getSettings().getHomeLimit(user))
|
if ((user.isAuthorized("essentials.sethome.multiple.unlimited")) || (user.getHomes().size() < ess.getGroups().getHomeLimit(user))
|
||||||
|| (user.getHomes().contains(args[0].toLowerCase(Locale.ENGLISH))))
|
|| (user.getHomes().contains(args[0].toLowerCase(Locale.ENGLISH))))
|
||||||
{
|
{
|
||||||
user.setHome(args[0].toLowerCase(Locale.ENGLISH));
|
user.acquireWriteLock();
|
||||||
|
if (user.getData().getHomes() == null)
|
||||||
|
{
|
||||||
|
user.getData().setHomes(new HashMap<String, Location>());
|
||||||
|
}
|
||||||
|
user.getData().getHomes().put(args[0].toLowerCase(Locale.ENGLISH), user.getLocation());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw new Exception(_("maxHomes", ess.getSettings().getHomeLimit(user)));
|
throw new Exception(_("maxHomes", ess.getGroups().getHomeLimit(user)));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -49,11 +57,8 @@ public class Commandsethome extends EssentialsCommand
|
|||||||
{
|
{
|
||||||
if (user.isAuthorized("essentials.sethome.others"))
|
if (user.isAuthorized("essentials.sethome.others"))
|
||||||
{
|
{
|
||||||
User usersHome = ess.getUser(ess.getServer().getPlayer(args[0]));
|
@Cleanup
|
||||||
if (usersHome == null)
|
IUser usersHome = ess.getUser(ess.getServer().getPlayer(args[0]));
|
||||||
{
|
|
||||||
usersHome = ess.getOfflineUser(args[0]);
|
|
||||||
}
|
|
||||||
if (usersHome == null)
|
if (usersHome == null)
|
||||||
{
|
{
|
||||||
throw new Exception(_("playerNotFound"));
|
throw new Exception(_("playerNotFound"));
|
||||||
@@ -63,13 +68,24 @@ public class Commandsethome extends EssentialsCommand
|
|||||||
{
|
{
|
||||||
name = "home";
|
name = "home";
|
||||||
}
|
}
|
||||||
usersHome.setHome(name, user.getLocation());
|
|
||||||
|
usersHome.acquireWriteLock();
|
||||||
|
if (usersHome.getData().getHomes() == null)
|
||||||
|
{
|
||||||
|
usersHome.getData().setHomes(new HashMap<String, Location>());
|
||||||
|
}
|
||||||
|
usersHome.getData().getHomes().put(name, user.getLocation());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
user.setHome();
|
user.acquireWriteLock();
|
||||||
|
if (user.getData().getHomes() == null)
|
||||||
|
{
|
||||||
|
user.getData().setHomes(new HashMap<String, Location>());
|
||||||
|
}
|
||||||
|
user.getData().getHomes().put("home", user.getLocation());
|
||||||
}
|
}
|
||||||
user.sendMessage(_("homeSet"));
|
user.sendMessage(_("homeSet"));
|
||||||
|
|
||||||
|
@@ -54,14 +54,12 @@ public class Commandworld extends EssentialsCommand
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ess.getSettings().getIsWorldTeleportPermissions())
|
|
||||||
{
|
|
||||||
if (!user.isAuthorized("essentials.world." + world.getName()))
|
if (!user.isAuthorized("essentials.world." + world.getName()))
|
||||||
{
|
{
|
||||||
user.sendMessage(_("invalidWorld")); //TODO: Make a "world teleport denied" translation
|
user.sendMessage(_("invalidWorld")); //TODO: Make a "world teleport denied" translation
|
||||||
throw new NoChargeException();
|
throw new NoChargeException();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
double factor;
|
double factor;
|
||||||
if (user.getWorld().getEnvironment() == World.Environment.NETHER && world.getEnvironment() == World.Environment.NORMAL)
|
if (user.getWorld().getEnvironment() == World.Environment.NETHER && world.getEnvironment() == World.Environment.NORMAL)
|
||||||
|
@@ -1,10 +1,9 @@
|
|||||||
package com.earth2me.essentials.commands;
|
package com.earth2me.essentials.commands;
|
||||||
|
|
||||||
import static com.earth2me.essentials.I18n._;
|
import static com.earth2me.essentials.I18n._;
|
||||||
|
import com.earth2me.essentials.Trade;
|
||||||
import com.earth2me.essentials.api.IEssentials;
|
import com.earth2me.essentials.api.IEssentials;
|
||||||
import com.earth2me.essentials.api.IEssentialsModule;
|
import com.earth2me.essentials.api.IEssentialsModule;
|
||||||
import com.earth2me.essentials.OfflinePlayer;
|
|
||||||
import com.earth2me.essentials.Trade;
|
|
||||||
import com.earth2me.essentials.api.IUser;
|
import com.earth2me.essentials.api.IUser;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
@@ -62,7 +61,7 @@ public abstract class EssentialsCommand implements IEssentialsCommand
|
|||||||
final IUser user = ess.getUser(args[pos]);
|
final IUser user = ess.getUser(args[pos]);
|
||||||
if (user != null)
|
if (user != null)
|
||||||
{
|
{
|
||||||
if (!getOffline && (user.getBase() instanceof OfflinePlayer || user.isHidden()))
|
if (!getOffline && (!user.isOnline() || user.isHidden()))
|
||||||
{
|
{
|
||||||
throw new NoSuchFieldException(_("playerNotFound"));
|
throw new NoSuchFieldException(_("playerNotFound"));
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,93 @@
|
|||||||
|
package com.earth2me.essentials.craftbukkit;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
|
||||||
|
public class DummyOfflinePlayer implements OfflinePlayer
|
||||||
|
{
|
||||||
|
private final transient String name;
|
||||||
|
|
||||||
|
public DummyOfflinePlayer(String name)
|
||||||
|
{
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isOnline()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName()
|
||||||
|
{
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isBanned()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setBanned(boolean bln)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isWhitelisted()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setWhitelisted(boolean bln)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Player getPlayer()
|
||||||
|
{
|
||||||
|
return Bukkit.getPlayerExact(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getFirstPlayed()
|
||||||
|
{
|
||||||
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getLastPlayed()
|
||||||
|
{
|
||||||
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasPlayedBefore()
|
||||||
|
{
|
||||||
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isOp()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setOp(boolean bln)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> serialize()
|
||||||
|
{
|
||||||
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
321
Essentials/src/com/earth2me/essentials/external/gnu/inet/encoding/Punycode.java
vendored
Normal file
321
Essentials/src/com/earth2me/essentials/external/gnu/inet/encoding/Punycode.java
vendored
Normal file
@@ -0,0 +1,321 @@
|
|||||||
|
package com.earth2me.essentials.external.gnu.inet.encoding;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
|
||||||
|
* Foundation, Inc.
|
||||||
|
*
|
||||||
|
* Author: Oliver Hitz
|
||||||
|
*
|
||||||
|
* This file is part of GNU Libidn.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2.1 of
|
||||||
|
* the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||||
|
* USA
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* This class offers static methods for encoding/decoding strings
|
||||||
|
* using the Punycode algorithm.
|
||||||
|
* <ul>
|
||||||
|
* <li>RFC3492 Punycode
|
||||||
|
* </ul>
|
||||||
|
* Note that this implementation only supports 16-bit Unicode code
|
||||||
|
* points.
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* Changes by snowleo:
|
||||||
|
* - Correctly catch wrong characters after the delimiter
|
||||||
|
* - If the string starts with the delimiter, it's an encoded string
|
||||||
|
* - If there is no delimiter, it's an ascii string.
|
||||||
|
* - Note: the string should never contain the delimiter.
|
||||||
|
*/
|
||||||
|
public class Punycode
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Punycode parameters
|
||||||
|
*/
|
||||||
|
final static int TMIN = 1;
|
||||||
|
final static int TMAX = 26;
|
||||||
|
final static int BASE = 36;
|
||||||
|
final static int INITIAL_N = 128;
|
||||||
|
final static int INITIAL_BIAS = 72;
|
||||||
|
final static int DAMP = 700;
|
||||||
|
final static int SKEW = 38;
|
||||||
|
final static char DELIMITER = '-';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Punycodes a unicode string.
|
||||||
|
*
|
||||||
|
* @param input Unicode string.
|
||||||
|
* @return Punycoded string.
|
||||||
|
*/
|
||||||
|
public static String encode(String input)
|
||||||
|
throws PunycodeException
|
||||||
|
{
|
||||||
|
int n = INITIAL_N;
|
||||||
|
int delta = 0;
|
||||||
|
int bias = INITIAL_BIAS;
|
||||||
|
StringBuffer output = new StringBuffer();
|
||||||
|
|
||||||
|
// Copy all basic code points to the output
|
||||||
|
int b = 0;
|
||||||
|
for (int i = 0; i < input.length(); i++)
|
||||||
|
{
|
||||||
|
char c = input.charAt(i);
|
||||||
|
if (isBasic(c))
|
||||||
|
{
|
||||||
|
output.append(c);
|
||||||
|
b++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Append delimiter
|
||||||
|
if (b < input.length()) // Changed by snowleo
|
||||||
|
{
|
||||||
|
output.append(DELIMITER);
|
||||||
|
}
|
||||||
|
|
||||||
|
int h = b;
|
||||||
|
while (h < input.length())
|
||||||
|
{
|
||||||
|
int m = Integer.MAX_VALUE;
|
||||||
|
|
||||||
|
// Find the minimum code point >= n
|
||||||
|
for (int i = 0; i < input.length(); i++)
|
||||||
|
{
|
||||||
|
int c = input.charAt(i);
|
||||||
|
if (c >= n && c < m)
|
||||||
|
{
|
||||||
|
m = c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m - n > (Integer.MAX_VALUE - delta) / (h + 1))
|
||||||
|
{
|
||||||
|
throw new PunycodeException(PunycodeException.OVERFLOW);
|
||||||
|
}
|
||||||
|
delta = delta + (m - n) * (h + 1);
|
||||||
|
n = m;
|
||||||
|
|
||||||
|
for (int j = 0; j < input.length(); j++)
|
||||||
|
{
|
||||||
|
int c = input.charAt(j);
|
||||||
|
if (c < n)
|
||||||
|
{
|
||||||
|
delta++;
|
||||||
|
if (0 == delta)
|
||||||
|
{
|
||||||
|
throw new PunycodeException(PunycodeException.OVERFLOW);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (c == n)
|
||||||
|
{
|
||||||
|
int q = delta;
|
||||||
|
|
||||||
|
for (int k = BASE;; k += BASE)
|
||||||
|
{
|
||||||
|
int t;
|
||||||
|
if (k <= bias)
|
||||||
|
{
|
||||||
|
t = TMIN;
|
||||||
|
}
|
||||||
|
else if (k >= bias + TMAX)
|
||||||
|
{
|
||||||
|
t = TMAX;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
t = k - bias;
|
||||||
|
}
|
||||||
|
if (q < t)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
output.append((char)digit2codepoint(t + (q - t) % (BASE - t)));
|
||||||
|
q = (q - t) / (BASE - t);
|
||||||
|
}
|
||||||
|
|
||||||
|
output.append((char)digit2codepoint(q));
|
||||||
|
bias = adapt(delta, h + 1, h == b);
|
||||||
|
delta = 0;
|
||||||
|
h++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
delta++;
|
||||||
|
n++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return output.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decode a punycoded string.
|
||||||
|
*
|
||||||
|
* @param input Punycode string
|
||||||
|
* @return Unicode string.
|
||||||
|
*/
|
||||||
|
public static String decode(String input)
|
||||||
|
throws PunycodeException
|
||||||
|
{
|
||||||
|
int n = INITIAL_N;
|
||||||
|
int i = 0;
|
||||||
|
int bias = INITIAL_BIAS;
|
||||||
|
StringBuffer output = new StringBuffer();
|
||||||
|
|
||||||
|
int d = input.lastIndexOf(DELIMITER);
|
||||||
|
// Change start by snowleo
|
||||||
|
if (d < 0) {
|
||||||
|
return input;
|
||||||
|
}
|
||||||
|
else if (d > 0) // Change end by snowleo
|
||||||
|
{
|
||||||
|
for (int j = 0; j < d; j++)
|
||||||
|
{
|
||||||
|
char c = input.charAt(j);
|
||||||
|
if (!isBasic(c))
|
||||||
|
{
|
||||||
|
throw new PunycodeException(PunycodeException.BAD_INPUT);
|
||||||
|
}
|
||||||
|
output.append(c);
|
||||||
|
}
|
||||||
|
d++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
d = 1; // Changed by snowleo
|
||||||
|
}
|
||||||
|
|
||||||
|
while (d < input.length())
|
||||||
|
{
|
||||||
|
int oldi = i;
|
||||||
|
int w = 1;
|
||||||
|
|
||||||
|
for (int k = BASE;; k += BASE)
|
||||||
|
{
|
||||||
|
if (d == input.length())
|
||||||
|
{
|
||||||
|
throw new PunycodeException(PunycodeException.BAD_INPUT);
|
||||||
|
}
|
||||||
|
int c = input.charAt(d++);
|
||||||
|
int digit = codepoint2digit(c);
|
||||||
|
if (digit > (Integer.MAX_VALUE - i) / w)
|
||||||
|
{
|
||||||
|
throw new PunycodeException(PunycodeException.OVERFLOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
i = i + digit * w;
|
||||||
|
|
||||||
|
int t;
|
||||||
|
if (k <= bias)
|
||||||
|
{
|
||||||
|
t = TMIN;
|
||||||
|
}
|
||||||
|
else if (k >= bias + TMAX)
|
||||||
|
{
|
||||||
|
t = TMAX;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
t = k - bias;
|
||||||
|
}
|
||||||
|
if (digit < t)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
w = w * (BASE - t);
|
||||||
|
}
|
||||||
|
|
||||||
|
bias = adapt(i - oldi, output.length() + 1, oldi == 0);
|
||||||
|
|
||||||
|
if (i / (output.length() + 1) > Integer.MAX_VALUE - n)
|
||||||
|
{
|
||||||
|
throw new PunycodeException(PunycodeException.OVERFLOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
n = n + i / (output.length() + 1);
|
||||||
|
i = i % (output.length() + 1);
|
||||||
|
output.insert(i, (char)n);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return output.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public final static int adapt(int delta, int numpoints, boolean first)
|
||||||
|
{
|
||||||
|
if (first)
|
||||||
|
{
|
||||||
|
delta = delta / DAMP;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
delta = delta / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
delta = delta + (delta / numpoints);
|
||||||
|
|
||||||
|
int k = 0;
|
||||||
|
while (delta > ((BASE - TMIN) * TMAX) / 2)
|
||||||
|
{
|
||||||
|
delta = delta / (BASE - TMIN);
|
||||||
|
k = k + BASE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return k + ((BASE - TMIN + 1) * delta) / (delta + SKEW);
|
||||||
|
}
|
||||||
|
|
||||||
|
public final static boolean isBasic(char c)
|
||||||
|
{
|
||||||
|
return c < 0x80;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final static int digit2codepoint(int d)
|
||||||
|
throws PunycodeException
|
||||||
|
{
|
||||||
|
if (d < 26)
|
||||||
|
{
|
||||||
|
// 0..25 : 'a'..'z'
|
||||||
|
return d + 'a';
|
||||||
|
}
|
||||||
|
else if (d < 36)
|
||||||
|
{
|
||||||
|
// 26..35 : '0'..'9';
|
||||||
|
return d - 26 + '0';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new PunycodeException(PunycodeException.BAD_INPUT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public final static int codepoint2digit(int c)
|
||||||
|
throws PunycodeException
|
||||||
|
{
|
||||||
|
if (c - '0' < 10 && c >= '0') // Changed by snowleo
|
||||||
|
{
|
||||||
|
// '0'..'9' : 26..35
|
||||||
|
return c - '0' + 26;
|
||||||
|
}
|
||||||
|
else if (c - 'a' < 26 && c >= 'a') // Changed by snowleo
|
||||||
|
{
|
||||||
|
// 'a'..'z' : 0..25
|
||||||
|
return c - 'a';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new PunycodeException(PunycodeException.BAD_INPUT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
45
Essentials/src/com/earth2me/essentials/external/gnu/inet/encoding/PunycodeException.java
vendored
Normal file
45
Essentials/src/com/earth2me/essentials/external/gnu/inet/encoding/PunycodeException.java
vendored
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
package com.earth2me.essentials.external.gnu.inet.encoding;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
|
||||||
|
* Foundation, Inc.
|
||||||
|
*
|
||||||
|
* Author: Oliver Hitz
|
||||||
|
*
|
||||||
|
* This file is part of GNU Libidn.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2.1 of
|
||||||
|
* the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||||
|
* USA
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* Exception handling for Punycode class.
|
||||||
|
*/
|
||||||
|
public class PunycodeException
|
||||||
|
extends Exception
|
||||||
|
{
|
||||||
|
public static String OVERFLOW = "Overflow.";
|
||||||
|
public static String BAD_INPUT = "Bad input.";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new PunycodeException.
|
||||||
|
*
|
||||||
|
* @param m message.
|
||||||
|
*/
|
||||||
|
public PunycodeException(String m)
|
||||||
|
{
|
||||||
|
super(m);
|
||||||
|
}
|
||||||
|
}
|
@@ -6,7 +6,7 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
|
||||||
public class ConfigPermissionsHandler extends AbstractPermissionsHandler
|
/*public class ConfigPermissionsHandler extends AbstractPermissionsHandler
|
||||||
{
|
{
|
||||||
private final transient IEssentials ess;
|
private final transient IEssentials ess;
|
||||||
|
|
||||||
@@ -58,4 +58,4 @@ public class ConfigPermissionsHandler extends AbstractPermissionsHandler
|
|||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
@@ -15,18 +15,18 @@ public class PermissionsHandler implements IPermissionsHandler
|
|||||||
private transient String defaultGroup = "default";
|
private transient String defaultGroup = "default";
|
||||||
private final transient Plugin plugin;
|
private final transient Plugin plugin;
|
||||||
private final static Logger LOGGER = Logger.getLogger("Minecraft");
|
private final static Logger LOGGER = Logger.getLogger("Minecraft");
|
||||||
private transient boolean useSuperperms = false;
|
//private transient boolean useSuperperms = false;
|
||||||
|
|
||||||
public PermissionsHandler(final Plugin plugin)
|
public PermissionsHandler(final Plugin plugin)
|
||||||
{
|
{
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PermissionsHandler(final Plugin plugin, final boolean useSuperperms)
|
/*public PermissionsHandler(final Plugin plugin, final boolean useSuperperms)
|
||||||
{
|
{
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.useSuperperms = useSuperperms;
|
this.useSuperperms = useSuperperms;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
public PermissionsHandler(final Plugin plugin, final String defaultGroup)
|
public PermissionsHandler(final Plugin plugin, final String defaultGroup)
|
||||||
{
|
{
|
||||||
@@ -167,14 +167,14 @@ public class PermissionsHandler implements IPermissionsHandler
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (useSuperperms)
|
//if (useSuperperms)
|
||||||
{
|
//{
|
||||||
if (!(handler instanceof SuperpermsHandler))
|
if (!(handler instanceof SuperpermsHandler))
|
||||||
{
|
{
|
||||||
LOGGER.log(Level.INFO, "Essentials: Using superperms based permissions.");
|
LOGGER.log(Level.INFO, "Essentials: Using superperms based permissions.");
|
||||||
handler = new SuperpermsHandler();
|
handler = new SuperpermsHandler();
|
||||||
}
|
}
|
||||||
}
|
/*}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!(handler instanceof ConfigPermissionsHandler))
|
if (!(handler instanceof ConfigPermissionsHandler))
|
||||||
@@ -182,11 +182,11 @@ public class PermissionsHandler implements IPermissionsHandler
|
|||||||
LOGGER.log(Level.INFO, "Essentials: Using config based permissions. Enable superperms in config.");
|
LOGGER.log(Level.INFO, "Essentials: Using config based permissions. Enable superperms in config.");
|
||||||
handler = new ConfigPermissionsHandler(plugin);
|
handler = new ConfigPermissionsHandler(plugin);
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUseSuperperms(final boolean useSuperperms)
|
/*public void setUseSuperperms(final boolean useSuperperms)
|
||||||
{
|
{
|
||||||
this.useSuperperms = useSuperperms;
|
this.useSuperperms = useSuperperms;
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
@@ -21,6 +21,7 @@ public class Commands implements StorageObject
|
|||||||
private Home home = new Home();
|
private Home home = new Home();
|
||||||
private Kit kit = new Kit();
|
private Kit kit = new Kit();
|
||||||
private Lightning lightning = new Lightning();
|
private Lightning lightning = new Lightning();
|
||||||
|
private com.earth2me.essentials.settings.commands.List list = new com.earth2me.essentials.settings.commands.List();
|
||||||
private Spawnmob spawnmob = new Spawnmob();
|
private Spawnmob spawnmob = new Spawnmob();
|
||||||
@ListType
|
@ListType
|
||||||
@Comment(
|
@Comment(
|
||||||
@@ -34,7 +35,7 @@ public class Commands implements StorageObject
|
|||||||
"We should try to take priority over /god. If this doesn't work, use /essentials:god or /egod.",
|
"We should try to take priority over /god. If this doesn't work, use /essentials:god or /egod.",
|
||||||
"If god is set using WorldGuard, use /ungod to remove then use whichever you see fit."
|
"If god is set using WorldGuard, use /ungod to remove then use whichever you see fit."
|
||||||
})
|
})
|
||||||
private List<String> overwritten = new ArrayList<String>();
|
private List<String> overridden = new ArrayList<String>();
|
||||||
@ListType
|
@ListType
|
||||||
@Comment("Disabled commands will be completelly unavailable on the server.")
|
@Comment("Disabled commands will be completelly unavailable on the server.")
|
||||||
private List<String> disabled = new ArrayList<String>();
|
private List<String> disabled = new ArrayList<String>();
|
||||||
@@ -54,4 +55,20 @@ public class Commands implements StorageObject
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isOverridden(final String commandName)
|
||||||
|
{
|
||||||
|
if (overridden == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (String overriddenCommand : overridden)
|
||||||
|
{
|
||||||
|
if (commandName.equalsIgnoreCase(overriddenCommand))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -40,6 +40,7 @@ public class Economy implements StorageObject
|
|||||||
@Comment("Enable this to log all interactions with trade/buy/sell signs and sell command")
|
@Comment("Enable this to log all interactions with trade/buy/sell signs and sell command")
|
||||||
private boolean logEnabled = false;
|
private boolean logEnabled = false;
|
||||||
private Worth worth = new Worth();
|
private Worth worth = new Worth();
|
||||||
|
private boolean tradeInStacks = false;
|
||||||
|
|
||||||
public double getCommandCost(String command)
|
public double getCommandCost(String command)
|
||||||
{
|
{
|
||||||
|
@@ -30,4 +30,18 @@ public class General implements StorageObject
|
|||||||
"If not, set to ''"
|
"If not, set to ''"
|
||||||
})
|
})
|
||||||
private String newPlayerAnnouncement = "&dWelcome {DISPLAYNAME} to the server!";
|
private String newPlayerAnnouncement = "&dWelcome {DISPLAYNAME} to the server!";
|
||||||
|
@Comment(
|
||||||
|
{
|
||||||
|
"The number of items given, if the quantity parameter is left out in /item or /give.",
|
||||||
|
"If this number is below 1, the maximum stack size size is given. If oversized stacks",
|
||||||
|
"is not enabled, any number higher then the maximum stack size results in more than one stack."
|
||||||
|
})
|
||||||
|
private int defaultStacksize = -1;
|
||||||
|
@Comment(
|
||||||
|
{
|
||||||
|
"Oversized stacks are stacks that ignore the normal max stacksize.",
|
||||||
|
"They can be obtained using /give and /item, if the player has essentials.oversizedstacks permission.",
|
||||||
|
"How many items should be in a oversized stack?"
|
||||||
|
})
|
||||||
|
private int oversizedStacksize = 64;
|
||||||
}
|
}
|
||||||
|
@@ -134,4 +134,17 @@ public class GroupsHolder extends AsyncStorageObjectHolder<Groups> implements IG
|
|||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getHomeLimit(final IUser player)
|
||||||
|
{
|
||||||
|
for (GroupOptions groupOptions : getGroups(player))
|
||||||
|
{
|
||||||
|
if (groupOptions.getHomes() != null)
|
||||||
|
{
|
||||||
|
return groupOptions.getHomes();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
14
Essentials/src/com/earth2me/essentials/settings/Warp.java
Normal file
14
Essentials/src/com/earth2me/essentials/settings/Warp.java
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
package com.earth2me.essentials.settings;
|
||||||
|
|
||||||
|
import com.earth2me.essentials.storage.StorageObject;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
public class Warp implements StorageObject
|
||||||
|
{
|
||||||
|
private String name;
|
||||||
|
private Location location;
|
||||||
|
}
|
@@ -0,0 +1,36 @@
|
|||||||
|
package com.earth2me.essentials.settings;
|
||||||
|
|
||||||
|
import com.earth2me.essentials.api.IEssentials;
|
||||||
|
import com.earth2me.essentials.api.IWarp;
|
||||||
|
import com.earth2me.essentials.api.InvalidNameException;
|
||||||
|
import com.earth2me.essentials.storage.AsyncStorageObjectHolder;
|
||||||
|
import com.earth2me.essentials.storage.StorageObject;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
|
||||||
|
public class WarpHolder extends AsyncStorageObjectHolder<Warp> implements IWarp
|
||||||
|
{
|
||||||
|
private final String name;
|
||||||
|
|
||||||
|
public WarpHolder(String name, IEssentials ess)
|
||||||
|
{
|
||||||
|
super(ess, Warp.class);
|
||||||
|
this.name = name;
|
||||||
|
onReload();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public File getStorageFile() throws IOException
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return ess.getWarps().getWarpFile(name);
|
||||||
|
}
|
||||||
|
catch (InvalidNameException ex)
|
||||||
|
{
|
||||||
|
throw new IOException(ex.getMessage(), ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,16 @@
|
|||||||
|
package com.earth2me.essentials.settings.commands;
|
||||||
|
|
||||||
|
|
||||||
|
import com.earth2me.essentials.storage.Comment;
|
||||||
|
import com.earth2me.essentials.storage.StorageObject;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
public class List implements StorageObject
|
||||||
|
{
|
||||||
|
@Comment("Sort output of /list command by groups")
|
||||||
|
private boolean sortByGroups = true;
|
||||||
|
}
|
@@ -5,6 +5,7 @@ import java.io.File;
|
|||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
@@ -12,24 +13,37 @@ import org.bukkit.plugin.Plugin;
|
|||||||
|
|
||||||
public abstract class AbstractDelayedYamlFileReader<T extends StorageObject> implements Runnable
|
public abstract class AbstractDelayedYamlFileReader<T extends StorageObject> implements Runnable
|
||||||
{
|
{
|
||||||
private final transient File file;
|
|
||||||
private final transient Class<T> clazz;
|
private final transient Class<T> clazz;
|
||||||
private final transient Plugin plugin;
|
private final transient Plugin plugin;
|
||||||
|
private final transient ReentrantLock lock = new ReentrantLock();
|
||||||
|
|
||||||
public AbstractDelayedYamlFileReader(final IEssentials ess, final File file, final Class<T> clazz)
|
public AbstractDelayedYamlFileReader(final IEssentials ess, final Class<T> clazz)
|
||||||
{
|
{
|
||||||
this.file = file;
|
|
||||||
this.clazz = clazz;
|
this.clazz = clazz;
|
||||||
this.plugin = ess;
|
this.plugin = ess;
|
||||||
ess.scheduleAsyncDelayedTask(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void onStart();
|
public void schedule(boolean instant)
|
||||||
|
{
|
||||||
|
if (instant)
|
||||||
|
{
|
||||||
|
run();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
plugin.getServer().getScheduler().scheduleAsyncDelayedTask(plugin, this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract File onStart() throws IOException;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
onStart();
|
lock.lock();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
final File file = onStart();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
final FileReader reader = new FileReader(file);
|
final FileReader reader = new FileReader(file);
|
||||||
@@ -59,7 +73,18 @@ public abstract class AbstractDelayedYamlFileReader<T extends StorageObject> imp
|
|||||||
catch (ObjectLoadException ex)
|
catch (ObjectLoadException ex)
|
||||||
{
|
{
|
||||||
onException();
|
onException();
|
||||||
Bukkit.getLogger().log(Level.SEVERE, "File broken: " + file.toString(), ex.getCause());
|
File broken = new File(file.getAbsolutePath() + ".broken." + System.currentTimeMillis());
|
||||||
|
file.renameTo(broken);
|
||||||
|
Bukkit.getLogger().log(Level.SEVERE, "The file " + file.toString() + " is broken, it has been renamed to " + broken.toString(), ex.getCause());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (IOException ex)
|
||||||
|
{
|
||||||
|
Bukkit.getLogger().log(Level.SEVERE, "File could not be opened: " + ex.getMessage(), ex);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
lock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -3,27 +3,41 @@ package com.earth2me.essentials.storage;
|
|||||||
import com.earth2me.essentials.api.IEssentials;
|
import com.earth2me.essentials.api.IEssentials;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
|
||||||
public abstract class AbstractDelayedYamlFileWriter implements Runnable
|
public abstract class AbstractDelayedYamlFileWriter implements Runnable
|
||||||
{
|
{
|
||||||
private final transient File file;
|
private final transient Plugin plugin;
|
||||||
|
private final transient ReentrantLock lock = new ReentrantLock();
|
||||||
|
|
||||||
public AbstractDelayedYamlFileWriter(IEssentials ess, File file)
|
public AbstractDelayedYamlFileWriter(IEssentials ess)
|
||||||
{
|
{
|
||||||
this.file = file;
|
this.plugin = ess;
|
||||||
ess.scheduleAsyncDelayedTask(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void schedule()
|
||||||
|
{
|
||||||
|
plugin.getServer().getScheduler().scheduleAsyncDelayedTask(plugin, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract File getFile() throws IOException;
|
||||||
|
|
||||||
public abstract StorageObject getObject();
|
public abstract StorageObject getObject();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
|
lock.lock();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
final File file = getFile();
|
||||||
PrintWriter pw = null;
|
PrintWriter pw = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -48,7 +62,15 @@ public abstract class AbstractDelayedYamlFileWriter implements Runnable
|
|||||||
pw.close();
|
pw.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
catch (IOException ex)
|
||||||
|
{
|
||||||
|
Bukkit.getLogger().log(Level.SEVERE, ex.getMessage(), ex);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
lock.unlock();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void onFinish();
|
public abstract void onFinish();
|
||||||
|
@@ -2,6 +2,8 @@ package com.earth2me.essentials.storage;
|
|||||||
|
|
||||||
import com.earth2me.essentials.api.IEssentials;
|
import com.earth2me.essentials.api.IEssentials;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@@ -13,6 +15,9 @@ public abstract class AsyncStorageObjectHolder<T extends StorageObject> implemen
|
|||||||
private final transient ReentrantReadWriteLock rwl = new ReentrantReadWriteLock();
|
private final transient ReentrantReadWriteLock rwl = new ReentrantReadWriteLock();
|
||||||
private final transient Class<T> clazz;
|
private final transient Class<T> clazz;
|
||||||
protected final transient IEssentials ess;
|
protected final transient IEssentials ess;
|
||||||
|
private final transient StorageObjectDataWriter writer = new StorageObjectDataWriter();
|
||||||
|
private final transient StorageObjectDataReader reader = new StorageObjectDataReader();
|
||||||
|
private final transient AtomicBoolean loaded = new AtomicBoolean(false);
|
||||||
|
|
||||||
public AsyncStorageObjectHolder(final IEssentials ess, final Class<T> clazz)
|
public AsyncStorageObjectHolder(final IEssentials ess, final Class<T> clazz)
|
||||||
{
|
{
|
||||||
@@ -34,16 +39,23 @@ public abstract class AsyncStorageObjectHolder<T extends StorageObject> implemen
|
|||||||
*
|
*
|
||||||
* @return Object storing all the data
|
* @return Object storing all the data
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public T getData()
|
public T getData()
|
||||||
{
|
{
|
||||||
|
if (!loaded.get())
|
||||||
|
{
|
||||||
|
reader.schedule(true);
|
||||||
|
}
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void acquireReadLock()
|
public void acquireReadLock()
|
||||||
{
|
{
|
||||||
rwl.readLock().lock();
|
rwl.readLock().lock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void acquireWriteLock()
|
public void acquireWriteLock()
|
||||||
{
|
{
|
||||||
while (rwl.getReadHoldCount() > 0)
|
while (rwl.getReadHoldCount() > 0)
|
||||||
@@ -54,17 +66,19 @@ public abstract class AsyncStorageObjectHolder<T extends StorageObject> implemen
|
|||||||
rwl.readLock().lock();
|
rwl.readLock().lock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void close()
|
public void close()
|
||||||
{
|
{
|
||||||
unlock();
|
unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void unlock()
|
public void unlock()
|
||||||
{
|
{
|
||||||
if (rwl.isWriteLockedByCurrentThread())
|
if (rwl.isWriteLockedByCurrentThread())
|
||||||
{
|
{
|
||||||
rwl.writeLock().unlock();
|
rwl.writeLock().unlock();
|
||||||
new StorageObjectDataWriter();
|
writer.schedule();
|
||||||
}
|
}
|
||||||
while (rwl.getReadHoldCount() > 0)
|
while (rwl.getReadHoldCount() > 0)
|
||||||
{
|
{
|
||||||
@@ -75,17 +89,23 @@ public abstract class AsyncStorageObjectHolder<T extends StorageObject> implemen
|
|||||||
@Override
|
@Override
|
||||||
public void onReload()
|
public void onReload()
|
||||||
{
|
{
|
||||||
new StorageObjectDataReader();
|
reader.schedule(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract File getStorageFile();
|
public abstract File getStorageFile() throws IOException;
|
||||||
|
|
||||||
|
|
||||||
private class StorageObjectDataWriter extends AbstractDelayedYamlFileWriter
|
private class StorageObjectDataWriter extends AbstractDelayedYamlFileWriter
|
||||||
{
|
{
|
||||||
public StorageObjectDataWriter()
|
public StorageObjectDataWriter()
|
||||||
{
|
{
|
||||||
super(ess, getStorageFile());
|
super(ess);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public File getFile() throws IOException
|
||||||
|
{
|
||||||
|
return getStorageFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -107,13 +127,15 @@ public abstract class AsyncStorageObjectHolder<T extends StorageObject> implemen
|
|||||||
{
|
{
|
||||||
public StorageObjectDataReader()
|
public StorageObjectDataReader()
|
||||||
{
|
{
|
||||||
super(ess, getStorageFile(), clazz);
|
super(ess, clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStart()
|
public File onStart() throws IOException
|
||||||
{
|
{
|
||||||
|
final File file = getStorageFile();
|
||||||
rwl.writeLock().lock();
|
rwl.writeLock().lock();
|
||||||
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -124,6 +146,7 @@ public abstract class AsyncStorageObjectHolder<T extends StorageObject> implemen
|
|||||||
data = object;
|
data = object;
|
||||||
}
|
}
|
||||||
rwl.writeLock().unlock();
|
rwl.writeLock().unlock();
|
||||||
|
loaded.set(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -141,6 +164,7 @@ public abstract class AsyncStorageObjectHolder<T extends StorageObject> implemen
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
rwl.writeLock().unlock();
|
rwl.writeLock().unlock();
|
||||||
|
loaded.set(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,24 @@
|
|||||||
|
|
||||||
|
package com.earth2me.essentials.storage;
|
||||||
|
|
||||||
|
import com.earth2me.essentials.api.IReload;
|
||||||
|
import com.earth2me.essentials.api.InvalidNameException;
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
interface IStorageObjectMap<I> extends IReload
|
||||||
|
{
|
||||||
|
boolean objectExists(final String name);
|
||||||
|
|
||||||
|
I getObject(final String name);
|
||||||
|
|
||||||
|
void removeObject(final String name) throws InvalidNameException;
|
||||||
|
|
||||||
|
Set<String> getAllKeys();
|
||||||
|
|
||||||
|
int getKeySize();
|
||||||
|
|
||||||
|
File getStorageFile(final String name) throws InvalidNameException;
|
||||||
|
}
|
@@ -0,0 +1,137 @@
|
|||||||
|
package com.earth2me.essentials.storage;
|
||||||
|
|
||||||
|
import com.earth2me.essentials.Util;
|
||||||
|
import com.earth2me.essentials.api.IEssentials;
|
||||||
|
import com.earth2me.essentials.api.InvalidNameException;
|
||||||
|
import com.google.common.cache.Cache;
|
||||||
|
import com.google.common.cache.CacheBuilder;
|
||||||
|
import com.google.common.cache.CacheLoader;
|
||||||
|
import com.google.common.util.concurrent.UncheckedExecutionException;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.ConcurrentSkipListSet;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
|
|
||||||
|
public abstract class StorageObjectMap<I> extends CacheLoader<String, I> implements IStorageObjectMap<I>
|
||||||
|
{
|
||||||
|
protected final transient IEssentials ess;
|
||||||
|
private final transient File folder;
|
||||||
|
protected final transient Cache<String, I> cache = CacheBuilder.newBuilder().softValues().build(this);
|
||||||
|
protected final transient ConcurrentSkipListSet<String> keys = new ConcurrentSkipListSet<String>();
|
||||||
|
|
||||||
|
public StorageObjectMap(final IEssentials ess, final String folderName)
|
||||||
|
{
|
||||||
|
super();
|
||||||
|
this.ess = ess;
|
||||||
|
this.folder = new File(ess.getDataFolder(), folderName);
|
||||||
|
if (!folder.exists())
|
||||||
|
{
|
||||||
|
folder.mkdirs();
|
||||||
|
}
|
||||||
|
loadAllObjectsAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadAllObjectsAsync()
|
||||||
|
{
|
||||||
|
ess.scheduleAsyncDelayedTask(new Runnable()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
if (!folder.exists() || !folder.isDirectory())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
keys.clear();
|
||||||
|
cache.invalidateAll();
|
||||||
|
for (String string : folder.list())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!string.endsWith(".yml"))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
final String name = Util.decodeFileName(string.substring(0, string.length() - 4));
|
||||||
|
keys.add(name.toLowerCase(Locale.ENGLISH));
|
||||||
|
}
|
||||||
|
catch (InvalidNameException ex)
|
||||||
|
{
|
||||||
|
Bukkit.getLogger().log(Level.WARNING, "Invalid filename: " + string, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean objectExists(final String name)
|
||||||
|
{
|
||||||
|
return keys.contains(name.toLowerCase(Locale.ENGLISH));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public I getObject(final String name)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return (I)cache.get(name.toLowerCase(Locale.ENGLISH));
|
||||||
|
}
|
||||||
|
catch (ExecutionException ex)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
catch (UncheckedExecutionException ex)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public abstract I load(final String name) throws Exception;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeObject(final String name) throws InvalidNameException
|
||||||
|
{
|
||||||
|
keys.remove(name.toLowerCase(Locale.ENGLISH));
|
||||||
|
cache.invalidate(name.toLowerCase(Locale.ENGLISH));
|
||||||
|
File file = getStorageFile(name);
|
||||||
|
if (file.exists())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<String> getAllKeys()
|
||||||
|
{
|
||||||
|
return Collections.unmodifiableSet(keys);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getKeySize()
|
||||||
|
{
|
||||||
|
return keys.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public File getStorageFile(final String name) throws InvalidNameException
|
||||||
|
{
|
||||||
|
if (!folder.exists() || !folder.isDirectory())
|
||||||
|
{
|
||||||
|
throw new InvalidNameException(new IOException("Folder does not exists: " + folder));
|
||||||
|
}
|
||||||
|
return new File(folder, Util.sanitizeFileName(name) + ".yml");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onReload()
|
||||||
|
{
|
||||||
|
loadAllObjectsAsync();
|
||||||
|
}
|
||||||
|
}
|
@@ -3,10 +3,15 @@ package com.earth2me.essentials.textreader;
|
|||||||
import com.earth2me.essentials.api.IEssentials;
|
import com.earth2me.essentials.api.IEssentials;
|
||||||
import com.earth2me.essentials.api.IUser;
|
import com.earth2me.essentials.api.IUser;
|
||||||
import com.earth2me.essentials.Util;
|
import com.earth2me.essentials.Util;
|
||||||
|
import com.earth2me.essentials.api.InvalidNameException;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import sun.util.BuddhistCalendar;
|
||||||
|
|
||||||
|
|
||||||
public class TextInput implements IText
|
public class TextInput implements IText
|
||||||
@@ -20,6 +25,8 @@ public class TextInput implements IText
|
|||||||
|
|
||||||
File file = null;
|
File file = null;
|
||||||
if (sender instanceof Player)
|
if (sender instanceof Player)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
final IUser user = ess.getUser((Player)sender);
|
final IUser user = ess.getUser((Player)sender);
|
||||||
file = new File(ess.getDataFolder(), filename + "_" + Util.sanitizeFileName(user.getName()) + ".txt");
|
file = new File(ess.getDataFolder(), filename + "_" + Util.sanitizeFileName(user.getName()) + ".txt");
|
||||||
@@ -28,6 +35,11 @@ public class TextInput implements IText
|
|||||||
file = new File(ess.getDataFolder(), filename + "_" + Util.sanitizeFileName(user.getGroup()) + ".txt");
|
file = new File(ess.getDataFolder(), filename + "_" + Util.sanitizeFileName(user.getGroup()) + ".txt");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (InvalidNameException ex)
|
||||||
|
{
|
||||||
|
Bukkit.getLogger().log(Level.WARNING, ex.getMessage(), ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
if (file == null || !file.exists())
|
if (file == null || !file.exists())
|
||||||
{
|
{
|
||||||
file = new File(ess.getDataFolder(), filename + ".txt");
|
file = new File(ess.getDataFolder(), filename + ".txt");
|
||||||
|
@@ -10,6 +10,7 @@ import com.earth2me.essentials.register.payment.Method;
|
|||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import lombok.Cleanup;
|
import lombok.Cleanup;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
@@ -41,6 +42,7 @@ public class User extends UserBase implements IUser
|
|||||||
private boolean hidden = false;
|
private boolean hidden = false;
|
||||||
private transient Location afkPosition;
|
private transient Location afkPosition;
|
||||||
private static final Logger logger = Bukkit.getLogger();
|
private static final Logger logger = Bukkit.getLogger();
|
||||||
|
private AtomicBoolean gotMailInfo = new AtomicBoolean(false);
|
||||||
|
|
||||||
public User(final Player base, final IEssentials ess)
|
public User(final Player base, final IEssentials ess)
|
||||||
{
|
{
|
||||||
@@ -625,4 +627,15 @@ public class User extends UserBase implements IUser
|
|||||||
{
|
{
|
||||||
return replyTo;
|
return replyTo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean gotMailInfo() {
|
||||||
|
return gotMailInfo.getAndSet(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addMail(String mail) {
|
||||||
|
super.addMail(mail);
|
||||||
|
gotMailInfo.set(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -3,10 +3,14 @@ package com.earth2me.essentials.user;
|
|||||||
import com.earth2me.essentials.Util;
|
import com.earth2me.essentials.Util;
|
||||||
import com.earth2me.essentials.api.IEssentials;
|
import com.earth2me.essentials.api.IEssentials;
|
||||||
import com.earth2me.essentials.api.ISettings;
|
import com.earth2me.essentials.api.ISettings;
|
||||||
|
import com.earth2me.essentials.api.InvalidNameException;
|
||||||
import com.earth2me.essentials.craftbukkit.OfflineBedLocation;
|
import com.earth2me.essentials.craftbukkit.OfflineBedLocation;
|
||||||
import com.earth2me.essentials.storage.AsyncStorageObjectHolder;
|
import com.earth2me.essentials.storage.AsyncStorageObjectHolder;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
import lombok.Cleanup;
|
import lombok.Cleanup;
|
||||||
import lombok.Delegate;
|
import lombok.Delegate;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@@ -131,10 +135,17 @@ public abstract class UserBase extends AsyncStorageObjectHolder<UserData> implem
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public File getStorageFile()
|
public File getStorageFile() throws IOException
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
return ess.getUserMap().getUserFile(getName());
|
return ess.getUserMap().getUserFile(getName());
|
||||||
}
|
}
|
||||||
|
catch (InvalidNameException ex)
|
||||||
|
{
|
||||||
|
throw new IOException(ex.getMessage(), ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public long getTimestamp(final UserData.TimestampType name)
|
public long getTimestamp(final UserData.TimestampType name)
|
||||||
{
|
{
|
||||||
@@ -353,12 +364,36 @@ public abstract class UserBase extends AsyncStorageObjectHolder<UserData> implem
|
|||||||
public void addMail(String string)
|
public void addMail(String string)
|
||||||
{
|
{
|
||||||
acquireWriteLock();
|
acquireWriteLock();
|
||||||
try {
|
try
|
||||||
if (getData().getMails() == null) {
|
{
|
||||||
|
if (getData().getMails() == null)
|
||||||
|
{
|
||||||
getData().setMails(new ArrayList<String>());
|
getData().setMails(new ArrayList<String>());
|
||||||
}
|
}
|
||||||
getData().getMails().add(string);
|
getData().getMails().add(string);
|
||||||
} finally {
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getMails()
|
||||||
|
{
|
||||||
|
acquireReadLock();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (getData().getMails() == null)
|
||||||
|
{
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return new ArrayList<String>(getData().getMails());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
unlock();
|
unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,88 +1,38 @@
|
|||||||
package com.earth2me.essentials.user;
|
package com.earth2me.essentials.user;
|
||||||
|
|
||||||
import com.earth2me.essentials.api.IEssentials;
|
import com.earth2me.essentials.api.IEssentials;
|
||||||
import com.earth2me.essentials.Util;
|
|
||||||
import com.earth2me.essentials.api.IUser;
|
import com.earth2me.essentials.api.IUser;
|
||||||
import com.earth2me.essentials.api.IUserMap;
|
import com.earth2me.essentials.api.IUserMap;
|
||||||
import com.google.common.cache.Cache;
|
import com.earth2me.essentials.api.InvalidNameException;
|
||||||
import com.google.common.cache.CacheBuilder;
|
import com.earth2me.essentials.storage.StorageObjectMap;
|
||||||
import com.google.common.cache.CacheLoader;
|
|
||||||
import com.google.common.util.concurrent.UncheckedExecutionException;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentSkipListSet;
|
|
||||||
import java.util.concurrent.ExecutionException;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
|
||||||
public class UserMap extends CacheLoader<String, User> implements IUserMap
|
public class UserMap extends StorageObjectMap<IUser> implements IUserMap
|
||||||
{
|
{
|
||||||
private final transient IEssentials ess;
|
|
||||||
private final transient Cache<String, User> users = CacheBuilder.newBuilder().softValues().build(this);
|
|
||||||
private final transient ConcurrentSkipListSet<String> keys = new ConcurrentSkipListSet<String>();
|
|
||||||
|
|
||||||
public UserMap(final IEssentials ess)
|
public UserMap(final IEssentials ess)
|
||||||
{
|
{
|
||||||
super();
|
super(ess, "users");
|
||||||
this.ess = ess;
|
|
||||||
loadAllUsersAsync();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void loadAllUsersAsync()
|
|
||||||
{
|
|
||||||
ess.scheduleAsyncDelayedTask(new Runnable()
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
final File userdir = new File(ess.getDataFolder(), "userdata");
|
|
||||||
if (!userdir.exists())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
keys.clear();
|
|
||||||
users.invalidateAll();
|
|
||||||
for (String string : userdir.list())
|
|
||||||
{
|
|
||||||
if (!string.endsWith(".yml"))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
final String name = string.substring(0, string.length() - 4);
|
|
||||||
keys.add(name.toLowerCase(Locale.ENGLISH));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean userExists(final String name)
|
public boolean userExists(final String name)
|
||||||
{
|
{
|
||||||
return keys.contains(name.toLowerCase(Locale.ENGLISH));
|
return objectExists(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IUser getUser(final String name)
|
public IUser getUser(final String name)
|
||||||
{
|
{
|
||||||
try
|
return getObject(name);
|
||||||
{
|
|
||||||
return users.get(name.toLowerCase(Locale.ENGLISH));
|
|
||||||
}
|
|
||||||
catch (ExecutionException ex)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
catch (UncheckedExecutionException ex)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public User load(final String name) throws Exception
|
public IUser load(final String name) throws Exception
|
||||||
{
|
{
|
||||||
for (Player player : ess.getServer().getOnlinePlayers())
|
for (Player player : ess.getServer().getOnlinePlayers())
|
||||||
{
|
{
|
||||||
@@ -102,35 +52,27 @@ public class UserMap extends CacheLoader<String, User> implements IUserMap
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeUser(final String name)
|
public void removeUser(final String name) throws InvalidNameException
|
||||||
{
|
{
|
||||||
keys.remove(name.toLowerCase(Locale.ENGLISH));
|
removeObject(name);
|
||||||
users.invalidate(name.toLowerCase(Locale.ENGLISH));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<String> getAllUniqueUsers()
|
public Set<String> getAllUniqueUsers()
|
||||||
{
|
{
|
||||||
return Collections.unmodifiableSet(keys);
|
return getAllKeys();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getUniqueUsers()
|
public int getUniqueUsers()
|
||||||
{
|
{
|
||||||
return keys.size();
|
return getKeySize();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public File getUserFile(final String name)
|
public File getUserFile(String name) throws InvalidNameException
|
||||||
{
|
{
|
||||||
final File userFolder = new File(ess.getDataFolder(), "userdata");
|
return getStorageFile(name);
|
||||||
return new File(userFolder, Util.sanitizeFileName(name) + ".yml");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onReload()
|
|
||||||
{
|
|
||||||
loadAllUsersAsync();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -3,6 +3,8 @@ package com.earth2me.essentials;
|
|||||||
import com.earth2me.essentials.api.Economy;
|
import com.earth2me.essentials.api.Economy;
|
||||||
import com.earth2me.essentials.api.NoLoanPermittedException;
|
import com.earth2me.essentials.api.NoLoanPermittedException;
|
||||||
import com.earth2me.essentials.api.UserDoesNotExistException;
|
import com.earth2me.essentials.api.UserDoesNotExistException;
|
||||||
|
import com.earth2me.essentials.craftbukkit.DummyOfflinePlayer;
|
||||||
|
import com.earth2me.essentials.user.User;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
import org.bukkit.World.Environment;
|
import org.bukkit.World.Environment;
|
||||||
@@ -34,7 +36,7 @@ public class EconomyTest extends TestCase
|
|||||||
{
|
{
|
||||||
fail("IOException");
|
fail("IOException");
|
||||||
}
|
}
|
||||||
server.addPlayer(new OfflinePlayer(PLAYERNAME, ess));
|
server.addPlayer(new User(new DummyOfflinePlayer(PLAYERNAME), ess));
|
||||||
}
|
}
|
||||||
|
|
||||||
// only one big test, since we use static instances
|
// only one big test, since we use static instances
|
||||||
|
@@ -3,6 +3,8 @@ package com.earth2me.essentials;
|
|||||||
import com.earth2me.essentials.craftbukkit.FakeWorld;
|
import com.earth2me.essentials.craftbukkit.FakeWorld;
|
||||||
import com.avaje.ebean.config.ServerConfig;
|
import com.avaje.ebean.config.ServerConfig;
|
||||||
import com.earth2me.essentials.api.IEssentials;
|
import com.earth2me.essentials.api.IEssentials;
|
||||||
|
import com.earth2me.essentials.craftbukkit.DummyOfflinePlayer;
|
||||||
|
import com.earth2me.essentials.user.User;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
@@ -324,13 +326,6 @@ public class FakeServer implements Server
|
|||||||
players.add(base1);
|
players.add(base1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public OfflinePlayer createPlayer(String name, IEssentials ess)
|
|
||||||
{
|
|
||||||
OfflinePlayer player = new OfflinePlayer(name, ess);
|
|
||||||
player.setLocation(new Location(worlds.get(0), 0, 0, 0, 0, 0));
|
|
||||||
return player;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public World createWorld(String string, Environment e, ChunkGenerator cg)
|
public World createWorld(String string, Environment e, ChunkGenerator cg)
|
||||||
{
|
{
|
||||||
|
@@ -133,7 +133,7 @@ public class StorageTest extends TestCase
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
/*@Test
|
||||||
public void testOldUserdata()
|
public void testOldUserdata()
|
||||||
{
|
{
|
||||||
ExecuteTimer ext = new ExecuteTimer();
|
ExecuteTimer ext = new ExecuteTimer();
|
||||||
@@ -157,5 +157,5 @@ public class StorageTest extends TestCase
|
|||||||
user.reloadConfig();
|
user.reloadConfig();
|
||||||
ext.mark("reloaded file (cached)");
|
ext.mark("reloaded file (cached)");
|
||||||
System.out.println(ext.end());
|
System.out.println(ext.end());
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
@@ -6,11 +6,13 @@ import org.bukkit.Location;
|
|||||||
import org.bukkit.World.Environment;
|
import org.bukkit.World.Environment;
|
||||||
import org.bukkit.plugin.InvalidDescriptionException;
|
import org.bukkit.plugin.InvalidDescriptionException;
|
||||||
import com.earth2me.essentials.api.IUser;
|
import com.earth2me.essentials.api.IUser;
|
||||||
|
import com.earth2me.essentials.craftbukkit.DummyOfflinePlayer;
|
||||||
|
import com.earth2me.essentials.user.User;
|
||||||
|
|
||||||
|
|
||||||
public class UserTest extends TestCase
|
public class UserTest extends TestCase
|
||||||
{
|
{
|
||||||
private final OfflinePlayer base1;
|
private final IUser base1;
|
||||||
private final Essentials ess;
|
private final Essentials ess;
|
||||||
private final FakeServer server;
|
private final FakeServer server;
|
||||||
|
|
||||||
@@ -32,7 +34,7 @@ public class UserTest extends TestCase
|
|||||||
{
|
{
|
||||||
fail("IOException");
|
fail("IOException");
|
||||||
}
|
}
|
||||||
base1 = server.createPlayer("testPlayer1", ess);
|
base1 = new User(new DummyOfflinePlayer("testPlayer1"), ess);
|
||||||
server.addPlayer(base1);
|
server.addPlayer(base1);
|
||||||
ess.getUser(base1);
|
ess.getUser(base1);
|
||||||
}
|
}
|
||||||
@@ -42,7 +44,7 @@ public class UserTest extends TestCase
|
|||||||
System.out.println(getName() + " should " + what);
|
System.out.println(getName() + " should " + what);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testUpdate()
|
/*public void testUpdate()
|
||||||
{
|
{
|
||||||
OfflinePlayer base1alt = server.createPlayer(base1.getName(), ess);
|
OfflinePlayer base1alt = server.createPlayer(base1.getName(), ess);
|
||||||
assertEquals(base1alt, ess.getUser(base1alt).getBase());
|
assertEquals(base1alt, ess.getUser(base1alt).getBase());
|
||||||
@@ -64,7 +66,7 @@ public class UserTest extends TestCase
|
|||||||
assertEquals(loc.getZ(), home.getZ());
|
assertEquals(loc.getZ(), home.getZ());
|
||||||
assertEquals(loc.getYaw(), home.getYaw());
|
assertEquals(loc.getYaw(), home.getYaw());
|
||||||
assertEquals(loc.getPitch(), home.getPitch());
|
assertEquals(loc.getPitch(), home.getPitch());
|
||||||
}
|
}*/
|
||||||
|
|
||||||
public void testMoney()
|
public void testMoney()
|
||||||
{
|
{
|
||||||
|
@@ -1,8 +1,11 @@
|
|||||||
package com.earth2me.essentials;
|
package com.earth2me.essentials;
|
||||||
|
|
||||||
|
import com.earth2me.essentials.api.InvalidNameException;
|
||||||
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 java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
import org.bukkit.World.Environment;
|
import org.bukkit.World.Environment;
|
||||||
import org.bukkit.plugin.InvalidDescriptionException;
|
import org.bukkit.plugin.InvalidDescriptionException;
|
||||||
@@ -171,4 +174,26 @@ public class UtilTest extends TestCase
|
|||||||
b = new GregorianCalendar(2000, 3, 7, 10, 0, 0);
|
b = new GregorianCalendar(2000, 3, 7, 10, 0, 0);
|
||||||
assertEquals(" 10 years 6 months 10 days 13 hours 45 minutes 45 seconds", Util.formatDateDiff(a, b));
|
assertEquals(" 10 years 6 months 10 days 13 hours 45 minutes 45 seconds", Util.formatDateDiff(a, b));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void filenameTest() {
|
||||||
|
try
|
||||||
|
{
|
||||||
|
assertEquals("_-", Util.sanitizeFileName("\u0000"));
|
||||||
|
assertEquals("_-", Util.sanitizeFileName("\u0001"));
|
||||||
|
assertEquals("_-", Util.sanitizeFileName("\u001f"));
|
||||||
|
assertEquals(" -", Util.sanitizeFileName(" "));
|
||||||
|
assertEquals("_-", Util.sanitizeFileName(".."));
|
||||||
|
assertEquals("_-", Util.sanitizeFileName("..\\"));
|
||||||
|
assertEquals("_-", Util.sanitizeFileName("../"));
|
||||||
|
assertEquals("_-", Util.sanitizeFileName("\""));
|
||||||
|
assertEquals("_-", Util.sanitizeFileName("<>?:*."));
|
||||||
|
assertEquals("a-0fa", Util.sanitizeFileName("aä"));
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (InvalidNameException ex)
|
||||||
|
{
|
||||||
|
Logger.getLogger(UtilTest.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user