示例#1
0
 @Subscribe
 public void onRedstoneEvent(BlockRedstoneUpdateEvent event) {
   org.spongepowered.api.world.Location block = event.getLocation();
   Location loc = SpongeUtil.getLocation(block);
   if (loc == null || !PS.get().isPlotWorld(loc.getWorld())) {
     return;
   }
   Plot plot = MainUtil.getPlot(loc);
   if (plot == null || !plot.hasOwner()) {
     return;
   }
   if (event.getOldSignalStrength() > event.getNewSignalStrength()) {
     return;
   }
   if (Settings.REDSTONE_DISABLER) {
     if (UUIDHandler.getPlayer(plot.owner) == null) {
       boolean disable = true;
       for (UUID trusted : plot.getTrusted()) {
         if (UUIDHandler.getPlayer(trusted) != null) {
           disable = false;
           break;
         }
       }
       if (disable) {
         event.setNewSignalStrength(0);
         return;
       }
     }
   }
   Flag redstone = FlagManager.getPlotFlag(plot, "redstone");
   if (FlagManager.isPlotFlagFalse(plot, "redstone")) {
     event.setNewSignalStrength(0);
     // TODO only disable clocks
   }
 }
 @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
 public void onBigBoom(final BlockExplodeEvent event) {
   final Block block = event.getBlock();
   final Location loc = BukkitUtil.getLocation(block.getLocation());
   final String world = loc.getWorld();
   if (!PS.get().isPlotWorld(world)) {
     return;
   }
   final Plot plot = MainUtil.getPlotAbs(loc);
   if ((plot != null) && plot.hasOwner()) {
     if (FlagManager.isPlotFlagTrue(plot, "explosion")) {
       final Iterator<Block> iter = event.blockList().iterator();
       while (iter.hasNext()) {
         final Block b = iter.next();
         if (!plot.equals(MainUtil.getPlotAbs(BukkitUtil.getLocation(b.getLocation())))) {
           iter.remove();
         }
       }
       return;
     }
   }
   if (MainUtil.isPlotArea(loc)) {
     event.setCancelled(true);
   } else {
     final Iterator<Block> iter = event.blockList().iterator();
     while (iter.hasNext()) {
       iter.next();
       if (MainUtil.isPlotArea(loc)) {
         iter.remove();
       }
     }
   }
 }
示例#3
0
 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 UUIDWrapper initUUIDHandler() {
   final boolean checkVersion = checkVersion(1, 7, 6);
   if (Settings.OFFLINE_MODE) {
     if (Settings.UUID_LOWERCASE) {
       UUIDHandler.uuidWrapper = new LowerOfflineUUIDWrapper();
     } else {
       UUIDHandler.uuidWrapper = new OfflineUUIDWrapper();
     }
     Settings.OFFLINE_MODE = true;
   } else if (checkVersion) {
     UUIDHandler.uuidWrapper = new DefaultUUIDWrapper();
     Settings.OFFLINE_MODE = false;
   } else {
     if (Settings.UUID_LOWERCASE) {
       UUIDHandler.uuidWrapper = new LowerOfflineUUIDWrapper();
     } else {
       UUIDHandler.uuidWrapper = new OfflineUUIDWrapper();
     }
     Settings.OFFLINE_MODE = true;
   }
   if (!checkVersion) {
     log(
         C.PREFIX.s()
             + " &c[WARN] Titles are disabled - please update your version of Bukkit to support this feature.");
     Settings.TITLES = false;
     FlagManager.removeFlag(FlagManager.getFlag("titles"));
   } else {
     AbstractTitle.TITLE_CLASS = new DefaultTitle();
     if (UUIDHandler.uuidWrapper instanceof DefaultUUIDWrapper) {
       Settings.TWIN_MODE_UUID = true;
     } else if (UUIDHandler.uuidWrapper instanceof OfflineUUIDWrapper && !Bukkit.getOnlineMode()) {
       Settings.TWIN_MODE_UUID = true;
     }
   }
   if (Settings.OFFLINE_MODE) {
     log(
         C.PREFIX.s()
             + " &6PlotSquared is using Offline Mode UUIDs either because of user preference, or because you are using an old version of Bukkit");
   } else {
     log(C.PREFIX.s() + " &6PlotSquared is using online UUIDs");
   }
   return UUIDHandler.uuidWrapper;
 }
