Esempio n. 1
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);
  }
Esempio n. 2
0
 public static void runTask() {
   ExpireManager.task =
       TaskManager.runTaskRepeat(
           new Runnable() {
             @Override
             public void run() {
               try {
                 for (final String world : PS.get().getPlotWorldsString()) {
                   if (!ExpireManager.updatingPlots.containsKey(world)) {
                     ExpireManager.updatingPlots.put(world, false);
                   }
                   final Boolean updating = ExpireManager.updatingPlots.get(world);
                   if (updating) {
                     PS.debug("$2[&5Expire&dManager$2] $4Waiting on fetch...");
                     return;
                   }
                   if (!expiredPlots.containsKey(world)) {
                     PS.debug("$2[&5Expire&dManager$2] $4Updating expired plots for: " + world);
                     updateExpired(world);
                     return;
                   }
                   final List<Plot> plots = expiredPlots.get(world);
                   if ((plots == null) || (plots.size() == 0)) {
                     if (updateExpired(world)) {
                       PS.debug(
                           "$2[&5Expire&dManager$2] $4Re-evaluating expired plots for: " + world);
                       return;
                     }
                     continue;
                   }
                   final Plot plot = plots.iterator().next();
                   if (!isExpired(plot)) {
                     expiredPlots.get(world).remove(plot);
                     PS.debug("$2[&5Expire&dManager$2] &bSkipping no longer expired: " + plot);
                     return;
                   }
                   for (final UUID helper : plot.getTrusted()) {
                     final PlotPlayer player = UUIDHandler.getPlayer(helper);
                     if (player != null) {
                       MainUtil.sendMessage(player, C.PLOT_REMOVED_USER, plot.id.toString());
                     }
                   }
                   for (final UUID helper : plot.getMembers()) {
                     final PlotPlayer player = UUIDHandler.getPlayer(helper);
                     if (player != null) {
                       MainUtil.sendMessage(player, C.PLOT_REMOVED_USER, plot.id.toString());
                     }
                   }
                   final PlotManager manager = PS.get().getPlotManager(world);
                   if (manager == null) {
                     PS.debug(
                         "$2[&5Expire&dManager$2] &cThis is a friendly reminder to create or delete "
                             + world
                             + " as it is currently setup incorrectly");
                     expiredPlots.get(world).remove(plot);
                     return;
                   }
                   final PlotWorld plotworld = PS.get().getPlotWorld(world);
                   RunnableVal<PlotAnalysis> run =
                       new RunnableVal<PlotAnalysis>() {
                         @Override
                         public void run() {
                           PlotAnalysis changed = this.value;
                           if (Settings.CLEAR_THRESHOLD != -1
                               && plotworld.TYPE == 0
                               && changed != null) {
                             if (changed.getComplexity() > Settings.CLEAR_THRESHOLD) {
                               PS.debug(
                                   "$2[&5Expire&dManager$2] &bIgnoring modified plot: "
                                       + plot
                                       + " : "
                                       + changed.getComplexity()
                                       + " - "
                                       + changed.changes);
                               expiredPlots.get(world).remove(plot);
                               FlagManager.addPlotFlag(
                                   plot, new Flag(FlagManager.getFlag("analysis"), value));
                               return;
                             }
                           }
                           if (plot.isMerged()) {
                             MainUtil.unlinkPlot(plot);
                           }
                           plot.deletePlot(null);
                           expiredPlots.get(world).remove(plot);
                           int complexity = changed == null ? 0 : changed.getComplexity();
                           int modified = changed == null ? 0 : changed.changes;
                           PS.debug(
                               "$2[&5Expire&dManager$2] &cDeleted expired plot: "
                                   + plot
                                   + " : "
                                   + complexity
                                   + " - "
                                   + modified);
                           PS.debug("$4 - World: " + plot.world);
                           if (plot.hasOwner()) {
                             PS.debug("$4 - Owner: " + UUIDHandler.getName(plot.owner));
                           } else {
                             PS.debug("$4 - Owner: Unowned");
                           }
                         }
                       };
                   if (MainUtil.runners.containsKey(plot)) {
                     PS.debug("$2[&5Expire&dManager$2] &bSkipping plot in use: " + plot);
                     expiredPlots.get(world).remove(plot);
                     this.run();
                     return;
                   }
                   if (Settings.CLEAR_THRESHOLD != -1 && plotworld.TYPE == 0) {
                     PlotAnalysis analysis = plot.getComplexity();
                     if (analysis != null) {
                       if (analysis.getComplexity() > Settings.CLEAR_THRESHOLD) {
                         PS.debug("$2[&5Expire&dManager$2] &bSkipping modified: " + plot);
                         expiredPlots.get(world).remove(plot);
                         this.run();
                         return;
                       }
                     }
                     HybridUtils.manager.analyzePlot(plot, run);
                   } else {
                     run.value = null;
                     run.run();
                   }
                   return;
                 }
               } catch (Exception e) {
                 e.printStackTrace();
               }
             }
           },
           Settings.CLEAR_INTERVAL * 20);
 }