1
0
mirror of https://github.com/moparisthebest/xAuth synced 2024-12-22 07:08:51 -05:00

MultiInv compatibility *seems* to be fixed, revision of entire Settings class, illegal action notify limit fixed, multiple other small fixes/edits

This commit is contained in:
CypherX 2011-03-26 02:00:21 -04:00
parent 525fee6d5e
commit 7a24b5cae0
5 changed files with 116 additions and 139 deletions

View File

@ -5,12 +5,10 @@ import org.bukkit.command.Command;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginDescriptionFile;
import com.cypherx.xauth.Settings.Keys;
public class CommandHandler
{
private final xAuth plugin;
PluginDescriptionFile pdfFile;
private final PluginDescriptionFile pdfFile;
public CommandHandler(final xAuth instance)
{
@ -24,25 +22,18 @@ public class CommandHandler
{
if (args.length != 1)
player.sendMessage(xAuth.strings.getString("register.usage"));
//player.sendMessage(ChatColor.RED + "Correct Usage: /register <password>");
else if (!xAuth.settings.getBool(Keys.REG_ENABLED))
else if (!xAuth.settings.getBool("registration.enabled"))
player.sendMessage(xAuth.strings.getString("register.err.disabled"));
//player.sendMessage(ChatColor.RED + "Registrations are currently disabled.");
else if (plugin.isRegistered(player.getName()))
player.sendMessage(xAuth.strings.getString("register.err.registered"));
//player.sendMessage(ChatColor.RED + "You are already registered.");
else if (args[0].length() < xAuth.settings.getInt(Keys.PW_MIN_LENGTH))
//player.sendMessage(xAuth.strings.get(Strings.Keys.REG_ERR_REGISTERED, xAuth.settings.getInt(Keys.PW_MIN_LENGTH)));
player.sendMessage(xAuth.strings.getString("register.err.password", xAuth.settings.getInt(Keys.PW_MIN_LENGTH)));
//player.sendMessage(ChatColor.RED + "Your password must contain " + xAuth.settings.getInt(Keys.PW_MIN_LENGTH) + " or more characters.");
else if (args[0].length() < xAuth.settings.getInt("registration.pw-min-length"))
player.sendMessage(xAuth.strings.getString("register.err.password", xAuth.settings.getInt("registration.pw-min-length")));
else
{
plugin.addAuth(player.getName(), args[0]);
plugin.login(player);
player.sendMessage(xAuth.strings.getString("register.success1"));
player.sendMessage(xAuth.strings.getString("register.success2", args[0]));
//player.sendMessage(ChatColor.GREEN + "You have successfully registered!");
//player.sendMessage(ChatColor.GREEN + "Your password is: " + ChatColor.WHITE + args[0]);
System.out.println("[" + pdfFile.getName() + "] Player '" + player.getName() + "' has registered");
}
}
@ -74,10 +65,10 @@ public class CommandHandler
{
if (!plugin.sessionExists(player.getName()))
player.sendMessage(ChatColor.RED + "You must login before changing your password!");
else if (!xAuth.settings.getBool(Keys.ALLOW_CHANGEPW))
else if (!xAuth.settings.getBool("misc.allow-changepw"))
player.sendMessage(ChatColor.RED + "Password changes are currently disabled.");
else if (args[0].length() < xAuth.settings.getInt(Keys.PW_MIN_LENGTH))
player.sendMessage(ChatColor.RED + "Your password must contain " + xAuth.settings.getInt(Keys.PW_MIN_LENGTH) + " or more characters.");
else if (args[0].length() < xAuth.settings.getInt("registration.pw-min-length"))
player.sendMessage(ChatColor.RED + "Your password must contain " + xAuth.settings.getInt("registration.pw-min-length") + " or more characters.");
else
{
plugin.changePass(player.getName(), args[0]);
@ -107,10 +98,10 @@ public class CommandHandler
player.sendMessage(ChatColor.RED + "Correct Usage: /changepw <newpassword>");
else if (!plugin.sessionExists(player.getName()))
player.sendMessage(ChatColor.RED + "You must login before changing your password!");
else if (!xAuth.settings.getBool(Keys.ALLOW_CHANGEPW))
else if (!xAuth.settings.getBool("misc.allow-changepw"))
player.sendMessage(ChatColor.RED + "Password changes are currently disabled.");
else if (args[0].length() < xAuth.settings.getInt(Keys.PW_MIN_LENGTH))
player.sendMessage(ChatColor.RED + "Your password must contain " + xAuth.settings.getInt(Keys.PW_MIN_LENGTH) + " or more characters.");
else if (args[0].length() < xAuth.settings.getInt("registration.pw-min-length"))
player.sendMessage(ChatColor.RED + "Your password must contain " + xAuth.settings.getInt("registration.pw-min-length") + " or more characters.");
else
{
plugin.changePass(player.getName(), args[0]);
@ -159,8 +150,8 @@ public class CommandHandler
player.sendMessage(ChatColor.RED + "You aren't allow to toggle that!");
else
{
Boolean b = xAuth.settings.getBool(Keys.REG_ENABLED);
xAuth.settings.update(Keys.REG_ENABLED, (b ? false : true));
Boolean b = xAuth.settings.getBool("registration.enabled");
xAuth.settings.updateValue("registration.enabled", (b ? false : true));
player.sendMessage(ChatColor.YELLOW + "[" + pdfFile.getName() + "] Registrations are now " + (b ? "disabled." : "enabled."));
System.out.println("[" + pdfFile.getName() + "] " + player.getName() + " has " + (b ? "disabled" : "enabled") + " registrations");
}
@ -172,8 +163,8 @@ public class CommandHandler
player.sendMessage(ChatColor.RED + "You aren't allow to toggle that!");
else
{
Boolean b = xAuth.settings.getBool(Keys.ALLOW_CHANGEPW);
xAuth.settings.update(Keys.ALLOW_CHANGEPW, (b ? false : true));
Boolean b = xAuth.settings.getBool("misc.allow-changepw");
xAuth.settings.updateValue("misc.allow-changepw", (b ? false : true));
player.sendMessage(ChatColor.YELLOW + "[" + pdfFile.getName() + "] Password changes are now " + (b ? "disabled." : "enabled."));
System.out.println("[" + pdfFile.getName() + "] " + player.getName() + " has " + (b ? "disabled" : "enabled") + " password changes");
}
@ -184,8 +175,8 @@ public class CommandHandler
player.sendMessage(ChatColor.RED + "You aren't allow to toggle that!");
else
{
Boolean b = xAuth.settings.getBool(Keys.AUTOSAVE);
xAuth.settings.update(Keys.AUTOSAVE, (b ? false : true));
Boolean b = xAuth.settings.getBool("misc.autosave");
xAuth.settings.updateValue("misc.autosave", (b ? false : true));
player.sendMessage(ChatColor.YELLOW + "[" + pdfFile.getName() + "] Autosaving of account modifications is now " + (b ? "disabled." : "enabled."));
System.out.println("[" + pdfFile.getName() + "] " + player.getName() + " has " + (b ? "disabled" : "enabled") + " autosave");
}
@ -242,20 +233,20 @@ public class CommandHandler
System.out.println("Correct Usage: /toggle <reg|changepw|autosave>");
else if (args[0].equalsIgnoreCase("reg"))
{
Boolean b = xAuth.settings.getBool(Keys.REG_ENABLED);
xAuth.settings.update(Keys.REG_ENABLED, (b ? false : true));
Boolean b = xAuth.settings.getBool("registration.enabled");
xAuth.settings.updateValue("registration.enabled", (b ? false : true));
System.out.println("[" + pdfFile.getName() + "] Registrations are now " + (b ? "disabled" : "enabled"));
}
else if (args[0].equalsIgnoreCase("changepw"))
{
Boolean b = xAuth.settings.getBool(Keys.ALLOW_CHANGEPW);
xAuth.settings.update(Keys.ALLOW_CHANGEPW, (b ? false : true));
Boolean b = xAuth.settings.getBool("misc.allow-changepw");
xAuth.settings.updateValue("misc.allow-changepw", (b ? false : true));
System.out.println("[" + pdfFile.getName() + "] Password changes are now " + (b ? "disabled" : "enabled"));
}
else if (args[0].equalsIgnoreCase("autosave"))
{
Boolean b = xAuth.settings.getBool(Keys.AUTOSAVE);
xAuth.settings.update(Keys.AUTOSAVE, (b ? false : true));
Boolean b = xAuth.settings.getBool("misc.autosave");
xAuth.settings.updateValue("misc.autosave", (b ? false : true));
System.out.println("[" + pdfFile.getName() + "] Autosaving of account modifications is now " + (b ? "disabled" : "enabled"));
}
else

View File

@ -1,7 +1,6 @@
package com.cypherx.xauth;
import java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
@ -9,89 +8,79 @@ import org.bukkit.util.config.Configuration;
public class Settings
{
interface Keys
private static String[] keys =
{
public static final String REG_ENABLED = "registration.enabled";
public static final String ALLOW_CHANGE_PW = "misc.allow-change-pw";//old allow-changepw
public static final String ALLOW_CHANGEPW = "misc.allow-changepw";//new allow-changepw
public static final String SAVE_ON_CHANGE = "misc.save-on-change";//old autosave
public static final String AUTOSAVE = "misc.autosave";//new autosave
public static final String SESSION_TIMEOUT = "session.timeout";
public static final String NOTIFY_LIMIT = "notify.limit";
public static final String PW_MIN_LENGTH = "registration.pw-min-length";
public static final String ALLOWED_CMDS = "misc.allowed-cmds";
}
"registration.enabled",
"misc.allow-changepw",
"misc.autosave",
"session.timeout",
"notify.limit",
"registration.pw-min-length",
"misc.allowed-cmds"
};
private static final String[][] keyUpdates =
{
{"misc.allow-change-pw", "misc.allow-changepw"},
{"misc.save-on-change", "misc.autosave"}
};
private static Configuration config;
private static final ConcurrentHashMap<String, Object> defaults = new ConcurrentHashMap<String, Object>();
private static final ConcurrentHashMap<String, Object> settings = new ConcurrentHashMap<String, Object>();
public Settings (File file)
public Settings(File file)
{
config = new Configuration(file);
config.load();
fillDefaults();
if (file.exists() && keyUpdates.length > 0)
updateKeys();
load();
config.save();
}
public void fillDefaults()
{
defaults.put("registration.enabled", true);
defaults.put("registration.pw-min-length", 3);
defaults.put("session.timeout", 3600);
defaults.put("notify.limit", 5);
defaults.put("misc.allow-changepw", true);
defaults.put("misc.allowed-cmds", new String[]{"/register", "/login"});
defaults.put("misc.autosave", true);
}
public void updateKeys()
{
String fromKey, toKey;
Object holder;
for (String[] update : keyUpdates)
{
fromKey = update[0];
if (config.getProperty(fromKey) != null)
{
toKey = update[1];
holder = config.getProperty(fromKey);
config.removeProperty(fromKey);
config.setProperty(toKey, holder);
}
}
}
public void load()
{
config.load();
//Booleans
String key = Keys.REG_ENABLED;
if (config.getProperty(key) == null)
config.setProperty(key, true);
settings.put(key, config.getBoolean(key, true));
key = Keys.ALLOW_CHANGE_PW;
if (config.getProperty(key) != null)
for (String key : keys)
{
settings.put(key, config.getBoolean(key, true));
config.removeProperty(key);
if (config.getProperty(key) == null)
config.setProperty(key, defaults.get(key));
settings.put(key, config.getProperty(key));
}
key = Keys.ALLOW_CHANGEPW;
if (config.getProperty(key) == null)
config.setProperty(key, getBool(Keys.ALLOW_CHANGE_PW) == null ? true : getBool(Keys.ALLOW_CHANGE_PW));
settings.put(key, config.getBoolean(key, true));
key = Keys.SAVE_ON_CHANGE;
if (config.getProperty(key) != null)
{
settings.put(key, config.getBoolean(key, true));
config.removeProperty(key);
}
key = Keys.AUTOSAVE;
if (config.getProperty(key) == null)
config.setProperty(key, getBool(Keys.SAVE_ON_CHANGE) == null ? true : getBool(Keys.SAVE_ON_CHANGE));
settings.put(key, config.getBoolean(key, true));
//end Booleans
//Integers
key = Keys.SESSION_TIMEOUT;
if (config.getProperty(key) == null)
config.setProperty(key, 3600);
settings.put(key, config.getInt(key, 3600));
key = Keys.NOTIFY_LIMIT;
if (config.getProperty(key) == null)
config.setProperty(key, 5);
settings.put(key, config.getInt(key, 5));
key = Keys.PW_MIN_LENGTH;
if (config.getProperty(key) == null)
config.setProperty(key, 3);
settings.put(key, config.getInt(key, 3));
//end Integers
//String Arrays
key = Keys.ALLOWED_CMDS;
if (config.getProperty(key) == null)
config.setProperty(key, Arrays.asList(new String[] {"/register", "/login"}));
settings.put(key, config.getStringList(key, Arrays.asList(new String[] {"/register", "/login"})));
//end String Arrays
config.save();
}
public void update(String key, Object value)
public void updateValue(String key, Object value)
{
settings.replace(key, value);
config.setProperty(key, value);
@ -109,7 +98,7 @@ public class Settings
}
@SuppressWarnings("unchecked")
public List<String> getStrArr(String key)
public List<String> getStrList(String key)
{
return (List<String>)settings.get(key);
}

View File

@ -18,10 +18,7 @@ public class Strings
"register.success2"
};
private static final String[][] keyUpdates =
{
};
private static final String[][] keyUpdates = {};
private static Configuration config;
private static final ConcurrentHashMap<String, String> defaults = new ConcurrentHashMap<String, String>();

View File

@ -25,7 +25,6 @@ import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginManager;
import com.cypherx.xauth.Settings.Keys;
import com.nijiko.permissions.PermissionHandler;
import com.nijikokun.bukkit.Permissions.Permissions;
@ -40,6 +39,7 @@ public class xAuth extends JavaPlugin
private final xAuthBlockListener blockListener = new xAuthBlockListener(this);
private final xAuthEntityListener entityListener = new xAuthEntityListener(this);
private final HashMap<Player, Boolean> debugees = new HashMap<Player, Boolean>();
private static PluginDescriptionFile pdfFile;
private static final String DIR = "plugins/xAuth/";
private static final String CONFIG_FILE = "config.yml";
@ -61,6 +61,8 @@ public class xAuth extends JavaPlugin
public void onEnable()
{
pdfFile = this.getDescription();
/*Whirlpool w = new Whirlpool();
byte[] digest = new byte[Whirlpool.DIGESTBYTES];
w.NESSIEinit();
@ -68,7 +70,6 @@ public class xAuth extends JavaPlugin
w.NESSIEfinalize(digest);
System.out.println(Whirlpool.display(digest));*/
PluginDescriptionFile pdfFile = this.getDescription();
PropertyManager props = new PropertyManager(new File("server.properties"));
if (props.a("online-mode", true))
{
@ -119,7 +120,7 @@ public class xAuth extends JavaPlugin
pm.registerEvent(Event.Type.PLAYER_ITEM, playerListener, Event.Priority.Highest, this);
pm.registerEvent(Event.Type.PLAYER_JOIN, playerListener, Event.Priority.Highest, this);
pm.registerEvent(Event.Type.PLAYER_MOVE, playerListener, Event.Priority.Highest, this);
pm.registerEvent(Event.Type.PLAYER_QUIT, playerListener, Event.Priority.Highest, this);
pm.registerEvent(Event.Type.PLAYER_QUIT, playerListener, Event.Priority.Lowest, this);
pm.registerEvent(Event.Type.BLOCK_BREAK, blockListener, Priority.Highest, this);
//pm.registerEvent(Event.Type.BLOCK_DAMAGED, blockListener, Priority.Highest, this);
@ -129,7 +130,6 @@ public class xAuth extends JavaPlugin
pm.registerEvent(Event.Type.ENTITY_DAMAGED, entityListener, Priority.Highest, this);
pm.registerEvent(Event.Type.ENTITY_TARGET, entityListener, Priority.Highest, this);
//PluginDescriptionFile pdfFile = this.getDescription();
System.out.println("[" + pdfFile.getName() + "]" + " v" + pdfFile.getVersion() + " Enabled!");
//autosave stuff
@ -138,7 +138,6 @@ public class xAuth extends JavaPlugin
public void getAuths()
{
PluginDescriptionFile pdfFile = this.getDescription();
System.out.println("[" + pdfFile.getName() + "] Loading player accounts..");
try
@ -174,7 +173,6 @@ public class xAuth extends JavaPlugin
if (fullyEnabled)
updateAuthFile();
PluginDescriptionFile pdfFile = this.getDescription();
System.out.println("[" + pdfFile.getName() + "]" + " v" + pdfFile.getVersion() + " Disabled");
}
@ -199,7 +197,7 @@ public class xAuth extends JavaPlugin
String hash = md5(pass);
auths.put(pName.toLowerCase(), pName.toLowerCase() + ":" + hash);
if (settings.getBool(Keys.AUTOSAVE))
if (settings.getBool("misc.autosave"))
updateAuthFile();
}
@ -218,7 +216,7 @@ public class xAuth extends JavaPlugin
auths.remove(pName.toLowerCase());
auths.put(pName.toLowerCase(), pName.toLowerCase() + ":" + hash);
if (settings.getBool(Keys.AUTOSAVE))
if (settings.getBool("misc.autosave"))
updateAuthFile();
}
@ -230,7 +228,7 @@ public class xAuth extends JavaPlugin
if (sessionExists(pName))
removeSession(pName);
if (settings.getBool(Keys.AUTOSAVE))
if (settings.getBool("misc.autosave"))
updateAuthFile();
}
@ -276,7 +274,7 @@ public class xAuth extends JavaPlugin
{
Session session = sessions.get(pName.toLowerCase());
if (session.isExpired(new Date(session.getLoginTime() + (settings.getInt(Keys.SESSION_TIMEOUT) * 1000))))
if (session.isExpired(new Date(session.getLoginTime() + (settings.getInt("session.timeout") * 1000))))
removeSession(pName);
}
else
@ -297,7 +295,7 @@ public class xAuth extends JavaPlugin
public Boolean isCmdAllowed(String cmd)
{
if (settings.getStrArr(Keys.ALLOWED_CMDS).contains(cmd))
if (settings.getStrList("misc.allowed-cmds").contains(cmd))
return true;
return false;
@ -308,7 +306,7 @@ public class xAuth extends JavaPlugin
if (lastNotifyTimes.get(player) == null)
return true;
Date nextNotifyTime = new Date(lastNotifyTimes.get(player).getTime() + (settings.getInt(Keys.NOTIFY_LIMIT) * 1000));
Date nextNotifyTime = new Date(lastNotifyTimes.get(player).getTime() + (settings.getInt("notify.limit") * 1000));
if (nextNotifyTime.compareTo(new Date()) < 0)
return true;
@ -323,9 +321,8 @@ public class xAuth extends JavaPlugin
public void updateNotifyTime(Player player, Date date)
{
lastNotifyTimes.replace(player, date);
//lastNotifyTimes.remove(player);
//lastNotifyTimes.put(player, date);
lastNotifyTimes.remove(player);
lastNotifyTimes.put(player, date);
}
//INVENTORY FUNCTIONS
@ -395,7 +392,7 @@ public class xAuth extends JavaPlugin
public Boolean isSessionValid(Player player)
{
Session session = sessions.get(player.getName().toLowerCase());
if (session.isExpired(new Date(session.getLoginTime() + (settings.getInt(Keys.SESSION_TIMEOUT) * 1000))))
if (session.isExpired(new Date(session.getLoginTime() + (settings.getInt("session.timeout") * 1000))))
return false;
if (!session.isValidAddr(player.getAddress().getAddress().getHostAddress()))
@ -414,7 +411,6 @@ public class xAuth extends JavaPlugin
//MISC FUNCTIONS
private void setupPermissions()
{
PluginDescriptionFile pdfFile = this.getDescription();
Plugin test = this.getServer().getPluginManager().getPlugin("Permissions");
if (xAuth.Permissions == null)
@ -465,7 +461,6 @@ public class xAuth extends JavaPlugin
public void reload()
{
PluginDescriptionFile pdfFile = this.getDescription();
updateAuthFile();
settings = new Settings(new File(DIR + CONFIG_FILE));
strings = new Strings(new File(DIR + STRINGS_FILE));

View File

@ -4,20 +4,25 @@ version: 1.1.4
commands:
register:
description:
usage:
description: Register your player name
usage: /register <password>
login:
description:
usage:
description: Authenticate yourself
usage: /login <password>
changepw:
description:
usage:
description: Change your or another players password
usage: |
/changepw <password>
/changepw <player> <password>
unregister:
description:
usage:
description: Remove a players registration
usage: /unregister <player>
authreload:
description:
usage:
description: Reload the account, configuration, and string files
usage: /authreload
toggle:
description:
usage:
description: Toggle various commands on/off
usage: |
/toggle reg
/toggle changepw
/toggle autosave