From 86e69bc3ba58a4d0351a65fa3def0cfbcbefa176 Mon Sep 17 00:00:00 2001 From: darbyjack Date: Thu, 20 May 2021 15:12:51 -0500 Subject: [PATCH 1/6] Implemented the ability to change titles to actionbar on plot entry --- .../core/configuration/Settings.java | 2 ++ .../core/listener/PlotListener.java | 13 +++++++++-- .../plotsquared/core/player/PlotPlayer.java | 22 +++++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/Core/src/main/java/com/plotsquared/core/configuration/Settings.java b/Core/src/main/java/com/plotsquared/core/configuration/Settings.java index b7609a33b5..0eca549756 100644 --- a/Core/src/main/java/com/plotsquared/core/configuration/Settings.java +++ b/Core/src/main/java/com/plotsquared/core/configuration/Settings.java @@ -58,6 +58,8 @@ public class Settings extends Config { public static int TITLES_STAY = 50; @Comment("Plot titles fading out (duration in ticks)") public static int TITLES_FADE_OUT = 20; + @Comment("Show the plot titles as an actionbar?") + public static boolean TITLES_AS_ACTIOBAR = false; @Create // This value will be generated automatically public static ConfigBlock AUTO_CLEAR = null; 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 a382e675ac..58d21385b9 100644 --- a/Core/src/main/java/com/plotsquared/core/listener/PlotListener.java +++ b/Core/src/main/java/com/plotsquared/core/listener/PlotListener.java @@ -303,8 +303,17 @@ public boolean plotEntry(final PlotPlayer player, final Plot plot) { Template plotTemplate = Template.of("plot", lastPlot.getId().toString()); Template worldTemplate = Template.of("world", player.getLocation().getWorldName()); Template ownerTemplate = Template.of("owner", owner); - final Consumer userConsumer = user -> player - .sendTitle(header, subHeader, plotTemplate, worldTemplate, ownerTemplate); + + Consumer userConsumer; + + if (Settings.TITLES_AS_ACTIOBAR) { + userConsumer = user -> player.sendPlotEntryBar(header, subHeader, plotTemplate, worldTemplate, + ownerTemplate); + } else { + userConsumer = user -> player + .sendTitle(header, subHeader, plotTemplate, worldTemplate, ownerTemplate); + } + UUID uuid = plot.getOwner(); if (uuid == null) { userConsumer.accept("Unknown"); 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 fb2c764f68..5affca7594 100644 --- a/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java +++ b/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java @@ -65,6 +65,7 @@ import com.sk89q.worldedit.world.item.ItemType; import net.kyori.adventure.audience.Audience; import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.minimessage.Template; import net.kyori.adventure.title.Title; @@ -841,6 +842,27 @@ public void sendTitle( .title(titleComponent, subtitleComponent, times)); } + /** + * Sends an actionbar to the player on plot entry. + * This takes in two captions as it will internally merge + * the captions together to send as a single component. + * + * @param header Header + * @param subHeader Subheader + * @param replacements Variable replacements + */ + public void sendPlotEntryBar( + final @NonNull Caption header, final @NonNull Caption subHeader, + final @NonNull Template... replacements + ) { + final Component titleComponent = MiniMessage.get().parse(header.getComponent(this), replacements); + final Component subtitleComponent = + MiniMessage.get().parse(subHeader.getComponent(this), replacements); + + getAudience().sendActionBar( + titleComponent.append(Component.text(" | ").color(NamedTextColor.GRAY)).append(subtitleComponent)); + } + @Override public void sendMessage( final @NonNull Caption caption, From 15720e913e8c3b7432d9a3236791ec01aac2039f Mon Sep 17 00:00:00 2001 From: darbyjack Date: Thu, 20 May 2021 15:17:58 -0500 Subject: [PATCH 2/6] Fixed typo in action --- .../main/java/com/plotsquared/core/configuration/Settings.java | 2 +- .../main/java/com/plotsquared/core/listener/PlotListener.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Core/src/main/java/com/plotsquared/core/configuration/Settings.java b/Core/src/main/java/com/plotsquared/core/configuration/Settings.java index 0eca549756..21fcc9ce42 100644 --- a/Core/src/main/java/com/plotsquared/core/configuration/Settings.java +++ b/Core/src/main/java/com/plotsquared/core/configuration/Settings.java @@ -59,7 +59,7 @@ public class Settings extends Config { @Comment("Plot titles fading out (duration in ticks)") public static int TITLES_FADE_OUT = 20; @Comment("Show the plot titles as an actionbar?") - public static boolean TITLES_AS_ACTIOBAR = false; + public static boolean TITLES_AS_ACTIONBAR = false; @Create // This value will be generated automatically public static ConfigBlock AUTO_CLEAR = null; 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 58d21385b9..ebfeacd887 100644 --- a/Core/src/main/java/com/plotsquared/core/listener/PlotListener.java +++ b/Core/src/main/java/com/plotsquared/core/listener/PlotListener.java @@ -306,7 +306,7 @@ public boolean plotEntry(final PlotPlayer player, final Plot plot) { Consumer userConsumer; - if (Settings.TITLES_AS_ACTIOBAR) { + if (Settings.TITLES_AS_ACTIONBAR) { userConsumer = user -> player.sendPlotEntryBar(header, subHeader, plotTemplate, worldTemplate, ownerTemplate); } else { From b6e50febfca66f2623ff2b99433813312a115a04 Mon Sep 17 00:00:00 2001 From: darbyjack Date: Thu, 20 May 2021 17:04:55 -0500 Subject: [PATCH 3/6] Updated explanation in Javadoc --- .../main/java/com/plotsquared/core/player/PlotPlayer.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 5affca7594..866cc5d3a8 100644 --- a/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java +++ b/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java @@ -843,7 +843,12 @@ public void sendTitle( } /** - * Sends an actionbar to the player on plot entry. + * This method is explicitly used for sending an ActionBar + * to a player when they enter a plot. + * + * This method will serve no purposes in other locations + * of the project. + * * This takes in two captions as it will internally merge * the captions together to send as a single component. * From 5a28d4c229102f0d724adba895a0ddf8be58a2ce Mon Sep 17 00:00:00 2001 From: darbyjack Date: Fri, 21 May 2021 14:57:37 -0500 Subject: [PATCH 4/6] Implemented suggestions --- .../core/configuration/Settings.java | 5 +++- .../core/listener/PlotListener.java | 16 ++++++------- .../plotsquared/core/player/PlotPlayer.java | 24 +++++-------------- 3 files changed, 17 insertions(+), 28 deletions(-) diff --git a/Core/src/main/java/com/plotsquared/core/configuration/Settings.java b/Core/src/main/java/com/plotsquared/core/configuration/Settings.java index 21fcc9ce42..5dc3d248a6 100644 --- a/Core/src/main/java/com/plotsquared/core/configuration/Settings.java +++ b/Core/src/main/java/com/plotsquared/core/configuration/Settings.java @@ -58,7 +58,10 @@ public class Settings extends Config { public static int TITLES_STAY = 50; @Comment("Plot titles fading out (duration in ticks)") public static int TITLES_FADE_OUT = 20; - @Comment("Show the plot titles as an actionbar?") + @Comment({"Changes the notification method on plot entry from Title + SubTitle -> ActionBar.", + "The message still sent to the player is pulled from the lang key \"titles.title_entered_plot\".", + "If you would like to still show the owner of the plot, append the contents of \"titles.title_entered_plot_sub\" onto the " + + "former lang key."}) public static boolean TITLES_AS_ACTIONBAR = false; @Create // This value will be generated automatically 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 ebfeacd887..110c51e206 100644 --- a/Core/src/main/java/com/plotsquared/core/listener/PlotListener.java +++ b/Core/src/main/java/com/plotsquared/core/listener/PlotListener.java @@ -304,15 +304,13 @@ public boolean plotEntry(final PlotPlayer player, final Plot plot) { Template worldTemplate = Template.of("world", player.getLocation().getWorldName()); Template ownerTemplate = Template.of("owner", owner); - Consumer userConsumer; - - if (Settings.TITLES_AS_ACTIONBAR) { - userConsumer = user -> player.sendPlotEntryBar(header, subHeader, plotTemplate, worldTemplate, - ownerTemplate); - } else { - userConsumer = user -> player - .sendTitle(header, subHeader, plotTemplate, worldTemplate, ownerTemplate); - } + final Consumer userConsumer = user -> { + if (Settings.TITLES_AS_ACTIONBAR) { + player.sendActionBar(header, plotTemplate, worldTemplate, ownerTemplate); + } else { + player.sendTitle(header, subHeader, plotTemplate, worldTemplate, ownerTemplate); + } + }; UUID uuid = plot.getOwner(); if (uuid == null) { 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 866cc5d3a8..005798f48f 100644 --- a/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java +++ b/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java @@ -843,29 +843,17 @@ public void sendTitle( } /** - * This method is explicitly used for sending an ActionBar - * to a player when they enter a plot. + * Method designed to send an ActionBar to a player. * - * This method will serve no purposes in other locations - * of the project. - * - * This takes in two captions as it will internally merge - * the captions together to send as a single component. - * - * @param header Header - * @param subHeader Subheader + * @param caption Caption * @param replacements Variable replacements */ - public void sendPlotEntryBar( - final @NonNull Caption header, final @NonNull Caption subHeader, + public void sendActionBar( + final @NonNull Caption caption, final @NonNull Template... replacements ) { - final Component titleComponent = MiniMessage.get().parse(header.getComponent(this), replacements); - final Component subtitleComponent = - MiniMessage.get().parse(subHeader.getComponent(this), replacements); - - getAudience().sendActionBar( - titleComponent.append(Component.text(" | ").color(NamedTextColor.GRAY)).append(subtitleComponent)); + final Component component = MiniMessage.get().parse(caption.getComponent(this), replacements); + getAudience().sendActionBar(component); } @Override From 597f3f0d2b97f16d1e192f208c4974bb2612b403 Mon Sep 17 00:00:00 2001 From: darbyjack Date: Fri, 21 May 2021 15:00:13 -0500 Subject: [PATCH 5/6] Remove excess import --- Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java | 1 - 1 file changed, 1 deletion(-) 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 005798f48f..3469863c98 100644 --- a/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java +++ b/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java @@ -65,7 +65,6 @@ import com.sk89q.worldedit.world.item.ItemType; import net.kyori.adventure.audience.Audience; import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.minimessage.Template; import net.kyori.adventure.title.Title; From 1e6a2560e0939b1d2e1403f32ddd87aa3c51ef21 Mon Sep 17 00:00:00 2001 From: darbyjack Date: Sun, 23 May 2021 09:50:24 -0500 Subject: [PATCH 6/6] Implemented PR suggestions --- .../plotsquared/core/player/PlotPlayer.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) 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 3469863c98..517d4bef93 100644 --- a/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java +++ b/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java @@ -851,7 +851,25 @@ public void sendActionBar( final @NonNull Caption caption, final @NonNull Template... replacements ) { - final Component component = MiniMessage.get().parse(caption.getComponent(this), replacements); + String message; + try { + message = caption.getComponent(this); + } catch (final CaptionMap.NoSuchCaptionException exception) { + // This sends feedback to the player + message = NON_EXISTENT_CAPTION + ((TranslatableCaption) caption).getKey(); + // And this also prints it to the console + exception.printStackTrace(); + } + if (message.isEmpty()) { + return; + } + // Replace placeholders, etc + message = CaptionUtility.format(this, message) + .replace('\u2010', '%').replace('\u2020', '&').replace('\u2030', '&') + .replace("", TranslatableCaption.of("core.prefix").getComponent(this)); + + + final Component component = MiniMessage.get().parse(message, replacements); getAudience().sendActionBar(component); }