Skip to content

Commit d192bf4

Browse files
committed
check modification lines still there
fix #51
1 parent 1fa3d0b commit d192bf4

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/client/java/com/coflnet/CoflModClient.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,17 +364,24 @@ public void onInitializeClient() {
364364
continue; // Skip if the line index is invalid
365365
}
366366
int targetLine = tooltip.line;
367-
if(targetLine != 0 && Formatting.strip(ogLoreLines.get(targetLine).toString()).equals(Formatting.strip(lines.get(targetLine).toString()))) {
368-
System.out.println("lines differ `" + Formatting.strip(ogLoreLines.get(targetLine +1).toString()) + "` to `" + Formatting.strip(lines.get(targetLine).toString()) + "`");
367+
if(targetLine > 0
368+
&& targetLine + 1 < ogLoreLines.size()
369+
&& Formatting.strip(ogLoreLines.get(targetLine).toString()).equals(Formatting.strip(lines.get(targetLine).toString()))) {
370+
System.out.println("lines differ `" + Formatting.strip(ogLoreLines.get(targetLine + 1).toString()) + "` to `" + Formatting.strip(lines.get(targetLine).toString()) + "`");
369371
targetLine++; // assume another mod added a line and move this down
370372
}
371373
lines.remove(targetLine);
372374
lines.add(targetLine, Text.of(tooltip.value));
373375
break;
374376
case "INSERT":
375-
lines.add(tooltip.line, Text.of(tooltip.value));
377+
int insertAt = Math.max(0, Math.min(tooltip.line, lines.size()));
378+
lines.add(insertAt, Text.of(tooltip.value));
376379
break;
377380
case "DELETE":
381+
if (tooltip.line < 0 || tooltip.line >= lines.size()) {
382+
System.out.println("Invalid delete line index: " + tooltip.line);
383+
continue;
384+
}
378385
lines.remove(tooltip.line);
379386
break;
380387
case "HIGHLIGHT":

0 commit comments

Comments
 (0)