-
-
Notifications
You must be signed in to change notification settings - Fork 104
/
PlayerBars.java
75 lines (62 loc) · 2.94 KB
/
PlayerBars.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package net.aufdemrand.denizen.utilities.packets;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.minecraft.server.v1_9_R1.PacketPlayOutExperience;
import net.minecraft.server.v1_9_R1.PacketPlayOutUpdateHealth;
import org.bukkit.entity.Player;
import java.lang.reflect.Field;
import java.util.Map;
public class PlayerBars {
private static final Field xp_current, xp_total, xp_level;
private static final Field health_health, health_food, health_saturation;
static {
Map<String, Field> fields = PacketHelper.registerFields(PacketPlayOutExperience.class);
xp_current = fields.get("a");// TODO: 1.9
xp_total = fields.get("b");// TODO: 1.9
xp_level = fields.get("c");// TODO: 1.9
fields = PacketHelper.registerFields(PacketPlayOutUpdateHealth.class);
health_health = fields.get("a");// TODO: 1.9
health_food = fields.get("b");// TODO: 1.9
health_saturation = fields.get("c");// TODO: 1.9
}
public static PacketPlayOutExperience getExperiencePacket(float exp, int level) {
PacketPlayOutExperience experiencePacket = new PacketPlayOutExperience();
try {
xp_current.set(experiencePacket, exp);
// xp_total.set(experiencePacket, totalExp);
xp_level.set(experiencePacket, level);
}
catch (Exception e) {
dB.echoError(e);
}
return experiencePacket;
}
public static PacketPlayOutUpdateHealth getHealthPacket(float health, int food, float food_saturation) {
PacketPlayOutUpdateHealth healthPacket = new PacketPlayOutUpdateHealth();
try {
health_health.set(healthPacket, health);
health_food.set(healthPacket, food);
health_saturation.set(healthPacket, food_saturation);
}
catch (Exception e) {
dB.echoError(e);
}
return healthPacket;
}
public static void showHealth(Player player, float health, int food, float food_saturation) {
PacketPlayOutUpdateHealth healthPacket = getHealthPacket(health, food, food_saturation);
PacketHelper.sendPacket(player, healthPacket);
}
public static void showExperience(Player player, float experience, int level) {
PacketPlayOutExperience experiencePacket = getExperiencePacket(experience, level);
PacketHelper.sendPacket(player, experiencePacket);
}
public static void resetExperience(Player player) {
PacketPlayOutExperience experiencePacket = getExperiencePacket(player.getExp(), player.getLevel());
PacketHelper.sendPacket(player, experiencePacket);
}
public static void resetHealth(Player player) {
PacketPlayOutUpdateHealth healthPacket = getHealthPacket((float) player.getHealth(),
player.getFoodLevel(), player.getSaturation());
PacketHelper.sendPacket(player, healthPacket);
}
}