Exemple #1
0
 public static boolean getBulkRegions(
     final ArrayList<ChunkLoc> empty, final String world, final Runnable whenDone) {
   if (Trim.TASK) {
     return false;
   }
   TaskManager.runTaskAsync(
       new Runnable() {
         @Override
         public void run() {
           final String directory = world + File.separator + "region";
           final File folder = new File(PS.get().IMP.getWorldContainer(), directory);
           final File[] regionFiles = folder.listFiles();
           for (final File file : regionFiles) {
             final String name = file.getName();
             if (name.endsWith("mca")) {
               if (file.getTotalSpace() <= 8192) {
                 try {
                   final String[] split = name.split("\\.");
                   final int x = Integer.parseInt(split[1]);
                   final int z = Integer.parseInt(split[2]);
                   final ChunkLoc loc = new ChunkLoc(x, z);
                   empty.add(loc);
                 } catch (final Exception e) {
                   PS.debug("INVALID MCA: " + name);
                 }
               } else {
                 final Path path = Paths.get(file.getPath());
                 try {
                   final BasicFileAttributes attr =
                       Files.readAttributes(path, BasicFileAttributes.class);
                   final long creation = attr.creationTime().toMillis();
                   final long modification = file.lastModified();
                   final long diff = Math.abs(creation - modification);
                   if (diff < 10000) {
                     try {
                       final String[] split = name.split("\\.");
                       final int x = Integer.parseInt(split[1]);
                       final int z = Integer.parseInt(split[2]);
                       final ChunkLoc loc = new ChunkLoc(x, z);
                       empty.add(loc);
                     } catch (final Exception e) {
                       PS.debug("INVALID MCA: " + name);
                     }
                   }
                 } catch (final Exception e) {
                 }
               }
             }
           }
           Trim.TASK = false;
           TaskManager.runTaskAsync(whenDone);
         }
       });
   Trim.TASK = true;
   return true;
 }
Exemple #2
0
  @Override
  public boolean onCommand(final PlotPlayer plr, final String[] args) {

    if (!Settings.METRICS) {
      MainUtil.sendMessage(
          plr,
          "&cPlease enable metrics in order to use this command.\n&7 - Or host it yourself if you don't like the free service");
      return false;
    }
    final String world = plr.getLocation().getWorld();
    if (!PS.get().isPlotWorld(world)) {
      return !sendMessage(plr, C.NOT_IN_PLOT_WORLD);
    }
    final Plot plot = MainUtil.getPlot(plr.getLocation());
    if (plot == null) {
      return !sendMessage(plr, C.NOT_IN_PLOT);
    }
    if (!plot.hasOwner()) {
      MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
      return false;
    }
    if (!plot.isOwner(plr.getUUID())
        && !Permissions.hasPermission(plr, "plots.admin.command.load")) {
      MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
      return false;
    }
    if (MainUtil.runners.containsKey(plot)) {
      MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
      return false;
    }

    if (args.length != 0) {
      if (args.length == 1) {
        // TODO load save here
        final List<String> schematics = (List<String>) plr.getMeta("plot_schematics");
        if (schematics == null) {
          // No schematics found:
          MainUtil.sendMessage(plr, C.LOAD_NULL);
          return false;
        }
        String schem;
        try {
          schem = schematics.get(Integer.parseInt(args[0]) - 1);
        } catch (final Exception e) {
          // use /plot load <index>
          MainUtil.sendMessage(plr, C.NOT_VALID_NUMBER, "(1, " + schematics.size() + ")");
          return false;
        }
        final URL url;
        try {
          url = new URL(Settings.WEB_URL + "saves/" + plr.getUUID() + "/" + schem + ".schematic");
        } catch (final MalformedURLException e) {
          e.printStackTrace();
          MainUtil.sendMessage(plr, C.LOAD_FAILED);
          return false;
        }

        MainUtil.runners.put(plot, 1);
        MainUtil.sendMessage(plr, C.GENERATING_COMPONENT);
        TaskManager.runTaskAsync(
            new Runnable() {
              @Override
              public void run() {
                final Schematic schematic = SchematicHandler.manager.getSchematic(url);
                if (schematic == null) {
                  MainUtil.runners.remove(plot);
                  sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent or not in gzip format");
                  return;
                }
                SchematicHandler.manager.paste(
                    schematic,
                    plot,
                    0,
                    0,
                    new RunnableVal<Boolean>() {
                      @Override
                      public void run() {
                        MainUtil.runners.remove(plot);
                        if (value) {
                          sendMessage(plr, C.SCHEMATIC_PASTE_SUCCESS);
                        } else {
                          sendMessage(plr, C.SCHEMATIC_PASTE_FAILED);
                        }
                      }
                    });
              }
            });
        return true;
      }
      MainUtil.runners.remove(plot);
      MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot load <index>");
      return false;
    }

    // list schematics

    final List<String> schematics = (List<String>) plr.getMeta("plot_schematics");
    if (schematics == null) {
      MainUtil.runners.put(plot, 1);
      TaskManager.runTaskAsync(
          new Runnable() {
            @Override
            public void run() {
              final List<String> schematics = SchematicHandler.manager.getSaves(plr.getUUID());
              MainUtil.runners.remove(plot);
              if ((schematics == null) || (schematics.size() == 0)) {
                MainUtil.sendMessage(plr, C.LOAD_FAILED);
                return;
              }
              plr.setMeta("plot_schematics", schematics);
              displaySaves(plr, 0);
            }
          });
    } else {
      displaySaves(plr, 0);
    }
    return true;
  }
