Skip to content

Commit d46fd55

Browse files
authored
GH-1036 GH-1037 Fillup oxygen, support custom health level. (#1038)
1 parent bc36d11 commit d46fd55

File tree

1 file changed

+17
-9
lines changed
  • eternalcore-core/src/main/java/com/eternalcode/core/feature/heal

1 file changed

+17
-9
lines changed

eternalcore-core/src/main/java/com/eternalcode/core/feature/heal/HealCommand.java

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
import com.eternalcode.core.notice.NoticeService;
66
import com.eternalcode.core.viewer.Viewer;
77
import dev.rollczi.litecommands.annotations.argument.Arg;
8+
import dev.rollczi.litecommands.annotations.command.Command;
89
import dev.rollczi.litecommands.annotations.context.Context;
910
import dev.rollczi.litecommands.annotations.execute.Execute;
1011
import dev.rollczi.litecommands.annotations.permission.Permission;
11-
import dev.rollczi.litecommands.annotations.command.Command;
1212
import org.bukkit.entity.Player;
1313
import org.bukkit.potion.PotionEffect;
1414

@@ -25,7 +25,7 @@ class HealCommand {
2525
@Execute
2626
@Permission("eternalcore.heal")
2727
@DescriptionDocs(description = "Heal yourself")
28-
void execute(@Context Player player) {
28+
void healSelf(@Context Player player) {
2929
this.heal(player);
3030

3131
this.noticeService.player(player.getUniqueId(), translation -> translation.player().healMessage());
@@ -34,30 +34,38 @@ void execute(@Context Player player) {
3434
@Execute
3535
@Permission("eternalcore.heal.other")
3636
@DescriptionDocs(description = "Heal other player", arguments = "<player>")
37-
void execute(@Context Viewer viewer, @Arg Player target) {
37+
void healOther(@Context Viewer viewer, @Arg Player target) {
3838
this.heal(target);
3939

4040
this.noticeService.create()
4141
.notice(translation -> translation.player().healMessage())
4242
.player(target.getUniqueId())
4343
.send();
4444

45-
4645
this.noticeService.create()
4746
.notice(translation -> translation.player().healMessageBy())
4847
.placeholder("{PLAYER}", target.getName())
4948
.viewer(viewer)
5049
.send();
5150
}
5251

53-
void heal(Player player) {
52+
private void heal(Player player) {
53+
/*
54+
* Sets the player's health to their maximum health.
55+
* We avoid using Attribute.GENERIC_MAX_HEALTH or Attribute.MAX_HEALTH directly
56+
* because the Attribute API has changed in recent Paper versions,
57+
* To maintain compatibility with older versions, we use player.getMaxHealth(),
58+
* which provides a stable way to get the player's max health.
59+
*/
60+
double maxHealth = player.getMaxHealth();
61+
62+
player.setHealth(maxHealth);
5463
player.setFoodLevel(20);
55-
player.setHealth(20);
5664
player.setFireTicks(0);
65+
player.setRemainingAir(player.getMaximumAir());
5766

58-
for (PotionEffect potionEffect : player.getActivePotionEffects()) {
59-
player.removePotionEffect(potionEffect.getType());
67+
for (PotionEffect effect : player.getActivePotionEffects()) {
68+
player.removePotionEffect(effect.getType());
6069
}
6170
}
62-
6371
}

0 commit comments

Comments
 (0)