Add dedicated compat module for CB 1.7.5-R0.1.

This commit is contained in:
asofold 2014-04-14 22:40:06 +02:00
parent 1f0aafb63e
commit 2434c71d20
9 changed files with 361 additions and 24 deletions

View File

@ -31,7 +31,7 @@
</dependency>
</dependencies>
<description>Compatibility for CB2922 (MC 1.7.5).
<description>Compatibility for CB2922 (MC 1.7.2).
Version updating is done for the NoCheatPlus sub-module.</description>
</project>

37
NCPCompatCB3026/pom.xml Normal file
View File

@ -0,0 +1,37 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>fr.neatmonster</groupId>
<artifactId>ncpcompatcb3026</artifactId>
<packaging>jar</packaging>
<name>NCPCompatCB3026</name>
<version>static</version>
<parent>
<groupId>fr.neatmonster</groupId>
<artifactId>nocheatplus-parent</artifactId>
<version>static</version>
</parent>
<dependencies>
<dependency>
<groupId>fr.neatmonster</groupId>
<artifactId>ncpcore</artifactId>
<version>static</version>
</dependency>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
<version>1.7.5-R0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.7.5-R0.1-SNAPSHOT</version>
</dependency>
</dependencies>
<description>Compatibility for CB3026 (MC 1.7.5).
Version updating is done for the NoCheatPlus sub-module.</description>
</project>

View File

@ -0,0 +1,121 @@
package fr.neatmonster.nocheatplus.compat.cb3026;
import java.util.Iterator;
import java.util.List;
import net.minecraft.server.v1_7_R2.AxisAlignedBB;
import net.minecraft.server.v1_7_R2.Block;
import net.minecraft.server.v1_7_R2.EntityBoat;
import net.minecraft.server.v1_7_R2.IBlockAccess;
import net.minecraft.server.v1_7_R2.TileEntity;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_7_R2.CraftWorld;
import org.bukkit.craftbukkit.v1_7_R2.entity.CraftEntity;
import org.bukkit.entity.Entity;
import fr.neatmonster.nocheatplus.utilities.BlockCache;
public class BlockCacheCB3026 extends BlockCache implements IBlockAccess{
/** Box for one time use, no nesting, no extra storing this(!). */
protected static final AxisAlignedBB useBox = AxisAlignedBB.a(0, 0, 0, 0, 0, 0);
protected net.minecraft.server.v1_7_R2.WorldServer world;
public BlockCacheCB3026(World world) {
setAccess(world);
}
@Override
public void setAccess(World world) {
if (world != null) {
this.maxBlockY = world.getMaxHeight() - 1;
this.world = ((CraftWorld) world).getHandle();
} else {
this.world = null;
}
}
@Override
public int fetchTypeId(final int x, final int y, final int z) {
return world.getTypeId(x, y, z);
}
@Override
public int fetchData(final int x, final int y, final int z) {
return world.getData(x, y, z);
}
@Override
public double[] fetchBounds(final int x, final int y, final int z){
// TODO: change api for this / use nodes (!)
final int id = getTypeId(x, y, z);
final net.minecraft.server.v1_7_R2.Block block = net.minecraft.server.v1_7_R2.Block.e(id);
if (block == null) return null;
block.updateShape(this, x, y, z); // TODO: use THIS instead of world.
// minX, minY, minZ, maxX, maxY, maxZ
return new double[]{block.x(), block.z(), block.B(), block.y(), block.A(), block.C()};
}
@Override
public boolean standsOnEntity(final Entity entity, final double minX, final double minY, final double minZ, final double maxX, final double maxY, final double maxZ){
try{
// TODO: Probably check other ids too before doing this ?
final net.minecraft.server.v1_7_R2.Entity mcEntity = ((CraftEntity) entity).getHandle();
final AxisAlignedBB box = useBox.b(minX, minY, minZ, maxX, maxY, maxZ);
@SuppressWarnings("rawtypes")
final List list = world.getEntities(mcEntity, box);
@SuppressWarnings("rawtypes")
final Iterator iterator = list.iterator();
while (iterator.hasNext()) {
final net.minecraft.server.v1_7_R2.Entity other = (net.minecraft.server.v1_7_R2.Entity) iterator.next();
if (!(other instanceof EntityBoat)){ // && !(other instanceof EntityMinecart)) continue;
continue;
}
if (minY >= other.locY && minY - other.locY <= 0.7){
return true;
}
// Still check this for some reason.
final AxisAlignedBB otherBox = other.boundingBox;
if (box.a > otherBox.d || box.d < otherBox.a || box.b > otherBox.e || box.e < otherBox.b || box.c > otherBox.f || box.f < otherBox.c) continue;
else {
return true;
}
}
}
catch (Throwable t){
// Ignore exceptions (Context: DisguiseCraft).
}
return false;
}
/* (non-Javadoc)
* @see fr.neatmonster.nocheatplus.utilities.BlockCache#cleanup()
*/
@Override
public void cleanup() {
super.cleanup();
world = null;
}
@Override
public TileEntity getTileEntity(final int x, final int y, final int z) {
return world.getTileEntity(x, y, z);
}
@Override
public int getBlockPower(final int arg0, final int arg1, final int arg2, final int arg3) {
return world.getBlockPower(arg0, arg1, arg2, arg3);
}
@Override
public Block getType(int x, int y, int z) {
return world.getType(x, y, z);
}
}

