mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-06-26 06:14:42 +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>
|
<dependency>
|
||||||
<groupId>org.bukkit</groupId>
|
<groupId>org.bukkit</groupId>
|
||||||
<artifactId>bukkit</artifactId>
|
<artifactId>bukkit</artifactId>
|
||||||
<version>1.9.4-R0.1-SNAPSHOT</version>
|
<version>1.11.2-R0.1-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
@ -38,6 +38,7 @@ import fr.neatmonster.nocheatplus.utilities.map.BlockCache;
|
||||||
public class MCAccessBukkitBase implements MCAccess {
|
public class MCAccessBukkitBase implements MCAccess {
|
||||||
|
|
||||||
// private AlmostBoolean entityPlayerAvailable = AlmostBoolean.MAYBE;
|
// private AlmostBoolean entityPlayerAvailable = AlmostBoolean.MAYBE;
|
||||||
|
protected final boolean bukkitHasGetHeightAndGetWidth;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor to let it fail.
|
* Constructor to let it fail.
|
||||||
|
@ -48,13 +49,16 @@ public class MCAccessBukkitBase implements MCAccess {
|
||||||
Material.AIR.isOccluding();
|
Material.AIR.isOccluding();
|
||||||
Material.AIR.isTransparent();
|
Material.AIR.isTransparent();
|
||||||
// TODO: Deactivate checks that might not work. => MCAccess should have availability method, NCP deactivates check on base of that.
|
// 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
|
@Override
|
||||||
public String getMCVersion() {
|
public String getMCVersion() {
|
||||||
// Bukkit API.
|
// Bukkit API.
|
||||||
// TODO: maybe output something else.
|
// 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
|
@Override
|
||||||
|
@ -84,8 +88,13 @@ public class MCAccessBukkitBase implements MCAccess {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getHeight(final Entity entity) {
|
public double getHeight(final Entity entity) {
|
||||||
// TODO: Copy defaults like with widths.
|
double entityHeight;
|
||||||
final double entityHeight = 1.0;
|
if (bukkitHasGetHeightAndGetWidth) {
|
||||||
|
entityHeight = entity.getHeight();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
entityHeight = 1.0;
|
||||||
|
}
|
||||||
if (entity instanceof LivingEntity) {
|
if (entity instanceof LivingEntity) {
|
||||||
return Math.max(((LivingEntity) entity).getEyeHeight(), entityHeight);
|
return Math.max(((LivingEntity) entity).getEyeHeight(), entityHeight);
|
||||||
} else {
|
} else {
|
||||||
|
@ -105,8 +114,7 @@ public class MCAccessBukkitBase implements MCAccess {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private final double legacyGetWidth(final Entity entity) {
|
||||||
public double getWidth(final Entity entity) {
|
|
||||||
// TODO: Make readable from file for defaults + register individual getters where appropriate.
|
// TODO: Make readable from file for defaults + register individual getters where appropriate.
|
||||||
// TODO: For height too. [Automatize most by spawning + checking?]
|
// TODO: For height too. [Automatize most by spawning + checking?]
|
||||||
// Values taken from 1.7.10.
|
// Values taken from 1.7.10.
|
||||||
|
@ -207,7 +215,16 @@ public class MCAccessBukkitBase implements MCAccess {
|
||||||
} catch (Throwable t) {}
|
} catch (Throwable t) {}
|
||||||
// Default entity width.
|
// Default entity width.
|
||||||
return 0.6f;
|
return 0.6f;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getWidth(final Entity entity) {
|
||||||
|
if (bukkitHasGetHeightAndGetWidth) {
|
||||||
|
return entity.getWidth();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return legacyGetWidth(entity);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -70,7 +70,7 @@ public class MCAccessCBReflect extends MCAccessBukkitBase {
|
||||||
@Override
|
@Override
|
||||||
public String getMCVersion() {
|
public String getMCVersion() {
|
||||||
// Potentially all :p.
|
// Potentially all :p.
|
||||||
return "1.4.5-1.11|?";
|
return "1.4.5-1.11.2|?";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -173,6 +173,9 @@ public class MCAccessCBReflect extends MCAccessBukkitBase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getHeight(Entity entity) {
|
public double getHeight(Entity entity) {
|
||||||
|
if (bukkitHasGetHeightAndGetWidth) {
|
||||||
|
return super.getHeight(entity);
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
return helper.getHeight(entity);
|
return helper.getHeight(entity);
|
||||||
}
|
}
|
||||||
|
@ -183,6 +186,9 @@ public class MCAccessCBReflect extends MCAccessBukkitBase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getWidth(Entity entity) {
|
public double getWidth(Entity entity) {
|
||||||
|
if (bukkitHasGetHeightAndGetWidth) {
|
||||||
|
return super.getWidth(entity);
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
return helper.getWidth(entity);
|
return helper.getWidth(entity);
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,8 +128,9 @@ public class MCAccessCBDev implements MCAccess {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getHeight(final Entity entity) {
|
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();
|
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));
|
final double entityHeight = Math.max(mcEntity.length, Math.max(mcEntity.getHeadHeight(), boundingBox.e - boundingBox.b));
|
||||||
if (entity instanceof LivingEntity) {
|
if (entity instanceof LivingEntity) {
|
||||||
return Math.max(((LivingEntity) entity).getEyeHeight(), entityHeight);
|
return Math.max(((LivingEntity) entity).getEyeHeight(), entityHeight);
|
||||||
|
@ -171,7 +172,7 @@ public class MCAccessCBDev implements MCAccess {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getWidth(final Entity entity) {
|
public double getWidth(final Entity entity) {
|
||||||
return ((CraftEntity) entity).getHandle().width;
|
return entity.getWidth();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -42,7 +42,11 @@ import fr.neatmonster.nocheatplus.utilities.map.BlockCache;
|
||||||
public interface MCAccess extends IGetBlockCache, IEntityAccessDimensions {
|
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
|
* @return
|
||||||
*/
|
*/
|
||||||
public String getMCVersion();
|
public String getMCVersion();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user