示例#5
0
 public static boolean isBooleanFlag(
     final Plot plot, final String key, final boolean defaultValue) {
   final Flag flag = FlagManager.getPlotFlagRaw(plot, key);
   if (flag == null) {
     return defaultValue;
   }
   final Object value = flag.getValue();
   if (value instanceof Boolean) {
     return (boolean) value;
   }
   return defaultValue;
 }
示例#6
0
 @Subscribe
 public void onBlockPlace(PlayerPlaceBlockEvent event) {
   Player player = event.getEntity();
   World world = player.getWorld();
   String worldname = world.getName();
   org.spongepowered.api.world.Location blockLoc = event.getLocation();
   final Location loc = SpongeUtil.getLocation(worldname, blockLoc);
   final Plot plot = MainUtil.getPlot(loc);
   if (plot != null) {
     if (blockLoc.getY() == 0) {
       event.setCancelled(true);
       return;
     }
     final PlotPlayer pp = SpongeUtil.getPlayer(player);
     if (!plot.hasOwner()) {
       if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_UNOWNED)) {
         return;
       }
       MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_UNOWNED);
       event.setCancelled(true);
       return;
     } else if (!plot.isAdded(pp.getUUID())) {
       final Flag destroy = FlagManager.getPlotFlag(plot, "place");
       BlockState state = blockLoc.getBlock();
       if ((destroy != null)
           && ((HashSet<PlotBlock>) destroy.getValue())
               .contains(SpongeMain.THIS.getPlotBlock(state))) {
         return;
       }
       if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER)) {
         return;
       }
       MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_DESTROY_OTHER);
       event.setCancelled(true);
     } else if (Settings.DONE_RESTRICTS_BUILDING && plot.getSettings().flags.containsKey("done")) {
       if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER)) {
         MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_OTHER);
         event.setCancelled(true);
         return;
       }
     }
     return;
   }
   final PlotPlayer pp = SpongeUtil.getPlayer(player);
   if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_ROAD)) {
     return;
   }
   if (MainUtil.isPlotArea(loc)) {
     MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_ROAD);
     event.setCancelled(true);
   }
 }
示例#7
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;
  }
示例#8
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;
 }
示例#9
0
 @Subscribe
 public void onBigBoom(final WorldOnExplosionEvent event) {
   World worldObj = event.getWorld();
   final String world = worldObj.getName();
   if (!PS.get().isPlotWorld(world)) {
     return;
   }
   Explosion explosion = event.getExplosion();
   Vector3d origin = explosion.getOrigin();
   Location loc = new Location(world, origin.getFloorX(), origin.getFloorY(), origin.getFloorZ());
   final Plot plot = MainUtil.getPlot(loc);
   if ((plot != null) && plot.hasOwner()) {
     if (FlagManager.isPlotFlagTrue(plot, "explosion")) {
       event.filterLocations(
           new Predicate<org.spongepowered.api.world.Location<World>>() {
             @Override
             public boolean apply(org.spongepowered.api.world.Location loc) {
               if (!plot.equals(MainUtil.getPlot(SpongeUtil.getLocation(loc)))) {
                 return false;
               }
               return true;
             }
           });
       event.filterEntities(
           new Predicate<Entity>() {
             @Override
             public boolean apply(Entity entity) {
               if (!plot.equals(MainUtil.getPlot(SpongeUtil.getLocation(entity)))) {
                 return false;
               }
               return true;
             }
           });
       return;
     }
   }
   if (MainUtil.isPlotArea(loc)) {
     explosion.shouldBreakBlocks(false);
     explosion.canCauseFire(false);
     explosion.setRadius(0);
     event.filterEntities(
         new Predicate<Entity>() {
           @Override
           public boolean apply(Entity entity) {
             if (!plot.equals(MainUtil.getPlot(SpongeUtil.getLocation(entity)))) {
               return false;
             }
             return true;
           }
         });
     return;
   } else {
     if (FlagManager.isPlotFlagTrue(plot, "explosion")) {
       event.filterLocations(
           new Predicate<org.spongepowered.api.world.Location<World>>() {
             @Override
             public boolean apply(org.spongepowered.api.world.Location loc) {
               if (!plot.equals(MainUtil.getPlot(SpongeUtil.getLocation(loc)))) {
                 return false;
               }
               return true;
             }
           });
       event.filterEntities(
           new Predicate<Entity>() {
             @Override
             public boolean apply(Entity entity) {
               if (!plot.equals(MainUtil.getPlot(SpongeUtil.getLocation(entity)))) {
                 return false;
               }
               return true;
             }
           });
       return;
     }
   }
 }
