From 6f3eabba0e872af27b10104c340447b7c359235b Mon Sep 17 00:00:00 2001 From: Jordan Date: Mon, 1 Nov 2021 11:23:53 +0000 Subject: [PATCH] feat: Don't display the default plot title if on a server-plot, unless configured otherwise. (#3305) - If plot-title flag is set, title will still be displayed. --- .../core/configuration/Settings.java | 3 + .../core/listener/PlotListener.java | 90 ++++++++++--------- 2 files changed, 49 insertions(+), 44 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 3810987b2..5185f23fe 100644 --- a/Core/src/main/java/com/plotsquared/core/configuration/Settings.java +++ b/Core/src/main/java/com/plotsquared/core/configuration/Settings.java @@ -708,6 +708,9 @@ public class Settings extends Config { "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; + @Comment({"If the default title should be displayed on plots with server-plot flag set.", + "Titles will still be sent if the plot-title flag is set."}) + public static boolean DISPLAY_DEFAULT_ON_SERVER_PLOT = false; } 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 d92bc2c3c..98b573d4d 100644 --- a/Core/src/main/java/com/plotsquared/core/listener/PlotListener.java +++ b/Core/src/main/java/com/plotsquared/core/listener/PlotListener.java @@ -58,6 +58,7 @@ import com.plotsquared.core.plot.flag.implementations.MusicFlag; import com.plotsquared.core.plot.flag.implementations.NotifyEnterFlag; import com.plotsquared.core.plot.flag.implementations.NotifyLeaveFlag; import com.plotsquared.core.plot.flag.implementations.PlotTitleFlag; +import com.plotsquared.core.plot.flag.implementations.ServerPlotFlag; import com.plotsquared.core.plot.flag.implementations.TimeFlag; import com.plotsquared.core.plot.flag.implementations.TitlesFlag; import com.plotsquared.core.plot.flag.implementations.WeatherFlag; @@ -317,51 +318,52 @@ public class PlotListener { subtitle = ""; fromFlag = false; } - // It's not actually possible for these to be null, but IntelliJ is dumb - TaskManager.runTaskLaterAsync(() -> { - Plot lastPlot; - try (final MetaDataAccess lastPlotAccess = - player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LAST_PLOT)) { - lastPlot = lastPlotAccess.get().orElse(null); - } - if ((lastPlot != null) && plot.getId().equals(lastPlot.getId()) && plot.hasOwner()) { - final UUID plotOwner = plot.getOwnerAbs(); - String owner = PlayerManager.getName(plotOwner, false); - Caption header = fromFlag ? StaticCaption.of(title) : TranslatableCaption.of("titles" + - ".title_entered_plot"); - Caption subHeader = fromFlag ? StaticCaption.of(subtitle) : TranslatableCaption.of("titles" + - ".title_entered_plot_sub"); - Template plotTemplate = Template.of("plot", lastPlot.getId().toString()); - Template worldTemplate = Template.of("world", player.getLocation().getWorldName()); - Template ownerTemplate = Template.of("owner", owner); - Template aliasTemplate = Template.of("alias", plot.getAlias()); - - final Consumer userConsumer = user -> { - if (Settings.Titles.TITLES_AS_ACTIONBAR) { - player.sendActionBar(header, aliasTemplate, plotTemplate, worldTemplate, ownerTemplate); - } else { - player.sendTitle(header, subHeader, aliasTemplate, plotTemplate, worldTemplate, ownerTemplate); - } - }; - - UUID uuid = plot.getOwner(); - if (uuid == null) { - userConsumer.accept("Unknown"); - } else if (uuid.equals(DBFunc.SERVER)) { - userConsumer.accept(MINI_MESSAGE.stripTokens(TranslatableCaption - .of("info.server") - .getComponent(player))); - } else { - PlotSquared.get().getImpromptuUUIDPipeline().getSingle(plot.getOwner(), (user, throwable) -> { - if (throwable != null) { - userConsumer.accept("Unknown"); - } else { - userConsumer.accept(user); - } - }); + if (fromFlag || !plot.getFlag(ServerPlotFlag.class) || Settings.Titles.DISPLAY_DEFAULT_ON_SERVER_PLOT) { + TaskManager.runTaskLaterAsync(() -> { + Plot lastPlot; + try (final MetaDataAccess lastPlotAccess = + player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LAST_PLOT)) { + lastPlot = lastPlotAccess.get().orElse(null); } - } - }, TaskTime.seconds(1L)); + if ((lastPlot != null) && plot.getId().equals(lastPlot.getId()) && plot.hasOwner()) { + final UUID plotOwner = plot.getOwnerAbs(); + String owner = PlayerManager.getName(plotOwner, false); + Caption header = fromFlag ? StaticCaption.of(title) : TranslatableCaption.of("titles" + + ".title_entered_plot"); + Caption subHeader = fromFlag ? StaticCaption.of(subtitle) : TranslatableCaption.of("titles" + + ".title_entered_plot_sub"); + Template plotTemplate = Template.of("plot", lastPlot.getId().toString()); + Template worldTemplate = Template.of("world", player.getLocation().getWorldName()); + Template ownerTemplate = Template.of("owner", owner); + Template aliasTemplate = Template.of("alias", plot.getAlias()); + + final Consumer userConsumer = user -> { + if (Settings.Titles.TITLES_AS_ACTIONBAR) { + player.sendActionBar(header, aliasTemplate, plotTemplate, worldTemplate, ownerTemplate); + } else { + player.sendTitle(header, subHeader, aliasTemplate, plotTemplate, worldTemplate, ownerTemplate); + } + }; + + UUID uuid = plot.getOwner(); + if (uuid == null) { + userConsumer.accept("Unknown"); + } else if (uuid.equals(DBFunc.SERVER)) { + userConsumer.accept(MINI_MESSAGE.stripTokens(TranslatableCaption + .of("info.server") + .getComponent(player))); + } else { + PlotSquared.get().getImpromptuUUIDPipeline().getSingle(plot.getOwner(), (user, throwable) -> { + if (throwable != null) { + userConsumer.accept("Unknown"); + } else { + userConsumer.accept(user); + } + }); + } + } + }, TaskTime.seconds(1L)); + } } TimedFlag.Timed feed = plot.getFlag(FeedFlag.class);