mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2025-02-19 05:01:50 +01:00
Spaces again.
This commit is contained in:
parent
7dba18cf67
commit
1eb8d98860
@ -30,78 +30,78 @@ import fr.neatmonster.nocheatplus.utilities.PotionUtil;
|
|||||||
import fr.neatmonster.nocheatplus.utilities.ReflectionUtil;
|
import fr.neatmonster.nocheatplus.utilities.ReflectionUtil;
|
||||||
|
|
||||||
public class MCAccessBukkit implements MCAccess, BlockPropertiesSetup{
|
public class MCAccessBukkit implements MCAccess, BlockPropertiesSetup{
|
||||||
|
|
||||||
// private AlmostBoolean entityPlayerAvailable = AlmostBoolean.MAYBE;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor to let it fail.
|
|
||||||
*/
|
|
||||||
public MCAccessBukkit() {
|
|
||||||
// TODO: Add more that might fail if not supported ?
|
|
||||||
Material.AIR.isSolid();
|
|
||||||
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.
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
// private AlmostBoolean entityPlayerAvailable = AlmostBoolean.MAYBE;
|
||||||
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.7.x is bold!
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
public String getServerVersionTag() {
|
* Constructor to let it fail.
|
||||||
return "Bukkit-API";
|
*/
|
||||||
}
|
public MCAccessBukkit() {
|
||||||
|
// TODO: Add more that might fail if not supported ?
|
||||||
|
Material.AIR.isSolid();
|
||||||
|
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.
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommandMap getCommandMap() {
|
public String getMCVersion() {
|
||||||
try{
|
// Bukkit API.
|
||||||
return (CommandMap) ReflectionUtil.invokeMethodNoArgs(Bukkit.getServer(), "getCommandMap");
|
// TODO: maybe output something else.
|
||||||
} catch (Throwable t) {
|
return "1.4.6|1.4.7|1.5.x|1.6.x|1.7.x"; // 1.7.x is bold!
|
||||||
// Nasty.
|
}
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockCache getBlockCache(final World world) {
|
public String getServerVersionTag() {
|
||||||
return new BlockCacheBukkit(world);
|
return "Bukkit-API";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getHeight(final Entity entity) {
|
public CommandMap getCommandMap() {
|
||||||
// TODO: Copy defaults like with widths.
|
try{
|
||||||
final double entityHeight = 1.0;
|
return (CommandMap) ReflectionUtil.invokeMethodNoArgs(Bukkit.getServer(), "getCommandMap");
|
||||||
if (entity instanceof LivingEntity) {
|
} catch (Throwable t) {
|
||||||
return Math.max(((LivingEntity) entity).getEyeHeight(), entityHeight);
|
// Nasty.
|
||||||
} else {
|
return null;
|
||||||
return entityHeight;
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AlmostBoolean isBlockSolid(final int id) {
|
public BlockCache getBlockCache(final World world) {
|
||||||
@SuppressWarnings("deprecation")
|
return new BlockCacheBukkit(world);
|
||||||
final Material mat = Material.getMaterial(id);
|
}
|
||||||
if (mat == null) {
|
|
||||||
return AlmostBoolean.MAYBE;
|
@Override
|
||||||
}
|
public double getHeight(final Entity entity) {
|
||||||
else {
|
// TODO: Copy defaults like with widths.
|
||||||
return AlmostBoolean.match(mat.isSolid());
|
final double entityHeight = 1.0;
|
||||||
}
|
if (entity instanceof LivingEntity) {
|
||||||
}
|
return Math.max(((LivingEntity) entity).getEyeHeight(), entityHeight);
|
||||||
|
} else {
|
||||||
@Override
|
return entityHeight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AlmostBoolean isBlockSolid(final int id) {
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
final Material mat = Material.getMaterial(id);
|
||||||
|
if (mat == null) {
|
||||||
|
return AlmostBoolean.MAYBE;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return AlmostBoolean.match(mat.isSolid());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public double getWidth(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.
|
||||||
final EntityType type = entity.getType();
|
final EntityType type = entity.getType();
|
||||||
switch(type){
|
switch(type){
|
||||||
// TODO: case COMPLEX_PART:
|
// TODO: case COMPLEX_PART:
|
||||||
case ENDER_SIGNAL: // this.a(0.25F, 0.25F);
|
case ENDER_SIGNAL: // this.a(0.25F, 0.25F);
|
||||||
case FIREWORK: // this.a(0.25F, 0.25F);
|
case FIREWORK: // this.a(0.25F, 0.25F);
|
||||||
case FISHING_HOOK: // this.a(0.25F, 0.25F);
|
case FISHING_HOOK: // this.a(0.25F, 0.25F);
|
||||||
@ -160,7 +160,7 @@ public class MCAccessBukkit implements MCAccess, BlockPropertiesSetup{
|
|||||||
return 3.6f; // (Better than nothing.)
|
return 3.6f; // (Better than nothing.)
|
||||||
case ENDER_DRAGON: // this.a(16.0F, 8.0F);
|
case ENDER_DRAGON: // this.a(16.0F, 8.0F);
|
||||||
return 16.0f;
|
return 16.0f;
|
||||||
// Variable size:
|
// Variable size:
|
||||||
case SLIME:
|
case SLIME:
|
||||||
case MAGMA_CUBE:
|
case MAGMA_CUBE:
|
||||||
if (entity instanceof Slime) {
|
if (entity instanceof Slime) {
|
||||||
@ -170,163 +170,163 @@ public class MCAccessBukkit implements MCAccess, BlockPropertiesSetup{
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// Check by instance for minecarts (too many).
|
// Check by instance for minecarts (too many).
|
||||||
if (entity instanceof Minecart) {
|
if (entity instanceof Minecart) {
|
||||||
return 0.98f; // this.a(0.98F, 0.7F);
|
return 0.98f; // this.a(0.98F, 0.7F);
|
||||||
}
|
}
|
||||||
// Latest Bukkit API.
|
// Latest Bukkit API.
|
||||||
try {
|
try {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case LEASH_HITCH: // hanging: this.a(0.5F, 0.5F);
|
case LEASH_HITCH: // hanging: this.a(0.5F, 0.5F);
|
||||||
return 0.5;
|
return 0.5;
|
||||||
case HORSE: // this.a(1.4F, 1.6F);
|
case HORSE: // this.a(1.4F, 1.6F);
|
||||||
return 1.4f;
|
return 1.4f;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} catch (Throwable t) {}
|
} catch (Throwable t) {}
|
||||||
// Default entity width.
|
// Default entity width.
|
||||||
return 0.6f;
|
return 0.6f;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AlmostBoolean isBlockLiquid(final int id) {
|
public AlmostBoolean isBlockLiquid(final int id) {
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
final Material mat = Material.getMaterial(id);
|
final Material mat = Material.getMaterial(id);
|
||||||
if (mat == null) return AlmostBoolean.MAYBE;
|
if (mat == null) return AlmostBoolean.MAYBE;
|
||||||
switch (mat) {
|
switch (mat) {
|
||||||
case STATIONARY_LAVA:
|
case STATIONARY_LAVA:
|
||||||
case STATIONARY_WATER:
|
case STATIONARY_WATER:
|
||||||
case WATER:
|
case WATER:
|
||||||
case LAVA:
|
case LAVA:
|
||||||
return AlmostBoolean.YES;
|
return AlmostBoolean.YES;
|
||||||
default:
|
default:
|
||||||
return AlmostBoolean.NO;
|
return AlmostBoolean.NO;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AlmostBoolean isIllegalBounds(final Player player) {
|
public AlmostBoolean isIllegalBounds(final Player player) {
|
||||||
if (player.isDead()) {
|
if (player.isDead()) {
|
||||||
return AlmostBoolean.NO;
|
return AlmostBoolean.NO;
|
||||||
}
|
}
|
||||||
if (!player.isSleeping()) { // TODO: ignored sleeping ?
|
if (!player.isSleeping()) { // TODO: ignored sleeping ?
|
||||||
// TODO: This can test like ... nothing !
|
// TODO: This can test like ... nothing !
|
||||||
// (Might not be necessary.)
|
// (Might not be necessary.)
|
||||||
}
|
}
|
||||||
return AlmostBoolean.MAYBE;
|
return AlmostBoolean.MAYBE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getJumpAmplifier(final Player player) {
|
public double getJumpAmplifier(final Player player) {
|
||||||
return PotionUtil.getPotionEffectAmplifier(player, PotionEffectType.JUMP);
|
return PotionUtil.getPotionEffectAmplifier(player, PotionEffectType.JUMP);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getFasterMovementAmplifier(final Player player) {
|
public double getFasterMovementAmplifier(final Player player) {
|
||||||
return PotionUtil.getPotionEffectAmplifier(player, PotionEffectType.SPEED);
|
return PotionUtil.getPotionEffectAmplifier(player, PotionEffectType.SPEED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getInvulnerableTicks(final Player player) {
|
public int getInvulnerableTicks(final Player player) {
|
||||||
// TODO: Ahhh...
|
// TODO: Ahhh...
|
||||||
return player.getNoDamageTicks();
|
return player.getNoDamageTicks();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setInvulnerableTicks(final Player player, final int ticks) {
|
public void setInvulnerableTicks(final Player player, final int ticks) {
|
||||||
// TODO: Not really.
|
// TODO: Not really.
|
||||||
player.setLastDamageCause(BridgeHealth.getEntityDamageEvent(player, DamageCause.CUSTOM, 500.0));
|
player.setLastDamageCause(BridgeHealth.getEntityDamageEvent(player, DamageCause.CUSTOM, 500.0));
|
||||||
player.setNoDamageTicks(ticks);
|
player.setNoDamageTicks(ticks);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void dealFallDamage(final Player player, final double damage) {
|
public void dealFallDamage(final Player player, final double damage) {
|
||||||
// TODO: Document in knowledge base.
|
// TODO: Document in knowledge base.
|
||||||
// TODO: Account for armor, other.
|
// TODO: Account for armor, other.
|
||||||
// TODO: use setLastDamageCause here ?
|
// TODO: use setLastDamageCause here ?
|
||||||
BridgeHealth.damage(player, damage);
|
BridgeHealth.damage(player, damage);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isComplexPart(final Entity entity) {
|
public boolean isComplexPart(final Entity entity) {
|
||||||
return entity instanceof ComplexEntityPart || entity instanceof ComplexLivingEntity;
|
return entity instanceof ComplexEntityPart || entity instanceof ComplexLivingEntity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean shouldBeZombie(final Player player) {
|
public boolean shouldBeZombie(final Player player) {
|
||||||
// Not sure :) ...
|
// Not sure :) ...
|
||||||
return BridgeHealth.getHealth(player) <= 0.0 && !player.isDead();
|
return BridgeHealth.getHealth(player) <= 0.0 && !player.isDead();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setDead(final Player player, final int deathTicks) {
|
public void setDead(final Player player, final int deathTicks) {
|
||||||
// TODO: Test / kick ? ...
|
// TODO: Test / kick ? ...
|
||||||
BridgeHealth.setHealth(player, 0.0);
|
BridgeHealth.setHealth(player, 0.0);
|
||||||
// TODO: Might try stuff like setNoDamageTicks.
|
// TODO: Might try stuff like setNoDamageTicks.
|
||||||
BridgeHealth.damage(player, 1.0);
|
BridgeHealth.damage(player, 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setupBlockProperties(final WorldConfigProvider<?> worldConfigProvider) {
|
public void setupBlockProperties(final WorldConfigProvider<?> worldConfigProvider) {
|
||||||
// Note deprecation suppression: These ids should be unique for a server run, that should be ok for setting up generic properties.
|
// Note deprecation suppression: These ids should be unique for a server run, that should be ok for setting up generic properties.
|
||||||
// TODO: (?) Set some generic properties matching what BlockCache.getShape returns.
|
// TODO: (?) Set some generic properties matching what BlockCache.getShape returns.
|
||||||
final Set<Material> fullBlocks = new HashSet<Material>();
|
final Set<Material> fullBlocks = new HashSet<Material>();
|
||||||
for (final Material mat : new Material[]{
|
for (final Material mat : new Material[]{
|
||||||
// TODO: Ice !? / Packed ice !?
|
// TODO: Ice !? / Packed ice !?
|
||||||
Material.GLASS, Material.GLOWSTONE, Material.ICE, Material.LEAVES,
|
Material.GLASS, Material.GLOWSTONE, Material.ICE, Material.LEAVES,
|
||||||
Material.COMMAND, Material.BEACON,
|
Material.COMMAND, Material.BEACON,
|
||||||
Material.PISTON_BASE,
|
Material.PISTON_BASE,
|
||||||
}) {
|
}) {
|
||||||
fullBlocks.add(mat);
|
fullBlocks.add(mat);
|
||||||
}
|
}
|
||||||
for (final Material mat : Material.values()) {
|
for (final Material mat : Material.values()) {
|
||||||
if (!mat.isBlock()) {
|
if (!mat.isBlock()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (fullBlocks.contains(mat)) {
|
if (fullBlocks.contains(mat)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!mat.isOccluding() || !mat.isSolid() || mat.isTransparent()) {
|
if (!mat.isOccluding() || !mat.isSolid() || mat.isTransparent()) {
|
||||||
// Uncertain bounding-box, allow passing through.
|
// Uncertain bounding-box, allow passing through.
|
||||||
long flags = BlockProperties.F_IGN_PASSABLE;
|
long flags = BlockProperties.F_IGN_PASSABLE;
|
||||||
if ((BlockProperties.isSolid(mat) || BlockProperties.isGround(mat)) && !BlockProperties.isLiquid(mat)) {
|
if ((BlockProperties.isSolid(mat) || BlockProperties.isGround(mat)) && !BlockProperties.isLiquid(mat)) {
|
||||||
// Block can be ground, so allow standing on any height.
|
// Block can be ground, so allow standing on any height.
|
||||||
flags |= BlockProperties.F_GROUND_HEIGHT;
|
flags |= BlockProperties.F_GROUND_HEIGHT;
|
||||||
}
|
}
|
||||||
BlockProperties.setBlockFlags(mat, BlockProperties.getBlockFlags(mat) | flags);
|
BlockProperties.setBlockFlags(mat, BlockProperties.getBlockFlags(mat) | flags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Blocks that are reported to be full and solid, but which are not.
|
// Blocks that are reported to be full and solid, but which are not.
|
||||||
for (final Material mat : new Material[]{
|
for (final Material mat : new Material[]{
|
||||||
Material.ENDER_PORTAL_FRAME,
|
Material.ENDER_PORTAL_FRAME,
|
||||||
}) {
|
}) {
|
||||||
final long flags = BlockProperties.F_IGN_PASSABLE | BlockProperties.F_GROUND_HEIGHT;
|
final long flags = BlockProperties.F_IGN_PASSABLE | BlockProperties.F_GROUND_HEIGHT;
|
||||||
BlockProperties.setBlockFlags(mat, BlockProperties.getBlockFlags(mat) | flags);
|
BlockProperties.setBlockFlags(mat, BlockProperties.getBlockFlags(mat) | flags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasGravity(final Material mat) {
|
public boolean hasGravity(final Material mat) {
|
||||||
try{
|
try{
|
||||||
return mat.hasGravity();
|
return mat.hasGravity();
|
||||||
}
|
}
|
||||||
catch(Throwable t) {
|
catch(Throwable t) {
|
||||||
// Backwards compatibility.
|
// Backwards compatibility.
|
||||||
switch(mat) {
|
switch(mat) {
|
||||||
case SAND:
|
case SAND:
|
||||||
case GRAVEL:
|
case GRAVEL:
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Override
|
||||||
|
// public void correctDirection(Player player) {
|
||||||
|
// // TODO: Consider using reflection (detect CraftPlayer, access EntityPlayer + check if possible (!), use flags for if valid or invalid.)
|
||||||
|
// }
|
||||||
|
|
||||||
// @Override
|
|
||||||
// public void correctDirection(Player player) {
|
|
||||||
// // TODO: Consider using reflection (detect CraftPlayer, access EntityPlayer + check if possible (!), use flags for if valid or invalid.)
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user