Beispiel #1
0
 @Override
 public boolean onCommand(final PlotPlayer plr, final String[] args) {
   final Location ploc = plr.getLocation();
   if (!PS.get().isPlotWorld(ploc.getWorld())) {
     MainUtil.sendMessage(plr, C.NOT_IN_PLOT_WORLD);
     return false;
   }
   PlotId id = PlotId.fromString(args[0]);
   if (id == null) {
     if (StringMan.isEqualIgnoreCaseToAny(args[0], "near", "nearest")) {
       Plot closest = null;
       int distance = Integer.MAX_VALUE;
       for (final Plot plot : PS.get().getPlotsInWorld(ploc.getWorld())) {
         final double current = plot.getBottomAbs().getEuclideanDistanceSquared(ploc);
         if (current < distance) {
           distance = (int) current;
           closest = plot;
         }
       }
       id = closest.getId();
     } else {
       MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
       return false;
     }
   }
   final Location loc = MainUtil.getPlotHome(ploc.getWorld(), id);
   plr.setCompassTarget(loc);
   MainUtil.sendMessage(plr, C.COMPASS_TARGET);
   return true;
 }
Beispiel #2
0
 public static boolean addFlag(final AbstractFlag af, final boolean reserved) {
   PS.debug(C.PREFIX + "&8 - Adding flag: &7" + af);
   PS.get()
       .foreachPlotArea(
           new RunnableVal<PlotArea>() {
             @Override
             public void run(PlotArea value) {
               final Flag flag = value.DEFAULT_FLAGS.get(af.getKey());
               if (flag != null) {
                 flag.setKey(af);
               }
             }
           });
   PS.get()
       .foreachPlotRaw(
           new RunnableVal<Plot>() {
             @Override
             public void run(Plot value) {
               final Flag flag = value.getFlags().get(af.getKey());
               if (flag != null) {
                 flag.setKey(af);
               }
             }
           });
   if (flags.remove(af)) {
     PS.debug("(Replaced existing flag)");
   }
   flags.add(af);
   if (reserved) {
     reserveFlag(af.getKey());
   }
   return false;
 }
Beispiel #3
0
 @Override
 public boolean onCommand(PlotPlayer plr, String[] args) {
   URL url;
   if (args.length == 0) {
     url = PS.get().update;
   } else if (args.length == 1) {
     try {
       url = new URL(args[0]);
     } catch (MalformedURLException e) {
       MainUtil.sendConsoleMessage("&cInvalid url: " + args[0]);
       MainUtil.sendConsoleMessage(C.COMMAND_SYNTAX, "/plot update [url]");
       return false;
     }
   } else {
     MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, getUsage().replaceAll("\\{label\\}", "plot"));
     return false;
   }
   if (url == null) {
     MainUtil.sendMessage(plr, "&cNo update found!");
     MainUtil.sendMessage(plr, "&cTo manually specify an update URL: /plot update <url>");
     return false;
   }
   if (PS.get().update(null, url) && url == PS.get().update) {
     PS.get().update = null;
   }
   return true;
 }
Beispiel #4
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);
 }
