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.
This commit is contained in:
Jordan 2021-11-01 11:23:53 +00:00 committed by GitHub
parent 804228fa6c
commit 6f3eabba0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 49 additions and 44 deletions

View File

@ -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 " + "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."}) "former lang key."})
public static boolean TITLES_AS_ACTIONBAR = false; 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;
} }

View File

@ -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.NotifyEnterFlag;
import com.plotsquared.core.plot.flag.implementations.NotifyLeaveFlag; import com.plotsquared.core.plot.flag.implementations.NotifyLeaveFlag;
import com.plotsquared.core.plot.flag.implementations.PlotTitleFlag; 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.TimeFlag;
import com.plotsquared.core.plot.flag.implementations.TitlesFlag; import com.plotsquared.core.plot.flag.implementations.TitlesFlag;
import com.plotsquared.core.plot.flag.implementations.WeatherFlag; import com.plotsquared.core.plot.flag.implementations.WeatherFlag;
@ -317,51 +318,52 @@ public class PlotListener {
subtitle = ""; subtitle = "";
fromFlag = false; fromFlag = false;
} }
// It's not actually possible for these to be null, but IntelliJ is dumb if (fromFlag || !plot.getFlag(ServerPlotFlag.class) || Settings.Titles.DISPLAY_DEFAULT_ON_SERVER_PLOT) {
TaskManager.runTaskLaterAsync(() -> { TaskManager.runTaskLaterAsync(() -> {
Plot lastPlot; Plot lastPlot;
try (final MetaDataAccess<Plot> lastPlotAccess = try (final MetaDataAccess<Plot> lastPlotAccess =
player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LAST_PLOT)) { player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LAST_PLOT)) {
lastPlot = lastPlotAccess.get().orElse(null); 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<String> 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 ((lastPlot != null) && plot.getId().equals(lastPlot.getId()) && plot.hasOwner()) {
}, TaskTime.seconds(1L)); 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<String> 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<Integer> feed = plot.getFlag(FeedFlag.class); TimedFlag.Timed<Integer> feed = plot.getFlag(FeedFlag.class);