Merge branch 'v6' of github.com:IntellectualSites/PlotSquared into v6

This commit is contained in:
dordsor21 2020-12-28 12:27:12 +00:00
commit 3cfbe9585a
No known key found for this signature in database
GPG Key ID: 1E53E88969FFCF0B
4 changed files with 59 additions and 30 deletions

View File

@ -119,6 +119,8 @@ import com.plotsquared.core.uuid.offline.OfflineModeUUIDService;
import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEdit;
import io.papermc.lib.PaperLib; import io.papermc.lib.PaperLib;
import net.kyori.adventure.audience.Audience; import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bstats.bukkit.Metrics; import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Chunk; import org.bukkit.Chunk;
@ -1107,4 +1109,10 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
} }
} }
@Nonnull
@Override
public String toLegacyPlatformString(Component component) {
return LegacyComponentSerializer.legacyAmpersand().serialize(component);
}
} }

View File

@ -48,6 +48,7 @@ import com.plotsquared.core.util.SetupUtils;
import com.plotsquared.core.util.WorldUtil; import com.plotsquared.core.util.WorldUtil;
import com.plotsquared.core.util.placeholders.PlaceholderRegistry; import com.plotsquared.core.util.placeholders.PlaceholderRegistry;
import net.kyori.adventure.audience.Audience; import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.Component;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -307,4 +308,6 @@ public interface PlotPlatform<P> extends LocaleHolder {
return injector().getInstance(PlaceholderRegistry.class); return injector().getInstance(PlaceholderRegistry.class);
} }
@Nonnull String toLegacyPlatformString(Component component);
} }

View File

@ -76,6 +76,7 @@ import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.biome.BiomeType;
import net.kyori.adventure.text.Component; 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.MiniMessage;
import net.kyori.adventure.text.minimessage.Template; import net.kyori.adventure.text.minimessage.Template;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -2693,11 +2694,12 @@ public class Plot {
description = TranslatableCaption.of("info.plot_no_description").getComponent(player); description = TranslatableCaption.of("info.plot_no_description").getComponent(player);
} }
Component flags = null; Component flags;
Collection<PlotFlag<?, ?>> flagCollection = this.getApplicableFlags(true); Collection<PlotFlag<?, ?>> flagCollection = this.getApplicableFlags(true);
if (flagCollection.isEmpty()) { if (flagCollection.isEmpty()) {
flags = MINI_MESSAGE.parse(TranslatableCaption.of("info.none").getComponent(player)); flags = MINI_MESSAGE.parse(TranslatableCaption.of("info.none").getComponent(player));
} else { } else {
TextComponent.Builder flagBuilder = Component.text();
String prefix = " "; String prefix = " ";
for (final PlotFlag<?, ?> flag : flagCollection) { for (final PlotFlag<?, ?> flag : flagCollection) {
Object value; Object value;
@ -2708,13 +2710,10 @@ public class Plot {
} }
Component snip = MINI_MESSAGE.parse(prefix + CaptionUtility.format(player, TranslatableCaption.of("info.plot_flag_list").getComponent(player)), 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()))); Template.of("flag", flag.getName()), Template.of("value", CaptionUtility.formatRaw(player, value.toString())));
if (flags != null) { flagBuilder.append(snip);
flags.append(snip);
} else {
flags = snip;
}
prefix = ", "; prefix = ", ";
} }
flags = flagBuilder.build();
} }
boolean build = this.isAdded(player.getUUID()); boolean build = this.isAdded(player.getUUID());
Component owner; Component owner;

View File