Beispiel #5
0
  @Subscribe
  public void onChat(PlayerChatEvent event) {
    final Player player = event.getEntity();
    final String world = player.getWorld().getName();
    if (!PS.get().isPlotWorld(world)) {
      return;
    }
    final PlotWorld plotworld = PS.get().getPlotWorld(world);
    final PlotPlayer plr = SpongeUtil.getPlayer(player);
    if (!plotworld.PLOT_CHAT && (plr.getMeta("chat") == null || !(Boolean) plr.getMeta("chat"))) {
      return;
    }
    final Location loc = SpongeUtil.getLocation(player);
    final Plot plot = MainUtil.getPlot(loc);
    if (plot == null) {
      return;
    }
    Text message = event.getUnformattedMessage();

    // TODO use display name rather than username
    //  - Getting displayname currently causes NPE, so wait until sponge fixes that

    String sender = player.getName();
    PlotId id = plot.id;
    String newMessage =
        StringMan.replaceAll(
            C.PLOT_CHAT_FORMAT.s(), "%plot_id%", id.x + ";" + id.y, "%sender%", sender);
    Text forcedMessage = event.getMessage();
    //        String forcedMessage = StringMan.replaceAll(C.PLOT_CHAT_FORCED.s(), "%plot_id%", id.x
    // + ";" + id.y, "%sender%", sender);
    for (PlotPlayer user : UUIDHandler.getPlayers().values()) {
      String toSend;
      if (plot.equals(MainUtil.getPlot(user.getLocation()))) {
        toSend = newMessage;
      } else if (Permissions.hasPermission(user, C.PERMISSION_COMMANDS_CHAT)) {
        ((SpongePlayer) user).player.sendMessage(forcedMessage);
        continue;
      } else {
        continue;
      }
      String[] split = (toSend + " ").split("%msg%");
      List<Text> components = new ArrayList<>();
      Text prefix = null;
      for (String part : split) {
        if (prefix != null) {
          components.add(prefix);
        } else {
          prefix = message;
        }
        components.add(Texts.of(part));
      }
      ((SpongePlayer) user).player.sendMessage(Texts.join(components));
    }
    event.setNewMessage(Texts.of());
    event.setCancelled(true);
  }
 /**
  * Returns the plot a player is currently in.
  *
  * @param player
  * @return boolean
  */
 public static Plot getCurrentPlot(final Player player) {
   if (!PS.get().isPlotWorld(player.getWorld().getName())) {
     return null;
   }
   final PlotId id = MainUtil.getPlotId(BukkitUtil.getLocation(player));
   final String world = player.getWorld().getName();
   if (id == null) {
     return null;
   }
   if (PS.get().getPlots(world).containsKey(id)) {
     return PS.get().getPlots(world).get(id);
   }
   return new Plot(id, null, new ArrayList<UUID>(), new ArrayList<UUID>(), world);
 }
Beispiel #7
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);
    }
  }
Beispiel #8
0
 public void displaySaves(final PlotPlayer player, final int page) {
   final List<String> schematics = (List<String>) player.getMeta("plot_schematics");
   for (int i = 0; i < Math.min(schematics.size(), 32); i++) {
     try {
       final String schem = schematics.get(i);
       final String[] split = schem.split("_");
       if (split.length != 6) {
         continue;
       }
       final String time =
           secToTime((System.currentTimeMillis() / 1000) - (Long.parseLong(split[0])));
       final String world = split[1];
       final PlotId id = PlotId.fromString(split[2] + ";" + split[3]);
       final String size = split[4];
       final String server = split[5].replaceAll(".schematic", "");
       String color;
       if (PS.get().IMP.getServerName().replaceAll("[^A-Za-z0-9]", "").equals(server)) {
         color = "$4";
       } else {
         color = "$1";
       }
       MainUtil.sendMessage(
           player,
           "$3[$2" + (i + 1) + "$3] " + color + time + "$3 | " + color + world + ";" + id + "$3 | "
               + color + size + "x" + size);
     } catch (final Exception e) {
       e.printStackTrace();
     }
   }
   MainUtil.sendMessage(player, C.LOAD_LIST);
 }
