コード例 #1
0
ファイル: Trim.java プロジェクト: Hiddd/PlotSquared
  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;
  }
コード例 #2
0
  @Override
  public void runEntityTask() {
    log(C.PREFIX.s() + "KillAllEntities started.");
    TaskManager.runTaskRepeat(
        new Runnable() {
          long ticked = 0l;
          long error = 0l;

          @Override
          public void run() {
            if (this.ticked > 36_000L) {
              this.ticked = 0l;
              if (this.error > 0) {
                log(
                    C.PREFIX.s()
                        + "KillAllEntities has been running for 6 hours. Errors: "
                        + this.error);
              }
              this.error = 0l;
            }
            World world;
            for (final String w : PS.get().getPlotWorlds()) {
              world = Bukkit.getWorld(w);
              try {
                if (world.getLoadedChunks().length < 1) {
                  continue;
                }
                for (final Chunk chunk : world.getLoadedChunks()) {
                  final Entity[] entities = chunk.getEntities();
                  Entity entity;
                  for (int i = entities.length - 1; i >= 0; i--) {
                    if (!((entity = entities[i]) instanceof Player)
                        && (MainUtil.getPlot(BukkitUtil.getLocation(entity)) == null)) {
                      entity.remove();
                    }
                  }
                }
              } catch (final Throwable e) {
                ++this.error;
              } finally {
                ++this.ticked;
              }
            }
          }
        },
        20);
  }