Skip to content

Commit d36ce32

Browse files
committed
fix [item]
1 parent 430b7b3 commit d36ce32

File tree

4 files changed

+25
-19
lines changed

4 files changed

+25
-19
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ plugins {
88

99
group = 'org.parallelmc'
1010

11-
version = '2.6.5'
11+
version = '2.6.6'
1212
description = 'A set of utilities and features for use on the Parallel Minecraft server'
1313

1414
java {

src/main/java/parallelmc/parallelutils/Constants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
public class Constants {
44

5-
public static final Version VERSION = new Version(2, 6, 5);
5+
public static final Version VERSION = new Version(2, 6, 6);
66
public static final String PLUGIN_NAME = "ParallelUtils";
77
public static final String DEFAULT_WORLD = "world2";
88
}

src/main/java/parallelmc/parallelutils/modules/parallelchat/ParallelChat.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.bukkit.configuration.file.FileConfiguration;
1717
import org.bukkit.configuration.file.YamlConfiguration;
1818
import org.bukkit.entity.Player;
19+
import org.bukkit.inventory.ItemStack;
1920
import org.bukkit.plugin.Plugin;
2021
import org.bukkit.plugin.PluginManager;
2122
import org.jetbrains.annotations.NotNull;
@@ -397,7 +398,7 @@ public Component formatForGroup(@NotNull Player source, @NotNull Component displ
397398
PlaceholderAPI.setPlaceholders(source, "%pronouns_pronouns%")).asHoverEvent())),
398399
Placeholder.component("tag", getTagForPlayer(source)),
399400
Placeholder.component("donorrank", getDonorRankForPlayer(source)),
400-
Placeholder.component("message", LegacyComponentSerializer.legacyAmpersand().deserialize(LegacyComponentSerializer.legacyAmpersand().serialize(message)))
401+
Placeholder.component("message", message)
401402
);
402403

403404
if (isUsingDefault) {

src/main/java/parallelmc/parallelutils/modules/parallelchat/events/OnChatMessage.java

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@
22

33
import io.papermc.paper.chat.ChatRenderer;
44
import io.papermc.paper.event.player.AsyncChatEvent;
5+
import me.clip.placeholderapi.PlaceholderAPI;
56
import net.kyori.adventure.text.Component;
7+
import net.kyori.adventure.text.ComponentBuilder;
68
import net.kyori.adventure.text.TextComponent;
79
import net.kyori.adventure.text.minimessage.MiniMessage;
810
import net.kyori.adventure.text.format.NamedTextColor;
11+
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
12+
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
913
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
14+
import net.minecraft.network.chat.HoverEvent;
1015
import org.bukkit.Material;
1116
import org.bukkit.Server;
1217
import org.bukkit.Sound;
@@ -166,20 +171,6 @@ public void onChatMessage(AsyncChatEvent event) {
166171
}
167172

168173

169-
// Item chat
170-
ItemStack item = player.getInventory().getItemInMainHand();
171-
172-
if (item.getType() != Material.AIR) {
173-
Component itemName = item.displayName().hoverEvent(item.asHoverEvent());
174-
175-
TextComponent itemComponent = Component.text()
176-
.append(itemName)
177-
.append(Component.text(" x" + item.getAmount(), item.displayName().color()))
178-
.build();
179-
180-
event.message(event.message().replaceText(x -> x.once().match("\\[item\\]").replacement(itemComponent)));
181-
}
182-
183174
// remove dnd players from the recipient list if they have not been mentioned
184175
// also show the message to the player if they send it
185176
event.viewers().removeAll(ParallelChat.dndPlayers.keySet()
@@ -189,8 +180,22 @@ public void onChatMessage(AsyncChatEvent event) {
189180
.collect(Collectors.toSet()));
190181

191182
// re-render the formatted message and send it
192-
event.renderer(ChatRenderer.viewerUnaware((source, sourceDisplayName, message)
193-
-> ParallelChat.get().formatForGroup(source, sourceDisplayName, message)));
183+
event.renderer(ChatRenderer.viewerUnaware((source, sourceDisplayName, message) ->
184+
{
185+
message = LegacyComponentSerializer.legacyAmpersand().deserialize(LegacyComponentSerializer.legacyAmpersand().serialize(message));
186+
// Item chat
187+
ItemStack item = player.getInventory().getItemInMainHand();
188+
189+
if (item.getType() != Material.AIR) {
190+
TextComponent itemComponent = Component.text()
191+
.append(item.displayName().hoverEvent(item.asHoverEvent()))
192+
.append(Component.text(" x" + item.getAmount(), item.displayName().color()))
193+
.build();
194+
195+
message = message.replaceText(x -> x.once().match("\\[item\\]").replacement(itemComponent));
196+
}
197+
return ParallelChat.get().formatForGroup(source, sourceDisplayName, message);
198+
}));
194199
// not sure if this is necessary but I don't want to touch it
195200
event.message(event.message());
196201
}

0 commit comments

Comments
 (0)