private void commandMainMode(final CommandSender sender, final String[] args) throws CrazyCommandException { if (!sender.hasPermission("crazylogin.mode")) throw new CrazyCommandPermissionException(); switch (args.length) { case 2: if (args[0].equalsIgnoreCase("alwaysNeedPassword")) { boolean newValue = false; if (args[1].equalsIgnoreCase("1") || args[1].equalsIgnoreCase("true") || args[1].equalsIgnoreCase("on") || args[1].equalsIgnoreCase("yes")) newValue = true; alwaysNeedPassword = newValue; sendLocaleMessage( "MODE.CHANGE", sender, "alwaysNeedPassword", alwaysNeedPassword ? "True" : "False"); saveConfiguration(); return; } else if (args[0].equalsIgnoreCase("forceSingleSession")) { boolean newValue = false; if (args[1].equalsIgnoreCase("1") || args[1].equalsIgnoreCase("true") || args[1].equalsIgnoreCase("on") || args[1].equalsIgnoreCase("yes")) newValue = true; forceSingleSession = newValue; sendLocaleMessage( "MODE.CHANGE", sender, "forceSingleSession", forceSingleSession ? "True" : "False"); saveConfiguration(); return; } else if (args[0].equalsIgnoreCase("forceSingleSessionSameIPBypass")) { boolean newValue = false; if (args[1].equalsIgnoreCase("1") || args[1].equalsIgnoreCase("true") || args[1].equalsIgnoreCase("on") || args[1].equalsIgnoreCase("yes")) newValue = true; forceSingleSessionSameIPBypass = newValue; sendLocaleMessage( "MODE.CHANGE", sender, "forceSingleSessionSameIPBypass", forceSingleSessionSameIPBypass ? "True" : "False"); saveConfiguration(); return; } else if (args[0].equalsIgnoreCase("autoLogout")) { int newValue = autoLogout; try { newValue = Integer.parseInt(args[1]); } catch (final NumberFormatException e) { throw new CrazyCommandParameterException( 1, "Integer", "-1 = disabled", "0 = instant", "1... time in seconds"); } autoLogout = Math.max(newValue, -1); sendLocaleMessage( "MODE.CHANGE", sender, "autoLogout", autoLogout == -1 ? "disabled" : autoLogout + " seconds"); saveConfiguration(); return; } else if (args[0].equalsIgnoreCase("autoKick")) { int time = autoKick; try { time = Integer.parseInt(args[1]); } catch (final NumberFormatException e) { throw new CrazyCommandParameterException( 1, "Integer", "-1 = disabled", "Time in Seconds > 60"); } autoKick = time; sendLocaleMessage( "MODE.CHANGE", sender, "autoKick", autoKick == -1 ? "disabled" : autoKick + " seconds"); saveConfiguration(); return; } else if (args[0].equalsIgnoreCase("autoKickUnregistered")) { int time = autoKickUnregistered; try { time = Integer.parseInt(args[1]); } catch (final NumberFormatException e) { throw new CrazyCommandParameterException( 1, "Integer", "-1 = disabled", "Time in Seconds"); } autoKickUnregistered = Math.max(time, -1); sendLocaleMessage( "MODE.CHANGE", sender, "autoKickUnregistered", autoKickUnregistered == -1 ? "disabled" : autoKickUnregistered + " seconds"); saveConfiguration(); return; } else if (args[0].equalsIgnoreCase("autoKickLoginFailer")) { int tries = autoKickLoginFailer; try { tries = Integer.parseInt(args[1]); } catch (final NumberFormatException e) { throw new CrazyCommandParameterException(1, "Integer", "-1 = disabled", "tries"); } autoKickLoginFailer = Math.max(tries, -1); sendLocaleMessage( "MODE.CHANGE", sender, "autoKickLoginFailer", autoKickLoginFailer == -1 ? "disabled" : autoKickUnregistered + " tries"); saveConfiguration(); return; } else if (args[0].equalsIgnoreCase("autoKickCommandUsers")) { boolean newValue = false; if (args[1].equalsIgnoreCase("1") || args[1].equalsIgnoreCase("true") || args[1].equalsIgnoreCase("on") || args[1].equalsIgnoreCase("yes")) newValue = true; autoKickCommandUsers = newValue; sendLocaleMessage( "MODE.CHANGE", sender, "autoKickCommandUsers", autoKickCommandUsers ? "True" : "False"); saveConfiguration(); return; } else if (args[0].equalsIgnoreCase("blockGuestCommands")) { boolean newValue = false; if (args[1].equalsIgnoreCase("1") || args[1].equalsIgnoreCase("true") || args[1].equalsIgnoreCase("on") || args[1].equalsIgnoreCase("yes")) newValue = true; blockGuestCommands = newValue; sendLocaleMessage( "MODE.CHANGE", sender, "blockGuestCommands", blockGuestCommands ? "True" : "False"); saveConfiguration(); return; } else if (args[0].equalsIgnoreCase("resetGuestLocations")) { boolean newValue = false; if (args[1].equalsIgnoreCase("1") || args[1].equalsIgnoreCase("true") || args[1].equalsIgnoreCase("on") || args[1].equalsIgnoreCase("yes")) newValue = true; resetGuestLocations = newValue; if (resetGuestLocations) playerListener.clearSaveLogin(true); sendLocaleMessage( "MODE.CHANGE", sender, "resetGuestLocations", resetGuestLocations ? "True" : "False"); saveConfiguration(); return; } else if (args[0].equalsIgnoreCase("saveType")) { final String saveType = args[1]; DatabaseType type = null; try { type = DatabaseType.valueOf(saveType.toUpperCase()); } catch (final Exception e) { type = null; } if (type == null) throw new CrazyCommandNoSuchException("SaveType", saveType); sendLocaleMessage("MODE.CHANGE", sender, "saveType", saveType); if (type == database.getType()) return; getConfig().set("database.saveType", type.toString()); setupDatabase(); save(); return; } else if (args[0].equalsIgnoreCase("autoDelete")) { int time = autoDelete; try { time = Integer.parseInt(args[1]); } catch (final NumberFormatException e) { throw new CrazyCommandParameterException(1, "Integer", "-1 = disabled", "Time in Days"); } autoDelete = Math.max(time, -1); sendLocaleMessage( "MODE.CHANGE", sender, "autoDelete", autoDelete == -1 ? "disabled" : autoKick + " days"); saveConfiguration(); if (autoDelete != -1) getServer() .getScheduler() .scheduleAsyncRepeatingTask( this, new DropInactiveAccountsTask(this), 20 * 60 * 60, 20 * 60 * 60 * 6); return; } else if (args[0].equalsIgnoreCase("moveRange")) { int range = moveRange; try { range = Integer.parseInt(args[1]); } catch (final NumberFormatException e) { throw new CrazyCommandParameterException(1, "Integer"); } moveRange = Math.max(range, 0); sendLocaleMessage("MODE.CHANGE", sender, "moveRange", moveRange + " blocks"); saveConfiguration(); return; } else if (args[0].equalsIgnoreCase("minNameLength")) { int length = minNameLength; try { length = Integer.parseInt(args[1]); } catch (final NumberFormatException e) { throw new CrazyCommandParameterException(1, "Integer"); } minNameLength = Math.min(Math.max(length, 1), 16); sendLocaleMessage("MODE.CHANGE", sender, "minNameLength", minNameLength + " characters"); saveConfiguration(); return; } else if (args[0].equalsIgnoreCase("maxNameLength")) { int length = maxNameLength; try { length = Integer.parseInt(args[1]); } catch (final NumberFormatException e) { throw new CrazyCommandParameterException(1, "Integer"); } maxNameLength = Math.min(Math.max(length, 1), 16); sendLocaleMessage("MODE.CHANGE", sender, "maxNameLength", maxNameLength + " characters"); saveConfiguration(); return; } throw new CrazyCommandNoSuchException("Mode", args[0]); case 1: if (args[0].equalsIgnoreCase("alwaysNeedPassword")) { sendLocaleMessage( "MODE.CHANGE", sender, "alwaysNeedPassword", alwaysNeedPassword ? "True" : "False"); return; } else if (args[0].equalsIgnoreCase("forceSingleSession")) { sendLocaleMessage( "MODE.CHANGE", sender, "forceSingleSession", forceSingleSession ? "True" : "False"); return; } else if (args[0].equalsIgnoreCase("forceSingleSessionSameIPBypass")) { sendLocaleMessage( "MODE.CHANGE", sender, "forceSingleSessionSameIPBypass", forceSingleSessionSameIPBypass ? "True" : "False"); return; } else if (args[0].equalsIgnoreCase("autoLogout")) { sendLocaleMessage( "MODE.CHANGE", sender, "autoLogout", autoLogout == -1 ? "disabled" : autoLogout + " seconds"); return; } else if (args[0].equalsIgnoreCase("autoKick")) { sendLocaleMessage( "MODE.CHANGE", sender, "autoKick", autoKick == -1 ? "disabled" : autoKick + " seconds"); return; } else if (args[0].equalsIgnoreCase("autoKickUnregistered")) { sendLocaleMessage( "MODE.CHANGE", sender, "autoKickUnregistered", autoKickUnregistered == -1 ? "disabled" : autoKickUnregistered + " seconds"); return; } else if (args[0].equalsIgnoreCase("autoKickLoginFailer")) { sendLocaleMessage( "MODE.CHANGE", sender, "autoKickLoginFailer", autoKickLoginFailer == -1 ? "disabled" : autoKickUnregistered + " tries"); return; } else if (args[0].equalsIgnoreCase("autoKickCommandUsers")) { sendLocaleMessage( "MODE.CHANGE", sender, "autoKickCommandUsers", autoKickCommandUsers ? "True" : "False"); return; } else if (args[0].equalsIgnoreCase("blockGuestCommands")) { sendLocaleMessage( "MODE.CHANGE", sender, "blockGuestCommands", blockGuestCommands ? "True" : "False"); return; } else if (args[0].equalsIgnoreCase("resetGuestLocations")) { sendLocaleMessage( "MODE.CHANGE", sender, "resetGuestLocations", resetGuestLocations ? "True" : "False"); return; } else if (args[0].equalsIgnoreCase("saveType")) { sendLocaleMessage("MODE.CHANGE", sender, "saveType", database.getType().toString()); return; } else if (args[0].equalsIgnoreCase("autoDelete")) { sendLocaleMessage( "MODE.CHANGE", sender, "autoDelete", autoDelete == -1 ? "disabled" : autoKick + " days"); return; } else if (args[0].equalsIgnoreCase("moveRange")) { sendLocaleMessage("MODE.CHANGE", sender, "moveRange", moveRange + " blocks"); return; } else if (args[0].equalsIgnoreCase("minNameLength")) { sendLocaleMessage("MODE.CHANGE", sender, "minNameLength", minNameLength + " characters"); return; } else if (args[0].equalsIgnoreCase("maxNameLength")) { sendLocaleMessage("MODE.CHANGE", sender, "maxNameLength", maxNameLength + " characters"); return; } else if (args[0].equalsIgnoreCase("algorithm")) { sendLocaleMessage("MODE.CHANGE", sender, "algorithm", encryptor.getAlgorithm()); return; } throw new CrazyCommandNoSuchException("Mode", args[0]); default: throw new CrazyCommandUsageException("/crazylogin mode <Mode> [Value]"); } }
@Override public void load() { super.load(); final ConfigurationSection config = getConfig(); if (config.getBoolean("autoLogout", false)) autoLogout = 0; else autoLogout = config.getInt("autoLogout", 60 * 60); alwaysNeedPassword = config.getBoolean("alwaysNeedPassword", true); autoKick = Math.max(config.getInt("autoKick", -1), -1); autoKickUnregistered = Math.max(config.getInt("kickUnregistered", -1), -1); autoKickLoginFailer = Math.max(config.getInt("autoKickLoginFailer", 3), -1); autoKickCommandUsers = config.getBoolean("autoKickCommandUsers", false); blockGuestCommands = config.getBoolean("blockGuestCommands", false); resetGuestLocations = config.getBoolean("resetGuestLocations", true); loginFailures.clear(); doNotSpamRequests = config.getBoolean("doNotSpamRequests", false); commandWhiteList = config.getStringList("commandWhitelist"); if (commandWhiteList.size() == 0) { commandWhiteList.add("/login"); commandWhiteList.add("/register"); commandWhiteList.add("/crazylogin password"); } forceSingleSession = config.getBoolean("forceSingleSession", true); forceSingleSessionSameIPBypass = config.getBoolean("forceSingleSessionSameIPBypass", true); maxRegistrationsPerIP = config.getInt("maxRegistrationsPerIP", 3); autoDelete = Math.max(config.getInt("autoDelete", -1), -1); if (autoDelete != -1) getServer() .getScheduler() .scheduleAsyncRepeatingTask( this, new DropInactiveAccountsTask(this), 20 * 60 * 60, 20 * 60 * 60 * 6); moveRange = config.getInt("moveRange", 5); minNameLength = Math.min(Math.max(config.getInt("minNameLength", 3), 1), 16); maxNameLength = Math.min(Math.max(config.getInt("maxNameLength", 16), minNameLength), 16); uniqueIDKey = config.getString("uniqueIDKey"); pluginCommunicationEnabled = config.getBoolean("pluginCommunicationEnabled", false); final String algorithm = config.getString("algorithm", "CrazyCrypt1"); if (algorithm.equalsIgnoreCase("CrazyCrypt1")) { encryptor = new CrazyCrypt1(); } else if (algorithm.equalsIgnoreCase("Whirlpool")) { encryptor = new WhirlPoolCrypt(); } else if (algorithm.equalsIgnoreCase("Plaintext")) { encryptor = new PlainCrypt(); } else if (algorithm.equalsIgnoreCase("AuthMe")) { encryptor = new AuthMeCrypt(); } else if (algorithm.equalsIgnoreCase("Custom")) { final String encryption = config.getString("customEncryptor.class"); encryptor = ObjectSaveLoadHelper.load(encryption, CustomEncryptor.class, new Class[0], new Object[0]); } else { try { encryptor = new DefaultCrypt(algorithm); } catch (final NoSuchAlgorithmException e) { broadcastLocaleMessage(true, "crazylogin.warnalgorithm", "ALGORITHM.MISSING", algorithm); encryptor = new CrazyCrypt1(); } } setupDatabase(); datas.clear(); if (database != null) for (final LoginPlayerData data : database.getAllEntries()) datas.put(data.getName().toLowerCase(), data); dropInactiveAccounts(); for (final Player player : getServer().getOnlinePlayers()) requestLogin(player); }