Skip to content
Permalink
Browse files

Add serverside & clientside absorption health, fixes #1576 (#1888)

* Add serverside & clientside absorption health, fixes #1576

* Fix bad copypasta
  • Loading branch information...
mergu authored and mcmonkey4eva committed Jan 18, 2019
1 parent faa2afb commit b05274cd74d809459bf5fd006c9809df6f19ff12
Showing with 160 additions and 42 deletions.
  1. +2 −0 nmshandler/src/main/java/net/aufdemrand/denizen/nms/interfaces/PacketHelper.java
  2. +4 −0 nmshandler/src/main/java/net/aufdemrand/denizen/nms/interfaces/PlayerHelper.java
  3. +36 −0 plugin/src/main/java/net/aufdemrand/denizen/objects/dPlayer.java
  4. +2 −4 v1_10_R1/src/main/java/net/aufdemrand/denizen/nms/helpers/EntityHelper_v1_10_R1.java
  5. +7 −0 v1_10_R1/src/main/java/net/aufdemrand/denizen/nms/helpers/PacketHelper_v1_10_R1.java
  6. +11 −4 v1_10_R1/src/main/java/net/aufdemrand/denizen/nms/helpers/PlayerHelper_v1_10_R1.java
  7. +2 −4 v1_11_R1/src/main/java/net/aufdemrand/denizen/nms/helpers/EntityHelper_v1_11_R1.java
  8. +7 −0 v1_11_R1/src/main/java/net/aufdemrand/denizen/nms/helpers/PacketHelper_v1_11_R1.java
  9. +11 −4 v1_11_R1/src/main/java/net/aufdemrand/denizen/nms/helpers/PlayerHelper_v1_11_R1.java
  10. +2 −4 v1_12_R1/src/main/java/net/aufdemrand/denizen/nms/helpers/EntityHelper_v1_12_R1.java
  11. +7 −0 v1_12_R1/src/main/java/net/aufdemrand/denizen/nms/helpers/PacketHelper_v1_12_R1.java
  12. +11 −4 v1_12_R1/src/main/java/net/aufdemrand/denizen/nms/helpers/PlayerHelper_v1_12_R1.java
  13. +3 −6 v1_13_R2/src/main/java/net/aufdemrand/denizen/nms/helpers/EntityHelper_v1_13_R2.java
  14. +7 −0 v1_13_R2/src/main/java/net/aufdemrand/denizen/nms/helpers/PacketHelper_v1_13_R2.java
  15. +11 −4 v1_13_R2/src/main/java/net/aufdemrand/denizen/nms/helpers/PlayerHelper_v1_13_R2.java
  16. +7 −0 v1_8_R3/src/main/java/net/aufdemrand/denizen/nms/helpers/PacketHelper_v1_8_R3.java
  17. +10 −0 v1_8_R3/src/main/java/net/aufdemrand/denizen/nms/helpers/PlayerHelper_v1_8_R3.java
  18. +2 −4 v1_9_R2/src/main/java/net/aufdemrand/denizen/nms/helpers/EntityHelper_v1_9_R2.java
  19. +7 −0 v1_9_R2/src/main/java/net/aufdemrand/denizen/nms/helpers/PacketHelper_v1_9_R2.java
  20. +11 −4 v1_9_R2/src/main/java/net/aufdemrand/denizen/nms/helpers/PlayerHelper_v1_9_R2.java
@@ -15,6 +15,8 @@