Beispiel #9
0
 @Subscribe
 public void onRedstoneEvent(BlockRedstoneUpdateEvent event) {
   org.spongepowered.api.world.Location block = event.getLocation();
   Location loc = SpongeUtil.getLocation(block);
   if (loc == null || !PS.get().isPlotWorld(loc.getWorld())) {
     return;
   }
   Plot plot = MainUtil.getPlot(loc);
   if (plot == null || !plot.hasOwner()) {
     return;
   }
   if (event.getOldSignalStrength() > event.getNewSignalStrength()) {
     return;
   }
   if (Settings.REDSTONE_DISABLER) {
     if (UUIDHandler.getPlayer(plot.owner) == null) {
       boolean disable = true;
       for (UUID trusted : plot.getTrusted()) {
         if (UUIDHandler.getPlayer(trusted) != null) {
           disable = false;
           break;
         }
       }
       if (disable) {
         event.setNewSignalStrength(0);
         return;
       }
     }
   }
   Flag redstone = FlagManager.getPlotFlag(plot, "redstone");
   if (FlagManager.isPlotFlagFalse(plot, "redstone")) {
     event.setNewSignalStrength(0);
     // TODO only disable clocks
   }
 }
 @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
 public void onBigBoom(final BlockExplodeEvent event) {
   final Block block = event.getBlock();
   final Location loc = BukkitUtil.getLocation(block.getLocation());
   final String world = loc.getWorld();
   if (!PS.get().isPlotWorld(world)) {
     return;
   }
   final Plot plot = MainUtil.getPlotAbs(loc);
   if ((plot != null) && plot.hasOwner()) {
     if (FlagManager.isPlotFlagTrue(plot, "explosion")) {
       final Iterator<Block> iter = event.blockList().iterator();
       while (iter.hasNext()) {
         final Block b = iter.next();
         if (!plot.equals(MainUtil.getPlotAbs(BukkitUtil.getLocation(b.getLocation())))) {
           iter.remove();
         }
       }
       return;
     }
   }
   if (MainUtil.isPlotArea(loc)) {
     event.setCancelled(true);
   } else {
     final Iterator<Block> iter = event.blockList().iterator();
     while (iter.hasNext()) {
       iter.next();
       if (MainUtil.isPlotArea(loc)) {
         iter.remove();
       }
     }
   }
 }
 public static List<Plot> getOldPlots(final String world) {
   final ArrayList<Plot> plots = new ArrayList<>(PS.get().getPlots(world).values());
   final List<Plot> toRemove = new ArrayList<>();
   Iterator<Plot> iter = plots.iterator();
   while (iter.hasNext()) {
     Plot plot = iter.next();
     final Flag keepFlag = FlagManager.getPlotFlag(plot, "keep");
     if (keepFlag != null && (Boolean) keepFlag.getValue()) {
       continue;
     }
     final UUID uuid = plot.owner;
     if (uuid == null) {
       toRemove.add(plot);
       continue;
     }
     final PlotPlayer player = UUIDHandler.getPlayer(uuid);
     if (player != null) {
       continue;
     }
     if (isExpired(plot)) {
       toRemove.add(plot);
     }
   }
   return toRemove;
 }
 /**
  * Get the plots for a player
  *
  * @param plr
  * @return boolean
  */
 public static Set<Plot> getPlayerPlots(final String world, final Player plr) {
   final Set<Plot> p = PS.get().getPlots(world, plr.getName());
   if (p == null) {
     return new HashSet<>();
   }
   return p;
 }
Beispiel #13
0
  @Subscribe
  public void onJoin(PlayerJoinEvent event) {
    final Player player = event.getUser();
    SpongeUtil.removePlayer(player.getName());
    final PlotPlayer pp = SpongeUtil.getPlayer(player);
    final String username = pp.getName();
    final StringWrapper name = new StringWrapper(username);
    final UUID uuid = pp.getUUID();
    UUIDHandler.add(name, uuid);
    ExpireManager.dates.put(uuid, System.currentTimeMillis());

    // TODO worldedit bypass

    if (PS.get().update != null && pp.hasPermission("plots.admin")) {
      TaskManager.runTaskLater(
          new Runnable() {
            @Override
            public void run() {
              MainUtil.sendMessage(pp, "&6An update for PlotSquared is available: &7/plot update");
            }
          },
          20);
    }
    final Location loc = SpongeUtil.getLocation(player);
    final Plot plot = MainUtil.getPlot(loc);
    if (plot == null) {
      return;
    }
    if (Settings.TELEPORT_ON_LOGIN) {
      MainUtil.teleportPlayer(pp, pp.getLocation(), plot);
      MainUtil.sendMessage(pp, C.TELEPORTED_TO_ROAD);
    }
    PlotListener.plotEntry(pp, plot);
  }
Beispiel #14
0
 @Override
 public EconHandler getEconomyHandler() {
   // TODO Auto-generated method stub
   // Nothing like Vault exists yet
   PS.log("getEconomyHandler NOT IMPLEMENTED YET");
   return null;
 }
 public static ArrayList<PlotId> getMaxPlotSelectionIds(
     final String world, PlotId pos1, PlotId pos2) {
   final Plot plot1 = PS.get().getPlots(world).get(pos1);
   final Plot plot2 = PS.get().getPlots(world).get(pos2);
   if (plot1 != null) {
     pos1 = MainUtil.getBottomPlot(plot1).id;
   }
   if (plot2 != null) {
     pos2 = MainUtil.getTopPlot(plot2).id;
   }
   final ArrayList<PlotId> myplots = new ArrayList<>();
   for (int x = pos1.x; x <= pos2.x; x++) {
     for (int y = pos1.y; y <= pos2.y; y++) {
       myplots.add(new PlotId(x, y));
     }
   }
   return myplots;
 }
