Skip to content

Commit

Permalink
Make scanner feedback translatable
Browse files Browse the repository at this point in the history
  • Loading branch information
NotRyken committed Jan 17, 2025
1 parent ddaa0cc commit 25fbbe1
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 61 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 2.0.5

- Made scanner feedback translatable

## 2.0.4

- Fixed some minor issues
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,7 @@ private static int showHelp() {
send(msg);
return Command.SINGLE_SUCCESS;
}

public static void sendWithPrefix(String content) {
MutableComponent message = ClaimPoints.PREFIX.copy();
message.append(content);
send(message);
}


public static void sendWithPrefix(Component content) {
MutableComponent message = ClaimPoints.PREFIX.copy();
message.append(content);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import dev.terminalmc.claimpoints.config.Config;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.world.phys.Vec2;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand All @@ -34,6 +35,8 @@
import java.util.regex.Pattern;
import java.util.stream.Stream;

import static dev.terminalmc.claimpoints.util.Localization.localized;

/**
* ClaimPoints obtains information about claim-worlds and claims by sending
* GriefPrevention commands, then scanning chat for the result.
Expand Down Expand Up @@ -113,9 +116,8 @@ private static void stopScanTimeout() {

private static void stopScanInvalid() {
stopScan();
Commands.sendWithPrefix("Unrecognized message found while waiting for " +
"GriefPrevention message. If the claim list appears in chat, you need to adjust " +
"the regex patterns in ClaimPoints config to capture it.");
Commands.sendWithPrefix(localized("message", "scanner.unknownMessage")
.append(" ").append(localized("message", "scanner.editConfig")));
}

/**
Expand Down Expand Up @@ -220,18 +222,16 @@ else if (anyMatches(content, Config.gpSettings().ignoredLinesCompiled)) {
*/
private static void handleWorlds() {
if (worlds.isEmpty()) {
Commands.sendWithPrefix("No worlds found using command '/" +
Config.gpSettings().claimListCommand +
"'. That might be the wrong command, or you might not have any claims. " +
"If the claim list appears in chat, you need to adjust " +
"the regex patterns in ClaimPoints config to capture it.");
Commands.sendWithPrefix(localized("message", "scanner.noWorlds",
Config.gpSettings().claimListCommand)
.append(" ").append(localized("message", "scanner.editConfig")));
} else {
StringBuilder sb = new StringBuilder("Claim worlds (" + worlds.size() + "):");
MutableComponent msg = localized("message", "scanner.worlds", worlds.size());
for (String world : worlds) {
sb.append("\n ");
sb.append(world);
msg.append("\n ");
msg.append(world);
}
Commands.sendWithPrefix(sb.toString());
Commands.sendWithPrefix(msg);
}
}

Expand Down Expand Up @@ -318,27 +318,18 @@ private static void handleClaims() {
*/
private static void addClaimPoints() {
if (claims.isEmpty()) {
Commands.sendWithPrefix(Component.empty()
.append(Component.literal("No claims found for '" + world + "'. Use "))
.append(Component.literal("/cp worlds").withStyle(ChatFormatting.DARK_AQUA))
.append(Component.literal(" to list GriefPrevention worlds in which you " +
"have active claims.")));
Commands.sendWithPrefix(localized("message", "scanner.noClaims", world,
Component.literal("/cp worlds").withStyle(ChatFormatting.DARK_AQUA)));
}
else {
int added = ClaimPoints.waypointManager.addClaimPoints(claims);
StringBuilder sb = new StringBuilder("Added ");
sb.append(added);
sb.append(added == 1 ? " claim from '" : " claims from '");
sb.append(world);
sb.append("' to the active waypoint list.");
MutableComponent msg = localized("message", "scanner.added", added, world);
int skipped = claims.size() - added;
if (skipped > 0) {
sb.append(" Skipped ");
sb.append(skipped);
sb.append(skipped == 1 ? " claim that already has a ClaimPoint." :
" claims that already have ClaimPoints.");
msg.append(" ");
msg.append(localized("message", "scanner.skipped", skipped));
}
Commands.sendWithPrefix(sb.toString());
Commands.sendWithPrefix(msg);
}
claims.clear();
}
Expand All @@ -353,13 +344,7 @@ private static void addClaimPoints() {
*/
private static void cleanClaimPoints() {
int removed = ClaimPoints.waypointManager.cleanClaimPoints(claims);
StringBuilder sb = new StringBuilder("Removed ");
sb.append(removed);
sb.append(removed == 1 ? " ClaimPoint" : " ClaimPoints");
sb.append(" not matching a claim in '");
sb.append(world);
sb.append("' from the active waypoint list.");
Commands.sendWithPrefix(sb.toString());
Commands.sendWithPrefix(localized("message", "scanner.removed", removed, world));
claims.clear();
}

Expand All @@ -377,27 +362,15 @@ private static void cleanClaimPoints() {
*/
private static void updateClaimPoints() {
if (claims.isEmpty()) {
Commands.sendWithPrefix(Component.empty()
.append(Component.literal("No claims found for '" + world + "'. Use "))
.append(Component.literal("/cp worlds").withStyle(ChatFormatting.DARK_AQUA))
.append(Component.literal(" to list GriefPrevention worlds in which you " +
"have active claims, or use /cp clean <world> to remove ClaimPoints.")));
Commands.sendWithPrefix(localized("message", "scanner.noClaims", world,
Component.literal("/cp worlds").withStyle(ChatFormatting.DARK_AQUA))
.append(" ").append(localized("message", "scanner.noClaims.remove",
Component.literal("/cp clean <world>").withStyle(ChatFormatting.DARK_AQUA))));
}
else {
int[] totals = ClaimPoints.waypointManager.updateClaimPoints(claims);
StringBuilder sb = new StringBuilder("Added ");
sb.append(totals[0]);
sb.append(totals[0] == 1 ? " new ClaimPoint" : " new ClaimPoints");
sb.append(" from '");
sb.append(world);
sb.append("', updated ");
sb.append(totals[1]);
sb.append(totals[1] == 1 ? " ClaimPoint size" : " ClaimPoint sizes");
sb.append(", and removed ");
sb.append(totals[2]);
sb.append(totals[2] == 1 ? " stray ClaimPoint" : " stray ClaimPoints");
sb.append(" from the active waypoint list.");
Commands.sendWithPrefix(sb.toString());
Commands.sendWithPrefix(localized("message", "scanner.updated",
totals[0], world, totals[1], totals[2]));
}
claims.clear();
}
Expand Down
10 changes: 10 additions & 0 deletions common/src/main/resources/assets/claimpoints/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@
"message.claimpoints.command.help.waypoints.show": "Enables (shows) all claim waypoints in the active waypoint list.",
"message.claimpoints.command.help.worlds": "Lists the GriefPrevention worlds in which you have active claims, and stores them for future autocompletion.",
"message.claimpoints.installCloth": "Install Cloth Config API to access mod options.",
"message.claimpoints.scanner.added": "Added %s claims from '%s' to the active waypoint list.",
"message.claimpoints.scanner.editConfig": "If the claim list appears in chat, you need to adjust the regex patterns in ClaimPoints config to detect it.",
"message.claimpoints.scanner.noClaims": "No claims found for '%s'. Use %s to list GriefPrevention worlds in which you have active claims.",
"message.claimpoints.scanner.noClaims.remove": "Use %s to remove claim waypoints.",
"message.claimpoints.scanner.noWorlds": "No worlds found using command '%s'. That might be the wrong command, or you might not have any claims.",
"message.claimpoints.scanner.removed": "Removed %s waypoints not matching a claim in '%s' from the active waypoint list.",
"message.claimpoints.scanner.skipped": "Skipped %s claims that already have claim waypoints.",
"message.claimpoints.scanner.unknownMessage": "Unrecognized message found while waiting for GriefPrevention message.",
"message.claimpoints.scanner.updated": "Added %s new claim waypoints from '%s', updated %s claim sizes, and removed %s stray waypoints from the active waypoint list.",
"message.claimpoints.scanner.worlds": "Claim worlds (%s):",
"message.claimpoints.viewModrinth": "View on Modrinth",
"message.claimpoints.waypoint.alias.set": "Set alias of all claim waypoints to '%s'",
"message.claimpoints.waypoint.color.error": "'%s' is not a valid color ID",
Expand Down
12 changes: 11 additions & 1 deletion common/src/main/resources/assets/claimpoints/lang/ru_ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@
"message.claimpoints.command.help.waypoints.show": "Включает (показывает) все точки участков в активном списке точек.",
"message.claimpoints.command.help.worlds": "Отображает миры GriefPrevention, в которых у вас есть активные участки, и сохраняет их для будущего автодополнения.",
"message.claimpoints.installCloth": "Установите Cloth Config API для доступа к параметрам мода.",
"message.claimpoints.scanner.added": "Added %s claims from '%s' to the active waypoint list.",
"message.claimpoints.scanner.editConfig": "If the claim list appears in chat, you need to adjust the regex patterns in ClaimPoints config to detect it.",
"message.claimpoints.scanner.noClaims": "No claims found for '%s'. Use %s to list GriefPrevention worlds in which you have active claims.",
"message.claimpoints.scanner.noClaims.remove": "Use %s to remove claim waypoints.",
"message.claimpoints.scanner.noWorlds": "No worlds found using command '%s'. That might be the wrong command, or you might not have any claims.",
"message.claimpoints.scanner.removed": "Removed %s waypoints not matching a claim in '%s' from the active waypoint list.",
"message.claimpoints.scanner.skipped": "Skipped %s claims that already have claim waypoints.",
"message.claimpoints.scanner.unknownMessage": "Unrecognized message found while waiting for GriefPrevention message.",
"message.claimpoints.scanner.updated": "Added %s new claim waypoints from '%s', updated %s claim sizes, and removed %s stray waypoints from the active waypoint list.",
"message.claimpoints.scanner.worlds": "Claim worlds (%s):",
"message.claimpoints.viewModrinth": "Посмотреть на Modrinth",
"message.claimpoints.waypoint.alias.set": "Установить для всех отметок псевдоним '%s'",
"message.claimpoints.waypoint.color.error": "'%s' не является действительным идентификатором цвета",
Expand Down Expand Up @@ -49,4 +59,4 @@
"option.claimpoints.waypoints.nameFormat": "Формат имени отметки",
"option.claimpoints.waypoints.nameFormat.error": "Формат имени должен содержать %%\u200Cd для размера участка",
"option.claimpoints.waypoints.nameFormat.tooltip": "Формат для имён отметок участка. Должен содержать %%\u200Cd для размера участка."
}
}
10 changes: 10 additions & 0 deletions common/src/main/resources/assets/claimpoints/lang/zh_cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@
"message.claimpoints.command.help.waypoints.show": "Enables (shows) all claim waypoints in the active waypoint list.",
"message.claimpoints.command.help.worlds": "Lists the GriefPrevention worlds in which you have active claims, and stores them for future autocompletion.",
"message.claimpoints.installCloth": "安装Cloth Config API以访问Mod选项。",
"message.claimpoints.scanner.added": "Added %s claims from '%s' to the active waypoint list.",
"message.claimpoints.scanner.editConfig": "If the claim list appears in chat, you need to adjust the regex patterns in ClaimPoints config to detect it.",
"message.claimpoints.scanner.noClaims": "No claims found for '%s'. Use %s to list GriefPrevention worlds in which you have active claims.",
"message.claimpoints.scanner.noClaims.remove": "Use %s to remove claim waypoints.",
"message.claimpoints.scanner.noWorlds": "No worlds found using command '%s'. That might be the wrong command, or you might not have any claims.",
"message.claimpoints.scanner.removed": "Removed %s waypoints not matching a claim in '%s' from the active waypoint list.",
"message.claimpoints.scanner.skipped": "Skipped %s claims that already have claim waypoints.",
"message.claimpoints.scanner.unknownMessage": "Unrecognized message found while waiting for GriefPrevention message.",
"message.claimpoints.scanner.updated": "Added %s new claim waypoints from '%s', updated %s claim sizes, and removed %s stray waypoints from the active waypoint list.",
"message.claimpoints.scanner.worlds": "Claim worlds (%s):",
"message.claimpoints.viewModrinth": "在Modrinth上查看",
"message.claimpoints.waypoint.alias.set": "Set alias of all claim waypoints to '%s'",
"message.claimpoints.waypoint.color.error": "'%s' is not a valid color ID",
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Neo/Forge version ranges: https://maven.apache.org/enforcer/enforcer-rules/versionRanges.html

# Project
mod_version=2.0.4
mod_version=2.0.5
mod_group=dev.terminalmc
mod_id=claimpoints
mod_name=ClaimPoints
Expand Down

0 comments on commit 25fbbe1

Please sign in to comment.