Example #1
0
 @Override
 public boolean onCommand(final PlotPlayer plr, final String[] args) {
   if (args.length == 1) {
     final String arg = args[0].toLowerCase();
     final PlotId id = getId(arg);
     if (id != null) {
       MainUtil.sendMessage(plr, "/plot trim x;z &l<world>");
       return false;
     }
     if (arg.equals("all")) {
       MainUtil.sendMessage(plr, "/plot trim all &l<world>");
       return false;
     }
     MainUtil.sendMessage(plr, C.TRIM_SYNTAX);
     return false;
   }
   if (args.length != 2) {
     MainUtil.sendMessage(plr, C.TRIM_SYNTAX);
     return false;
   }
   final String arg = args[0].toLowerCase();
   if (!arg.equals("all")) {
     MainUtil.sendMessage(plr, C.TRIM_SYNTAX);
     return false;
   }
   final String world = args[1];
   if (!BlockManager.manager.isWorld(world) || (PS.get().getPlotWorld(world) == null)) {
     MainUtil.sendMessage(plr, C.NOT_VALID_WORLD);
     return false;
   }
   if (Trim.TASK) {
     sendMessage(C.TRIM_IN_PROGRESS.s());
     return false;
   }
   sendMessage(C.TRIM_START.s());
   final ArrayList<ChunkLoc> empty = new ArrayList<>();
   getTrimRegions(
       empty,
       world,
       new Runnable() {
         public void run() {
           deleteChunks(
               world,
               empty,
               new Runnable() {
                 @Override
                 public void run() {
                   PS.log("$1Trim task complete!");
                 }
               });
         }
       });
   return true;
 }
Example #2
0
  public static boolean getTrimRegions(
      final ArrayList<ChunkLoc> empty, final String world, final Runnable whenDone) {
    if (Trim.TASK) {
      return false;
    }
    System.currentTimeMillis();
    sendMessage("Collecting region data...");
    final ArrayList<Plot> plots = new ArrayList<>();
    plots.addAll(PS.get().getPlotsInWorld(world));
    final HashSet<ChunkLoc> chunks = new HashSet<>(ChunkManager.manager.getChunkChunks(world));
    sendMessage(" - MCA #: " + chunks.size());
    sendMessage(" - CHUNKS: " + (chunks.size() * 1024) + " (max)");
    sendMessage(" - TIME ESTIMATE: " + (chunks.size() / 1200) + " minutes");
    Trim.TASK_ID =
        TaskManager.runTaskRepeat(
            new Runnable() {
              @Override
              public void run() {
                final long start = System.currentTimeMillis();
                while ((System.currentTimeMillis() - start) < 50) {
                  if (plots.size() == 0) {
                    empty.addAll(chunks);
                    Trim.TASK = false;
                    TaskManager.runTaskAsync(whenDone);
                    PS.get().TASK.cancelTask(Trim.TASK_ID);
                    return;
                  }
                  final Plot plot = plots.remove(0);

                  final Location pos1 = MainUtil.getPlotBottomLoc(world, plot.id);
                  final Location pos2 = MainUtil.getPlotTopLoc(world, plot.id);

                  final int ccx1 = (pos1.getX() >> 9);
                  final int ccz1 = (pos1.getZ() >> 9);
                  final int ccx2 = (pos2.getX() >> 9);
                  final int ccz2 = (pos2.getZ() >> 9);

                  for (int x = ccx1; x <= ccx2; x++) {
                    for (int z = ccz1; z <= ccz2; z++) {
                      chunks.remove(new ChunkLoc(x, z));
                    }
                  }
                }
              }
            },
            20);
    Trim.TASK = true;
    return true;
  }