Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(spigot): support death screen translation #407

Merged
merged 1 commit into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> hologramList = holograms.getStringList("types");
for (String hologram : hologramList)
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions core/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'):
Expand Down
Loading