mirror of
				https://github.com/IntellectualSites/PlotSquared.git
				synced 2025-11-03 18:53:43 +01:00 
			
		
		
		
	Merge branch 'v6' of github.com:IntellectualSites/PlotSquared into v6
This commit is contained in:
		@@ -119,6 +119,8 @@ import com.plotsquared.core.uuid.offline.OfflineModeUUIDService;
 | 
			
		||||
import com.sk89q.worldedit.WorldEdit;
 | 
			
		||||
import io.papermc.lib.PaperLib;
 | 
			
		||||
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.bukkit.Bukkit;
 | 
			
		||||
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);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -48,6 +48,7 @@ import com.plotsquared.core.util.SetupUtils;
 | 
			
		||||
import com.plotsquared.core.util.WorldUtil;
 | 
			
		||||
import com.plotsquared.core.util.placeholders.PlaceholderRegistry;
 | 
			
		||||
import net.kyori.adventure.audience.Audience;
 | 
			
		||||
import net.kyori.adventure.text.Component;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nonnull;
 | 
			
		||||
import javax.annotation.Nullable;
 | 
			
		||||
@@ -307,4 +308,6 @@ public interface PlotPlatform<P> extends LocaleHolder {
 | 
			
		||||
        return injector().getInstance(PlaceholderRegistry.class);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Nonnull String toLegacyPlatformString(Component component);
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
@@ -2693,11 +2694,12 @@ public class Plot {
 | 
			
		||||
                description = TranslatableCaption.of("info.plot_no_description").getComponent(player);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            Component flags = null;
 | 
			
		||||
            Component flags;
 | 
			
		||||
            Collection<PlotFlag<?, ?>> flagCollection = this.getApplicableFlags(true);
 | 
			
		||||
            if (flagCollection.isEmpty()) {
 | 
			
		||||
                flags = MINI_MESSAGE.parse(TranslatableCaption.of("info.none").getComponent(player));
 | 
			
		||||
            } else {
 | 
			
		||||
                TextComponent.Builder flagBuilder = Component.text();
 | 
			
		||||
                String prefix = " ";
 | 
			
		||||
                for (final PlotFlag<?, ?> flag : flagCollection) {
 | 
			
		||||
                    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)),
 | 
			
		||||
                            Template.of("flag", flag.getName()), Template.of("value", CaptionUtility.formatRaw(player, value.toString())));
 | 
			
		||||
                    if (flags != null) {
 | 
			
		||||
                        flags.append(snip);
 | 
			
		||||
                    } else {
 | 
			
		||||
                        flags = snip;
 | 
			
		||||
                    }
 | 
			
		||||
                    flagBuilder.append(snip);
 | 
			
		||||
                    prefix = ", ";
 | 
			
		||||
                }
 | 
			
		||||
                flags = flagBuilder.build();
 | 
			
		||||
            }
 | 
			
		||||
            boolean build = this.isAdded(player.getUUID());
 | 
			
		||||
            Component owner;
 | 
			
		||||
 
 | 
			
		||||
@@ -29,7 +29,9 @@ import com.google.common.base.Function;
 | 
			
		||||
import com.google.common.base.Preconditions;
 | 
			
		||||
import com.google.common.collect.Maps;
 | 
			
		||||
import com.google.inject.Singleton;
 | 
			
		||||
import com.plotsquared.core.PlotSquared;
 | 
			
		||||
import com.plotsquared.core.configuration.Settings;
 | 
			
		||||
import com.plotsquared.core.configuration.caption.LocaleHolder;
 | 
			
		||||
import com.plotsquared.core.configuration.caption.TranslatableCaption;
 | 
			
		||||
import com.plotsquared.core.player.PlotPlayer;
 | 
			
		||||
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.util.EventDispatcher;
 | 
			
		||||
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.Nullable;
 | 
			
		||||