示例#10
0
  @Subscribe
  public void onMobSpawn(EntitySpawnEvent event) {
    Entity entity = event.getEntity();
    if (entity instanceof Player) {
      return;
    }
    final Location loc = SpongeUtil.getLocation(event.getLocation());
    final String world = loc.getWorld();
    PlotWorld plotworld = PS.get().getPlotWorld(world);
    if (plotworld == null) {
      return;
    }
    Plot plot = MainUtil.getPlot(loc);
    if (plot == null) {
      if (MainUtil.isPlotRoad(loc)) {
        event.setCancelled(true);
      }
      return;
    }
    final PlotWorld pW = PS.get().getPlotWorld(world);

    // TODO selectively cancel depending on spawn reason
    // - Not sure if possible to get spawn reason (since there are no callbacks)

    if (entity.getType() == EntityTypes.DROPPED_ITEM) {
      if (FlagManager.isPlotFlagFalse(plot, "item-drop")) {
        event.setCancelled(true);
      }
      return;
    }
    int[] mobs = null;
    if (entity instanceof Living) {
      if (!plotworld.MOB_SPAWNING) {
        event.setCancelled(true);
        return;
      }
      Flag mobCap = FlagManager.getPlotFlag(plot, "mob-cap");
      if (mobCap != null) {
        Integer cap = (Integer) mobCap.getValue();
        if (cap == 0) {
          event.setCancelled(true);
          return;
        }
        if (mobs == null) mobs = ChunkManager.manager.countEntities(plot);
        if (mobs[3] >= cap) {
          event.setCancelled(true);
          return;
        }
      }
      if (entity instanceof Ambient || entity instanceof Animal) {
        Flag animalFlag = FlagManager.getPlotFlag(plot, "animal-cap");
        if (animalFlag != null) {
          int cap = ((Integer) animalFlag.getValue());
          if (cap == 0) {
            event.setCancelled(true);
            return;
          }
          if (mobs == null) mobs = ChunkManager.manager.countEntities(plot);
          if (mobs[1] >= cap) {
            event.setCancelled(true);
            return;
          }
        }
      }
      if (entity instanceof Monster) {
        Flag monsterFlag = FlagManager.getPlotFlag(plot, "hostile-cap");
        if (monsterFlag != null) {
          int cap = ((Integer) monsterFlag.getValue());
          if (cap == 0) {
            event.setCancelled(true);
            return;
          }
          if (mobs == null) mobs = ChunkManager.manager.countEntities(plot);
          if (mobs[2] >= cap) {
            event.setCancelled(true);
            return;
          }
        }
      }
      return;
    }
    if (entity instanceof Minecart || entity instanceof Boat) {
      Flag vehicleFlag = FlagManager.getPlotFlag(plot, "vehicle-cap");
      if (vehicleFlag != null) {
        int cap = ((Integer) vehicleFlag.getValue());
        if (cap == 0) {
          event.setCancelled(true);
          return;
        }
        if (mobs == null) mobs = ChunkManager.manager.countEntities(plot);
        if (mobs[4] >= cap) {
          event.setCancelled(true);
          return;
        }
      }
    }
    Flag entityCap = FlagManager.getPlotFlag(plot, "entity-cap");
    if (entityCap != null) {
      Integer cap = (Integer) entityCap.getValue();
      if (cap == 0) {
        event.setCancelled(true);
        return;
      }
      if (mobs == null) mobs = ChunkManager.manager.countEntities(plot);
      if (mobs[0] >= cap) {
        event.setCancelled(true);
        return;
      }
    }
  }
