Use getWidth and getHeight for Bukkit entities, once available.

* Simplify MC version string.
This commit is contained in:
asofold 2017-04-02 17:04:30 +02:00
parent c017d00866
commit 0491fa7805
5 changed files with 38 additions and 10 deletions

View File

@ -17,7 +17,7 @@
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.9.4-R0.1-SNAPSHOT</version>
<version>1.11.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>

View File

@ -38,6 +38,7 @@ import fr.neatmonster.nocheatplus.utilities.map.BlockCache;
public class MCAccessBukkitBase implements MCAccess {
// private AlmostBoolean entityPlayerAvailable = AlmostBoolean.MAYBE;
protected final boolean bukkitHasGetHeightAndGetWidth;
/**
* Constructor to let it fail.
@ -48,13 +49,16 @@ public class MCAccessBukkitBase implements MCAccess {
Material.AIR.isOccluding();
Material.AIR.isTransparent();
// TODO: Deactivate checks that might not work. => MCAccess should have availability method, NCP deactivates check on base of that.
// TODO: Move getHeight and the like to EntityAccessXY.
bukkitHasGetHeightAndGetWidth = ReflectionUtil.getMethodNoArgs(Entity.class, "getHeight", double.class) != null
&& ReflectionUtil.getMethodNoArgs(Entity.class, "getWidth", double.class) != null;
}
@Override
public String getMCVersion() {
// Bukkit API.
// TODO: maybe output something else.
return "1.4.6|1.4.7|1.5.x|1.6.x|1.7.x|1.8.x|1.9.x|?"; // 1.8.x is bold!
return "1.4.6-1.11.2|?"; // uh oh
}
@Override
@ -84,8 +88,13 @@ public class MCAccessBukkitBase implements MCAccess {
@Override
public double getHeight(final Entity entity) {
// TODO: Copy defaults like with widths.
final double entityHeight = 1.0;
double entityHeight;
if (bukkitHasGetHeightAndGetWidth) {
entityHeight = entity.getHeight();
}
else {
entityHeight = 1.0;
}
if (entity instanceof LivingEntity) {
return Math.max(((LivingEntity) entity).getEyeHeight(), entityHeight);
} else {
@ -105,8 +114,7 @@ public class MCAccessBukkitBase implements MCAccess {
}
}
@Override
public double getWidth(final Entity entity) {
private final double legacyGetWidth(final Entity entity) {
// TODO: Make readable from file for defaults + register individual getters where appropriate.
// TODO: For height too. [Automatize most by spawning + checking?]
// Values taken from 1.7.10.
@ -207,7 +215,16 @@ public class MCAccessBukkitBase implements MCAccess {
} catch (Throwable t) {}
// Default entity width.
return 0.6f;
}
@Override
public double getWidth(final Entity entity) {
if (bukkitHasGetHeightAndGetWidth) {
return entity.getWidth();
}
else {
return legacyGetWidth(entity);
}
}
@Override

View File

@ -70,7 +70,7 @@ public class MCAccessCBReflect extends MCAccessBukkitBase {
@Override
public String getMCVersion() {
// Potentially all :p.
return "1.4.5-1.11|?";
return "1.4.5-1.11.2|?";
}
@Override
@ -173,6 +173,9 @@ public class MCAccessCBReflect extends MCAccessBukkitBase {
@Override
public double getHeight(Entity entity) {
if (bukkitHasGetHeightAndGetWidth) {
return super.getHeight(entity);
}
try {
return helper.getHeight(entity);
}
@ -183,6 +186,9 @@ public class MCAccessCBReflect extends MCAccessBukkitBase {
@Override
public double getWidth(Entity entity) {
if (bukkitHasGetHeightAndGetWidth) {
return super.getWidth(entity);
}
try {
return helper.getWidth(entity);
}

View File

@ -128,8 +128,9 @@ public class MCAccessCBDev implements MCAccess {
@Override
public double getHeight(final Entity entity) {
// (entity.getHeight() returns the length field, but we access nms anyway.)
final net.minecraft.server.v1_11_R1.Entity mcEntity = ((CraftEntity) entity).getHandle();
AxisAlignedBB boundingBox = mcEntity.getBoundingBox();
final AxisAlignedBB boundingBox = mcEntity.getBoundingBox();
final double entityHeight = Math.max(mcEntity.length, Math.max(mcEntity.getHeadHeight(), boundingBox.e - boundingBox.b));
if (entity instanceof LivingEntity) {
return Math.max(((LivingEntity) entity).getEyeHeight(), entityHeight);
@ -171,7 +172,7 @@ public class MCAccessCBDev implements MCAccess {
@Override
public double getWidth(final Entity entity) {
return ((CraftEntity) entity).getHandle().width;
return entity.getWidth();
}
@Override

View File

@ -42,7 +42,11 @@ import fr.neatmonster.nocheatplus.utilities.map.BlockCache;
public interface MCAccess extends IGetBlockCache, IEntityAccessDimensions {
/**
* Simple version identifiers, if several must be separated by '|' like "1.4.2|1.4.4|1.4.5", to indicate multiple sub-versions supported use "1.5.x", use "?" to indicate general future support.
* Simple/rough version information, separate several individual versions by
* '|' ranges with '-', potential future support with '?', e.g.
* "1.x.1|1.x.2|2.3.4-3.4.5|?". For large ranges, don't expect all versions
* between to be supported.
*
* @return
*/
public String getMCVersion();