public void saveConfiguration() { final ConfigurationSection config = getConfig(); config.set("alwaysNeedPassword", alwaysNeedPassword); config.set("autoLogout", autoLogout); config.set("autoKick", autoKick); config.set("kickUnregistered", autoKickUnregistered); config.set("autoKickLoginFailer", autoKickLoginFailer); config.set("autoKickCommandUsers", autoKickCommandUsers); config.set("blockGuestCommands", blockGuestCommands); config.set("resetGuestLocations", resetGuestLocations); config.set("doNotSpamRequests", doNotSpamRequests); config.set("commandWhitelist", commandWhiteList); config.set("uniqueIDKey", uniqueIDKey); config.set("algorithm", encryptor.getAlgorithm()); config.set("autoDelete", autoDelete); config.set("forceSingleSession", forceSingleSession); config.set("forceSingleSessionSameIPBypass", forceSingleSessionSameIPBypass); config.set("maxRegistrationsPerIP", maxRegistrationsPerIP); config.set("pluginCommunicationEnabled", pluginCommunicationEnabled); config.set("moveRange", moveRange); config.set("minNameLength", minNameLength); config.set("maxNameLength", maxNameLength); saveConfig(); }
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]"); } }