This commit is contained in:
parent
49c6139d99
commit
799833b685
2 changed files with 34 additions and 17 deletions
|
@ -14,32 +14,32 @@ import net.md_5.bungee.api.chat.hover.content.Text;
|
|||
import org.bukkit.entity.Player;
|
||||
|
||||
public class ChatFormatUtils {
|
||||
public static BaseComponent[] formatPlayer(Player player) {
|
||||
public static BaseComponent formatPlayer(Player player) {
|
||||
ChatColor nameColor = ChatColor.of("#" + Integer.toHexString(player.getName().hashCode()).substring(0, 6));
|
||||
|
||||
if (player.getCustomName() != null) {
|
||||
return new ComponentBuilder()
|
||||
.append("~" + player.getCustomName()).color(nameColor)
|
||||
.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(player.getName())))
|
||||
.create();
|
||||
.build();
|
||||
} else {
|
||||
return new ComponentBuilder()
|
||||
.append(player.getName()).color(nameColor)
|
||||
.create();
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
public static BaseComponent[] chatRoomPrefixShort(ChatRoom chatRoom) {
|
||||
public static BaseComponent chatRoomPrefixShort(ChatRoom chatRoom) {
|
||||
ChatColor prefixColor = ChatColor.of(chatRoom.color.getColor().darker());
|
||||
|
||||
return new ComponentBuilder(chatRoom.id.charAt(0) + " ").color(prefixColor)
|
||||
.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(chatRoom.getInfoComponent())))
|
||||
.create();
|
||||
.build();
|
||||
}
|
||||
|
||||
public static BaseComponent[] formatChatRoom(ChatRoom chatRoom) {
|
||||
public static BaseComponent formatChatRoom(ChatRoom chatRoom) {
|
||||
return new ComponentBuilder(chatRoom.id).color(chatRoom.color)
|
||||
.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(chatRoom.getInfoComponent())))
|
||||
.create();
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,11 @@ import eu.m724.tweaks.TweaksConfig;
|
|||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.TranslatableComponent;
|
||||
import net.md_5.bungee.chat.ComponentSerializer;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import org.bukkit.craftbukkit.v1_21_R1.CraftRegistry;
|
||||
import org.bukkit.craftbukkit.v1_21_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
@ -39,11 +44,9 @@ public class ChatListener implements Listener {
|
|||
|
||||
if (localEvents) {
|
||||
chatRoom.broadcast(
|
||||
new ComponentBuilder()
|
||||
.append(ChatFormatUtils.chatRoomPrefixShort(chatRoom))
|
||||
.append(ChatFormatUtils.formatPlayer(player))
|
||||
.append(" has joined the server").color(ChatColor.GREEN)
|
||||
.create()
|
||||
new ComponentBuilder(ChatFormatUtils.chatRoomPrefixShort(chatRoom))
|
||||
.append(new TranslatableComponent("multiplayer.player.joined", ChatFormatUtils.formatPlayer(player))).color(ChatColor.GREEN)
|
||||
.create()
|
||||
);
|
||||
|
||||
// remove Minecraft join message
|
||||
|
@ -58,10 +61,8 @@ public class ChatListener implements Listener {
|
|||
|
||||
if (localEvents) {
|
||||
chatRoom.broadcast(
|
||||
new ComponentBuilder()
|
||||
.append(ChatFormatUtils.chatRoomPrefixShort(chatRoom))
|
||||
.append(ChatFormatUtils.formatPlayer(player))
|
||||
.append(" has left the server").color(ChatColor.RED)
|
||||
new ComponentBuilder(ChatFormatUtils.chatRoomPrefixShort(chatRoom))
|
||||
.append(new TranslatableComponent("multiplayer.player.left", ChatFormatUtils.formatPlayer(player))).color(ChatColor.RED)
|
||||
.create()
|
||||
);
|
||||
|
||||
|
@ -76,13 +77,29 @@ public class ChatListener implements Listener {
|
|||
Player player = event.getEntity();
|
||||
ChatRoom chatRoom = chatManager.getPlayerChatRoom(player);
|
||||
|
||||
// would be easier on Paper but this is not Paper
|
||||
BaseComponent deathMessage = ComponentSerializer.deserialize(Component.Serializer.toJson(((CraftPlayer)player).getHandle().getCombatTracker().getDeathMessage(), CraftRegistry.getMinecraftRegistry()));
|
||||
|
||||
// TODO make players ChatFormatUtils
|
||||
|
||||
chatRoom.broadcast(
|
||||
new ComponentBuilder()
|
||||
.append(ChatFormatUtils.chatRoomPrefixShort(chatRoom))
|
||||
.append(event.getDeathMessage())
|
||||
.append(deathMessage)
|
||||
.create()
|
||||
);
|
||||
|
||||
// broadcast to killer if available
|
||||
if (player.getLastDamageCause().getDamageSource().getCausingEntity() instanceof Player killer) {
|
||||
ChatRoom chatRoom2 = chatManager.getPlayerChatRoom(killer);
|
||||
chatRoom2.broadcast(
|
||||
new ComponentBuilder()
|
||||
.append(ChatFormatUtils.chatRoomPrefixShort(chatRoom2))
|
||||
.append(deathMessage)
|
||||
.create()
|
||||
);
|
||||
}
|
||||
|
||||
// remove Minecraft death message
|
||||
event.setDeathMessage(null);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue