Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dedicated compat module for Spigot/CraftBukkit 1.9-1.9.3 (1.9_R1).
- Loading branch information
Showing
7 changed files
with
473 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<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>ncpcompatspigotcb1_9_r1</artifactId> | ||
<packaging>jar</packaging> | ||
<name>NCPCompatSpigotCB1_9_R1</name> | ||
<version>1.1-SNAPSHOT</version> | ||
|
||
<parent> | ||
<groupId>fr.neatmonster</groupId> | ||
<artifactId>nocheatplus-parent</artifactId> | ||
<version>1.1-SNAPSHOT</version> | ||
</parent> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>fr.neatmonster</groupId> | ||
<artifactId>ncpcore</artifactId> | ||
<version>1.1-SNAPSHOT</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.bukkit</groupId> | ||
<artifactId>craftbukkit</artifactId> | ||
<version>1.9-R0.1-SNAPSHOT</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<description>Compatibility for Minecraft 1.9-1.9.3 with CraftBukkit/Spigot (1_9_R1).</description> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-deploy-plugin</artifactId> | ||
<configuration> | ||
<skip>true</skip> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
141 changes: 141 additions & 0 deletions
141
.../main/java/fr/neatmonster/nocheatplus/compat/spigotcb1_9_R1/BlockCacheSpigotCB1_9_R1.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
package fr.neatmonster.nocheatplus.compat.spigotcb1_9_R1; | ||
|
||
import java.util.Iterator; | ||
import java.util.List; | ||
|
||
import net.minecraft.server.v1_9_R1.AxisAlignedBB; | ||
import net.minecraft.server.v1_9_R1.BlockPosition; | ||
import net.minecraft.server.v1_9_R1.EntityBoat; | ||
import net.minecraft.server.v1_9_R1.EntityShulker; | ||
import net.minecraft.server.v1_9_R1.EnumDirection; | ||
import net.minecraft.server.v1_9_R1.IBlockAccess; | ||
import net.minecraft.server.v1_9_R1.IBlockData; | ||
import net.minecraft.server.v1_9_R1.TileEntity; | ||
|
||
import org.bukkit.World; | ||
import org.bukkit.craftbukkit.v1_9_R1.CraftWorld; | ||
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftEntity; | ||
import org.bukkit.entity.Entity; | ||
|
||
import fr.neatmonster.nocheatplus.utilities.BlockCache; | ||
|
||
public class BlockCacheSpigotCB1_9_R1 extends BlockCache implements IBlockAccess { | ||
|
||
protected net.minecraft.server.v1_9_R1.WorldServer world; | ||
protected World bukkitWorld; | ||
|
||
public BlockCacheSpigotCB1_9_R1(World world) { | ||
setAccess(world); | ||
} | ||
|
||
@Override | ||
public void setAccess(World world) { | ||
if (world != null) { | ||
this.maxBlockY = world.getMaxHeight() - 1; | ||
this.world = ((CraftWorld) world).getHandle(); | ||
this.bukkitWorld = world; | ||
} else { | ||
this.world = null; | ||
this.bukkitWorld = null; | ||
} | ||
} | ||
|
||
@SuppressWarnings("deprecation") | ||
@Override | ||
public int fetchTypeId(final int x, final int y, final int z) { | ||
return bukkitWorld.getBlockTypeIdAt(x, y, z); | ||
} | ||
|
||
@SuppressWarnings("deprecation") | ||
@Override | ||
public int fetchData(final int x, final int y, final int z) { | ||
return bukkitWorld.getBlockAt(x, y, z).getData(); | ||
} | ||
|
||
@Override | ||
public double[] fetchBounds(final int x, final int y, final int z){ | ||
final int id = getTypeId(x, y, z); | ||
final net.minecraft.server.v1_9_R1.Block block = net.minecraft.server.v1_9_R1.Block.getById(id); | ||
if (block == null) { | ||
// TODO: Convention for null blocks -> full ? | ||
return null; | ||
} | ||
final BlockPosition pos = new BlockPosition(x, y, z); | ||
final AxisAlignedBB bb = block.a(getType(pos), this, pos); | ||
if (bb == null) { | ||
return new double[] {0.0, 0.0, 0.0, 1.0, 1.0, 1.0}; // Special case. | ||
//return null; | ||
} | ||
// minX, minY, minZ, maxX, maxY, maxZ | ||
return new double[]{bb.a, bb.b, bb.c, bb.d, bb.e, bb.f}; | ||
} | ||
|
||
@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: Find some simplification! | ||
|
||
final net.minecraft.server.v1_9_R1.Entity mcEntity = ((CraftEntity) entity).getHandle(); | ||
|
||
final AxisAlignedBB box = new AxisAlignedBB(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_9_R1.Entity other = (net.minecraft.server.v1_9_R1.Entity) iterator.next(); | ||
if (mcEntity == other || !(other instanceof EntityBoat) && !(other instanceof EntityShulker)) { // && !(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.getBoundingBox(); | ||
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; | ||
bukkitWorld = null; | ||
} | ||
|
||
@Override | ||
public int getBlockPower(BlockPosition pos, EnumDirection dir) { | ||
return world.getBlockPower(pos, dir); | ||
} | ||
|
||
@Override | ||
public TileEntity getTileEntity(BlockPosition pos) { | ||
return world.getTileEntity(pos); | ||
} | ||
|
||
@Override | ||
public IBlockData getType(BlockPosition pos) { | ||
// TODO: Can this be cached ? | ||
return world.getType(pos); | ||
} | ||
|
||
@Override | ||
public boolean isEmpty(BlockPosition pos) { | ||
// TODO: Can (and should) this be cached ? | ||
return world.isEmpty(pos); | ||
} | ||
|
||
} |
Oops, something went wrong.