View File

@ -0,0 +1,164 @@
package fr.neatmonster.nocheatplus.compat.cb3026;
import net.minecraft.server.v1_7_R2.AxisAlignedBB;
import net.minecraft.server.v1_7_R2.Block;
import net.minecraft.server.v1_7_R2.DamageSource;
import net.minecraft.server.v1_7_R2.EntityComplexPart;
import net.minecraft.server.v1_7_R2.EntityPlayer;
import net.minecraft.server.v1_7_R2.MobEffectList;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.command.CommandMap;
import org.bukkit.craftbukkit.v1_7_R2.CraftServer;
import org.bukkit.craftbukkit.v1_7_R2.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_7_R2.entity.CraftPlayer;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
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 MCAccessCB3026 implements MCAccess{
/**
* Constructor to let it fail.
*/
public MCAccessCB3026(){
getCommandMap();
ReflectionUtil.checkMembers("net.minecraft.server.v1_7_R2.", new String[]{"Entity" , "dead"});
// block bounds, original: minX, maxX, minY, maxY, minZ, maxZ
ReflectionUtil.checkMethodReturnTypesNoArgs(net.minecraft.server.v1_7_R2.Block.class,
new String[]{"x", "y", "z", "A", "B", "C"}, double.class);
// TODO: Nail it down further.
}
@Override
public String getMCVersion() {
// 1_7_R2
return "1.7.5";
}
@Override
public String getServerVersionTag() {
return "CB3026";
}
@Override
public CommandMap getCommandMap() {
return ((CraftServer) Bukkit.getServer()).getCommandMap();
}
@Override
public BlockCache getBlockCache(final World world) {
return new BlockCacheCB3026(world);
}
@Override
public double getHeight(final Entity entity) {
final net.minecraft.server.v1_7_R2.Entity mcEntity = ((CraftEntity) entity).getHandle();
final double entityHeight = Math.max(mcEntity.length, Math.max(mcEntity.height, mcEntity.boundingBox.e - mcEntity.boundingBox.b));
if (entity instanceof LivingEntity) {
return Math.max(((LivingEntity) entity).getEyeHeight(), entityHeight);
} else return entityHeight;
}
@Override
public AlmostBoolean isBlockSolid(final int id) {
final Block block = Block.e(id);
if (block == null || block.getMaterial() == null) return AlmostBoolean.MAYBE;
else return AlmostBoolean.match(block.getMaterial().isSolid());
}
@Override
public AlmostBoolean isBlockLiquid(final int id) {
final Block block = Block.e(id);
if (block == null || block.getMaterial() == null) return AlmostBoolean.MAYBE;
else return AlmostBoolean.match(block.getMaterial().isLiquid());
}
@Override
public double getWidth(final Entity entity) {
return ((CraftEntity) entity).getHandle().width;
}
@Override
public AlmostBoolean isIllegalBounds(final Player player) {
final EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle();
if (entityPlayer.dead) return AlmostBoolean.NO;
// TODO: Does this need a method call for the "real" box? Might be no problem during moving events, though.
final AxisAlignedBB box = entityPlayer.boundingBox;
if (!entityPlayer.isSleeping()){
// This can not really test stance but height of bounding box.
final double dY = Math.abs(box.e - box.b);
if (dY > 1.8) return AlmostBoolean.YES; // dY > 1.65D ||
if (dY < 0.1D && entityPlayer.length >= 0.1) return AlmostBoolean.YES;
}
return AlmostBoolean.MAYBE;
}
@Override
public double getJumpAmplifier(final Player player) {
final net.minecraft.server.v1_7_R2.EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle();
if (mcPlayer.hasEffect(MobEffectList.JUMP)) return mcPlayer.getEffect(MobEffectList.JUMP).getAmplifier();
else return Double.NEGATIVE_INFINITY;
}
@Override
public double getFasterMovementAmplifier(final Player player) {
final net.minecraft.server.v1_7_R2.EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle();
if (mcPlayer.hasEffect(MobEffectList.FASTER_MOVEMENT)) return mcPlayer.getEffect(MobEffectList.FASTER_MOVEMENT).getAmplifier();
else return Double.NEGATIVE_INFINITY;
}
@Override
public int getInvulnerableTicks(final Player player) {
return ((CraftPlayer) player).getHandle().invulnerableTicks;
}
@Override
public void setInvulnerableTicks(final Player player, final int ticks) {
((CraftPlayer) player).getHandle().invulnerableTicks = ticks;
}
@Override
public void dealFallDamage(final Player player, final double damage) {
((CraftPlayer) player).getHandle().damageEntity(DamageSource.FALL, (float) damage);
}
@Override
public boolean isComplexPart(final Entity entity) {
return ((CraftEntity) entity).getHandle() instanceof EntityComplexPart;
}
@Override
public boolean shouldBeZombie(final Player player) {
final net.minecraft.server.v1_7_R2.EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle();
return !mcPlayer.dead && mcPlayer.getHealth() <= 0.0f ;
}
@Override
public void setDead(final Player player, final int deathTicks) {
final net.minecraft.server.v1_7_R2.EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle();
mcPlayer.deathTicks = deathTicks;
mcPlayer.dead = true;
}
@Override
public long getKeepAliveTime(final Player player) {
// TODO: Implement if possible.
return Long.MIN_VALUE;
}
@Override
public boolean hasGravity(final Material mat) {
// TODO: Test/check.
return mat.hasGravity();
}
}