@ -29,7 +29,9 @@ import com.google.common.base.Function;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.inject.Singleton; import com.google.inject.Singleton;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.configuration.caption.LocaleHolder;
import com.plotsquared.core.configuration.caption.TranslatableCaption; import com.plotsquared.core.configuration.caption.TranslatableCaption;
import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.Plot;
@ -37,6 +39,8 @@ import com.plotsquared.core.plot.flag.GlobalFlagContainer;
import com.plotsquared.core.plot.flag.PlotFlag; import com.plotsquared.core.plot.flag.PlotFlag;
import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.EventDispatcher;
import com.plotsquared.core.util.PlayerManager; import com.plotsquared.core.util.PlayerManager;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -80,74 +84,77 @@ public final class PlaceholderRegistry {
this.createPlaceholder("has_plot", player -> player.getPlotCount() > 0 ? "true" : "false"); this.createPlaceholder("has_plot", player -> player.getPlotCount() > 0 ? "true" : "false");
this.createPlaceholder("allowed_plot_count", (player) -> { this.createPlaceholder("allowed_plot_count", (player) -> {
if (player.getAllowedPlots() >= Integer.MAX_VALUE) { // Beautifies cases with '*' permission if (player.getAllowedPlots() >= Integer.MAX_VALUE) { // Beautifies cases with '*' permission
return String.valueOf(TranslatableCaption.of("info.infinite")); return legacyComponent(TranslatableCaption.of("info.infinite"), player);
} }
return Integer.toString(player.getAllowedPlots()); return Integer.toString(player.getAllowedPlots());
}); });
this.createPlaceholder("plot_count", player -> Integer.toString(player.getPlotCount())); this.createPlaceholder("plot_count", player -> Integer.toString(player.getPlotCount()));
this.createPlaceholder("currentplot_alias", (player, plot) -> { this.createPlaceholder("currentplot_alias", (player, plot) -> {
if (plot.getAlias() == null) { if (plot.getAlias().isEmpty()) {
return String.valueOf(TranslatableCaption.of("info.none")); return legacyComponent(TranslatableCaption.of("info.none"), player);
} }
return plot.getAlias(); return plot.getAlias();
}); });
this.createPlaceholder("currentplot_owner", (player, plot) -> { this.createPlaceholder("currentplot_owner", (player, plot) -> {
final UUID plotOwner = plot.getOwnerAbs(); final UUID plotOwner = plot.getOwnerAbs();
if (plotOwner == null) { if (plotOwner == null) {
return String.valueOf(TranslatableCaption.of("generic.generic_unowned")); return legacyComponent(TranslatableCaption.of("generic.generic_unowned"), player);
} }
try { try {
return PlayerManager.getName(plotOwner, false); return PlayerManager.getName(plotOwner, false);
} catch (final Exception ignored) { } catch (final Exception ignored) {
} }
return String.valueOf(TranslatableCaption.of("info.unknown")); return legacyComponent(TranslatableCaption.of("info.unknown"), player);
}); });
this.createPlaceholder("currentplot_members", (player, plot) -> { this.createPlaceholder("currentplot_members", (player, plot) -> {
if (plot.getMembers() == null && plot.getTrusted() == null) { if (plot.getMembers().isEmpty() && plot.getTrusted().isEmpty()) {
return String.valueOf(TranslatableCaption.of("info.none")); return legacyComponent(TranslatableCaption.of("info.none"), player);
} }
return String.valueOf(plot.getMembers().size() + plot.getTrusted().size()); return String.valueOf(plot.getMembers().size() + plot.getTrusted().size());
}); });
this.createPlaceholder("currentplot_members_added", (player, plot) -> { this.createPlaceholder("currentplot_members_added", (player, plot) -> {
if (plot.getMembers() == null) { if (plot.getMembers() .isEmpty()) {
return String.valueOf(TranslatableCaption.of("info.none")); return legacyComponent(TranslatableCaption.of("info.none"), player);
} }
return String.valueOf(plot.getMembers().size()); return String.valueOf(plot.getMembers().size());
}); });
this.createPlaceholder("currentplot_members_trusted", (player, plot) -> { this.createPlaceholder("currentplot_members_trusted", (player, plot) -> {
if (plot.getTrusted() == null) { if (plot.getTrusted().isEmpty()) {
return String.valueOf(TranslatableCaption.of("info.none")); return legacyComponent(TranslatableCaption.of("info.none"), player);
} }
return String.valueOf(plot.getTrusted().size()); return String.valueOf(plot.getTrusted().size());
}); });
this.createPlaceholder("currentplot_members_denied", (player, plot) -> { this.createPlaceholder("currentplot_members_denied", (player, plot) -> {
if (plot.getDenied() == null) { if (plot.getDenied().isEmpty()) {
return String.valueOf(TranslatableCaption.of("info.none")); return legacyComponent(TranslatableCaption.of("info.none"), player);
} }
return String.valueOf(plot.getDenied().size()); return String.valueOf(plot.getDenied().size());
}); });
this.createPlaceholder("currentplot_members_trusted_list", (player, plot) -> { this.createPlaceholder("currentplot_members_trusted_list", (player, plot) -> {
if (plot.getTrusted() == null) { if (plot.getTrusted().isEmpty()) {
return String.valueOf(TranslatableCaption.of("info.none")); return legacyComponent(TranslatableCaption.of("info.none"), player);
} }
return String.valueOf(PlayerManager.getPlayerList(plot.getTrusted(), player)); return PlotSquared.platform().toLegacyPlatformString(
PlayerManager.getPlayerList(plot.getTrusted(), player));
}); });
this.createPlaceholder("currentplot_members_added_list", (player, plot) -> { this.createPlaceholder("currentplot_members_added_list", (player, plot) -> {
if (plot.getMembers() == null) { if (plot.getMembers().isEmpty()) {
return String.valueOf(TranslatableCaption.of("info.none")); return legacyComponent(TranslatableCaption.of("info.none"), player);
} }
return String.valueOf(PlayerManager.getPlayerList(plot.getMembers(), player)); return PlotSquared.platform().toLegacyPlatformString(
PlayerManager.getPlayerList(plot.getMembers(), player));
}); });
this.createPlaceholder("currentplot_members_denied_list", (player, plot) -> { this.createPlaceholder("currentplot_members_denied_list", (player, plot) -> {
if (plot.getDenied() == null) { if (plot.getDenied().isEmpty()) {
return String.valueOf(TranslatableCaption.of("info.none")); return legacyComponent(TranslatableCaption.of("info.none"), player);
} }
return String.valueOf(PlayerManager.getPlayerList(plot.getDenied(), player)); return PlotSquared.platform().toLegacyPlatformString(
PlayerManager.getPlayerList(plot.getDenied(), player));
}); });
this.createPlaceholder("currentplot_creationdate", (player, plot) -> { this.createPlaceholder("currentplot_creationdate", (player, plot) -> {
if (plot.getTimestamp() == 0) { if (plot.getTimestamp() == 0) {
return String.valueOf(TranslatableCaption.of("info.unknown")); return legacyComponent(TranslatableCaption.of("info.unknown"), player);
} }
long creationDate = plot.getTimestamp(); long creationDate = plot.getTimestamp();
SimpleDateFormat sdf = new SimpleDateFormat(Settings.Timeformat.DATE_FORMAT); SimpleDateFormat sdf = new SimpleDateFormat(Settings.Timeformat.DATE_FORMAT);
@ -258,6 +265,18 @@ public final class PlaceholderRegistry {
return Collections.unmodifiableCollection(this.placeholders.values()); return Collections.unmodifiableCollection(this.placeholders.values());
} }
/**
* Converts a {@link Component} into a legacy-formatted string.
*
* @param caption the caption key.
* @param localeHolder the locale holder to get the component for
* @return a legacy-formatted string.
*/
private static String legacyComponent(TranslatableCaption caption, LocaleHolder localeHolder) {
Component component = MiniMessage.get().parse(caption.getComponent(localeHolder));
return PlotSquared.platform().toLegacyPlatformString(component);
}
/** /**
* Event called when a new {@link Placeholder} has been added * Event called when a new {@link Placeholder} has been added