Beispiel #16
0
 @Override
 public UUIDHandlerImplementation initUUIDHandler() {
   UUIDWrapper wrapper;
   if (Settings.OFFLINE_MODE || !PS.get().checkVersion(this.getServerVersion(), 1, 7, 6)) {
     wrapper = new SpongeLowerOfflineUUIDWrapper();
   } else {
     wrapper = new SpongeOnlineUUIDWrapper();
   }
   return new SpongeUUIDHandler(wrapper);
 }
Beispiel #17
0
 @Subscribe
 public void onBlockChange(EntityChangeBlockEvent event) {
   Entity entity = event.getEntity();
   if (entity.getType() == EntityTypes.PLAYER) {
     return;
   }
   if (PS.get().isPlotWorld(entity.getWorld().getName())) {
     event.setCancelled(true);
   }
 }
Beispiel #18
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;
 }
Beispiel #19
0
 @Override
 public boolean onCommand(final PlotPlayer plr, final String[] args) {
   if (args.length == 1) {
     final String arg = args[0].toLowerCase();
     final PlotId id = getId(arg);
     if (id != null) {
       MainUtil.sendMessage(plr, "/plot trim x;z &l<world>");
       return false;
     }
     if (arg.equals("all")) {
       MainUtil.sendMessage(plr, "/plot trim all &l<world>");
       return false;
     }
     MainUtil.sendMessage(plr, C.TRIM_SYNTAX);
     return false;
   }
   if (args.length != 2) {
     MainUtil.sendMessage(plr, C.TRIM_SYNTAX);
     return false;
   }
   final String arg = args[0].toLowerCase();
   if (!arg.equals("all")) {
     MainUtil.sendMessage(plr, C.TRIM_SYNTAX);
     return false;
   }
   final String world = args[1];
   if (!BlockManager.manager.isWorld(world) || (PS.get().getPlotWorld(world) == null)) {
     MainUtil.sendMessage(plr, C.NOT_VALID_WORLD);
     return false;
   }
   if (Trim.TASK) {
     sendMessage(C.TRIM_IN_PROGRESS.s());
     return false;
   }
   sendMessage(C.TRIM_START.s());
   final ArrayList<ChunkLoc> empty = new ArrayList<>();
   getTrimRegions(
       empty,
       world,
       new Runnable() {
         public void run() {
           deleteChunks(
               world,
               empty,
               new Runnable() {
                 @Override
                 public void run() {
                   PS.log("$1Trim task complete!");
                 }
               });
         }
       });
   return true;
 }
Beispiel #20
0
 @Override
 public String getVersion() {
   int[] version = PS.get().getVersion();
   String result = "";
   String prefix = "";
   for (int i : version) {
     result += prefix + i;
     prefix = ".";
   }
   return result;
 }
Beispiel #21
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) {
   }
 }
Beispiel #22
0
 public World createWorldFromConfig(String world) {
   SpongeBasicGen generator = new SpongeBasicGen(world);
   PlotWorld plotworld = generator.getNewPlotWorld(world);
   SpongeGeneratorWrapper wrapper;
   if (plotworld.TYPE == 0) {
     wrapper = new SpongeGeneratorWrapper(world, generator);
   } else {
     wrapper = new SpongeGeneratorWrapper(world, null);
   }
   PS.get().loadWorld(world, wrapper);
   switch (plotworld.TYPE) {
       // Normal
     case 0:
       {
         this.modify = new WorldModify(generator, false);
         game.getRegistry().registerWorldGeneratorModifier(modify);
         Optional<World> builder =
             game.getRegistry()
                 .createWorldBuilder()
                 .name(world)
                 .enabled(true)
                 .loadsOnStartup(true)
                 .keepsSpawnLoaded(true)
                 .dimensionType(DimensionTypes.OVERWORLD)
                 .generator(GeneratorTypes.FLAT)
                 .usesMapFeatures(false)
                 .generatorModifiers(modify)
                 .build();
         return builder.get();
       }
       // Augmented
     default:
       {
         this.modify = new WorldModify(generator, true);
         game.getRegistry().registerWorldGeneratorModifier(modify);
         Optional<World> builder =
             game.getRegistry()
                 .createWorldBuilder()
                 .name(world)
                 .enabled(true)
                 .loadsOnStartup(true)
                 .keepsSpawnLoaded(true)
                 .dimensionType(DimensionTypes.OVERWORLD)
                 .generator(GeneratorTypes.OVERWORLD)
                 .usesMapFeatures(false)
                 .generatorModifiers(modify)
                 .build();
         return builder.get();
       }
   }
 }
