diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java b/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java index 536fc328b..8a66f1fd0 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java @@ -44,10 +44,12 @@ import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.world.item.ItemType; import com.sk89q.worldedit.world.item.ItemTypes; import io.papermc.lib.PaperLib; +import net.kyori.adventure.audience.Audience; import net.kyori.adventure.platform.bukkit.BukkitAudiences; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.minimessage.Template; +import net.kyori.adventure.title.Title; import org.bukkit.GameMode; import org.bukkit.Sound; import org.bukkit.WeatherType; @@ -59,6 +61,8 @@ import org.bukkit.permissions.PermissionAttachmentInfo; import org.bukkit.plugin.RegisteredListener; import org.jetbrains.annotations.NotNull; +import java.time.Duration; +import java.time.temporal.ChronoUnit; import java.util.Arrays; import java.util.Set; import java.util.UUID; @@ -144,11 +148,6 @@ public class BukkitPlayer extends PlotPlayer { return true; } - @Override - public void sendTitle(String title, String subtitle, int fadeIn, int stay, int fadeOut) { - player.sendTitle(title, subtitle, fadeIn, stay, fadeOut); - } - private void callEvent(@NotNull final Event event) { final RegisteredListener[] listeners = event.getHandlers().getRegisteredListeners(); for (final RegisteredListener listener : listeners) { @@ -234,6 +233,16 @@ public class BukkitPlayer extends PlotPlayer { return this.player.isPermissionSet(permission); } + @Override + public void sendTitle(@NotNull final Caption title, @NotNull final Caption subtitle, + final int fadeIn, final int stay, final int fadeOut, @NotNull final Template ... replacements) { + final Component titleComponent = MINI_MESSAGE.parse(title.getComponent(this), replacements); + final Component subtitleComponent = MINI_MESSAGE.parse(subtitle.getComponent(this), replacements); + final Audience audience = BUKKIT_AUDIENCES.player(this.player); + audience.showTitle(Title.of(titleComponent, subtitleComponent, Duration.of(fadeIn * 50, + ChronoUnit.MILLIS), Duration.of(stay * 50, ChronoUnit.MILLIS), Duration.of(fadeOut * 50, ChronoUnit.MILLIS))); + } + @Override public void sendMessage(@NotNull final Caption caption, @NotNull final Template... replacements) { // TODO: Inject the prefix here diff --git a/Core/src/main/java/com/plotsquared/core/configuration/caption/CaptionLoader.java b/Core/src/main/java/com/plotsquared/core/configuration/caption/CaptionLoader.java index 5b66d1f74..9850925c7 100644 --- a/Core/src/main/java/com/plotsquared/core/configuration/caption/CaptionLoader.java +++ b/Core/src/main/java/com/plotsquared/core/configuration/caption/CaptionLoader.java @@ -78,7 +78,7 @@ public final class CaptionLoader { JsonObject.class); Map captions = new HashMap<>(); for (Map.Entry entry : object.entrySet()) { - TranslatableCaption key = TranslatableCaption.keyed(entry.getKey()); + TranslatableCaption key = TranslatableCaption.of(entry.getKey()); captions.put(key, entry.getValue().getAsString()); } return new LocalizedCaptionMap(locale, captions); diff --git a/Core/src/main/java/com/plotsquared/core/configuration/caption/TranslatableCaption.java b/Core/src/main/java/com/plotsquared/core/configuration/caption/TranslatableCaption.java index 50521b271..869a17ac1 100644 --- a/Core/src/main/java/com/plotsquared/core/configuration/caption/TranslatableCaption.java +++ b/Core/src/main/java/com/plotsquared/core/configuration/caption/TranslatableCaption.java @@ -48,7 +48,7 @@ public final class TranslatableCaption implements KeyedCaption { * @param key Caption key * @return Caption instance */ - @NotNull public static TranslatableCaption keyed(@NotNull final String key) { + @NotNull public static TranslatableCaption of(@NotNull final String key) { return new TranslatableCaption(key.toLowerCase(Locale.ENGLISH)); } diff --git a/Core/src/main/java/com/plotsquared/core/listener/PlotListener.java b/Core/src/main/java/com/plotsquared/core/listener/PlotListener.java index 361a71b28..a43587744 100644 --- a/Core/src/main/java/com/plotsquared/core/listener/PlotListener.java +++ b/Core/src/main/java/com/plotsquared/core/listener/PlotListener.java @@ -29,6 +29,7 @@ import com.plotsquared.core.PlotSquared; import com.plotsquared.core.collection.ByteArrayUtilities; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.Settings; +import com.plotsquared.core.configuration.caption.TranslatableCaption; import com.plotsquared.core.events.PlotFlagRemoveEvent; import com.plotsquared.core.events.Result; import com.plotsquared.core.location.Location; @@ -65,6 +66,7 @@ import com.sk89q.worldedit.world.gamemode.GameMode; import com.sk89q.worldedit.world.gamemode.GameModes; import com.sk89q.worldedit.world.item.ItemType; import com.sk89q.worldedit.world.item.ItemTypes; +import net.kyori.adventure.text.minimessage.Template; import java.util.HashMap; import java.util.Iterator; @@ -259,20 +261,16 @@ public class PlotListener { TaskManager.runTaskLaterAsync(() -> { Plot lastPlot = player.getMeta(PlotPlayer.META_LAST_PLOT); if ((lastPlot != null) && plot.getId().equals(lastPlot.getId())) { - Map replacements = new HashMap<>(); - replacements.put("%x%", String.valueOf(lastPlot.getId().x)); - replacements.put("%z%", lastPlot.getId().y + ""); - replacements.put("%world%", plot.getArea().toString()); - replacements.put("%greeting%", greeting); - replacements.put("%alias", plot.toString()); - replacements.put("%s", MainUtil.getName(plot.getOwner())); - String main = StringMan - .replaceFromMap(Captions.TITLE_ENTERED_PLOT.getTranslated(), - replacements); - String sub = StringMan - .replaceFromMap(Captions.TITLE_ENTERED_PLOT_SUB.getTranslated(), - replacements); - player.sendTitle(main, sub); + player.sendTitle( + TranslatableCaption.of("titles.title_entered_plot"), + TranslatableCaption.of("titles.title_entered_plot_sub"), + Template.of("x", Integer.toString(lastPlot.getId().getX())), + Template.of("z", Integer.toString(lastPlot.getId().getY())), + Template.of("world", plot.getArea().toString()), + Template.of("greeting", greeting), + Template.of("alias", plot.toString()), + Template.of("owner", MainUtil.getName(plot.getOwner())) + ); } }, 20); } diff --git a/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java b/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java index 964572d29..8455d285e 100644 --- a/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java +++ b/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java @@ -29,6 +29,7 @@ import com.google.common.base.Preconditions; import com.plotsquared.core.PlotSquared; import com.plotsquared.core.command.CommandCaller; import com.plotsquared.core.command.RequiredType; +import com.plotsquared.core.configuration.Caption; import com.plotsquared.core.configuration.CaptionUtility; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.Settings; @@ -54,6 +55,7 @@ import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.world.gamemode.GameMode; import com.sk89q.worldedit.world.item.ItemType; import lombok.NonNull; +import net.kyori.adventure.text.minimessage.Template; import org.jetbrains.annotations.NotNull; import java.nio.ByteBuffer; @@ -79,7 +81,8 @@ public abstract class PlotPlayer

implements CommandCaller, OfflinePlotPlayer, public static final String META_LOCATION = "location"; // Used to track debug mode - private static final Set> debugModeEnabled = Collections.synchronizedSet(new HashSet<>()); + private static final Set> debugModeEnabled = + Collections.synchronizedSet(new HashSet<>()); private static final Map converters = new HashMap<>(); private Map metaMap = new HashMap<>(); @@ -408,12 +411,31 @@ public abstract class PlotPlayer

implements CommandCaller, OfflinePlotPlayer, return result; } - public void sendTitle(String title, String subtitle) { - sendTitle(title, subtitle, 10, 50, 10); + /** + * Send a title to the player that fades in, in 10 ticks, stays for 50 ticks and fades + * out in 20 ticks + * + * @param title Title text + * @param subtitle Subtitle text + * @param replacements Variable replacements + */ + public void sendTitle(@NotNull final Caption title, @NotNull final Caption subtitle, + @NotNull final Template ... replacements) { + sendTitle(title, subtitle, 10, 50, 10, replacements); } - public abstract void sendTitle(String title, String subtitle, int fadeIn, int stay, - int fadeOut); + /** + * Send a title to the player + * + * @param title Title text + * @param subtitle Subtitle text + * @param fadeIn time in ticks for titles to fade in. Defaults to 10 + * @param stay time in ticks for titles to stay. Defaults to 70 + * @param fadeOut time in ticks for titles to fade out. Defaults to 20 + * @param replacements Variable replacements + */ + public abstract void sendTitle(@NotNull Caption title, @NotNull Caption subtitle, int fadeIn, + int stay, int fadeOut, @NotNull final Template ... replacements); /** * Teleport this player to a location. @@ -774,7 +796,9 @@ public abstract class PlotPlayer

implements CommandCaller, OfflinePlotPlayer, * The amount of money this Player has. */ public double getMoney() { - return EconHandler.getEconHandler() == null ? 0 : EconHandler.getEconHandler().getMoney(this); + return EconHandler.getEconHandler() == null ? + 0 : + EconHandler.getEconHandler().getMoney(this); } public void withdraw(double amount) { diff --git a/Core/src/main/java/com/plotsquared/core/plot/comment/CommentManager.java b/Core/src/main/java/com/plotsquared/core/plot/comment/CommentManager.java index 141d729c7..7a5e38ded 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/comment/CommentManager.java +++ b/Core/src/main/java/com/plotsquared/core/plot/comment/CommentManager.java @@ -26,12 +26,14 @@ package com.plotsquared.core.plot.comment; import com.google.common.annotations.Beta; -import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.Settings; +import com.plotsquared.core.configuration.StaticCaption; +import com.plotsquared.core.configuration.caption.TranslatableCaption; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.util.task.RunnableVal; import com.plotsquared.core.util.task.TaskManager; +import net.kyori.adventure.text.minimessage.Template; import java.util.Collection; import java.util.HashMap; @@ -66,8 +68,11 @@ import java.util.concurrent.atomic.AtomicInteger; total = count.get(); } if ((size.decrementAndGet() == 0) && (total > 0)) { - player.sendTitle("", Captions.INBOX_NOTIFICATION.getTranslated() - .replaceAll("%s", "" + total)); + player.sendTitle( + StaticCaption.of(""), + TranslatableCaption.of("comment.inbox_notification"), + Template.of("amount", Integer.toString(total)) + ); } } });