Fixes for MCPC / Cauldron / Thermos

This commit is contained in:
Dan Mulloy 2016-07-26 20:44:08 -04:00
parent 421db9f02a
commit d78e00f80f
3 changed files with 31 additions and 21 deletions

View File

@ -33,14 +33,14 @@ class LoginPackets {
clientSide.add(Packets.Client.GET_INFO);
// In 1.6.2, Minecraft started sending CUSTOM_PAYLOAD in the server list protocol
if (version.compareTo(MinecraftVersion.HORSE_UPDATE) >= 0) {
if (version.compareTo(MinecraftVersion.HORSE_UPDATE) >= 0 || triesForgeIntegration()) {
clientSide.add(Packets.Client.CUSTOM_PAYLOAD);
}
serverSide.add(Packets.Server.KICK_DISCONNECT);
// MCPC++ contains Forge, which uses packet 250 during login
if (isMCPC()) {
clientSide.add(Packets.Client.CUSTOM_PAYLOAD);
// Forge uses packet 250 during login
if (triesForgeIntegration()) {
serverSide.add(Packets.Client.CUSTOM_PAYLOAD);
}
}
@ -48,8 +48,9 @@ class LoginPackets {
* Determine if we are runnign MCPC.
* @return TRUE if we are, FALSE otherwise.
*/
private static boolean isMCPC() {
return Bukkit.getServer().getVersion().contains("MCPC-Plus");
private static boolean triesForgeIntegration() {
String version = Bukkit.getVersion();
return version.contains("MCPC-Plus") || version.contains("Cauldron") || version.contains("Thermos");
}
/**

View File

@ -66,8 +66,8 @@ import com.comphenix.protocol.reflect.fuzzy.FuzzyClassContract;
import com.comphenix.protocol.reflect.fuzzy.FuzzyFieldContract;
import com.comphenix.protocol.reflect.fuzzy.FuzzyMatchers;
import com.comphenix.protocol.reflect.fuzzy.FuzzyMethodContract;
import com.comphenix.protocol.utility.RemappedClassSource.RemapperUnavaibleException;
import com.comphenix.protocol.utility.RemappedClassSource.RemapperUnavaibleException.Reason;
import com.comphenix.protocol.utility.RemappedClassSource.RemapperUnavailableException;
import com.comphenix.protocol.utility.RemappedClassSource.RemapperUnavailableException.Reason;
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
import com.comphenix.protocol.wrappers.nbt.NbtFactory;
import com.comphenix.protocol.wrappers.nbt.NbtType;
@ -1954,7 +1954,7 @@ public class MinecraftReflection {
// Attempt to use MCPC
try {
return classSource = new RemappedClassSource().initialize();
} catch (RemapperUnavaibleException e) {
} catch (RemapperUnavailableException e) {
if (e.getReason() != Reason.MCPC_NOT_PRESENT)
reporter.reportWarning(MinecraftReflection.class, Report.newBuilder(REPORT_CANNOT_FIND_MCPC_REMAPPER));
} catch (Exception e) {

View File

@ -27,7 +27,7 @@ import org.bukkit.Bukkit;
import com.comphenix.protocol.reflect.FieldUtils;
import com.comphenix.protocol.reflect.MethodUtils;
import com.comphenix.protocol.utility.RemappedClassSource.RemapperUnavaibleException.Reason;
import com.comphenix.protocol.utility.RemappedClassSource.RemapperUnavailableException.Reason;
class RemappedClassSource extends ClassSource {
private Object classRemapper;
@ -52,19 +52,23 @@ class RemappedClassSource extends ClassSource {
/**
* Attempt to load the MCPC remapper.
* @return TRUE if we succeeded, FALSE otherwise.
* @throws RemapperUnavaibleException If the remapper is not present.
* @throws RemapperUnavailableException If the remapper is not present.
*/
public RemappedClassSource initialize() {
try {
if (Bukkit.getServer() == null || !Bukkit.getServer().getVersion().contains("MCPC-Plus")) {
throw new RemapperUnavaibleException(Reason.MCPC_NOT_PRESENT);
if (Bukkit.getServer() == null) {
throw new RemapperUnavailableException(Reason.BUKKIT_NOT_INIT);
}
// Obtain the Class remapper used by MCPC+
if (!triesForgeIntegration(Bukkit.getVersion())) {
throw new RemapperUnavailableException(Reason.MCPC_NOT_PRESENT);
}
// Obtain the Class remapper used by MCPC+/Cauldron/What have you
this.classRemapper = FieldUtils.readField(getClass().getClassLoader(), "remapper", true);
if (this.classRemapper == null) {
throw new RemapperUnavaibleException(Reason.REMAPPER_DISABLED);
throw new RemapperUnavailableException(Reason.REMAPPER_DISABLED);
}
// Initialize some fields and methods used by the Jar Remapper
@ -75,7 +79,7 @@ class RemappedClassSource extends ClassSource {
return this;
} catch (RemapperUnavaibleException e) {
} catch (RemapperUnavailableException e) {
throw e;
} catch (Exception e) {
// Damn it
@ -83,6 +87,10 @@ class RemappedClassSource extends ClassSource {
}
}
private boolean triesForgeIntegration(String version) {
return version.contains("MCPC") || version.contains("Cauldron") || version.contains("Thermos");
}
@Override
public Class<?> loadClass(String canonicalName) throws ClassNotFoundException {
final String remapped = getClassName(canonicalName);
@ -108,12 +116,13 @@ class RemappedClassSource extends ClassSource {
}
}
public static class RemapperUnavaibleException extends RuntimeException {
public static class RemapperUnavailableException extends RuntimeException {
private static final long serialVersionUID = 1L;
public enum Reason {
MCPC_NOT_PRESENT("The server is not running MCPC+"),
REMAPPER_DISABLED("Running an MCPC+ server but the remapper is unavailable. Please turn it on!");
BUKKIT_NOT_INIT("Bukkit is not initialized"),
MCPC_NOT_PRESENT("The server is not running Forge+Bukkit"),
REMAPPER_DISABLED("Running a Forge+Bukkit server but the remapper is unavailable. Please turn it on!");
private final String message;
@ -132,13 +141,13 @@ class RemappedClassSource extends ClassSource {
private final Reason reason;
public RemapperUnavaibleException(Reason reason) {
public RemapperUnavailableException(Reason reason) {
super(reason.getMessage());
this.reason = reason;
}
/**
* Retrieve the reasont he remapper is unavailable.
* Retrieve the reason the remapper is unavailable.
* @return The reason.
*/
public Reason getReason() {