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 807a289c6..c635abb44 100644 --- a/Core/src/main/java/com/plotsquared/core/listener/PlotListener.java +++ b/Core/src/main/java/com/plotsquared/core/listener/PlotListener.java @@ -35,7 +35,6 @@ import com.plotsquared.core.events.PlotFlagRemoveEvent; import com.plotsquared.core.events.Result; import com.plotsquared.core.location.Location; import com.plotsquared.core.permissions.Permission; -import com.plotsquared.core.player.ConsolePlayer; import com.plotsquared.core.player.MetaDataAccess; import com.plotsquared.core.player.PlayerMetaDataKeys; import com.plotsquared.core.player.PlotPlayer; @@ -297,60 +296,59 @@ public class PlotListener { String subtitle; PlotTitle titleFlag = plot.getFlag(PlotTitleFlag.class); boolean fromFlag; - if (!titleFlag.title().isEmpty() && !titleFlag.subtitle().isEmpty()) { + if (titleFlag.title() != null && titleFlag.subtitle() != null) { title = titleFlag.title(); subtitle = titleFlag.subtitle(); fromFlag = true; } else { - title = TranslatableCaption.of("titles.title_entered_plot").getComponent(ConsolePlayer.getConsole()); - subtitle = TranslatableCaption.of("titles.title_entered_plot_sub").getComponent(ConsolePlayer.getConsole()); + title = ""; + subtitle = ""; fromFlag = false; } - if (!title.isEmpty() && !subtitle.isEmpty()) { - 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); + // 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); - final Consumer userConsumer = user -> { - if (Settings.Titles.TITLES_AS_ACTIONBAR) { - player.sendActionBar(header, plotTemplate, worldTemplate, ownerTemplate); - } else { - player.sendTitle(header, subHeader, 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))); + final Consumer userConsumer = user -> { + if (Settings.Titles.TITLES_AS_ACTIONBAR) { + player.sendActionBar(header, plotTemplate, worldTemplate, ownerTemplate); } else { - PlotSquared.get().getImpromptuUUIDPipeline().getSingle(plot.getOwner(), (user, throwable) -> { - if (throwable != null) { - userConsumer.accept("Unknown"); - } else { - userConsumer.accept(user); - } - }); + player.sendTitle(header, subHeader, 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)); - } + } + }, TaskTime.seconds(1L)); } TimedFlag.Timed feed = plot.getFlag(FeedFlag.class); diff --git a/Core/src/main/java/com/plotsquared/core/plot/PlotTitle.java b/Core/src/main/java/com/plotsquared/core/plot/PlotTitle.java index 3c73d111e..e2f0fef51 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/PlotTitle.java +++ b/Core/src/main/java/com/plotsquared/core/plot/PlotTitle.java @@ -25,13 +25,21 @@ */ package com.plotsquared.core.plot; +import javax.annotation.Nullable; import java.util.Objects; public class PlotTitle { + public static final PlotTitle CONFIGURED = new PlotTitle(); + private final String title; private final String subtitle; + private PlotTitle() { + title = null; + subtitle = null; + } + public PlotTitle(String title, String subtitle) { Objects.requireNonNull(title); Objects.requireNonNull(subtitle); @@ -39,10 +47,12 @@ public class PlotTitle { this.subtitle = subtitle; } + @Nullable public String title() { return title; } + @Nullable public String subtitle() { return subtitle; } diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/PlotTitleFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/PlotTitleFlag.java index 9d1b8422d..ccfaad961 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/PlotTitleFlag.java +++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/PlotTitleFlag.java @@ -33,7 +33,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; public class PlotTitleFlag extends PlotFlag { - public static final PlotTitleFlag TITLE_FLAG_EMPTY = new PlotTitleFlag(new PlotTitle("", "")); + public static final PlotTitleFlag TITLE_FLAG_EMPTY = new PlotTitleFlag(PlotTitle.CONFIGURED); /** * Construct a new flag instance.