mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2025-01-07 07:37:35 +01:00
Add support for component bungee messages
Requires at least BungeeCord commit a64c34d
This commit is contained in:
parent
98985efd63
commit
742f838f09
@ -525,6 +525,18 @@ public class MaterialUtil {
|
||||
* @param stock The items in stock
|
||||
*/
|
||||
public static boolean sendMessage(Player player, Messages.Message message, ItemStack[] stock, Map<String, String> replacementMap, String... replacements) {
|
||||
return sendMessage(player, player.getName(), message, stock, replacementMap, replacements);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message with hover info and icons
|
||||
*
|
||||
* @param player The player to send the message to
|
||||
* @param playerName The name of the player in case he is offline and bungee messages are enabled
|
||||
* @param message The raw message
|
||||
* @param stock The items in stock
|
||||
*/
|
||||
public static boolean sendMessage(Player player, String playerName, Messages.Message message, ItemStack[] stock, Map<String, String> replacementMap, String... replacements) {
|
||||
if (showItem == null) {
|
||||
return false;
|
||||
}
|
||||
@ -543,31 +555,19 @@ public class MaterialUtil {
|
||||
|
||||
Map<String, String> newMap = new LinkedHashMap<>(replacementMap);
|
||||
newMap.put("material", "item");
|
||||
BaseComponent[] components = message.getComponents(player, true, newMap, replacements);
|
||||
player.spigot().sendMessage(new Replacer()
|
||||
BaseComponent[] components = new Replacer()
|
||||
.placeholderSuffix("")
|
||||
.replace("item", ComponentSerializer.parse("[" + joinedItemJson + "]"))
|
||||
.replaceIn(components));
|
||||
|
||||
/*
|
||||
String prevColor = "";
|
||||
List<String> parts = new ArrayList<>();
|
||||
for (String s : message.split("%item")) {
|
||||
parts.add(new JSONObject(ImmutableMap.of("text", prevColor + s)).toJSONString());
|
||||
prevColor = ChatColor.getLastColors(s);
|
||||
.replaceIn(message.getComponents(player, true, newMap, replacements));
|
||||
if (player != null) {
|
||||
player.spigot().sendMessage(components);
|
||||
return true;
|
||||
} else if (playerName != null) {
|
||||
ChestShop.sendBungeeMessage(playerName, components);
|
||||
return true;
|
||||
}
|
||||
|
||||
String messageJsonString = String.join("," + joinedItemJson + ",", parts);
|
||||
|
||||
while (messageJsonString.startsWith(",")) {
|
||||
messageJsonString = messageJsonString.substring(1);
|
||||
}
|
||||
while (messageJsonString.endsWith(",")) {
|
||||
messageJsonString = messageJsonString.substring(0, messageJsonString.length() - 1);
|
||||
}
|
||||
|
||||
showItem.tellRaw(player, messageJsonString);
|
||||
*/return true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -46,6 +46,8 @@ import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.chat.ComponentSerializer;
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Marker;
|
||||
@ -519,14 +521,21 @@ public class ChestShop extends JavaPlugin {
|
||||
}
|
||||
|
||||
public static void sendBungeeMessage(String playerName, Messages.Message message, Map<String, String> replacementMap, String... replacements) {
|
||||
// TODO: Component support for bungee messages?
|
||||
sendBungeeMessage(playerName, message.getTextWithPrefix(null, replacementMap, replacements));
|
||||
sendBungeeMessage(playerName, message.getComponents(null, true, replacementMap, replacements));
|
||||
}
|
||||
|
||||
public static void sendBungeeMessage(String playerName, String message) {
|
||||
sendBungeeMessage(playerName, "Message", message);
|
||||
}
|
||||
|
||||
public static void sendBungeeMessage(String playerName, BaseComponent[] message) {
|
||||
sendBungeeMessage(playerName, "MessageRaw", ComponentSerializer.toString(message));
|
||||
}
|
||||
|
||||
private static void sendBungeeMessage(String playerName, String channel, String message) {
|
||||
if (Properties.BUNGEECORD_MESSAGES && !Bukkit.getOnlinePlayers().isEmpty()) {
|
||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
out.writeUTF("Message");
|
||||
out.writeUTF(channel);
|
||||
out.writeUTF(playerName);
|
||||
out.writeUTF(message);
|
||||
|
||||
|
@ -70,10 +70,11 @@ public class TransactionMessageSender implements Listener {
|
||||
replacementMap.put(replacements[i], replacements[i + 1]);
|
||||
}
|
||||
|
||||
if (Properties.SHOWITEM_MESSAGE && MaterialUtil.Show.sendMessage(player, playerName, rawMessage, event.getStock(), replacementMap)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (player != null) {
|
||||
if (Properties.SHOWITEM_MESSAGE && MaterialUtil.Show.sendMessage(player, rawMessage, event.getStock(), replacementMap)) {
|
||||
return;
|
||||
}
|
||||
replacementMap.put("item", MaterialUtil.getItemList(event.getStock()));
|
||||
rawMessage.sendWithPrefix(player, replacementMap);
|
||||
} else if (playerName != null) {
|
||||
|
Loading…
Reference in New Issue
Block a user