@@ -80,74 +84,77 @@ public final class PlaceholderRegistry {
 | 
			
		||||
        this.createPlaceholder("has_plot", player -> player.getPlotCount() > 0 ? "true" : "false");
 | 
			
		||||
        this.createPlaceholder("allowed_plot_count", (player) -> {
 | 
			
		||||
            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());
 | 
			
		||||
        });
 | 
			
		||||
        this.createPlaceholder("plot_count", player -> Integer.toString(player.getPlotCount()));
 | 
			
		||||
        this.createPlaceholder("currentplot_alias", (player, plot) -> {
 | 
			
		||||
            if (plot.getAlias() == null) {
 | 
			
		||||
                return String.valueOf(TranslatableCaption.of("info.none"));
 | 
			
		||||
            if (plot.getAlias().isEmpty()) {
 | 
			
		||||
                return legacyComponent(TranslatableCaption.of("info.none"), player);
 | 
			
		||||
            }
 | 
			
		||||
            return plot.getAlias();
 | 
			
		||||
        });
 | 
			
		||||
        this.createPlaceholder("currentplot_owner", (player, plot) -> {
 | 
			
		||||
            final UUID plotOwner = plot.getOwnerAbs();
 | 
			
		||||
            if (plotOwner == null) {
 | 
			
		||||
                return String.valueOf(TranslatableCaption.of("generic.generic_unowned"));
 | 
			
		||||
                return legacyComponent(TranslatableCaption.of("generic.generic_unowned"), player);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            try {
 | 
			
		||||
                return PlayerManager.getName(plotOwner, false);
 | 
			
		||||
            } catch (final Exception ignored) {
 | 
			
		||||
            }
 | 
			
		||||
            return String.valueOf(TranslatableCaption.of("info.unknown"));
 | 
			
		||||
            return legacyComponent(TranslatableCaption.of("info.unknown"), player);
 | 
			
		||||
        });
 | 
			
		||||
        this.createPlaceholder("currentplot_members", (player, plot) -> {
 | 
			
		||||
            if (plot.getMembers() == null && plot.getTrusted() == null) {
 | 
			
		||||
                return String.valueOf(TranslatableCaption.of("info.none"));
 | 
			
		||||
            if (plot.getMembers().isEmpty() && plot.getTrusted().isEmpty()) {
 | 
			
		||||
                return legacyComponent(TranslatableCaption.of("info.none"), player);
 | 
			
		||||
            }
 | 
			
		||||
            return String.valueOf(plot.getMembers().size() + plot.getTrusted().size());
 | 
			
		||||
        });
 | 
			
		||||
        this.createPlaceholder("currentplot_members_added", (player, plot) -> {
 | 
			
		||||
            if (plot.getMembers() == null) {
 | 
			
		||||
                return String.valueOf(TranslatableCaption.of("info.none"));
 | 
			
		||||
            if (plot.getMembers() .isEmpty()) {
 | 
			
		||||
                return legacyComponent(TranslatableCaption.of("info.none"), player);
 | 
			
		||||
            }
 | 
			
		||||
            return String.valueOf(plot.getMembers().size());
 | 
			
		||||
        });
 | 
			
		||||
        this.createPlaceholder("currentplot_members_trusted", (player, plot) -> {
 | 
			
		||||
            if (plot.getTrusted() == null) {
 | 
			
		||||
                return String.valueOf(TranslatableCaption.of("info.none"));
 | 
			
		||||
            if (plot.getTrusted().isEmpty()) {
 | 
			
		||||
                return legacyComponent(TranslatableCaption.of("info.none"), player);
 | 
			
		||||
            }
 | 
			
		||||
            return String.valueOf(plot.getTrusted().size());
 | 
			
		||||
        });
 | 
			
		||||
        this.createPlaceholder("currentplot_members_denied", (player, plot) -> {
 | 
			
		||||
            if (plot.getDenied() == null) {
 | 
			
		||||
                return String.valueOf(TranslatableCaption.of("info.none"));
 | 
			
		||||
            if (plot.getDenied().isEmpty()) {
 | 
			
		||||
                return legacyComponent(TranslatableCaption.of("info.none"), player);
 | 
			
		||||
            }
 | 
			
		||||
            return String.valueOf(plot.getDenied().size());
 | 
			
		||||
        });
 | 
			
		||||
        this.createPlaceholder("currentplot_members_trusted_list", (player, plot) -> {
 | 
			
		||||
            if (plot.getTrusted() == null) {
 | 
			
		||||
                return String.valueOf(TranslatableCaption.of("info.none"));
 | 
			
		||||
            if (plot.getTrusted().isEmpty()) {
 | 
			
		||||
                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) -> {
 | 
			
		||||
            if (plot.getMembers() == null) {
 | 
			
		||||
                return String.valueOf(TranslatableCaption.of("info.none"));
 | 
			
		||||
            if (plot.getMembers().isEmpty()) {
 | 
			
		||||
                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) -> {
 | 
			
		||||
            if (plot.getDenied() == null) {
 | 
			
		||||
                return String.valueOf(TranslatableCaption.of("info.none"));
 | 
			
		||||
            if (plot.getDenied().isEmpty()) {
 | 
			
		||||
                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) -> {
 | 
			
		||||
            if (plot.getTimestamp() == 0) {
 | 
			
		||||
                return String.valueOf(TranslatableCaption.of("info.unknown"));
 | 
			
		||||
                return legacyComponent(TranslatableCaption.of("info.unknown"), player);
 | 
			
		||||
            }
 | 
			
		||||
            long creationDate = plot.getTimestamp();
 | 
			
		||||
            SimpleDateFormat sdf = new SimpleDateFormat(Settings.Timeformat.DATE_FORMAT);
 | 
			
		||||
@@ -258,6 +265,18 @@ public final class PlaceholderRegistry {
 | 
			
		||||
        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
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user