mirror of
https://github.com/Auxilor/EcoArmor.git
synced 2025-12-28 03:19:25 +00:00
Made potion effects follow conditions
This commit is contained in:
@@ -15,7 +15,6 @@ import com.willfp.ecoarmor.effects.Effects;
|
||||
import com.willfp.ecoarmor.effects.util.EffectWatcher;
|
||||
import com.willfp.ecoarmor.sets.ArmorSets;
|
||||
import com.willfp.ecoarmor.sets.util.EffectiveDurabilityListener;
|
||||
import com.willfp.ecoarmor.sets.util.PotionEffectListener;
|
||||
import com.willfp.ecoarmor.sets.util.PreventSkullPlaceListener;
|
||||
import com.willfp.ecoarmor.upgrades.Tiers;
|
||||
import com.willfp.ecoarmor.upgrades.listeners.AdvancementShardListener;
|
||||
@@ -141,7 +140,6 @@ public class EcoArmorPlugin extends AbstractEcoPlugin {
|
||||
return Arrays.asList(
|
||||
new CrystalListener(this),
|
||||
new AdvancementShardListener(this),
|
||||
new PotionEffectListener(this),
|
||||
new EffectiveDurabilityListener(this),
|
||||
new DiscoverRecipeListener(this),
|
||||
new EffectWatcher(this),
|
||||
|
||||
@@ -8,6 +8,7 @@ import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class Condition<T> implements Listener {
|
||||
@@ -77,8 +78,24 @@ public abstract class Condition<T> implements Listener {
|
||||
effect.enable(player, strength);
|
||||
}
|
||||
}
|
||||
|
||||
set.getPotionEffects().forEach((potionEffectType, integer) -> {
|
||||
player.addPotionEffect(new PotionEffect(potionEffectType, 0x6fffffff, integer - 1, false, false, true));
|
||||
});
|
||||
|
||||
if (ArmorUtils.isWearingAdvanced(player)) {
|
||||
set.getAdvancedPotionEffects().forEach((potionEffectType, integer) -> {
|
||||
player.addPotionEffect(new PotionEffect(potionEffectType, 0x6fffffff, integer - 1, false, false, true));
|
||||
});
|
||||
}
|
||||
} else {
|
||||
set.getEffects().keySet().forEach(effect -> effect.disable(player));
|
||||
|
||||
for (PotionEffect effect : player.getActivePotionEffects()) {
|
||||
if (effect.getDuration() >= 500000000) {
|
||||
player.removePotionEffect(effect.getType());
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 1);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.willfp.ecoarmor.sets.util.ArmorUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class EffectWatcher extends PluginDependent implements Listener {
|
||||
@@ -34,6 +35,8 @@ public class EffectWatcher extends PluginDependent implements Listener {
|
||||
this.getPlugin().getScheduler().runLater(() -> {
|
||||
ArmorSet set = ArmorUtils.getSetOnPlayer(player);
|
||||
|
||||
boolean conditionsMet = ArmorUtils.areConditionsMet(player);
|
||||
|
||||
for (Effect<?> effect : Effects.values()) {
|
||||
boolean enabled = true;
|
||||
|
||||
@@ -55,7 +58,7 @@ public class EffectWatcher extends PluginDependent implements Listener {
|
||||
enabled = false;
|
||||
}
|
||||
|
||||
if (!ArmorUtils.areConditionsMet(player)) {
|
||||
if (!conditionsMet) {
|
||||
enabled = false;
|
||||
}
|
||||
|
||||
@@ -65,6 +68,24 @@ public class EffectWatcher extends PluginDependent implements Listener {
|
||||
effect.disable(player);
|
||||
}
|
||||
}
|
||||
|
||||
if (set == null || !conditionsMet) {
|
||||
for (PotionEffect effect : player.getActivePotionEffects()) {
|
||||
if (effect.getDuration() >= 500000000) {
|
||||
player.removePotionEffect(effect.getType());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
set.getPotionEffects().forEach((potionEffectType, integer) -> {
|
||||
player.addPotionEffect(new PotionEffect(potionEffectType, 0x6fffffff, integer - 1, false, false, true));
|
||||
});
|
||||
|
||||
if (ArmorUtils.isWearingAdvanced(player)) {
|
||||
set.getAdvancedPotionEffects().forEach((potionEffectType, integer) -> {
|
||||
player.addPotionEffect(new PotionEffect(potionEffectType, 0x6fffffff, integer - 1, false, false, true));
|
||||
});
|
||||
}
|
||||
}
|
||||
}, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
package com.willfp.ecoarmor.sets.util;
|
||||
|
||||
import com.willfp.eco.util.events.armorequip.ArmorEquipEvent;
|
||||
import com.willfp.eco.util.internal.PluginDependent;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.ecoarmor.sets.ArmorSet;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class PotionEffectListener extends PluginDependent implements Listener {
|
||||
/**
|
||||
* Create new potion effect listener for set effects.
|
||||
*
|
||||
* @param plugin EcoArmor.
|
||||
*/
|
||||
public PotionEffectListener(@NotNull final AbstractEcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply set potion effects.
|
||||
*
|
||||
* @param event The event to listen for.
|
||||
*/
|
||||
@EventHandler
|
||||
public void onEquip(@NotNull final ArmorEquipEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
|
||||
this.getPlugin().getScheduler().runLater(() -> {
|
||||
for (PotionEffect effect : player.getActivePotionEffects()) {
|
||||
if (effect.getDuration() >= 500000000) {
|
||||
player.removePotionEffect(effect.getType());
|
||||
}
|
||||
}
|
||||
|
||||
ArmorSet set = ArmorUtils.getSetOnPlayer(player);
|
||||
if (set == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
set.getPotionEffects().forEach((potionEffectType, integer) -> {
|
||||
player.addPotionEffect(new PotionEffect(potionEffectType, 0x6fffffff, integer - 1, false, false, true));
|
||||
});
|
||||
|
||||
if (ArmorUtils.isWearingAdvanced(player)) {
|
||||
set.getAdvancedPotionEffects().forEach((potionEffectType, integer) -> {
|
||||
player.addPotionEffect(new PotionEffect(potionEffectType, 0x6fffffff, integer - 1, false, false, true));
|
||||
});
|
||||
}
|
||||
}, 1);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user