mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2025-01-13 19:11:22 +01:00
Add class-member checks for failing constructors (compat).
This commit is contained in:
parent
f485fc7a2d
commit
940e7d83e3
@ -32,6 +32,10 @@ public interface MCAccess {
|
|||||||
*/
|
*/
|
||||||
public String getServerVersionTag();
|
public String getServerVersionTag();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the servers command map.
|
||||||
|
* @return MAy rturn null if not supported.
|
||||||
|
*/
|
||||||
public CommandMap getCommandMap();
|
public CommandMap getCommandMap();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -20,6 +20,7 @@ import org.bukkit.entity.Player;
|
|||||||
import fr.neatmonster.nocheatplus.compat.AlmostBoolean;
|
import fr.neatmonster.nocheatplus.compat.AlmostBoolean;
|
||||||
import fr.neatmonster.nocheatplus.compat.MCAccess;
|
import fr.neatmonster.nocheatplus.compat.MCAccess;
|
||||||
import fr.neatmonster.nocheatplus.utilities.BlockCache;
|
import fr.neatmonster.nocheatplus.utilities.BlockCache;
|
||||||
|
import fr.neatmonster.nocheatplus.utilities.ReflectionUtil;
|
||||||
|
|
||||||
|
|
||||||
public class MCAccessCB2511 implements MCAccess {
|
public class MCAccessCB2511 implements MCAccess {
|
||||||
@ -29,6 +30,7 @@ public class MCAccessCB2511 implements MCAccess {
|
|||||||
*/
|
*/
|
||||||
public MCAccessCB2511(){
|
public MCAccessCB2511(){
|
||||||
getCommandMap();
|
getCommandMap();
|
||||||
|
ReflectionUtil.checkMembers("net.minecraft.server.", new String[]{"Entity" , "dead"});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -20,6 +20,7 @@ import org.bukkit.entity.Player;
|
|||||||
import fr.neatmonster.nocheatplus.compat.AlmostBoolean;
|
import fr.neatmonster.nocheatplus.compat.AlmostBoolean;
|
||||||
import fr.neatmonster.nocheatplus.compat.MCAccess;
|
import fr.neatmonster.nocheatplus.compat.MCAccess;
|
||||||
import fr.neatmonster.nocheatplus.utilities.BlockCache;
|
import fr.neatmonster.nocheatplus.utilities.BlockCache;
|
||||||
|
import fr.neatmonster.nocheatplus.utilities.ReflectionUtil;
|
||||||
|
|
||||||
public class MCAccessCB2512 implements MCAccess{
|
public class MCAccessCB2512 implements MCAccess{
|
||||||
|
|
||||||
@ -28,6 +29,7 @@ public class MCAccessCB2512 implements MCAccess{
|
|||||||
*/
|
*/
|
||||||
public MCAccessCB2512(){
|
public MCAccessCB2512(){
|
||||||
getCommandMap();
|
getCommandMap();
|
||||||
|
ReflectionUtil.checkMembers("net.minecraft.server.v1_4_5.", new String[]{"Entity" , "dead"});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -20,6 +20,7 @@ import org.bukkit.entity.Player;
|
|||||||
import fr.neatmonster.nocheatplus.compat.AlmostBoolean;
|
import fr.neatmonster.nocheatplus.compat.AlmostBoolean;
|
||||||
import fr.neatmonster.nocheatplus.compat.MCAccess;
|
import fr.neatmonster.nocheatplus.compat.MCAccess;
|
||||||
import fr.neatmonster.nocheatplus.utilities.BlockCache;
|
import fr.neatmonster.nocheatplus.utilities.BlockCache;
|
||||||
|
import fr.neatmonster.nocheatplus.utilities.ReflectionUtil;
|
||||||
|
|
||||||
public class MCAccessCB2545 implements MCAccess{
|
public class MCAccessCB2545 implements MCAccess{
|
||||||
|
|
||||||
@ -28,6 +29,7 @@ public class MCAccessCB2545 implements MCAccess{
|
|||||||
*/
|
*/
|
||||||
public MCAccessCB2545(){
|
public MCAccessCB2545(){
|
||||||
getCommandMap();
|
getCommandMap();
|
||||||
|
ReflectionUtil.checkMembers("net.minecraft.server.v1_4_6.", new String[]{"Entity" , "dead"});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -20,6 +20,7 @@ import org.bukkit.entity.Player;
|
|||||||
import fr.neatmonster.nocheatplus.compat.AlmostBoolean;
|
import fr.neatmonster.nocheatplus.compat.AlmostBoolean;
|
||||||
import fr.neatmonster.nocheatplus.compat.MCAccess;
|
import fr.neatmonster.nocheatplus.compat.MCAccess;
|
||||||
import fr.neatmonster.nocheatplus.utilities.BlockCache;
|
import fr.neatmonster.nocheatplus.utilities.BlockCache;
|
||||||
|
import fr.neatmonster.nocheatplus.utilities.ReflectionUtil;
|
||||||
|
|
||||||
public class MCAccessCBDev implements MCAccess{
|
public class MCAccessCBDev implements MCAccess{
|
||||||
|
|
||||||
@ -28,6 +29,7 @@ public class MCAccessCBDev implements MCAccess{
|
|||||||
*/
|
*/
|
||||||
public MCAccessCBDev(){
|
public MCAccessCBDev(){
|
||||||
getCommandMap();
|
getCommandMap();
|
||||||
|
ReflectionUtil.checkMembers("net.minecraft.server.v1_4_R1.", new String[]{"Entity" , "dead"});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user