mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-21 11:45:19 +01:00
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:
parent
804228fa6c
commit
6f3eabba0e
@ -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;
|
||||
|
||||
}
|
||||
|
||||
|
@ -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<Plot> 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<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 (fromFlag || !plot.getFlag(ServerPlotFlag.class) || Settings.Titles.DISPLAY_DEFAULT_ON_SERVER_PLOT) {
|
||||
TaskManager.runTaskLaterAsync(() -> {
|
||||
Plot lastPlot;
|
||||
try (final MetaDataAccess<Plot> 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<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);
|
||||
|
Loading…
Reference in New Issue
Block a user