mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-09-27 14:13:11 +02:00
Use getWidth and getHeight for Bukkit entities, once available.
* Simplify MC version string.
This commit is contained in:
parent
c017d00866
commit
0491fa7805
@ -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>
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user