Beispiel #23
0
  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;
  }
Beispiel #24
0
 @Subscribe
 public void onFloraGrow(FloraGrowEvent event) {
   org.spongepowered.api.world.Location block = event.getLocation();
   Extent extent = block.getExtent();
   if (extent instanceof World) {
     World world = (World) extent;
     final String worldname = world.getName();
     if (!PS.get().isPlotWorld(worldname)) {
       return;
     }
     if (MainUtil.isPlotRoad(SpongeUtil.getLocation(worldname, block))) {
       event.setCancelled(true);
     }
   }
 }
Beispiel #25
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;
 }
 /**
  * This method is called when a world loads. Make sure you set all your constants here. You are
  * provided with the configuration section for that specific world.
  */
 @Override
 public void loadConfiguration(final ConfigurationSection config) {
   super.loadConfiguration(config);
   if ((ROAD_WIDTH & 1) == 0) {
     PATH_WIDTH_LOWER = (short) (Math.floor(ROAD_WIDTH / 2) - 1);
   } else {
     PATH_WIDTH_LOWER = (short) (Math.floor(ROAD_WIDTH / 2));
   }
   PATH_WIDTH_UPPER = (short) (PATH_WIDTH_LOWER + PLOT_WIDTH + 1);
   try {
     setupSchematics();
   } catch (final Exception e) {
     PS.debug("&c - road schematics are disabled for this world.");
   }
 }
 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]);
   }
 }
 @Override
 public Entity createEntity(Location location, BaseEntity entity) {
   if (this.Eblocked) {
     return null;
   }
   this.Ecount++;
   if (this.Ecount > Settings.CHUNK_PROCESSOR_MAX_ENTITIES) {
     this.Eblocked = true;
     PS.debug(
         "&cPlotSquared detected unsafe WorldEdit: "
             + location.getBlockX()
             + ","
             + location.getBlockZ());
   }
   if (WEManager.maskContains(
       this.mask, location.getBlockX(), location.getBlockY(), location.getBlockZ())) {
     return super.createEntity(location, entity);
   }
   return null;
 }
 public void add(final BiMap<StringWrapper, UUID> toAdd) {
   if (uuidMap.size() == 0) {
     uuidMap = toAdd;
   }
   for (Map.Entry<StringWrapper, UUID> entry : toAdd.entrySet()) {
     UUID uuid = entry.getValue();
     StringWrapper name = entry.getKey();
     if ((uuid == null) || (name == null)) {
       continue;
     }
     BiMap<UUID, StringWrapper> inverse = uuidMap.inverse();
     if (inverse.containsKey(uuid)) {
       if (uuidMap.containsKey(name)) {
         continue;
       }
       rename(uuid, name);
       continue;
     }
     uuidMap.put(name, uuid);
   }
   PS.debug(C.PREFIX.s() + "&6Cached a total of: " + uuidMap.size() + " UUIDs");
 }
Beispiel #30
0
 @Subscribe
 public void onBlockMove(BlockMoveEvent event) {
   org.spongepowered.api.world.Location block = event.getLocations().get(0);
   Extent extent = block.getExtent();
   if (extent instanceof World) {
     World world = (World) extent;
     final String worldname = world.getName();
     if (!PS.get().isPlotWorld(worldname)) {
       return;
     }
     event.filterLocations(
         new Predicate<org.spongepowered.api.world.Location<World>>() {
           @Override
           public boolean apply(org.spongepowered.api.world.Location loc) {
             if (MainUtil.isPlotRoad(SpongeUtil.getLocation(worldname, loc))) {
               return false;
             }
             return true;
           }
         });
   }
 }