Fix plot info, sign usage in Plot.class

This commit is contained in:
dordsor21 2020-08-04 15:07:07 +01:00
parent 3fd3baaa47
commit d3fe1d3b2b
No known key found for this signature in database
GPG Key ID: 1E53E88969FFCF0B
4 changed files with 148 additions and 145 deletions

View File

@ -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<BlockType> 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) {

View File

@ -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;
}

View File

@ -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,42 +3491,40 @@ public class Plot {
return FlagContainer.<T, V>castUnsafe(flagInstance).getValue();
}
public CompletableFuture<String> format(final String iInfo, PlotPlayer<?> player, final boolean full) {
final CompletableFuture<String> future = new CompletableFuture<>();
public CompletableFuture<Caption> format(final Caption iInfo, PlotPlayer<?> player, final boolean full) {
final CompletableFuture<Caption> 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;
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 = Captions.NOW.getTranslated();
seen = TranslatableCaption.of("info.now").getComponent(player);
} else {
int time = (int) (ExpireManager.IMP.getAge(this) / 1000);
if (time != 0) {
seen = TimeUtil.secToTime(time);
} else {
seen = Captions.UNKNOWN.getTranslated();
seen = TranslatableCaption.of("info.known").getComponent(player);
}
}
} else {
seen = Captions.NEVER.getTranslated();
seen = TranslatableCaption.of("info.never").getComponent(player);
}
String description = this.getFlag(DescriptionFlag.class);
if (description.isEmpty()) {
description = Captions.PLOT_NO_DESCRIPTION.getTranslated();
description = TranslatableCaption.of("info.plot_no_description").getComponent(player);
}
StringBuilder flags = new StringBuilder();
Component flags = null;
Collection<PlotFlag<?, ?>> flagCollection = this.getApplicableFlags(true);
if (flagCollection.isEmpty()) {
flags.append(Captions.NONE.getTranslated());
flags = MINI_MESSAGE.parse(TranslatableCaption.of("info.none").getComponent(player));
} else {
String prefix = " ";
for (final PlotFlag<?, ?> flag : flagCollection) {
@ -3534,71 +3534,76 @@ public class Plot {
} else {
value = flag.toString();
}
flags.append(prefix).append(CaptionUtility
.format(player, Captions.PLOT_FLAG_LIST.getTranslated(), flag.getName(),
CaptionUtility.formatRaw(player, value.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 = ", ";
}
}
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) {
info = info.replace("%area%",
this.getArea().getWorldName() + (this.getArea().getId() == null ?
"" :
"(" + this.getArea().getId() + ")"));
areaTemplate =
Template.of("area", this.getArea().getWorldName() + (this.getArea().getId() == null ? "" : "(" + this.getArea().getId() + ")"));
} else {
info = info.replace("%area%", Captions.NONE.getTranslated());
areaTemplate = Template.of("area", TranslatableCaption.of("info.none").getComponent(player));
}
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;
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("<rating>")) {
TaskManager.runTaskAsync(() -> {
String info1;
Template ratingTemplate;
if (Settings.Ratings.USE_LIKES) {
info1 = newInfo.replaceAll("%rating%",
String.format("%.0f%%", Like.getLikesPercentage(this) * 100D));
ratingTemplate = Template.of("rating", String.format("%.0f%%", Like.getLikesPercentage(this) * 100D));
} else {
int max = 10;
if (Settings.Ratings.CATEGORIES != null && !Settings.Ratings.CATEGORIES
.isEmpty()) {
if (Settings.Ratings.CATEGORIES != null && !Settings.Ratings.CATEGORIES.isEmpty()) {
max = 8;
}
if (full && Settings.Ratings.CATEGORIES != null
&& Settings.Ratings.CATEGORIES.size() > 1) {
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]);
rating += prefix + Settings.Ratings.CATEGORIES.get(i) + '=' + String.format("%.1f", ratings[i]);
prefix = ",";
}
info1 = newInfo.replaceAll("%rating%", rating);
ratingTemplate = Template.of("rating", rating);
} else {
info1 = newInfo.replaceAll("%rating%",
String.format("%.1f", this.getAverageRating()) + '/' + max);
ratingTemplate = Template.of("rating", String.format("%.1f", this.getAverageRating()) + '/' + max);
}
}
future.complete(info1);
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(info);
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;
}

View File

@ -348,6 +348,7 @@
"info.none": "<gray>None</gray>",
"info.now": "<gray>Now</gray>",
"info.never": "<gray>Never</gray>",
"info.unknown": "<gray>Unknown</gray>",
"info.server": "<gray>Server</gray>",
"info.everyone": "<gray>Everyone</gray>",
@ -355,7 +356,7 @@
"info.plot_info_unclaimed": "<prefix><gray>Plot <gold><plot></gold> is not yet claimed.</gray>",
"info.plot_info_header": "<dark_gray><strikethrough>--------- <reset><gold>INFO </gold><dark_gray><strikethrough>---------</dark_gray>",
"info.plot_info_hidden": "<prefix><red>You cannot view the information about this plot.</red>",
"info.plot_info_format": "<gold>ID: <gray><id></gray>\nArea: <gray><area></gray>\nAlias:<gray><alias></gray>\nOwner:<gray><owner></gray>\nBiome: <gray><biome></gray>\nCan Build: <gray><build></gray>\nRating: <gray><rating></gray>\nSeen: <gray><seen></gray>\nTrusted:<gray><trusted></gray>\nMembers:<gray><members></gray>\nDenied:<gray><denied></gray>\nFlags:<gray><flags></gray>\nDescription: <gray><desc></gray></gold>",
"info.plot_info_format": "<header>\n<gold>ID: <gray><id></gray>\nArea: <gray><area></gray>\nAlias:<gray><alias></gray>\nOwner:<gray><owner></gray>\nBiome: <gray><biome></gray>\nCan Build: <gray><build></gray>\nRating: <gray><rating></gray>\nSeen: <gray><seen></gray>\nTrusted:<gray><trusted></gray>\nMembers:<gray><members></gray>\nDenied:<gray><denied></gray>\nFlags:<gray><flags></gray>\nDescription: <gray><desc></gray></gold>\n<footer>",
"info.plot_info_footer": "<dark_gray><strikethrough>--------- <reset><gold>INFO </gold><dark_gray><strikethrough>---------<reset>",
"info.plot_info_trusted": "<gold>Trusted:</gold><gray><trusted></gray>",
"info.plot_info_members": "<gold>Members:</gold><gray><members></gray>",
@ -415,8 +416,8 @@
"owner.now_owner": "<prefix><dark_aqua>You are now the plot owner of plot <plot>.</dark_aqua>",
"signs.owner_sign_line_1": "<gold>ID: </gold><gray><id></gray>",
"signs.owner_sign_line_2": "<gold>Owner: </gold><gray><owner></gray>",
"signs.owner_sign_line_3": "<gray><plr></gray>",
"signs.owner_sign_line_2": "<gold>Owner:",
"signs.owner_sign_line_3": "<gray><owner></gray>",
"signs.owner_sign_line_4": "<dark_gray>Claimed</dark_gray>",
"help.help_header": "<dark_gray><strikethrough>---------<reset> <gold>PlotSquared Help </gold><dark_gray><strikethrough>---------<reset>",