27
27
28
28
import com .comphenix .protocol .reflect .FieldUtils ;
29
29
import com .comphenix .protocol .reflect .MethodUtils ;
30
- import com .comphenix .protocol .utility .RemappedClassSource .RemapperUnavaibleException .Reason ;
30
+ import com .comphenix .protocol .utility .RemappedClassSource .RemapperUnavailableException .Reason ;
31
31
32
32
class RemappedClassSource extends ClassSource {
33
33
private Object classRemapper ;
@@ -52,19 +52,23 @@ public RemappedClassSource(ClassLoader loader) {
52
52
/**
53
53
* Attempt to load the MCPC remapper.
54
54
* @return TRUE if we succeeded, FALSE otherwise.
55
- * @throws RemapperUnavaibleException If the remapper is not present.
55
+ * @throws RemapperUnavailableException If the remapper is not present.
56
56
*/
57
57
public RemappedClassSource initialize () {
58
58
try {
59
- if (Bukkit .getServer () == null || ! Bukkit . getServer (). getVersion (). contains ( "MCPC-Plus" ) ) {
60
- throw new RemapperUnavaibleException (Reason .MCPC_NOT_PRESENT );
59
+ if (Bukkit .getServer () == null ) {
60
+ throw new RemapperUnavailableException (Reason .BUKKIT_NOT_INIT );
61
61
}
62
62
63
- // Obtain the Class remapper used by MCPC+
63
+ if (!triesForgeIntegration (Bukkit .getVersion ())) {
64
+ throw new RemapperUnavailableException (Reason .MCPC_NOT_PRESENT );
65
+ }
66
+
67
+ // Obtain the Class remapper used by MCPC+/Cauldron/What have you
64
68
this .classRemapper = FieldUtils .readField (getClass ().getClassLoader (), "remapper" , true );
65
69
66
70
if (this .classRemapper == null ) {
67
- throw new RemapperUnavaibleException (Reason .REMAPPER_DISABLED );
71
+ throw new RemapperUnavailableException (Reason .REMAPPER_DISABLED );
68
72
}
69
73
70
74
// Initialize some fields and methods used by the Jar Remapper
@@ -75,14 +79,18 @@ public RemappedClassSource initialize() {
75
79
76
80
return this ;
77
81
78
- } catch (RemapperUnavaibleException e ) {
82
+ } catch (RemapperUnavailableException e ) {
79
83
throw e ;
80
84
} catch (Exception e ) {
81
85
// Damn it
82
86
throw new RuntimeException ("Cannot access MCPC remapper." , e );
83
87
}
84
88
}
85
89
90
+ private boolean triesForgeIntegration (String version ) {
91
+ return version .contains ("MCPC" ) || version .contains ("Cauldron" ) || version .contains ("Thermos" );
92
+ }
93
+
86
94
@ Override
87
95
public Class <?> loadClass (String canonicalName ) throws ClassNotFoundException {
88
96
final String remapped = getClassName (canonicalName );
@@ -108,12 +116,13 @@ public String getClassName(String path) {
108
116
}
109
117
}
110
118
111
- public static class RemapperUnavaibleException extends RuntimeException {
119
+ public static class RemapperUnavailableException extends RuntimeException {
112
120
private static final long serialVersionUID = 1L ;
113
121
114
122
public enum Reason {
115
- MCPC_NOT_PRESENT ("The server is not running MCPC+" ),
116
- REMAPPER_DISABLED ("Running an MCPC+ server but the remapper is unavailable. Please turn it on!" );
123
+ BUKKIT_NOT_INIT ("Bukkit is not initialized" ),
124
+ MCPC_NOT_PRESENT ("The server is not running Forge+Bukkit" ),
125
+ REMAPPER_DISABLED ("Running a Forge+Bukkit server but the remapper is unavailable. Please turn it on!" );
117
126
118
127
private final String message ;
119
128
@@ -132,13 +141,13 @@ public String getMessage() {
132
141
133
142
private final Reason reason ;
134
143
135
- public RemapperUnavaibleException (Reason reason ) {
144
+ public RemapperUnavailableException (Reason reason ) {
136
145
super (reason .getMessage ());
137
146
this .reason = reason ;
138
147
}
139
148
140
149
/**
141
- * Retrieve the reasont he remapper is unavailable.
150
+ * Retrieve the reason the remapper is unavailable.
142
151
* @return The reason.
143
152
*/
144
153
public Reason getReason () {
0 commit comments