@Override @Localized({ "CRAZYTIMECARD.COMMAND.REGISTER.HEADER $CurrentPage$ $MaxPage$ $ChatHeader$ $DateTime$", "CRAZYTIMECARD.COMMAND.REGISTER.LISTFORMAT $Index$ $Entry$ $ChatHeader$" }) public void command(final CommandSender sender, final String[] args) throws CrazyException { final Map<String, Paramitrisable> params = new TreeMap<String, Paramitrisable>(); final StringParamitrisable card = new StringParamitrisable(null); params.put("", card); params.put("c", card); params.put("card", card); final StringParamitrisable owner = new StringParamitrisable(sender.getName()); params.put("o", owner); params.put("owner", owner); final DurationParamitrisable duration = new DurationParamitrisable(plugin.getDefaultDuration()); params.put("d", duration); params.put("duration", duration); final IntegerParamitrisable amount = new IntegerParamitrisable(1); params.put("a", amount); params.put("amount", amount); ChatHelperExtended.readParameters(args, params); final ArrayList<String> cards = new ArrayList<String>(amount.getValue()); if (card.getValue() == null) for (int i = 0; i < amount.getValue(); i++) cards.add(plugin.genCardKey()); else for (int i = 0; i < amount.getValue(); i++) cards.add(card.getValue() + "_" + i); final Database<CardData> database = plugin.getCardDatabase(); for (int i = 0; i < amount.getValue(); i++) database.save(new CardData(cards.get(i), owner.getValue(), duration.getValue())); plugin.sendLocaleList( sender, "COMMAND.REGISTER.HEADER", "COMMAND.REGISTER.LISTFORMAT", null, -1, 1, cards); }
private void commandMainAdmin(final CommandSender sender, final String[] args) throws CrazyCommandException { if (!sender.hasPermission("crazylogin.admin")) throw new CrazyCommandPermissionException(); switch (args.length) { case 0: throw new CrazyCommandUsageException("/crazylogin admin <Player> <Passwort...>"); case 1: OfflinePlayer target = getServer().getPlayerExact(args[0]); if (target == null) { target = getServer().getPlayer(args[0]); if (target == null) target = getServer().getOfflinePlayer(args[0]); } if (target == null) throw new CrazyCommandNoSuchException("Player", args[0]); datas.remove(target.getName().toLowerCase()); sendLocaleMessage("PASSWORDDELETE.SUCCESS", sender); if (database != null) database.delete(target.getName()); return; } OfflinePlayer target = getServer().getPlayerExact(args[0]); if (target == null) { target = getServer().getPlayer(args[0]); if (target == null) target = getServer().getOfflinePlayer(args[0]); } if (target == null) throw new CrazyCommandNoSuchException("Player", args[0]); final LoginPlayerData data = datas.get(target.getName().toLowerCase()); if (data == null) throw new CrazyCommandNoSuchException("Player", args[0]); final String password = ChatHelper.listingString(ChatHelper.shiftArray(args, 1)); data.setPassword(password); sendLocaleMessage("PASSWORDCHANGE.SUCCESS", sender); if (database != null) database.save(data); }
@Override public void save() { final ConfigurationSection config = getConfig(); if (database != null) config.set("database.saveType", database.getType().toString()); dropInactiveAccounts(); if (database != null) database.saveAll(datas.values()); saveConfiguration(); }
@Override public boolean deletePlayerData(final String player) { final LoginPlayerData data = datas.remove(player.toLowerCase()); if (data == null) return false; if (database != null) database.delete(data.getName()); return true; }
private void commandLogout(final CommandSender sender, final String[] args) throws CrazyCommandException { if (sender instanceof ConsoleCommandSender) throw new CrazyCommandExecutorException(false); final Player player = (Player) sender; if (!isLoggedIn(player)) throw new CrazyCommandPermissionException(); final LoginPlayerData data = datas.get(player.getName().toLowerCase()); if (data != null) { data.logout(); if (database != null) database.save(data); } player.kickPlayer(locale.getLanguageEntry("LOGOUT.SUCCESS").getLanguageText(player)); }
private void commandLogin(final CommandSender sender, final String[] args) throws CrazyCommandException { if (sender instanceof ConsoleCommandSender) throw new CrazyCommandExecutorException(false); if (args.length == 0) throw new CrazyCommandUsageException("/login <Passwort...>"); final Player player = (Player) sender; final String password = ChatHelper.listingString(args); final LoginPlayerData data = datas.get(player.getName().toLowerCase()); final CrazyLoginPreLoginEvent event = new CrazyLoginPreLoginEvent(this, player, data); getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { getServer() .getPluginManager() .callEvent(new CrazyLoginLoginFailEvent(this, data, player, LoginFailReason.CANCELLED)); sendLocaleMessage("LOGIN.FAILED", player); return; } if (data == null) { getServer() .getPluginManager() .callEvent(new CrazyLoginLoginFailEvent(this, data, player, LoginFailReason.NO_ACCOUNT)); sendLocaleMessage("REGISTER.HEADER", player); sendLocaleMessage("REGISTER.MESSAGE", player); return; } if (!data.login(password)) { getServer() .getPluginManager() .callEvent( new CrazyLoginLoginFailEvent(this, data, player, LoginFailReason.WRONG_PASSWORD)); broadcastLocaleMessage( true, "crazylogin.warnloginfailure", "LOGIN.FAILEDWARN", player.getName(), player.getAddress().getAddress().getHostAddress()); Integer fails = loginFailures.get(player.getName().toLowerCase()); if (fails == null) fails = 0; fails++; if (fails >= autoKickLoginFailer) { player.kickPlayer(locale.getLocaleMessage(player, "LOGIN.FAILED")); fails = 0; } else sendLocaleMessage("LOGIN.FAILED", player); loginFailures.put(player.getName().toLowerCase(), fails); return; } getServer().getPluginManager().callEvent(new CrazyLoginLoginEvent(this, data, player)); sendLocaleMessage("LOGIN.SUCCESS", player); playerListener.notifyLogin(player); loginFailures.remove(player.getName().toLowerCase()); data.addIP(player.getAddress().getAddress().getHostAddress()); if (database != null) database.save(data); }
protected int dropInactiveAccounts(final Date limit) { int amount = 0; final Iterator<LoginPlayerData> it = datas.values().iterator(); while (it.hasNext()) { final LoginPlayerData data = it.next(); if (data.getLastActionTime().before(limit)) { amount++; datas.remove(data.getName().toLowerCase()); if (database != null) database.delete(data.getName()); } } return amount; }
private void commandMainPassword(final CommandSender sender, final String[] args) throws CrazyCommandException { if (sender instanceof ConsoleCommandSender) throw new CrazyCommandExecutorException(false); final Player player = (Player) sender; if (!isLoggedIn(player) && hasAccount(player)) throw new CrazyCommandPermissionException(); if (args.length == 0) { if (alwaysNeedPassword) throw new CrazyCommandUsageException("/crazylogin password <Passwort...>"); datas.remove(player.getName().toLowerCase()); sendLocaleMessage("PASSWORDDELETE.SUCCESS", sender); if (database != null) database.delete(player.getName()); return; } LoginPlayerData data = datas.get(player.getName().toLowerCase()); if (data == null) { if (!sender.hasPermission("crazylogin.register")) throw new CrazyCommandPermissionException(); final String ip = player.getAddress().getAddress().getHostAddress(); final int registrations = getRegistrationsPerIP(ip).size(); if (registrations >= maxRegistrationsPerIP) throw new CrazyCommandExceedingLimitsException( "Max Registrations per IP", maxRegistrationsPerIP); final CrazyLoginPreRegisterEvent event = new CrazyLoginPreRegisterEvent(this, player, data); getServer().getPluginManager().callEvent(event); if (event.isCancelled()) throw new CrazyCommandPermissionException(); data = new LoginPlayerData(player); datas.put(player.getName().toLowerCase(), data); } final String password = ChatHelper.listingString(args); if (pluginCommunicationEnabled) getServer().getPluginManager().callEvent(new CrazyLoginPasswordEvent(this, player, password)); data.setPassword(password); data.login(password); sendLocaleMessage("PASSWORDCHANGE.SUCCESS", player); playerListener.notifyLogin(player); if (database != null) database.save(data); }
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); }