예제 #1
0
 @Override
 public EconHandler getEconomyHandler() {
   // TODO Auto-generated method stub
   // Nothing like Vault exists yet
   PS.log("getEconomyHandler NOT IMPLEMENTED YET");
   return null;
 }
예제 #2
0
 /**
  * Get the plot from a string.
  *
  * @param player Provides a context for what world to search in. Prefixing the term with
  *     'world_name;' will override this context.
  * @param arg The search term
  * @param message If a message should be sent to the player if a plot cannot be found
  * @return The plot if only 1 result is found, or null
  */
 public static Plot getPlotFromString(PlotPlayer player, String arg, boolean message) {
   if (arg == null) {
     if (player == null) {
       if (message) {
         PS.log(C.NOT_VALID_PLOT_WORLD);
       }
       return null;
     }
     return player.getCurrentPlot();
   }
   PlotArea area;
   if (player != null) {
     area = PS.get().getPlotAreaByString(arg);
     if (area == null) {
       area = player.getApplicablePlotArea();
     }
   } else {
     area = ConsolePlayer.getConsole().getApplicablePlotArea();
   }
   String[] split = arg.split(";|,");
   PlotId id;
   if (split.length == 4) {
     area = PS.get().getPlotAreaByString(split[0] + ';' + split[1]);
     id = PlotId.fromString(split[2] + ';' + split[3]);
   } else if (split.length == 3) {
     area = PS.get().getPlotAreaByString(split[0]);
     id = PlotId.fromString(split[1] + ';' + split[2]);
   } else if (split.length == 2) {
     id = PlotId.fromString(arg);
   } else {
     Collection<Plot> plots = area == null ? PS.get().getPlots() : area.getPlots();
     for (Plot p : plots) {
       String name = p.getAlias();
       if (!name.isEmpty() && StringMan.isEqualIgnoreCase(name, arg)) {
         return p;
       }
     }
     if (message) {
       sendMessage(player, C.NOT_VALID_PLOT_ID);
     }
     return null;
   }
   if (id == null) {
     if (message) {
       sendMessage(player, C.NOT_VALID_PLOT_ID);
     }
     return null;
   }
   if (area == null) {
     if (message) {
       sendMessage(player, C.NOT_VALID_PLOT_WORLD);
     }
     return null;
   }
   return area.getPlotAbs(id);
 }
예제 #3
0
 /**
  * Send a message to a player.
  *
  * @param player Can be null to represent console, or use ConsolePlayer.getConsole()
  * @param msg
  * @param prefix If the message should be prefixed with the configured prefix
  * @return
  */
 public static boolean sendMessage(PlotPlayer player, String msg, boolean prefix) {
   if (!msg.isEmpty()) {
     if (player == null) {
       String message = (prefix ? C.PREFIX.s() : "") + msg;
       PS.log(message);
     } else {
       player.sendMessage((prefix ? C.PREFIX.s() : "") + C.color(msg));
     }
   }
   return true;
 }
예제 #4
0
 @Override
 public boolean execute(final PlotPlayer player, final String... args) {
   if (player != null) {
     sendMessage(player, C.NOT_CONSOLE);
     return false;
   }
   if (args.length < 1) {
     sendMessage(player, C.NEED_PLOT_WORLD);
     return false;
   }
   int height = 0;
   if (args.length == 2) {
     try {
       height = Integer.parseInt(args[1]);
     } catch (NumberFormatException e) {
       sendMessage(player, C.NOT_VALID_NUMBER, "(0, 256)");
       sendMessage(player, C.COMMAND_SYNTAX, "/plot regenallroads <world> [height]");
       return false;
     }
   }
   final String name = args[0];
   final PlotManager manager = PS.get().getPlotManager(name);
   if ((manager == null) || !(manager instanceof HybridPlotManager)) {
     sendMessage(player, C.NOT_VALID_PLOT_WORLD);
     return false;
   }
   final List<ChunkLoc> chunks = ChunkManager.manager.getChunkChunks(name);
   PS.log("&cIf no schematic is set, the following will not do anything");
   PS.log("&7 - To set a schematic, stand in a plot and use &c/plot createroadschematic");
   PS.log("&6Potential chunks to update: &7" + (chunks.size() * 1024));
   PS.log("&6Estimated time: &7" + (chunks.size()) + " seconds");
   final boolean result = HybridUtils.manager.scheduleRoadUpdate(name, height);
   if (!result) {
     PS.log("&cCannot schedule mass schematic update! (Is one already in progress?)");
     return false;
   }
   return true;
 }
