Skip to content

Commit 3073323

Browse files
committed
rapy fix
1 parent 981293d commit 3073323

4 files changed

Lines changed: 61 additions & 19 deletions

File tree

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ yarn_mappings=1.21.4+build.8
88
loader_version=0.16.10
99

1010
# Mod Properties
11-
mod_version=1.5.4-Alpha+1.21.4
11+
mod_version=1.5.5-Alpha+1.21.4
1212
maven_group=pl.lordtricker
1313
archives_base_name=ltrynek
1414

src/client/java/pl/lordtricker/ltrynek/client/config/ConfigLoader.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ public static ServersConfig loadConfig() {
4040
if (config == null) {
4141
config = createDefaultConfig();
4242
}
43-
// Ensure default for new fields
4443
if (config.adsEnabled == null) {
4544
config.adsEnabled = true;
4645
// Persist the new default into the main config file
@@ -182,9 +181,9 @@ private static ServersConfig createDefaultConfig() {
182181
cfg.servers.add(server2);
183182

184183
ServerEntry server3 = new ServerEntry();
185-
server3.domains = List.of("rapy.pl");
184+
server3.domains = List.of("rapy.pl", "rapy.gg", "rapysmp.pl", "jjsmp.pl");
186185
server3.profileName = "rapy";
187-
server3.loreRegex = "(?i).*Cena.*?\\$?([\\d.,]+(?:mld|m|k)?).*";
186+
server3.loreRegex = "(?i).*Cena\\s*:?\\s*(?:\\$\\s*)?((?:\\d{1,3}(?:[\\s\\u00A0.,]\\d{3})*|\\d+)(?:mld|m|k)?)(?:\\s*\\$)?.*";
188187
server3.highlightColor = "#00FF33";
189188
server3.highlightColorStack = "#FFAB00";
190189
server3.miniAlarmSound = "minecraft:ui.button.click";
@@ -231,4 +230,4 @@ private static ServersConfig createDefaultConfig() {
231230

232231
return cfg;
233232
}
234-
}
233+
}

src/client/java/pl/lordtricker/ltrynek/client/manager/ClientPriceListManager.java

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,20 +101,39 @@ public static void removePriceEntry(String rawItem) {
101101
public static PriceEntry findMatchingPriceEntry(String noColorName, List<String> loreLines, String materialId, String enchantments) {
102102
List<PriceEntry> entries = priceLists.get(activeProfile);
103103
if (entries == null) return null;
104+
105+
PriceEntry best = null;
106+
int bestScore = -1;
107+
108+
String lowerName = noColorName.toLowerCase();
109+
String lowerMaterialId = materialId.toLowerCase();
110+
String lowerEnchantments = enchantments == null ? "" : enchantments.toLowerCase();
111+
104112
for (PriceEntry pe : entries) {
113+
int score = 0;
114+
115+
// Material check (strict equality if provided)
105116
if (pe.material != null && !pe.material.isEmpty()) {
106117
if (!materialId.equalsIgnoreCase(pe.material)) {
107118
continue;
108119
}
120+
score += 1000; // prefer rules with explicit material
109121
}
122+
123+
// Name check (contains; prefer longer/ exact matches)
110124
if (!pe.name.isEmpty()) {
111-
String lowerName = noColorName.toLowerCase();
112-
String lowerMaterial = materialId.toLowerCase();
113125
String lowerEntryName = pe.name.toLowerCase();
114-
if (!lowerName.contains(lowerEntryName) && !lowerMaterial.contains(lowerEntryName)) {
126+
boolean nameMatches = lowerName.contains(lowerEntryName) || lowerMaterialId.contains(lowerEntryName);
127+
if (!nameMatches) {
115128
continue;
116129
}
130+
score += Math.min(500, lowerEntryName.length());
131+
if (lowerName.equals(lowerEntryName)) {
132+
score += 200; // exact name match bonus
133+
}
117134
}
135+
136+
// Lore substring check
118137
if (pe.lore != null && !pe.lore.isEmpty()) {
119138
boolean foundLore = false;
120139
for (String line : loreLines) {
@@ -126,16 +145,23 @@ public static PriceEntry findMatchingPriceEntry(String noColorName, List<String>
126145
if (!foundLore) {
127146
continue;
128147
}
148+
score += 50;
129149
}
150+
151+
// Enchant check
130152
if (pe.enchants != null && !pe.enchants.isEmpty()) {
131-
if (enchantments == null || enchantments.isEmpty() ||
132-
!enchantments.toLowerCase().contains(pe.enchants.toLowerCase())) {
153+
if (lowerEnchantments.isEmpty() || !lowerEnchantments.contains(pe.enchants.toLowerCase())) {
133154
continue;
134155
}
156+
score += 25;
157+
}
158+
159+
if (score > bestScore) {
160+
bestScore = score;
161+
best = pe;
135162
}
136-
return pe;
137163
}
138-
return null;
164+
return best;
139165
}
140166

141167

src/client/java/pl/lordtricker/ltrynek/client/mixin/HandledScreenMixin.java

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ private boolean processSlot(DrawContext context, Slot slot) {
167167

168168
int stackSize = stack.getCount();
169169
boolean isStack = stackSize > 1;
170-
double finalPrice = isStack ? (foundPrice / stackSize) : foundPrice;
170+
double finalPrice = foundPrice;
171171

172172
if (ClientSearchListManager.isSearchActive()) {
173173
String uniqueKey = slot.id + "|" + noColorName + "|" + finalPrice + "|" + stackSize;
@@ -252,7 +252,7 @@ public void run() {
252252
}
253253

254254
private double parsePriceWithSuffix(String raw) {
255-
raw = raw.trim().replace(" ", "");
255+
raw = raw.trim().replaceAll("[\\s\\u00A0\\u202F]+", "");
256256
String lower = raw.toLowerCase();
257257
double multiplier = 1.0;
258258
if (lower.endsWith("mld")) {
@@ -265,16 +265,33 @@ private double parsePriceWithSuffix(String raw) {
265265
multiplier = 1000.0;
266266
raw = raw.substring(0, raw.length() - 1);
267267
}
268-
if (!raw.contains(".")) {
269-
int i = raw.indexOf(',', raw.length() - 3);
270-
if (i != -1) raw = raw.substring(0, i) + "." + raw.substring(i + 1);
268+
int lastDot = raw.lastIndexOf('.');
269+
int lastComma = raw.lastIndexOf(',');
270+
int lastSep = Math.max(lastDot, lastComma);
271+
if (lastSep != -1) {
272+
int digitsAfter = raw.length() - lastSep - 1;
273+
if (digitsAfter > 0 && digitsAfter <= 2) {
274+
String intPart = raw.substring(0, lastSep).replaceAll("[.,]", "");
275+
String fracPart = raw.substring(lastSep + 1).replaceAll("[.,]", "");
276+
raw = intPart + "." + fracPart;
277+
} else {
278+
raw = raw.replaceAll("[.,]", "");
279+
}
280+
} else {
281+
raw = raw.replaceAll("[.,]", "");
271282
}
272-
raw = raw.replace(",", "");
273283
try {
274284
double base = Double.parseDouble(raw);
275285
return base * multiplier;
276286
} catch (NumberFormatException e) {
277-
return -1;
287+
String digitsOnly = raw.replaceAll("\\D+", "");
288+
if (digitsOnly.isEmpty()) return -1;
289+
try {
290+
double base = Double.parseDouble(digitsOnly);
291+
return base * multiplier;
292+
} catch (NumberFormatException ex) {
293+
return -1;
294+
}
278295
}
279296
}
280297

0 commit comments

Comments
 (0)