Exemple #3
0
 @Override
 public boolean onCommand(PlotPlayer player, String... args) {
   if (args.length == 1) {
     if ("next".equalsIgnoreCase(args[0])) {
       ArrayList<Plot> plots = new ArrayList<>(PS.get().getBasePlots());
       Collections.sort(
           plots,
           (p1, p2) -> {
             double v1 = 0;
             if (!p1.getRatings().isEmpty()) {
               for (Map.Entry<UUID, Rating> entry : p1.getRatings().entrySet()) {
                 v1 -= 11 - entry.getValue().getAverageRating();
               }
             }
             double v2 = 0;
             if (!p2.getRatings().isEmpty()) {
               for (Map.Entry<UUID, Rating> entry : p2.getRatings().entrySet()) {
                 v2 -= 11 - entry.getValue().getAverageRating();
               }
             }
             if (v1 == v2) {
               return -0;
             }
             return v2 > v1 ? 1 : -1;
           });
       UUID uuid = player.getUUID();
       for (Plot p : plots) {
         if ((!Settings.Done.REQUIRED_FOR_RATINGS || p.hasFlag(Flags.DONE))
             && p.isBasePlot()
             && (p.hasRatings() || !p.getRatings().containsKey(uuid))
             && !p.isAdded(uuid)) {
           p.teleportPlayer(player);
           MainUtil.sendMessage(player, C.RATE_THIS);
           return true;
         }
       }
       MainUtil.sendMessage(player, C.FOUND_NO_PLOTS);
       return false;
     }
   }
   Plot plot = player.getCurrentPlot();
   if (plot == null) {
     return !this.sendMessage(player, C.NOT_IN_PLOT);
   }
   if (!plot.hasOwner()) {
     this.sendMessage(player, C.RATING_NOT_OWNED);
     return false;
   }
   if (plot.isOwner(player.getUUID())) {
     this.sendMessage(player, C.RATING_NOT_YOUR_OWN);
     return false;
   }
   if (Settings.Done.REQUIRED_FOR_RATINGS && !plot.hasFlag(Flags.DONE)) {
     this.sendMessage(player, C.RATING_NOT_DONE);
     return false;
   }
   if (Settings.Ratings.CATEGORIES != null && !Settings.Ratings.CATEGORIES.isEmpty()) {
     Runnable run =
         new Runnable() {
           @Override
           public void run() {
             if (plot.getRatings().containsKey(player.getUUID())) {
               Rate.this.sendMessage(player, C.RATING_ALREADY_EXISTS, plot.getId().toString());
               return;
             }
             MutableInt index = new MutableInt(0);
             MutableInt rating = new MutableInt(0);
             String title = Settings.Ratings.CATEGORIES.get(0);
             PlotInventory inventory =
                 new PlotInventory(player, 1, title) {
                   @Override
                   public boolean onClick(int i) {
                     rating.add((i + 1) * Math.pow(10, index.getValue()));
                     index.increment();
                     if (index.getValue() >= Settings.Ratings.CATEGORIES.size()) {
                       int rV = rating.getValue();
                       Rating result =
                           EventUtil.manager.callRating(this.player, plot, new Rating(rV));
                       plot.addRating(this.player.getUUID(), result);
                       Rate.this.sendMessage(
                           this.player, C.RATING_APPLIED, plot.getId().toString());
                       if (Permissions.hasPermission(this.player, "plots.comment")) {
                         Command command = MainCommand.getInstance().getCommand(Comment.class);
                         if (command != null) {
                           MainUtil.sendMessage(this.player, C.COMMENT_THIS, command.getUsage());
                         }
                       }
                       return false;
                     }
                     this.setTitle(Settings.Ratings.CATEGORIES.get(index.getValue()));
                     return true;
                   }
                 };
             inventory.setItem(0, new PlotItemStack(35, (short) 12, 0, "0/8"));
             inventory.setItem(1, new PlotItemStack(35, (short) 14, 1, "1/8"));
             inventory.setItem(2, new PlotItemStack(35, (short) 1, 2, "2/8"));
             inventory.setItem(3, new PlotItemStack(35, (short) 4, 3, "3/8"));
             inventory.setItem(4, new PlotItemStack(35, (short) 5, 4, "4/8"));
             inventory.setItem(5, new PlotItemStack(35, (short) 9, 5, "5/8"));
             inventory.setItem(6, new PlotItemStack(35, (short) 11, 6, "6/8"));
             inventory.setItem(7, new PlotItemStack(35, (short) 10, 7, "7/8"));
             inventory.setItem(8, new PlotItemStack(35, (short) 2, 8, "8/8"));
             inventory.openInventory();
           }
         };
     if (plot.getSettings().ratings == null) {
       if (!Settings.Enabled_Components.RATING_CACHE) {
         TaskManager.runTaskAsync(
             () -> {
               plot.getSettings().ratings = DBFunc.getRatings(plot);
               run.run();
             });
         return true;
       }
       plot.getSettings().ratings = new HashMap<>();
     }
     run.run();
     return true;
   }
   if (args.length < 1) {
     this.sendMessage(player, C.RATING_NOT_VALID);
     return true;
   }
   String arg = args[0];
   int rating;
   if (MathMan.isInteger(arg) && arg.length() < 3 && !arg.isEmpty()) {
     rating = Integer.parseInt(arg);
     if (rating > 10 || rating < 1) {
       this.sendMessage(player, C.RATING_NOT_VALID);
       return false;
     }
   } else {
     this.sendMessage(player, C.RATING_NOT_VALID);
     return false;
   }
   UUID uuid = player.getUUID();
   Runnable run =
       () -> {
         if (plot.getRatings().containsKey(uuid)) {
           this.sendMessage(player, C.RATING_ALREADY_EXISTS, plot.getId().toString());
           return;
         }
         Rating result = EventUtil.manager.callRating(player, plot, new Rating(rating));
         plot.addRating(uuid, result);
         this.sendMessage(player, C.RATING_APPLIED, plot.getId().toString());
       };
   if (plot.getSettings().ratings == null) {
     if (!Settings.Enabled_Components.RATING_CACHE) {
       TaskManager.runTaskAsync(
           () -> {
             plot.getSettings().ratings = DBFunc.getRatings(plot);
             run.run();
           });
       return true;
     }
     plot.getSettings().ratings = new HashMap<>();
   }
   run.run();
   return true;
 }
  @Override
  public boolean execute(final PlotPlayer player, final String... args) {
    if (args.length == 1) {
      if (args[0].equalsIgnoreCase("next")) {
        ArrayList<Plot> plots = new ArrayList<>(PlotSquared.getPlots());
        Collections.sort(
            plots,
            new Comparator<Plot>() {
              @Override
              public int compare(Plot p1, Plot p2) {
                int v1 = 0;
                int v2 = 0;
                if (p1.settings.ratings != null) {
                  for (Entry<UUID, Integer> entry : p1.settings.ratings.entrySet()) {
                    v1 -= 11 - entry.getValue();
                  }
                }
                if (p2.settings.ratings != null) {
                  for (Entry<UUID, Integer> entry : p2.settings.ratings.entrySet()) {
                    v2 -= 11 - entry.getValue();
                  }
                }
                return v2 - v1;
              }
            });
        UUID uuid = player.getUUID();
        for (Plot p : plots) {
          if (p.settings.ratings == null || !p.settings.ratings.containsKey(uuid)) {
            MainUtil.teleportPlayer(player, player.getLocation(), p);
            MainUtil.sendMessage(player, C.RATE_THIS);
            return true;
          }
        }
        MainUtil.sendMessage(player, C.FOUND_NO_PLOTS);
        return false;
      }
    }
    final Location loc = player.getLocation();
    final Plot plot = MainUtil.getPlot(loc);
    if (plot == null) {
      return !sendMessage(player, C.NOT_IN_PLOT);
    }
    if (!plot.hasOwner()) {
      sendMessage(player, C.RATING_NOT_OWNED);
      return true;
    }
    if (plot.isOwner(player.getUUID())) {
      sendMessage(player, C.RATING_NOT_YOUR_OWN);
      return true;
    }
    if (Settings.RATING_CATEGORIES != null && Settings.RATING_CATEGORIES.size() != 0) {
      final Runnable run =
          new Runnable() {
            @Override
            public void run() {
              if (plot.settings.ratings.containsKey(player.getUUID())) {
                sendMessage(player, C.RATING_ALREADY_EXISTS, plot.getId().toString());
                return;
              }
              final MutableInt index = new MutableInt(0);
              final MutableInt rating = new MutableInt(0);
              String title = Settings.RATING_CATEGORIES.get(0);
              PlotInventory inventory =
                  new PlotInventory(player, 1, title) {
                    public boolean onClick(int i) {
                      rating.add((i + 1) * Math.pow(10, index.intValue()));
                      index.increment();
                      if (index.intValue() >= Settings.RATING_CATEGORIES.size()) {
                        close();
                        // set rating!
                        plot.settings.ratings.put(player.getUUID(), rating.intValue());
                        DBFunc.setRating(plot, player.getUUID(), rating.intValue());
                        sendMessage(player, C.RATING_APPLIED, plot.getId().toString());
                        sendMessage(player, C.RATING_APPLIED, plot.getId().toString());
                        return false;
                      }
                      setTitle(Settings.RATING_CATEGORIES.get(index.intValue()));
                      return false;
                    }
                  };
              inventory.setItem(0, new PlotItemStack(35, (short) 12, 0, "0/8", null));
              inventory.setItem(1, new PlotItemStack(35, (short) 14, 1, "1/8", null));
              inventory.setItem(2, new PlotItemStack(35, (short) 1, 2, "2/8", null));
              inventory.setItem(3, new PlotItemStack(35, (short) 4, 3, "3/8", null));
              inventory.setItem(4, new PlotItemStack(35, (short) 5, 4, "4/8", null));
              inventory.setItem(5, new PlotItemStack(35, (short) 9, 5, "5/8", null));
              inventory.setItem(6, new PlotItemStack(35, (short) 11, 6, "6/8", null));
              inventory.setItem(7, new PlotItemStack(35, (short) 10, 7, "7/8", null));
              inventory.setItem(8, new PlotItemStack(35, (short) 2, 8, "8/8", null));
              inventory.openInventory();
            }
          };
      if (plot.settings.ratings == null) {
        TaskManager.runTaskAsync(
            new Runnable() {
              @Override
              public void run() {
                plot.settings.ratings = DBFunc.getRatings(plot);
                run.run();
              }
            });
        return true;
      }
      run.run();
      return true;
    }
    if (args.length < 1) {
      sendMessage(player, C.RATING_NOT_VALID);
      return true;
    }
    final String arg = args[0];

    if (arg.equalsIgnoreCase("next")) {}

    final int rating;
    if (StringUtils.isNumeric(arg) && arg.length() < 3 && arg.length() > 0) {
      rating = Integer.parseInt(arg);
      if (rating > 10) {
        sendMessage(player, C.RATING_NOT_VALID);
        return false;
      }
    } else {
      sendMessage(player, C.RATING_NOT_VALID);
      return false;
    }
    final UUID uuid = player.getUUID();
    final Runnable run =
        new Runnable() {
          @Override
          public void run() {
            if (plot.settings.ratings.containsKey(uuid)) {
              sendMessage(player, C.RATING_ALREADY_EXISTS, plot.getId().toString());
              return;
            }
            plot.settings.ratings.put(uuid, rating);
            DBFunc.setRating(plot, uuid, rating);
            sendMessage(player, C.RATING_APPLIED, plot.getId().toString());
          }
        };
    if (plot.settings.ratings == null) {
      TaskManager.runTaskAsync(
          new Runnable() {
            @Override
            public void run() {
              plot.settings.ratings = DBFunc.getRatings(plot);
              run.run();
            }
          });
      return true;
    }
    run.run();
    return true;
  }
Exemple #5
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;
 }