예제 #5
0
 /**
  * Send a message to the player
  *
  * @param player the recipient of the message
  * @param caption the message to send
  * @return boolean success
  */
 public static boolean sendMessage(PlotPlayer player, C caption, Object... args) {
   if (caption.s().isEmpty()) {
     return true;
   }
   TaskManager.runTaskAsync(
       () -> {
         String m = C.format(caption, args);
         if (player == null) {
           PS.log(m);
         } else {
           player.sendMessage(m);
         }
       });
   return true;
 }
 public Player[] getOnlinePlayers() {
   if (this.getOnline == null) {
     return Bukkit.getOnlinePlayers().toArray(new Player[0]);
   }
   try {
     final Object players = this.getOnline.invoke(Bukkit.getServer(), this.arg);
     if (players instanceof Player[]) {
       return (Player[]) players;
     } else {
       @SuppressWarnings("unchecked")
       final Collection<? extends Player> p = (Collection<? extends Player>) players;
       return p.toArray(new Player[0]);
     }
   } catch (final Exception e) {
     PS.log("Failed to resolve online players");
     this.getOnline = null;
     return Bukkit.getOnlinePlayers().toArray(new Player[0]);
   }
 }
  public boolean add(final StringWrapper name, final UUID uuid) {
    if ((uuid == null)) {
      return false;
    }
    if (name == null) {
      try {
        unknown.add(uuid);
      } catch (Exception e) {
        PS.log("&c(minor) Invalid UUID mapping: " + uuid);
        e.printStackTrace();
      }
      return false;
    }

    /*
     * lazy UUID conversion:
     *  - Useful if the person misconfigured the database, or settings before PlotMe conversion
     */
    if (!Settings.OFFLINE_MODE) {
      UUID offline =
          UUID.nameUUIDFromBytes(("OfflinePlayer:" + name.value).getBytes(Charsets.UTF_8));
      if (!unknown.contains(offline) && !name.value.equals(name.value.toLowerCase())) {
        offline = UUID.nameUUIDFromBytes(("OfflinePlayer:" + name.value).getBytes(Charsets.UTF_8));
        if (!unknown.contains(offline)) {
          offline = null;
        }
      }
      if (offline != null) {
        unknown.remove(offline);
        Set<Plot> plots = PS.get().getPlots(offline);
        if (plots.size() > 0) {
          for (Plot plot : PS.get().getPlots(offline)) {
            plot.owner = uuid;
          }
          DBFunc.replaceUUID(offline, uuid);
          PS.debug("&cDetected invalid UUID stored for: " + name.value);
          PS.debug(
              "&7 - Did you recently switch to online-mode storage without running `uuidconvert`?");
          PS.debug(
              "&6PlotSquared will update incorrect entries when the user logs in, or you can reconstruct your database.");
        }
      }
    }
    try {
      UUID offline = uuidMap.put(name, uuid);
      if (offline != null && !offline.equals(uuid)) {
        Set<Plot> plots = PS.get().getPlots(offline);
        if (plots.size() > 0) {
          for (Plot plot : PS.get().getPlots(offline)) {
            plot.owner = uuid;
          }
          DBFunc.replaceUUID(offline, uuid);
          PS.debug("&cDetected invalid UUID stored for (1): " + name.value);
          PS.debug(
              "&7 - Did you recently switch to online-mode storage without running `uuidconvert`?");
          PS.debug(
              "&6PlotSquared will update incorrect entries when the user logs in, or you can reconstruct your database.");
        }
      }
    } catch (Exception e) {
      BiMap<UUID, StringWrapper> inverse = uuidMap.inverse();
      if (inverse.containsKey(uuid)) {
        if (uuidMap.containsKey(name)) {
          return false;
        }
        rename(uuid, name);
        return false;
      }
      uuidMap.put(name, uuid);
    }
    return true;
  }
예제 #8
0
 @Override
 public void registerWorldEvents() {
   // TODO Auto-generated method stub
   PS.log("registerWorldEvents NOT IMPLEMENTED YET");
 }
예제 #9
0
 @Override
 public void registerChunkProcessor() {
   // TODO Auto-generated method stub
   PS.log("registerChunkProcessor NOT IMPLEMENTED YET");
 }
예제 #10
0
 @Override
 public boolean initPlotMeConverter() {
   // TODO Auto-generated method stub
   PS.log("initPlotMeConverter NOT IMPLEMENTED YET");
   return false;
 }
예제 #11
0
파일: Trim.java 프로젝트: Hiddd/PlotSquared
 public static void sendMessage(final String message) {
   PS.log("&3PlotSquared -> World trim&8: &7" + message);
 }
예제 #12
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;
 }