mirror of
https://github.com/nulli0n/ExcellentEnchants-spigot.git
synced 2024-11-12 10:04:26 +01:00
PassiveEnchantsTask fix
This commit is contained in:
parent
d5537829eb
commit
938d15c2f4
@ -96,7 +96,7 @@ public class ExcellentEnchants extends NexPlugin<ExcellentEnchants> {
|
||||
case V1_20_R2 -> new V1_20_R2();
|
||||
default -> null;
|
||||
};
|
||||
return this.enchantManager != null;
|
||||
return this.enchantNMS != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -6,8 +6,8 @@ public interface Periodic {
|
||||
|
||||
@NotNull Periodic getPeriodImplementation();
|
||||
|
||||
default long getInterval(int level) {
|
||||
return this.getPeriodImplementation().getInterval(level);
|
||||
default long getInterval() {
|
||||
return this.getPeriodImplementation().getInterval();
|
||||
}
|
||||
|
||||
default long getNextTriggerTime() {
|
||||
@ -18,7 +18,7 @@ public interface Periodic {
|
||||
return this.getPeriodImplementation().isTriggerTime();
|
||||
}
|
||||
|
||||
default void updateTriggerTime(int level) {
|
||||
this.getPeriodImplementation().updateTriggerTime(level);
|
||||
default void updateTriggerTime() {
|
||||
this.getPeriodImplementation().updateTriggerTime();
|
||||
}
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ public abstract class ExcellentEnchant extends Enchantment implements IEnchantme
|
||||
map.add(Placeholders.ENCHANTMENT_CHANCE, () -> NumberUtil.format(chanced.getTriggerChance(level)));
|
||||
}
|
||||
if (this instanceof Periodic periodic) {
|
||||
map.add(Placeholders.ENCHANTMENT_INTERVAL, () -> NumberUtil.format(periodic.getInterval(level) / 20D));
|
||||
map.add(Placeholders.ENCHANTMENT_INTERVAL, () -> NumberUtil.format(periodic.getInterval() / 20D));
|
||||
}
|
||||
if (this instanceof Potioned potioned) {
|
||||
map.add(Placeholders.ENCHANTMENT_POTION_LEVEL, () -> NumberUtil.toRoman(potioned.getEffectAmplifier(level)));
|
||||
|
@ -34,8 +34,8 @@ public class PeriodImplementation implements Periodic {
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getInterval(int level) {
|
||||
return (long) this.triggerInterval.getValue(level);
|
||||
public long getInterval() {
|
||||
return (long) this.triggerInterval.getValue(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -49,7 +49,7 @@ public class PeriodImplementation implements Periodic {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTriggerTime(int level) {
|
||||
this.nextTriggerTime = System.currentTimeMillis() + this.getInterval(level) / 20L * 1000L;
|
||||
public void updateTriggerTime() {
|
||||
this.nextTriggerTime = System.currentTimeMillis() + this.getInterval() * 50L - 100L;
|
||||
}
|
||||
}
|
||||
|
@ -64,8 +64,8 @@ public final class PotionImplementation implements Potioned {
|
||||
|
||||
public int getEffectDuration(int level) {
|
||||
if (this.isPermanent()) {
|
||||
int duration = Config.TASKS_PASSIVE_ENCHANTS_TRIGGER_INTERVAL.get().intValue() + 30;
|
||||
if (this.getEffectType().getName().equalsIgnoreCase(PotionEffectType.NIGHT_VISION.getName())) {
|
||||
int duration = Config.TASKS_PASSIVE_ENCHANTS_TRIGGER_INTERVAL.get().intValue() * 2;
|
||||
if (this.getEffectType().getName().equalsIgnoreCase(PotionEffectType.NIGHT_VISION.getName()) && duration < 600) {
|
||||
duration += 30 * 20;
|
||||
}
|
||||
return duration;
|
||||
|
@ -3,8 +3,12 @@ package su.nightexpress.excellentenchants.enchantment.task;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import su.nexmedia.engine.api.server.AbstractTask;
|
||||
import su.nexmedia.engine.utils.Pair;
|
||||
import su.nightexpress.excellentenchants.ExcellentEnchants;
|
||||
import su.nightexpress.excellentenchants.api.enchantment.type.PassiveEnchant;
|
||||
import su.nightexpress.excellentenchants.config.Config;
|
||||
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
|
||||
import su.nightexpress.excellentenchants.enchantment.registry.EnchantRegistry;
|
||||
import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils;
|
||||
|
||||
import java.util.Collection;
|
||||
@ -13,15 +17,43 @@ import java.util.Set;
|
||||
|
||||
public class PassiveEnchantsTask extends AbstractTask<ExcellentEnchants> {
|
||||
|
||||
private final Set<Pair<PassiveEnchant, ExcellentEnchant>> enchants;
|
||||
|
||||
public PassiveEnchantsTask(@NotNull ExcellentEnchants plugin) {
|
||||
super(plugin, Config.TASKS_PASSIVE_ENCHANTS_TRIGGER_INTERVAL.get(), false);
|
||||
this.enchants = new HashSet<>();
|
||||
|
||||
EnchantRegistry.getEnchantments(PassiveEnchant.class).forEach(enchant -> {
|
||||
ExcellentEnchant excellent = EnchantRegistry.getByKey(enchant.getKey());
|
||||
if (excellent == null) return;
|
||||
|
||||
this.enchants.add(Pair.of(enchant, excellent));
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void action() {
|
||||
for (LivingEntity entity : this.getEntities()) {
|
||||
EnchantUtils.triggerPassiveEnchants(entity);
|
||||
}
|
||||
if (this.enchants.isEmpty()) return;
|
||||
|
||||
var entities = this.getEntities();
|
||||
|
||||
this.enchants.forEach(pair -> {
|
||||
PassiveEnchant enchant = pair.getFirst();
|
||||
ExcellentEnchant excellent = pair.getSecond();
|
||||
if (!enchant.isTriggerTime()) return;
|
||||
|
||||
for (LivingEntity entity : entities) {
|
||||
EnchantUtils.getEquipped(entity, excellent).forEach((item, level) -> {
|
||||
if (!enchant.isAvailableToUse(entity)) return;
|
||||
if (enchant.isOutOfCharges(item)) return;
|
||||
if (enchant.onTrigger(entity, item, level)) {
|
||||
enchant.consumeCharges(item, level);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
enchant.updateTriggerTime();
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
@ -24,7 +24,6 @@ import su.nexmedia.engine.utils.ItemUtil;
|
||||
import su.nexmedia.engine.utils.PDCUtil;
|
||||
import su.nightexpress.excellentenchants.ExcellentEnchantsAPI;
|
||||
import su.nightexpress.excellentenchants.api.enchantment.IEnchantment;
|
||||
import su.nightexpress.excellentenchants.api.enchantment.type.PassiveEnchant;
|
||||
import su.nightexpress.excellentenchants.config.Config;
|
||||
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
|
||||
import su.nightexpress.excellentenchants.enchantment.registry.EnchantRegistry;
|
||||
@ -355,23 +354,16 @@ public class EnchantUtils {
|
||||
return map;
|
||||
}
|
||||
|
||||
public static void triggerPassiveEnchants(@NotNull LivingEntity entity) {
|
||||
Player player = entity instanceof Player p1 ? p1 : null;
|
||||
|
||||
getEquipped(entity, PassiveEnchant.class).forEach((item, enchants) -> {
|
||||
enchants.forEach((enchant, level) -> {
|
||||
if (!enchant.isAvailableToUse(entity)) return;
|
||||
if (!enchant.isTriggerTime()) return;
|
||||
if (enchant.isOutOfCharges(item)) return;
|
||||
if (enchant.onTrigger(entity, item, level)) {
|
||||
enchant.consumeChargesNoUpdate(item, level);
|
||||
enchant.updateTriggerTime(level);
|
||||
}
|
||||
});
|
||||
if (Config.ENCHANTMENTS_CHARGES_ENABLED.get() && player != null) {
|
||||
EnchantUtils.updateDisplay(item);
|
||||
@NotNull
|
||||
public static Map<ItemStack, Integer> getEquipped(@NotNull LivingEntity entity, @NotNull ExcellentEnchant enchantment) {
|
||||
Map<ItemStack, Integer> map = new HashMap<>();
|
||||
getEnchantedEquipment(entity).values().forEach(item -> {
|
||||
int level = getLevel(item, enchantment);
|
||||
if (level > 0) {
|
||||
map.put(item, level);
|
||||
}
|
||||
});
|
||||
return map;
|
||||
}
|
||||
|
||||
public static void setSourceWeapon(@NotNull Projectile projectile, @Nullable ItemStack item) {
|
||||
|
Loading…
Reference in New Issue
Block a user