Beispiel #1
0
  public static boolean plotEntry(final PlotPlayer pp, final Plot plot) {
    if (plot.isDenied(pp.getUUID()) && !Permissions.hasPermission(pp, "plots.admin.entry.denied")) {
      return false;
    }
    Plot last = pp.getMeta("lastplot");
    if ((last != null) && !last.getId().equals(plot.getId())) {
      plotExit(pp, last);
    }
    if (ExpireManager.IMP != null) {
      ExpireManager.IMP.handleEntry(pp, plot);
    }
    pp.setMeta("lastplot", plot);
    EventUtil.manager.callEntry(pp, plot);
    if (plot.hasOwner()) {
      HashMap<String, Flag> flags = FlagManager.getPlotFlags(plot);
      int size = flags.size();
      boolean titles = Settings.TITLES;
      final String greeting;

      if (size != 0) {
        Flag titleFlag = flags.get("titles");
        if (titleFlag != null) {
          titles = (Boolean) titleFlag.getValue();
        }
        Flag greetingFlag = flags.get("greeting");
        if (greetingFlag != null) {
          greeting = (String) greetingFlag.getValue();
          MainUtil.format(
              C.PREFIX_GREETING.s() + greeting,
              plot,
              pp,
              false,
              new RunnableVal<String>() {
                @Override
                public void run(String value) {
                  MainUtil.sendMessage(pp, value);
                }
              });
        } else {
          greeting = "";
        }
        Flag enter = flags.get("notify-enter");
        if (enter != null && (Boolean) enter.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(
                    owner,
                    C.NOTIFY_ENTER
                        .s()
                        .replace("%player", pp.getName())
                        .replace("%plot", plot.getId().toString()));
              }
            }
          }
        }
        Flag gamemodeFlag = flags.get("gamemode");
        if (gamemodeFlag != null) {
          if (pp.getGameMode() != gamemodeFlag.getValue()) {
            if (!Permissions.hasPermission(pp, "plots.gamemode.bypass")) {
              pp.setGameMode((PlotGameMode) gamemodeFlag.getValue());
            } else {
              MainUtil.sendMessage(
                  pp,
                  StringMan.replaceAll(
                      C.GAMEMODE_WAS_BYPASSED.s(),
                      "{plot}",
                      plot.getId(),
                      "{gamemode}",
                      gamemodeFlag.getValue()));
            }
          }
        }
        Flag flyFlag = flags.get("fly");
        if (flyFlag != null) {
          pp.setFlight((boolean) flyFlag.getValue());
        }
        Flag timeFlag = flags.get("time");
        if (timeFlag != null) {
          try {
            long time = (long) timeFlag.getValue();
            pp.setTime(time);
          } catch (Exception e) {
            FlagManager.removePlotFlag(plot, "time");
          }
        }
        Flag weatherFlag = flags.get("weather");
        if (weatherFlag != null) {
          pp.setWeather((PlotWeather) weatherFlag.getValue());
        }

        Flag musicFlag = flags.get("music");
        if (musicFlag != null) {
          Integer id = (Integer) musicFlag.getValue();
          if ((id >= 2256 && id <= 2267) || (id == 0)) {
            Location loc = pp.getLocation();
            Location lastLoc = pp.getMeta("music");
            if (lastLoc != null) {
              pp.playMusic(lastLoc, 0);
              if (id == 0) {
                pp.deleteMeta("music");
              }
            }
            if (id != 0) {
              try {
                pp.setMeta("music", loc);
                pp.playMusic(loc, id);
              } catch (Exception ignored) {
              }
            }
          }
        } else {
          Location lastLoc = pp.getMeta("music");
          if (lastLoc != null) {
            pp.deleteMeta("music");
            pp.playMusic(lastLoc, 0);
          }
        }
        CommentManager.sendTitle(pp, plot);
      } else if (titles) {
        greeting = "";
      } else {
        return true;
      }
      if (titles) {
        if (!C.TITLE_ENTERED_PLOT.s().isEmpty() || !C.TITLE_ENTERED_PLOT_SUB.s().isEmpty()) {
          TaskManager.runTaskLaterAsync(
              new Runnable() {
                @Override
                public void run() {
                  Plot lastPlot = pp.getMeta("lastplot");
                  if ((lastPlot != null) && plot.getId().equals(lastPlot.getId())) {
                    Map<String, String> replacements = new HashMap<>();
                    replacements.put("%x%", lastPlot.getId().x + "");
                    replacements.put("%z%", lastPlot.getId().y + "");
                    replacements.put("%world%", plot.getArea().toString());
                    replacements.put("%greeting%", greeting);
                    replacements.put("%alias", plot.toString());
                    replacements.put("%s", MainUtil.getName(plot.owner));
                    String main = StringMan.replaceFromMap(C.TITLE_ENTERED_PLOT.s(), replacements);
                    String sub =
                        StringMan.replaceFromMap(C.TITLE_ENTERED_PLOT_SUB.s(), replacements);
                    AbstractTitle.sendTitle(pp, main, sub);
                  }
                }
              },
              20);
        }
      }
      return true;
    }
    return true;
  }
Beispiel #2
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);
  }