Skip to content

Commit

Permalink
Add a fallback impl for if the setAbsorptionAmount bkcl API isn't ava…
Browse files Browse the repository at this point in the history
…ilable
  • Loading branch information
bergerkiller committed Feb 14, 2023
1 parent 71ea824 commit 21471b8
Showing 1 changed file with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.function.Consumer;
import java.util.logging.Level;

import com.bergerkiller.mountiplex.reflection.resolver.Resolver;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.GameMode;
Expand Down Expand Up @@ -545,9 +546,26 @@ public void refreshState(Player player) {
player.setFireTicks(playerData.getValue("Fire", (short) 0));
player.setFallDistance(playerData.getValue("FallDistance", 0.0f));

float absorptionAmount = playerData.getValue("AbsorptionAmount", 0.0f);
try {
playerHandle.setAbsorptionAmount(playerData.getValue("AbsorptionAmount", 0.0f));
} catch (Throwable t) { /* Until BKCL 1.19.3-v2 is a hard-dep, we need this. */ }
playerHandle.setAbsorptionAmount(absorptionAmount);
} catch (Throwable t) {
/* Until BKCL 1.19.3-v2 is a hard-dep, we need this. */
try {
java.lang.reflect.Method m;
if (Common.evaluateMCVersion(">=", "1.18")) {
m = Resolver.resolveAndGetDeclaredMethod(EntityLivingHandle.T.getType(),
"setAbsorptionAmount", float.class);
} else {
m = Resolver.resolveAndGetDeclaredMethod(EntityLivingHandle.T.getType(),
"setAbsorptionHearts", float.class);
}
m.setAccessible(true);
m.invoke(playerHandle.getRaw(), absorptionAmount);
} catch (Throwable t2) {
plugin.getLogger().log(Level.WARNING, "Failed to apply absorption. Update BKCL?", t2);
}
}

{
final double maxHealth = commonPlayer.getMaxHealth();
Expand Down

0 comments on commit 21471b8

Please sign in to comment.