Implemented the ability to change titles to actionbar on plot entry (#3060)

* Implemented the ability to change titles to actionbar on plot entry

* Fixed typo in action

* Updated explanation in Javadoc

* Implemented suggestions

* Remove excess import

* Implemented PR suggestions

Co-authored-by: NotMyFault <mc.cache@web.de>
This commit is contained in:
Glare 2021-05-23 10:28:03 -05:00 committed by GitHub
parent 399d77c60f
commit a69b1d895c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 2 deletions

View File

@ -58,6 +58,11 @@ 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({"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
public static ConfigBlock<Auto_Clear> AUTO_CLEAR = null;

View File

@ -303,8 +303,15 @@ public class PlotListener {
Template plotTemplate = Template.of("plot", lastPlot.getId().toString());
Template worldTemplate = Template.of("world", player.getLocation().getWorldName());
Template ownerTemplate = Template.of("owner", owner);
final Consumer<String> userConsumer = user -> player
.sendTitle(header, subHeader, plotTemplate, worldTemplate, ownerTemplate);
final Consumer<String> 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) {
userConsumer.accept("Unknown");

View File

@ -841,6 +841,38 @@ public abstract class PlotPlayer<P> implements CommandCaller, OfflinePlotPlayer,
.title(titleComponent, subtitleComponent, times));
}
/**
* Method designed to send an ActionBar to a player.
*
* @param caption Caption
* @param replacements Variable replacements
*/
public void sendActionBar(
final @NonNull Caption caption,
final @NonNull Template... 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("<prefix>", TranslatableCaption.of("core.prefix").getComponent(this));
final Component component = MiniMessage.get().parse(message, replacements);
getAudience().sendActionBar(component);
}
@Override
public void sendMessage(
final @NonNull Caption caption,