예제 #1
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);
 }
예제 #2
0
  public void init() {
    if (engine != null) {
      return;
    }
    engine = (new ScriptEngineManager(null)).getEngineByName("nashorn");
    if (engine == null) {
      engine = (new ScriptEngineManager(null)).getEngineByName("JavaScript");
    }
    final ScriptContext context = new SimpleScriptContext();
    scope = context.getBindings(ScriptContext.ENGINE_SCOPE);

    // stuff
    scope.put("MainUtil", new MainUtil());
    scope.put("Settings", new Settings());
    scope.put("StringMan", new StringMan());
    scope.put("MathMan", new MathMan());
    scope.put("FlagManager", new FlagManager());

    // Classes
    scope.put("Location", Location.class);
    scope.put("PlotBlock", PlotBlock.class);
    scope.put("Plot", Plot.class);
    scope.put("PlotId", PlotId.class);
    scope.put("Runnable", Runnable.class);
    scope.put("RunnableVal", RunnableVal.class);

    // Instances
    scope.put("PS", PS.get());
    scope.put("TaskManager", PS.get().TASK);
    scope.put("TitleManager", AbstractTitle.TITLE_CLASS);
    scope.put("ConsolePlayer", ConsolePlayer.getConsole());
    scope.put("SchematicHandler", SchematicHandler.manager);
    scope.put("ChunkManager", ChunkManager.manager);
    scope.put("BlockManager", BlockManager.manager);
    scope.put("SetupUtils", SetupUtils.manager);
    scope.put("EventUtil", EventUtil.manager);
    scope.put("EconHandler", EconHandler.manager);
    scope.put("UUIDHandler", UUIDHandler.implementation);
    scope.put("DBFunc", DBFunc.dbManager);
    scope.put("HybridUtils", HybridUtils.manager);
    scope.put("IMP", PS.get().IMP);
    scope.put("MainCommand", MainCommand.getInstance());

    // enums
    for (final Enum<?> value : C.values()) {
      scope.put("C_" + value.name(), value);
    }
  }
예제 #3
0
 public DebugExec() {
   try {
     final File file =
         new File(PS.get().IMP.getDirectory(), "scripts" + File.separator + "start.js");
     if (file.exists()) {
       init();
       final String script =
           StringMan.join(
               Files.readLines(
                   new File(
                       new File(PS.get().IMP.getDirectory() + File.separator + "scripts"),
                       "start.js"),
                   StandardCharsets.UTF_8),
               System.getProperty("line.separator"));
       scope.put("THIS", this);
       scope.put("PlotPlayer", ConsolePlayer.getConsole());
       engine.eval(script, scope);
     }
   } catch (final Exception e) {
   }
 }