From 003e104ef429a986af94105ce6a170fb5b192397 Mon Sep 17 00:00:00 2001 From: asofold Date: Fri, 12 Apr 2013 19:00:19 +0200 Subject: [PATCH] Add module for CB2691 to match the beta release of CraftBukkit. The dev module will compile with 1.5.1-R0.2 but not be used for the moment. --- NCPCompatCB2691/pom.xml | 32 ++++ .../compat/cb2691/BlockCacheCB2691.java | 127 ++++++++++++++ .../compat/cb2691/MCAccessCB2691.java | 160 ++++++++++++++++++ NCPCompatCBDev/pom.xml | 2 +- NCPPlugin/pom.xml | 6 + .../nocheatplus/compat/MCAccessFactory.java | 18 +- pom.xml | 1 + 7 files changed, 340 insertions(+), 6 deletions(-) create mode 100644 NCPCompatCB2691/pom.xml create mode 100644 NCPCompatCB2691/src/main/java/fr/neatmonster/nocheatplus/compat/cb2691/BlockCacheCB2691.java create mode 100644 NCPCompatCB2691/src/main/java/fr/neatmonster/nocheatplus/compat/cb2691/MCAccessCB2691.java diff --git a/NCPCompatCB2691/pom.xml b/NCPCompatCB2691/pom.xml new file mode 100644 index 00000000..4511223d --- /dev/null +++ b/NCPCompatCB2691/pom.xml @@ -0,0 +1,32 @@ + + 4.0.0 + fr.neatmonster + ncpcompatcb2691 + jar + NCPCompatCB2691 + static + + + fr.neatmonster + nocheatplus-parent + static + + + + + fr.neatmonster + ncpcompat + static + + + org.bukkit + craftbukkit + 1.5.1-R0.1 + + + + Compatibility for CB2691 (1.5.1-R0.1 beta release). + +Version updating is done for NCPPlugin mainly, expect the other poms version to change randomly rather. + \ No newline at end of file diff --git a/NCPCompatCB2691/src/main/java/fr/neatmonster/nocheatplus/compat/cb2691/BlockCacheCB2691.java b/NCPCompatCB2691/src/main/java/fr/neatmonster/nocheatplus/compat/cb2691/BlockCacheCB2691.java new file mode 100644 index 00000000..158bf31f --- /dev/null +++ b/NCPCompatCB2691/src/main/java/fr/neatmonster/nocheatplus/compat/cb2691/BlockCacheCB2691.java @@ -0,0 +1,127 @@ +package fr.neatmonster.nocheatplus.compat.cb2691; + +import java.util.Iterator; +import java.util.List; + +import net.minecraft.server.v1_5_R2.AxisAlignedBB; +import net.minecraft.server.v1_5_R2.EntityBoat; +import net.minecraft.server.v1_5_R2.IBlockAccess; +import net.minecraft.server.v1_5_R2.Material; +import net.minecraft.server.v1_5_R2.TileEntity; +import net.minecraft.server.v1_5_R2.Vec3DPool; + +import org.bukkit.World; +import org.bukkit.craftbukkit.v1_5_R2.CraftWorld; +import org.bukkit.craftbukkit.v1_5_R2.entity.CraftEntity; +import org.bukkit.entity.Entity; + +import fr.neatmonster.nocheatplus.utilities.BlockCache; + +public class BlockCacheCB2691 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_5_R2.World world; + + public BlockCacheCB2691(World world) { + setAccess(world); + } + + @Override + public void setAccess(World world) { + this.world = world == null ? null : ((CraftWorld) world).getHandle(); + } + + @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_5_R2.Block block = net.minecraft.server.v1_5_R2.Block.byId[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.u(), block.w(), block.y(), block.v(), block.x(), block.z()}; + } + + @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_5_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_5_R2.Entity other = (net.minecraft.server.v1_5_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 Material getMaterial(final int x, final int y, final int z) { + return world.getMaterial(x, y, z); + } + + @Override + public TileEntity getTileEntity(final int x, final int y, final int z) { + return world.getTileEntity(x, y, z); + } + + @Override + public Vec3DPool getVec3DPool() { + return world.getVec3DPool(); + } + + @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 boolean u(final int arg0, final int arg1, final int arg2) { + return world.u(arg0, arg1, arg2); + } + +} diff --git a/NCPCompatCB2691/src/main/java/fr/neatmonster/nocheatplus/compat/cb2691/MCAccessCB2691.java b/NCPCompatCB2691/src/main/java/fr/neatmonster/nocheatplus/compat/cb2691/MCAccessCB2691.java new file mode 100644 index 00000000..1f7c387c --- /dev/null +++ b/NCPCompatCB2691/src/main/java/fr/neatmonster/nocheatplus/compat/cb2691/MCAccessCB2691.java @@ -0,0 +1,160 @@ +package fr.neatmonster.nocheatplus.compat.cb2691; + +import net.minecraft.server.v1_5_R2.AxisAlignedBB; +import net.minecraft.server.v1_5_R2.Block; +import net.minecraft.server.v1_5_R2.DamageSource; +import net.minecraft.server.v1_5_R2.EntityComplexPart; +import net.minecraft.server.v1_5_R2.EntityPlayer; +import net.minecraft.server.v1_5_R2.MobEffectList; + +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.command.CommandMap; +import org.bukkit.craftbukkit.v1_5_R2.CraftServer; +import org.bukkit.craftbukkit.v1_5_R2.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_5_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.BlockProperties; +import fr.neatmonster.nocheatplus.utilities.ReflectionUtil; + +public class MCAccessCB2691 implements MCAccess{ + + /** + * Constructor to let it fail. + */ + public MCAccessCB2691(){ + getCommandMap(); + ReflectionUtil.checkMembers("net.minecraft.server.v1_5_R2.", new String[]{"Entity" , "dead"}); + } + + @Override + public String getMCVersion() { + // 1_5_R2 + return "1.5.1"; + } + + @Override + public String getServerVersionTag() { + return "CB2691"; + } + + @Override + public CommandMap getCommandMap() { + return ((CraftServer) Bukkit.getServer()).getCommandMap(); + } + + @Override + public BlockCache getBlockCache(final World world) { + return new BlockCacheCB2691(world); + } + + @Override + public double getHeight(final Entity entity) { + final net.minecraft.server.v1_5_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.byId[id]; + if (block == null || block.material == null) return AlmostBoolean.MAYBE; + else return AlmostBoolean.match(block.material.isSolid()); + } + + @Override + public AlmostBoolean isBlockLiquid(final int id) { + final Block block = Block.byId[id]; + if (block == null || block.material == null) return AlmostBoolean.MAYBE; + else return AlmostBoolean.match(block.material.isLiquid()); + } + + @Override + public boolean Block_i(final int id) { + // TODO: This is inaccurate (would be something like "can suffocate"), however it is used for piling upwards and might about do. + return BlockProperties.isGround(id) || BlockProperties.isSolid(id); + } + + @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_5_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_5_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 int damage) { + ((CraftPlayer) player).getHandle().damageEntity(DamageSource.FALL, 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_5_R2.EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); + return !mcPlayer.dead && mcPlayer.getHealth() <= 0 ; + } + + @Override + public void setDead(final Player player, final int deathTicks) { + final net.minecraft.server.v1_5_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; + } + +} diff --git a/NCPCompatCBDev/pom.xml b/NCPCompatCBDev/pom.xml index 9e8a8003..949ac49d 100644 --- a/NCPCompatCBDev/pom.xml +++ b/NCPCompatCBDev/pom.xml @@ -22,7 +22,7 @@ org.bukkit craftbukkit - 1.5.1-R0.1-SNAPSHOT + 1.5.1-R0.2-SNAPSHOT diff --git a/NCPPlugin/pom.xml b/NCPPlugin/pom.xml index e7a75ff3..868440d9 100644 --- a/NCPPlugin/pom.xml +++ b/NCPPlugin/pom.xml @@ -75,6 +75,11 @@ ncpcompatcb2645 static + + fr.neatmonster + ncpcompatcb2691 + static + fr.neatmonster ncpcompatcbdev @@ -138,6 +143,7 @@ fr.neatmonster:ncpcompatcb2545 fr.neatmonster:ncpcompatcb2602 fr.neatmonster:ncpcompatcb2645 + fr.neatmonster:ncpcompatcb2691 fr.neatmonster:ncpcompatcbdev diff --git a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/compat/MCAccessFactory.java b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/compat/MCAccessFactory.java index 05399ad3..54f3c708 100644 --- a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/compat/MCAccessFactory.java +++ b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/compat/MCAccessFactory.java @@ -9,7 +9,7 @@ import fr.neatmonster.nocheatplus.compat.cb2512.MCAccessCB2512; import fr.neatmonster.nocheatplus.compat.cb2545.MCAccessCB2545; import fr.neatmonster.nocheatplus.compat.cb2602.MCAccessCB2602; import fr.neatmonster.nocheatplus.compat.cb2645.MCAccessCB2645; -import fr.neatmonster.nocheatplus.compat.cbdev.MCAccessCBDev; +import fr.neatmonster.nocheatplus.compat.cb2691.MCAccessCB2691; import fr.neatmonster.nocheatplus.config.ConfPaths; import fr.neatmonster.nocheatplus.config.ConfigManager; import fr.neatmonster.nocheatplus.logging.LogUtil; @@ -39,15 +39,23 @@ public class MCAccessFactory { if (!bukkitOnly){ // TEST // - // Only add as long as no stable module has been added. - // 1.5.1 +// // Only add as long as no stable module has been added. +// // 1.5.1 +// try{ +// return new MCAccessCBDev(); +// } +// catch(Throwable t){ +// throwables.add(t); +// }; + // TEST END // + + // 1.5.1 (cb beta) try{ - return new MCAccessCBDev(); + return new MCAccessCB2691(); } catch(Throwable t){ throwables.add(t); }; - // TEST END // // 1.5 try{ diff --git a/pom.xml b/pom.xml index 82b0fd91..b0990556 100644 --- a/pom.xml +++ b/pom.xml @@ -24,6 +24,7 @@ NCPCompatCB2545 NCPCompatCB2602 NCPCompatCB2645 + NCPCompatCB2691 NCPCompatCBDev