示例#11
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);
  }
示例#12
0
 @Override
 public boolean onCommand(final PlotPlayer plr, final String... args) {
   final Location loc = plr.getLocation();
   final Plot plot;
   if (args.length == 1) {
     if (args[0].equalsIgnoreCase("mine")) {
       Set<Plot> plots = plr.getPlots();
       if (plots.size() > 0) {
         plot = plots.iterator().next();
       } else {
         MainUtil.sendMessage(plr, C.NO_PLOTS);
         return false;
       }
     } else {
       plot = MainUtil.getPlotFromString(plr, args[0], true);
     }
     if (plot == null) {
       MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot clear [X;Z|mine]");
       return false;
     }
   } else if (args.length == 0) {
     plot = MainUtil.getPlotAbs(loc);
     if (plot == null) {
       MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot clear [X;Z|mine]");
       C.NOT_IN_PLOT.send(plr);
       return false;
     }
   } else {
     MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot clear [X;Z|mine]");
     return false;
   }
   if ((!plot.hasOwner() || !plot.isOwner(plr.getUUID()))
       && !Permissions.hasPermission(plr, "plots.admin.command.clear")) {
     return sendMessage(plr, C.NO_PLOT_PERMS);
   }
   if (plot.getRunning() != 0) {
     MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
     return false;
   }
   if ((FlagManager.getPlotFlagRaw(plot, "done") != null)
       && (!Permissions.hasPermission(plr, "plots.continue")
           || (Settings.DONE_COUNTS_TOWARDS_LIMIT
               && (MainUtil.getAllowedPlots(plr) >= MainUtil.getPlayerPlotCount(plr))))) {
     MainUtil.sendMessage(plr, C.DONE_ALREADY_DONE);
     return false;
   }
   final Runnable runnable =
       new Runnable() {
         @Override
         public void run() {
           final long start = System.currentTimeMillis();
           final boolean result =
               MainUtil.clearAsPlayer(
                   plot,
                   plot.owner == null,
                   new Runnable() {
                     @Override
                     public void run() {
                       plot.unlink();
                       SetBlockQueue.addNotify(
                           new Runnable() {
                             @Override
                             public void run() {
                               plot.removeRunning();
                               // If the state changes, then mark it as no longer done
                               if (FlagManager.getPlotFlagRaw(plot, "done") != null) {
                                 FlagManager.removePlotFlag(plot, "done");
                               }
                               if (FlagManager.getPlotFlagRaw(plot, "analysis") != null) {
                                 FlagManager.removePlotFlag(plot, "analysis");
                               }
                               MainUtil.sendMessage(
                                   plr,
                                   C.CLEARING_DONE,
                                   "" + (System.currentTimeMillis() - start));
                             }
                           });
                     }
                   });
           if (!result) {
             MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
           } else {
             plot.addRunning();
           }
         }
       };
   if (Settings.CONFIRM_CLEAR && !(Permissions.hasPermission(plr, "plots.confirm.bypass"))) {
     CmdConfirm.addPending(plr, "/plot clear " + plot.id, runnable);
   } else {
     TaskManager.runTask(runnable);
   }
   return true;
 }