View File

@ -45,7 +45,7 @@ public class MCAccessCBDev implements MCAccess{
@Override
public String getServerVersionTag() {
return "CB2922-DEV";
return "CB3026-DEV";
}
@Override

View File

@ -83,6 +83,11 @@
<artifactId>ncpcompatcb2922</artifactId>
<version>static</version>
</dependency>
<dependency>
<groupId>fr.neatmonster</groupId>
<artifactId>ncpcompatcb3026</artifactId>
<version>static</version>
</dependency>
<dependency>
<groupId>fr.neatmonster</groupId>
<artifactId>ncpcompatcbdev</artifactId>

View File

@ -16,7 +16,7 @@ import fr.neatmonster.nocheatplus.compat.cb2794.MCAccessCB2794;
import fr.neatmonster.nocheatplus.compat.cb2808.MCAccessCB2808;
import fr.neatmonster.nocheatplus.compat.cb2882.MCAccessCB2882;
import fr.neatmonster.nocheatplus.compat.cb2922.MCAccessCB2922;
import fr.neatmonster.nocheatplus.compat.cbdev.MCAccessCBDev;
import fr.neatmonster.nocheatplus.compat.cb3026.MCAccessCB3026;
import fr.neatmonster.nocheatplus.config.ConfPaths;
import fr.neatmonster.nocheatplus.config.ConfigManager;
import fr.neatmonster.nocheatplus.logging.LogUtil;
@ -38,7 +38,7 @@ public class MCAccessFactory {
* @return MCAccess instance.
* @throws RuntimeException if no access can be set.
*/
public MCAccess getMCAccess(){
public MCAccess getMCAccess() {
return getMCAccess(ConfigManager.getConfigFile().getBoolean(ConfPaths.COMPATIBILITY_BUKKITONLY));
}
@ -48,28 +48,36 @@ public class MCAccessFactory {
* @return
* @throws RuntimeException if no access can be set.
*/
public MCAccess getMCAccess(final boolean bukkitOnly){
public MCAccess getMCAccess(final boolean bukkitOnly) {
final List<Throwable> throwables = new ArrayList<Throwable>();
// Try to set up native access.
if (!bukkitOnly){
if (!bukkitOnly) {
// TEMP //
// Only add as long as no stable module has been added.
// 1.7.5
// try{
// return new MCAccessCBDev();
// }
// catch(Throwable t) {
// throwables.add(t);
// };
// TEMP END //
// 1.7.5
try{
return new MCAccessCBDev();
return new MCAccessCB3026();
}
catch(Throwable t){
catch(Throwable t) {
throwables.add(t);
};
// TEMP END //
// 1.7.2
try{
return new MCAccessCB2922();
}
catch(Throwable t){
catch(Throwable t) {
throwables.add(t);
};
@ -77,7 +85,7 @@ public class MCAccessFactory {
try{
return new MCAccessCB2882();
}
catch(Throwable t){
catch(Throwable t) {
throwables.add(t);
};
@ -85,7 +93,7 @@ public class MCAccessFactory {
try{
return new MCAccessCB2808();
}
catch(Throwable t){
catch(Throwable t) {
throwables.add(t);
};
@ -93,7 +101,7 @@ public class MCAccessFactory {
try{
return new MCAccessCB2794();
}
catch(Throwable t){
catch(Throwable t) {
throwables.add(t);
};
@ -101,7 +109,7 @@ public class MCAccessFactory {
try{
return new MCAccessCB2763();
}
catch(Throwable t){
catch(Throwable t) {
throwables.add(t);
};
@ -109,7 +117,7 @@ public class MCAccessFactory {
try{
return new MCAccessCB2691();
}
catch(Throwable t){
catch(Throwable t) {
throwables.add(t);
};
@ -117,7 +125,7 @@ public class MCAccessFactory {
try{
return new MCAccessCB2645();
}
catch(Throwable t){
catch(Throwable t) {
throwables.add(t);
};
@ -125,7 +133,7 @@ public class MCAccessFactory {
try{
return new MCAccessCB2602();
}
catch(Throwable t){
catch(Throwable t) {
throwables.add(t);
};
@ -133,7 +141,7 @@ public class MCAccessFactory {
try{
return new MCAccessCB2545();
}
catch(Throwable t){
catch(Throwable t) {
throwables.add(t);
};
@ -141,7 +149,7 @@ public class MCAccessFactory {
try{
return new MCAccessCB2512();
}
catch(Throwable t){
catch(Throwable t) {
throwables.add(t);
};
@ -150,12 +158,12 @@ public class MCAccessFactory {
// Try to set up api-only access (since 1.4.6).
try{
final String msg;
if (bukkitOnly){
if (bukkitOnly) {
msg = "[NoCheatPlus] The plugin is configured for Bukkit-API-only access.";
}
else{
msg = "[NoCheatPlus] Could not set up native access for the server-mod (" + Bukkit.getServer().getVersion() + "). Please check for updates and consider to request support.";
for (String uMsg : updateLocs){
for (String uMsg : updateLocs) {
LogUtil.logWarning(uMsg);
}
}
@ -164,18 +172,18 @@ public class MCAccessFactory {
LogUtil.logWarning("[NoCheatPlus] Bukkit-API-only access: Some features will likely not function properly, performance might suffer.");
return mcAccess;
}
catch(Throwable t){
catch(Throwable t) {
throwables.add(t);
};
// All went wrong.
// TODO: Fall-back solution (disable plugin, disable checks).
LogUtil.logSevere("[NoCheatPlus] Your version of NoCheatPlus is not compatible with the version of the server-mod (" + Bukkit.getServer().getVersion() + "). Please check for updates and consider to request support.");
for (String msg : updateLocs){
for (String msg : updateLocs) {
LogUtil.logSevere(msg);
}
LogUtil.logSevere("[NoCheatPlus] >>> Failed to set up MCAccess <<<");
for (Throwable t : throwables ){
for (Throwable t : throwables ) {
LogUtil.logSevere(t);
}
// TODO: Schedule disabling the plugin or running in circles.

View File

@ -79,6 +79,7 @@
<include>fr.neatmonster:ncpcompatcb2808</include>
<include>fr.neatmonster:ncpcompatcb2882</include>
<include>fr.neatmonster:ncpcompatcb2922</include>
<include>fr.neatmonster:ncpcompatcb3026</include>
<include>fr.neatmonster:ncpcompatcbdev</include>
<include>fr.neatmonster:ncpplugin</include>
<!-- <include>fr.neatmonster:nocheatplus-parent</include> -->

View File

@ -28,6 +28,7 @@
<module>NCPCompatCB2808</module>
<module>NCPCompatCB2882</module>
<module>NCPCompatCB2922</module>
<module>NCPCompatCB3026</module>
<module>NCPCompatCBDev</module>
<module>NCPPlugin</module>
<module>NoCheatPlus</module>