Skip to content

Commit

Permalink
Send DeathInfoPacket (#2128)
Browse files Browse the repository at this point in the history
  • Loading branch information
PetteriM1 authored Jun 26, 2023
1 parent 6c042e7 commit b555909
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/main/java/cn/nukkit/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -4286,6 +4286,14 @@ public void kill() {

if (showMessages && !ev.getDeathMessage().toString().isEmpty()) {
this.server.broadcast(ev.getDeathMessage(), Server.BROADCAST_CHANNEL_USERS);

DeathInfoPacket pk = new DeathInfoPacket();
if (ev.getDeathMessage() instanceof TranslationContainer) {
pk.messageTranslationKey = this.server.getLanguage().translateString(ev.getDeathMessage().getText(), ((TranslationContainer) ev.getDeathMessage()).getParameters(), null);
} else {
pk.messageTranslationKey = ev.getDeathMessage().getText();
}
this.dataPacket(pk);
}

RespawnPacket pk = new RespawnPacket();
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/cn/nukkit/network/protocol/DeathInfoPacket.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package cn.nukkit.network.protocol;

public class DeathInfoPacket extends DataPacket {

public static final byte NETWORK_ID = ProtocolInfo.DEATH_INFO_PACKET;

public String messageTranslationKey;
public String[] messageParameters = new String[0];

@Override
public byte pid() {
return NETWORK_ID;
}

@Override
public void decode() {
}

@Override
public void encode() {
this.reset();
this.putString(this.messageTranslationKey);
this.putUnsignedVarInt(this.messageParameters.length);
for (String parameter : this.messageParameters) {
this.putString(parameter);
}
}
}
1 change: 1 addition & 0 deletions src/main/java/cn/nukkit/network/protocol/ProtocolInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ public interface ProtocolInfo {
byte TOAST_REQUEST_PACKET = (byte) 0xba;
byte UPDATE_ABILITIES_PACKET = (byte) 0xbb;
byte UPDATE_ADVENTURE_SETTINGS_PACKET = (byte) 0xbc;
byte DEATH_INFO_PACKET = (byte) 0xbd;
byte REQUEST_NETWORK_SETTINGS_PACKET = (byte) 0xc1;
byte GAME_TEST_REQUEST_PACKET = (byte) 0xc2;
byte GAME_TEST_RESULTS_PACKET = (byte) 0xc3;
Expand Down

0 comments on commit b555909

Please sign in to comment.