mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-30 13:08:19 +01:00
Merge pull request #5 from Draycia/master
Replace minecraft-text with kyori-text
This commit is contained in:
commit
ca7e220543
@ -11,7 +11,6 @@ sourceCompatibility = 1.11
|
|||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
maven { url 'https://jitpack.io' }
|
maven { url 'https://jitpack.io' }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -33,7 +32,6 @@ dependencies {
|
|||||||
api group: 'com.google.code.gson', name: 'gson', version: '2.8.5'
|
api group: 'com.google.code.gson', name: 'gson', version: '2.8.5'
|
||||||
|
|
||||||
api 'com.github.TheMode:CommandBuilder:f893cfbfe4'
|
api 'com.github.TheMode:CommandBuilder:f893cfbfe4'
|
||||||
api 'com.github.Minestom:minecraft-text:69fd808e92'
|
|
||||||
|
|
||||||
// https://jitpack.io/#Articdive/Jnoise/1.0-SNAPSHOT
|
// https://jitpack.io/#Articdive/Jnoise/1.0-SNAPSHOT
|
||||||
api 'com.github.Articdive:Jnoise:1.0-SNAPSHOT'
|
api 'com.github.Articdive:Jnoise:1.0-SNAPSHOT'
|
||||||
@ -41,4 +39,8 @@ dependencies {
|
|||||||
// https://mvnrepository.com/artifact/org.rocksdb/rocksdbjni
|
// https://mvnrepository.com/artifact/org.rocksdb/rocksdbjni
|
||||||
api group: 'org.rocksdb', name: 'rocksdbjni', version: '6.8.1'
|
api group: 'org.rocksdb', name: 'rocksdbjni', version: '6.8.1'
|
||||||
|
|
||||||
|
api 'net.kyori:text-api:3.0.3'
|
||||||
|
api 'net.kyori:text-serializer-legacy:3.0.3'
|
||||||
|
api 'net.kyori:text-serializer-gson:3.0.3'
|
||||||
|
api 'net.kyori:text-serializer-plain:3.0.3'
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
package net.minestom.server.chat;
|
package net.minestom.server.chat;
|
||||||
|
|
||||||
import club.thectm.minecraft.text.LegacyText;
|
import net.kyori.text.Component;
|
||||||
import club.thectm.minecraft.text.TextObject;
|
import net.kyori.text.TextComponent;
|
||||||
|
import net.kyori.text.serializer.gson.GsonComponentSerializer;
|
||||||
|
import net.kyori.text.serializer.legacy.LegacyComponentSerializer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Thank for the minecraft-text library made by rbrick:
|
* Thank for the minecraft-text library made by rbrick:
|
||||||
@ -11,23 +13,23 @@ public class Chat {
|
|||||||
|
|
||||||
public static final char COLOR_CHAR = (char) 0xA7; // Represent the character '§'
|
public static final char COLOR_CHAR = (char) 0xA7; // Represent the character '§'
|
||||||
|
|
||||||
public static TextObject legacyText(String text, char colorChar) {
|
public static String toJsonString(Component component) {
|
||||||
return LegacyText.fromLegacy(text, colorChar);
|
return GsonComponentSerializer.INSTANCE.serialize(component);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TextObject legacyText(String text) {
|
public static Component fromJsonString(String json) {
|
||||||
return legacyText(text, COLOR_CHAR);
|
return GsonComponentSerializer.INSTANCE.deserialize(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String legacyTextString(String text, char colorChar) {
|
public static String toLegacyText(Component component) {
|
||||||
return legacyText(text, colorChar).toJson().toString();
|
return LegacyComponentSerializer.legacyLinking().serialize(component);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String legacyTextString(String text) {
|
public static TextComponent fromLegacyText(String text, char colorChar) {
|
||||||
return legacyText(text).toJson().toString();
|
return LegacyComponentSerializer.legacyLinking().deserialize(text, colorChar);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String uncoloredLegacyText(String text) {
|
public static TextComponent fromLegacyText(String text) {
|
||||||
return text.replace(String.valueOf(COLOR_CHAR), "");
|
return fromLegacyText(text, COLOR_CHAR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,39 +0,0 @@
|
|||||||
package net.minestom.server.chat;
|
|
||||||
|
|
||||||
import net.minestom.server.utils.HexUtils;
|
|
||||||
|
|
||||||
public enum ChatColor {
|
|
||||||
|
|
||||||
BLACK((byte) 0),
|
|
||||||
DARK_BLUE((byte) 1),
|
|
||||||
DARK_GREEN((byte) 2),
|
|
||||||
DARK_AQUA((byte) 3),
|
|
||||||
DARK_RED((byte) 4),
|
|
||||||
DARK_PURPLE((byte) 5),
|
|
||||||
GOLD((byte) 6),
|
|
||||||
GRAY((byte) 7),
|
|
||||||
DARK_GRAY((byte) 8),
|
|
||||||
BLUE((byte) 9),
|
|
||||||
GREEN((byte) 0xa),
|
|
||||||
AQUA((byte) 0xb),
|
|
||||||
RED((byte) 0xc),
|
|
||||||
LIGHT_PURPLE((byte) 0xd),
|
|
||||||
YELLOW((byte) 0xe),
|
|
||||||
WHITE((byte) 0xf);
|
|
||||||
|
|
||||||
|
|
||||||
private byte id;
|
|
||||||
|
|
||||||
ChatColor(byte id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return Chat.COLOR_CHAR + String.valueOf(HexUtils.byteToHex(id));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,8 +1,7 @@
|
|||||||
package net.minestom.server.entity;
|
package net.minestom.server.entity;
|
||||||
|
|
||||||
import club.thectm.minecraft.text.TextBuilder;
|
import net.kyori.text.Component;
|
||||||
import club.thectm.minecraft.text.TextObject;
|
import net.kyori.text.TextComponent;
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import net.minestom.server.MinecraftServer;
|
import net.minestom.server.MinecraftServer;
|
||||||
import net.minestom.server.bossbar.BossBar;
|
import net.minestom.server.bossbar.BossBar;
|
||||||
import net.minestom.server.chat.Chat;
|
import net.minestom.server.chat.Chat;
|
||||||
@ -249,21 +248,21 @@ public class Player extends LivingEntity {
|
|||||||
public void kill() {
|
public void kill() {
|
||||||
if (!isDead()) {
|
if (!isDead()) {
|
||||||
// send death message to player
|
// send death message to player
|
||||||
TextObject deathMessage;
|
Component deathMessage;
|
||||||
if (lastDamageSource != null) {
|
if (lastDamageSource != null) {
|
||||||
deathMessage = lastDamageSource.buildDeathScreenMessage(this);
|
deathMessage = lastDamageSource.buildDeathScreenMessage(this);
|
||||||
} else { // may happen if killed by the server without applying damage
|
} else { // may happen if killed by the server without applying damage
|
||||||
deathMessage = TextBuilder.of("Killed by poor programming.").build();
|
deathMessage = TextComponent.of("Killed by poor programming.");
|
||||||
}
|
}
|
||||||
CombatEventPacket deathPacket = CombatEventPacket.death(this, Optional.empty(), deathMessage);
|
CombatEventPacket deathPacket = CombatEventPacket.death(this, Optional.empty(), deathMessage);
|
||||||
playerConnection.sendPacket(deathPacket);
|
playerConnection.sendPacket(deathPacket);
|
||||||
|
|
||||||
// send death message to chat
|
// send death message to chat
|
||||||
TextObject chatMessage;
|
Component chatMessage;
|
||||||
if (lastDamageSource != null) {
|
if (lastDamageSource != null) {
|
||||||
chatMessage = lastDamageSource.buildChatMessage(this);
|
chatMessage = lastDamageSource.buildChatMessage(this);
|
||||||
} else { // may happen if killed by the server without applying damage
|
} else { // may happen if killed by the server without applying damage
|
||||||
chatMessage = TextBuilder.of(getUsername() + " was killed by poor programming.").build();
|
chatMessage = TextComponent.of(getUsername() + " was killed by poor programming.");
|
||||||
}
|
}
|
||||||
MinecraftServer.getConnectionManager().getOnlinePlayers().forEach(player -> {
|
MinecraftServer.getConnectionManager().getOnlinePlayers().forEach(player -> {
|
||||||
player.sendMessage(chatMessage);
|
player.sendMessage(chatMessage);
|
||||||
@ -399,20 +398,16 @@ public class Player extends LivingEntity {
|
|||||||
|
|
||||||
// Use legacy color formatting
|
// Use legacy color formatting
|
||||||
public void sendMessage(String message) {
|
public void sendMessage(String message) {
|
||||||
sendMessage(Chat.legacyText(message));
|
sendMessage(Chat.fromLegacyText(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendMessage(String message, char colorChar) {
|
public void sendMessage(String message, char colorChar) {
|
||||||
sendMessage(Chat.legacyText(message, colorChar));
|
sendMessage(Chat.fromLegacyText(message, colorChar));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendMessage(JsonObject jsonObject) {
|
public void sendMessage(Component textObject) {
|
||||||
ChatMessagePacket chatMessagePacket = new ChatMessagePacket(jsonObject.toString(), ChatMessagePacket.Position.CHAT);
|
String json = Chat.toJsonString(textObject);
|
||||||
playerConnection.sendPacket(chatMessagePacket);
|
playerConnection.sendPacket(new ChatMessagePacket(json, ChatMessagePacket.Position.CHAT));
|
||||||
}
|
|
||||||
|
|
||||||
public void sendMessage(TextObject textObject) {
|
|
||||||
sendMessage(textObject.toJson());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void playSound(Sound sound, SoundCategory soundCategory, int x, int y, int z, float volume, float pitch) {
|
public void playSound(Sound sound, SoundCategory soundCategory, int x, int y, int z, float volume, float pitch) {
|
||||||
@ -452,24 +447,77 @@ public class Player extends LivingEntity {
|
|||||||
playerConnection.sendPacket(stopSoundPacket);
|
playerConnection.sendPacket(stopSoundPacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendHeaderFooter(String header, String footer, char colorChar) {
|
public void sendHeaderFooter(Component header, Component footer) {
|
||||||
PlayerListHeaderAndFooterPacket playerListHeaderAndFooterPacket = new PlayerListHeaderAndFooterPacket();
|
PlayerListHeaderAndFooterPacket playerListHeaderAndFooterPacket = new PlayerListHeaderAndFooterPacket();
|
||||||
playerListHeaderAndFooterPacket.emptyHeader = header == null;
|
playerListHeaderAndFooterPacket.emptyHeader = header == null;
|
||||||
playerListHeaderAndFooterPacket.emptyFooter = footer == null;
|
playerListHeaderAndFooterPacket.emptyFooter = footer == null;
|
||||||
|
playerListHeaderAndFooterPacket.header = Chat.toJsonString(header);
|
||||||
playerListHeaderAndFooterPacket.header = Chat.legacyText(header, colorChar).toJson().toString();
|
playerListHeaderAndFooterPacket.footer = Chat.toJsonString(footer);
|
||||||
playerListHeaderAndFooterPacket.footer = Chat.legacyText(footer, colorChar).toJson().toString();
|
|
||||||
|
|
||||||
playerConnection.sendPacket(playerListHeaderAndFooterPacket);
|
playerConnection.sendPacket(playerListHeaderAndFooterPacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendActionBarMessage(String message, char colorChar) {
|
public void sendHeaderFooter(String header, String footer, char colorChar) {
|
||||||
|
sendHeaderFooter(Chat.fromLegacyText(header, colorChar), Chat.fromLegacyText(footer, colorChar));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendTitle(Component title, TitlePacket.Action action) {
|
||||||
TitlePacket titlePacket = new TitlePacket();
|
TitlePacket titlePacket = new TitlePacket();
|
||||||
titlePacket.action = TitlePacket.Action.SET_ACTION_BAR;
|
titlePacket.action = action;
|
||||||
titlePacket.actionBarText = Chat.legacyText(message, colorChar).toJson().toString();
|
|
||||||
|
switch (action) {
|
||||||
|
case SET_TITLE:
|
||||||
|
titlePacket.titleText = Chat.toJsonString(title);
|
||||||
|
break;
|
||||||
|
case SET_SUBTITLE:
|
||||||
|
titlePacket.subtitleText = Chat.toJsonString(title);
|
||||||
|
break;
|
||||||
|
case SET_ACTION_BAR:
|
||||||
|
titlePacket.actionBarText = Chat.toJsonString(title);
|
||||||
|
default:
|
||||||
|
throw new UnsupportedOperationException("Invalid TitlePacket.Action type!");
|
||||||
|
}
|
||||||
|
|
||||||
playerConnection.sendPacket(titlePacket);
|
playerConnection.sendPacket(titlePacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void sendTitleSubtitleMessage(Component title, Component subtitle) {
|
||||||
|
sendTitle(title, TitlePacket.Action.SET_TITLE);
|
||||||
|
sendTitle(subtitle, TitlePacket.Action.SET_SUBTITLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendTitleMessage(Component title) {
|
||||||
|
sendTitle(title, TitlePacket.Action.SET_TITLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendTitleMessage(String title, char colorChar) {
|
||||||
|
sendTitleMessage(Chat.fromLegacyText(title, colorChar));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendTitleMessage(String title) {
|
||||||
|
sendTitleMessage(title, Chat.COLOR_CHAR);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendSubtitleMessage(Component subtitle) {
|
||||||
|
sendTitle(subtitle, TitlePacket.Action.SET_SUBTITLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendSubtitleMessage(String subtitle, char colorChar) {
|
||||||
|
sendSubtitleMessage(Chat.fromLegacyText(subtitle, colorChar));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendSubtitleMessage(String subtitle) {
|
||||||
|
sendSubtitleMessage(subtitle, Chat.COLOR_CHAR);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendActionBarMessage(Component actionBar) {
|
||||||
|
sendTitle(actionBar, TitlePacket.Action.SET_ACTION_BAR);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendActionBarMessage(String message, char colorChar) {
|
||||||
|
sendActionBarMessage(Chat.fromLegacyText(message, colorChar));
|
||||||
|
}
|
||||||
|
|
||||||
public void sendActionBarMessage(String message) {
|
public void sendActionBarMessage(String message) {
|
||||||
sendActionBarMessage(message, Chat.COLOR_CHAR);
|
sendActionBarMessage(message, Chat.COLOR_CHAR);
|
||||||
}
|
}
|
||||||
@ -703,13 +751,17 @@ public class Player extends LivingEntity {
|
|||||||
playerConnection.sendPacket(respawnPacket);
|
playerConnection.sendPacket(respawnPacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void kick(String message) {
|
public void kick(Component message) {
|
||||||
DisconnectPacket disconnectPacket = new DisconnectPacket();
|
DisconnectPacket disconnectPacket = new DisconnectPacket();
|
||||||
disconnectPacket.message = message;
|
disconnectPacket.message = Chat.toJsonString(message);
|
||||||
playerConnection.sendPacket(disconnectPacket);
|
playerConnection.sendPacket(disconnectPacket);
|
||||||
playerConnection.getChannel().close();
|
playerConnection.getChannel().close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void kick(String message) {
|
||||||
|
kick(Chat.fromLegacyText(message));
|
||||||
|
}
|
||||||
|
|
||||||
public LevelType getLevelType() {
|
public LevelType getLevelType() {
|
||||||
return levelType;
|
return levelType;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
package net.minestom.server.entity.damage;
|
package net.minestom.server.entity.damage;
|
||||||
|
|
||||||
import club.thectm.minecraft.text.TextBuilder;
|
import net.kyori.text.Component;
|
||||||
import club.thectm.minecraft.text.TextObject;
|
import net.kyori.text.TextComponent;
|
||||||
|
import net.kyori.text.TranslatableComponent;
|
||||||
import net.minestom.server.entity.Entity;
|
import net.minestom.server.entity.Entity;
|
||||||
import net.minestom.server.entity.LivingEntity;
|
import net.minestom.server.entity.LivingEntity;
|
||||||
import net.minestom.server.entity.Player;
|
import net.minestom.server.entity.Player;
|
||||||
@ -34,15 +35,15 @@ public class DamageType {
|
|||||||
return new EntityProjectileDamage(shooter, projectile);
|
return new EntityProjectileDamage(shooter, projectile);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TextObject buildChatMessage(Player killed) {
|
public Component buildChatMessage(Player killed) {
|
||||||
return TextBuilder.ofTranslation("death."+identifier, TextBuilder.of(killed.getUsername()).build()).build();
|
return TranslatableComponent.of("death."+identifier, TextComponent.of(killed.getUsername()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DamageType fromPlayer(Player player) {
|
public static DamageType fromPlayer(Player player) {
|
||||||
return new EntityDamage(player);
|
return new EntityDamage(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TextObject buildDeathScreenMessage(Player killed) {
|
public Component buildDeathScreenMessage(Player killed) {
|
||||||
return buildChatMessage(killed);
|
return buildChatMessage(killed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package net.minestom.server.event;
|
package net.minestom.server.event;
|
||||||
|
|
||||||
import club.thectm.minecraft.text.TextObject;
|
import net.kyori.text.TextComponent;
|
||||||
import net.minestom.server.entity.Player;
|
import net.minestom.server.entity.Player;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -12,7 +12,7 @@ public class PlayerChatEvent extends CancellableEvent {
|
|||||||
private Player sender;
|
private Player sender;
|
||||||
private Collection<Player> recipients;
|
private Collection<Player> recipients;
|
||||||
private String message;
|
private String message;
|
||||||
private Function<PlayerChatEvent, TextObject> chatFormat;
|
private Function<PlayerChatEvent, TextComponent> chatFormat;
|
||||||
|
|
||||||
public PlayerChatEvent(Player sender, Collection<Player> recipients, String message) {
|
public PlayerChatEvent(Player sender, Collection<Player> recipients, String message) {
|
||||||
this.sender = sender;
|
this.sender = sender;
|
||||||
@ -20,7 +20,7 @@ public class PlayerChatEvent extends CancellableEvent {
|
|||||||
this.message = message;
|
this.message = message;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setChatFormat(Function<PlayerChatEvent, TextObject> chatFormat) {
|
public void setChatFormat(Function<PlayerChatEvent, TextComponent> chatFormat) {
|
||||||
this.chatFormat = chatFormat;
|
this.chatFormat = chatFormat;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,7 +40,7 @@ public class PlayerChatEvent extends CancellableEvent {
|
|||||||
this.message = message;
|
this.message = message;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Function<PlayerChatEvent, TextObject> getChatFormatFunction() {
|
public Function<PlayerChatEvent, TextComponent> getChatFormatFunction() {
|
||||||
return chatFormat;
|
return chatFormat;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
package net.minestom.server.listener;
|
package net.minestom.server.listener;
|
||||||
|
|
||||||
import club.thectm.minecraft.text.*;
|
import net.kyori.text.TextComponent;
|
||||||
|
import net.kyori.text.event.ClickEvent;
|
||||||
|
import net.kyori.text.event.HoverEvent;
|
||||||
|
import net.kyori.text.format.TextColor;
|
||||||
|
import net.kyori.text.serializer.plain.PlainComponentSerializer;
|
||||||
import net.minestom.server.MinecraftServer;
|
import net.minestom.server.MinecraftServer;
|
||||||
import net.minestom.server.chat.Chat;
|
import net.minestom.server.chat.Chat;
|
||||||
import net.minestom.server.command.CommandManager;
|
import net.minestom.server.command.CommandManager;
|
||||||
@ -14,7 +18,7 @@ import java.util.function.Function;
|
|||||||
public class ChatMessageListener {
|
public class ChatMessageListener {
|
||||||
|
|
||||||
public static void listener(ClientChatMessagePacket packet, Player player) {
|
public static void listener(ClientChatMessagePacket packet, Player player) {
|
||||||
String message = Chat.uncoloredLegacyText(packet.message);
|
String message = PlainComponentSerializer.INSTANCE.serialize(Chat.fromLegacyText(packet.message));
|
||||||
|
|
||||||
CommandManager commandManager = MinecraftServer.getCommandManager();
|
CommandManager commandManager = MinecraftServer.getCommandManager();
|
||||||
String cmdPrefix = commandManager.getCommandPrefix();
|
String cmdPrefix = commandManager.getCommandPrefix();
|
||||||
@ -38,12 +42,11 @@ public class ChatMessageListener {
|
|||||||
playerChatEvent.setChatFormat((event) -> {
|
playerChatEvent.setChatFormat((event) -> {
|
||||||
String username = player.getUsername();
|
String username = player.getUsername();
|
||||||
|
|
||||||
TextObject usernameText = TextBuilder.of(String.format("<%s>", username))
|
TextComponent usernameText = TextComponent.of(String.format("<%s>", username))
|
||||||
.color(ChatColor.WHITE)
|
.color(TextColor.WHITE)
|
||||||
.hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, ChatColor.GRAY + "Its " + username))
|
.hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Its " + username).color(TextColor.GRAY)))
|
||||||
.clickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/msg " + username + " "))
|
.clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, "/msg " + username + " "))
|
||||||
.append(" " + event.getMessage())
|
.append(TextComponent.of(" " + event.getMessage()));
|
||||||
.build();
|
|
||||||
|
|
||||||
return usernameText;
|
return usernameText;
|
||||||
});
|
});
|
||||||
@ -51,11 +54,11 @@ public class ChatMessageListener {
|
|||||||
// Call the event
|
// Call the event
|
||||||
player.callCancellableEvent(PlayerChatEvent.class, playerChatEvent, () -> {
|
player.callCancellableEvent(PlayerChatEvent.class, playerChatEvent, () -> {
|
||||||
|
|
||||||
Function<PlayerChatEvent, TextObject> formatFunction = playerChatEvent.getChatFormatFunction();
|
Function<PlayerChatEvent, TextComponent> formatFunction = playerChatEvent.getChatFormatFunction();
|
||||||
if (formatFunction == null)
|
if (formatFunction == null)
|
||||||
throw new NullPointerException("PlayerChatEvent#chatFormat cannot be null!");
|
throw new NullPointerException("PlayerChatEvent#chatFormat cannot be null!");
|
||||||
|
|
||||||
TextObject textObject = formatFunction.apply(playerChatEvent);
|
TextComponent textObject = formatFunction.apply(playerChatEvent);
|
||||||
|
|
||||||
for (Player recipient : playerChatEvent.getRecipients()) {
|
for (Player recipient : playerChatEvent.getRecipients()) {
|
||||||
recipient.sendMessage(textObject);
|
recipient.sendMessage(textObject);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package net.minestom.server.listener;
|
package net.minestom.server.listener;
|
||||||
|
|
||||||
import net.minestom.server.chat.ChatColor;
|
import net.kyori.text.format.TextColor;
|
||||||
import net.minestom.server.entity.Player;
|
import net.minestom.server.entity.Player;
|
||||||
import net.minestom.server.network.packet.client.play.ClientKeepAlivePacket;
|
import net.minestom.server.network.packet.client.play.ClientKeepAlivePacket;
|
||||||
|
|
||||||
@ -8,7 +8,7 @@ public class KeepAliveListener {
|
|||||||
|
|
||||||
public static void listener(ClientKeepAlivePacket packet, Player player) {
|
public static void listener(ClientKeepAlivePacket packet, Player player) {
|
||||||
if (packet.id != player.getLastKeepAlive()) {
|
if (packet.id != player.getLastKeepAlive()) {
|
||||||
player.kick(ChatColor.RED + "Bad Keep Alive packet");
|
player.kick(TextColor.RED + "Bad Keep Alive packet");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,8 +92,8 @@ public class AdvancementsPacket implements ServerPacket {
|
|||||||
public float y;
|
public float y;
|
||||||
|
|
||||||
private void write(PacketWriter writer) {
|
private void write(PacketWriter writer) {
|
||||||
writer.writeSizedString(Chat.legacyTextString(title));
|
writer.writeSizedString(Chat.toJsonString(Chat.fromLegacyText(title)));
|
||||||
writer.writeSizedString(Chat.legacyTextString(description));
|
writer.writeSizedString(Chat.toJsonString(Chat.fromLegacyText(title)));
|
||||||
writer.writeItemStack(icon);
|
writer.writeItemStack(icon);
|
||||||
writer.writeVarInt(frameType.ordinal());
|
writer.writeVarInt(frameType.ordinal());
|
||||||
writer.writeInt(flags);
|
writer.writeInt(flags);
|
||||||
|
@ -28,7 +28,7 @@ public class BossBarPacket implements ServerPacket {
|
|||||||
|
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case ADD:
|
case ADD:
|
||||||
writer.writeSizedString(Chat.legacyTextString(title));
|
writer.writeSizedString(Chat.toJsonString(Chat.fromLegacyText(title)));
|
||||||
writer.writeFloat(health);
|
writer.writeFloat(health);
|
||||||
writer.writeVarInt(color.ordinal());
|
writer.writeVarInt(color.ordinal());
|
||||||
writer.writeVarInt(division.ordinal());
|
writer.writeVarInt(division.ordinal());
|
||||||
@ -41,7 +41,7 @@ public class BossBarPacket implements ServerPacket {
|
|||||||
writer.writeFloat(health);
|
writer.writeFloat(health);
|
||||||
break;
|
break;
|
||||||
case UPDATE_TITLE:
|
case UPDATE_TITLE:
|
||||||
writer.writeSizedString(Chat.legacyTextString(title));
|
writer.writeSizedString(Chat.toJsonString(Chat.fromLegacyText(title)));
|
||||||
break;
|
break;
|
||||||
case UPDATE_STYLE:
|
case UPDATE_STYLE:
|
||||||
writer.writeVarInt(color.ordinal());
|
writer.writeVarInt(color.ordinal());
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package net.minestom.server.network.packet.server.play;
|
package net.minestom.server.network.packet.server.play;
|
||||||
|
|
||||||
import club.thectm.minecraft.text.TextObject;
|
import net.kyori.text.Component;
|
||||||
|
import net.kyori.text.TextComponent;
|
||||||
import net.minestom.server.chat.Chat;
|
import net.minestom.server.chat.Chat;
|
||||||
import net.minestom.server.entity.Entity;
|
import net.minestom.server.entity.Entity;
|
||||||
import net.minestom.server.entity.Player;
|
import net.minestom.server.entity.Player;
|
||||||
@ -20,7 +21,7 @@ public class CombatEventPacket implements ServerPacket {
|
|||||||
private int duration;
|
private int duration;
|
||||||
private int opponent;
|
private int opponent;
|
||||||
private int playerID;
|
private int playerID;
|
||||||
private TextObject deathMessage;
|
private Component deathMessage;
|
||||||
|
|
||||||
private CombatEventPacket() {}
|
private CombatEventPacket() {}
|
||||||
|
|
||||||
@ -38,7 +39,7 @@ public class CombatEventPacket implements ServerPacket {
|
|||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CombatEventPacket death(Player player, Optional<Entity> killer, TextObject message) {
|
public static CombatEventPacket death(Player player, Optional<Entity> killer, Component message) {
|
||||||
CombatEventPacket packet = new CombatEventPacket();
|
CombatEventPacket packet = new CombatEventPacket();
|
||||||
packet.type = EventType.DEATH;
|
packet.type = EventType.DEATH;
|
||||||
packet.playerID = player.getEntityId();
|
packet.playerID = player.getEntityId();
|
||||||
@ -63,7 +64,7 @@ public class CombatEventPacket implements ServerPacket {
|
|||||||
case DEATH:
|
case DEATH:
|
||||||
writer.writeVarInt(playerID);
|
writer.writeVarInt(playerID);
|
||||||
writer.writeInt(opponent);
|
writer.writeInt(opponent);
|
||||||
writer.writeSizedString(deathMessage.toJson().toString());
|
writer.writeSizedString(Chat.toJsonString(deathMessage));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package net.minestom.server.network.packet.server.play;
|
package net.minestom.server.network.packet.server.play;
|
||||||
|
|
||||||
import net.minestom.server.chat.Chat;
|
|
||||||
import net.minestom.server.network.packet.PacketWriter;
|
import net.minestom.server.network.packet.PacketWriter;
|
||||||
import net.minestom.server.network.packet.server.ServerPacket;
|
import net.minestom.server.network.packet.server.ServerPacket;
|
||||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||||
@ -11,7 +10,7 @@ public class DisconnectPacket implements ServerPacket {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(PacketWriter writer) {
|
public void write(PacketWriter writer) {
|
||||||
writer.writeSizedString(Chat.legacyTextString(message));
|
writer.writeSizedString(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -18,7 +18,7 @@ public class ScoreboardObjectivePacket implements ServerPacket {
|
|||||||
writer.writeByte(mode);
|
writer.writeByte(mode);
|
||||||
|
|
||||||
if (mode == 0 || mode == 2) {
|
if (mode == 0 || mode == 2) {
|
||||||
writer.writeSizedString(Chat.legacyTextString(objectiveValue));
|
writer.writeSizedString(Chat.toJsonString(Chat.fromLegacyText(objectiveValue)));
|
||||||
writer.writeVarInt(type);
|
writer.writeVarInt(type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,13 +27,13 @@ public class TeamsPacket implements ServerPacket {
|
|||||||
switch (action) {
|
switch (action) {
|
||||||
case CREATE_TEAM:
|
case CREATE_TEAM:
|
||||||
case UPDATE_TEAM_INFO:
|
case UPDATE_TEAM_INFO:
|
||||||
writer.writeSizedString(Chat.legacyTextString(teamDisplayName));
|
writer.writeSizedString(Chat.toJsonString(Chat.fromLegacyText(teamDisplayName)));
|
||||||
writer.writeByte(friendlyFlags);
|
writer.writeByte(friendlyFlags);
|
||||||
writer.writeSizedString(nameTagVisibility.getIdentifier());
|
writer.writeSizedString(nameTagVisibility.getIdentifier());
|
||||||
writer.writeSizedString(collisionRule.getIdentifier());
|
writer.writeSizedString(collisionRule.getIdentifier());
|
||||||
writer.writeVarInt(teamColor);
|
writer.writeVarInt(teamColor);
|
||||||
writer.writeSizedString(Chat.legacyTextString(teamPrefix));
|
writer.writeSizedString(Chat.toJsonString(Chat.fromLegacyText(teamPrefix)));
|
||||||
writer.writeSizedString(Chat.legacyTextString(teamSuffix));
|
writer.writeSizedString(Chat.toJsonString(Chat.fromLegacyText(teamSuffix)));
|
||||||
break;
|
break;
|
||||||
case REMOVE_TEAM:
|
case REMOVE_TEAM:
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package net.minestom.server.network.packet.server.play;
|
package net.minestom.server.network.packet.server.play;
|
||||||
|
|
||||||
import net.minestom.server.chat.Chat;
|
|
||||||
import net.minestom.server.network.packet.PacketWriter;
|
import net.minestom.server.network.packet.PacketWriter;
|
||||||
import net.minestom.server.network.packet.server.ServerPacket;
|
import net.minestom.server.network.packet.server.ServerPacket;
|
||||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||||
@ -25,13 +24,13 @@ public class TitlePacket implements ServerPacket {
|
|||||||
|
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case SET_TITLE:
|
case SET_TITLE:
|
||||||
writer.writeSizedString(Chat.legacyTextString(titleText));
|
writer.writeSizedString(titleText);
|
||||||
break;
|
break;
|
||||||
case SET_SUBTITLE:
|
case SET_SUBTITLE:
|
||||||
writer.writeSizedString(Chat.legacyTextString(subtitleText));
|
writer.writeSizedString(subtitleText);
|
||||||
break;
|
break;
|
||||||
case SET_ACTION_BAR:
|
case SET_ACTION_BAR:
|
||||||
writer.writeSizedString(Chat.legacyTextString(actionBarText));
|
writer.writeSizedString(actionBarText);
|
||||||
break;
|
break;
|
||||||
case SET_TIMES_AND_DISPLAY:
|
case SET_TIMES_AND_DISPLAY:
|
||||||
writer.writeInt(fadeIn);
|
writer.writeInt(fadeIn);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package net.minestom.server.scoreboard;
|
package net.minestom.server.scoreboard;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import net.minestom.server.chat.ChatColor;
|
import net.kyori.text.format.TextColor;
|
||||||
import net.minestom.server.entity.Player;
|
import net.minestom.server.entity.Player;
|
||||||
import net.minestom.server.network.packet.server.play.TeamsPacket;
|
import net.minestom.server.network.packet.server.play.TeamsPacket;
|
||||||
import net.minestom.server.utils.PacketUtils;
|
import net.minestom.server.utils.PacketUtils;
|
||||||
@ -17,7 +17,7 @@ public class Team {
|
|||||||
private byte friendlyFlags = 0x00;
|
private byte friendlyFlags = 0x00;
|
||||||
private TeamsPacket.NameTagVisibility nameTagVisibility = TeamsPacket.NameTagVisibility.ALWAYS;
|
private TeamsPacket.NameTagVisibility nameTagVisibility = TeamsPacket.NameTagVisibility.ALWAYS;
|
||||||
private TeamsPacket.CollisionRule collisionRule = TeamsPacket.CollisionRule.NEVER;
|
private TeamsPacket.CollisionRule collisionRule = TeamsPacket.CollisionRule.NEVER;
|
||||||
private ChatColor teamColor = ChatColor.WHITE;
|
private TextColor teamColor = TextColor.WHITE;
|
||||||
private String prefix = "", suffix = "";
|
private String prefix = "", suffix = "";
|
||||||
private String[] entities = new String[0];
|
private String[] entities = new String[0];
|
||||||
private Set<Player> players = new CopyOnWriteArraySet<>();
|
private Set<Player> players = new CopyOnWriteArraySet<>();
|
||||||
@ -36,7 +36,7 @@ public class Team {
|
|||||||
teamsCreationPacket.friendlyFlags = friendlyFlags;
|
teamsCreationPacket.friendlyFlags = friendlyFlags;
|
||||||
teamsCreationPacket.nameTagVisibility = nameTagVisibility;
|
teamsCreationPacket.nameTagVisibility = nameTagVisibility;
|
||||||
teamsCreationPacket.collisionRule = collisionRule;
|
teamsCreationPacket.collisionRule = collisionRule;
|
||||||
teamsCreationPacket.teamColor = teamColor.getId();
|
teamsCreationPacket.teamColor = teamColor.ordinal();
|
||||||
teamsCreationPacket.teamPrefix = prefix;
|
teamsCreationPacket.teamPrefix = prefix;
|
||||||
teamsCreationPacket.teamSuffix = suffix;
|
teamsCreationPacket.teamSuffix = suffix;
|
||||||
teamsCreationPacket.entities = entities;
|
teamsCreationPacket.entities = entities;
|
||||||
@ -107,9 +107,9 @@ public class Team {
|
|||||||
sendUpdatePacket();
|
sendUpdatePacket();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTeamColor(ChatColor teamColor) {
|
public void setTeamColor(TextColor teamColor) {
|
||||||
this.teamColor = teamColor;
|
this.teamColor = teamColor;
|
||||||
this.teamsCreationPacket.teamColor = teamColor.getId();
|
this.teamsCreationPacket.teamColor = teamColor.ordinal();
|
||||||
sendUpdatePacket();
|
sendUpdatePacket();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,7 +152,7 @@ public class Team {
|
|||||||
updatePacket.friendlyFlags = friendlyFlags;
|
updatePacket.friendlyFlags = friendlyFlags;
|
||||||
updatePacket.nameTagVisibility = nameTagVisibility;
|
updatePacket.nameTagVisibility = nameTagVisibility;
|
||||||
updatePacket.collisionRule = collisionRule;
|
updatePacket.collisionRule = collisionRule;
|
||||||
updatePacket.teamColor = teamColor.getId();
|
updatePacket.teamColor = teamColor.ordinal();
|
||||||
updatePacket.teamPrefix = prefix;
|
updatePacket.teamPrefix = prefix;
|
||||||
updatePacket.teamSuffix = suffix;
|
updatePacket.teamSuffix = suffix;
|
||||||
ByteBuf buffer = PacketUtils.writePacket(updatePacket);
|
ByteBuf buffer = PacketUtils.writePacket(updatePacket);
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
package net.minestom.server.utils;
|
package net.minestom.server.utils;
|
||||||
|
|
||||||
import club.thectm.minecraft.text.LegacyText;
|
import net.kyori.text.Component;
|
||||||
import club.thectm.minecraft.text.TextObject;
|
import net.minestom.server.chat.Chat;
|
||||||
import com.google.gson.JsonParser;
|
|
||||||
import net.minestom.server.item.Enchantment;
|
import net.minestom.server.item.Enchantment;
|
||||||
import net.minestom.server.item.ItemStack;
|
import net.minestom.server.item.ItemStack;
|
||||||
import net.minestom.server.network.packet.PacketReader;
|
import net.minestom.server.network.packet.PacketReader;
|
||||||
@ -122,8 +121,9 @@ public class NbtReaderUtils {
|
|||||||
|
|
||||||
if (stringName.equals("Name")) {
|
if (stringName.equals("Name")) {
|
||||||
String jsonDisplayName = reader.readShortSizedString();
|
String jsonDisplayName = reader.readShortSizedString();
|
||||||
TextObject textObject = TextObject.fromJson(new JsonParser().parse(jsonDisplayName).getAsJsonObject());
|
Component textObject = Chat.fromJsonString(jsonDisplayName);
|
||||||
String displayName = LegacyText.toLegacy(textObject);
|
String displayName = Chat.toLegacyText(textObject);
|
||||||
|
|
||||||
item.setDisplayName(displayName);
|
item.setDisplayName(displayName);
|
||||||
readItemStackDisplayNBT(reader, item);
|
readItemStackDisplayNBT(reader, item);
|
||||||
}
|
}
|
||||||
@ -139,9 +139,9 @@ public class NbtReaderUtils {
|
|||||||
ArrayList<String> lore = new ArrayList<>(size);
|
ArrayList<String> lore = new ArrayList<>(size);
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
String string = reader.readShortSizedString();
|
String string = reader.readShortSizedString();
|
||||||
|
Component textObject = Chat.fromJsonString(string);
|
||||||
|
String line = Chat.toLegacyText(textObject);
|
||||||
|
|
||||||
TextObject textObject = TextObject.fromJson(new JsonParser().parse(string).getAsJsonObject());
|
|
||||||
String line = LegacyText.toLegacy(textObject);
|
|
||||||
lore.add(line);
|
lore.add(line);
|
||||||
if (lore.size() == size) {
|
if (lore.size() == size) {
|
||||||
item.setLore(lore);
|
item.setLore(lore);
|
||||||
|
@ -117,7 +117,7 @@ public class Utils {
|
|||||||
if (hasDisplayName) {
|
if (hasDisplayName) {
|
||||||
packet.writeByte((byte) 0x08);
|
packet.writeByte((byte) 0x08);
|
||||||
packet.writeShortSizedString("Name");
|
packet.writeShortSizedString("Name");
|
||||||
packet.writeShortSizedString(Chat.legacyTextString(itemStack.getDisplayName()));
|
packet.writeShortSizedString(Chat.toJsonString(Chat.fromLegacyText(itemStack.getDisplayName())));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasLore) {
|
if (hasLore) {
|
||||||
@ -128,7 +128,7 @@ public class Utils {
|
|||||||
packet.writeByte((byte) 0x08);
|
packet.writeByte((byte) 0x08);
|
||||||
packet.writeInt(lore.size());
|
packet.writeInt(lore.size());
|
||||||
for (String line : lore) {
|
for (String line : lore) {
|
||||||
packet.writeShortSizedString(Chat.legacyTextString(line));
|
packet.writeShortSizedString(Chat.toJsonString(Chat.fromLegacyText(line)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user