|
| 1 | +package de.kiridevs.ksmpplugin.features; |
| 2 | + |
| 3 | +import org.bukkit.Bukkit; |
| 4 | +import org.bukkit.entity.Player; |
| 5 | +import org.bukkit.event.EventHandler; |
| 6 | +import org.bukkit.event.Listener; |
| 7 | +import org.bukkit.event.entity.EntityPotionEffectEvent; |
| 8 | +import org.bukkit.potion.PotionEffect; |
| 9 | +import org.bukkit.potion.PotionEffectType; |
| 10 | + |
| 11 | +import de.kiridevs.ksmpplugin.main.KiriSmpPlugin; |
| 12 | + |
| 13 | +public class ShorterMiningFatigue implements Listener { |
| 14 | + public static final PotionEffectType GUARDIAN_FATIGUE_TYPE = PotionEffectType.SLOW_DIGGING; |
| 15 | + private static final int GUARDIAN_FATIGUE_AMPLIFIER = 2; |
| 16 | + private static final int GUARDIAN_FATIGUE_TICK_DURATION = 20 * 60 * 5; |
| 17 | + private static final int SHORTENED_DURATION = 20 * 60 * 2; |
| 18 | + |
| 19 | + private final KiriSmpPlugin plugin; |
| 20 | + |
| 21 | + public ShorterMiningFatigue(KiriSmpPlugin plugin) { |
| 22 | + this.plugin = plugin; |
| 23 | + } |
| 24 | + |
| 25 | + public void init() { |
| 26 | + this.plugin.log.info("features: ShorterMiningFatigue: Initializing"); |
| 27 | + Bukkit.getPluginManager().registerEvents(this, this.plugin); |
| 28 | + } |
| 29 | + |
| 30 | + @EventHandler |
| 31 | + public void onMiningFatigue(EntityPotionEffectEvent event) { |
| 32 | + // Check if this is Mining Fatigue being added by an Elder Guardian |
| 33 | + if (!(event.getEntity() instanceof Player player)) return; |
| 34 | + if (!event.getAction().equals(EntityPotionEffectEvent.Action.ADDED)) return; |
| 35 | + if (!event.getCause().equals(EntityPotionEffectEvent.Cause.ATTACK)) return; |
| 36 | + |
| 37 | + PotionEffect effect = event.getNewEffect(); |
| 38 | + if (effect == null) { |
| 39 | + plugin.log.warning("Added potion effect is null?"); |
| 40 | + return; |
| 41 | + } |
| 42 | + |
| 43 | + if (!effect.getType().equals(ShorterMiningFatigue.GUARDIAN_FATIGUE_TYPE)) return; |
| 44 | + if (effect.getAmplifier() != GUARDIAN_FATIGUE_AMPLIFIER) return; |
| 45 | + if (effect.getDuration() != GUARDIAN_FATIGUE_TICK_DURATION) return; |
| 46 | + |
| 47 | + // Apply a shorter copy ... |
| 48 | + player.addPotionEffect(new PotionEffect( |
| 49 | + GUARDIAN_FATIGUE_TYPE, SHORTENED_DURATION, |
| 50 | + effect.getAmplifier(), effect.isAmbient(), effect.hasParticles() |
| 51 | + )); |
| 52 | + // ... and cancel adding the original effect |
| 53 | + event.setCancelled(true); |
| 54 | + } |
| 55 | +} |
0 commit comments