Add class-member checks for failing constructors (compat).

This commit is contained in:
asofold 2013-01-24 21:38:31 +01:00
parent f485fc7a2d
commit 940e7d83e3
6 changed files with 39 additions and 0 deletions

View File

@ -32,6 +32,10 @@ public interface MCAccess {
*/
public String getServerVersionTag();
/**
* Get the servers command map.
* @return MAy rturn null if not supported.
*/
public CommandMap getCommandMap();
/**

View File

@ -0,0 +1,27 @@
package fr.neatmonster.nocheatplus.utilities;
public class ReflectionUtil {
/**
* Convenience method to check if members exist and fail if not.
* @param prefix
* @param specs
* @throws RuntimeException
*/
public static void checkMembers(String prefix, String[]... specs){
try {
for (String[] spec : specs){
Class<?> clazz = Class.forName(prefix + spec[0]);
for (int i = 1; i < spec.length; i++){
if (clazz.getField(spec[i]) == null) throw new NoSuchFieldException(prefix + spec[0] + " : " + spec[i]);
}
}
} catch (SecurityException e) {
// Let this one pass.
//throw new RuntimeException(e);
} catch (Throwable t) {
throw new RuntimeException(t);
}
}
}

View File

@ -20,6 +20,7 @@ import org.bukkit.entity.Player;
import fr.neatmonster.nocheatplus.compat.AlmostBoolean;
import fr.neatmonster.nocheatplus.compat.MCAccess;
import fr.neatmonster.nocheatplus.utilities.BlockCache;
import fr.neatmonster.nocheatplus.utilities.ReflectionUtil;
public class MCAccessCB2511 implements MCAccess {
@ -29,6 +30,7 @@ public class MCAccessCB2511 implements MCAccess {
*/
public MCAccessCB2511(){
getCommandMap();
ReflectionUtil.checkMembers("net.minecraft.server.", new String[]{"Entity" , "dead"});
}
@Override

View File

@ -20,6 +20,7 @@ import org.bukkit.entity.Player;
import fr.neatmonster.nocheatplus.compat.AlmostBoolean;
import fr.neatmonster.nocheatplus.compat.MCAccess;
import fr.neatmonster.nocheatplus.utilities.BlockCache;
import fr.neatmonster.nocheatplus.utilities.ReflectionUtil;
public class MCAccessCB2512 implements MCAccess{
@ -28,6 +29,7 @@ public class MCAccessCB2512 implements MCAccess{
*/
public MCAccessCB2512(){
getCommandMap();
ReflectionUtil.checkMembers("net.minecraft.server.v1_4_5.", new String[]{"Entity" , "dead"});
}
@Override

View File

@ -20,6 +20,7 @@ import org.bukkit.entity.Player;
import fr.neatmonster.nocheatplus.compat.AlmostBoolean;
import fr.neatmonster.nocheatplus.compat.MCAccess;
import fr.neatmonster.nocheatplus.utilities.BlockCache;
import fr.neatmonster.nocheatplus.utilities.ReflectionUtil;
public class MCAccessCB2545 implements MCAccess{
@ -28,6 +29,7 @@ public class MCAccessCB2545 implements MCAccess{
*/
public MCAccessCB2545(){
getCommandMap();
ReflectionUtil.checkMembers("net.minecraft.server.v1_4_6.", new String[]{"Entity" , "dead"});
}
@Override

View File

@ -20,6 +20,7 @@ import org.bukkit.entity.Player;
import fr.neatmonster.nocheatplus.compat.AlmostBoolean;
import fr.neatmonster.nocheatplus.compat.MCAccess;
import fr.neatmonster.nocheatplus.utilities.BlockCache;
import fr.neatmonster.nocheatplus.utilities.ReflectionUtil;
public class MCAccessCBDev implements MCAccess{
@ -28,6 +29,7 @@ public class MCAccessCBDev implements MCAccess{
*/
public MCAccessCBDev(){
getCommandMap();
ReflectionUtil.checkMembers("net.minecraft.server.v1_4_R1.", new String[]{"Entity" , "dead"});
}
@Override