mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-24 22:26:45 +01:00
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:
parent
399d77c60f
commit
a69b1d895c
@ -58,6 +58,11 @@ public class Settings extends Config {
|
|||||||
public static int TITLES_STAY = 50;
|
public static int TITLES_STAY = 50;
|
||||||
@Comment("Plot titles fading out (duration in ticks)")
|
@Comment("Plot titles fading out (duration in ticks)")
|
||||||
public static int TITLES_FADE_OUT = 20;
|
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
|
@Create // This value will be generated automatically
|
||||||
public static ConfigBlock<Auto_Clear> AUTO_CLEAR = null;
|
public static ConfigBlock<Auto_Clear> AUTO_CLEAR = null;
|
||||||
|
@ -303,8 +303,15 @@ public class PlotListener {
|
|||||||
Template plotTemplate = Template.of("plot", lastPlot.getId().toString());
|
Template plotTemplate = Template.of("plot", lastPlot.getId().toString());
|
||||||
Template worldTemplate = Template.of("world", player.getLocation().getWorldName());
|
Template worldTemplate = Template.of("world", player.getLocation().getWorldName());
|
||||||
Template ownerTemplate = Template.of("owner", owner);
|
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();
|
UUID uuid = plot.getOwner();
|
||||||
if (uuid == null) {
|
if (uuid == null) {
|
||||||
userConsumer.accept("Unknown");
|
userConsumer.accept("Unknown");
|
||||||
|
@ -841,6 +841,38 @@ public abstract class PlotPlayer<P> implements CommandCaller, OfflinePlotPlayer,
|
|||||||
.title(titleComponent, subtitleComponent, times));
|
.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
|
@Override
|
||||||
public void sendMessage(
|
public void sendMessage(
|
||||||
final @NonNull Caption caption,
|
final @NonNull Caption caption,
|
||||||
|
Loading…
Reference in New Issue
Block a user