diff --git a/Core/build.gradle.kts b/Core/build.gradle.kts index 423aca3ac..aee1b3d4f 100644 --- a/Core/build.gradle.kts +++ b/Core/build.gradle.kts @@ -12,7 +12,7 @@ dependencies { compileOnlyApi("org.yaml:snakeyaml:1.26") // Some platforms provide this // Adventure stuff - api("net.kyori:adventure-api:4.1.0") + api("net.kyori:adventure-api:4.1.1") api("net.kyori:adventure-text-minimessage:4.0.0-SNAPSHOT") // Guice diff --git a/Core/src/main/java/com/plotsquared/core/command/Area.java b/Core/src/main/java/com/plotsquared/core/command/Area.java index 8d1bc9a75..c2a6103c1 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Area.java +++ b/Core/src/main/java/com/plotsquared/core/command/Area.java @@ -29,9 +29,7 @@ import com.google.inject.Inject; import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.ConfigurationSection; import com.plotsquared.core.configuration.ConfigurationUtil; -import com.plotsquared.core.configuration.caption.Caption; import com.plotsquared.core.configuration.caption.CaptionHolder; -import com.plotsquared.core.configuration.caption.StaticCaption; import com.plotsquared.core.configuration.caption.Templates; import com.plotsquared.core.configuration.caption.TranslatableCaption; import com.plotsquared.core.configuration.file.YamlConfiguration; @@ -110,11 +108,13 @@ public class Area extends SubCommand { private final Map> metaData = new HashMap<>(); @Inject public Area(@Nonnull final PlotAreaManager plotAreaManager, - @WorldConfig @Nonnull final YamlConfiguration worldConfiguration, - @WorldFile @Nonnull final File worldFile, - @Nonnull final HybridPlotWorldFactory hybridPlotWorldFactory, - @Nonnull final SetupUtils setupUtils, @Nonnull final WorldUtil worldUtil, - @Nonnull final RegionManager regionManager, @Nonnull final GlobalBlockQueue blockQueue) { + @WorldConfig @Nonnull final YamlConfiguration worldConfiguration, + @WorldFile @Nonnull final File worldFile, + @Nonnull final HybridPlotWorldFactory hybridPlotWorldFactory, + @Nonnull final SetupUtils setupUtils, + @Nonnull final WorldUtil worldUtil, + @Nonnull final RegionManager regionManager, + @Nonnull final GlobalBlockQueue blockQueue) { this.plotAreaManager = plotAreaManager; this.worldConfiguration = worldConfiguration; this.worldFile = worldFile; @@ -137,31 +137,26 @@ public class Area extends SubCommand { return false; } if (!Permissions.hasPermission(player, "plots.area.create")) { - player.sendMessage(TranslatableCaption.of("permission.no_permission"), - Template.of("node", "plots.area.create")); + player.sendMessage(TranslatableCaption.of("permission.no_permission"), Template.of("node", "plots.area.create")); return false; } if (args.length < 2) { - player.sendMessage(TranslatableCaption.of("single.single_area_needs_name"), - Template.of("command", "/plot area single ")); + player.sendMessage(TranslatableCaption.of("single.single_area_needs_name"), Template.of("command", "/plot area single ")); return false; } - final PlotArea existingArea = - this.plotAreaManager.getPlotArea(player.getLocation().getWorldName(), args[1]); + final PlotArea existingArea = this.plotAreaManager.getPlotArea(player.getLocation().getWorldName(), args[1]); if (existingArea != null && existingArea.getId().equalsIgnoreCase(args[1])) { player.sendMessage(TranslatableCaption.of("single.single_area_name_taken")); return false; } - final LocalSession localSession = - WorldEdit.getInstance().getSessionManager().getIfPresent(player.toActor()); + final LocalSession localSession = WorldEdit.getInstance().getSessionManager().getIfPresent(player.toActor()); if (localSession == null) { player.sendMessage(TranslatableCaption.of("single.single_area_missing_selection")); return false; } Region playerSelectedRegion = null; try { - playerSelectedRegion = - localSession.getSelection(((Player) player.toActor()).getWorld()); + playerSelectedRegion = localSession.getSelection(((Player) player.toActor()).getWorld()); } catch (final Exception ignored) { } if (playerSelectedRegion == null) { @@ -172,8 +167,8 @@ public class Area extends SubCommand { player.sendMessage(TranslatableCaption.of("single.single_area_not_square")); return false; } - if (this.plotAreaManager.getPlotAreas( - Objects.requireNonNull(playerSelectedRegion.getWorld()).getName(), CuboidRegion.makeCuboid(playerSelectedRegion)).length != 0) { + if (this.plotAreaManager.getPlotAreas(Objects.requireNonNull(playerSelectedRegion.getWorld()).getName(), + CuboidRegion.makeCuboid(playerSelectedRegion)).length != 0) { player.sendMessage(TranslatableCaption.of("single.single_area_overlapping")); } // Alter the region @@ -181,18 +176,15 @@ public class Area extends SubCommand { final BlockVector3 playerSelectionMax = playerSelectedRegion.getMaximumPoint(); // Create a new selection that spans the entire vertical range of the world final CuboidRegion selectedRegion = - new CuboidRegion(playerSelectedRegion.getWorld(), - BlockVector3.at(playerSelectionMin.getX(), 0, playerSelectionMin.getZ()), + new CuboidRegion(playerSelectedRegion.getWorld(), BlockVector3.at(playerSelectionMin.getX(), 0, playerSelectionMin.getZ()), BlockVector3.at(playerSelectionMax.getX(), 255, playerSelectionMax.getZ())); // There's only one plot in the area... final PlotId plotId = PlotId.of(1, 1); final HybridPlotWorld hybridPlotWorld = this.hybridPlotWorldFactory - .create(player.getLocation().getWorldName(), args[1], - Objects.requireNonNull(PlotSquared.platform()).getDefaultGenerator(), + .create(player.getLocation().getWorldName(), args[1], Objects.requireNonNull(PlotSquared.platform()).getDefaultGenerator(), plotId, plotId); // Plot size is the same as the region width - hybridPlotWorld.PLOT_WIDTH = - hybridPlotWorld.SIZE = (short) selectedRegion.getWidth(); + hybridPlotWorld.PLOT_WIDTH = hybridPlotWorld.SIZE = (short) selectedRegion.getWidth(); // We use a schematic generator hybridPlotWorld.setTerrain(PlotAreaTerrainType.NONE); // It is always a partial plot world @@ -200,30 +192,24 @@ public class Area extends SubCommand { // We save the schematic :D hybridPlotWorld.PLOT_SCHEMATIC = true; // Set the road width to 0 - hybridPlotWorld.ROAD_WIDTH = - hybridPlotWorld.ROAD_OFFSET_X = hybridPlotWorld.ROAD_OFFSET_Z = 0; + hybridPlotWorld.ROAD_WIDTH = hybridPlotWorld.ROAD_OFFSET_X = hybridPlotWorld.ROAD_OFFSET_Z = 0; // Set the plot height to the selection height - hybridPlotWorld.PLOT_HEIGHT = hybridPlotWorld.ROAD_HEIGHT = - hybridPlotWorld.WALL_HEIGHT = playerSelectionMin.getBlockY(); + hybridPlotWorld.PLOT_HEIGHT = hybridPlotWorld.ROAD_HEIGHT = hybridPlotWorld.WALL_HEIGHT = playerSelectionMin.getBlockY(); // No sign plz hybridPlotWorld.setAllowSigns(false); final File parentFile = FileUtils.getFile(PlotSquared.platform().getDirectory(), - "schematics" + File.separator + "GEN_ROAD_SCHEMATIC" + File.separator - + hybridPlotWorld.getWorldName() + File.separator + hybridPlotWorld - .getId()); + "schematics" + File.separator + "GEN_ROAD_SCHEMATIC" + File.separator + hybridPlotWorld.getWorldName() + File.separator + + hybridPlotWorld.getId()); if (!parentFile.exists() && !parentFile.mkdirs()) { player.sendMessage(TranslatableCaption.of("single.single_area_could_not_make_directories")); return false; } final File file = new File(parentFile, "plot.schem"); - try (final ClipboardWriter clipboardWriter = BuiltInClipboardFormat.SPONGE_SCHEMATIC - .getWriter(new FileOutputStream(file))) { + try (final ClipboardWriter clipboardWriter = BuiltInClipboardFormat.SPONGE_SCHEMATIC.getWriter(new FileOutputStream(file))) { final BlockArrayClipboard clipboard = new BlockArrayClipboard(selectedRegion); - final EditSession editSession = WorldEdit.getInstance().getEditSessionFactory() - .getEditSession(selectedRegion.getWorld(), -1); + final EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(selectedRegion.getWorld(), -1); final ForwardExtentCopy forwardExtentCopy = - new ForwardExtentCopy(editSession, selectedRegion, clipboard, - selectedRegion.getMinimumPoint()); + new ForwardExtentCopy(editSession, selectedRegion, clipboard, selectedRegion.getMinimumPoint()); forwardExtentCopy.setCopyingBiomes(true); forwardExtentCopy.setCopyingEntities(true); Operations.complete(forwardExtentCopy); @@ -245,15 +231,12 @@ public class Area extends SubCommand { final BlockVector3 singlePos1 = selectedRegion.getMinimumPoint(); // Now the schematic is saved, which is wonderful! - PlotAreaBuilder singleBuilder = PlotAreaBuilder.ofPlotArea(hybridPlotWorld) - .plotManager(PlotSquared.platform().getPluginName()) - .generatorName(PlotSquared.platform().getPluginName()).maximumId(plotId) - .minimumId(plotId); + PlotAreaBuilder singleBuilder = PlotAreaBuilder.ofPlotArea(hybridPlotWorld).plotManager(PlotSquared.platform().getPluginName()) + .generatorName(PlotSquared.platform().getPluginName()).maximumId(plotId).minimumId(plotId); Runnable singleRun = () -> { final String path = - "worlds." + hybridPlotWorld.getWorldName() + ".areas." + hybridPlotWorld - .getId() + '-' + singleBuilder.minimumId() + '-' + singleBuilder - .maximumId(); + "worlds." + hybridPlotWorld.getWorldName() + ".areas." + hybridPlotWorld.getId() + '-' + singleBuilder.minimumId() + '-' + + singleBuilder.maximumId(); final int offsetX = singlePos1.getX(); final int offsetZ = singlePos1.getZ(); if (offsetX != 0) { @@ -267,10 +250,7 @@ public class Area extends SubCommand { PlotSquared.get().loadWorld(world, null); player.sendMessage(TranslatableCaption.of("single.single_area_created")); } else { - player.sendMessage( - TranslatableCaption.of("errors.error_create"), - Template.of("world", hybridPlotWorld.getWorldName()) - ); + player.sendMessage(TranslatableCaption.of("errors.error_create"), Template.of("world", hybridPlotWorld.getWorldName())); } }; singleRun.run(); @@ -279,8 +259,7 @@ public class Area extends SubCommand { case "setup": case "create": if (!Permissions.hasPermission(player, "plots.area.create")) { - player.sendMessage(TranslatableCaption.of("permission.no_permission"), - Template.of("node", "plots.area.create")); + player.sendMessage(TranslatableCaption.of("permission.no_permission"), Template.of("node", "plots.area.create")); return false; } switch (args.length) { @@ -291,103 +270,82 @@ public class Area extends SubCommand { case 2: switch (args[1].toLowerCase()) { case "pos1": { // Set position 1 - HybridPlotWorld area = (HybridPlotWorld) metaData - .computeIfAbsent(player.getUUID(), - missingUUID -> new HashMap<>()).get("area_create_area"); + HybridPlotWorld area = (HybridPlotWorld) metaData.computeIfAbsent(player.getUUID(), missingUUID -> new HashMap<>()) + .get("area_create_area"); if (area == null) { player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax"), Templates.of("value", "/plot area create [world[:id]] [=]...")); return false; } Location location = player.getLocation(); - metaData.computeIfAbsent(player.getUUID(), missingUUID -> new HashMap<>()) - .put("area_pos1", location); - player.sendMessage(TranslatableCaption.of("set.set_attribute"), - Template.of("attribute", "area_pos1"), - Template.of("value", location.getX() + "," + location.getZ())); - player.sendMessage(TranslatableCaption.of("area.set_pos2"), - Template.of("command", "/plot area create pos2")); + metaData.computeIfAbsent(player.getUUID(), missingUUID -> new HashMap<>()).put("area_pos1", location); + player.sendMessage(TranslatableCaption.of("set.set_attribute"), Template.of("attribute", "area_pos1"), + Template.of("value", location.getX() + "," + location.getZ())); + player.sendMessage(TranslatableCaption.of("area.set_pos2"), Template.of("command", "/plot area create pos2")); return true; } case "pos2": // Set position 2 and finish creation for type=2 (partial) - final HybridPlotWorld area = (HybridPlotWorld) metaData - .computeIfAbsent(player.getUUID(), - missingUUID -> new HashMap<>()).get("area_create_area"); + final HybridPlotWorld area = + (HybridPlotWorld) metaData.computeIfAbsent(player.getUUID(), missingUUID -> new HashMap<>()) + .get("area_create_area"); if (area == null) { player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax"), Templates.of("value", "/plot area create [world[:id]] [=]...")); return false; } Location pos1 = player.getLocation(); - Location pos2 = (Location) metaData - .computeIfAbsent(player.getUUID(), - missingUUID -> new HashMap<>()).get("area_pos1"); + Location pos2 = + (Location) metaData.computeIfAbsent(player.getUUID(), missingUUID -> new HashMap<>()).get("area_pos1"); int dx = Math.abs(pos1.getX() - pos2.getX()); int dz = Math.abs(pos1.getZ() - pos2.getZ()); - int numX = Math.max(1, - (dx + 1 + area.ROAD_WIDTH + area.SIZE / 2) / area.SIZE); - int numZ = Math.max(1, - (dz + 1 + area.ROAD_WIDTH + area.SIZE / 2) / area.SIZE); + int numX = Math.max(1, (dx + 1 + area.ROAD_WIDTH + area.SIZE / 2) / area.SIZE); + int numZ = Math.max(1, (dz + 1 + area.ROAD_WIDTH + area.SIZE / 2) / area.SIZE); int ddx = dx - (numX * area.SIZE - area.ROAD_WIDTH); int ddz = dz - (numZ * area.SIZE - area.ROAD_WIDTH); int bx = Math.min(pos1.getX(), pos2.getX()) + ddx; int bz = Math.min(pos1.getZ(), pos2.getZ()) + ddz; int tx = Math.max(pos1.getX(), pos2.getX()) - ddx; int tz = Math.max(pos1.getZ(), pos2.getZ()) - ddz; - int lower = (area.ROAD_WIDTH & 1) == 0 ? - area.ROAD_WIDTH / 2 - 1 : - area.ROAD_WIDTH / 2; + int lower = (area.ROAD_WIDTH & 1) == 0 ? area.ROAD_WIDTH / 2 - 1 : area.ROAD_WIDTH / 2; final int offsetX = bx - (area.ROAD_WIDTH == 0 ? 0 : lower); final int offsetZ = bz - (area.ROAD_WIDTH == 0 ? 0 : lower); final CuboidRegion region = RegionUtil.createRegion(bx, tx, bz, tz); - final Set areas = this.plotAreaManager - .getPlotAreasSet(area.getWorldName(), region); + final Set areas = this.plotAreaManager.getPlotAreasSet(area.getWorldName(), region); if (!areas.isEmpty()) { player.sendMessage(TranslatableCaption.of("cluster.cluster_intersection"), - Template.of("cluster", areas.iterator().next().toString())); + Template.of("cluster", areas.iterator().next().toString())); return false; } - PlotAreaBuilder builder = PlotAreaBuilder.ofPlotArea(area) - .plotManager(PlotSquared.platform().getPluginName()) - .generatorName(PlotSquared.platform().getPluginName()) - .minimumId(PlotId.of(1, 1)).maximumId(PlotId.of(numX, numZ)); + PlotAreaBuilder builder = PlotAreaBuilder.ofPlotArea(area).plotManager(PlotSquared.platform().getPluginName()) + .generatorName(PlotSquared.platform().getPluginName()).minimumId(PlotId.of(1, 1)) + .maximumId(PlotId.of(numX, numZ)); final String path = - "worlds." + area.getWorldName() + ".areas." + area.getId() + '-' - + builder.minimumId() + '-' + builder.maximumId(); + "worlds." + area.getWorldName() + ".areas." + area.getId() + '-' + builder.minimumId() + '-' + builder + .maximumId(); Runnable run = () -> { if (offsetX != 0) { - this.worldConfiguration - .set(path + ".road.offset.x", offsetX); + this.worldConfiguration.set(path + ".road.offset.x", offsetX); } if (offsetZ != 0) { - this.worldConfiguration - .set(path + ".road.offset.z", offsetZ); + this.worldConfiguration.set(path + ".road.offset.z", offsetZ); } final String world = this.setupUtils.setupWorld(builder); if (this.worldUtil.isWorld(world)) { PlotSquared.get().loadWorld(world, null); player.sendMessage(TranslatableCaption.of("setup.setup_finished")); - player.teleport(this.worldUtil.getSpawn(world), - TeleportCause.COMMAND); + player.teleport(this.worldUtil.getSpawn(world), TeleportCause.COMMAND); if (area.getTerrain() != PlotAreaTerrainType.ALL) { - QueueCoordinator queue = - blockQueue.getNewQueue(worldUtil.getWeWorld(world)); - queue.setChunkConsumer(chunk -> AugmentedUtils - .generate(null, world, chunk.getX(), chunk.getZ(), - null)); + QueueCoordinator queue = blockQueue.getNewQueue(worldUtil.getWeWorld(world)); + queue.setChunkConsumer(chunk -> AugmentedUtils.generate(null, world, chunk.getX(), chunk.getZ(), null)); queue.addReadChunks(region.getChunks()); queue.enqueue(); } } else { - player.sendMessage( - TranslatableCaption.of("errors.error_create"), - Template.of("world", area.getWorldName()) - ); + player.sendMessage(TranslatableCaption.of("errors.error_create"), Template.of("world", area.getWorldName())); } }; if (hasConfirmation(player)) { - CmdConfirm.addPending(player, - getCommandString() + " create pos2 (Creates world)", run); + CmdConfirm.addPending(player, getCommandString() + " create pos2 (Creates world)", run); } else { run.run(); } @@ -403,17 +361,14 @@ public class Area extends SubCommand { } PlotAreaBuilder builder = PlotAreaBuilder.newBuilder(); builder.worldName(split[0]); - final HybridPlotWorld pa = this.hybridPlotWorldFactory - .create(builder.worldName(), id, - PlotSquared.platform().getDefaultGenerator(), null, null); + final HybridPlotWorld pa = + this.hybridPlotWorldFactory.create(builder.worldName(), id, PlotSquared.platform().getDefaultGenerator(), null, null); PlotArea other = this.plotAreaManager.getPlotArea(pa.getWorldName(), id); if (other != null && Objects.equals(pa.getId(), other.getId())) { - player.sendMessage(TranslatableCaption.of("setup.setup_world_taken"), - Template.of("value", pa.toString())); + player.sendMessage(TranslatableCaption.of("setup.setup_world_taken"), Template.of("value", pa.toString())); return false; } - Set areas = - this.plotAreaManager.getPlotAreasSet(pa.getWorldName()); + Set areas = this.plotAreaManager.getPlotAreasSet(pa.getWorldName()); if (!areas.isEmpty()) { PlotArea area = areas.iterator().next(); pa.setType(area.getType()); @@ -422,11 +377,9 @@ public class Area extends SubCommand { for (int i = 2; i < args.length; i++) { String[] pair = args[i].split("="); if (pair.length != 2) { - player.sendMessage( - TranslatableCaption.of("commandconfig.command_syntax_extended"), - Template.of("value1,", getCommandString()), - Template.of("value2", " create [world[:id]] [=]...") - ); + player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax_extended"), + Template.of("value1,", getCommandString()), + Template.of("value2", " create [world[:id]] [=]...")); return false; } switch (pair[0].toLowerCase()) { @@ -449,49 +402,40 @@ public class Area extends SubCommand { break; case "f": case "floor": - pa.TOP_BLOCK = - ConfigurationUtil.BLOCK_BUCKET.parseString(pair[1]); + pa.TOP_BLOCK = ConfigurationUtil.BLOCK_BUCKET.parseString(pair[1]); break; case "m": case "main": - pa.MAIN_BLOCK = - ConfigurationUtil.BLOCK_BUCKET.parseString(pair[1]); + pa.MAIN_BLOCK = ConfigurationUtil.BLOCK_BUCKET.parseString(pair[1]); break; case "w": case "wall": - pa.WALL_FILLING = - ConfigurationUtil.BLOCK_BUCKET.parseString(pair[1]); + pa.WALL_FILLING = ConfigurationUtil.BLOCK_BUCKET.parseString(pair[1]); break; case "b": case "border": - pa.WALL_BLOCK = - ConfigurationUtil.BLOCK_BUCKET.parseString(pair[1]); + pa.WALL_BLOCK = ConfigurationUtil.BLOCK_BUCKET.parseString(pair[1]); break; case "terrain": pa.setTerrain(PlotAreaTerrainType.fromString(pair[1]) - .orElseThrow(() -> new IllegalArgumentException( - pair[1] + " is not a valid terrain."))); + .orElseThrow(() -> new IllegalArgumentException(pair[1] + " is not a valid terrain."))); builder.terrainType(pa.getTerrain()); break; case "type": - pa.setType(PlotAreaType.fromString(pair[1]).orElseThrow( - () -> new IllegalArgumentException( - pair[1] + " is not a valid type."))); + pa.setType(PlotAreaType.fromString(pair[1]) + .orElseThrow(() -> new IllegalArgumentException(pair[1] + " is not a valid type."))); builder.plotAreaType(pa.getType()); break; default: - player.sendMessage( - TranslatableCaption.of("commandconfig.command_syntax_extended"), - Template.of("value1", getCommandString()), - Template.of("value2", " create [world[:id]] [=]...") - ); + player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax_extended"), + Template.of("value1", getCommandString()), + Template.of("value2", " create [world[:id]] [=]...")); return false; } } if (pa.getType() != PlotAreaType.PARTIAL) { if (this.worldUtil.isWorld(pa.getWorldName())) { - player.sendMessage(TranslatableCaption.of("setup.setup_world_taken"), - Template.of("value", pa.getWorldName())); + player.sendMessage(TranslatableCaption.of("setup.setup_world_taken"), Template.of("value", pa.getWorldName())); return false; } Runnable run = () -> { @@ -499,8 +443,7 @@ public class Area extends SubCommand { if (!this.worldConfiguration.contains(path)) { this.worldConfiguration.createSection(path); } - ConfigurationSection section = - this.worldConfiguration.getConfigurationSection(path); + ConfigurationSection section = this.worldConfiguration.getConfigurationSection(path); pa.saveConfiguration(section); pa.loadConfiguration(section); builder.plotManager(PlotSquared.platform().getPluginName()); @@ -508,13 +451,9 @@ public class Area extends SubCommand { String world = this.setupUtils.setupWorld(builder); if (this.worldUtil.isWorld(world)) { player.sendMessage(TranslatableCaption.of("setup.setup_finished")); - player.teleport(this.worldUtil.getSpawn(world), - TeleportCause.COMMAND); + player.teleport(this.worldUtil.getSpawn(world), TeleportCause.COMMAND); } else { - player.sendMessage( - TranslatableCaption.of("errors.error_create"), - Template.of("world", pa.getWorldName()) - ); + player.sendMessage(TranslatableCaption.of("errors.error_create"), Template.of("world", pa.getWorldName())); } try { this.worldConfiguration.save(this.worldFile); @@ -523,49 +462,37 @@ public class Area extends SubCommand { } }; if (hasConfirmation(player)) { - CmdConfirm.addPending(player, - getCommandString() + ' ' + StringMan.join(args, " "), run); + CmdConfirm.addPending(player, getCommandString() + ' ' + StringMan.join(args, " "), run); } else { run.run(); } return true; } if (pa.getId() == null) { - player.sendMessage( - TranslatableCaption.of("commandconfig.command_syntax"), - Template.of("value", getUsage())); - player.sendMessage( - TranslatableCaption.of("commandconfig.command_syntax_extended"), - Template.of("value1", getCommandString()), - Template.of("value2", " create [world[:id]] [=]...") - ); + player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax"), Template.of("value", getUsage())); + player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax_extended"), + Template.of("value1", getCommandString()), Template.of("value2", " create [world[:id]] [=]...")); return false; } if (this.worldUtil.isWorld(pa.getWorldName())) { if (!player.getLocation().getWorldName().equals(pa.getWorldName())) { - player.teleport(this.worldUtil.getSpawn(pa.getWorldName()), - TeleportCause.COMMAND); + player.teleport(this.worldUtil.getSpawn(pa.getWorldName()), TeleportCause.COMMAND); } } else { builder.terrainType(PlotAreaTerrainType.NONE); builder.plotAreaType(PlotAreaType.NORMAL); this.setupUtils.setupWorld(builder); - player.teleport(this.worldUtil.getSpawn(pa.getWorldName()), - TeleportCause.COMMAND); + player.teleport(this.worldUtil.getSpawn(pa.getWorldName()), TeleportCause.COMMAND); } metaData.computeIfAbsent(player.getUUID(), missingUUID -> new HashMap<>()).put("area_create_area", pa); - player.sendMessage( - TranslatableCaption.of("single.get_position"), - Template.of("command", getCommandString()) - ); + player.sendMessage(TranslatableCaption.of("single.get_position"), Template.of("command", getCommandString())); break; } return true; case "i": case "info": { if (!Permissions.hasPermission(player, "plots.area.info")) { - player.sendMessage(TranslatableCaption.of("permission.no_permission"), - Template.of("node", "plots.area.info")); + player.sendMessage(TranslatableCaption.of("permission.no_permission"), Template.of("node", "plots.area.info")); return false; } PlotArea area; @@ -577,17 +504,13 @@ public class Area extends SubCommand { area = this.plotAreaManager.getPlotAreaByString(args[1]); break; default: - player.sendMessage( - TranslatableCaption.of("commandconfig.command_syntax_extended"), - Template.of("value1", getCommandString()), - Template.of("value2", " info [area]") - ); + player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax_extended"), Template.of("value1", getCommandString()), + Template.of("value2", " info [area]")); return false; } if (area == null) { if (args.length == 2) { - player.sendMessage(TranslatableCaption.of("errors.not_valid_plot_world"), - Template.of("value", args[1])); + player.sendMessage(TranslatableCaption.of("errors.not_valid_plot_world"), Template.of("value", args[1])); } else { player.sendMessage(TranslatableCaption.of("errors.not_in_plot_world")); } @@ -616,11 +539,11 @@ public class Area extends SubCommand { Template typeTemplate = Template.of("type", area.getType().name()); Template terrainTemplate = Template.of("terrain", area.getTerrain().name()); Template usageTemplate = Template.of("usage", String.format("%.2f", percent)); - Template claimedTemplate = Template.of("name", String.valueOf(claimed)); - Template clustersTemplate = Template.of("name", String.valueOf(clusters)); - Template regionTemplate = Template.of("name", region); - Template generatorTemplate = Template.of("name", generator); - Template footerTemplate = Template.of("name", TranslatableCaption.of("info.plot_info_footer").getComponent(player)); + Template claimedTemplate = Template.of("claimed", String.valueOf(claimed)); + Template clustersTemplate = Template.of("clusters", String.valueOf(clusters)); + Template regionTemplate = Template.of("region", region); + Template generatorTemplate = Template.of("generator", generator); + Template footerTemplate = Template.of("footer", TranslatableCaption.of("info.plot_info_footer").getComponent(player)); player.sendMessage(TranslatableCaption.of("info.area_info_format"), headerTemplate, nameTemplate, typeTemplate, terrainTemplate, usageTemplate, claimedTemplate, clustersTemplate, regionTemplate, generatorTemplate, footerTemplate); return true; @@ -628,8 +551,7 @@ public class Area extends SubCommand { case "l": case "list": if (!Permissions.hasPermission(player, "plots.area.list")) { - player.sendMessage(TranslatableCaption.of("permission.no_permission"), - Template.of("node", "plots.area.list")); + player.sendMessage(TranslatableCaption.of("permission.no_permission"), Template.of("node", "plots.area.list")); return false; } int page; @@ -643,86 +565,71 @@ public class Area extends SubCommand { break; } default: - player.sendMessage( - TranslatableCaption.of("commandconfig.command_syntax_extended"), - Template.of("value1", getCommandString()), - Template.of("value2", " list [#]") - ); + player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax_extended"), Template.of("value1", getCommandString()), + Template.of("value2", " list [#]")); return false; } - final List areas = - new ArrayList<>(Arrays.asList(this.plotAreaManager.getAllPlotAreas())); - paginate(player, areas, 8, page, - new RunnableVal3() { - @Override public void run(Integer i, PlotArea area, CaptionHolder caption) { - String name; - double percent; - int claimed = area.getPlotCount(); - int clusters = area.getClusters().size(); - String region; - String generator = String.valueOf(area.getGenerator()); - if (area.getType() == PlotAreaType.PARTIAL) { - PlotId min = area.getMin(); - PlotId max = area.getMax(); - name = area.getWorldName() + ';' + area.getId() + ';' + min + ';' - + max; - int size = - (max.getX() - min.getX() + 1) * (max.getY() - min.getY() + 1); - percent = claimed == 0 ? 0 : size / (double) claimed; - region = area.getRegion().toString(); - } else { - name = area.getWorldName(); - percent = claimed == 0 ? 0 : Short.MAX_VALUE * Short.MAX_VALUE / (double) claimed; - region = "N/A"; - } - Template claimedTemplate = Template.of("claimed", String.valueOf(claimed)); - Template usageTemplate = Template.of("usage", String.format("%.2f", percent) + "%"); - Template clustersTemplate = Template.of("clusters", String.valueOf(clusters)); - Template regionTemplate = Template.of("region", region); - Template generatorTemplate = Template.of("generator", generator); - String tooltip = MINI_MESSAGE.serialize(MINI_MESSAGE - .parse(TranslatableCaption.of("info.area_list_tooltip").getComponent(player), claimedTemplate, usageTemplate, - clustersTemplate, regionTemplate, generatorTemplate)); - Template tooltipTemplate = Template.of("hover_info", tooltip); - Template visitcmdTemplate = Template.of("command_tp", "/plot area tp " + area.toString()); - Template numberTemplate = Template.of("number", String.valueOf(i)); - Template nameTemplate = Template.of("area_name", name); - Template typeTemplate = Template.of("area_type", area.getType().name()); - Template terrainTemplate = Template.of("area_terrain", area.getTerrain().name()); - Caption item = TranslatableCaption.of("info.area_list_item"); - caption.set(StaticCaption.of(MINI_MESSAGE.serialize(MINI_MESSAGE - .parse(item.getComponent(player), tooltipTemplate, visitcmdTemplate, numberTemplate, nameTemplate, typeTemplate, - terrainTemplate)))); + final List areas = new ArrayList<>(Arrays.asList(this.plotAreaManager.getAllPlotAreas())); + paginate(player, areas, 8, page, new RunnableVal3() { + @Override public void run(Integer i, PlotArea area, CaptionHolder caption) { + String name; + double percent; + int claimed = area.getPlotCount(); + int clusters = area.getClusters().size(); + String region; + String generator = String.valueOf(area.getGenerator()); + if (area.getType() == PlotAreaType.PARTIAL) { + PlotId min = area.getMin(); + PlotId max = area.getMax(); + name = area.getWorldName() + ';' + area.getId() + ';' + min + ';' + max; + int size = (max.getX() - min.getX() + 1) * (max.getY() - min.getY() + 1); + percent = claimed == 0 ? 0 : claimed / (double) size; + region = area.getRegion().toString(); + } else { + name = area.getWorldName(); + percent = claimed == 0 ? 0 : (double) claimed / Short.MAX_VALUE * Short.MAX_VALUE; + region = "N/A"; } - }, "/plot area list", TranslatableCaption.of("list.area_list_header_paged")); + Template claimedTemplate = Template.of("claimed", String.valueOf(claimed)); + Template usageTemplate = Template.of("usage", String.format("%.2f", percent) + "%"); + Template clustersTemplate = Template.of("clusters", String.valueOf(clusters)); + Template regionTemplate = Template.of("region", region); + Template generatorTemplate = Template.of("generator", generator); + String tooltip = MINI_MESSAGE.serialize(MINI_MESSAGE + .parse(TranslatableCaption.of("info.area_list_tooltip").getComponent(player), claimedTemplate, usageTemplate, + clustersTemplate, regionTemplate, generatorTemplate)); + Template tooltipTemplate = Template.of("hover_info", tooltip); + Template visitcmdTemplate = Template.of("command_tp", "/plot area tp " + area.toString()); + Template infocmdTemplate = Template.of("command_info", "/plot area info " + area.toString()); + Template numberTemplate = Template.of("number", String.valueOf(i)); + Template nameTemplate = Template.of("area_name", name); + Template typeTemplate = Template.of("area_type", area.getType().name()); + Template terrainTemplate = Template.of("area_terrain", area.getTerrain().name()); + caption.set(TranslatableCaption.of("info.area_list_item")); + caption.setTemplates(tooltipTemplate, visitcmdTemplate, numberTemplate, nameTemplate, typeTemplate, terrainTemplate, + infocmdTemplate); + } + }, "/plot area list", TranslatableCaption.of("list.area_list_header_paged")); return true; case "regen": case "clear": case "reset": case "regenerate": { if (!Permissions.hasPermission(player, "plots.area.regen")) { - player.sendMessage(TranslatableCaption.of("permission.no_permission"), - Template.of("node", "plots.area.regen")); + player.sendMessage(TranslatableCaption.of("permission.no_permission"), Template.of("node", "plots.area.regen")); return false; } final PlotArea area = player.getApplicablePlotArea(); if (area == null) { - player.sendMessage( - TranslatableCaption.of("errors.not_in_plot_world") - ); + player.sendMessage(TranslatableCaption.of("errors.not_in_plot_world")); return false; } if (area.getType() != PlotAreaType.PARTIAL) { - player.sendMessage( - TranslatableCaption.of("single.delete_world_region"), - Template.of("world", area.getWorldName()) - ); + player.sendMessage(TranslatableCaption.of("single.delete_world_region"), Template.of("world", area.getWorldName())); return false; } - QueueCoordinator queue = - blockQueue.getNewQueue(worldUtil.getWeWorld(area.getWorldName())); - queue.setChunkConsumer(chunk -> AugmentedUtils - .generate(null, area.getWorldName(), chunk.getX(), chunk.getZ(), null)); + QueueCoordinator queue = blockQueue.getNewQueue(worldUtil.getWeWorld(area.getWorldName())); + queue.setChunkConsumer(chunk -> AugmentedUtils.generate(null, area.getWorldName(), chunk.getX(), chunk.getZ(), null)); queue.addReadChunks(area.getRegion().getChunks()); queue.setCompleteTask(() -> player.sendMessage(TranslatableCaption.of("single.regeneration_complete"))); queue.enqueue(); @@ -734,21 +641,16 @@ public class Area extends SubCommand { case "visit": case "tp": if (!Permissions.hasPermission(player, "plots.area.tp")) { - player.sendMessage(TranslatableCaption.of("permission.no_permission"), - Template.of("node", "plots.area.tp")); + player.sendMessage(TranslatableCaption.of("permission.no_permission"), Template.of("node", "plots.area.tp")); return false; } if (args.length != 2) { - player.sendMessage( - TranslatableCaption.of("commandconfig.command_syntax"), - Template.of("value", "/plot visit [area]") - ); + player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax"), Template.of("value", "/plot visit [area]")); return false; } PlotArea area = this.plotAreaManager.getPlotAreaByString(args[1]); if (area == null) { - player.sendMessage(TranslatableCaption.of("errors.not_valid_plot_world"), - Template.of("value", args[1])); + player.sendMessage(TranslatableCaption.of("errors.not_valid_plot_world"), Template.of("value", args[1])); return false; } Location center; @@ -757,14 +659,11 @@ public class Area extends SubCommand { player.teleport(center, TeleportCause.COMMAND); } else { CuboidRegion region = area.getRegion(); - center = Location.at(area.getWorldName(), region.getMinimumPoint().getX() - + (region.getMaximumPoint().getX() - region.getMinimumPoint().getX()) / 2, - 0, region.getMinimumPoint().getZ() - + (region.getMaximumPoint().getZ() - region.getMinimumPoint().getZ()) - / 2); - this.worldUtil - .getHighestBlock(area.getWorldName(), center.getX(), center.getZ(), - y -> player.teleport(center.withY(1 + y), TeleportCause.COMMAND)); + center = Location.at(area.getWorldName(), + region.getMinimumPoint().getX() + (region.getMaximumPoint().getX() - region.getMinimumPoint().getX()) / 2, 0, + region.getMinimumPoint().getZ() + (region.getMaximumPoint().getZ() - region.getMinimumPoint().getZ()) / 2); + this.worldUtil.getHighestBlock(area.getWorldName(), center.getX(), center.getZ(), + y -> player.teleport(center.withY(1 + y), TeleportCause.COMMAND)); } return true; case "delete": diff --git a/Core/src/main/java/com/plotsquared/core/command/Command.java b/Core/src/main/java/com/plotsquared/core/command/Command.java index 006b93433..ef325eec0 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Command.java +++ b/Core/src/main/java/com/plotsquared/core/command/Command.java @@ -248,7 +248,7 @@ public abstract class Command { if (page < 0) { page = 0; } - int totalPages = (int) Math.ceil((double) c.size() / size); + int totalPages = (int) Math.floor((double) c.size() / size); if (page > totalPages) { page = totalPages; } @@ -266,9 +266,9 @@ public abstract class Command { int i = page * size; for (T obj : subList) { i++; - CaptionHolder msg = new CaptionHolder(); + final CaptionHolder msg = new CaptionHolder(); add.run(i, obj, msg); - player.sendMessage(msg.get()); + player.sendMessage(msg.get(), msg.getTemplates()); } // Send the footer if (page < totalPages && page > 0) { // Back | Next diff --git a/Core/src/main/java/com/plotsquared/core/command/ListCmd.java b/Core/src/main/java/com/plotsquared/core/command/ListCmd.java index a396b010e..5aac7a27a 100644 --- a/Core/src/main/java/com/plotsquared/core/command/ListCmd.java +++ b/Core/src/main/java/com/plotsquared/core/command/ListCmd.java @@ -27,13 +27,12 @@ package com.plotsquared.core.command; import com.google.inject.Inject; import com.plotsquared.core.PlotSquared; -import com.plotsquared.core.permissions.Permission; import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.configuration.caption.Caption; import com.plotsquared.core.configuration.caption.CaptionHolder; -import com.plotsquared.core.configuration.caption.StaticCaption; import com.plotsquared.core.configuration.caption.Templates; import com.plotsquared.core.configuration.caption.TranslatableCaption; +import com.plotsquared.core.permissions.Permission; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.PlotArea; @@ -52,10 +51,11 @@ import com.plotsquared.core.util.query.PlotQuery; import com.plotsquared.core.util.query.SortingStrategy; import com.plotsquared.core.util.task.RunnableVal3; import com.plotsquared.core.uuid.UUIDMapping; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.minimessage.Template; import javax.annotation.Nonnull; -import javax.annotation.Nullable; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -80,16 +80,14 @@ public class ListCmd extends SubCommand { private final PlotAreaManager plotAreaManager; private final EconHandler econHandler; - @Inject public ListCmd(@Nonnull final PlotAreaManager plotAreaManager, - @Nonnull final EconHandler econHandler) { + @Inject public ListCmd(@Nonnull final PlotAreaManager plotAreaManager, @Nonnull final EconHandler econHandler) { this.plotAreaManager = plotAreaManager; this.econHandler = econHandler; } private String[] getArgumentList(PlotPlayer player) { List args = new ArrayList<>(); - if (this.econHandler != null && Permissions - .hasPermission(player, Permission.PERMISSION_LIST_FOR_SALE)) { + if (this.econHandler != null && Permissions.hasPermission(player, Permission.PERMISSION_LIST_FOR_SALE)) { args.add("forsale"); } if (Permissions.hasPermission(player, Permission.PERMISSION_LIST_MINE)) { @@ -130,7 +128,7 @@ public class ListCmd extends SubCommand { public void noArgs(PlotPlayer player) { player.sendMessage(TranslatableCaption.of("commandconfig.subcommand_set_options_header"), - Templates.of("values", Arrays.toString(getArgumentList(player)))); + Templates.of("values", Arrays.toString(getArgumentList(player)))); } @Override public boolean onCommand(PlotPlayer player, String[] args) { @@ -162,11 +160,8 @@ public class ListCmd extends SubCommand { final Consumer plotConsumer = query -> { if (query == null) { - player.sendMessage( - TranslatableCaption.of("commandconfig.did_you_mean"), - Template.of("value", new StringComparison<>(args[0], new String[] {"mine", "shared", "world", "all"}) - .getBestMatch()) - ); + player.sendMessage(TranslatableCaption.of("commandconfig.did_you_mean"), + Template.of("value", new StringComparison<>(args[0], new String[] {"mine", "shared", "world", "all"}).getBestMatch())); return; } @@ -190,8 +185,7 @@ public class ListCmd extends SubCommand { switch (arg) { case "mine": if (!Permissions.hasPermission(player, Permission.PERMISSION_LIST_MINE)) { - player.sendMessage(TranslatableCaption.of("permission.no_permission"), - Templates.of("node", "plots.list.mine")); + player.sendMessage(TranslatableCaption.of("permission.no_permission"), Templates.of("node", "plots.list.mine")); return false; } sort[0] = false; @@ -199,29 +193,25 @@ public class ListCmd extends SubCommand { break; case "shared": if (!Permissions.hasPermission(player, Permission.PERMISSION_LIST_SHARED)) { - player.sendMessage(TranslatableCaption.of("permission.no_permission"), - Templates.of("node", "plots.list.shared")); + player.sendMessage(TranslatableCaption.of("permission.no_permission"), Templates.of("node", "plots.list.shared")); return false; } plotConsumer.accept(PlotQuery.newQuery().withMember(player.getUUID()).thatPasses(plot -> !plot.isOwnerAbs(player.getUUID()))); break; case "world": if (!Permissions.hasPermission(player, Permission.PERMISSION_LIST_WORLD)) { - player.sendMessage(TranslatableCaption.of("permission.no_permission"), - Templates.of("node", "plots.list.world")); + player.sendMessage(TranslatableCaption.of("permission.no_permission"), Templates.of("node", "plots.list.world")); return false; } if (!Permissions.hasPermission(player, "plots.list.world." + world)) { - player.sendMessage(TranslatableCaption.of("permission.no_permission"), - Templates.of("node", "plots.list.world" + world)); + player.sendMessage(TranslatableCaption.of("permission.no_permission"), Templates.of("node", "plots.list.world" + world)); return false; } plotConsumer.accept(PlotQuery.newQuery().inWorld(world)); break; case "expired": if (!Permissions.hasPermission(player, Permission.PERMISSION_LIST_EXPIRED)) { - player.sendMessage(TranslatableCaption.of("permission.no_permission"), - Templates.of("node", "plots.list.expired")); + player.sendMessage(TranslatableCaption.of("permission.no_permission"), Templates.of("node", "plots.list.expired")); return false; } if (ExpireManager.IMP == null) { @@ -232,13 +222,11 @@ public class ListCmd extends SubCommand { break; case "area": if (!Permissions.hasPermission(player, Permission.PERMISSION_LIST_AREA)) { - player.sendMessage(TranslatableCaption.of("permission.no_permission"), - Templates.of("node", "plots.list.area")); + player.sendMessage(TranslatableCaption.of("permission.no_permission"), Templates.of("node", "plots.list.area")); return false; } if (!Permissions.hasPermission(player, "plots.list.world." + world)) { - player.sendMessage(TranslatableCaption.of("permission.no_permission"), - Templates.of("node", "plots.list.world" + world)); + player.sendMessage(TranslatableCaption.of("permission.no_permission"), Templates.of("node", "plots.list.world" + world)); return false; } if (area == null) { @@ -249,16 +237,14 @@ public class ListCmd extends SubCommand { break; case "all": if (!Permissions.hasPermission(player, Permission.PERMISSION_LIST_ALL)) { - player.sendMessage(TranslatableCaption.of("permission.no_permission"), - Templates.of("node", "plots.list.all")); + player.sendMessage(TranslatableCaption.of("permission.no_permission"), Templates.of("node", "plots.list.all")); return false; } plotConsumer.accept(PlotQuery.newQuery().allPlots()); break; case "done": if (!Permissions.hasPermission(player, Permission.PERMISSION_LIST_DONE)) { - player.sendMessage(TranslatableCaption.of("permission.no_permission"), - Templates.of("node", "plots.list.done")); + player.sendMessage(TranslatableCaption.of("permission.no_permission"), Templates.of("node", "plots.list.done")); return false; } sort[0] = false; @@ -266,8 +252,7 @@ public class ListCmd extends SubCommand { break; case "top": if (!Permissions.hasPermission(player, Permission.PERMISSION_LIST_TOP)) { - player.sendMessage(TranslatableCaption.of("permission.no_permission"), - Templates.of("node", "plots.list.top")); + player.sendMessage(TranslatableCaption.of("permission.no_permission"), Templates.of("node", "plots.list.top")); return false; } sort[0] = false; @@ -275,8 +260,7 @@ public class ListCmd extends SubCommand { break; case "forsale": if (!Permissions.hasPermission(player, Permission.PERMISSION_LIST_FOR_SALE)) { - player.sendMessage(TranslatableCaption.of("permission.no_permission"), - Templates.of("node", "plots.list.forsale")); + player.sendMessage(TranslatableCaption.of("permission.no_permission"), Templates.of("node", "plots.list.forsale")); return false; } if (this.econHandler.isSupported()) { @@ -286,21 +270,19 @@ public class ListCmd extends SubCommand { break; case "unowned": if (!Permissions.hasPermission(player, Permission.PERMISSION_LIST_UNOWNED)) { - player.sendMessage(TranslatableCaption.of("permission.no_permission"), - Templates.of("node", "plots.list.unowned")); + player.sendMessage(TranslatableCaption.of("permission.no_permission"), Templates.of("node", "plots.list.unowned")); return false; } plotConsumer.accept(PlotQuery.newQuery().allPlots().thatPasses(plot -> plot.getOwner() == null)); break; case "fuzzy": if (!Permissions.hasPermission(player, Permission.PERMISSION_LIST_FUZZY)) { - player.sendMessage(TranslatableCaption.of("permission.no_permission"), - Templates.of("node", "plots.list.fuzzy")); + player.sendMessage(TranslatableCaption.of("permission.no_permission"), Templates.of("node", "plots.list.fuzzy")); return false; } if (args.length < (page == -1 ? 2 : 3)) { player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax"), - Templates.of("value", "/plot list fuzzy [#]")); + Templates.of("value", "/plot list fuzzy [#]")); return false; } String term; @@ -315,45 +297,39 @@ public class ListCmd extends SubCommand { default: if (this.plotAreaManager.hasPlotArea(args[0])) { if (!Permissions.hasPermission(player, Permission.PERMISSION_LIST_WORLD)) { - player.sendMessage(TranslatableCaption.of("permission.no_permission"), - Templates.of("node", "plots.list.world")); + player.sendMessage(TranslatableCaption.of("permission.no_permission"), Templates.of("node", "plots.list.world")); return false; } if (!Permissions.hasPermission(player, "plots.list.world." + args[0])) { - player.sendMessage(TranslatableCaption.of("permission.no_permission"), - Templates.of("node", "plots.list.world." + args[0])); + player.sendMessage(TranslatableCaption.of("permission.no_permission"), Templates.of("node", "plots.list.world." + args[0])); return false; } plotConsumer.accept(PlotQuery.newQuery().inWorld(args[0])); break; } - PlotSquared.get().getImpromptuUUIDPipeline() - .getSingle(args[0], (uuid, throwable) -> { - if (throwable instanceof TimeoutException) { - player.sendMessage(TranslatableCaption.of("players.fetching_players_timeout")); - } else if (throwable != null) { - if (uuid == null) { - try { - uuid = UUID.fromString(args[0]); - } catch (Exception ignored) { - } - } - } + PlotSquared.get().getImpromptuUUIDPipeline().getSingle(args[0], (uuid, throwable) -> { + if (throwable instanceof TimeoutException) { + player.sendMessage(TranslatableCaption.of("players.fetching_players_timeout")); + } else if (throwable != null) { if (uuid == null) { - player.sendMessage(TranslatableCaption.of("errors.invalid_player"), - Templates.of("value", args[0])); - } else { - if (!Permissions - .hasPermission(player, Permission.PERMISSION_LIST_PLAYER)) { - player.sendMessage(TranslatableCaption.of("permission.no_permission"), - Templates.of("node", "plots.list.player")); - } else { - sort[0] = false; - plotConsumer.accept(PlotQuery.newQuery().ownedBy(uuid).withSortingStrategy(SortingStrategy.SORT_BY_TEMP)); + try { + uuid = UUID.fromString(args[0]); + } catch (Exception ignored) { } } - }); + } + if (uuid == null) { + player.sendMessage(TranslatableCaption.of("errors.invalid_player"), Templates.of("value", args[0])); + } else { + if (!Permissions.hasPermission(player, Permission.PERMISSION_LIST_PLAYER)) { + player.sendMessage(TranslatableCaption.of("permission.no_permission"), Templates.of("node", "plots.list.player")); + } else { + sort[0] = false; + plotConsumer.accept(PlotQuery.newQuery().ownedBy(uuid).withSortingStrategy(SortingStrategy.SORT_BY_TEMP)); + } + } + }); } return true; @@ -376,32 +352,32 @@ public class ListCmd extends SubCommand { } else { color = TranslatableCaption.of("info.plot_list_default"); } - String trusted = MINI_MESSAGE.serialize(MINI_MESSAGE.parse(TranslatableCaption.of("info.plot_info_trusted").getComponent(player), - Template.of("trusted", PlayerManager.getPlayerList(plot.getTrusted())))); - String members = MINI_MESSAGE.serialize(MINI_MESSAGE.parse(TranslatableCaption.of("info.plot_info_members").getComponent(player), - Template.of("members", PlayerManager.getPlayerList(plot.getMembers())))); + Component trusted = MINI_MESSAGE.parse(TranslatableCaption.of("info.plot_info_trusted").getComponent(player), + Template.of("trusted", PlayerManager.getPlayerList(plot.getTrusted()))); + Component members = MINI_MESSAGE.parse(TranslatableCaption.of("info.plot_info_members").getComponent(player), + Template.of("members", PlayerManager.getPlayerList(plot.getMembers()))); Template command_tp = Template.of("command_tp", "/plot visit " + plot.getArea() + ";" + plot.getId()); Template command_info = Template.of("command_info", "/plot info " + plot.getArea() + ";" + plot.getId()); - Template hover_info = Template.of("hover_info", trusted + "\n" + members); + Template hover_info = + Template.of("hover_info", MINI_MESSAGE.serialize(Component.text().append(trusted).append(Component.newline()).append(members).asComponent())); Template numberTemplate = Template.of("number", String.valueOf(i)); - Template plotTemplate = - Template.of("plot", MINI_MESSAGE.serialize(MINI_MESSAGE.parse(color.getComponent(player), Template.of("plot", plot.toString())))); + Template plotTemplate = Template.of("plot", MINI_MESSAGE.parse(color.getComponent(player), Template.of("plot", plot.toString()))); + String prefix = ""; String online = TranslatableCaption.of("info.plot_list_player_online").getComponent(player); String offline = TranslatableCaption.of("info.plot_list_player_offline").getComponent(player); - StringBuilder builder = new StringBuilder(); - + TextComponent.Builder builder = Component.text(); try { final List names = PlotSquared.get().getImpromptuUUIDPipeline().getNames(plot.getOwners()) .get(Settings.UUID.BLOCKING_TIMEOUT, TimeUnit.MILLISECONDS); for (final UUIDMapping uuidMapping : names) { PlotPlayer pp = PlotSquared.platform().getPlayerManager().getPlayerIfExists(uuidMapping.getUuid()); Template prefixTemplate = Template.of("prefix", prefix); - Template playerTemplate = Template.of("prefix", uuidMapping.getUsername()); + Template playerTemplate = Template.of("player", uuidMapping.getUsername()); if (pp != null) { - builder.append(MINI_MESSAGE.serialize(MINI_MESSAGE.parse(online, prefixTemplate, playerTemplate))); + builder.append(MINI_MESSAGE.parse(online, prefixTemplate, playerTemplate)); } else { - builder.append(MINI_MESSAGE.serialize(MINI_MESSAGE.parse(offline, prefixTemplate, playerTemplate))); + builder.append(MINI_MESSAGE.parse(offline, prefixTemplate, playerTemplate)); } prefix = ", "; } @@ -419,18 +395,16 @@ public class ListCmd extends SubCommand { } catch (TimeoutException e) { player.sendMessage(TranslatableCaption.of("players.fetching_players_timeout")); } - Template players = Template.of("players", builder.toString()); - caption.set(StaticCaption.of(MINI_MESSAGE.serialize(MINI_MESSAGE - .parse(TranslatableCaption.of("info.plot_list_item").getComponent(player), command_tp, command_info, hover_info, numberTemplate, - plotTemplate, players)))); + Template players = Template.of("players", builder.asComponent()); + caption.set(TranslatableCaption.of("info.plot_list_item")); + caption.setTemplates(command_tp, command_info, hover_info, numberTemplate, plotTemplate, players); } }, "/plot list " + args[0], TranslatableCaption.of("list.plot_list_header_paged")); } @Override public Collection tab(PlotPlayer player, String[] args, boolean space) { final List completions = new LinkedList<>(); - if (this.econHandler.isSupported() && Permissions - .hasPermission(player, Permission.PERMISSION_LIST_FOR_SALE)) { + if (this.econHandler.isSupported() && Permissions.hasPermission(player, Permission.PERMISSION_LIST_FOR_SALE)) { completions.add("forsale"); } if (Permissions.hasPermission(player, Permission.PERMISSION_LIST_MINE)) { diff --git a/Core/src/main/java/com/plotsquared/core/configuration/caption/CaptionHolder.java b/Core/src/main/java/com/plotsquared/core/configuration/caption/CaptionHolder.java index 347c8e0fb..f2161e13b 100644 --- a/Core/src/main/java/com/plotsquared/core/configuration/caption/CaptionHolder.java +++ b/Core/src/main/java/com/plotsquared/core/configuration/caption/CaptionHolder.java @@ -25,9 +25,12 @@ */ package com.plotsquared.core.configuration.caption; +import net.kyori.adventure.text.minimessage.Template; + public class CaptionHolder { private Caption caption = StaticCaption.of(""); + private Template[] templates = new Template[0]; public void set(Caption caption) { this.caption = caption; @@ -37,4 +40,12 @@ public class CaptionHolder { return this.caption; } + public Template[] getTemplates() { + return this.templates; + } + + public void setTemplates(Template... templates) { + this.templates = templates; + } + } diff --git a/Core/src/main/java/com/plotsquared/core/plot/Plot.java b/Core/src/main/java/com/plotsquared/core/plot/Plot.java index c2689461e..0400c1e8a 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/Plot.java +++ b/Core/src/main/java/com/plotsquared/core/plot/Plot.java @@ -76,6 +76,7 @@ import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.world.biome.BiomeType; import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.minimessage.Template; import org.slf4j.Logger; @@ -2663,9 +2664,9 @@ public class Plot { String alias = !this.getAlias().isEmpty() ? this.getAlias() : TranslatableCaption.of("info.none").getComponent(player); Location bot = this.getCorners()[0]; PlotSquared.platform().getWorldUtil().getBiome(Objects.requireNonNull(this.getWorldName()), bot.getX(), bot.getZ(), biome -> { - String trusted = PlayerManager.getPlayerList(this.getTrusted()); - String members = PlayerManager.getPlayerList(this.getMembers()); - String denied = PlayerManager.getPlayerList(this.getDenied()); + Component trusted = PlayerManager.getPlayerList(this.getTrusted()); + Component members = PlayerManager.getPlayerList(this.getMembers()); + Component denied = PlayerManager.getPlayerList(this.getDenied()); String seen; if (Settings.Enabled_Components.PLOT_EXPIRY && ExpireManager.IMP != null) { if (this.isOnline()) { @@ -2712,7 +2713,7 @@ public class Plot { } } boolean build = this.isAdded(player.getUUID()); - String owner = this.getOwners().isEmpty() ? "unowned" : PlayerManager.getPlayerList(this.getOwners()); + Component owner = this.getOwners().isEmpty() ? Component.text("unowned") : PlayerManager.getPlayerList(this.getOwners()); Template headerTemplate = Template.of("header", TranslatableCaption.of("info.plot_info_header").getComponent(player)); Template footerTemplate = Template.of("footer", TranslatableCaption.of("info.plot_info_footer").getComponent(player)); Template areaTemplate; @@ -2748,13 +2749,14 @@ public class Plot { } if (full && Settings.Ratings.CATEGORIES != null && Settings.Ratings.CATEGORIES.size() > 1) { double[] ratings = this.getAverageRatings(); - String rating = ""; + StringBuilder rating = new StringBuilder(); String prefix = ""; for (int i = 0; i < ratings.length; i++) { - rating += prefix + Settings.Ratings.CATEGORIES.get(i) + '=' + String.format("%.1f", ratings[i]); + rating.append(prefix).append(Settings.Ratings.CATEGORIES.get(i)).append('=') + .append(String.format("%.1f", ratings[i])); prefix = ","; } - ratingTemplate = Template.of("rating", rating); + ratingTemplate = Template.of("rating", rating.toString()); } else { ratingTemplate = Template.of("rating", String.format("%.1f", this.getAverageRating()) + '/' + max); } diff --git a/Core/src/main/java/com/plotsquared/core/util/PlayerManager.java b/Core/src/main/java/com/plotsquared/core/util/PlayerManager.java index b3a265f15..bc8375cf4 100644 --- a/Core/src/main/java/com/plotsquared/core/util/PlayerManager.java +++ b/Core/src/main/java/com/plotsquared/core/util/PlayerManager.java @@ -27,6 +27,7 @@ package com.plotsquared.core.util; import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Settings; +import com.plotsquared.core.configuration.caption.Caption; import com.plotsquared.core.configuration.caption.TranslatableCaption; import com.plotsquared.core.database.DBFunc; import com.plotsquared.core.player.ConsolePlayer; @@ -34,6 +35,7 @@ import com.plotsquared.core.player.OfflinePlotPlayer; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.uuid.UUIDMapping; import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.minimessage.Template; @@ -110,9 +112,9 @@ public abstract class PlayerManager

, T> { * - Uses the format {@link TranslatableCaption#of(String)} of "info.plot_user_list" for the returned string * * @param uuids UUIDs - * @return Name list + * @return Component of name list */ - @Nonnull public static String getPlayerList(@Nonnull final Collection uuids) { + @Nonnull public static Component getPlayerList(@Nonnull final Collection uuids) { if (uuids.size() < 1) { TranslatableCaption.of("info.none"); } @@ -141,7 +143,7 @@ public abstract class PlayerManager

, T> { } String c = TranslatableCaption.of("info.plot_user_list").getComponent(ConsolePlayer.getConsole()); - Component list = MINI_MESSAGE.deserialize(""); + TextComponent.Builder list = Component.text(); for (int x = 0; x < users.size(); x++) { if (x + 1 == uuids.size()) { list.append(MINI_MESSAGE.parse(c, Template.of("user", users.get(x)))); @@ -149,7 +151,7 @@ public abstract class PlayerManager

, T> { list.append(MINI_MESSAGE.parse(c + ", ", Template.of("user", users.get(x)))); } } - return list.toString(); + return list.asComponent(); } /** diff --git a/Core/src/main/resources/lang/messages_en.json b/Core/src/main/resources/lang/messages_en.json index 19d38d09f..7ea0fa700 100644 --- a/Core/src/main/resources/lang/messages_en.json +++ b/Core/src/main/resources/lang/messages_en.json @@ -2,12 +2,12 @@ "confirm.expired_confirm": "Confirmation has expired, please run the command again!", "confirm.failed_confirm": "You have no pending actions to confirm!", "confirm.requires_confirm": "Are you sure you wish to execute: ?\nThis cannot be undone! If you are sure: ", - + "move.move_success": "Successfully moved plot.", "move.move_merged": "Merged plots may not be moved. Please unmerge the plot before performing the move.", "move.copy_success": "Successfully copied plot.", "move.requires_unowned": "The location specified is already occupied.", - + "debug.requires_unmerged": "The plot cannot be merged.", "debug.debug_header": " Debug Information\n", "debug.debug_section": ">> &l", @@ -18,11 +18,11 @@ "debug.player_in_debugmode": "Player(s) in debug mode: ", "debug.player_in_debugmode_list": "- \n", "debug.entity_categories": "Entity categories:", - + "set.set_attribute": "Successfully set to .", "area.set_pos2": "You will now set pos2: . Note: The chosen plot size may result in the created area not exactly matching your second position.", - + "web.generating_link": "Processing plot...", "web.generating_link_failed": "Failed to generate download link!", "web.generation_link_success": ">", @@ -31,9 +31,9 @@ "web.load_failed": "Failed to load schematic.", "web.load_list": "To load a schematic, use .", "web.save_success": "Successfully saved!", - + "compass.compass_target": "Successfully targeted plot with your compass.", - + "cluster.cluster_available_args": "The following sub commands are available: list, create, delete, resize, invite, kick, leave, members, info, tp, sethome", "cluster.cluster_list_heading": "There are clusters in this world.", "cluster.cluster_list_element": " - \n", @@ -60,21 +60,21 @@ "cluster.cluster_info": "Current cluster: \nName: \nOwner: \nSize: \nRights: ", "border.border": "You are outside the current map border.", - + "worldedit.worldedit_bypass": "To bypass your restrictions use ", "worldedit.worldedit_bypassed": "Currently bypassing WorldEdit restriction.", - + "gamemode.gamemode_was_bypassed": "You bypassed the gamemode () set for .", - + "height.height_limit": "This plot area has a height limit of .", - + "notification.notify_enter": " entered your plot ().", "notification.notify_leave": " left your plot ().", - + "swap.swap_overlap": "The proposed areas are not allowed to overlap.", "swap.swap_success": "Successfully swapped plots.", "swap.swap_merged": "Merged plots may not be swapped. Please unmerge the plots before performing the swap.", - + "comment.inbox_notification": " unread messages. Use .", "comment.not_valid_inbox_index": "No comment at index .", "comment.inbox_item": " - ", @@ -87,23 +87,23 @@ "comment.comment_removed_failure": "Failed to delete comment!", "comment.comment_added": "A comment has been left.", "comment.inbox_empty": "No comments.", - + "console.not_console": "For safety reasons, this command can only be executed by console.", "console.is_console": "This command can only be executed by a player.", - + "clipboard.paste_failed": "Failed to paste the selection. Reason: ", - + "toggle.toggle_enabled": "Enabled setting: ", "toggle.toggle_disabled": "Disabled setting: ", - + "blockedcmds.command_blocked": "That command is not allowed in this plot.", - + "done.done_already_done": "This plot is already marked as done.", "done.done_not_done": "This plot is not marked as done.", "done.done_insufficient_complexity": "This plot is too simple. Please add more detail before using this command.", "done.done_success": "Successfully marked this plot as done.", "done.done_removed": "You may now continue building in this plot.", - + "ratings.ratings_purged": "Purged ratings for this plot.", "ratings.rating_not_valid": "You need to specify a number between 1 and 10.", "ratings.rating_already_exists": "You have already rated plot .", @@ -113,10 +113,10 @@ "ratings.rating_not_your_own": "You cannot rate your own plot.", "ratings.rating_not_done": "You can only rate finished plots.", "ratings.rating_not_owned": "You cannot rate a plot that is not claimed by anyone.", - + "tutorial.rate_this": "Rate this plot!", "tutorial.comment_this": "Leave some feedback on this plot: .", - + "economy.econ_disabled": "Economy is not enabled.", "economy.cannot_afford_plot": "You cannot afford to buy this plot. It costs .", "economy.not_for_sale": "This plot is not for sale.", @@ -126,7 +126,7 @@ "economy.added_balance": " has been added to your balance.", "economy.removed_balance": " has been taken from your balance.", "economy.removed_granted_plot": "You used plot grant(s), you've got left.", - + "setup.setup_not_started": "No setup started.", "setup.setup_init": "Usage: /plot setup ", "setup.setup_step": "[Step ] - Expecting: Default: ", @@ -152,7 +152,7 @@ "setup.setup_area_max_plot_id": "What should be the maximum Plot ID?", "setup.setup_area_max_plot_id_error": "You must choose a valid maximum Plot ID!", "setup.setup_area_plot_id_greater_than_minimum": "The maximum Plot ID must be greater than the minimum!", - + "plotareatype.plot_area_type_normal": "Standard plot generation", "plotareatype.plot_area_type_augmented": "Plot generation with vanilla terrain", "plotareatype.plot_area_type_partial": "Vanilla with clusters of plots", @@ -171,30 +171,30 @@ "schematics.schematic_exportall_single_finished": "Finished export.", "schematic.schematic_exportall_world": "Invalid world.", "schematics.plot_to_schem": "Plot->Schematic: Found plots...", - + "error.task_in_process": "Task is already running.", - + "titles.title_entered_plot": "Plot: ;;", "titles.title_entered_plot_sub": "Owned by ", "titles.prefix_greeting": ">", "titles.prefix_farewell": ">", - + "core.prefix": "[P2] ", "core.enabled": " is now enabled.", "placeholder.hooked": "PlotSquared hooked into MVdWPlaceholderAPI", - + "reload.reloaded_configs": "Translations and world settings have been reloaded successfully.", "reload.reload_failed": "Failed to reload file configurations.", - + "desc.desc_set": "Plot description set.", "desc.desc_unset": "Plot description unset.", - + "alias.alias_set_to": "Plot alias set to .", "alias.alias_removed": "Plot alias removed.", "alias.alias_too_long": "The alias must have less than 50 characters in length.", "alias.alias_is_taken": "That alias is already taken.", - + "position.position_set": "Home position set to your current location.", "position.position_unset": "Home position reset to the default location.", @@ -206,7 +206,7 @@ "permission.cant_claim_more_clusters": "You can't claim more clusters.", "permission.cant_transfer_more_plots": "You can't send more plots to that user.", "permission.cant_claim_more_plots_num": "You can't claim more than plots at once.", - + "merge.merge_request_confirm": "Merge request from .", "merge.merge_not_valid": "This merge request is no longer valid.", "merge.merge_accepted": "The merge request has been accepted.", @@ -216,7 +216,7 @@ "merge.unlink_impossible": "You can only unlink a mega-plot.", "merge.unmerge_cancelled": "Unlink has been cancelled.", "merge.unlink_success": "Successfully unlinked plots.", - + "commandconfig.not_valid_subcommand": "That is not a valid subcommand.", "commandconfig.did_you_mean": "Did you mean: ", "commandconfig.subcommand_set_options_header": "Possible Values: ", @@ -224,7 +224,7 @@ "commandconfig.command_syntax": "Usage: ", "commandconfig.command_syntax_extended": "Usage: ", "commandconfig.flag_tutorial_usage": "Have an admin set the flag: ", - + "invalid.component_illegal_block": "You are not allowed to generate a component containing the block ", "invalid.not_valid_block": "That's not a valid block: ", "invalid.not_allowed_block": "That block is not allowed: ", @@ -287,7 +287,7 @@ "debugexec.script_list_item": "[] ", "debugexec.analyze_done": "Done. Use for more information. ", - "expiry.expired_options_clicky": " expired: >>\n - >>Delete this ()\n - >>Remind later ()\n - >>Keep this ()\n - >>Don't show me this ()", + "expiry.expired_options_clicky": " expired: >\">\n - >\">Delete this ()\n - >\">Remind later ()\n - >\">Keep this ()\n - >\">Don't show me this ()", "debugimportworlds.single_plot_area": "Must be a single plot area.", "debugimportworlds.world_container": "World container must be configured to be a separate directory to your base files.", @@ -333,37 +333,37 @@ "debugsavetest.starting": "Starting debugsavetest.", "debugsavetest.done": "Database sync finished.", - + "purge.purge_success": "Successfully purged plots.", - + "players.fetching_player": "PlotSquared is attempting to find the specified player from your argument(s). This may take a while.", "players.fetching_players_timeout": "The specified users did not exist in the cache and will be fetched in the background. Please wait a couple of minutes.", - + "trim.trim_in_progress": "A world trim task is already in progress!", "trim.trim_done": "Trim done.", "trim.trim_starting": "Collecting region data...", "blocklist.block_list_separator": ", ", - + "biome.need_biome": "You need to specify a valid biome.", "biome.biome_set_to": "Plot biome set to ", - + "teleport.teleported_to_plot": "You have been teleported.", "teleport.teleported_to_road": "You got teleported to the road.", "teleport.teleport_in_seconds": "Teleporting in seconds. Do not move...", "teleport.teleport_failed": "Teleportation cancelled due to movement or damage.", - + "setblock.set_block_action_finished": "The last setblock action is now finished.", - + "unsafe.debugallowunsafe_on": "Unsafe actions enabled.", "unsafe.debugallowunsafe_off": "Unsafe actions disabled.", - + "need.need_block": "You've got to specify a block.", - + "near.plot_near": "Players: ", "scripts.script_list": "--------- SCRIPTS ---------", - + "info.none": "None", "info.now": "Now", "info.never": "Never", @@ -374,16 +374,16 @@ "info.plot_info_unclaimed": "Plot is not yet claimed.", "info.plot_info_header": "--------- INFO ---------", "info.plot_info_hidden": "You cannot view the information about this plot.", - "info.plot_info_format": "

\nID: \nArea: \nAlias:\nOwner:\nBiome: \nCan Build: \nRating: \nSeen: \nTrusted:\nMembers:\nDenied:\nFlags:\nDescription: \n