diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java index 1b2224a27..64ee7e724 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java @@ -116,7 +116,7 @@ import java.util.stream.Stream; private static final Logger logger = LoggerFactory.getLogger("P2/" + BukkitUtil.class.getSimpleName()); public static final BukkitAudiences BUKKIT_AUDIENCES = BukkitAudiences.create(BukkitPlatform.getPlugin(BukkitPlatform.class)); - public static final LegacyComponentSerializer LEGACY_COMPONENT_SERIALIZER = LegacyComponentSerializer.legacy(); + public static final LegacyComponentSerializer LEGACY_COMPONENT_SERIALIZER = LegacyComponentSerializer.legacyAmpersand(); public static final MiniMessage MINI_MESSAGE = MiniMessage.builder().build(); private final Collection tileEntityTypes = new HashSet<>(); @@ -322,13 +322,11 @@ import java.util.stream.Stream; } @Override @SuppressWarnings("deprecation") - public void setSign(@Nonull final Location location, @Nonnull final Caption[] lines, + public void setSign(@Nonnull final Location location, @Nonnull final Caption[] lines, @Nonnull final Template ... replacements) { - ensureLoaded(location.getWorld(), location.getX(), location.getZ(), chunk -> { - final World world = getWorld(location.getWorld()); + ensureLoaded(location.getWorldName(), location.getX(), location.getZ(), chunk -> { + final World world = getWorld(location.getWorldName()); final Block block = world.getBlockAt(location.getX(), location.getY(), location.getZ()); - final World world = getWorld(worldName); - final Block block = world.getBlockAt(x, y, z); // block.setType(Material.AIR); final Material type = block.getType(); if (type != Material.LEGACY_SIGN && type != Material.LEGACY_WALL_SIGN) { diff --git a/Core/src/main/java/com/plotsquared/core/command/Info.java b/Core/src/main/java/com/plotsquared/core/command/Info.java index 3b921fd2c..5e4cf840b 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Info.java +++ b/Core/src/main/java/com/plotsquared/core/command/Info.java @@ -27,6 +27,7 @@ package com.plotsquared.core.command; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.Settings; +import com.plotsquared.core.configuration.caption.Caption; import com.plotsquared.core.configuration.caption.StaticCaption; import com.plotsquared.core.configuration.caption.TranslatableCaption; import com.plotsquared.core.database.DBFunc; @@ -98,7 +99,7 @@ public class Info extends SubCommand { for (final String argument : args) { if (argument.equalsIgnoreCase("-f")) { if (!player - .hasPermission(Captions.PERMISSION_AREA_INFO_FORCE.getTranslated())) { + .hasPermission(Captions.PERMISSION_AREA_INFO_FORCE.toString())) { player.sendMessage( TranslatableCaption.of("permission.no_permission"), Template.of("node", "plots.area.info.force") @@ -127,7 +128,7 @@ public class Info extends SubCommand { ); return true; } - String info = Captions.PLOT_INFO_FORMAT.getTranslated(); + Caption info = TranslatableCaption.of("info.plot_info_format"); boolean full; if (arg != null) { info = getCaption(arg); @@ -145,38 +146,36 @@ public class Info extends SubCommand { } else { full = false; } - plot.format(info, player, full).thenAcceptAsync(value -> - player.sendMessage(Captions.PLOT_INFO_HEADER.getTranslated() + '\n' + value + '\n' - + Captions.PLOT_INFO_FOOTER.getTranslated())); + plot.format(info, player, full).thenAcceptAsync(player::sendMessage); return true; } - private String getCaption(String string) { + private Caption getCaption(String string) { switch (string) { case "trusted": - return Captions.PLOT_INFO_TRUSTED.getTranslated(); + return TranslatableCaption.of("info.plot_info_trusted"); case "alias": - return Captions.PLOT_INFO_ALIAS.getTranslated(); + return TranslatableCaption.of("info.plot_info_alias"); case "biome": - return Captions.PLOT_INFO_BIOME.getTranslated(); + return TranslatableCaption.of("info.plot_info_biome"); case "denied": - return Captions.PLOT_INFO_DENIED.getTranslated(); + return TranslatableCaption.of("info.plot_info_denied"); case "flags": - return Captions.PLOT_INFO_FLAGS.getTranslated(); + return TranslatableCaption.of("info.plot_info_flags"); case "id": - return Captions.PLOT_INFO_ID.getTranslated(); + return TranslatableCaption.of("info.plot_info_id"); case "size": - return Captions.PLOT_INFO_SIZE.getTranslated(); + return TranslatableCaption.of("info.plot_info_size"); case "members": - return Captions.PLOT_INFO_MEMBERS.getTranslated(); + return TranslatableCaption.of("info.plot_info_members"); case "owner": - return Captions.PLOT_INFO_OWNER.getTranslated(); + return TranslatableCaption.of("info.plot_info_owner"); case "rating": - return Captions.PLOT_INFO_RATING.getTranslated(); + return TranslatableCaption.of("info.plot_info_rating"); case "likes": - return Captions.PLOT_INFO_LIKES.getTranslated(); + return TranslatableCaption.of("info.plot_info_likes"); case "seen": - return Captions.PLOT_INFO_SEEN.getTranslated(); + return TranslatableCaption.of("info.plot_info_seen"); default: return null; } 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 cfa4d5108..59a725b60 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/Plot.java +++ b/Core/src/main/java/com/plotsquared/core/plot/Plot.java @@ -31,10 +31,11 @@ import com.google.common.collect.Sets; import com.google.inject.Inject; import com.plotsquared.core.PlotSquared; import com.plotsquared.core.command.Like; -import com.plotsquared.core.configuration.caption.CaptionUtility; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.ConfigurationUtil; import com.plotsquared.core.configuration.Settings; +import com.plotsquared.core.configuration.caption.Caption; +import com.plotsquared.core.configuration.caption.CaptionUtility; import com.plotsquared.core.configuration.caption.StaticCaption; import com.plotsquared.core.configuration.caption.TranslatableCaption; import com.plotsquared.core.database.DBFunc; @@ -87,6 +88,8 @@ import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BlockTypes; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.minimessage.Template; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -140,6 +143,8 @@ public class Plot { private static final Logger logger = LoggerFactory.getLogger("P2/" + Plot.class.getSimpleName()); private static final DecimalFormat FLAG_DECIMAL_FORMAT = new DecimalFormat("0"); + private static final MiniMessage MINI_MESSAGE = MiniMessage.builder().build(); + static { FLAG_DECIMAL_FORMAT.setMaximumFractionDigits(340); } @@ -1189,16 +1194,12 @@ public class Plot { if (this.area.allowSigns()) { Location location = manager.getSignLoc(this); String id = this.id.toString(); - String[] lines = - new String[] {Captions.OWNER_SIGN_LINE_1.formatted().replaceAll("%id%", id), - Captions.OWNER_SIGN_LINE_2.formatted().replaceAll("%id%", id).replaceAll( - "%plr%", name), - Captions.OWNER_SIGN_LINE_3.formatted().replaceAll("%id%", id).replaceAll( - "%plr%", name), - Captions.OWNER_SIGN_LINE_4.formatted().replaceAll("%id%", id).replaceAll( - "%plr%", name)}; - this.worldUtil.setSign(this.getWorldName(), location.getX(), location.getY(), location.getZ(), - lines); + Caption[] lines = + new Caption[] {TranslatableCaption.of("signs.owner_sign_line_1"), + TranslatableCaption.of("signs.owner_sign_line_2"), + TranslatableCaption.of("signs.owner_sign_line_3"), + TranslatableCaption.of("signs.owner_sign_line_4")}; + this.worldUtil.setSign(location, lines, Template.of("id", id), Template.of("owner", name)); } } @@ -3005,11 +3006,12 @@ public class Plot { if (players.isEmpty()) { return; } - final String string = - Captions.PLOT_DEBUG.getTranslated().replace("%plot%", this.toString()).replace("%message%", message); + Caption caption = TranslatableCaption.of("debug.plot_debug"); + Template plotTemplate = Template.of("plot", this.toString()); + Template messageTemplate = Template.of("message", message); for (final PlotPlayer player : players) { if (isOwner(player.getUUID()) || Permissions.hasPermission(player, Captions.PERMISSION_ADMIN_DEBUG_OTHER)) { - player.sendMessage(StaticCaption.of(string)); + player.sendMessage(caption, plotTemplate, messageTemplate); } } } catch (final Exception ignored) {} @@ -3489,117 +3491,120 @@ public class Plot { return FlagContainer.castUnsafe(flagInstance).getValue(); } - public CompletableFuture format(final String iInfo, PlotPlayer player, final boolean full) { - final CompletableFuture future = new CompletableFuture<>(); + public CompletableFuture format(final Caption iInfo, PlotPlayer player, final boolean full) { + final CompletableFuture future = new CompletableFuture<>(); int num = this.getConnectedPlots().size(); - String alias = !this.getAlias().isEmpty() ? this.getAlias() : Captions.NONE.getTranslated(); + String alias = !this.getAlias().isEmpty() ? this.getAlias() : TranslatableCaption.of("info.none").getComponent(player); Location bot = this.getCorners()[0]; - PlotSquared.platform().getWorldUtil() - .getBiome(this.getWorldName(), bot.getX(), bot.getZ(), biome -> { - String info = iInfo; - String trusted = PlayerManager.getPlayerList(this.getTrusted()); - String members = PlayerManager.getPlayerList(this.getMembers()); - String denied = PlayerManager.getPlayerList(this.getDenied()); - String seen; - if (Settings.Enabled_Components.PLOT_EXPIRY && ExpireManager.IMP != null) { - if (this.isOnline()) { - seen = Captions.NOW.getTranslated(); + PlotSquared.platform().getWorldUtil().getBiome(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()); + String seen; + if (Settings.Enabled_Components.PLOT_EXPIRY && ExpireManager.IMP != null) { + if (this.isOnline()) { + seen = TranslatableCaption.of("info.now").getComponent(player); + } else { + int time = (int) (ExpireManager.IMP.getAge(this) / 1000); + if (time != 0) { + seen = TimeUtil.secToTime(time); } else { - int time = (int) (ExpireManager.IMP.getAge(this) / 1000); - if (time != 0) { - seen = TimeUtil.secToTime(time); - } else { - seen = Captions.UNKNOWN.getTranslated(); - } - } - } else { - seen = Captions.NEVER.getTranslated(); - } - - String description = this.getFlag(DescriptionFlag.class); - if (description.isEmpty()) { - description = Captions.PLOT_NO_DESCRIPTION.getTranslated(); - } - - StringBuilder flags = new StringBuilder(); - Collection> flagCollection = this.getApplicableFlags(true); - if (flagCollection.isEmpty()) { - flags.append(Captions.NONE.getTranslated()); - } else { - String prefix = " "; - for (final PlotFlag flag : flagCollection) { - Object value; - if (flag instanceof DoubleFlag && !Settings.General.SCIENTIFIC) { - value = FLAG_DECIMAL_FORMAT.format(flag.getValue()); - } else { - value = flag.toString(); - } - flags.append(prefix).append(CaptionUtility - .format(player, Captions.PLOT_FLAG_LIST.getTranslated(), flag.getName(), - CaptionUtility.formatRaw(player, value.toString(), ""))); - prefix = ", "; + seen = TranslatableCaption.of("info.known").getComponent(player); } } - boolean build = this.isAdded(player.getUUID()); - String owner = this.getOwners().isEmpty() ? "unowned" : PlayerManager.getPlayerList(this.getOwners()); - if (this.getArea() != null) { - info = info.replace("%area%", - this.getArea().getWorldName() + (this.getArea().getId() == null ? - "" : - "(" + this.getArea().getId() + ")")); - } else { - info = info.replace("%area%", Captions.NONE.getTranslated()); + } else { + seen = TranslatableCaption.of("info.never").getComponent(player); + } + + String description = this.getFlag(DescriptionFlag.class); + if (description.isEmpty()) { + description = TranslatableCaption.of("info.plot_no_description").getComponent(player); + } + + Component flags = null; + Collection> flagCollection = this.getApplicableFlags(true); + if (flagCollection.isEmpty()) { + flags = MINI_MESSAGE.parse(TranslatableCaption.of("info.none").getComponent(player)); + } else { + String prefix = " "; + for (final PlotFlag flag : flagCollection) { + Object value; + if (flag instanceof DoubleFlag && !Settings.General.SCIENTIFIC) { + value = FLAG_DECIMAL_FORMAT.format(flag.getValue()); + } else { + value = flag.toString(); + } + Component snip = MINI_MESSAGE + .parse(prefix + CaptionUtility.format(player, TranslatableCaption.of("info.plot_flag_list").getComponent(player)), + Template.of("flag", flag.getName()), Template.of("value", CaptionUtility.formatRaw(player, value.toString()))); + if (flags != null) { + flags.append(snip); + } else { + flags = snip; + } + prefix = ", "; } - info = info.replace("%id%", this.getId().toString()); - info = info.replace("%alias%", alias); - info = info.replace("%num%", String.valueOf(num)); - info = info.replace("%desc%", description); - info = info.replace("%biome%", biome.toString().toLowerCase()); - info = info.replace("%owner%", owner); - info = info.replace("%members%", members); - info = info.replace("%player%", player.getName()); - info = info.replace("%trusted%", trusted); - info = info.replace("%helpers%", members); - info = info.replace("%denied%", denied); - info = info.replace("%seen%", seen); - info = info.replace("%flags%", flags); - info = info.replace("%build%", String.valueOf(build)); - if (info.contains("%rating%")) { - final String newInfo = info; - TaskManager.runTaskAsync(() -> { - String info1; - if (Settings.Ratings.USE_LIKES) { - info1 = newInfo.replaceAll("%rating%", - String.format("%.0f%%", Like.getLikesPercentage(this) * 100D)); - } else { - int max = 10; - if (Settings.Ratings.CATEGORIES != null && !Settings.Ratings.CATEGORIES - .isEmpty()) { - max = 8; - } - if (full && Settings.Ratings.CATEGORIES != null - && Settings.Ratings.CATEGORIES.size() > 1) { - double[] ratings = this.getAverageRatings(); - String rating = ""; - String prefix = ""; - for (int i = 0; i < ratings.length; i++) { - rating += - prefix + Settings.Ratings.CATEGORIES.get(i) + '=' + String - .format("%.1f", ratings[i]); - prefix = ","; - } - info1 = newInfo.replaceAll("%rating%", rating); - } else { - info1 = newInfo.replaceAll("%rating%", - String.format("%.1f", this.getAverageRating()) + '/' + max); - } + } + boolean build = this.isAdded(player.getUUID()); + String owner = this.getOwners().isEmpty() ? "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; + if (this.getArea() != null) { + areaTemplate = + Template.of("area", this.getArea().getWorldName() + (this.getArea().getId() == null ? "" : "(" + this.getArea().getId() + ")")); + } else { + areaTemplate = Template.of("area", TranslatableCaption.of("info.none").getComponent(player)); + } + Template idTemplate = Template.of("id", this.getId().toString()); + Template aliasTemplate = Template.of("alias", alias); + Template numTemplate = Template.of("num", String.valueOf(num)); + Template descTemplate = Template.of("desc", description); + Template biomeTemplate = Template.of("biome", biome.toString().toLowerCase()); + Template ownerTemplate = Template.of("owner", owner); + Template membersTemplate = Template.of("members", members); + Template playerTemplate = Template.of("player", player.getName()); + Template trustedTemplate = Template.of("trusted", trusted); + Template helpersTemplate = Template.of("helpers", members); + Template deniedTemplate = Template.of("denied", denied); + Template seenTemplate = Template.of("seen", seen); + Template flagsTemplate = Template.of("flags", flags); + Template buildTemplate = Template.of("build", String.valueOf(build)); + if (iInfo.getComponent(player).contains("")) { + TaskManager.runTaskAsync(() -> { + Template ratingTemplate; + if (Settings.Ratings.USE_LIKES) { + ratingTemplate = Template.of("rating", String.format("%.0f%%", Like.getLikesPercentage(this) * 100D)); + } else { + int max = 10; + if (Settings.Ratings.CATEGORIES != null && !Settings.Ratings.CATEGORIES.isEmpty()) { + max = 8; } - future.complete(info1); - }); - return; - } - future.complete(info); - }); + if (full && Settings.Ratings.CATEGORIES != null && Settings.Ratings.CATEGORIES.size() > 1) { + double[] ratings = this.getAverageRatings(); + String rating = ""; + String prefix = ""; + for (int i = 0; i < ratings.length; i++) { + rating += prefix + Settings.Ratings.CATEGORIES.get(i) + '=' + String.format("%.1f", ratings[i]); + prefix = ","; + } + ratingTemplate = Template.of("rating", rating); + } else { + ratingTemplate = Template.of("rating", String.format("%.1f", this.getAverageRating()) + '/' + max); + } + } + future.complete(StaticCaption.of(MINI_MESSAGE.serialize(MINI_MESSAGE + .parse(iInfo.getComponent(player), headerTemplate, areaTemplate, idTemplate, aliasTemplate, numTemplate, descTemplate, + biomeTemplate, ownerTemplate, membersTemplate, playerTemplate, trustedTemplate, helpersTemplate, deniedTemplate, + seenTemplate, flagsTemplate, buildTemplate, ratingTemplate, footerTemplate)))); + }); + return; + } + future.complete(StaticCaption.of(MINI_MESSAGE.serialize(MINI_MESSAGE + .parse(iInfo.getComponent(player), headerTemplate, areaTemplate, idTemplate, aliasTemplate, numTemplate, descTemplate, biomeTemplate, + ownerTemplate, membersTemplate, playerTemplate, trustedTemplate, helpersTemplate, deniedTemplate, seenTemplate, flagsTemplate, + buildTemplate, footerTemplate)))); + }); return future; } diff --git a/Core/src/main/resources/lang/messages_en.json b/Core/src/main/resources/lang/messages_en.json index 75b9bff63..8b2c2bc82 100644 --- a/Core/src/main/resources/lang/messages_en.json +++ b/Core/src/main/resources/lang/messages_en.json @@ -348,6 +348,7 @@ "info.none": "None", "info.now": "Now", + "info.never": "Never", "info.unknown": "Unknown", "info.server": "Server", "info.everyone": "Everyone", @@ -355,7 +356,7 @@ "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": "ID: \nArea: \nAlias:\nOwner:\nBiome: \nCan Build: \nRating: \nSeen: \nTrusted:\nMembers:\nDenied:\nFlags:\nDescription: ", + "info.plot_info_format": "
\nID: \nArea: \nAlias:\nOwner:\nBiome: \nCan Build: \nRating: \nSeen: \nTrusted:\nMembers:\nDenied:\nFlags:\nDescription: \n