public interface PacketHelper {

void setFakeAbsorption(Player player, float value);

void resetWorldBorder(Player player);

void setWorldBorder(Player player, Location center, double size, double currSize, long time, int warningDistance, int warningTime);
@@ -9,6 +9,10 @@

public interface PlayerHelper {

float getAbsorption(Player player);

void setAbsorption(Player player, float value);

boolean hasChunkLoaded(Player player, Chunk chunk);

int getPing(Player player);
@@ -1156,6 +1156,18 @@ else if (attribute.startsWith("uuid") && !isOnline())
.getAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <p@player.absorption_health>
// @returns Element(Decimal)
// @description
// Returns the player's absorption health.
// @mechanism dPlayer.absorption_health
// -->
if (attribute.startsWith("absorption_health")) {
return new Element(NMSHandler.getInstance().getPlayerHelper().getAbsorption(getPlayerEntity()))
.getAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <p@player.health.is_scaled>
// @returns Element(Boolean)
@@ -2313,6 +2325,30 @@ public void adjust(Mechanism mechanism) {
getPlayerEntity().awardAchievement(Achievement.valueOf(value.asString().toUpperCase()));
}

// <--[mechanism]
// @object dPlayer
// @name absorption_health
// @input Element(Decimal)
// @description
// Sets the player's absorption health.
// @tags
// <p@player.absorption_health>
// -->
if (mechanism.matches("absorption_health") && mechanism.requireFloat()) {
NMSHandler.getInstance().getPlayerHelper().setAbsorption(getPlayerEntity(), mechanism.getValue().asFloat());
}

// <--[mechanism]
// @object dPlayer
// @name fake_absorption_health
// @input Element(Decimal)
// @description
// Shows the player fake absorption health that persists on damage.
// -->
if (mechanism.matches("fake_absorption_health") && mechanism.requireFloat()) {
NMSHandler.getInstance().getPacketHelper().setFakeAbsorption(getPlayerEntity(), mechanism.getValue().asFloat());
}

// <--[mechanism]
// @object dPlayer
// @name health_scale
@@ -40,15 +40,13 @@
@Override
public int getBodyArrows(Entity entity) {
// https://wiki.vg/Entity_metadata#Living
return ((CraftEntity) entity).getHandle().getDataWatcher().get(
new DataWatcherObject<>(10, DataWatcherRegistry.b));
return ((CraftEntity) entity).getHandle().getDataWatcher().get(DataWatcherRegistry.b.a(10));
}

@Override
public void setBodyArrows(Entity entity, int numArrows) {
// https://wiki.vg/Entity_metadata#Living
((CraftEntity) entity).getHandle().getDataWatcher().set(
new DataWatcherObject<>(10, DataWatcherRegistry.b), numArrows);
((CraftEntity) entity).getHandle().getDataWatcher().set(DataWatcherRegistry.b.a(10), numArrows);
}

@Override
@@ -33,6 +33,13 @@

public class PacketHelper_v1_10_R1 implements PacketHelper {

@Override
public void setFakeAbsorption(Player player, float value) {
DataWatcher dw = new DataWatcher(null);
dw.register(DataWatcherRegistry.c.a(11), value);
sendPacket(player, new PacketPlayOutEntityMetadata(player.getEntityId(), dw, true));
}

@Override
public void resetWorldBorder(Player player) {
WorldBorder wb = ((CraftWorld) player.getWorld()).getHandle().getWorldBorder();
@@ -4,10 +4,7 @@
import net.aufdemrand.denizen.nms.abstracts.ImprovedOfflinePlayer;
import net.aufdemrand.denizen.nms.impl.ImprovedOfflinePlayer_v1_10_R1;
import net.aufdemrand.denizen.nms.interfaces.PlayerHelper;
import net.minecraft.server.v1_10_R1.MinecraftServer;
import net.minecraft.server.v1_10_R1.OpList;
import net.minecraft.server.v1_10_R1.OpListEntry;
import net.minecraft.server.v1_10_R1.PacketPlayOutGameStateChange;
import net.minecraft.server.v1_10_R1.*;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.OfflinePlayer;
@@ -28,6 +25,16 @@

public class PlayerHelper_v1_10_R1 implements PlayerHelper {

@Override
public float getAbsorption(Player player) {
return ((CraftPlayer) player).getHandle().getDataWatcher().get(DataWatcherRegistry.c.a(11));
}

@Override
public void setAbsorption(Player player, float value) {
((CraftPlayer) player).getHandle().getDataWatcher().set(DataWatcherRegistry.c.a(11), value);
}

@Override
public boolean hasChunkLoaded(Player player, Chunk chunk) {
return ((CraftWorld) chunk.getWorld()).getHandle().getPlayerChunkMap()
@@ -40,15 +40,13 @@
@Override
public int getBodyArrows(Entity entity) {
// https://wiki.vg/Entity_metadata#Living
return ((CraftEntity) entity).getHandle().getDataWatcher().get(
new DataWatcherObject<>(10, DataWatcherRegistry.b));
return ((CraftEntity) entity).getHandle().getDataWatcher().get(DataWatcherRegistry.b.a(10));
}

@Override
public void setBodyArrows(Entity entity, int numArrows) {
// https://wiki.vg/Entity_metadata#Living
((CraftEntity) entity).getHandle().getDataWatcher().set(
new DataWatcherObject<>(10, DataWatcherRegistry.b), numArrows);
((CraftEntity) entity).getHandle().getDataWatcher().set(DataWatcherRegistry.b.a(10), numArrows);
}

@Override
@@ -33,6 +33,13 @@

public class PacketHelper_v1_11_R1 implements PacketHelper {

@Override
public void setFakeAbsorption(Player player, float value) {
DataWatcher dw = new DataWatcher(null);
dw.register(DataWatcherRegistry.c.a(11), value);
sendPacket(player, new PacketPlayOutEntityMetadata(player.getEntityId(), dw, true));
}

@Override
public void resetWorldBorder(Player player) {
WorldBorder wb = ((CraftWorld) player.getWorld()).getHandle().getWorldBorder();
@@ -4,10 +4,7 @@
import net.aufdemrand.denizen.nms.abstracts.ImprovedOfflinePlayer;
import net.aufdemrand.denizen.nms.impl.ImprovedOfflinePlayer_v1_11_R1;
import net.aufdemrand.denizen.nms.interfaces.PlayerHelper;
import net.minecraft.server.v1_11_R1.MinecraftServer;
import net.minecraft.server.v1_11_R1.OpList;
import net.minecraft.server.v1_11_R1.OpListEntry;
import net.minecraft.server.v1_11_R1.PacketPlayOutGameStateChange;
import net.minecraft.server.v1_11_R1.*;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.OfflinePlayer;
@@ -28,6 +25,16 @@

public class PlayerHelper_v1_11_R1 implements PlayerHelper {

@Override
public float getAbsorption(Player player) {
return ((CraftPlayer) player).getHandle().getDataWatcher().get(DataWatcherRegistry.c.a(11));
}

@Override
public void setAbsorption(Player player, float value) {
((CraftPlayer) player).getHandle().getDataWatcher().set(DataWatcherRegistry.c.a(11), value);
}

@Override
public boolean hasChunkLoaded(Player player, Chunk chunk) {
return ((CraftWorld) chunk.getWorld()).getHandle().getPlayerChunkMap()
@@ -45,15 +45,13 @@
@Override
public int getBodyArrows(Entity entity) {
// https://wiki.vg/Entity_metadata#Living
return ((CraftEntity) entity).getHandle().getDataWatcher().get(
new DataWatcherObject<>(10, DataWatcherRegistry.b));
return ((CraftEntity) entity).getHandle().getDataWatcher().get(DataWatcherRegistry.b.a(10));
}

@Override
public void setBodyArrows(Entity entity, int numArrows) {
// https://wiki.vg/Entity_metadata#Living
((CraftEntity) entity).getHandle().getDataWatcher().set(
new DataWatcherObject<>(10, DataWatcherRegistry.b), numArrows);
((CraftEntity) entity).getHandle().getDataWatcher().set(DataWatcherRegistry.b.a(10), numArrows);
}

@Override
@@ -33,6 +33,13 @@

public class PacketHelper_v1_12_R1 implements PacketHelper {

@Override
public void setFakeAbsorption(Player player, float value) {
DataWatcher dw = new DataWatcher(null);
dw.register(DataWatcherRegistry.c.a(11), value);
sendPacket(player, new PacketPlayOutEntityMetadata(player.getEntityId(), dw, true));
}

@Override
public void resetWorldBorder(Player player) {
WorldBorder wb = ((CraftWorld) player.getWorld()).getHandle().getWorldBorder();
@@ -4,10 +4,7 @@
import net.aufdemrand.denizen.nms.abstracts.ImprovedOfflinePlayer;
import net.aufdemrand.denizen.nms.impl.ImprovedOfflinePlayer_v1_12_R1;
import net.aufdemrand.denizen.nms.interfaces.PlayerHelper;
import net.minecraft.server.v1_12_R1.MinecraftServer;
import net.minecraft.server.v1_12_R1.OpList;
import net.minecraft.server.v1_12_R1.OpListEntry;
import net.minecraft.server.v1_12_R1.PacketPlayOutGameStateChange;
import net.minecraft.server.v1_12_R1.*;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.OfflinePlayer;
@@ -28,6 +25,16 @@

public class PlayerHelper_v1_12_R1 implements PlayerHelper {

@Override
public float getAbsorption(Player player) {
return ((CraftPlayer) player).getHandle().getDataWatcher().get(DataWatcherRegistry.c.a(11));
}

@Override
public void setAbsorption(Player player, float value) {
((CraftPlayer) player).getHandle().getDataWatcher().set(DataWatcherRegistry.c.a(11), value);
}

@Override
public boolean hasChunkLoaded(Player player, Chunk chunk) {
return ((CraftWorld) chunk.getWorld()).getHandle().getPlayerChunkMap()
@@ -46,22 +46,19 @@
@Override
public void setRiptide(Entity entity, boolean state) {
// https://wiki.vg/Entity_metadata#Living
((CraftEntity) entity).getHandle().getDataWatcher().set(
new DataWatcherObject<>(6, DataWatcherRegistry.a), (byte) (state ? 4 : 0));
((CraftEntity) entity).getHandle().getDataWatcher().set(DataWatcherRegistry.a.a(6), (byte) (state ? 4 : 0));
}

@Override
public int getBodyArrows(Entity entity) {
// https://wiki.vg/Entity_metadata#Living
return ((CraftEntity) entity).getHandle().getDataWatcher().get(
new DataWatcherObject<>(10, DataWatcherRegistry.b));
return ((CraftEntity) entity).getHandle().getDataWatcher().get(DataWatcherRegistry.b.a(10));
}

@Override
public void setBodyArrows(Entity entity, int numArrows) {
// https://wiki.vg/Entity_metadata#Living
((CraftEntity) entity).getHandle().getDataWatcher().set(
new DataWatcherObject<>(10, DataWatcherRegistry.b), numArrows);
((CraftEntity) entity).getHandle().getDataWatcher().set(DataWatcherRegistry.b.a(10), numArrows);
}

@Override
@@ -34,6 +34,13 @@

public class PacketHelper_v1_13_R2 implements PacketHelper {

@Override
public void setFakeAbsorption(Player player, float value) {
DataWatcher dw = new DataWatcher(null);
dw.register(DataWatcherRegistry.c.a(11), value);
sendPacket(player, new PacketPlayOutEntityMetadata(player.getEntityId(), dw, true));
}

@Override
public void resetWorldBorder(Player player) {
WorldBorder wb = ((CraftWorld) player.getWorld()).getHandle().getWorldBorder();
@@ -4,10 +4,7 @@
import net.aufdemrand.denizen.nms.abstracts.ImprovedOfflinePlayer;
import net.aufdemrand.denizen.nms.impl.ImprovedOfflinePlayer_v1_13_R2;
import net.aufdemrand.denizen.nms.interfaces.PlayerHelper;
import net.minecraft.server.v1_13_R2.MinecraftServer;
import net.minecraft.server.v1_13_R2.OpList;
import net.minecraft.server.v1_13_R2.OpListEntry;
import net.minecraft.server.v1_13_R2.PacketPlayOutGameStateChange;
import net.minecraft.server.v1_13_R2.*;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.OfflinePlayer;
@@ -28,6 +25,16 @@

public class PlayerHelper_v1_13_R2 implements PlayerHelper {

@Override
public float getAbsorption(Player player) {
return ((CraftPlayer) player).getHandle().getDataWatcher().get(DataWatcherRegistry.c.a(11));
}

@Override
public void setAbsorption(Player player, float value) {
((CraftPlayer) player).getHandle().getDataWatcher().set(DataWatcherRegistry.c.a(11), value);
}

@Override
public boolean hasChunkLoaded(Player player, Chunk chunk) {
return ((CraftWorld) chunk.getWorld()).getHandle().getPlayerChunkMap()
@@ -33,6 +33,13 @@

public class PacketHelper_v1_8_R3 implements PacketHelper {

@Override
public void setFakeAbsorption(Player player, float value) {
DataWatcher dw = new DataWatcher(null);
dw.a(17, value);
sendPacket(player, new PacketPlayOutEntityMetadata(player.getEntityId(), dw, true));
}

@Override
public void resetWorldBorder(Player player) {
WorldBorder wb = ((CraftWorld) player.getWorld()).getHandle().getWorldBorder();
@@ -21,6 +21,16 @@

public class PlayerHelper_v1_8_R3 implements PlayerHelper {

@Override
public float getAbsorption(Player player) {
return ((CraftPlayer) player).getHandle().getDataWatcher().getFloat(17);
}

@Override
public void setAbsorption(Player player, float value) {
((CraftPlayer) player).getHandle().getDataWatcher().watch(17, value);
}

@Override
public boolean hasChunkLoaded(Player player, Chunk chunk) {
return ((CraftWorld) chunk.getWorld()).getHandle().getPlayerChunkMap()
@@ -40,15 +40,13 @@
@Override
public int getBodyArrows(Entity entity) {
// https://wiki.vg/Entity_metadata#Living
return ((CraftEntity) entity).getHandle().getDataWatcher().get(
new DataWatcherObject<>(10, DataWatcherRegistry.b));
return ((CraftEntity) entity).getHandle().getDataWatcher().get(DataWatcherRegistry.b.a(10));
}

@Override
public void setBodyArrows(Entity entity, int numArrows) {
// https://wiki.vg/Entity_metadata#Living
((CraftEntity) entity).getHandle().getDataWatcher().set(
new DataWatcherObject<>(10, DataWatcherRegistry.b), numArrows);
((CraftEntity) entity).getHandle().getDataWatcher().set(DataWatcherRegistry.b.a(10), numArrows);
}

@Override
@@ -35,6 +35,13 @@

public class PacketHelper_v1_9_R2 implements PacketHelper {

@Override
public void setFakeAbsorption(Player player, float value) {
DataWatcher dw = new DataWatcher(null);
dw.register(DataWatcherRegistry.c.a(11), value);
sendPacket(player, new PacketPlayOutEntityMetadata(player.getEntityId(), dw, true));
}

@Override
public void resetWorldBorder(Player player) {
WorldBorder wb = ((CraftWorld) player.getWorld()).getHandle().getWorldBorder();

0 comments on commit b05274c

Please sign in to comment.
You can’t perform that action at this time.