Esempio n. 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;
 }
Esempio n. 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;
 }
Esempio n. 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;
 }
Esempio n. 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);
 }
Esempio n. 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);
 }
Esempio n. 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);
    }
  }
Esempio n. 8
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);
  }
Esempio n. 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
   }
 }
 /**
  * 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;
 }
Esempio n. 11
0
 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;
 }
 @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();
       }
     }
   }
 }
Esempio n. 13
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);
 }
 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;
 }
Esempio n. 15
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);
 }
Esempio n. 16
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);
   }
 }
Esempio n. 17
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;
 }
Esempio n. 18
0
 @Override
 public String getVersion() {
   int[] version = PS.get().getVersion();
   String result = "";
   String prefix = "";
   for (int i : version) {
     result += prefix + i;
     prefix = ".";
   }
   return result;
 }
Esempio n. 19
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) {
   }
 }
Esempio n. 20
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();
       }
   }
 }
Esempio n. 21
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;
  }
Esempio n. 22
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);
     }
   }
 }
Esempio n. 23
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;
           }
         });
   }
 }
 @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;
 }
Esempio n. 25
0
  @Subscribe
  public void onServerAboutToStart(ServerAboutToStartEvent event) {
    log("INIT");
    THIS = this;

    //
    resolver = game.getServiceManager().provide(GameProfileResolver.class).get();
    plugin = game.getPluginManager().getPlugin("PlotSquared").get().getInstance();
    log("PLUGIN IS THIS: " + (plugin == this));
    plugin = this;
    server = game.getServer();
    //

    PS.instance = new PS(this, "Sponge");

    registerBlocks();

    ConfigurationSection worldSection = PS.get().config.getConfigurationSection("worlds");
    if (worldSection != null) {
      for (String world : worldSection.getKeys(false)) {
        createWorldFromConfig(world);
      }
    }
  }
Esempio n. 26
0
 public static void load(final File file) {
   try {
     if (!file.exists()) {
       file.getParentFile().mkdirs();
       file.createNewFile();
     }
     final YamlConfiguration yml = YamlConfiguration.loadConfiguration(file);
     final Set<String> keys = yml.getKeys(true);
     final EnumSet<C> all = EnumSet.allOf(C.class);
     final HashSet<String> allNames = new HashSet<>();
     final HashSet<String> allCats = new HashSet<>();
     final HashSet<String> toRemove = new HashSet<>();
     for (final C c : all) {
       allNames.add(c.name());
       allCats.add(c.cat.toLowerCase());
     }
     final HashSet<C> captions = new HashSet<>();
     boolean changed = false;
     for (final String key : keys) {
       if (!yml.isString(key)) {
         if (!allCats.contains(key)) {
           toRemove.add(key);
         }
         continue;
       }
       final String[] split = key.split("\\.");
       final String node = split[split.length - 1].toUpperCase();
       final C caption = allNames.contains(node) ? valueOf(node) : null;
       if (caption != null) {
         if (caption.cat.startsWith("static")) {
           continue;
         }
         final String value = yml.getString(key);
         if (!split[0].equalsIgnoreCase(caption.cat)) {
           changed = true;
           yml.set(key, null);
           yml.set(caption.cat + "." + caption.name().toLowerCase(), value);
         }
         captions.add(caption);
         caption.s = value;
       } else {
         toRemove.add(key);
       }
     }
     for (final String remove : toRemove) {
       changed = true;
       yml.set(remove, null);
     }
     final ConfigurationSection config = PS.get().style.getConfigurationSection("color");
     final Set<String> styles = config.getKeys(false);
     // HashMap<String, String> replacements = new HashMap<>();
     replacements.clear();
     for (final String style : styles) {
       replacements.put("$" + style, "\u00a7" + config.getString(style));
     }
     for (final char letter : "1234567890abcdefklmnor".toCharArray()) {
       replacements.put("&" + letter, "\u00a7" + letter);
     }
     replacements.put("\\\\n", "\n");
     replacements.put("\\n", "\n");
     replacements.put("&-", "\n");
     for (final C caption : all) {
       if (!captions.contains(caption)) {
         if (caption.cat.startsWith("static")) {
           continue;
         }
         changed = true;
         yml.set(caption.cat + "." + caption.name().toLowerCase(), caption.d);
       }
       caption.s = StringMan.replaceFromMap(caption.s, replacements);
     }
     if (changed) {
       yml.save(file);
     }
   } catch (final Exception e) {
     e.printStackTrace();
   }
 }
Esempio n. 27
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;
  }
Esempio n. 28
0
  public static boolean generate(
      final String world, final int cx, final int cz, LazyResult<PlotChunk<?>> lazyChunk) {
    if (!enabled) {
      return false;
    }
    if (lazyChunk == null) {
      lazyChunk =
          new LazyResult<PlotChunk<?>>() {
            @Override
            public PlotChunk<?> create() {
              return SetQueue.IMP.queue.getChunk(SetQueue.IMP.new ChunkWrapper(world, cx, cz));
            }
          };
    }
    final int bx = cx << 4;
    final int bz = cz << 4;
    RegionWrapper region = new RegionWrapper(bx, bx + 15, bz, bz + 15);
    Set<PlotArea> areas = PS.get().getPlotAreas(world, region);
    if (areas.isEmpty()) {
      return false;
    }
    PseudoRandom r = new PseudoRandom();
    r.state = (cx << 16) | (cz & 0xFFFF);
    ChunkWrapper wrap = SetQueue.IMP.new ChunkWrapper(world, cx, cz);
    boolean toReturn = false;
    for (final PlotArea area : areas) {
      if (area.TYPE == 0) {
        return false;
      }
      if (area.TERRAIN == 3) {
        continue;
      }
      IndependentPlotGenerator generator = area.getGenerator();
      if (generator == null) {
        continue;
      }
      final PlotChunk<?> result = lazyChunk.getOrCreate();
      final PlotChunk<?> primaryMask;
      // coords
      int bxx;
      int bzz;
      int txx;
      int tzz;
      // gen
      if (area.TYPE == 2) {
        bxx = Math.max(0, area.getRegion().minX - bx);
        bzz = Math.max(0, area.getRegion().minZ - bz);
        txx = Math.min(15, area.getRegion().maxX - bx);
        tzz = Math.min(15, area.getRegion().maxZ - bz);
        primaryMask =
            new PlotChunk<Object>(wrap) {
              @Override
              public Object getChunkAbs() {
                return null;
              }

              @Override
              public void setBlock(int x, int y, int z, int id, byte data) {
                if (area.contains(bx + x, bz + z)) {
                  result.setBlock(x, y, z, id, data);
                }
              }

              @Override
              public void setBiome(int x, int z, int biome) {
                if (area.contains(bx + x, bz + z)) {
                  result.setBiome(x, z, biome);
                }
              }

              @Override
              public PlotChunk clone() {
                return null;
              }

              @Override
              public PlotChunk shallowClone() {
                return null;
              }
            };
      } else {
        bxx = bzz = 0;
        txx = tzz = 15;
        primaryMask = result;
      }
      PlotChunk<?> secondaryMask;
      PlotBlock air = new PlotBlock((short) 0, (byte) 0);
      if (area.TERRAIN == 2) {
        PlotManager manager = area.getPlotManager();
        final boolean[][] canPlace = new boolean[16][16];
        boolean has = false;
        for (int x = bxx; x <= txx; x++) {
          for (int z = bzz; z <= tzz; z++) {
            int rx = x + bx;
            int rz = z + bz;
            boolean can = manager.getPlotIdAbs(area, rx, 0, rz) == null;
            if (can) {
              for (int y = 1; y < 128; y++) {
                result.setBlock(x, y, z, air);
              }
              canPlace[x][z] = can;
              has = true;
            }
          }
        }
        if (!has) {
          continue;
        } else {
          toReturn = true;
        }
        secondaryMask =
            new PlotChunk<Object>(wrap) {
              @Override
              public Object getChunkAbs() {
                return null;
              }

              @Override
              public void setBlock(int x, int y, int z, int id, byte data) {
                if (canPlace[x][z]) {
                  primaryMask.setBlock(x, y, z, id, data);
                }
              }

              @Override
              public void setBiome(int x, int z, int biome) {}

              @Override
              public PlotChunk clone() {
                return null;
              }

              @Override
              public PlotChunk shallowClone() {
                return null;
              }
            };
      } else {
        secondaryMask = primaryMask;
        for (int x = bxx; x <= txx; x++) {
          for (int z = bzz; z <= tzz; z++) {
            for (int y = 1; y < 128; y++) {
              result.setBlock(x, y, z, air);
            }
          }
        }
        toReturn = true;
      }
      generator.generateChunk(secondaryMask, area, r);
    }
    if (lazyChunk.get() != null) {
      lazyChunk.get().addToQueue();
      lazyChunk.get().flush(false);
    }
    return toReturn;
  }
Esempio n. 29
0
 @Subscribe
 public void onWorldChange(EntityTeleportEvent event) {
   Entity entity = event.getEntity();
   if (entity instanceof Player) {
     org.spongepowered.api.world.Location from = event.getOldLocation();
     org.spongepowered.api.world.Location to = event.getNewLocation();
     int x2;
     if (getInt(from.getX()) != (x2 = getInt(to.getX()))) {
       Player player = (Player) entity;
       PlotPlayer pp = SpongeUtil.getPlayer(player);
       Extent extent = to.getExtent();
       if (!(extent instanceof World)) {
         pp.deleteMeta("location");
         return;
       }
       pp.setMeta("location", SpongeUtil.getLocation(player));
       World world = (World) extent;
       String worldname = ((World) extent).getName();
       PlotWorld plotworld = PS.get().getPlotWorld(worldname);
       if (plotworld == null) {
         return;
       }
       PlotManager plotManager = PS.get().getPlotManager(worldname);
       PlotId id = plotManager.getPlotId(plotworld, x2, 0, getInt(to.getZ()));
       Plot lastPlot = (Plot) pp.getMeta("lastplot");
       if (id == null) {
         if (lastPlot == null) {
           return;
         }
         if (!PlotListener.plotExit(pp, lastPlot)) {
           MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_EXIT_DENIED);
           if (lastPlot.equals(MainUtil.getPlot(SpongeUtil.getLocation(worldname, from)))) {
             event.setNewLocation(from);
           } else {
             event.setNewLocation(world.getSpawnLocation());
           }
           return;
         }
       } else if (lastPlot != null && id.equals(lastPlot.id)) {
         return;
       } else {
         Plot plot = MainUtil.getPlot(worldname, id);
         if (!PlotListener.plotEntry(pp, plot)) {
           MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_ENTRY_DENIED);
           if (!plot.equals(MainUtil.getPlot(SpongeUtil.getLocation(worldname, from)))) {
             event.setNewLocation(from);
           } else {
             event.setNewLocation(world.getSpawnLocation());
           }
           return;
         }
       }
       Integer border = MainUtil.worldBorder.get(worldname);
       if (border != null) {
         if (x2 > border) {
           Vector3d pos = to.getPosition();
           to = to.setPosition(new Vector3d(border - 4, pos.getY(), pos.getZ()));
           event.setNewLocation(to);
           MainUtil.sendMessage(pp, C.BORDER);
         } else if (x2 < -border) {
           Vector3d pos = to.getPosition();
           to = to.setPosition(new Vector3d(-border + 4, pos.getY(), pos.getZ()));
           event.setNewLocation(to);
           MainUtil.sendMessage(pp, C.BORDER);
         }
       }
       return;
     }
     int z2;
     if (getInt(from.getZ()) != (z2 = getInt(to.getZ()))) {
       Player player = (Player) entity;
       PlotPlayer pp = SpongeUtil.getPlayer(player);
       Extent extent = to.getExtent();
       if (!(extent instanceof World)) {
         pp.deleteMeta("location");
         return;
       }
       pp.setMeta("location", SpongeUtil.getLocation(player));
       World world = (World) extent;
       String worldname = ((World) extent).getName();
       PlotWorld plotworld = PS.get().getPlotWorld(worldname);
       if (plotworld == null) {
         return;
       }
       PlotManager plotManager = PS.get().getPlotManager(worldname);
       PlotId id = plotManager.getPlotId(plotworld, x2, 0, z2);
       Plot lastPlot = (Plot) pp.getMeta("lastplot");
       if (id == null) {
         if (lastPlot == null) {
           return;
         }
         if (!PlotListener.plotExit(pp, lastPlot)) {
           MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_EXIT_DENIED);
           if (lastPlot.equals(MainUtil.getPlot(SpongeUtil.getLocation(worldname, from)))) {
             event.setNewLocation(from);
           } else {
             event.setNewLocation(player.getWorld().getSpawnLocation());
           }
           return;
         }
       } else if (lastPlot != null && id.equals(lastPlot.id)) {
         return;
       } else {
         Plot plot = MainUtil.getPlot(worldname, id);
         if (!PlotListener.plotEntry(pp, plot)) {
           MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_ENTRY_DENIED);
           if (!plot.equals(MainUtil.getPlot(SpongeUtil.getLocation(worldname, from)))) {
             event.setNewLocation(from);
           } else {
             event.setNewLocation(player.getWorld().getSpawnLocation());
           }
           return;
         }
       }
       Integer border = MainUtil.worldBorder.get(worldname);
       if (border != null) {
         if (z2 > border) {
           Vector3d pos = to.getPosition();
           to = to.setPosition(new Vector3d(pos.getX(), pos.getY(), border - 4));
           event.setNewLocation(to);
           MainUtil.sendMessage(pp, C.BORDER);
         } else if (z2 < -border) {
           Vector3d pos = to.getPosition();
           to = to.setPosition(new Vector3d(pos.getX(), pos.getY(), -border + 4));
           event.setNewLocation(to);
           MainUtil.sendMessage(pp, C.BORDER);
         }
       }
     }
   }
 }
Esempio n. 30
0
  @Override
  public boolean onCommand(final PlotPlayer plr, final String[] args) {

    final Location loc = plr.getLocationFull();
    final Plot plot = MainUtil.getPlot(loc);
    if (plot == null) {
      return !sendMessage(plr, C.NOT_IN_PLOT);
    }
    if ((plot == null) || !plot.hasOwner()) {
      MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
      return false;
    }
    final boolean admin = Permissions.hasPermission(plr, "plots.admin.command.merge");
    if (!plot.isOwner(plr.getUUID()) && !admin) {
      MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
      return false;
    }
    int direction = -1;
    if (args.length == 0) {
      switch (direction(plr.getLocationFull().getYaw())) {
        case "NORTH":
          direction = 0;
          break;
        case "EAST":
          direction = 1;
          break;
        case "SOUTH":
          direction = 2;
          break;
        case "WEST":
          direction = 3;
          break;
      }
    } else {
      for (int i = 0; i < values.length; i++) {
        if (args[0].equalsIgnoreCase(values[i]) || args[0].equalsIgnoreCase(aliases[i])) {
          direction = i;
          break;
        }
      }
    }
    if (direction == -1) {
      MainUtil.sendMessage(
          plr,
          C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + StringMan.join(values, C.BLOCK_LIST_SEPARATER.s()));
      MainUtil.sendMessage(plr, C.DIRECTION.s().replaceAll("%dir%", direction(loc.getYaw())));
      return false;
    }
    PlotId bot = MainUtil.getBottomPlot(plot).id;
    PlotId top = MainUtil.getTopPlot(plot).id;
    ArrayList<PlotId> selPlots;
    final String world = loc.getWorld();
    switch (direction) {
      case 0: // north = -y
        selPlots =
            MainUtil.getMaxPlotSelectionIds(
                world, new PlotId(bot.x, bot.y - 1), new PlotId(top.x, top.y));
        break;
      case 1: // east = +x
        selPlots =
            MainUtil.getMaxPlotSelectionIds(
                world, new PlotId(bot.x, bot.y), new PlotId(top.x + 1, top.y));
        break;
      case 2: // south = +y
        selPlots =
            MainUtil.getMaxPlotSelectionIds(
                world, new PlotId(bot.x, bot.y), new PlotId(top.x, top.y + 1));
        break;
      case 3: // west = -x
        selPlots =
            MainUtil.getMaxPlotSelectionIds(
                world, new PlotId(bot.x - 1, bot.y), new PlotId(top.x, top.y));
        break;
      default:
        return false;
    }
    int size = selPlots.size();
    if (Permissions.hasPermissionRange(plr, "plots.merge", Settings.MAX_PLOTS) < size) {
      MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.merge." + size);
      return false;
    }
    final PlotId botId = selPlots.get(0);
    final PlotId topId = selPlots.get(selPlots.size() - 1);
    final PlotId bot1 = MainUtil.getBottomPlot(MainUtil.getPlot(world, botId)).id;
    final PlotId bot2 = MainUtil.getBottomPlot(MainUtil.getPlot(world, topId)).id;
    final PlotId top1 = MainUtil.getTopPlot(MainUtil.getPlot(world, topId)).id;
    final PlotId top2 = MainUtil.getTopPlot(MainUtil.getPlot(world, botId)).id;
    bot = new PlotId(Math.min(bot1.x, bot2.x), Math.min(bot1.y, bot2.y));
    top = new PlotId(Math.max(top1.x, top2.x), Math.max(top1.y, top2.y));
    final ArrayList<PlotId> plots = MainUtil.getMaxPlotSelectionIds(world, bot, top);
    boolean multiMerge = false;
    final HashSet<UUID> multiUUID = new HashSet<UUID>();
    HashSet<PlotId> multiPlots = new HashSet<>();
    final UUID u1 = plot.owner;
    for (final PlotId myid : plots) {
      final Plot myplot = PS.get().getPlot(world, myid);
      if (myplot == null || myplot.owner == null) {
        MainUtil.sendMessage(plr, C.NO_PERM_MERGE.s().replaceAll("%plot%", myid.toString()));
        return false;
      }
      UUID u2 = myplot.owner;
      if (u2.equals(u1)) {
        continue;
      }
      PlotPlayer p2 = UUIDHandler.getPlayer(u2);
      if (p2 == null) {
        MainUtil.sendMessage(plr, C.NO_PERM_MERGE.s().replaceAll("%plot%", myid.toString()));
        return false;
      }
      multiMerge = true;
      multiPlots.add(myid);
      multiUUID.add(u2);
    }
    if (multiMerge) {
      if (!Permissions.hasPermission(plr, C.PERMISSION_MERGE_OTHER)) {
        MainUtil.sendMessage(plr, C.NO_PERMISSION, C.PERMISSION_MERGE_OTHER.s());
        return false;
      }
      for (final UUID uuid : multiUUID) {
        PlotPlayer accepter = UUIDHandler.getPlayer(uuid);
        CmdConfirm.addPending(
            accepter,
            C.MERGE_REQUEST_CONFIRM.s().replaceAll("%s", plr.getName()),
            new Runnable() {
              @Override
              public void run() {
                PlotPlayer accepter = UUIDHandler.getPlayer(uuid);
                multiUUID.remove(uuid);
                if (multiUUID.size() == 0) {
                  PlotPlayer pp = UUIDHandler.getPlayer(u1);
                  if (pp == null) {
                    sendMessage(accepter, C.MERGE_NOT_VALID);
                    return;
                  }
                  final PlotWorld plotWorld = PS.get().getPlotWorld(world);
                  if ((EconHandler.manager != null) && plotWorld.USE_ECONOMY) {
                    double cost = plotWorld.MERGE_PRICE;
                    cost = plots.size() * cost;
                    if (cost > 0d) {
                      if (EconHandler.manager.getMoney(plr) < cost) {
                        sendMessage(plr, C.CANNOT_AFFORD_MERGE, cost + "");
                        return;
                      }
                      EconHandler.manager.withdrawMoney(plr, cost);
                      sendMessage(plr, C.REMOVED_BALANCE, cost + "");
                    }
                  }
                  final boolean result = EventUtil.manager.callMerge(world, plot, plots);
                  if (!result) {
                    MainUtil.sendMessage(plr, "&cMerge has been cancelled");
                    return;
                  }
                  MainUtil.sendMessage(plr, C.SUCCESS_MERGE);
                  MainUtil.mergePlots(world, plots, true, true);
                  MainUtil.setSign(UUIDHandler.getName(plot.owner), plot);
                }
                MainUtil.sendMessage(accepter, C.MERGE_ACCEPTED);
              }
            });
      }
      MainUtil.sendMessage(plr, C.MERGE_REQUESTED);
      return true;
    }
    final PlotWorld plotWorld = PS.get().getPlotWorld(world);
    if ((EconHandler.manager != null) && plotWorld.USE_ECONOMY) {
      double cost = plotWorld.MERGE_PRICE;
      cost = plots.size() * cost;
      if (cost > 0d) {
        if (EconHandler.manager.getMoney(plr) < cost) {
          sendMessage(plr, C.CANNOT_AFFORD_MERGE, cost + "");
          return false;
        }
        EconHandler.manager.withdrawMoney(plr, cost);
        sendMessage(plr, C.REMOVED_BALANCE, cost + "");
      }
    }
    final boolean result = EventUtil.manager.callMerge(world, plot, plots);
    if (!result) {
      MainUtil.sendMessage(plr, "&cMerge has been cancelled");
      return false;
    }
    MainUtil.sendMessage(plr, C.SUCCESS_MERGE);
    MainUtil.mergePlots(world, plots, true, true);
    MainUtil.setSign(UUIDHandler.getName(plot.owner), plot);
    return true;
  }