1
1
package com .laytonsmith .abstraction .enums .bukkit ;
2
2
3
+ import com .laytonsmith .PureUtilities .Common .ReflectionUtils ;
3
4
import com .laytonsmith .abstraction .enums .MCProfession ;
4
5
import com .laytonsmith .core .MSLog ;
5
6
import com .laytonsmith .core .Static ;
6
7
import com .laytonsmith .core .constructs .Target ;
8
+ import org .bukkit .Keyed ;
9
+ import org .bukkit .NamespacedKey ;
10
+ import org .bukkit .Registry ;
7
11
import org .bukkit .entity .Villager ;
8
12
9
13
import java .util .HashMap ;
14
+ import java .util .Locale ;
10
15
import java .util .Map ;
11
16
12
17
public class BukkitMCProfession extends MCProfession <Villager .Profession > {
@@ -19,14 +24,20 @@ public BukkitMCProfession(MCVanillaProfession vanillaProfession, Villager.Profes
19
24
20
25
@ Override
21
26
public String name () {
22
- return getAbstracted () == MCVanillaProfession .NONE ? getConcrete ().name () : getAbstracted ().name ();
27
+ if (getAbstracted () == MCVanillaProfession .UNKNOWN ) {
28
+ // changed from enum to interface in 1.21
29
+ NamespacedKey key = ReflectionUtils .invokeMethod (Keyed .class , getConcrete (), "getKey" );
30
+ return key .getKey ().toUpperCase (Locale .ROOT );
31
+ }
32
+ return getAbstracted ().name ();
23
33
}
24
34
25
35
public static MCProfession valueOfConcrete (Villager .Profession test ) {
26
36
MCProfession profession = BUKKIT_MAP .get (test );
27
37
if (profession == null ) {
38
+ NamespacedKey key = ReflectionUtils .invokeMethod (Keyed .class , test , "getKey" );
28
39
MSLog .GetLogger ().e (MSLog .Tags .GENERAL , "Bukkit Villager Profession missing in BUKKIT_MAP: "
29
- + test . name ( ), Target .UNKNOWN );
40
+ + key . getKey (). toUpperCase ( Locale . ROOT ), Target .UNKNOWN );
30
41
return new BukkitMCProfession (MCVanillaProfession .UNKNOWN , test );
31
42
}
32
43
return profession ;
@@ -48,15 +59,16 @@ public static void build() {
48
59
BUKKIT_MAP .put (profession , wrapper );
49
60
}
50
61
}
51
- for (Villager .Profession pr : Villager . Profession . values () ) {
62
+ for (Villager .Profession pr : Registry . VILLAGER_PROFESSION ) {
52
63
if (pr != null && !BUKKIT_MAP .containsKey (pr )) {
53
- MAP .put (pr .name (), new BukkitMCProfession (MCVanillaProfession .UNKNOWN , pr ));
64
+ NamespacedKey key = ReflectionUtils .invokeMethod (Keyed .class , pr , "getKey" );
65
+ MAP .put (key .getKey ().toUpperCase (Locale .ROOT ), new BukkitMCProfession (MCVanillaProfession .UNKNOWN , pr ));
54
66
BUKKIT_MAP .put (pr , new BukkitMCProfession (MCVanillaProfession .UNKNOWN , pr ));
55
67
}
56
68
}
57
69
}
58
70
59
71
private static Villager .Profession getBukkitType (MCVanillaProfession v ) {
60
- return Villager . Profession . valueOf ( v .name ());
72
+ return Registry . VILLAGER_PROFESSION . get ( NamespacedKey . minecraft ( v .name (). toLowerCase ( Locale . ROOT ) ));
61
73
}
62
74
}
0 commit comments