Merge pull request #183 from simoleo89/fix/command-description-texts

fix(commands): complete and quiet command descriptions
This commit is contained in:
DuckieTM
2026-06-15 07:21:39 +02:00
committed by GitHub
10 changed files with 115 additions and 3 deletions
@@ -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);
}
@@ -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 = "";
@@ -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;
}
}
}
@@ -0,0 +1,45 @@
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 java.util.List;
import org.junit.jupiter.api.Test;
class CommandDescriptionTextsContractTest {
private static final Path FULL_DATABASE = Path.of("../Default Database/FullDatabase.sql");
private static final Path LIVE_SCHEMA_UPDATE = Path.of("../Database Updates/003_live_required_schema.sql");
private static final List<String> REQUIRED_DESCRIPTION_KEYS = List.of(
"commands.description.acc_modtool_room_info",
"commands.description.cmd_add_youtube_playlist",
"commands.description.cmd_disablemassmentions",
"commands.description.cmd_disablementions",
"commands.description.cmd_give_prefix",
"commands.description.cmd_hidewired",
"commands.description.cmd_list_prefixes",
"commands.description.cmd_remove_prefix",
"commands.description.cmd_setroom_template",
"commands.description.cmd_update_youtube_playlists"
);
@Test
void fullDatabaseDefinesCommandDescriptionsUsedByCommandsList() throws IOException {
assertContainsAllDescriptionKeys(Files.readString(FULL_DATABASE), "FullDatabase.sql");
}
@Test
void liveSchemaUpdateBackfillsCommandDescriptionsForExistingDatabases() throws IOException {
assertContainsAllDescriptionKeys(Files.readString(LIVE_SCHEMA_UPDATE), "003_live_required_schema.sql");
}
private static void assertContainsAllDescriptionKeys(String source, String fileName) {
for (String key : REQUIRED_DESCRIPTION_KEYS) {
assertTrue(source.contains("'" + key + "'"),
fileName + " must define " + key + " to avoid TextsManager missing-key logs");
}
}
}
@@ -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");
}
}