mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-03 22:16:34 +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;
|
package net.william278.huskhomes.player;
|
||||||
|
|
||||||
import de.themoep.minedown.MineDown;
|
import de.themoep.minedown.MineDown;
|
||||||
|
import de.themoep.minedown.MineDownParser;
|
||||||
import io.papermc.lib.PaperLib;
|
import io.papermc.lib.PaperLib;
|
||||||
import net.md_5.bungee.api.ChatMessageType;
|
import net.md_5.bungee.api.ChatMessageType;
|
||||||
import net.md_5.bungee.api.chat.BaseComponent;
|
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.md_5.bungee.api.chat.TranslatableComponent;
|
||||||
import net.william278.huskhomes.BukkitHuskHomes;
|
import net.william278.huskhomes.BukkitHuskHomes;
|
||||||
import net.william278.huskhomes.HuskHomesException;
|
import net.william278.huskhomes.HuskHomesException;
|
||||||
@@ -92,14 +94,26 @@ public class BukkitPlayer extends OnlineUser {
|
|||||||
PermissionAttachmentInfo::getValue, (a, b) -> b));
|
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
|
@Override
|
||||||
public void sendActionBar(@NotNull MineDown mineDown) {
|
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
|
@Override
|
||||||
public void sendMessage(@NotNull MineDown mineDown) {
|
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) {
|
if (messageComponents.length == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package net.william278.huskhomes.config;
|
package net.william278.huskhomes.config;
|
||||||
|
|
||||||
import de.themoep.minedown.MineDown;
|
import de.themoep.minedown.MineDown;
|
||||||
import de.themoep.minedown.Util;
|
|
||||||
import net.william278.annotaml.RootedMap;
|
import net.william278.annotaml.RootedMap;
|
||||||
import net.william278.annotaml.YamlFile;
|
import net.william278.annotaml.YamlFile;
|
||||||
import org.apache.commons.text.StringEscapeUtils;
|
import org.apache.commons.text.StringEscapeUtils;
|
||||||
@@ -111,8 +110,7 @@ public class Locales {
|
|||||||
boolean isEscape = c == '\\';
|
boolean isEscape = c == '\\';
|
||||||
boolean isColorCode = i + 1 < string.length() && (c == 167 || c == '&');
|
boolean isColorCode = i + 1 < string.length() && (c == 167 || c == '&');
|
||||||
boolean isEvent = c == '[' || c == ']' || c == '(' || c == ')';
|
boolean isEvent = c == '[' || c == ']' || c == '(' || c == ')';
|
||||||
boolean isFormatting = (c == '_' || c == '*' || c == '~' || c == '?' || c == '#') && Util.isDouble(string, i);
|
if (isEscape || isColorCode || isEvent) {
|
||||||
if (isEscape || isColorCode || isEvent || isFormatting) {
|
|
||||||
value.append('\\');
|
value.append('\\');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -281,7 +281,8 @@ public class Settings {
|
|||||||
public enum MessageDisplayType {
|
public enum MessageDisplayType {
|
||||||
MESSAGE,
|
MESSAGE,
|
||||||
ACTION_BAR,
|
ACTION_BAR,
|
||||||
SUBTITLE
|
SUBTITLE,
|
||||||
|
TITLE
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -57,6 +57,14 @@ public abstract class OnlineUser extends User {
|
|||||||
@NotNull
|
@NotNull
|
||||||
public abstract Map<String, Boolean> getPermissions();
|
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
|
* Dispatch a MineDown-formatted action bar message to this player
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -415,6 +415,8 @@ public class TeleportManager {
|
|||||||
.ifPresent(message -> {
|
.ifPresent(message -> {
|
||||||
switch (plugin.getSettings().teleportWarmupDisplay) {
|
switch (plugin.getSettings().teleportWarmupDisplay) {
|
||||||
case ACTION_BAR -> teleport.getPlayer().sendActionBar(message);
|
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);
|
case MESSAGE -> teleport.getPlayer().sendMessage(message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -423,6 +425,8 @@ public class TeleportManager {
|
|||||||
.ifPresent(message -> {
|
.ifPresent(message -> {
|
||||||
switch (plugin.getSettings().teleportWarmupDisplay) {
|
switch (plugin.getSettings().teleportWarmupDisplay) {
|
||||||
case ACTION_BAR -> teleport.getPlayer().sendActionBar(message);
|
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);
|
case MESSAGE -> teleport.getPlayer().sendMessage(message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in new issue
Block a user