示例#13
0
 @Override
 public boolean onCommand(final PlotPlayer player, final String... args) {
   final List<String> allowed_params =
       Arrays.asList(
           "calibrate-analysis",
           "remove-flag",
           "stop-expire",
           "start-expire",
           "show-expired",
           "update-expired",
           "seen",
           "trim-check");
   if (args.length > 0) {
     final String arg = args[0].toLowerCase();
     String script;
     boolean async = false;
     switch (arg) {
       case "analyze":
         {
           final Plot plot = MainUtil.getPlotAbs(player.getLocation());
           if (plot == null) {
             MainUtil.sendMessage(player, C.NOT_IN_PLOT);
             return false;
           }
           final PlotAnalysis analysis = plot.getComplexity();
           if (analysis != null) {
             final int complexity = analysis.getComplexity();
             MainUtil.sendMessage(player, "Changes/column: " + (analysis.changes / 1.0));
             MainUtil.sendMessage(player, "Complexity: " + complexity);
             return true;
           }
           MainUtil.sendMessage(player, "$1Starting task...");
           HybridUtils.manager.analyzePlot(
               plot,
               new RunnableVal<PlotAnalysis>() {
                 @Override
                 public void run() {
                   MainUtil.sendMessage(
                       player, "$1Done: $2use $3/plot debugexec analyze$2 for more information");
                 }
               });
           return true;
         }
       case "calibrate-analysis":
         {
           if (args.length != 2) {
             MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot debugexec analyze <threshold>");
             MainUtil.sendMessage(
                 player,
                 "$1<threshold> $2= $1The percentage of plots you want to clear (100 clears 100% of plots so no point calibrating it)");
             return false;
           }
           double threshold;
           try {
             threshold = Integer.parseInt(args[1]) / 100d;
           } catch (final NumberFormatException e) {
             MainUtil.sendMessage(player, "$2Invalid threshold: " + args[1]);
             MainUtil.sendMessage(
                 player,
                 "$1<threshold> $2= $1The percentage of plots you want to clear as a number between 0 - 100");
             return false;
           }
           PlotAnalysis.calcOptimalModifiers(
               new Runnable() {
                 @Override
                 public void run() {
                   MainUtil.sendMessage(
                       player, "$1Thank you for calibrating PlotSquared plot expiry");
                 }
               },
               threshold);
           return true;
         }
       case "stop-expire":
         {
           if (ExpireManager.task != -1) {
             PS.get().TASK.cancelTask(ExpireManager.task);
           } else {
             return MainUtil.sendMessage(player, "Task already halted");
           }
           ExpireManager.task = -1;
           return MainUtil.sendMessage(player, "Cancelled task.");
         }
       case "remove-flag":
         {
           if (args.length != 2) {
             MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot debugexec remove-flag <flag>");
             return false;
           }
           final String flag = args[1];
           for (final Plot plot : PS.get().getPlots()) {
             if (FlagManager.getPlotFlagRaw(plot, flag) != null) {
               FlagManager.removePlotFlag(plot, flag);
             }
           }
           return MainUtil.sendMessage(player, "Cleared flag: " + flag);
         }
       case "start-rgar":
         {
           if (args.length != 2) {
             MainUtil.sendMessage(player, "&cInvalid syntax: /plot debugexec start-rgar <world>");
             return false;
           }
           boolean result;
           if (!PS.get().isPlotWorld(args[1])) {
             MainUtil.sendMessage(player, C.NOT_VALID_PLOT_WORLD, args[1]);
             return false;
           }
           if (HybridUtils.regions != null) {
             result =
                 ((BukkitHybridUtils) (HybridUtils.manager))
                     .scheduleRoadUpdate(args[1], HybridUtils.regions, 0);
           } else {
             result = HybridUtils.manager.scheduleRoadUpdate(args[1], 0);
           }
           if (!result) {
             MainUtil.sendMessage(
                 player, "&cCannot schedule mass schematic update! (Is one already in progress?)");
             return false;
           }
           return true;
         }
       case "stop-rgar":
         {
           if (!HybridUtils.UPDATE) {
             MainUtil.sendMessage(player, "&cTASK NOT RUNNING!");
             return false;
           }
           HybridUtils.UPDATE = false;
           MainUtil.sendMessage(player, "&cCancelling task... (please wait)");
           return true;
         }
       case "start-expire":
         {
           if (ExpireManager.task == -1) {
             ExpireManager.runTask();
           } else {
             return MainUtil.sendMessage(player, "Plot expiry task already started");
           }
           return MainUtil.sendMessage(player, "Started plot expiry task");
         }
       case "update-expired":
         {
           if (args.length > 1) {
             final String world = args[1];
             if (!BlockManager.manager.isWorld(world)) {
               return MainUtil.sendMessage(player, "Invalid world: " + args[1]);
             }
             MainUtil.sendMessage(player, "Updating expired plot list");
             ExpireManager.updateExpired(args[1]);
             return true;
           }
           return MainUtil.sendMessage(player, "Use /plot debugexec update-expired <world>");
         }
       case "show-expired":
         {
           if (args.length > 1) {
             final String world = args[1];
             if (!BlockManager.manager.isWorld(world)) {
               return MainUtil.sendMessage(player, "Invalid world: " + args[1]);
             }
             if (!ExpireManager.expiredPlots.containsKey(args[1])) {
               return MainUtil.sendMessage(player, "No task for world: " + args[1]);
             }
             MainUtil.sendMessage(
                 player,
                 "Expired plots (" + ExpireManager.expiredPlots.get(args[1]).size() + "):");
             for (final Plot plot : ExpireManager.expiredPlots.get(args[1])) {
               MainUtil.sendMessage(
                   player,
                   " - "
                       + plot.world
                       + ";"
                       + plot.id.x
                       + ";"
                       + plot.id.y
                       + ";"
                       + UUIDHandler.getName(plot.owner)
                       + " : "
                       + ExpireManager.dates.get(plot.owner));
             }
             return true;
           }
           return MainUtil.sendMessage(player, "Use /plot debugexec show-expired <world>");
         }
       case "seen":
         {
           if (args.length != 2) {
             return MainUtil.sendMessage(player, "Use /plot debugexec seen <player>");
           }
           final UUID uuid = UUIDHandler.getUUID(args[1], null);
           if (uuid == null) {
             return MainUtil.sendMessage(player, "player not found: " + args[1]);
           }
           final OfflinePlotPlayer op = UUIDHandler.getUUIDWrapper().getOfflinePlayer(uuid);
           if ((op == null) || (op.getLastPlayed() == 0)) {
             return MainUtil.sendMessage(player, "player hasn't connected before: " + args[1]);
           }
           final Timestamp stamp = new Timestamp(op.getLastPlayed());
           final Date date = new Date(stamp.getTime());
           MainUtil.sendMessage(player, "PLAYER: " + args[1]);
           MainUtil.sendMessage(player, "UUID: " + uuid);
           MainUtil.sendMessage(player, "Object: " + date.toGMTString());
           MainUtil.sendMessage(player, "GMT: " + date.toGMTString());
           MainUtil.sendMessage(player, "Local: " + date.toLocaleString());
           return true;
         }
       case "trim-check":
         {
           if (args.length != 2) {
             MainUtil.sendMessage(player, "Use /plot debugexec trim-check <world>");
             MainUtil.sendMessage(player, "&7 - Generates a list of regions to trim");
             return MainUtil.sendMessage(player, "&7 - Run after plot expiry has run");
           }
           final String world = args[1];
           if (!BlockManager.manager.isWorld(world) || !PS.get().isPlotWorld(args[1])) {
             return MainUtil.sendMessage(player, "Invalid world: " + args[1]);
           }
           final ArrayList<ChunkLoc> empty = new ArrayList<>();
           final boolean result =
               Trim.getTrimRegions(
                   empty,
                   world,
                   new Runnable() {
                     @Override
                     public void run() {
                       Trim.sendMessage(
                           "Processing is complete! Here's how many chunks would be deleted:");
                       Trim.sendMessage(" - MCA #: " + empty.size());
                       Trim.sendMessage(" - CHUNKS: " + (empty.size() * 1024) + " (max)");
                       Trim.sendMessage("Exporting log for manual approval...");
                       final File file =
                           new File(PS.get().IMP.getDirectory() + File.separator + "trim.txt");
                       PrintWriter writer;
                       try {
                         writer = new PrintWriter(file);
                         for (final ChunkLoc loc : empty) {
                           writer.println(world + "/region/r." + loc.x + "." + loc.z + ".mca");
                         }
                         writer.close();
                         Trim.sendMessage("File saved to 'plugins/PlotSquared/trim.txt'");
                       } catch (final FileNotFoundException e) {
                         e.printStackTrace();
                         Trim.sendMessage("File failed to save! :(");
                       }
                       Trim.sendMessage("How to get the chunk coords from a region file:");
                       Trim.sendMessage(
                           " - Locate the x,z values for the region file (the two numbers which are separated by a dot)");
                       Trim.sendMessage(
                           " - Multiply each number by 32; this gives you the starting position");
                       Trim.sendMessage(" - Add 31 to each number to get the end position");
                     }
                   });
           if (!result) {
             MainUtil.sendMessage(player, "Trim task already started!");
           }
           return result;
         }
       case "h":
       case "he":
       case "?":
       case "help":
         {
           MainUtil.sendMessage(
               player,
               "Possible sub commands: /plot debugexec <"
                   + StringMan.join(allowed_params, "|")
                   + ">");
           return false;
         }
       case "addcmd":
         {
           try {
             final String cmd =
                 StringMan.join(
                     Files.readLines(
                         new File(
                             new File(PS.get().IMP.getDirectory() + File.separator + "scripts"),
                             args[1]),
                         StandardCharsets.UTF_8),
                     System.getProperty("line.separator"));
             final Command<PlotPlayer> subcommand =
                 new Command<PlotPlayer>(args[1].split("\\.")[0]) {
                   @Override
                   public boolean onCommand(final PlotPlayer plr, final String[] args) {
                     try {
                       scope.put("PlotPlayer", plr);
                       scope.put("args", args);
                       engine.eval(cmd, scope);
                       return true;
                     } catch (final ScriptException e) {
                       e.printStackTrace();
                       MainUtil.sendMessage(player, C.COMMAND_WENT_WRONG);
                       return false;
                     }
                   }
                 };
             MainCommand.getInstance().addCommand(subcommand);
             return true;
           } catch (final Exception e) {
             e.printStackTrace();
             MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot debugexec addcmd <file>");
             return false;
           }
         }
       case "runasync":
         {
           async = true;
         }
       case "run":
         {
           try {
             script =
                 StringMan.join(
                     Files.readLines(
                         new File(
                             new File(PS.get().IMP.getDirectory() + File.separator + "scripts"),
                             args[1]),
                         StandardCharsets.UTF_8),
                     System.getProperty("line.separator"));
             if (args.length > 2) {
               final HashMap<String, String> replacements = new HashMap<>();
               for (int i = 2; i < args.length; i++) {
                 replacements.put("%s" + (i - 2), args[i]);
               }
               script = StringMan.replaceFromMap(script, replacements);
             }
           } catch (final IOException e) {
             e.printStackTrace();
             return false;
           }
           break;
         }
       default:
         {
           script = StringMan.join(args, " ");
         }
     }
     if (!ConsolePlayer.isConsole(player)) {
       MainUtil.sendMessage(player, C.NOT_CONSOLE);
       return false;
     }
     init();
     scope.put("PlotPlayer", player);
     PS.debug("> " + script);
     try {
       if (async) {
         final String toExec = script;
         TaskManager.runTaskAsync(
             new Runnable() {
               @Override
               public void run() {
                 final long start = System.currentTimeMillis();
                 Object result = null;
                 try {
                   result = engine.eval(toExec, scope);
                 } catch (final ScriptException e) {
                   e.printStackTrace();
                 }
                 PS.log("> " + (System.currentTimeMillis() - start) + "ms -> " + result);
               }
             });
       } else {
         final long start = System.currentTimeMillis();
         Object result = engine.eval(script, scope);
         PS.log("> " + (System.currentTimeMillis() - start) + "ms -> " + result);
       }
       return true;
     } catch (final ScriptException e) {
       e.printStackTrace();
       return false;
     }
   }
   return false;
 }