public static boolean isExpired(final UUID uuid) {
   if (UUIDHandler.getPlayer(uuid) != null) {
     return false;
   }
   final String name = UUIDHandler.getName(uuid);
   if (name != null) {
     long last;
     if (dates.contains(uuid)) {
       last = dates.get(uuid);
     } else {
       final OfflinePlayer op = Bukkit.getOfflinePlayer(name);
       if (op.hasPlayedBefore()) {
         last = op.getLastPlayed();
         dates.put(uuid, last);
       } else {
         return false;
       }
     }
     if (last == 0) {
       return false;
     }
     final long compared = System.currentTimeMillis() - last;
     if (compared >= (86400000l * Settings.AUTO_CLEAR_DAYS)) {
       return true;
     }
   }
   return false;
 }
Beispiel #2
0
 public static Set<UUID> getUUIDsFromString(String list) {
   String[] split = list.split(",");
   HashSet<UUID> result = new HashSet<>();
   for (String name : split) {
     if (name.isEmpty()) {
       // Invalid
       return Collections.emptySet();
     }
     if ("*".equals(name)) {
       result.add(DBFunc.everyone);
       continue;
     }
     if (name.length() > 16) {
       try {
         result.add(UUID.fromString(name));
         continue;
       } catch (IllegalArgumentException ignored) {
         return Collections.emptySet();
       }
     }
     UUID uuid = UUIDHandler.getUUID(name, null);
     if (uuid == null) {
       return Collections.emptySet();
     }
     result.add(uuid);
   }
   return result;
 }
 public static List<Plot> getOldPlots(final String world) {
   final ArrayList<Plot> plots = new ArrayList<>(PS.get().getPlots(world).values());
   final List<Plot> toRemove = new ArrayList<>();
   Iterator<Plot> iter = plots.iterator();
   while (iter.hasNext()) {
     Plot plot = iter.next();
     final Flag keepFlag = FlagManager.getPlotFlag(plot, "keep");
     if (keepFlag != null && (Boolean) keepFlag.getValue()) {
       continue;
     }
     final UUID uuid = plot.owner;
     if (uuid == null) {
       toRemove.add(plot);
       continue;
     }
     final PlotPlayer player = UUIDHandler.getPlayer(uuid);
     if (player != null) {
       continue;
     }
     if (isExpired(plot)) {
       toRemove.add(plot);
     }
   }
   return toRemove;
 }
 @Override
 public void onEnable() {
   THIS = this;
   PS.instance = new PS(this);
   if (Settings.METRICS) {
     try {
       final Metrics metrics = new Metrics(this);
       metrics.start();
       log(C.PREFIX.s() + "&6Metrics enabled.");
     } catch (final Exception e) {
       log(C.PREFIX.s() + "&cFailed to load up metrics.");
     }
   } else {
     log("&dUsing metrics will allow us to improve the plugin, please consider it :)");
   }
   List<World> worlds = Bukkit.getWorlds();
   if (worlds.size() > 0) {
     UUIDHandler.cacheAll(worlds.get(0).getName());
     for (World world : worlds) {
       try {
         SetGenCB.setGenerator(world);
       } catch (Exception e) {
         log("Failed to reload world: " + world.getName());
         Bukkit.getServer().unloadWorld(world, false);
       }
     }
   }
 }
 public static String getPlayerName(final UUID uuid) {
   if (uuid == null) {
     return "unknown";
   }
   final String name = UUIDHandler.getName(uuid);
   if (name == null) {
     return "unknown";
   }
   return name;
 }
Beispiel #6
0
 /**
  * Get the name from a UUID.
  *
  * @param owner
  * @return The player's name, None, Everyone or Unknown
  */
 public static String getName(UUID owner) {
   if (owner == null) {
     return C.NONE.s();
   }
   if (owner.equals(DBFunc.everyone)) {
     return C.EVERYONE.s();
   }
   String name = UUIDHandler.getName(owner);
   if (name == null) {
     return C.UNKNOWN.s();
   }
   return name;
 }
Beispiel #7
0
 public static void getPersistentMeta(UUID uuid, String key, RunnableVal<byte[]> result) {
   PlotPlayer player = UUIDHandler.getPlayer(uuid);
   if (player != null) {
     result.run(player.getPersistentMeta(key));
   } else {
     DBFunc.getPersistentMeta(
         uuid,
         new RunnableVal<Map<String, byte[]>>() {
           @Override
           public void run(Map<String, byte[]> value) {
             result.run(value.get(key));
           }
         });
   }
 }
Beispiel #8
0
  /**
   * Fuzzy plot search with spaces separating terms. - Terms: type, alias, world, owner, trusted,
   * member
   *
   * @param search
   * @return
   */
  public static List<Plot> getPlotsBySearch(String search) {
    String[] split = search.split(" ");

    List<UUID> uuids = new ArrayList<>();
    PlotId id = null;
    PlotArea area = null;
    String alias = null;

    for (String term : split) {
      try {
        UUID uuid = UUIDHandler.getUUID(term, null);
        if (uuid == null) {
          uuid = UUID.fromString(term);
        }
        uuids.add(uuid);
      } catch (Exception ignored) {
        id = PlotId.fromString(term);
        if (id != null) {
          continue;
        }
        area = PS.get().getPlotAreaByString(term);
        if (area == null) {
          alias = term;
        }
      }
    }

    int size = split.length * 2;
    ArrayList<ArrayList<Plot>> plotList = new ArrayList<>(size);
    for (int i = 0; i < size; i++) {
      plotList.add(new ArrayList<>());
    }

    for (Plot plot : PS.get().getPlots()) {
      int count = 0;
      if (!uuids.isEmpty()) {
        for (UUID uuid : uuids) {
          if (plot.isOwner(uuid)) {
            count += 2;
          } else if (plot.isAdded(uuid)) {
            count++;
          }
        }
      }
      if (id != null) {
        if (plot.getId().equals(id)) {
          count++;
        }
      }
      if (area != null && plot.getArea().equals(area)) {
        count++;
      }
      if (alias != null && alias.equals(plot.getAlias())) {
        count += 2;
      }
      if (count != 0) {
        plotList.get(count - 1).add(plot);
      }
    }

    List<Plot> plots = new ArrayList<>();
    for (int i = plotList.size() - 1; i >= 0; i--) {
      if (!plotList.get(i).isEmpty()) {
        plots.addAll(plotList.get(i));
      }
    }
    return plots;
  }