From a92feb2ef0d043f30d66d842f56d04d9e96c1950 Mon Sep 17 00:00:00 2001 From: simoleo89 Date: Sun, 14 Jun 2026 15:48:36 +0200 Subject: [PATCH] fix(commands): quiet optional descriptions --- .../java/com/eu/habbo/core/TextsManager.java | 4 +++ .../habbohotel/commands/CommandsCommand.java | 2 +- .../commands/AvailableCommandsComposer.java | 4 +-- .../core/CommandTextLookupContractTest.java | 35 +++++++++++++++++++ 4 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 Emulator/src/test/java/com/eu/habbo/core/CommandTextLookupContractTest.java diff --git a/Emulator/src/main/java/com/eu/habbo/core/TextsManager.java b/Emulator/src/main/java/com/eu/habbo/core/TextsManager.java index 5c27eedb..02f634e1 100644 --- a/Emulator/src/main/java/com/eu/habbo/core/TextsManager.java +++ b/Emulator/src/main/java/com/eu/habbo/core/TextsManager.java @@ -52,6 +52,10 @@ public class TextsManager { return this.texts.getProperty(key, defaultValue); } + public String getValueQuietly(String key, String defaultValue) { + return this.texts.getProperty(key, defaultValue); + } + public boolean getBoolean(String key) { return this.getBoolean(key, false); } diff --git a/Emulator/src/main/java/com/eu/habbo/habbohotel/commands/CommandsCommand.java b/Emulator/src/main/java/com/eu/habbo/habbohotel/commands/CommandsCommand.java index 0d0e0a48..6d9f80c8 100644 --- a/Emulator/src/main/java/com/eu/habbo/habbohotel/commands/CommandsCommand.java +++ b/Emulator/src/main/java/com/eu/habbo/habbohotel/commands/CommandsCommand.java @@ -18,7 +18,7 @@ public class CommandsCommand extends Command { for (Command c : commands) { String textKey = "commands.description." + c.permission; - String commandText = Emulator.getTexts().getValue(textKey, ""); + String commandText = Emulator.getTexts().getValueQuietly(textKey, ""); String commandLine = ":" + c.keys[0]; String description = ""; diff --git a/Emulator/src/main/java/com/eu/habbo/messages/outgoing/commands/AvailableCommandsComposer.java b/Emulator/src/main/java/com/eu/habbo/messages/outgoing/commands/AvailableCommandsComposer.java index 0f8e00f5..dab605b5 100644 --- a/Emulator/src/main/java/com/eu/habbo/messages/outgoing/commands/AvailableCommandsComposer.java +++ b/Emulator/src/main/java/com/eu/habbo/messages/outgoing/commands/AvailableCommandsComposer.java @@ -23,10 +23,10 @@ public class AvailableCommandsComposer extends MessageComposer { for (Command cmd : this.commands) { this.response.appendString(cmd.keys[0]); this.response.appendString( - Emulator.getTexts().getValue("commands.description." + cmd.permission, cmd.permission) + Emulator.getTexts().getValueQuietly("commands.description." + cmd.permission, cmd.permission) ); } return this.response; } -} \ No newline at end of file +} diff --git a/Emulator/src/test/java/com/eu/habbo/core/CommandTextLookupContractTest.java b/Emulator/src/test/java/com/eu/habbo/core/CommandTextLookupContractTest.java new file mode 100644 index 00000000..a688f8ce --- /dev/null +++ b/Emulator/src/test/java/com/eu/habbo/core/CommandTextLookupContractTest.java @@ -0,0 +1,35 @@ +package com.eu.habbo.core; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; + +import org.junit.jupiter.api.Test; + +class CommandTextLookupContractTest { + private static final Path TEXTS_MANAGER = Path.of("src/main/java/com/eu/habbo/core/TextsManager.java"); + private static final Path COMMANDS_COMMAND = Path.of("src/main/java/com/eu/habbo/habbohotel/commands/CommandsCommand.java"); + private static final Path AVAILABLE_COMMANDS_COMPOSER = Path.of( + "src/main/java/com/eu/habbo/messages/outgoing/commands/AvailableCommandsComposer.java"); + + @Test + void textsManagerExposesQuietFallbackLookupForOptionalTexts() throws IOException { + String source = Files.readString(TEXTS_MANAGER); + + assertTrue(source.contains("public String getValueQuietly(String key, String defaultValue)")); + assertTrue(source.contains("return this.texts.getProperty(key, defaultValue);")); + } + + @Test + void commandListsUseQuietDescriptionLookups() throws IOException { + String commandsCommand = Files.readString(COMMANDS_COMMAND); + String availableCommandsComposer = Files.readString(AVAILABLE_COMMANDS_COMPOSER); + + assertTrue(commandsCommand.contains("getValueQuietly(textKey, \"\")"), + ":commands should not log an error when an optional command description is missing"); + assertTrue(availableCommandsComposer.contains("getValueQuietly(\"commands.description.\" + cmd.permission, cmd.permission)"), + "available commands composer should not log an error when an optional command description is missing"); + } +}