Пример #1
0
 public static boolean plotExit(final PlotPlayer pp, Plot plot) {
   pp.deleteMeta("lastplot");
   EventUtil.manager.callLeave(pp, plot);
   if (plot.hasOwner()) {
     PlotArea pw = plot.getArea();
     if (pw == null) {
       return true;
     }
     if (FlagManager.getPlotFlagRaw(plot, "gamemode") != null) {
       if (pp.getGameMode() != pw.GAMEMODE) {
         if (!Permissions.hasPermission(pp, "plots.gamemode.bypass")) {
           pp.setGameMode(pw.GAMEMODE);
         } else {
           MainUtil.sendMessage(
               pp,
               StringMan.replaceAll(
                   C.GAMEMODE_WAS_BYPASSED.s(),
                   "{plot}",
                   plot.toString(),
                   "{gamemode}",
                   pw.GAMEMODE.name().toLowerCase()));
         }
       }
     }
     Flag farewell = FlagManager.getPlotFlagRaw(plot, "farewell");
     if (farewell != null) {
       MainUtil.format(
           C.PREFIX_FAREWELL.s() + farewell.getValueString(),
           plot,
           pp,
           false,
           new RunnableVal<String>() {
             @Override
             public void run(String value) {
               MainUtil.sendMessage(pp, value);
             }
           });
     }
     Flag leave = FlagManager.getPlotFlagRaw(plot, "notify-leave");
     if ((leave != null) && (Boolean) leave.getValue()) {
       if (!Permissions.hasPermission(pp, "plots.flag.notify-enter.bypass")) {
         for (UUID uuid : plot.getOwners()) {
           PlotPlayer owner = UUIDHandler.getPlayer(uuid);
           if ((owner != null) && !owner.getUUID().equals(pp.getUUID())) {
             MainUtil.sendMessage(
                 pp,
                 C.NOTIFY_LEAVE
                     .s()
                     .replace("%player", pp.getName())
                     .replace("%plot", plot.getId().toString()));
           }
         }
       }
     }
     if (FlagManager.getPlotFlagRaw(plot, "fly") != null) {
       PlotGameMode gamemode = pp.getGameMode();
       if (gamemode == PlotGameMode.SURVIVAL || (gamemode == PlotGameMode.ADVENTURE)) {
         pp.setFlight(false);
       }
     }
     if (FlagManager.getPlotFlagRaw(plot, "time") != null) {
       pp.setTime(Long.MAX_VALUE);
     }
     if (FlagManager.getPlotFlagRaw(plot, "weather") != null) {
       pp.setWeather(PlotWeather.RESET);
     }
     Location lastLoc = pp.getMeta("music");
     if (lastLoc != null) {
       pp.deleteMeta("music");
       pp.playMusic(lastLoc, 0);
     }
   }
   return true;
 }
Пример #2
0
 /**
  * @param plot
  * @return set of flags
  */
 public static HashMap<String, Flag> getPlotFlags(final Plot plot) {
   if (!plot.hasOwner()) {
     return null;
   }
   return getSettingFlags(plot.getArea(), plot.getSettings());
 }
Пример #3
0
  /**
   * Format a string with plot information.
   *
   * @param info
   * @param plot
   * @param player
   * @param full
   * @param whenDone
   */
  public static void format(
      String info, Plot plot, PlotPlayer player, boolean full, RunnableVal<String> whenDone) {
    int num = plot.getConnectedPlots().size();
    String alias = !plot.getAlias().isEmpty() ? plot.getAlias() : C.NONE.s();
    Location bot = plot.getCorners()[0];
    String biome = WorldUtil.IMP.getBiome(plot.getArea().worldname, bot.getX(), bot.getZ());
    String trusted = getPlayerList(plot.getTrusted());
    String members = getPlayerList(plot.getMembers());
    String denied = getPlayerList(plot.getDenied());
    String seen;
    if (Settings.Enabled_Components.PLOT_EXPIRY) {
      if (plot.isOnline()) {
        seen = C.NOW.s();
      } else {
        int time = (int) (ExpireManager.IMP.getAge(plot) / 1000);
        seen = time != 0 ? secToTime(time) : C.UNKNOWN.s();
      }
    } else {
      seen = C.NEVER.s();
    }
    Optional<String> descriptionFlag = plot.getFlag(Flags.DESCRIPTION);
    String description =
        descriptionFlag.isPresent()
            ? Flags.DESCRIPTION.valueToString(descriptionFlag.get())
            : C.NONE.s();

    StringBuilder flags = new StringBuilder();
    HashMap<Flag<?>, Object> flagMap =
        FlagManager.getPlotFlags(plot.getArea(), plot.getSettings(), true);
    if (flagMap.isEmpty()) {
      flags.append(C.NONE.s());
    } else {
      String prefix = "";
      for (Map.Entry<Flag<?>, Object> entry : flagMap.entrySet()) {
        flags.append(prefix).append(C.PLOT_FLAG_LIST.f(entry.getKey().getName(), entry.getValue()));
        prefix = ", ";
      }
    }
    boolean build = plot.isAdded(player.getUUID());
    String owner = plot.getOwners().isEmpty() ? "unowned" : getPlayerList(plot.getOwners());
    info = info.replace("%id%", plot.getId().toString());
    info = info.replace("%alias%", alias);
    info = info.replace("%num%", String.valueOf(num));
    info = info.replace("%desc%", description);
    info = info.replace("%biome%", biome);
    info = info.replace("%owner%", owner);
    info = info.replace("%members%", members);
    info = info.replace("%player%", player.getName());
    info = info.replace("%trusted%", trusted);
    info = info.replace("%helpers%", members);
    info = info.replace("%denied%", denied);
    info = info.replace("%seen%", seen);
    info = info.replace("%flags%", flags);
    info = info.replace("%build%", String.valueOf(build));
    info = info.replace("%desc%", "No description set.");
    if (info.contains("%rating%")) {
      String newInfo = info;
      TaskManager.runTaskAsync(
          () -> {
            int max = 10;
            if (Settings.Ratings.CATEGORIES != null && !Settings.Ratings.CATEGORIES.isEmpty()) {
              max = 8;
            }
            String info1;
            if (full
                && Settings.Ratings.CATEGORIES != null
                && Settings.Ratings.CATEGORIES.size() > 1) {
              double[] ratings = getAverageRatings(plot);
              String rating = "";
              String prefix = "";
              for (int i = 0; i < ratings.length; i++) {
                rating +=
                    prefix
                        + Settings.Ratings.CATEGORIES.get(i)
                        + '='
                        + String.format("%.1f", ratings[i]);
                prefix = ",";
              }
              info1 = newInfo.replaceAll("%rating%", rating);
            } else {
              info1 =
                  newInfo.replaceAll(
                      "%rating%", String.format("%.1f", plot.getAverageRating()) + '/' + max);
            }
            whenDone.run(info1);
          });
      return;
    }
    whenDone.run(info);
  }
Пример #4
0
 /**
  * Returns the raw flag<br>
  * - Faster - You should not modify the flag
  *
  * @param plot
  * @param flag
  * @return
  */
 public static Flag getPlotFlagRaw(final Plot plot, final String flag) {
   if (plot.owner == null) {
     return null;
   }
   return getSettingFlag(plot.getArea(), plot.getSettings(), flag);
 }
Пример #5
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;
  }