Search in sources :

Example 1 with UserMap

use of com.earth2me.essentials.UserMap in project Essentials by drtshock.

the class Commandessentials method run_cleanup.

private void run_cleanup(final Server server, final CommandSource sender, final String command, final String[] args) throws Exception {
    if (args.length < 2 || !NumberUtil.isInt(args[1])) {
        sender.sendMessage("This sub-command will delete users who havent logged in in the last <days> days.");
        sender.sendMessage("Optional parameters define the minium amount required to prevent deletion.");
        sender.sendMessage("Unless you define larger default values, this command wil ignore people who have more than 0 money/homes.");
        throw new Exception("/<command> cleanup <days> [money] [homes]");
    }
    sender.sendMessage(tl("cleaning"));
    final long daysArg = Long.parseLong(args[1]);
    final double moneyArg = args.length >= 3 ? FloatUtil.parseDouble(args[2].replaceAll("[^0-9\\.]", "")) : 0;
    final int homesArg = args.length >= 4 && NumberUtil.isInt(args[3]) ? Integer.parseInt(args[3]) : 0;
    final UserMap userMap = ess.getUserMap();
    ess.runTaskAsynchronously(new Runnable() {

        @Override
        public void run() {
            Long currTime = System.currentTimeMillis();
            for (UUID u : userMap.getAllUniqueUsers()) {
                final User user = ess.getUserMap().getUser(u);
                if (user == null) {
                    continue;
                }
                long lastLog = user.getLastLogout();
                if (lastLog == 0) {
                    lastLog = user.getLastLogin();
                }
                if (lastLog == 0) {
                    user.setLastLogin(currTime);
                }
                if (user.isNPC()) {
                    continue;
                }
                long timeDiff = currTime - lastLog;
                long milliDays = daysArg * 24L * 60L * 60L * 1000L;
                int homeCount = user.getHomes().size();
                double moneyCount = user.getMoney().doubleValue();
                if ((lastLog == 0) || (timeDiff < milliDays) || (homeCount > homesArg) || (moneyCount > moneyArg)) {
                    continue;
                }
                if (ess.getSettings().isDebug()) {
                    ess.getLogger().info("Deleting user: " + user.getName() + " Money: " + moneyCount + " Homes: " + homeCount + " Last seen: " + DateUtil.formatDateDiff(lastLog));
                }
                user.reset();
            }
            sender.sendMessage(tl("cleaned"));
        }
    });
}
Also used : UserMap(com.earth2me.essentials.UserMap) User(com.earth2me.essentials.User) UUID(java.util.UUID) IOException(java.io.IOException)

Example 2 with UserMap

use of com.earth2me.essentials.UserMap in project Essentials by drtshock.

the class Commandseen method seenIP.

private void seenIP(final Server server, final CommandSource sender, final String ipAddress) throws Exception {
    final UserMap userMap = ess.getUserMap();
    if (ess.getServer().getBanList(BanList.Type.IP).isBanned(ipAddress)) {
        sender.sendMessage(tl("isIpBanned", ipAddress));
    }
    sender.sendMessage(tl("runningPlayerMatch", ipAddress));
    ess.runTaskAsynchronously(new Runnable() {

        @Override
        public void run() {
            final List<String> matches = new ArrayList<>();
            for (final UUID u : userMap.getAllUniqueUsers()) {
                final User user = ess.getUserMap().getUser(u);
                if (user == null) {
                    continue;
                }
                final String uIPAddress = user.getLastLoginAddress();
                if (!uIPAddress.isEmpty() && uIPAddress.equalsIgnoreCase(ipAddress)) {
                    matches.add(user.getName());
                }
            }
            if (matches.size() > 0) {
                sender.sendMessage(tl("matchingIPAddress"));
                sender.sendMessage(StringUtil.joinList(matches));
            } else {
                sender.sendMessage(tl("noMatchingPlayers"));
            }
        }
    });
}
Also used : UserMap(com.earth2me.essentials.UserMap) User(com.earth2me.essentials.User) BanList(org.bukkit.BanList) ArrayList(java.util.ArrayList) List(java.util.List) UUID(java.util.UUID)

Aggregations

User (com.earth2me.essentials.User)2 UserMap (com.earth2me.essentials.UserMap)2 UUID (java.util.UUID)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 BanList (org.bukkit.BanList)1