Skip to content

Commit dacf13d

Browse files
authored
GH-1054 Allow clearing only negative potion effects when using /heal command (#1059)
* GH-1054 Allow clearing only negative potion effects when using /heal command
1 parent 59ee476 commit dacf13d

File tree

6 files changed

+73
-1
lines changed

6 files changed

+73
-1
lines changed

buildSrc/src/main/kotlin/Versions.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ object Versions {
3434

3535
const val TRIUMPH_GUI = "3.1.12"
3636

37+
const val XSERIES = "13.3.3"
38+
3739
const val BSTATS = "3.1.0"
3840

3941
const val CAFFEINE = "3.2.2"

eternalcore-core/build.gradle.kts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ eternalShadow {
4949
"com.eternalcode.multification",
5050
)
5151

52+
// XSeries
53+
library("com.github.cryptomorin:XSeries:${Versions.XSERIES}")
54+
libraryRelocate(
55+
"com.cryptomorin.xseries",
56+
)
57+
5258
// EternalCode Commons & GitCheck
5359
library("com.eternalcode:eternalcode-commons-bukkit:${Versions.ETERNALCODE_COMMONS}")
5460
library("com.eternalcode:eternalcode-commons-adventure:${Versions.ETERNALCODE_COMMONS}")

eternalcore-core/src/main/java/com/eternalcode/core/configuration/implementation/PluginConfiguration.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.eternalcode.core.feature.automessage.AutoMessageSettings;
77
import com.eternalcode.core.feature.catboy.CatBoySettings;
88
import com.eternalcode.core.feature.chat.ChatSettings;
9+
import com.eternalcode.core.feature.heal.HealConfiguration;
910
import com.eternalcode.core.feature.helpop.HelpOpSettings;
1011
import com.eternalcode.core.feature.jail.JailSettings;
1112
import com.eternalcode.core.feature.randomteleport.RandomTeleportSettingsImpl;
@@ -154,6 +155,10 @@ public static class Homes {
154155
};
155156
}
156157

158+
@Bean
159+
@Description({ " ", "# Settings controlling how player healing works and which potion effects get cleared" })
160+
public HealConfiguration heal = new HealConfiguration();
161+
157162
@Description({ " ", "# Awesome sounds" })
158163
public Sounds sound = new Sounds();
159164

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package com.eternalcode.core.feature.heal;
22

33
import com.eternalcode.annotations.scan.command.DescriptionDocs;
4+
import com.eternalcode.core.configuration.implementation.PluginConfiguration;
45
import com.eternalcode.core.injector.annotations.Inject;
56
import com.eternalcode.core.notice.NoticeService;
7+
import com.eternalcode.core.util.PotionEffectUtil;
68
import com.eternalcode.core.viewer.Viewer;
79
import dev.rollczi.litecommands.annotations.argument.Arg;
810
import dev.rollczi.litecommands.annotations.command.Command;
@@ -16,10 +18,12 @@
1618
class HealCommand {
1719

1820
private final NoticeService noticeService;
21+
private final HealConfiguration healConfiguration;
1922

2023
@Inject
21-
HealCommand(NoticeService noticeService) {
24+
HealCommand(NoticeService noticeService, PluginConfiguration pluginConfiguration) {
2225
this.noticeService = noticeService;
26+
this.healConfiguration = pluginConfiguration.heal;
2327
}
2428

2529
@Execute
@@ -65,6 +69,11 @@ private void heal(Player player) {
6569
player.setRemainingAir(player.getMaximumAir());
6670

6771
for (PotionEffect effect : player.getActivePotionEffects()) {
72+
if (healConfiguration.removeOnlyNegativeEffects) {
73+
if (!PotionEffectUtil.isNegativeEffect(effect.getType())) {
74+
continue;
75+
}
76+
}
6877
player.removePotionEffect(effect.getType());
6978
}
7079
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.eternalcode.core.feature.heal;
2+
3+
import net.dzikoysk.cdn.entity.Contextual;
4+
import net.dzikoysk.cdn.entity.Description;
5+
6+
@Contextual
7+
public class HealConfiguration {
8+
9+
@Description({
10+
"If true, only negative potion effects will be removed on heal",
11+
"If false, all potion effects will be removed on heal"
12+
})
13+
public boolean removeOnlyNegativeEffects = true;
14+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.eternalcode.core.util;
2+
3+
import com.cryptomorin.xseries.XPotion;
4+
import com.cryptomorin.xseries.XTag;
5+
import org.bukkit.potion.PotionEffectType;
6+
7+
/**
8+
* XSeries is controversial, but it provides long-term mappings
9+
* that support multiple Minecraft versions reliably.
10+
* <p>
11+
* This utility uses XPotion from XSeries to detect negative potion effects (debuffs).
12+
* It helps keep compatibility and simplifies effect management across versions.
13+
* <p>
14+
* <u>Important:</u> Because potion effect names have changed between Minecraft versions
15+
* from 1.17.1 (our support target) up to 1.21.7 (and later),
16+
* I decided to use XSeries to handle these naming differences consistently.
17+
* <p>
18+
* This special utility class was created to avoid overusing XSeries directly
19+
* throughout the codebase and to isolate its usage in one dedicated place.
20+
*/
21+
public final class PotionEffectUtil {
22+
23+
public PotionEffectUtil() {
24+
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
25+
}
26+
27+
public static boolean isNegativeEffect(PotionEffectType effectType) {
28+
if (effectType == null) {
29+
return false;
30+
}
31+
32+
XPotion xpotion = XPotion.of(effectType);
33+
34+
return XTag.DEBUFFS.isTagged(xpotion);
35+
}
36+
}

0 commit comments

Comments
 (0)