Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ 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("Show the plot titles as an actionbar?")
public static boolean TITLES_AS_ACTIONBAR = false;

@Create // This value will be generated automatically
public static ConfigBlock<Auto_Clear> AUTO_CLEAR = null;
Expand Down
13 changes: 11 additions & 2 deletions Core/src/main/java/com/plotsquared/core/listener/PlotListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,17 @@ public boolean plotEntry(final PlotPlayer<?> player, final Plot plot) {
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);

Consumer<String> userConsumer;

if (Settings.TITLES_AS_ACTIONBAR) {
userConsumer = user -> player.sendPlotEntryBar(header, subHeader, plotTemplate, worldTemplate,
ownerTemplate);
} else {
userConsumer = user -> player
.sendTitle(header, subHeader, plotTemplate, worldTemplate, ownerTemplate);
}

UUID uuid = plot.getOwner();
if (uuid == null) {
userConsumer.accept("Unknown");
Expand Down
22 changes: 22 additions & 0 deletions Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import com.sk89q.worldedit.world.item.ItemType;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.Template;
import net.kyori.adventure.title.Title;
Expand Down Expand Up @@ -841,6 +842,27 @@ public void sendTitle(
.title(titleComponent, subtitleComponent, times));
}

/**
* Sends an actionbar to the player on plot entry.
* This takes in two captions as it will internally merge
* the captions together to send as a single component.
NotMyFault marked this conversation as resolved.
Show resolved Hide resolved
*
* @param header Header
* @param subHeader Subheader
* @param replacements Variable replacements
*/
public void sendPlotEntryBar(
darbyjack marked this conversation as resolved.
Show resolved Hide resolved
final @NonNull Caption header, final @NonNull Caption subHeader,
final @NonNull Template... replacements
) {
final Component titleComponent = MiniMessage.get().parse(header.getComponent(this), replacements);
final Component subtitleComponent =
MiniMessage.get().parse(subHeader.getComponent(this), replacements);

getAudience().sendActionBar(
titleComponent.append(Component.text(" | ").color(NamedTextColor.GRAY)).append(subtitleComponent));
}

@Override
public void sendMessage(
final @NonNull Caption caption,
Expand Down