[BLEEDING] Use 1.9 API to detect actually using elytra.

This commit is contained in:
asofold 2016-03-23 22:35:09 +01:00
parent 8353bdbfbe
commit 677622ac66
6 changed files with 42 additions and 6 deletions

View File

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

View File

@ -358,7 +358,7 @@ public class MovingConfig extends ACheckConfig {
// TODO: INCONSISTENT. // TODO: INCONSISTENT.
return modelGameMode; return modelGameMode;
} }
if (Bridge1_9.isWearingElytra(player)) { if (Bridge1_9.isWearingElytra(player)) { // Defensive: don't demand isGliding.
return flyingModelElytra; return flyingModelElytra;
} }
// Default by game mode. // Default by game mode.

View File

@ -950,7 +950,7 @@ public class MovingListener extends CheckListener implements TickListener, IRemo
// Default margin: Allow slightly less than the previous speed. // Default margin: Allow slightly less than the previous speed.
final double defaultAmount = lastMove.hDistance * (1.0 + Magic.FRICTION_MEDIUM_AIR) / 2.0; final double defaultAmount = lastMove.hDistance * (1.0 + Magic.FRICTION_MEDIUM_AIR) / 2.0;
// Test for exceptions. // Test for exceptions.
if (thisMove.hDistance > defaultAmount && Bridge1_9.isWearingElytra(player)) { if (thisMove.hDistance > defaultAmount && Bridge1_9.isGlidingWithElytra(player)) {
// Allowing the same speed won't always work on elytra (still increasing, differing modeling on client side with motXYZ). // Allowing the same speed won't always work on elytra (still increasing, differing modeling on client side with motXYZ).
// (Doesn't seem to be overly effective.) // (Doesn't seem to be overly effective.)
final MoveData pastMove1 = data.moveData.get(1); final MoveData pastMove1 = data.moveData.get(1);

View File

@ -1850,6 +1850,7 @@ public class SurvivalFly extends Check {
tags.add("lowfoodsprint"); tags.add("lowfoodsprint");
} }
if (Bridge1_9.isWearingElytra(player)) { if (Bridge1_9.isWearingElytra(player)) {
// Just wearing (not isGliding).
tags.add("elytra_off"); tags.add("elytra_off");
} }
if (!tags.isEmpty()) { if (!tags.isEmpty()) {

View File

@ -56,7 +56,7 @@ public class MovingUtil {
&& (cc.ignoreAllowFlight || !player.getAllowFlight()) && (cc.ignoreAllowFlight || !player.getAllowFlight())
&& !NCPExemptionManager.isExempted(player, CheckType.MOVING_SURVIVALFLY) && !NCPExemptionManager.isExempted(player, CheckType.MOVING_SURVIVALFLY)
&& (Bridge1_9.getLevitationAmplifier(player) == Double.NEGATIVE_INFINITY || fromLocation.isInLiquid()) && (Bridge1_9.getLevitationAmplifier(player) == Double.NEGATIVE_INFINITY || fromLocation.isInLiquid())
&& (!Bridge1_9.isWearingElytra(player) || fromLocation.isOnGroundOrResetCond()) && (!Bridge1_9.isGlidingWithElytra(player) || fromLocation.isOnGroundOrResetCond())
&& !player.hasPermission(Permissions.MOVING_SURVIVALFLY); && !player.hasPermission(Permissions.MOVING_SURVIVALFLY);
} }

View File

@ -20,6 +20,9 @@ public class Bridge1_9 {
private static final Material ELYTRA = Material.getMaterial("ELYTRA"); private static final Material ELYTRA = Material.getMaterial("ELYTRA");
private static Method getItemInOffHand = ReflectionUtil.getMethodNoArgs(PlayerInventory.class, "getItemInOffHand", ItemStack.class); private static Method getItemInOffHand = ReflectionUtil.getMethodNoArgs(PlayerInventory.class, "getItemInOffHand", ItemStack.class);
private static Method getItemInMainHand = ReflectionUtil.getMethodNoArgs(PlayerInventory.class, "getItemInMainHand", ItemStack.class);
private static Method isGliding = ReflectionUtil.getMethodNoArgs(Player.class, "isGliding", boolean.class);
public static boolean hasLevitation() { public static boolean hasLevitation() {
return LEVITATION != null; return LEVITATION != null;
@ -37,6 +40,14 @@ public class Bridge1_9 {
return getItemInOffHand != null; return getItemInOffHand != null;
} }
public static boolean hasGetItemInMainHand() {
return getItemInMainHand != null;
}
public static boolean hasIsGliding() {
return isGliding != null;
}
/** /**
* Test for the 'levitation' potion effect. * Test for the 'levitation' potion effect.
* *
@ -50,6 +61,15 @@ public class Bridge1_9 {
return PotionUtil.getPotionEffectAmplifier(player, LEVITATION); return PotionUtil.getPotionEffectAmplifier(player, LEVITATION);
} }
/**
* Gliding + wearing elytra.
* @param player
* @return
*/
public static boolean isGlidingWithElytra(final Player player) {
return isGliding(player) && isWearingElytra(player);
}
/** /**
* Just test if the player has elytra equipped in the chest plate slot. The * Just test if the player has elytra equipped in the chest plate slot. The
* player may or may not be holding an end rod in either hand. * player may or may not be holding an end rod in either hand.
@ -86,8 +106,14 @@ public class Bridge1_9 {
return false; return false;
} }
@SuppressWarnings("deprecation")
public static ItemStack getItemInMainHand(final Player player) { public static ItemStack getItemInMainHand(final Player player) {
return player.getItemInHand(); // As long as feasible (see: CraftInventoryPlayer). if (getItemInMainHand == null) {
return player.getItemInHand(); // As long as feasible (see: CraftInventoryPlayer).
}
else {
return player.getInventory().getItemInMainHand();
}
} }
/** /**
@ -101,7 +127,16 @@ public class Bridge1_9 {
return null; return null;
} }
else { else {
return(ItemStack) ReflectionUtil.invokeMethodNoArgs(getItemInOffHand, player.getInventory()); return player.getInventory().getItemInOffHand();
}
}
public static boolean isGliding(final Player player) {
if (isGliding == null) {
return false;
}
else {
return player.isGliding();
} }
} }