diff --git a/api/src/main/java/com/rexcantor64/triton/api/config/TritonConfig.java b/api/src/main/java/com/rexcantor64/triton/api/config/TritonConfig.java index f409aeed..5eed41e8 100644 --- a/api/src/main/java/com/rexcantor64/triton/api/config/TritonConfig.java +++ b/api/src/main/java/com/rexcantor64/triton/api/config/TritonConfig.java @@ -199,6 +199,12 @@ public interface TritonConfig { */ boolean isAdvancements(); + /** + * @return The value of "language-creation.death-screen.enabled" in the config. + * @since 3.10.0 + */ + boolean isDeathScreen(); + /** * @return The value of "language-creation.terminal" in the config. * @since 2.6.0 @@ -323,4 +329,10 @@ public interface TritonConfig { */ FeatureSyntax getAdvancementsSyntax(); + /** + * @return The {@link com.rexcantor64.triton.api.config.FeatureSyntax FeatureSyntax} of "language-creation + * .death-screen" in the config. + */ + FeatureSyntax getDeathScreenSyntax(); + } diff --git a/core/src/main/java/com/rexcantor64/triton/config/MainConfig.java b/core/src/main/java/com/rexcantor64/triton/config/MainConfig.java index 2bc01691..484dd2a2 100644 --- a/core/src/main/java/com/rexcantor64/triton/config/MainConfig.java +++ b/core/src/main/java/com/rexcantor64/triton/config/MainConfig.java @@ -87,6 +87,8 @@ public class MainConfig implements TritonConfig { private FeatureSyntax scoreboardSyntax; private boolean advancements; private FeatureSyntax advancementsSyntax; + private boolean deathScreen; + private FeatureSyntax deathScreenSyntax; private boolean advancementsRefresh; private boolean terminal; private boolean terminalAnsi; @@ -287,6 +289,10 @@ private void setupLanguageCreation(Configuration section) { this.advancementsSyntax = FeatureSyntax.fromSection(advancements); this.advancementsRefresh = advancements.getBoolean("experimental-advancements-refresh", false); + Configuration deathScreen = section.getSection("death-screen"); + this.deathScreen = deathScreen.getBoolean("enabled", true); + this.deathScreenSyntax = FeatureSyntax.fromSection(deathScreen); + List hologramList = holograms.getStringList("types"); for (String hologram : hologramList) try { diff --git a/core/src/main/java/com/rexcantor64/triton/packetinterceptor/ProtocolLibListener.java b/core/src/main/java/com/rexcantor64/triton/packetinterceptor/ProtocolLibListener.java index 8ede0780..94aefb41 100644 --- a/core/src/main/java/com/rexcantor64/triton/packetinterceptor/ProtocolLibListener.java +++ b/core/src/main/java/com/rexcantor64/triton/packetinterceptor/ProtocolLibListener.java @@ -175,8 +175,12 @@ private void setupPacketHandlers() { // New actionbar packet packetHandlers.put(PacketType.Play.Server.SET_ACTION_BAR_TEXT, asAsync(this::handleActionbar)); + + // Combat packet split on 1.17 + packetHandlers.put(PacketType.Play.Server.PLAYER_COMBAT_KILL, asAsync(this::handleDeathScreen)); } else { packetHandlers.put(PacketType.Play.Server.TITLE, asAsync(this::handleTitle)); + packetHandlers.put(PacketType.Play.Server.COMBAT_EVENT, asAsync(this::handleDeathScreen)); } packetHandlers.put(PacketType.Play.Server.PLAYER_LIST_HEADER_FOOTER, asAsync(this::handlePlayerListHeaderFooter)); @@ -716,6 +720,29 @@ private void handleScoreboardObjective(PacketEvent packet, SpigotLanguagePlayer packet.getPacket().getChatComponents().writeSafely(0, displayName); } + private void handleDeathScreen(PacketEvent packet, SpigotLanguagePlayer languagePlayer) { + if (!main.getConf().isDeathScreen()) return; + + val component = packet.getPacket().getChatComponents().readSafely(0); + if (component == null) { + // Likely it's MC 1.16 or below and type of packet is not ENTITY_DIED. + // Alternatively, this will always be null on 1.8.8 since it uses a String, but there's nothing interesting to translate anyway. + return; + } + + BaseComponent[] result = main.getLanguageParser().parseComponent( + languagePlayer, + main.getConf().getDeathScreenSyntax(), + ComponentSerializer.parse(component.getJson()) + ); + if (result == null) { + result = new BaseComponent[]{new TextComponent("")}; + } + component.setJson(ComponentSerializer.toString(result)); + + packet.getPacket().getChatComponents().writeSafely(0, component); + } + /* PROTOCOL LIB */ @Override diff --git a/core/src/main/resources/config.yml b/core/src/main/resources/config.yml index 72653a18..08170a7d 100644 --- a/core/src/main/resources/config.yml +++ b/core/src/main/resources/config.yml @@ -241,6 +241,13 @@ language-creation: # There might be some issues with this enabled, disable if you have those issues. # Without this enabled, players will have to leave and join the server for the language of custom advancements to be updated. experimental-advancements-refresh: false + death-screen: + # Should the plugin check for placeholders in the death screen (shown when the player dies)? + # Only works on 1.9 and above. + enabled: true + syntax-lang: lang + syntax-args: args + syntax-arg: arg # If any message contains a placeholder with the key defined in the field below, that message won't be sent to the players (console will still receive it). # Leave empty to disable this feature (it's disabled by default). # Example (assuming you have the default values on your config and you've set disabled-line to 'disabled.line'):