mirror of
https://github.com/songoda/SongodaCore.git
synced 2024-12-12 11:46:45 +01:00
Fix chat messages become blank for players
This commit is contained in:
parent
af9e071ad8
commit
65e03a58ae
@ -10,17 +10,23 @@ import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
|||||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||||
|
import net.kyori.adventure.title.Title;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.time.temporal.ChronoUnit;
|
||||||
|
import java.time.temporal.TemporalUnit;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class AdventureUtils {
|
public class AdventureUtils {
|
||||||
private static Method displayNameMethod = null;
|
private static Method displayNameMethod = null;
|
||||||
@ -399,4 +405,57 @@ public class AdventureUtils {
|
|||||||
public static String clear(Component component) {
|
public static String clear(Component component) {
|
||||||
return PlainTextComponentSerializer.plainText().serialize(component);
|
return PlainTextComponentSerializer.plainText().serialize(component);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<Component> splitComponent(Component message, char c) {
|
||||||
|
List<Component> components = new ArrayList<>();
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
for (char character : toLegacy(message).toCharArray()) {
|
||||||
|
if (character == c) {
|
||||||
|
components.add(formatComponent(builder.toString()));
|
||||||
|
builder = new StringBuilder();
|
||||||
|
} else {
|
||||||
|
builder.append(character);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
components.add(formatComponent(builder.toString()));
|
||||||
|
return components;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Component formatPlaceholder(Component message, MiniMessagePlaceholder... placeholder) {
|
||||||
|
return AdventureUtils.formatComponent(AdventureUtils.replaceLegacy(AdventureUtils.toLegacy(message)), placeholder);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Bukkit defaults for time
|
||||||
|
public static Title createTitle (Component title, Component subtitle) {
|
||||||
|
return Title.title(title, subtitle, Title.Times.times(
|
||||||
|
Duration.of(10 * 50L, ChronoUnit.MILLIS),
|
||||||
|
Duration.of(70 * 50L, ChronoUnit.MILLIS),
|
||||||
|
Duration.of(20 * 50L, ChronoUnit.MILLIS)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
// times in ticks
|
||||||
|
public static Title createTitle (Component title, Component subtitle, int fadeIn, int stay, int fadeOut) {
|
||||||
|
return Title.title(title, subtitle, Title.Times.times(
|
||||||
|
Duration.of(fadeIn * 50L, ChronoUnit.MILLIS),
|
||||||
|
Duration.of(stay * 50L, ChronoUnit.MILLIS),
|
||||||
|
Duration.of(fadeOut * 50L, ChronoUnit.MILLIS)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Title createTitle(Component title, Component subtitle, Title.Times times) {
|
||||||
|
return Title.title(title, subtitle, times);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void sendTitle(JavaPlugin hijackedPlugin, Title title, CommandSender sender) {
|
||||||
|
try (BukkitAudiences bukkitAudiences = BukkitAudiences.create(hijackedPlugin)) {
|
||||||
|
bukkitAudiences.sender(sender).showTitle(title);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void sendActionBar(JavaPlugin hijackedPlugin, Component message, CommandSender sender) {
|
||||||
|
try (BukkitAudiences bukkitAudiences = BukkitAudiences.create(hijackedPlugin)) {
|
||||||
|
bukkitAudiences.sender(sender).sendActionBar(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,244 +0,0 @@
|
|||||||
package com.craftaro.core.chat;
|
|
||||||
|
|
||||||
import com.craftaro.core.SongodaCore;
|
|
||||||
import com.craftaro.core.SongodaPlugin;
|
|
||||||
import com.craftaro.core.compatibility.ClassMapping;
|
|
||||||
import com.craftaro.core.compatibility.ServerProject;
|
|
||||||
import com.craftaro.core.compatibility.ServerVersion;
|
|
||||||
import com.craftaro.core.nms.Nms;
|
|
||||||
import com.craftaro.core.utils.TextUtils;
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.google.gson.GsonBuilder;
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import net.minecraft.core.HolderLookup;
|
|
||||||
import net.minecraft.core.IRegistry;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
public class ChatMessage {
|
|
||||||
private static final Gson GSON = new GsonBuilder().create();
|
|
||||||
private final List<JsonObject> textList = new ArrayList<>();
|
|
||||||
|
|
||||||
public void clear() {
|
|
||||||
this.textList.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
public ChatMessage fromText(String text) {
|
|
||||||
return fromText(text, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ChatMessage fromText(String text, boolean noHex) {
|
|
||||||
Pattern pattern = Pattern.compile(
|
|
||||||
"(.*?)(?!&([omnlk]))(?=(&([123456789abcdefr#])|$)|#([a-f]|[A-F]|[0-9]){6})",
|
|
||||||
Pattern.CASE_INSENSITIVE);
|
|
||||||
Matcher matcher = pattern.matcher(text);
|
|
||||||
|
|
||||||
while (matcher.find()) {
|
|
||||||
ColorContainer color = null;
|
|
||||||
String match1 = matcher.group(1);
|
|
||||||
|
|
||||||
if (matcher.groupCount() == 0 || match1.isEmpty()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
char colorChar = '-';
|
|
||||||
|
|
||||||
if (matcher.start() != 0) {
|
|
||||||
colorChar = text.substring(matcher.start() - 1, matcher.start()).charAt(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (colorChar != '-') {
|
|
||||||
if (colorChar == '#') {
|
|
||||||
color = new ColorContainer(match1.substring(0, 6), noHex);
|
|
||||||
match1 = match1.substring(5);
|
|
||||||
} else if (colorChar == '&') {
|
|
||||||
color = new ColorContainer(ColorCode.getByChar(Character.toLowerCase(match1.charAt(0))));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Pattern subPattern = Pattern.compile("(.*?)(?=&([omnlk])|$)");
|
|
||||||
Matcher subMatcher = subPattern.matcher(match1);
|
|
||||||
|
|
||||||
List<ColorCode> stackedCodes = new ArrayList<>();
|
|
||||||
while (subMatcher.find()) {
|
|
||||||
String match2 = subMatcher.group(1);
|
|
||||||
if (match2.isEmpty()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
ColorCode code = ColorCode.getByChar(Character.toLowerCase(match2.charAt(0)));
|
|
||||||
|
|
||||||
if (code != null && code != ColorCode.RESET) {
|
|
||||||
stackedCodes.add(code);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (color != null) {
|
|
||||||
match2 = match2.substring(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!match2.isEmpty()) {
|
|
||||||
addMessage(match2, color, stackedCodes);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toText() {
|
|
||||||
return toText(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toText(boolean noHex) {
|
|
||||||
StringBuilder text = new StringBuilder();
|
|
||||||
|
|
||||||
for (JsonObject object : this.textList) {
|
|
||||||
if (object.has("color")) {
|
|
||||||
String color = object.get("color").getAsString();
|
|
||||||
text.append("&");
|
|
||||||
|
|
||||||
if (color.length() == 7) {
|
|
||||||
text.append(new ColorContainer(color, noHex).getColor().getCode());
|
|
||||||
} else {
|
|
||||||
text.append(ColorCode.valueOf(color.toUpperCase()).getCode());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (ColorCode code : ColorCode.values()) {
|
|
||||||
if (code.isColor()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
String c = code.name().toLowerCase();
|
|
||||||
if (object.has(c) && object.get(c).getAsBoolean()) {
|
|
||||||
text.append("&").append(code.getCode());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
text.append(object.get("text").getAsString());
|
|
||||||
}
|
|
||||||
|
|
||||||
return text.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public ChatMessage addMessage(String s) {
|
|
||||||
JsonObject txt = new JsonObject();
|
|
||||||
txt.addProperty("text", s);
|
|
||||||
|
|
||||||
this.textList.add(txt);
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ChatMessage addMessage(String text, ColorContainer color) {
|
|
||||||
return addMessage(text, color, Collections.emptyList());
|
|
||||||
}
|
|
||||||
|
|
||||||
public ChatMessage addMessage(String text, ColorContainer color, List<ColorCode> colorCodes) {
|
|
||||||
JsonObject txt = new JsonObject();
|
|
||||||
txt.addProperty("text", text);
|
|
||||||
|
|
||||||
if (color != null) {
|
|
||||||
txt.addProperty("color", color.getHexCode() != null ? "#" + color.getHexCode() : color.getColorCode().name().toLowerCase());
|
|
||||||
}
|
|
||||||
|
|
||||||
for (ColorCode code : ColorCode.values()) {
|
|
||||||
if (!code.isColor()) {
|
|
||||||
txt.addProperty(code.name().toLowerCase(), colorCodes.contains(code));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.textList.add(txt);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ChatMessage addRunCommand(String text, String hoverText, String cmd) {
|
|
||||||
JsonObject txt = new JsonObject();
|
|
||||||
txt.addProperty("text", text);
|
|
||||||
|
|
||||||
JsonObject hover = new JsonObject();
|
|
||||||
hover.addProperty("action", "show_text");
|
|
||||||
hover.addProperty("value", hoverText);
|
|
||||||
txt.add("hoverEvent", hover);
|
|
||||||
|
|
||||||
JsonObject click = new JsonObject();
|
|
||||||
click.addProperty("action", "run_command");
|
|
||||||
click.addProperty("value", cmd);
|
|
||||||
txt.add("clickEvent", click);
|
|
||||||
|
|
||||||
this.textList.add(txt);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ChatMessage addPromptCommand(String text, String hoverText, String cmd) {
|
|
||||||
JsonObject txt = new JsonObject();
|
|
||||||
txt.addProperty("text", text);
|
|
||||||
|
|
||||||
JsonObject hover = new JsonObject();
|
|
||||||
hover.addProperty("action", "show_text");
|
|
||||||
hover.addProperty("value", hoverText);
|
|
||||||
txt.add("hoverEvent", hover);
|
|
||||||
|
|
||||||
JsonObject click = new JsonObject();
|
|
||||||
click.addProperty("action", "suggest_command");
|
|
||||||
click.addProperty("value", cmd);
|
|
||||||
txt.add("clickEvent", click);
|
|
||||||
|
|
||||||
this.textList.add(txt);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ChatMessage addURL(String text, String hoverText, String url) {
|
|
||||||
JsonObject txt = new JsonObject();
|
|
||||||
txt.addProperty("text", text);
|
|
||||||
|
|
||||||
JsonObject hover = new JsonObject();
|
|
||||||
hover.addProperty("action", "show_text");
|
|
||||||
hover.addProperty("value", hoverText);
|
|
||||||
txt.add("hoverEvent", hover);
|
|
||||||
|
|
||||||
JsonObject click = new JsonObject();
|
|
||||||
click.addProperty("action", "open_url");
|
|
||||||
click.addProperty("value", url);
|
|
||||||
txt.add("clickEvent", hover);
|
|
||||||
|
|
||||||
this.textList.add(txt);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return GSON.toJson(this.textList);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void sendTo(CommandSender sender) {
|
|
||||||
sendTo(null, sender);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void sendTo(ChatMessage prefix, CommandSender sender) {
|
|
||||||
AdventureUtils.sendMessage(SongodaCore.getHijackedPlugin(), AdventureUtils.formatComponent(prefix == null ? "" : prefix.toText() + toText()), sender);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ChatMessage replaceAll(String toReplace, String replaceWith) {
|
|
||||||
for (JsonObject object : this.textList) {
|
|
||||||
String text = object.get("text").getAsString().replaceAll(toReplace, replaceWith);
|
|
||||||
|
|
||||||
object.remove("text");
|
|
||||||
object.addProperty("text", text);
|
|
||||||
}
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,6 +1,8 @@
|
|||||||
package com.craftaro.core.commands;
|
package com.craftaro.core.commands;
|
||||||
|
|
||||||
import com.craftaro.core.chat.ChatMessage;
|
import com.craftaro.core.SongodaCore;
|
||||||
|
import com.craftaro.core.chat.AdventureUtils;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.ConsoleCommandSender;
|
import org.bukkit.command.ConsoleCommandSender;
|
||||||
@ -60,9 +62,11 @@ public class MainCommand extends AbstractCommand {
|
|||||||
if (this.header != null) {
|
if (this.header != null) {
|
||||||
sender.sendMessage(this.header);
|
sender.sendMessage(this.header);
|
||||||
} else {
|
} else {
|
||||||
new ChatMessage().fromText(String.format("#ff8080&l%s &8» &7Version %s Created with <3 by #ec4e74&l&oS#fa5b65&l&oo#ff6c55&l&on#ff7f44&l&og#ff9432&l&oo#ffaa1e&l&od#f4c009&l&oa",
|
AdventureUtils.sendMessage(SongodaCore.getHijackedPlugin(), AdventureUtils.formatComponent(
|
||||||
this.plugin.getDescription().getName(), this.plugin.getDescription().getVersion()), sender instanceof ConsoleCommandSender)
|
String.format("<color:#ff8080>&l%s &8» &7Version %s Created with <3 by <b><i><gradient:#ec4e74:#f4c009>Songoda</gradient>",
|
||||||
.sendTo(sender);
|
this.plugin.getDescription().getName(),
|
||||||
|
this.plugin.getDescription().getVersion()
|
||||||
|
)), sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
sender.sendMessage(ChatColor.DARK_GRAY + "- " + ChatColor.YELLOW + "/songoda" + ChatColor.GRAY + " - Opens the Songoda plugin GUI");
|
sender.sendMessage(ChatColor.DARK_GRAY + "- " + ChatColor.YELLOW + "/songoda" + ChatColor.GRAY + " - Opens the Songoda plugin GUI");
|
||||||
@ -85,12 +89,16 @@ public class MainCommand extends AbstractCommand {
|
|||||||
if (!isPlayer) {
|
if (!isPlayer) {
|
||||||
sender.sendMessage(ChatColor.DARK_GRAY + "- " + ChatColor.YELLOW + cmd.getSyntax() + ChatColor.GRAY + " - " + cmd.getDescription());
|
sender.sendMessage(ChatColor.DARK_GRAY + "- " + ChatColor.YELLOW + cmd.getSyntax() + ChatColor.GRAY + " - " + cmd.getDescription());
|
||||||
} else if (cmd.getPermissionNode() == null || sender.hasPermission(cmd.getPermissionNode())) {
|
} else if (cmd.getPermissionNode() == null || sender.hasPermission(cmd.getPermissionNode())) {
|
||||||
ChatMessage chatMessage = new ChatMessage();
|
String command = "/" + this.command + " ";
|
||||||
final String command = "/" + this.command + " ";
|
Component component = AdventureUtils.formatComponent(
|
||||||
chatMessage.addMessage(ChatColor.DARK_GRAY + "- ")
|
String.format("<DARK_GRAY>- <YELLOW>%s%s <GRAY>- %s %s",
|
||||||
.addPromptCommand(ChatColor.YELLOW + command + cmd.getSyntax(), ChatColor.YELLOW + command + cmdStr, command + cmdStr)
|
command,
|
||||||
.addMessage(ChatColor.GRAY + " - " + cmd.getDescription());
|
cmd.getSyntax(),
|
||||||
chatMessage.sendTo(sender);
|
cmd.getDescription(),
|
||||||
|
cmd.getPermissionNode() == null ? "" : cmd.getPermissionNode()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
AdventureUtils.sendMessage(SongodaCore.getHijackedPlugin(), component, sender);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,12 @@
|
|||||||
package com.craftaro.core.locale;
|
package com.craftaro.core.locale;
|
||||||
|
|
||||||
import com.craftaro.core.chat.ChatMessage;
|
import com.craftaro.core.SongodaCore;
|
||||||
|
import com.craftaro.core.chat.AdventureUtils;
|
||||||
|
import com.craftaro.core.chat.MiniMessagePlaceholder;
|
||||||
import com.craftaro.core.compatibility.ServerVersion;
|
import com.craftaro.core.compatibility.ServerVersion;
|
||||||
import com.craftaro.core.utils.TextUtils;
|
import com.craftaro.core.utils.TextUtils;
|
||||||
|
import net.kyori.adventure.Adventure;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -30,8 +34,8 @@ public class Message {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ChatMessage prefix = null;
|
private Component prefix = null;
|
||||||
private ChatMessage message;
|
private Component message;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* create a new message
|
* create a new message
|
||||||
@ -39,19 +43,7 @@ public class Message {
|
|||||||
* @param message the message text
|
* @param message the message text
|
||||||
*/
|
*/
|
||||||
public Message(String message) {
|
public Message(String message) {
|
||||||
ChatMessage chatMessage = new ChatMessage();
|
this.message = AdventureUtils.formatComponent(message);
|
||||||
chatMessage.fromText(message);
|
|
||||||
|
|
||||||
this.message = chatMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* create a new message
|
|
||||||
*
|
|
||||||
* @param message the message text
|
|
||||||
*/
|
|
||||||
public Message(ChatMessage message) {
|
|
||||||
this.message = message;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -60,7 +52,7 @@ public class Message {
|
|||||||
* @param player player to send the message to
|
* @param player player to send the message to
|
||||||
*/
|
*/
|
||||||
public void sendMessage(Player player) {
|
public void sendMessage(Player player) {
|
||||||
player.sendMessage(this.getMessage());
|
sendMessage((CommandSender) player);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -69,7 +61,7 @@ public class Message {
|
|||||||
* @param sender command sender to send the message to
|
* @param sender command sender to send the message to
|
||||||
*/
|
*/
|
||||||
public void sendMessage(CommandSender sender) {
|
public void sendMessage(CommandSender sender) {
|
||||||
this.message.sendTo(sender);
|
AdventureUtils.sendMessage(SongodaCore.getHijackedPlugin(), this.message, sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -80,16 +72,16 @@ public class Message {
|
|||||||
public void sendTitle(CommandSender sender) {
|
public void sendTitle(CommandSender sender) {
|
||||||
if (sender instanceof Player) {
|
if (sender instanceof Player) {
|
||||||
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_11)) {
|
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_11)) {
|
||||||
((Player) sender).sendTitle("", getMessage(), 10, 30, 10);
|
AdventureUtils.sendTitle(SongodaCore.getHijackedPlugin(), AdventureUtils.createTitle(Component.empty(), getMessage(), 10, 30, 10), sender);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
((Player) sender).sendTitle("", getMessage());
|
AdventureUtils.sendTitle(SongodaCore.getHijackedPlugin(), AdventureUtils.createTitle(Component.empty(), getMessage()), sender);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
sender.sendMessage(this.getMessage());
|
AdventureUtils.sendMessage(SongodaCore.getHijackedPlugin(), this.message, sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -99,7 +91,7 @@ public class Message {
|
|||||||
*/
|
*/
|
||||||
public void sendActionBar(CommandSender sender) {
|
public void sendActionBar(CommandSender sender) {
|
||||||
if (!(sender instanceof Player)) {
|
if (!(sender instanceof Player)) {
|
||||||
sender.sendMessage(this.getMessage());
|
AdventureUtils.sendMessage(SongodaCore.getHijackedPlugin(), this.message, sender);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,8 +100,7 @@ public class Message {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
((Player) sender).spigot().sendMessage(net.md_5.bungee.api.ChatMessageType.ACTION_BAR,
|
AdventureUtils.sendActionBar(SongodaCore.getHijackedPlugin(), getMessage(), sender);
|
||||||
new net.md_5.bungee.api.chat.TextComponent(getMessage()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -119,7 +110,7 @@ public class Message {
|
|||||||
* @param sender command sender to send the message to
|
* @param sender command sender to send the message to
|
||||||
*/
|
*/
|
||||||
public void sendPrefixedMessage(CommandSender sender) {
|
public void sendPrefixedMessage(CommandSender sender) {
|
||||||
this.message.sendTo(this.prefix, sender);
|
AdventureUtils.sendMessage(SongodaCore.getHijackedPlugin(), this.prefix.append(this.message), sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -128,8 +119,8 @@ public class Message {
|
|||||||
*
|
*
|
||||||
* @return the prefixed message
|
* @return the prefixed message
|
||||||
*/
|
*/
|
||||||
public String getPrefixedMessage() {
|
public Component getPrefixedMessage() {
|
||||||
return TextUtils.formatText((this.prefix == null ? "" : this.prefix.toText()) + " " + this.message.toText());
|
return this.prefix.append(this.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -137,8 +128,8 @@ public class Message {
|
|||||||
*
|
*
|
||||||
* @return the message
|
* @return the message
|
||||||
*/
|
*/
|
||||||
public String getMessage() {
|
public Component getMessage() {
|
||||||
return TextUtils.formatText(this.message.toText());
|
return this.message;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -146,17 +137,9 @@ public class Message {
|
|||||||
*
|
*
|
||||||
* @return the message
|
* @return the message
|
||||||
*/
|
*/
|
||||||
public List<String> getMessageLines() {
|
public List<Component> getMessageLines() {
|
||||||
return Arrays.asList(ChatColor.translateAlternateColorCodes('&', this.message.toText()).split("[\n|]"));
|
//return Arrays.asList(ChatColor.translateAlternateColorCodes('&', this.message.toText()).split("[\n|]"));
|
||||||
}
|
return AdventureUtils.splitComponent(this.message, '\n');
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the held message
|
|
||||||
*
|
|
||||||
* @return the message
|
|
||||||
*/
|
|
||||||
public String getUnformattedMessage() {
|
|
||||||
return this.message.toText();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -169,25 +152,23 @@ public class Message {
|
|||||||
* @return the modified Message
|
* @return the modified Message
|
||||||
*/
|
*/
|
||||||
public Message processPlaceholder(String placeholder, Object replacement) {
|
public Message processPlaceholder(String placeholder, Object replacement) {
|
||||||
final String place = Matcher.quoteReplacement(placeholder);
|
MiniMessagePlaceholder placeholderProcessor = new MiniMessagePlaceholder(placeholder, replacement == null ? "" : replacement.toString());
|
||||||
this.message = this.message.replaceAll("%" + place + "%|\\{" + place + "\\}", replacement == null ? "" : Matcher.quoteReplacement(replacement.toString()));
|
this.message = AdventureUtils.formatPlaceholder(this.message, placeholderProcessor);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Message setPrefix(String prefix) {
|
Message setPrefix(String prefix) {
|
||||||
this.prefix = new ChatMessage();
|
this.prefix = AdventureUtils.formatComponent(prefix + " ");
|
||||||
this.prefix.fromText(prefix + " ");
|
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return this.message.toString();
|
return AdventureUtils.toLegacy(this.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toText() {
|
public String toText() {
|
||||||
return this.message.toText();
|
return AdventureUtils.toLegacy(this.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user