File tree 1 file changed +7
-4
lines changed
src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders
1 file changed +7
-4
lines changed Original file line number Diff line number Diff line change 11
11
import org .jetbrains .annotations .NotNull ;
12
12
13
13
import java .util .List ;
14
+ import java .util .regex .Matcher ;
15
+ import java .util .regex .Pattern ;
14
16
15
17
public class MinionLevelAdder extends SlotTextAdder {
18
+ private static final Pattern MINION_PATTERN = Pattern .compile (".* Minion ([IVXLCDM]+)" );
16
19
public MinionLevelAdder () {
17
20
super ();
18
21
}
@@ -21,11 +24,11 @@ public MinionLevelAdder() {
21
24
public @ NotNull List <SlotText > getText (Slot slot ) {
22
25
ItemStack itemStack = slot .getStack ();
23
26
if (!itemStack .isOf (Items .PLAYER_HEAD )) return List .of ();
24
- String name = itemStack .getName ().getString ();
25
- if (!name .contains ("Minion" )) return List .of ();
26
- String romanNumeral = name .substring (name .lastIndexOf (' ' ) + 1 ); //+1 because we don't need the space itself
27
+ Matcher matcher = MINION_PATTERN .matcher (itemStack .getName ().getString ());
28
+ if (!matcher .matches ()) return List .of ();
29
+ String romanNumeral = matcher .group (1 );
30
+ if (!RomanNumerals .isValidRomanNumeral (romanNumeral )) return List .of ();
27
31
int level = RomanNumerals .romanToDecimal (romanNumeral );
28
- if (level == 0 ) return List .of ();
29
32
return List .of (SlotText .topRight (Text .literal (String .valueOf (level )).formatted (Formatting .AQUA )));
30
33
}
31
34
}
You can’t perform that action at this time.
0 commit comments