Skip to content

Commit d78e00f

Browse files
committed
Fixes for MCPC / Cauldron / Thermos
1 parent 421db9f commit d78e00f

File tree

3 files changed

+31
-21
lines changed

3 files changed

+31
-21
lines changed

ProtocolLib/src/main/java/com/comphenix/protocol/injector/LoginPackets.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,24 @@ public LoginPackets(MinecraftVersion version) {
3333
clientSide.add(Packets.Client.GET_INFO);
3434

3535
// In 1.6.2, Minecraft started sending CUSTOM_PAYLOAD in the server list protocol
36-
if (version.compareTo(MinecraftVersion.HORSE_UPDATE) >= 0) {
36+
if (version.compareTo(MinecraftVersion.HORSE_UPDATE) >= 0 || triesForgeIntegration()) {
3737
clientSide.add(Packets.Client.CUSTOM_PAYLOAD);
3838
}
3939
serverSide.add(Packets.Server.KICK_DISCONNECT);
4040

41-
// MCPC++ contains Forge, which uses packet 250 during login
42-
if (isMCPC()) {
43-
clientSide.add(Packets.Client.CUSTOM_PAYLOAD);
41+
// Forge uses packet 250 during login
42+
if (triesForgeIntegration()) {
43+
serverSide.add(Packets.Client.CUSTOM_PAYLOAD);
4444
}
4545
}
4646

4747
/**
4848
* Determine if we are runnign MCPC.
4949
* @return TRUE if we are, FALSE otherwise.
5050
*/
51-
private static boolean isMCPC() {
52-
return Bukkit.getServer().getVersion().contains("MCPC-Plus");
51+
private static boolean triesForgeIntegration() {
52+
String version = Bukkit.getVersion();
53+
return version.contains("MCPC-Plus") || version.contains("Cauldron") || version.contains("Thermos");
5354
}
5455

5556
/**

ProtocolLib/src/main/java/com/comphenix/protocol/utility/MinecraftReflection.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@
6666
import com.comphenix.protocol.reflect.fuzzy.FuzzyFieldContract;
6767
import com.comphenix.protocol.reflect.fuzzy.FuzzyMatchers;
6868
import com.comphenix.protocol.reflect.fuzzy.FuzzyMethodContract;
69-
import com.comphenix.protocol.utility.RemappedClassSource.RemapperUnavaibleException;
70-
import com.comphenix.protocol.utility.RemappedClassSource.RemapperUnavaibleException.Reason;
69+
import com.comphenix.protocol.utility.RemappedClassSource.RemapperUnavailableException;
70+
import com.comphenix.protocol.utility.RemappedClassSource.RemapperUnavailableException.Reason;
7171
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
7272
import com.comphenix.protocol.wrappers.nbt.NbtFactory;
7373
import com.comphenix.protocol.wrappers.nbt.NbtType;
@@ -1954,7 +1954,7 @@ private static ClassSource getClassSource() {
19541954
// Attempt to use MCPC
19551955
try {
19561956
return classSource = new RemappedClassSource().initialize();
1957-
} catch (RemapperUnavaibleException e) {
1957+
} catch (RemapperUnavailableException e) {
19581958
if (e.getReason() != Reason.MCPC_NOT_PRESENT)
19591959
reporter.reportWarning(MinecraftReflection.class, Report.newBuilder(REPORT_CANNOT_FIND_MCPC_REMAPPER));
19601960
} catch (Exception e) {

ProtocolLib/src/main/java/com/comphenix/protocol/utility/RemappedClassSource.java

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
import com.comphenix.protocol.reflect.FieldUtils;
2929
import com.comphenix.protocol.reflect.MethodUtils;
30-
import com.comphenix.protocol.utility.RemappedClassSource.RemapperUnavaibleException.Reason;
30+
import com.comphenix.protocol.utility.RemappedClassSource.RemapperUnavailableException.Reason;
3131

3232
class RemappedClassSource extends ClassSource {
3333
private Object classRemapper;
@@ -52,19 +52,23 @@ public RemappedClassSource(ClassLoader loader) {
5252
/**
5353
* Attempt to load the MCPC remapper.
5454
* @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.
5656
*/
5757
public RemappedClassSource initialize() {
5858
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);
6161
}
6262

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
6468
this.classRemapper = FieldUtils.readField(getClass().getClassLoader(), "remapper", true);
6569

6670
if (this.classRemapper == null) {
67-
throw new RemapperUnavaibleException(Reason.REMAPPER_DISABLED);
71+
throw new RemapperUnavailableException(Reason.REMAPPER_DISABLED);
6872
}
6973

7074
// Initialize some fields and methods used by the Jar Remapper
@@ -75,14 +79,18 @@ public RemappedClassSource initialize() {
7579

7680
return this;
7781

78-
} catch (RemapperUnavaibleException e) {
82+
} catch (RemapperUnavailableException e) {
7983
throw e;
8084
} catch (Exception e) {
8185
// Damn it
8286
throw new RuntimeException("Cannot access MCPC remapper.", e);
8387
}
8488
}
8589

90+
private boolean triesForgeIntegration(String version) {
91+
return version.contains("MCPC") || version.contains("Cauldron") || version.contains("Thermos");
92+
}
93+
8694
@Override
8795
public Class<?> loadClass(String canonicalName) throws ClassNotFoundException {
8896
final String remapped = getClassName(canonicalName);
@@ -108,12 +116,13 @@ public String getClassName(String path) {
108116
}
109117
}
110118

111-
public static class RemapperUnavaibleException extends RuntimeException {
119+
public static class RemapperUnavailableException extends RuntimeException {
112120
private static final long serialVersionUID = 1L;
113121

114122
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!");
117126

118127
private final String message;
119128

@@ -132,13 +141,13 @@ public String getMessage() {
132141

133142
private final Reason reason;
134143

135-
public RemapperUnavaibleException(Reason reason) {
144+
public RemapperUnavailableException(Reason reason) {
136145
super(reason.getMessage());
137146
this.reason = reason;
138147
}
139148

140149
/**
141-
* Retrieve the reasont he remapper is unavailable.
150+
* Retrieve the reason the remapper is unavailable.
142151
* @return The reason.
143152
*/
144153
public Reason getReason() {

0 commit comments

Comments
 (0)