@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); }
@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); }
@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 } }
@Subscribe public void onBlockPlace(PlayerPlaceBlockEvent event) { Player player = event.getEntity(); World world = player.getWorld(); String worldname = world.getName(); org.spongepowered.api.world.Location blockLoc = event.getLocation(); final Location loc = SpongeUtil.getLocation(worldname, blockLoc); final Plot plot = MainUtil.getPlot(loc); if (plot != null) { if (blockLoc.getY() == 0) { event.setCancelled(true); return; } final PlotPlayer pp = SpongeUtil.getPlayer(player); if (!plot.hasOwner()) { if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_UNOWNED)) { return; } MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_UNOWNED); event.setCancelled(true); return; } else if (!plot.isAdded(pp.getUUID())) { final Flag destroy = FlagManager.getPlotFlag(plot, "place"); BlockState state = blockLoc.getBlock(); if ((destroy != null) && ((HashSet<PlotBlock>) destroy.getValue()) .contains(SpongeMain.THIS.getPlotBlock(state))) { return; } if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER)) { return; } MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_DESTROY_OTHER); event.setCancelled(true); } else if (Settings.DONE_RESTRICTS_BUILDING && plot.getSettings().flags.containsKey("done")) { if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER)) { MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_OTHER); event.setCancelled(true); return; } } return; } final PlotPlayer pp = SpongeUtil.getPlayer(player); if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_ROAD)) { return; } if (MainUtil.isPlotArea(loc)) { MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_ROAD); event.setCancelled(true); } }
@Subscribe public void onFluidSpread(FluidSpreadEvent event) { // TODO This event isn't called Location loc = SpongeUtil.getLocation(event.getLocation()); final Plot plot = MainUtil.getPlot(loc); if (plot == null) { if (MainUtil.isPlotAreaAbs(loc)) { event.setCancelled(true); } return; } event.filterLocations( new Predicate<org.spongepowered.api.world.Location<World>>() { @Override public boolean apply(org.spongepowered.api.world.Location<World> loc) { if (!plot.equals(MainUtil.getPlot(SpongeUtil.getLocation(loc)))) { return false; } return true; } }); }
public static Location getHome(final PlotCluster cluster) { final BlockLoc home = cluster.settings.getPosition(); Location toReturn; if (home.y == 0) { // default pos final PlotId center = getCenterPlot(cluster); toReturn = MainUtil.getPlotHome(cluster.world, center); if (toReturn.getY() == 0) { final PlotManager manager = PlotSquared.getPlotManager(cluster.world); final PlotWorld plotworld = PlotSquared.getPlotWorld(cluster.world); final Location loc = manager.getSignLoc(plotworld, MainUtil.getPlot(cluster.world, center)); toReturn.setY(loc.getY()); } } else { toReturn = getClusterBottom(cluster).add(home.x, home.y, home.z); } final int max = BukkitUtil.getHeighestBlock(cluster.world, toReturn.getX(), toReturn.getZ()); if (max > toReturn.getY()) { toReturn.setY(max); } return toReturn; }
@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; }
@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; }
@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); } } } } }
@Subscribe public void onBigBoom(final WorldOnExplosionEvent event) { World worldObj = event.getWorld(); final String world = worldObj.getName(); if (!PS.get().isPlotWorld(world)) { return; } Explosion explosion = event.getExplosion(); Vector3d origin = explosion.getOrigin(); Location loc = new Location(world, origin.getFloorX(), origin.getFloorY(), origin.getFloorZ()); final Plot plot = MainUtil.getPlot(loc); if ((plot != null) && plot.hasOwner()) { if (FlagManager.isPlotFlagTrue(plot, "explosion")) { event.filterLocations( new Predicate<org.spongepowered.api.world.Location<World>>() { @Override public boolean apply(org.spongepowered.api.world.Location loc) { if (!plot.equals(MainUtil.getPlot(SpongeUtil.getLocation(loc)))) { return false; } return true; } }); event.filterEntities( new Predicate<Entity>() { @Override public boolean apply(Entity entity) { if (!plot.equals(MainUtil.getPlot(SpongeUtil.getLocation(entity)))) { return false; } return true; } }); return; } } if (MainUtil.isPlotArea(loc)) { explosion.shouldBreakBlocks(false); explosion.canCauseFire(false); explosion.setRadius(0); event.filterEntities( new Predicate<Entity>() { @Override public boolean apply(Entity entity) { if (!plot.equals(MainUtil.getPlot(SpongeUtil.getLocation(entity)))) { return false; } return true; } }); return; } else { if (FlagManager.isPlotFlagTrue(plot, "explosion")) { event.filterLocations( new Predicate<org.spongepowered.api.world.Location<World>>() { @Override public boolean apply(org.spongepowered.api.world.Location loc) { if (!plot.equals(MainUtil.getPlot(SpongeUtil.getLocation(loc)))) { return false; } return true; } }); event.filterEntities( new Predicate<Entity>() { @Override public boolean apply(Entity entity) { if (!plot.equals(MainUtil.getPlot(SpongeUtil.getLocation(entity)))) { return false; } return true; } }); return; } } }
@Subscribe public void onMobSpawn(EntitySpawnEvent event) { Entity entity = event.getEntity(); if (entity instanceof Player) { return; } final Location loc = SpongeUtil.getLocation(event.getLocation()); final String world = loc.getWorld(); PlotWorld plotworld = PS.get().getPlotWorld(world); if (plotworld == null) { return; } Plot plot = MainUtil.getPlot(loc); if (plot == null) { if (MainUtil.isPlotRoad(loc)) { event.setCancelled(true); } return; } final PlotWorld pW = PS.get().getPlotWorld(world); // TODO selectively cancel depending on spawn reason // - Not sure if possible to get spawn reason (since there are no callbacks) if (entity.getType() == EntityTypes.DROPPED_ITEM) { if (FlagManager.isPlotFlagFalse(plot, "item-drop")) { event.setCancelled(true); } return; } int[] mobs = null; if (entity instanceof Living) { if (!plotworld.MOB_SPAWNING) { event.setCancelled(true); return; } Flag mobCap = FlagManager.getPlotFlag(plot, "mob-cap"); if (mobCap != null) { Integer cap = (Integer) mobCap.getValue(); if (cap == 0) { event.setCancelled(true); return; } if (mobs == null) mobs = ChunkManager.manager.countEntities(plot); if (mobs[3] >= cap) { event.setCancelled(true); return; } } if (entity instanceof Ambient || entity instanceof Animal) { Flag animalFlag = FlagManager.getPlotFlag(plot, "animal-cap"); if (animalFlag != null) { int cap = ((Integer) animalFlag.getValue()); if (cap == 0) { event.setCancelled(true); return; } if (mobs == null) mobs = ChunkManager.manager.countEntities(plot); if (mobs[1] >= cap) { event.setCancelled(true); return; } } } if (entity instanceof Monster) { Flag monsterFlag = FlagManager.getPlotFlag(plot, "hostile-cap"); if (monsterFlag != null) { int cap = ((Integer) monsterFlag.getValue()); if (cap == 0) { event.setCancelled(true); return; } if (mobs == null) mobs = ChunkManager.manager.countEntities(plot); if (mobs[2] >= cap) { event.setCancelled(true); return; } } } return; } if (entity instanceof Minecart || entity instanceof Boat) { Flag vehicleFlag = FlagManager.getPlotFlag(plot, "vehicle-cap"); if (vehicleFlag != null) { int cap = ((Integer) vehicleFlag.getValue()); if (cap == 0) { event.setCancelled(true); return; } if (mobs == null) mobs = ChunkManager.manager.countEntities(plot); if (mobs[4] >= cap) { event.setCancelled(true); return; } } } Flag entityCap = FlagManager.getPlotFlag(plot, "entity-cap"); if (entityCap != null) { Integer cap = (Integer) entityCap.getValue(); if (cap == 0) { event.setCancelled(true); return; } if (mobs == null) mobs = ChunkManager.manager.countEntities(plot); if (mobs[0] >= cap) { event.setCancelled(true); return; } } }
@Override public boolean execute(final PlotPlayer plr, final String... args) { if (plr == null) { if (args.length < 3) { return !MainUtil.sendMessage( null, "如果你删除了你的数据库, 这个指令将可以识别地皮牌子来恢复数据库. \n\n&c缺失地皮世界参数 /plot debugclaimtest {世界名称} {最小地皮ID} {最大地皮ID}"); } final String world = args[0]; if (!BlockManager.manager.isWorld(world) || !PS.get().isPlotWorld(world)) { return !MainUtil.sendMessage(null, "&c无效的地皮世界!"); } PlotId min, max; try { final String[] split1 = args[1].split(";"); final String[] split2 = args[2].split(";"); min = new PlotId(Integer.parseInt(split1[0]), Integer.parseInt(split1[1])); max = new PlotId(Integer.parseInt(split2[0]), Integer.parseInt(split2[1])); } catch (final Exception e) { return !MainUtil.sendMessage( null, "&c无效的最大最小地皮ID参数. &7地皮ID参数格式 &cX;Y &7这个 X,Y 是地皮的坐标\n加入这个参数后, 数据恢复将在所选区域进行."); } MainUtil.sendMessage(null, "&3木牌恢复&8->&3PlotSquared&8: &7正在开始地皮数据恢复. 该过程需要一些时间..."); MainUtil.sendMessage(null, "&3木牌恢复&8->&3PlotSquared&8: 发现超过 25000 区块. 请限制半径... (~3.8 分钟)"); final PlotManager manager = PS.get().getPlotManager(world); final PlotWorld plotworld = PS.get().getPlotWorld(world); final ArrayList<Plot> plots = new ArrayList<>(); for (final PlotId id : MainUtil.getPlotSelectionIds(min, max)) { final Plot plot = MainUtil.getPlot(world, id); final boolean contains = PS.get().getPlots(world).containsKey(plot.id); if (contains) { MainUtil.sendMessage(null, " - &c数据库已存在: " + plot.id); continue; } final Location loc = manager.getSignLoc(plotworld, plot); final ChunkLoc chunk = new ChunkLoc(loc.getX() >> 4, loc.getZ() >> 4); final boolean result = ChunkManager.manager.loadChunk(world, chunk); if (!result) { continue; } final String[] lines = BlockManager.manager.getSign(loc); if (lines != null) { String line = lines[2]; if ((line != null) && (line.length() > 2)) { line = line.substring(2); final BiMap<StringWrapper, UUID> map = UUIDHandler.getUuidMap(); UUID uuid = (map.get(new StringWrapper(line))); if (uuid == null) { for (final StringWrapper string : map.keySet()) { if (string.value.toLowerCase().startsWith(line.toLowerCase())) { uuid = map.get(string); break; } } } if (uuid == null) { uuid = UUIDHandler.getUUID(line); } if (uuid != null) { MainUtil.sendMessage(null, " - &a发现了地皮: " + plot.id + " : " + line); plot.owner = uuid; plot.hasChanged = true; plots.add(plot); } else { MainUtil.sendMessage(null, " - &c无效的玩家名称: " + plot.id + " : " + line); } } } } if (plots.size() > 0) { MainUtil.sendMessage(null, "&3木牌恢复&8->&3PlotSquared&8: &7更新了 '" + plots.size() + "' 块地皮!"); DBFunc.createPlotsAndData( plots, new Runnable() { @Override public void run() { MainUtil.sendMessage(null, "&6数据库更新成功!"); } }); for (final Plot plot : plots) { PS.get().updatePlot(plot); } MainUtil.sendMessage(null, "&3木牌恢复&8->&3PlotSquared&8: &7已完成!"); } else { MainUtil.sendMessage(null, "给出的搜索条件已经没有未恢复地图了."); } } else { MainUtil.sendMessage(plr, "&6这个指令只能通过控制台使用."); } return true; }
@Override public boolean execute(final PlotPlayer player, final String... args) { if (args.length == 1) { if (args[0].equalsIgnoreCase("next")) { ArrayList<Plot> plots = new ArrayList<>(PlotSquared.getPlots()); Collections.sort( plots, new Comparator<Plot>() { @Override public int compare(Plot p1, Plot p2) { int v1 = 0; int v2 = 0; if (p1.settings.ratings != null) { for (Entry<UUID, Integer> entry : p1.settings.ratings.entrySet()) { v1 -= 11 - entry.getValue(); } } if (p2.settings.ratings != null) { for (Entry<UUID, Integer> entry : p2.settings.ratings.entrySet()) { v2 -= 11 - entry.getValue(); } } return v2 - v1; } }); UUID uuid = player.getUUID(); for (Plot p : plots) { if (p.settings.ratings == null || !p.settings.ratings.containsKey(uuid)) { MainUtil.teleportPlayer(player, player.getLocation(), p); MainUtil.sendMessage(player, C.RATE_THIS); return true; } } MainUtil.sendMessage(player, C.FOUND_NO_PLOTS); return false; } } final Location loc = player.getLocation(); final Plot plot = MainUtil.getPlot(loc); if (plot == null) { return !sendMessage(player, C.NOT_IN_PLOT); } if (!plot.hasOwner()) { sendMessage(player, C.RATING_NOT_OWNED); return true; } if (plot.isOwner(player.getUUID())) { sendMessage(player, C.RATING_NOT_YOUR_OWN); return true; } if (Settings.RATING_CATEGORIES != null && Settings.RATING_CATEGORIES.size() != 0) { final Runnable run = new Runnable() { @Override public void run() { if (plot.settings.ratings.containsKey(player.getUUID())) { sendMessage(player, C.RATING_ALREADY_EXISTS, plot.getId().toString()); return; } final MutableInt index = new MutableInt(0); final MutableInt rating = new MutableInt(0); String title = Settings.RATING_CATEGORIES.get(0); PlotInventory inventory = new PlotInventory(player, 1, title) { public boolean onClick(int i) { rating.add((i + 1) * Math.pow(10, index.intValue())); index.increment(); if (index.intValue() >= Settings.RATING_CATEGORIES.size()) { close(); // set rating! plot.settings.ratings.put(player.getUUID(), rating.intValue()); DBFunc.setRating(plot, player.getUUID(), rating.intValue()); sendMessage(player, C.RATING_APPLIED, plot.getId().toString()); sendMessage(player, C.RATING_APPLIED, plot.getId().toString()); return false; } setTitle(Settings.RATING_CATEGORIES.get(index.intValue())); return false; } }; inventory.setItem(0, new PlotItemStack(35, (short) 12, 0, "0/8", null)); inventory.setItem(1, new PlotItemStack(35, (short) 14, 1, "1/8", null)); inventory.setItem(2, new PlotItemStack(35, (short) 1, 2, "2/8", null)); inventory.setItem(3, new PlotItemStack(35, (short) 4, 3, "3/8", null)); inventory.setItem(4, new PlotItemStack(35, (short) 5, 4, "4/8", null)); inventory.setItem(5, new PlotItemStack(35, (short) 9, 5, "5/8", null)); inventory.setItem(6, new PlotItemStack(35, (short) 11, 6, "6/8", null)); inventory.setItem(7, new PlotItemStack(35, (short) 10, 7, "7/8", null)); inventory.setItem(8, new PlotItemStack(35, (short) 2, 8, "8/8", null)); inventory.openInventory(); } }; if (plot.settings.ratings == null) { TaskManager.runTaskAsync( new Runnable() { @Override public void run() { plot.settings.ratings = DBFunc.getRatings(plot); run.run(); } }); return true; } run.run(); return true; } if (args.length < 1) { sendMessage(player, C.RATING_NOT_VALID); return true; } final String arg = args[0]; if (arg.equalsIgnoreCase("next")) {} final int rating; if (StringUtils.isNumeric(arg) && arg.length() < 3 && arg.length() > 0) { rating = Integer.parseInt(arg); if (rating > 10) { sendMessage(player, C.RATING_NOT_VALID); return false; } } else { sendMessage(player, C.RATING_NOT_VALID); return false; } final UUID uuid = player.getUUID(); final Runnable run = new Runnable() { @Override public void run() { if (plot.settings.ratings.containsKey(uuid)) { sendMessage(player, C.RATING_ALREADY_EXISTS, plot.getId().toString()); return; } plot.settings.ratings.put(uuid, rating); DBFunc.setRating(plot, uuid, rating); sendMessage(player, C.RATING_APPLIED, plot.getId().toString()); } }; if (plot.settings.ratings == null) { TaskManager.runTaskAsync( new Runnable() { @Override public void run() { plot.settings.ratings = DBFunc.getRatings(plot); run.run(); } }); return true; } run.run(); return true; }