Skip to content

Commit

Permalink
[BLEEDING] Use 1.9 API to detect actually using elytra.
Browse files Browse the repository at this point in the history
  • Loading branch information
asofold committed Mar 23, 2016
1 parent 8353bdb commit 677622a
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 6 deletions.
2 changes: 1 addition & 1 deletion NCPCore/pom.xml
Expand Up @@ -17,7 +17,7 @@
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.8.8-R0.1-SNAPSHOT</version>
<version>1.9-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
Expand Up @@ -358,7 +358,7 @@ public ModelFlying getModelFlying(final Player player, final PlayerLocation from
// TODO: INCONSISTENT.
return modelGameMode;
}
if (Bridge1_9.isWearingElytra(player)) {
if (Bridge1_9.isWearingElytra(player)) { // Defensive: don't demand isGliding.
return flyingModelElytra;
}
// Default by game mode.
Expand Down
Expand Up @@ -950,7 +950,7 @@ private static double guessFlyNoFlyVelocity(final Player player, final MoveData
// Default margin: Allow slightly less than the previous speed.
final double defaultAmount = lastMove.hDistance * (1.0 + Magic.FRICTION_MEDIUM_AIR) / 2.0;
// 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).
// (Doesn't seem to be overly effective.)
final MoveData pastMove1 = data.moveData.get(1);
Expand Down
Expand Up @@ -1850,6 +1850,7 @@ private void outputDebug(final Player player, final PlayerLocation to, final Mov
tags.add("lowfoodsprint");
}
if (Bridge1_9.isWearingElytra(player)) {
// Just wearing (not isGliding).
tags.add("elytra_off");
}
if (!tags.isEmpty()) {
Expand Down
Expand Up @@ -56,7 +56,7 @@ public static final boolean shouldCheckSurvivalFly(final Player player, final Pl
&& (cc.ignoreAllowFlight || !player.getAllowFlight())
&& !NCPExemptionManager.isExempted(player, CheckType.MOVING_SURVIVALFLY)
&& (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);
}

Expand Down
Expand Up @@ -20,6 +20,9 @@ public class Bridge1_9 {
private static final Material ELYTRA = Material.getMaterial("ELYTRA");

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() {
return LEVITATION != null;
Expand All @@ -37,6 +40,14 @@ public static boolean hasGetItemInOffHand() {
return getItemInOffHand != null;
}

public static boolean hasGetItemInMainHand() {
return getItemInMainHand != null;
}

public static boolean hasIsGliding() {
return isGliding != null;
}

/**
* Test for the 'levitation' potion effect.
*
Expand All @@ -50,6 +61,15 @@ public static double getLevitationAmplifier(final Player player) {
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
* player may or may not be holding an end rod in either hand.
Expand Down Expand Up @@ -86,8 +106,14 @@ public static boolean hasItemInAnyHand(final Player player, final Material mater
return false;
}

@SuppressWarnings("deprecation")
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();
}
}

/**
Expand All @@ -101,7 +127,16 @@ public static ItemStack getItemInOffHand(final Player player) {
return null;
}
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();
}
}

Expand Down

0 comments on commit 677622a

Please sign in to comment.