mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-01 05:58:00 +01:00
Update packets having a Chat component
This commit is contained in:
parent
8ef5a0b394
commit
76f9a059b5
@ -1,6 +1,7 @@
|
||||
package net.minestom.server.bossbar;
|
||||
|
||||
import net.minestom.server.Viewable;
|
||||
import net.minestom.server.chat.Chat;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.network.packet.server.play.BossBarPacket;
|
||||
|
||||
@ -94,7 +95,7 @@ public class BossBar implements Viewable {
|
||||
BossBarPacket bossBarPacket = new BossBarPacket();
|
||||
bossBarPacket.uuid = uuid;
|
||||
bossBarPacket.action = BossBarPacket.Action.ADD;
|
||||
bossBarPacket.title = title;
|
||||
bossBarPacket.title = Chat.fromLegacyText(title);
|
||||
bossBarPacket.health = progress;
|
||||
bossBarPacket.color = color;
|
||||
bossBarPacket.division = division;
|
||||
@ -113,7 +114,7 @@ public class BossBar implements Viewable {
|
||||
BossBarPacket bossBarPacket = new BossBarPacket();
|
||||
bossBarPacket.uuid = uuid;
|
||||
bossBarPacket.action = BossBarPacket.Action.UPDATE_TITLE;
|
||||
bossBarPacket.title = title;
|
||||
bossBarPacket.title = Chat.fromLegacyText(title);
|
||||
sendPacketToViewers(bossBarPacket);
|
||||
}
|
||||
|
||||
|
@ -239,8 +239,6 @@ public class Player extends LivingEntity {
|
||||
playerConnection.sendPacket(getPropertiesPacket()); // Send default properties
|
||||
refreshHealth();
|
||||
refreshAbilities();
|
||||
|
||||
sendUpdateHealthPacket();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -733,7 +731,13 @@ public class Player extends LivingEntity {
|
||||
return food;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set and refresh client food bar
|
||||
*
|
||||
* @param food the new food value
|
||||
*/
|
||||
public void setFood(int food) {
|
||||
Check.argCondition(!MathUtils.isBetween(food, 0, 20), "Food needs to be between 0 and 20");
|
||||
this.food = food;
|
||||
sendUpdateHealthPacket();
|
||||
}
|
||||
@ -742,7 +746,13 @@ public class Player extends LivingEntity {
|
||||
return foodSaturation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set and refresh client food saturation
|
||||
*
|
||||
* @param foodSaturation the food saturation
|
||||
*/
|
||||
public void setFoodSaturation(float foodSaturation) {
|
||||
Check.argCondition(!MathUtils.isBetween(foodSaturation, 0, 5), "Food saturation has to be between 0 and 5");
|
||||
this.foodSaturation = foodSaturation;
|
||||
sendUpdateHealthPacket();
|
||||
}
|
||||
@ -866,9 +876,10 @@ public class Player extends LivingEntity {
|
||||
}
|
||||
|
||||
protected void refreshHealth() {
|
||||
heal();
|
||||
this.food = 20;
|
||||
this.foodSaturation = 5;
|
||||
// refresh health and send health packet
|
||||
heal();
|
||||
}
|
||||
|
||||
protected void sendUpdateHealthPacket() {
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.kyori.text.Component;
|
||||
import net.minestom.server.bossbar.BarColor;
|
||||
import net.minestom.server.bossbar.BarDivision;
|
||||
import net.minestom.server.chat.Chat;
|
||||
@ -14,7 +15,7 @@ public class BossBarPacket implements ServerPacket {
|
||||
public UUID uuid;
|
||||
public Action action;
|
||||
|
||||
public String title;
|
||||
public Component title;
|
||||
public float health;
|
||||
public BarColor color;
|
||||
public BarDivision division;
|
||||
@ -28,7 +29,7 @@ public class BossBarPacket implements ServerPacket {
|
||||
|
||||
switch (action) {
|
||||
case ADD:
|
||||
writer.writeSizedString(Chat.toJsonString(Chat.fromLegacyText(title)));
|
||||
writer.writeSizedString(Chat.toJsonString(title));
|
||||
writer.writeFloat(health);
|
||||
writer.writeVarInt(color.ordinal());
|
||||
writer.writeVarInt(division.ordinal());
|
||||
@ -41,7 +42,7 @@ public class BossBarPacket implements ServerPacket {
|
||||
writer.writeFloat(health);
|
||||
break;
|
||||
case UPDATE_TITLE:
|
||||
writer.writeSizedString(Chat.toJsonString(Chat.fromLegacyText(title)));
|
||||
writer.writeSizedString(Chat.toJsonString(title));
|
||||
break;
|
||||
case UPDATE_STYLE:
|
||||
writer.writeVarInt(color.ordinal());
|
||||
|
@ -1,7 +1,6 @@
|
||||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.kyori.text.Component;
|
||||
import net.kyori.text.TextComponent;
|
||||
import net.minestom.server.chat.Chat;
|
||||
import net.minestom.server.entity.Entity;
|
||||
import net.minestom.server.entity.Player;
|
||||
@ -23,7 +22,8 @@ public class CombatEventPacket implements ServerPacket {
|
||||
private int playerID;
|
||||
private Component deathMessage;
|
||||
|
||||
private CombatEventPacket() {}
|
||||
private CombatEventPacket() {
|
||||
}
|
||||
|
||||
public static CombatEventPacket enter() {
|
||||
CombatEventPacket packet = new CombatEventPacket();
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.kyori.text.Component;
|
||||
import net.minestom.server.chat.Chat;
|
||||
import net.minestom.server.network.packet.PacketWriter;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
@ -9,7 +10,7 @@ public class ScoreboardObjectivePacket implements ServerPacket {
|
||||
|
||||
public String objectiveName;
|
||||
public byte mode;
|
||||
public String objectiveValue;
|
||||
public Component objectiveValue;
|
||||
public int type;
|
||||
|
||||
@Override
|
||||
@ -18,7 +19,7 @@ public class ScoreboardObjectivePacket implements ServerPacket {
|
||||
writer.writeByte(mode);
|
||||
|
||||
if (mode == 0 || mode == 2) {
|
||||
writer.writeSizedString(Chat.toJsonString(Chat.fromLegacyText(objectiveValue)));
|
||||
writer.writeSizedString(Chat.toJsonString(objectiveValue));
|
||||
writer.writeVarInt(type);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.kyori.text.Component;
|
||||
import net.minestom.server.chat.Chat;
|
||||
import net.minestom.server.network.packet.PacketWriter;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
@ -10,13 +11,13 @@ public class TeamsPacket implements ServerPacket {
|
||||
public String teamName;
|
||||
public Action action;
|
||||
|
||||
public String teamDisplayName;
|
||||
public Component teamDisplayName;
|
||||
public byte friendlyFlags;
|
||||
public NameTagVisibility nameTagVisibility;
|
||||
public CollisionRule collisionRule;
|
||||
public int teamColor;
|
||||
public String teamPrefix;
|
||||
public String teamSuffix;
|
||||
public Component teamPrefix;
|
||||
public Component teamSuffix;
|
||||
public String[] entities;
|
||||
|
||||
@Override
|
||||
@ -27,13 +28,13 @@ public class TeamsPacket implements ServerPacket {
|
||||
switch (action) {
|
||||
case CREATE_TEAM:
|
||||
case UPDATE_TEAM_INFO:
|
||||
writer.writeSizedString(Chat.toJsonString(Chat.fromLegacyText(teamDisplayName)));
|
||||
writer.writeSizedString(Chat.toJsonString(teamDisplayName));
|
||||
writer.writeByte(friendlyFlags);
|
||||
writer.writeSizedString(nameTagVisibility.getIdentifier());
|
||||
writer.writeSizedString(collisionRule.getIdentifier());
|
||||
writer.writeVarInt(teamColor);
|
||||
writer.writeSizedString(Chat.toJsonString(Chat.fromLegacyText(teamPrefix)));
|
||||
writer.writeSizedString(Chat.toJsonString(Chat.fromLegacyText(teamSuffix)));
|
||||
writer.writeSizedString(Chat.toJsonString(teamPrefix));
|
||||
writer.writeSizedString(Chat.toJsonString(teamSuffix));
|
||||
break;
|
||||
case REMOVE_TEAM:
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.minestom.server.scoreboard;
|
||||
|
||||
import net.minestom.server.Viewable;
|
||||
import net.minestom.server.chat.Chat;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.network.packet.server.play.DisplayScoreboardPacket;
|
||||
import net.minestom.server.network.packet.server.play.ScoreboardObjectivePacket;
|
||||
@ -34,7 +35,7 @@ public class BelowNameScoreboard implements Viewable {
|
||||
scoreboardObjectivePacket = new ScoreboardObjectivePacket();
|
||||
scoreboardObjectivePacket.objectiveName = objectiveName;
|
||||
scoreboardObjectivePacket.mode = 0;
|
||||
scoreboardObjectivePacket.objectiveValue = "test:" + objectiveName;
|
||||
scoreboardObjectivePacket.objectiveValue = Chat.fromLegacyText(objectiveName);
|
||||
scoreboardObjectivePacket.type = 0;
|
||||
|
||||
displayScoreboardPacket = new DisplayScoreboardPacket();
|
||||
|
@ -53,7 +53,7 @@ public class Sidebar implements Viewable {
|
||||
ScoreboardObjectivePacket scoreboardObjectivePacket = new ScoreboardObjectivePacket();
|
||||
scoreboardObjectivePacket.objectiveName = objectiveName;
|
||||
scoreboardObjectivePacket.mode = 2; // Update display text
|
||||
scoreboardObjectivePacket.objectiveValue = title;
|
||||
scoreboardObjectivePacket.objectiveValue = Chat.fromLegacyText(title);
|
||||
scoreboardObjectivePacket.type = 0;
|
||||
|
||||
sendPacketToViewers(scoreboardObjectivePacket);
|
||||
@ -131,7 +131,7 @@ public class Sidebar implements Viewable {
|
||||
ScoreboardObjectivePacket scoreboardObjectivePacket = new ScoreboardObjectivePacket();
|
||||
scoreboardObjectivePacket.objectiveName = objectiveName;
|
||||
scoreboardObjectivePacket.mode = 0; // Create scoreboard
|
||||
scoreboardObjectivePacket.objectiveValue = title;
|
||||
scoreboardObjectivePacket.objectiveValue = Chat.fromLegacyText(title);
|
||||
scoreboardObjectivePacket.type = 0; // Type integer
|
||||
|
||||
DisplayScoreboardPacket displayScoreboardPacket = new DisplayScoreboardPacket();
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.minestom.server.scoreboard;
|
||||
|
||||
import net.minestom.server.chat.Chat;
|
||||
import net.minestom.server.network.packet.server.play.TeamsPacket;
|
||||
|
||||
public class SidebarTeam {
|
||||
@ -26,13 +27,13 @@ public class SidebarTeam {
|
||||
TeamsPacket teamsPacket = new TeamsPacket();
|
||||
teamsPacket.teamName = teamName;
|
||||
teamsPacket.action = TeamsPacket.Action.CREATE_TEAM;
|
||||
teamsPacket.teamDisplayName = teamDisplayName;
|
||||
teamsPacket.teamDisplayName = Chat.fromLegacyText(teamDisplayName);
|
||||
teamsPacket.friendlyFlags = friendlyFlags;
|
||||
teamsPacket.nameTagVisibility = nameTagVisibility;
|
||||
teamsPacket.collisionRule = collisionRule;
|
||||
teamsPacket.teamColor = teamColor;
|
||||
teamsPacket.teamPrefix = prefix;
|
||||
teamsPacket.teamSuffix = suffix;
|
||||
teamsPacket.teamPrefix = Chat.fromLegacyText(prefix);
|
||||
teamsPacket.teamSuffix = Chat.fromLegacyText(suffix);
|
||||
teamsPacket.entities = new String[]{entityName};
|
||||
return teamsPacket;
|
||||
}
|
||||
@ -48,13 +49,13 @@ public class SidebarTeam {
|
||||
TeamsPacket teamsPacket = new TeamsPacket();
|
||||
teamsPacket.teamName = teamName;
|
||||
teamsPacket.action = TeamsPacket.Action.UPDATE_TEAM_INFO;
|
||||
teamsPacket.teamDisplayName = teamDisplayName;
|
||||
teamsPacket.teamDisplayName = Chat.fromLegacyText(teamDisplayName);
|
||||
teamsPacket.friendlyFlags = friendlyFlags;
|
||||
teamsPacket.nameTagVisibility = nameTagVisibility;
|
||||
teamsPacket.collisionRule = collisionRule;
|
||||
teamsPacket.teamColor = teamColor;
|
||||
teamsPacket.teamPrefix = prefix;
|
||||
teamsPacket.teamSuffix = suffix;
|
||||
teamsPacket.teamPrefix = Chat.fromLegacyText(prefix);
|
||||
teamsPacket.teamSuffix = Chat.fromLegacyText(suffix);
|
||||
return teamsPacket;
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@ package net.minestom.server.scoreboard;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.kyori.text.format.TextColor;
|
||||
import net.minestom.server.chat.Chat;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.network.packet.server.play.TeamsPacket;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
@ -32,13 +33,13 @@ public class Team {
|
||||
teamsCreationPacket = new TeamsPacket();
|
||||
teamsCreationPacket.teamName = teamName;
|
||||
teamsCreationPacket.action = TeamsPacket.Action.CREATE_TEAM;
|
||||
teamsCreationPacket.teamDisplayName = teamDisplayName;
|
||||
teamsCreationPacket.teamDisplayName = Chat.fromLegacyText(teamDisplayName);
|
||||
teamsCreationPacket.friendlyFlags = friendlyFlags;
|
||||
teamsCreationPacket.nameTagVisibility = nameTagVisibility;
|
||||
teamsCreationPacket.collisionRule = collisionRule;
|
||||
teamsCreationPacket.teamColor = teamColor.ordinal();
|
||||
teamsCreationPacket.teamPrefix = prefix;
|
||||
teamsCreationPacket.teamSuffix = suffix;
|
||||
teamsCreationPacket.teamPrefix = Chat.fromLegacyText(prefix);
|
||||
teamsCreationPacket.teamSuffix = Chat.fromLegacyText(suffix);
|
||||
teamsCreationPacket.entities = entities;
|
||||
|
||||
TeamsPacket destroyPacket = new TeamsPacket();
|
||||
@ -91,7 +92,7 @@ public class Team {
|
||||
|
||||
public void setTeamDisplayName(String teamDisplayName) {
|
||||
this.teamDisplayName = teamDisplayName;
|
||||
this.teamsCreationPacket.teamDisplayName = teamDisplayName;
|
||||
this.teamsCreationPacket.teamDisplayName = Chat.fromLegacyText(teamDisplayName);
|
||||
sendUpdatePacket();
|
||||
}
|
||||
|
||||
@ -115,13 +116,13 @@ public class Team {
|
||||
|
||||
public void setPrefix(String prefix) {
|
||||
this.prefix = prefix;
|
||||
this.teamsCreationPacket.teamPrefix = prefix;
|
||||
this.teamsCreationPacket.teamPrefix = Chat.fromLegacyText(prefix);
|
||||
sendUpdatePacket();
|
||||
}
|
||||
|
||||
public void setSuffix(String suffix) {
|
||||
this.suffix = suffix;
|
||||
this.teamsCreationPacket.teamSuffix = suffix;
|
||||
this.teamsCreationPacket.teamSuffix = Chat.fromLegacyText(suffix);
|
||||
sendUpdatePacket();
|
||||
}
|
||||
|
||||
@ -148,13 +149,13 @@ public class Team {
|
||||
TeamsPacket updatePacket = new TeamsPacket();
|
||||
updatePacket.teamName = teamName;
|
||||
updatePacket.action = TeamsPacket.Action.UPDATE_TEAM_INFO;
|
||||
updatePacket.teamDisplayName = teamDisplayName;
|
||||
updatePacket.teamDisplayName = Chat.fromLegacyText(teamDisplayName);
|
||||
updatePacket.friendlyFlags = friendlyFlags;
|
||||
updatePacket.nameTagVisibility = nameTagVisibility;
|
||||
updatePacket.collisionRule = collisionRule;
|
||||
updatePacket.teamColor = teamColor.ordinal();
|
||||
updatePacket.teamPrefix = prefix;
|
||||
updatePacket.teamSuffix = suffix;
|
||||
updatePacket.teamPrefix = Chat.fromLegacyText(prefix);
|
||||
updatePacket.teamSuffix = Chat.fromLegacyText(suffix);
|
||||
ByteBuf buffer = PacketUtils.writePacket(updatePacket);
|
||||
players.forEach(p -> p.getPlayerConnection().sendPacket(buffer));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user