|
19 | 19 | import net.md_5.bungee.api.ChatMessageType; |
20 | 20 | import net.md_5.bungee.api.chat.TextComponent; |
21 | 21 | import org.bukkit.Bukkit; |
| 22 | +import org.bukkit.ChatColor; |
22 | 23 | import org.bukkit.Material; |
23 | 24 | import org.bukkit.enchantments.Enchantment; |
24 | 25 | import org.bukkit.entity.Player; |
@@ -261,9 +262,17 @@ private static void smartSetLore(@NotNull ItemMeta meta, @NotNull List<String> t |
261 | 262 | return; |
262 | 263 | } |
263 | 264 |
|
264 | | - final int[] bounds = findPrefixBounds(lore); |
265 | | - final int start = bounds[0]; |
266 | | - final int end = bounds[1]; |
| 265 | + int[] bounds = findPrefixBounds(lore); |
| 266 | + int start = bounds[0]; |
| 267 | + int end = bounds[1]; |
| 268 | + |
| 269 | + // Fallback: detect old LevelTools lore lines (without §§ prefix) by progress bar pattern |
| 270 | + if (start == -1) { |
| 271 | + bounds = findLegacyBounds(lore); |
| 272 | + start = bounds[0]; |
| 273 | + end = bounds[1]; |
| 274 | + } |
| 275 | + |
267 | 276 | if (start == -1) { |
268 | 277 | lore.addAll(toAdd); |
269 | 278 | meta.setLore(lore); |
@@ -298,6 +307,36 @@ private static int[] findPrefixBounds(@NotNull List<String> lore) { |
298 | 307 | return arr; |
299 | 308 | } |
300 | 309 |
|
| 310 | + private static int[] findLegacyBounds(@NotNull List<String> lore) { |
| 311 | + final int[] arr = new int[]{-1, -1}; |
| 312 | + for (int i = 0; i < lore.size(); i++) { |
| 313 | + final String stripped = ChatColor.stripColor(colorize(lore.get(i))); |
| 314 | + if (stripped != null && stripped.matches("^\\[\\|+.*\\].*$")) { |
| 315 | + // Found a progress bar line from old LevelTools format |
| 316 | + // Walk backwards to find the start (skip empty lines and level label) |
| 317 | + int scanStart = i; |
| 318 | + for (int j = i - 1; j >= 0; j--) { |
| 319 | + String prev = ChatColor.stripColor(colorize(lore.get(j))); |
| 320 | + if (prev == null || prev.trim().isEmpty()) { |
| 321 | + scanStart = j; |
| 322 | + continue; |
| 323 | + } |
| 324 | + if (prev.matches(".*(?:Level|Nível|Nivel).*:\\s*\\d+.*")) { |
| 325 | + scanStart = j; |
| 326 | + continue; |
| 327 | + } |
| 328 | + break; |
| 329 | + } |
| 330 | + if (arr[0] == -1 || scanStart < arr[0]) { |
| 331 | + arr[0] = scanStart; |
| 332 | + } |
| 333 | + arr[1] = i; |
| 334 | + } |
| 335 | + } |
| 336 | + |
| 337 | + return arr; |
| 338 | + } |
| 339 | + |
301 | 340 | public static void handleReward(LevelToolsItem tool, Player player) { |
302 | 341 | Material material = tool.getItemStack().getType(); |
303 | 342 | ItemProfile itemProfile = getItemProfile(material); |
|
0 commit comments