5
5
import com .eternalcode .core .notice .NoticeService ;
6
6
import com .eternalcode .core .viewer .Viewer ;
7
7
import dev .rollczi .litecommands .annotations .argument .Arg ;
8
+ import dev .rollczi .litecommands .annotations .command .Command ;
8
9
import dev .rollczi .litecommands .annotations .context .Context ;
9
10
import dev .rollczi .litecommands .annotations .execute .Execute ;
10
11
import dev .rollczi .litecommands .annotations .permission .Permission ;
11
- import dev .rollczi .litecommands .annotations .command .Command ;
12
12
import org .bukkit .entity .Player ;
13
13
import org .bukkit .potion .PotionEffect ;
14
14
@@ -25,7 +25,7 @@ class HealCommand {
25
25
@ Execute
26
26
@ Permission ("eternalcore.heal" )
27
27
@ DescriptionDocs (description = "Heal yourself" )
28
- void execute (@ Context Player player ) {
28
+ void healSelf (@ Context Player player ) {
29
29
this .heal (player );
30
30
31
31
this .noticeService .player (player .getUniqueId (), translation -> translation .player ().healMessage ());
@@ -34,30 +34,38 @@ void execute(@Context Player player) {
34
34
@ Execute
35
35
@ Permission ("eternalcore.heal.other" )
36
36
@ 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 ) {
38
38
this .heal (target );
39
39
40
40
this .noticeService .create ()
41
41
.notice (translation -> translation .player ().healMessage ())
42
42
.player (target .getUniqueId ())
43
43
.send ();
44
44
45
-
46
45
this .noticeService .create ()
47
46
.notice (translation -> translation .player ().healMessageBy ())
48
47
.placeholder ("{PLAYER}" , target .getName ())
49
48
.viewer (viewer )
50
49
.send ();
51
50
}
52
51
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 );
54
63
player .setFoodLevel (20 );
55
- player .setHealth (20 );
56
64
player .setFireTicks (0 );
65
+ player .setRemainingAir (player .getMaximumAir ());
57
66
58
- for (PotionEffect potionEffect : player .getActivePotionEffects ()) {
59
- player .removePotionEffect (potionEffect .getType ());
67
+ for (PotionEffect effect : player .getActivePotionEffects ()) {
68
+ player .removePotionEffect (effect .getType ());
60
69
}
61
70
}
62
-
63
71
}
0 commit comments