mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-01 22:16:08 +00:00
Add TITLE and SUBTITLE warmup display options, stop parsing simple inline MineDown formatting, close #210
This commit is contained in:
1 parent
f80261d919
commit
41ce426480
5 files changed
+31
-6
No files matched your search
@@ -1,9 +1,11 @@
|
||||
package net.william278.huskhomes.player;
|
||||
|
||||
import de.themoep.minedown.MineDown;
|
||||
import de.themoep.minedown.MineDownParser;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.chat.TranslatableComponent;
|
||||
import net.william278.huskhomes.BukkitHuskHomes;
|
||||
import net.william278.huskhomes.HuskHomesException;
|
||||
@@ -92,14 +94,26 @@ public class BukkitPlayer extends OnlineUser {
|
||||
PermissionAttachmentInfo::getValue, (a, b) -> b));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendTitle(@NotNull MineDown mineDown, boolean subTitle) {
|
||||
final String legacyText = TextComponent.toLegacyText(mineDown
|
||||
.disable(MineDownParser.Option.SIMPLE_FORMATTING)
|
||||
.replace().toComponent());
|
||||
player.sendTitle(subTitle ? "" : legacyText, subTitle ? legacyText : "", 10, 70, 20);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendActionBar(@NotNull MineDown mineDown) {
|
||||
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, mineDown.replace().toComponent());
|
||||
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, mineDown
|
||||
.disable(MineDownParser.Option.SIMPLE_FORMATTING)
|
||||
.replace().toComponent());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(@NotNull MineDown mineDown) {
|
||||
final BaseComponent[] messageComponents = mineDown.replace().toComponent();
|
||||
final BaseComponent[] messageComponents = mineDown
|
||||
.disable(MineDownParser.Option.SIMPLE_FORMATTING)
|
||||
.replace().toComponent();
|
||||
if (messageComponents.length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package net.william278.huskhomes.config;
|
||||
|
||||
import de.themoep.minedown.MineDown;
|
||||
import de.themoep.minedown.Util;
|
||||
import net.william278.annotaml.RootedMap;
|
||||
import net.william278.annotaml.YamlFile;
|
||||
import org.apache.commons.text.StringEscapeUtils;
|
||||
@@ -111,8 +110,7 @@ public class Locales {
|
||||
boolean isEscape = c == '\\';
|
||||
boolean isColorCode = i + 1 < string.length() && (c == 167 || c == '&');
|
||||
boolean isEvent = c == '[' || c == ']' || c == '(' || c == ')';
|
||||
boolean isFormatting = (c == '_' || c == '*' || c == '~' || c == '?' || c == '#') && Util.isDouble(string, i);
|
||||
if (isEscape || isColorCode || isEvent || isFormatting) {
|
||||
if (isEscape || isColorCode || isEvent) {
|
||||
value.append('\\');
|
||||
}
|
||||
|
||||
|
||||
@@ -281,7 +281,8 @@ public class Settings {
|
||||
public enum MessageDisplayType {
|
||||
MESSAGE,
|
||||
ACTION_BAR,
|
||||
SUBTITLE
|
||||
SUBTITLE,
|
||||
TITLE
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -57,6 +57,14 @@ public abstract class OnlineUser extends User {
|
||||
@NotNull
|
||||
public abstract Map<String, Boolean> getPermissions();
|
||||
|
||||
/**
|
||||
* Dispatch a MineDown-formatted title or subtitle to the player
|
||||
*
|
||||
* @param mineDown the parsed {@link MineDown} to send
|
||||
* @param subTitle whether to send the title as a subtitle ({@code true} for a subtitle, {@code false} for a title)
|
||||
*/
|
||||
public abstract void sendTitle(@NotNull MineDown mineDown, boolean subTitle);
|
||||
|
||||
/**
|
||||
* Dispatch a MineDown-formatted action bar message to this player
|
||||
*
|
||||
|
||||
@@ -415,6 +415,8 @@ public class TeleportManager {
|
||||
.ifPresent(message -> {
|
||||
switch (plugin.getSettings().teleportWarmupDisplay) {
|
||||
case ACTION_BAR -> teleport.getPlayer().sendActionBar(message);
|
||||
case SUBTITLE -> teleport.getPlayer().sendTitle(message, true);
|
||||
case TITLE -> teleport.getPlayer().sendTitle(message, false);
|
||||
case MESSAGE -> teleport.getPlayer().sendMessage(message);
|
||||
}
|
||||
});
|
||||
@@ -423,6 +425,8 @@ public class TeleportManager {
|
||||
.ifPresent(message -> {
|
||||
switch (plugin.getSettings().teleportWarmupDisplay) {
|
||||
case ACTION_BAR -> teleport.getPlayer().sendActionBar(message);
|
||||
case SUBTITLE -> teleport.getPlayer().sendTitle(message, true);
|
||||
case TITLE -> teleport.getPlayer().sendTitle(message, false);
|
||||
case MESSAGE -> teleport.getPlayer().sendMessage(message);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user