|
1 | 1 | package me.NoChance.PvPManager.Utils;
|
2 | 2 |
|
| 3 | +import java.lang.reflect.InvocationTargetException; |
3 | 4 | import java.text.DecimalFormat;
|
4 | 5 | import java.util.List;
|
5 | 6 | import java.util.Map;
|
|
19 | 20 | import org.bukkit.event.entity.EntityCombustByEntityEvent;
|
20 | 21 | import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
21 | 22 | import org.bukkit.inventory.ItemStack;
|
| 23 | +import org.bukkit.potion.PotionEffect; |
22 | 24 | import org.bukkit.potion.PotionEffectType;
|
| 25 | +import org.bukkit.potion.PotionType; |
23 | 26 | import org.bukkit.projectiles.ProjectileSource;
|
24 | 27 |
|
25 | 28 | import me.NoChance.PvPManager.Settings.Messages;
|
26 | 29 | import me.NoChance.PvPManager.Settings.Settings;
|
27 | 30 | import me.chancesd.pvpmanager.utils.ScheduleUtils;
|
28 | 31 | import me.chancesd.sdutils.utils.Log;
|
| 32 | +import me.chancesd.sdutils.utils.ReflectionUtil; |
29 | 33 |
|
30 | 34 | public final class CombatUtils {
|
31 | 35 |
|
@@ -187,6 +191,23 @@ public static boolean isWorldExcluded(final String worldName) {
|
187 | 191 | return Settings.getWorldsExcluded().contains(worldName);
|
188 | 192 | }
|
189 | 193 |
|
| 194 | + public static boolean hasHarmfulPotion(final AreaEffectCloud areaCloud) { |
| 195 | + if (isVersionAtLeast(Settings.getMinecraftVersion(), "1.20")) { |
| 196 | + final PotionType basePotionType = areaCloud.getBasePotionType(); |
| 197 | + if (basePotionType == null) |
| 198 | + return false; |
| 199 | + final List<PotionEffect> potionTypes = basePotionType.getPotionEffects(); |
| 200 | + return !potionTypes.isEmpty() && potionTypes.stream().anyMatch(p -> isHarmfulPotion(p.getType())); |
| 201 | + } |
| 202 | + PotionEffectType potionEffectType = null; |
| 203 | + try { |
| 204 | + potionEffectType = (PotionEffectType) ReflectionUtil.invokeMethods(areaCloud, "getBasePotionData", "getType", "getEffectType"); |
| 205 | + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { |
| 206 | + Log.severe("Error getting potion type of lingering potion", e); |
| 207 | + } |
| 208 | + return potionEffectType != null && isHarmfulPotion(potionEffectType); |
| 209 | + } |
| 210 | + |
190 | 211 | public static boolean isHarmfulPotion(final PotionEffectType type) {
|
191 | 212 | return Settings.getHarmfulPotions().contains(type.getName());
|
192 | 213 | }
|
|
0 commit comments