This commit is contained in:
nulli0n 2022-11-30 19:18:05 +06:00
parent e2835aee73
commit a4cc0bfd88
34 changed files with 607 additions and 213 deletions

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>ExcellentEnchants</artifactId>
<groupId>su.nightexpress.excellentenchants</groupId>
<version>3.2.7</version>
<version>3.2.8</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@ -36,22 +36,22 @@
<dependency>
<groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>NMS</artifactId>
<version>3.2.7</version>
<version>3.2.8</version>
</dependency>
<dependency>
<groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>V1_17_R1</artifactId>
<version>3.2.7</version>
<version>3.2.8</version>
</dependency>
<dependency>
<groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>V1_18_R2</artifactId>
<version>3.2.7</version>
<version>3.2.8</version>
</dependency>
<dependency>
<groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>V1_19_R1</artifactId>
<version>3.2.7</version>
<version>3.2.8</version>
</dependency>
<dependency>
<groupId>fr.neatmonster</groupId>

View File

@ -6,7 +6,6 @@ import su.nexmedia.engine.NexPlugin;
import su.nexmedia.engine.Version;
import su.nexmedia.engine.api.command.GeneralCommand;
import su.nexmedia.engine.command.list.ReloadSubCommand;
import su.nexmedia.engine.utils.Reflex;
import su.nightexpress.excellentenchants.command.BookCommand;
import su.nightexpress.excellentenchants.command.EnchantCommand;
import su.nightexpress.excellentenchants.command.ListCommand;
@ -16,6 +15,9 @@ import su.nightexpress.excellentenchants.config.Lang;
import su.nightexpress.excellentenchants.manager.EnchantManager;
import su.nightexpress.excellentenchants.manager.type.FitItemType;
import su.nightexpress.excellentenchants.nms.EnchantNMS;
import su.nightexpress.excellentenchants.nms.v1_17_R1.V1_17_R1;
import su.nightexpress.excellentenchants.nms.v1_18_R2.V1_18_R2;
import su.nightexpress.excellentenchants.nms.v1_19_R1.V1_19_R1;
public class ExcellentEnchants extends NexPlugin<ExcellentEnchants> {
@ -51,20 +53,12 @@ public class ExcellentEnchants extends NexPlugin<ExcellentEnchants> {
}
private boolean setNMS() {
Version current = Version.CURRENT;
if (current == null) return false;
String pack = EnchantNMS.class.getPackage().getName();
Class<?> clazz = Reflex.getClass(pack, current.name());
if (clazz == null) return false;
try {
this.enchantNMS = (EnchantNMS) clazz.getConstructor().newInstance();
}
catch (Exception e) {
e.printStackTrace();
}
return this.enchantNMS != null;
this.enchantNMS = switch (Version.CURRENT) {
case V1_17_R1 -> new V1_17_R1();
case V1_18_R2 -> new V1_18_R2();
case V1_19_R1 -> new V1_19_R1();
};
return true;
}
@Override

View File

@ -0,0 +1,6 @@
package su.nightexpress.excellentenchants;
public class ExcellentEnchantsAPI {
public static final ExcellentEnchants PLUGIN = ExcellentEnchants.getPlugin(ExcellentEnchants.class);
}

View File

@ -316,9 +316,11 @@ public abstract class ExcellentEnchant extends Enchantment implements IListener
}
public int getLevelByEnchantCost(int expLevel) {
Optional<Map.Entry<Integer, Double>> opt = this.levelByEnchantCost.getValues().entrySet().stream()
.filter(en -> expLevel >= en.getValue().intValue()).max(Comparator.comparingInt(Map.Entry::getKey));
return opt.isPresent() ? opt.get().getKey() : Rnd.get(this.getStartLevel(), this.getMaxLevel());
int get = this.levelByEnchantCost.getValues().entrySet().stream()
.filter(en -> expLevel >= en.getValue().intValue()).max(Comparator.comparingInt(Map.Entry::getKey))
.map(Map.Entry::getKey).orElse(0);
return get != 0 ? this.fineLevel(get, ObtainType.ENCHANTING) : 0;
}
public double getObtainChance(@NotNull ObtainType obtainType) {
@ -333,6 +335,16 @@ public abstract class ExcellentEnchant extends Enchantment implements IListener
return this.obtainLevelCap.getOrDefault(obtainType, Pair.of(-1, -1)).getSecond();
}
public int fineLevel(int level, @NotNull ObtainType obtainType) {
int levelCapMin = this.getObtainLevelMin(obtainType);
int levelCapMax = this.getObtainLevelMax(obtainType);
if (levelCapMin > 0 && level < levelCapMin) level = levelCapMin;
if (levelCapMax > 0 && level > levelCapMax) level = levelCapMax;
return level;
}
public int generateLevel() {
return Rnd.get(this.getStartLevel(), this.getMaxLevel());
}

View File

@ -72,8 +72,17 @@ public abstract class IEnchantPotionTemplate extends IEnchantChanceTemplate {
return new PotionEffect(this.potionEffectType, duration, amplifier, false, this.potionParticles);
}
public final boolean hasEffect(@NotNull LivingEntity entity) {
return EnchantManager.hasEnchantmentEffect(entity, this);
}
public final boolean addEffect(@NotNull LivingEntity target, int level) {
EnchantManager.addPotionEffect(target, this.getEffect(level), true);
if (this instanceof PassiveEnchant) {
this.plugin.getEnchantNMS().addEnchantmentEffect(target, this, this.getEffect(level));
}
else {
target.addPotionEffect(this.getEffect(level));
}
return true;
}
}

View File

@ -2,6 +2,7 @@ package su.nightexpress.excellentenchants.config;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import su.nexmedia.engine.api.config.JOption;
import su.nexmedia.engine.api.config.JYML;
import su.nexmedia.engine.utils.Placeholders;
import su.nexmedia.engine.utils.StringUtil;
@ -17,7 +18,7 @@ import java.util.stream.Collectors;
public class Config {
public static long TASKS_ARROW_TRAIL_TICKS_INTERVAL;
public static long TASKS_PASSIVE_ENCHANTS_TICKS_INTERVAL;
public static final JOption<Integer> TASKS_PASSIVE_POTION_EFFECTS_APPLY_INTERVAL = JOption.create("General.Tasks.Passive_Potion_Effects.Apply_Interval", "Sets how often (in ticks) the plugin will apply permanent potion effects from enchanted items to an entity who wear them.\nThis setting does NOT refreshes currently active effects, but only attempts to add them if absent.", 150);
public static Set<String> ENCHANTMENTS_DISABLED;
public static Map<String, Set<String>> ENCHANTMENTS_DISABLED_IN_WORLDS;
@ -35,10 +36,10 @@ public class Config {
public static void load(@NotNull ExcellentEnchants plugin) {
JYML cfg = plugin.getConfig();
cfg.initializeOptions(Config.class);
String path = "General.Tasks.";
TASKS_ARROW_TRAIL_TICKS_INTERVAL = cfg.getLong(path + "Arrow_Trails.Ticks_Interval", 1);
TASKS_PASSIVE_ENCHANTS_TICKS_INTERVAL = cfg.getLong(path + "Passive_Enchants.Ticks_Interval", 100);
path = "General.Enchantments.";
cfg.addMissing(path + "Disabled_In_Worlds.my_world", Collections.singletonList(Placeholders.MASK_ANY));

View File

@ -4,6 +4,7 @@ import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.entity.LivingEntity;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
import org.bukkit.inventory.meta.ItemMeta;
@ -11,21 +12,28 @@ import org.bukkit.potion.PotionEffect;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import su.nexmedia.engine.api.manager.AbstractManager;
import su.nexmedia.engine.utils.EntityUtil;
import su.nexmedia.engine.utils.ItemUtil;
import su.nexmedia.engine.utils.random.Rnd;
import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.ExcellentEnchantsAPI;
import su.nightexpress.excellentenchants.api.enchantment.ExcellentEnchant;
import su.nightexpress.excellentenchants.api.enchantment.IEnchantPotionTemplate;
import su.nightexpress.excellentenchants.api.enchantment.type.PassiveEnchant;
import su.nightexpress.excellentenchants.config.Config;
import su.nightexpress.excellentenchants.config.ObtainSettings;
import su.nightexpress.excellentenchants.manager.listeners.EnchantGenericListener;
import su.nightexpress.excellentenchants.manager.listeners.EnchantHandlerListener;
import su.nightexpress.excellentenchants.manager.object.EnchantListGUI;
import su.nightexpress.excellentenchants.manager.object.EnchantPopulator;
import su.nightexpress.excellentenchants.manager.object.EnchantTier;
import su.nightexpress.excellentenchants.manager.tasks.ArrowTrailsTask;
import su.nightexpress.excellentenchants.manager.tasks.EnchantEffectPassiveTask;
import su.nightexpress.excellentenchants.manager.type.ObtainType;
import java.util.*;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@ -76,19 +84,6 @@ public class EnchantManager extends AbstractManager<ExcellentEnchants> {
return enchantListGUI;
}
public static void addPotionEffect(@NotNull LivingEntity entity, @NotNull PotionEffect effect, boolean compat) {
if (compat) {
PotionEffect has = entity.getPotionEffect(effect.getType());
if (has != null && has.getAmplifier() > effect.getAmplifier()) {
return;
}
}
else {
entity.removePotionEffect(effect.getType());
}
entity.addPotionEffect(effect);
}
public static boolean isEnchantable(@NotNull ItemStack item) {
if (item.getType().isAir()) return false;
@ -96,28 +91,73 @@ public class EnchantManager extends AbstractManager<ExcellentEnchants> {
/*|| ItemUtil.isWeapon(item) || ItemUtil.isArmor(item) || ItemUtil.isTool(item) || ItemUtil.isBow(item)*/;
}
public static boolean populateEnchantments(@NotNull ItemStack item, @NotNull ObtainType obtainType) {
@NotNull
public static Map<Enchantment, Integer> getEnchantsToPopulate(@NotNull ItemStack item, @NotNull ObtainType obtainType) {
return getEnchantsToPopulate(item, obtainType, new HashMap<>(), (enchant) -> enchant.generateLevel(obtainType));
}
@NotNull
public static Map<Enchantment, Integer> getEnchantsToPopulate(@NotNull ItemStack item, @NotNull ObtainType obtainType,
@NotNull Map<Enchantment, Integer> enchantsPrepared,
@NotNull Function<ExcellentEnchant, Integer> levelFunc) {
Map<Enchantment, Integer> enchantsToAdd = new HashMap<>(enchantsPrepared);
ObtainSettings settings = Config.getObtainSettings(obtainType);
if (settings == null) return false;
if (settings == null || !Rnd.chance(settings.getEnchantsCustomGenerationChance())) return enchantsToAdd;
if (Rnd.get(true) > settings.getEnchantsCustomGenerationChance()) return false;
int enchHas = EnchantManager.getItemEnchantsAmount(item);
int enchMax = settings.getEnchantsTotalMax();
int enchRoll = Rnd.get(settings.getEnchantsCustomMin(), settings.getEnchantsCustomMax());
for (int count = 0; (count < enchRoll && count + enchHas < enchMax); count++) {
EnchantTier tier = EnchantManager.getTierByChance(obtainType);
if (tier == null) continue;
// Класс для исключения неудачных попыток.
EnchantPopulator populator = new EnchantPopulator(obtainType, item);
ExcellentEnchant enchant = tier.getEnchant(obtainType, item);
if (enchant == null) continue;
// Херачим до талого, пока нужное количество не будет добавлено
// или не закончатся чары и/или тиры.
while (!populator.isEmpty() && enchRoll > 0) {
// Достигнут максимум чар (любых) для итема, заканчиваем.
if (enchantsToAdd.size() >= enchMax) break;
int level = enchant.generateLevel(obtainType);
EnchantManager.addEnchant(item, enchant, level, false);
EnchantTier tier = populator.getTierByChance();
if (tier == null) break; // Нет тира?
ExcellentEnchant enchant = populator.getEnchantByChance(tier);
// В тире нет подходящих чар (вообще) для итема, исключаем и идем дальше.
if (enchant == null) {
populator.getEnchants().remove(tier);
continue;
}
// Среди уже добавленных чар есть конфликты с тем, что нашли.
// Исключаем, идем дальше.
if (enchantsToAdd.keySet().stream().anyMatch(has -> has.conflictsWith(enchant) || enchant.conflictsWith(has))) {
populator.getEnchants(tier).remove(enchant);
continue;
}
// Не получилось сгенерировать подходящий уровень.
// Исключаем, идем дальше.
int level = levelFunc.apply(enchant);
if (level < enchant.getStartLevel()) {
populator.getEnchants(tier).remove(enchant);
continue;
}
// Добавляем чар, засчитываем попытку.
populator.getEnchants(tier).remove(enchant);
enchantsToAdd.put(enchant, level);
enchRoll--;
}
EnchantManager.updateItemLoreEnchants(item);
return true;
return enchantsToAdd;
}
public static boolean populateEnchantments(@NotNull ItemStack item, @NotNull ObtainType obtainType) {
int enchantsHad = EnchantManager.getItemCustomEnchantsAmount(item);
EnchantManager.getEnchantsToPopulate(item, obtainType).forEach((enchantment, level) -> {
EnchantManager.addEnchant(item, enchantment, level, false);
});
return EnchantManager.getItemCustomEnchantsAmount(item) != enchantsHad;
}
public static void updateItemLoreEnchants(@NotNull ItemStack item) {
@ -149,35 +189,40 @@ public class EnchantManager extends AbstractManager<ExcellentEnchants> {
}
}
public static boolean addEnchant(@NotNull ItemStack item, @NotNull ExcellentEnchant ench, int level, boolean force) {
if (!force && !ench.canEnchantItem(item)) return false;
public static boolean addEnchant(@NotNull ItemStack item, @NotNull Enchantment enchantment, int level, boolean force) {
if (!force && !enchantment.canEnchantItem(item)) return false;
EnchantManager.removeEnchant(item, ench);
ItemUtil.addLore(item, ench.getId(), ench.getNameFormatted(level), 0);
EnchantManager.removeEnchant(item, enchantment);
if (enchantment instanceof ExcellentEnchant excellentEnchant) {
ItemUtil.addLore(item, excellentEnchant.getId(), excellentEnchant.getNameFormatted(level), 0);
}
ItemMeta meta = item.getItemMeta();
if (meta == null) return false;
if (meta instanceof EnchantmentStorageMeta meta2) {
if (!meta2.addStoredEnchant(ench, level, true)) return false;
if (meta instanceof EnchantmentStorageMeta storageMeta) {
if (!storageMeta.addStoredEnchant(enchantment, level, true)) return false;
}
else {
if (!meta.addEnchant(ench, level, true)) return false;
if (!meta.addEnchant(enchantment, level, true)) return false;
}
item.setItemMeta(meta);
return true;
}
public static void removeEnchant(@NotNull ItemStack item, @NotNull ExcellentEnchant en) {
ItemUtil.delLore(item, en.getId());
public static void removeEnchant(@NotNull ItemStack item, @NotNull Enchantment enchantment) {
if (enchantment instanceof ExcellentEnchant excellentEnchant) {
ItemUtil.delLore(item, excellentEnchant.getId());
}
ItemMeta meta = item.getItemMeta();
if (meta instanceof EnchantmentStorageMeta meta2) {
meta2.removeStoredEnchant(en);
if (meta instanceof EnchantmentStorageMeta storageMeta) {
storageMeta.removeStoredEnchant(enchantment);
}
else {
meta.removeEnchant(en);
meta.removeEnchant(enchantment);
}
item.setItemMeta(meta);
}
@ -204,9 +249,15 @@ public class EnchantManager extends AbstractManager<ExcellentEnchants> {
return EnchantManager.getItemCustomEnchants(item).size();
}
public static int getItemEnchantLevel(@NotNull ItemStack item, @NotNull Enchantment enchantment) {
return getItemEnchants(item).getOrDefault(enchantment, 0);
}
@NotNull
public static Map<Enchantment, Integer> getItemEnchants(@NotNull ItemStack item) {
ItemMeta meta = item.getItemMeta();
if (meta == null) return Collections.emptyMap();
return (meta instanceof EnchantmentStorageMeta meta2) ? meta2.getStoredEnchants() : meta.getEnchants();
}
@ -214,6 +265,70 @@ public class EnchantManager extends AbstractManager<ExcellentEnchants> {
return EnchantManager.getItemEnchants(item).size();
}
public static int getEnchantmentLevel(@NotNull ItemStack item, @NotNull Enchantment enchant) {
ItemMeta meta = item.getItemMeta();
if (meta == null) return 0;
return meta.getEnchantLevel(enchant);
}
@Nullable
public static ExcellentEnchant getEnchantmentByEffect(@NotNull LivingEntity entity, @NotNull PotionEffect effect) {
Enchantment enchantment = ExcellentEnchantsAPI.PLUGIN.getEnchantNMS().getEnchantmentByEffect(entity, effect);
if (enchantment instanceof ExcellentEnchant enchant) return enchant;
return null;
}
public static boolean isEnchantmentEffect(@NotNull LivingEntity entity, @NotNull PotionEffect effect) {
return getEnchantmentByEffect(entity, effect) != null;
}
public static boolean hasEnchantmentEffect(@NotNull LivingEntity entity, @NotNull ExcellentEnchant enchant) {
return entity.getActivePotionEffects().stream().anyMatch(effect -> enchant.equals(getEnchantmentByEffect(entity, effect)));
}
@NotNull
public static Map<ExcellentEnchant, Integer> getEquippedEnchantsMax(@NotNull LivingEntity entity) {
return getEquippedEnchants(entity, Math::max);
}
@NotNull
public static Map<ExcellentEnchant, Integer> getEquippedEnchantsTotal(@NotNull LivingEntity entity) {
return getEquippedEnchants(entity, Integer::sum);
}
@NotNull
private static Map<ExcellentEnchant, Integer> getEquippedEnchants(@NotNull LivingEntity entity, @NotNull BiFunction<Integer, Integer, Integer> remap) {
Map<ExcellentEnchant, Integer> map = new HashMap<>();
Map<EquipmentSlot, ItemStack> equipment = EntityUtil.getEquippedItems(entity);
equipment.entrySet().stream().filter(entry -> {
if (entry.getValue().getType() == Material.ENCHANTED_BOOK) return false;
if ((entry.getKey() == EquipmentSlot.HAND || entry.getKey() == EquipmentSlot.OFF_HAND) && ItemUtil.isArmor(entry.getValue())) return false;
return true;
}).map(Map.Entry::getValue).map(EnchantManager::getItemCustomEnchants).forEach(itemEnchants -> {
itemEnchants.forEach((enchant, level) -> map.merge(enchant, level, remap));
});
return map;
}
public static int getEquippedEnchantLevelMax(@NotNull LivingEntity entity, @NotNull ExcellentEnchant enchant) {
return getEquippedEnchantsMax(entity).getOrDefault(enchant, 0);
}
public static int getEquippedEnchantLevelTotal(@NotNull LivingEntity entity, @NotNull ExcellentEnchant enchant) {
return getEquippedEnchantsTotal(entity).getOrDefault(enchant, 0);
}
public static void updateEquippedEnchantEffects(@NotNull LivingEntity entity) {
getEquippedEnchantsMax(entity).forEach((enchant, level) -> {
if (enchant instanceof PassiveEnchant passiveEnchant && enchant instanceof IEnchantPotionTemplate) {
passiveEnchant.use(entity, level);
}
});
}
@Nullable
public static EnchantTier getTierById(@NotNull String id) {
return Config.getTierById(id);

View File

@ -15,6 +15,7 @@ import su.nexmedia.engine.utils.NumberUtil;
import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.api.enchantment.EnchantPriority;
import su.nightexpress.excellentenchants.api.enchantment.IEnchantChanceTemplate;
import su.nightexpress.excellentenchants.manager.EnchantManager;
import su.nightexpress.excellentenchants.manager.object.EnchantScaler;
import java.util.function.UnaryOperator;
@ -85,7 +86,7 @@ public class EnchantElementalProtection extends IEnchantChanceTemplate {
for (ItemStack armor : EntityUtil.getArmor(victim)) {
if (armor == null || armor.getType().isAir()) continue;
int level = armor.getEnchantmentLevel(this);
int level = EnchantManager.getItemEnchantLevel(armor, this);
if (this.checkTriggerChance(level)) {
protectionAmount += this.getProtectionAmount(level);
}

View File

@ -26,6 +26,7 @@ import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.api.enchantment.EnchantPriority;
import su.nightexpress.excellentenchants.api.enchantment.IEnchantChanceTemplate;
import su.nightexpress.excellentenchants.api.enchantment.type.MoveEnchant;
import su.nightexpress.excellentenchants.manager.EnchantManager;
import su.nightexpress.excellentenchants.manager.object.EnchantScaler;
import java.util.HashMap;
@ -112,7 +113,8 @@ public class EnchantFlameWalker extends IEnchantChanceTemplate implements MoveEn
ItemStack boots = player.getInventory().getBoots();
if (boots == null || boots.getType().isAir()) return;
int level = boots.getEnchantmentLevel(this);
//int level = boots.getEnchantmentLevel(this);
int level = EnchantManager.getItemEnchants(boots).getOrDefault(this, 0);
if (level < 1) return;
Block bTo = to.getBlock().getRelative(BlockFace.DOWN);
@ -143,7 +145,7 @@ public class EnchantFlameWalker extends IEnchantChanceTemplate implements MoveEn
ItemStack boots = equipment.getBoots();
if (boots == null || boots.getType().isAir()) return;
int level = boots.getEnchantmentLevel(this);
int level = EnchantManager.getItemEnchantLevel(boots, this);
if (level < 1) return;
if (!this.checkTriggerChance(level)) return;

View File

@ -4,8 +4,6 @@ import org.bukkit.Particle;
import org.bukkit.attribute.Attribute;
import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.entity.LivingEntity;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.NotNull;
import su.nexmedia.engine.api.config.JYML;
import su.nexmedia.engine.api.manager.ICleanable;
@ -15,11 +13,13 @@ import su.nexmedia.engine.utils.EntityUtil;
import su.nexmedia.engine.utils.NumberUtil;
import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.api.enchantment.EnchantPriority;
import su.nightexpress.excellentenchants.api.enchantment.ExcellentEnchant;
import su.nightexpress.excellentenchants.api.enchantment.IEnchantChanceTemplate;
import su.nightexpress.excellentenchants.api.enchantment.type.PassiveEnchant;
import su.nightexpress.excellentenchants.manager.object.EnchantScaler;
import su.nightexpress.excellentenchants.manager.tasks.AbstractEnchantPassiveTask;
import java.util.Map;
import java.util.function.UnaryOperator;
public class EnchantRegrowth extends IEnchantChanceTemplate implements PassiveEnchant, ICleanable {
@ -115,11 +115,8 @@ public class EnchantRegrowth extends IEnchantChanceTemplate implements PassiveEn
}
@Override
protected void apply(@NotNull LivingEntity entity, @NotNull ItemStack armor, @NotNull ItemMeta meta) {
int level = meta.getEnchantLevel(EnchantRegrowth.this);
if (level < 1) return;
use(entity, level);
protected void apply(@NotNull LivingEntity entity, @NotNull Map<ExcellentEnchant, Integer> enchants) {
use(entity, enchants.getOrDefault(EnchantRegrowth.this, 0));
}
}
}

View File

@ -3,8 +3,6 @@ package su.nightexpress.excellentenchants.manager.enchants.armor;
import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.NotNull;
import su.nexmedia.engine.api.config.JYML;
import su.nexmedia.engine.api.manager.ICleanable;
@ -12,11 +10,13 @@ import su.nexmedia.engine.manager.leveling.Scaler;
import su.nexmedia.engine.utils.NumberUtil;
import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.api.enchantment.EnchantPriority;
import su.nightexpress.excellentenchants.api.enchantment.ExcellentEnchant;
import su.nightexpress.excellentenchants.api.enchantment.IEnchantChanceTemplate;
import su.nightexpress.excellentenchants.api.enchantment.type.PassiveEnchant;
import su.nightexpress.excellentenchants.manager.object.EnchantScaler;
import su.nightexpress.excellentenchants.manager.tasks.AbstractEnchantPassiveTask;
import java.util.Map;
import java.util.function.UnaryOperator;
public class EnchantSaturation extends IEnchantChanceTemplate implements PassiveEnchant, ICleanable {
@ -86,8 +86,8 @@ public class EnchantSaturation extends IEnchantChanceTemplate implements Passive
public boolean use(@NotNull LivingEntity entity, int level) {
if (!this.isEnchantmentAvailable(entity)) return false;
if (!(entity instanceof Player player)) return false;
if (!this.checkTriggerChance(level)) return false;
if (player.getFoodLevel() >= 20) return false;
if (!this.checkTriggerChance(level)) return false;
if (!this.takeCostItem(player)) return false;
float amount = (float) this.getSaturationAmount(level);
@ -103,11 +103,9 @@ public class EnchantSaturation extends IEnchantChanceTemplate implements Passive
}
@Override
protected void apply(@NotNull LivingEntity entity, @NotNull ItemStack armor, @NotNull ItemMeta meta) {
int level = meta.getEnchantLevel(EnchantSaturation.this);
if (level < 1) return;
use(entity, level);
protected void apply(@NotNull LivingEntity entity, @NotNull Map<ExcellentEnchant, Integer> enchants) {
// TODO Need to use SUM level and bypass the Scaler cap
use(entity, enchants.getOrDefault(EnchantSaturation.this, 0));
}
}
}

View File

@ -17,6 +17,7 @@ import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.api.enchantment.EnchantPriority;
import su.nightexpress.excellentenchants.api.enchantment.IEnchantChanceTemplate;
import su.nightexpress.excellentenchants.api.enchantment.type.BowEnchant;
import su.nightexpress.excellentenchants.manager.EnchantManager;
import su.nightexpress.excellentenchants.manager.object.EnchantScaler;
public class EnchantGhast extends IEnchantChanceTemplate implements BowEnchant {
@ -93,7 +94,7 @@ public class EnchantGhast extends IEnchantChanceTemplate implements BowEnchant {
@Override
public boolean use(@NotNull EntityDamageByEntityEvent e, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
// Support for the 'Power' enchantment.
int power = weapon.getEnchantmentLevel(Enchantment.ARROW_DAMAGE);
int power = EnchantManager.getEnchantmentLevel(weapon, Enchantment.ARROW_DAMAGE);
if (power < 1) return false;
double damagePower = 0.5 + power * 0.5;

View File

@ -13,6 +13,7 @@ import su.nexmedia.engine.utils.NumberUtil;
import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.api.enchantment.EnchantPriority;
import su.nightexpress.excellentenchants.api.enchantment.IEnchantChanceTemplate;
import su.nightexpress.excellentenchants.manager.EnchantManager;
import su.nightexpress.excellentenchants.manager.object.EnchantScaler;
import java.util.function.UnaryOperator;
@ -63,7 +64,7 @@ public class EnchantCurseOfBreaking extends IEnchantChanceTemplate {
if (!this.isEnchantmentAvailable(player)) return;
ItemStack item = e.getItem();
int level = item.getEnchantmentLevel(this);
int level = EnchantManager.getItemEnchantLevel(item, this);
if (level < 1) return;
if (!this.checkTriggerChance(level)) return;

View File

@ -12,6 +12,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockDropItemEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryPickupItemEvent;
import org.bukkit.event.inventory.InventoryType;
@ -160,15 +161,24 @@ public class EnchantSilkChest extends IEnchantChanceTemplate implements CustomDr
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onSilkChestStore(InventoryClickEvent e) {
Inventory inv = e.getInventory();
if (inv.getType() == InventoryType.CRAFTING || inv.getType() == InventoryType.CREATIVE) return;
Inventory inventory = e.getInventory();
if (inventory.getType() == InventoryType.CRAFTING || inventory.getType() == InventoryType.CREATIVE) return;
ItemStack item = e.getCurrentItem();
if (item == null || item.getType().isAir()) return;
if (this.isSilkChest(item)) {
e.setCancelled(true);
Player player = (Player) e.getWhoClicked();
ItemStack item;
if (e.getHotbarButton() >= 0) {
item = player.getInventory().getItem(e.getHotbarButton());
}
else item = e.getCurrentItem();
if (item == null || item.getType().isAir() || !this.isSilkChest(item)) return;
Inventory clicked = e.getClickedInventory();
if (e.getClick() != ClickType.NUMBER_KEY) {
if (clicked != null && clicked.equals(e.getView().getTopInventory())) return;
}
e.setCancelled(true);
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)

View File

@ -75,17 +75,17 @@ public class EnchantTelekinesis extends IEnchantChanceTemplate implements Custom
}
@Override
public void handleDrop(@NotNull EnchantDropContainer e, @NotNull Player player, @NotNull ItemStack item, int level) {
BlockDropItemEvent parent = e.getParent();
Block block = parent.getBlockState().getBlock();
public void handleDrop(@NotNull EnchantDropContainer container, @NotNull Player player, @NotNull ItemStack item, int level) {
BlockDropItemEvent dropItemEvent = container.getParent();
Block block = dropItemEvent.getBlockState().getBlock();
if (!this.isEnchantmentAvailable(player)) return;
//if (block.getState() instanceof Container) return;
if (!this.checkTriggerChance(level)) return;
List<ItemStack> drops = new ArrayList<>();
drops.addAll(parent.getItems().stream().map(Item::getItemStack).toList());
drops.addAll(e.getDrop());
drops.addAll(dropItemEvent.getItems().stream().map(Item::getItemStack).toList());
drops.addAll(container.getDrop());
drops.removeIf(Objects::isNull);
StringBuilder builder = new StringBuilder();
@ -99,7 +99,7 @@ public class EnchantTelekinesis extends IEnchantChanceTemplate implements Custom
});
this.messageDropReceived.replace("%items%", builder.toString()).send(player);
e.getDrop().clear();
parent.getItems().clear();
container.getDrop().clear();
dropItemEvent.getItems().clear();
}
}

View File

@ -16,6 +16,7 @@ import su.nexmedia.engine.utils.NumberUtil;
import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.api.enchantment.EnchantPriority;
import su.nightexpress.excellentenchants.api.enchantment.IEnchantChanceTemplate;
import su.nightexpress.excellentenchants.manager.EnchantManager;
import su.nightexpress.excellentenchants.manager.object.EnchantScaler;
import java.util.function.UnaryOperator;
@ -69,7 +70,7 @@ public class EnchantInfernus extends IEnchantChanceTemplate {
ItemStack item = trident.getItem();
int level = item.getEnchantmentLevel(this);
int level = EnchantManager.getItemEnchantLevel(item, this);
if (level <= 0) return;
if (!this.checkTriggerChance(level)) return;
@ -84,7 +85,7 @@ public class EnchantInfernus extends IEnchantChanceTemplate {
ItemStack item = trident.getItem();
int level = item.getEnchantmentLevel(this);
int level = EnchantManager.getItemEnchantLevel(item, this);
if (level <= 0 || trident.getFireTicks() <= 0) return;
int ticks = this.getFireTicks(level);

View File

@ -2,6 +2,7 @@ package su.nightexpress.excellentenchants.manager.listeners;
import org.bukkit.Material;
import org.bukkit.block.Chest;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.*;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@ -13,19 +14,17 @@ import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.inventory.PrepareAnvilEvent;
import org.bukkit.event.player.PlayerFishEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.world.LootGenerateEvent;
import org.bukkit.inventory.*;
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.NotNull;
import su.nexmedia.engine.api.manager.AbstractListener;
import su.nexmedia.engine.utils.random.Rnd;
import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.api.enchantment.ExcellentEnchant;
import su.nightexpress.excellentenchants.config.Config;
import su.nightexpress.excellentenchants.config.ObtainSettings;
import su.nightexpress.excellentenchants.manager.EnchantManager;
import su.nightexpress.excellentenchants.manager.object.EnchantTier;
import su.nightexpress.excellentenchants.manager.type.ObtainType;
import java.util.HashMap;
@ -37,6 +36,16 @@ public class EnchantGenericListener extends AbstractListener<ExcellentEnchants>
super(enchantManager.plugin());
}
@EventHandler(priority = EventPriority.MONITOR)
public void onEnchantPotionEffectQuit(PlayerQuitEvent e) {
Player player = e.getPlayer();
player.getActivePotionEffects().stream()
.filter(effect -> EnchantManager.isEnchantmentEffect(player, effect)).forEach(effect -> {
player.removePotionEffect(effect.getType());
});
}
// ---------------------------------------------------------------
// Handle Anvil
// ---------------------------------------------------------------
@ -149,53 +158,32 @@ public class EnchantGenericListener extends AbstractListener<ExcellentEnchants>
// ---------------------------------------------------------------
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onEnchantPopulateEnchantingTable(final EnchantItemEvent e) {
ObtainSettings settings = Config.getObtainSettings(ObtainType.ENCHANTING);
if (settings == null || Rnd.get(true) > settings.getEnchantsCustomGenerationChance()) return;
ItemStack target = e.getItem();
boolean enchantAdded = false;
Map<Enchantment, Integer> enchantsPrepared = e.getEnchantsToAdd();
Map<Enchantment, Integer> enchantsToPopulate = EnchantManager.getEnchantsToPopulate(target, ObtainType.ENCHANTING, enchantsPrepared, enchant -> enchant.getLevelByEnchantCost(e.getExpLevelCost()));
int enchMax = settings.getEnchantsTotalMax();
int enchRoll = Rnd.get(settings.getEnchantsCustomMin(), settings.getEnchantsCustomMax());
enchantsPrepared.putAll(enchantsToPopulate);
for (int count = 0; (count < enchRoll && e.getEnchantsToAdd().size() < enchMax); count++) {
EnchantTier tier = EnchantManager.getTierByChance(ObtainType.ENCHANTING);
if (tier == null) continue;
plugin.getServer().getScheduler().runTask(plugin, () -> {
ItemStack result = e.getInventory().getItem(0);
if (result == null) return;
ExcellentEnchant enchant = tier.getEnchant(ObtainType.ENCHANTING, target);
if (enchant == null) continue;
if (e.getEnchantsToAdd().keySet().stream().anyMatch(add -> add.conflictsWith(enchant) || enchant.conflictsWith(add)))
continue;
// Fix enchantments for Enchant Books.
// Enchants are not added on book because they do not exists in NMS.
// Server gets enchants from NMS to apply it on Book NBT tags.
ItemMeta meta = result.getItemMeta();
if (meta instanceof EnchantmentStorageMeta storageMeta) {
e.getEnchantsToAdd().forEach((enchantment, level) -> {
if (!storageMeta.hasStoredEnchant(enchantment)) {
storageMeta.addStoredEnchant(enchantment, level, true);
}
});
result.setItemMeta(storageMeta);
}
int level = enchant.getLevelByEnchantCost(e.getExpLevelCost());
if (level < 1) continue;
e.getEnchantsToAdd().put(enchant, level);
enchantAdded = true;
}
if (enchantAdded) {
plugin.getServer().getScheduler().runTask(plugin, () -> {
ItemStack result = e.getInventory().getItem(0);
if (result == null) return;
// Fix enchantments for Enchant Books.
// Enchants are not added on book because they do not exists in NMS.
// Server gets enchants from NMS to apply it on Book NBT tags.
ItemMeta meta = result.getItemMeta();
if (meta instanceof EnchantmentStorageMeta meta2) {
e.getEnchantsToAdd().forEach((en, lvl) -> {
if (!meta2.hasStoredEnchant(en)) {
meta2.addStoredEnchant(en, lvl, true);
}
});
result.setItemMeta(meta2);
}
EnchantManager.updateItemLoreEnchants(result);
e.getInventory().setItem(0, result);
});
}
EnchantManager.updateItemLoreEnchants(result);
e.getInventory().setItem(0, result);
});
}
// ---------------------------------------------------------------

View File

@ -0,0 +1,77 @@
package su.nightexpress.excellentenchants.manager.object;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import su.nexmedia.engine.utils.random.Rnd;
import su.nightexpress.excellentenchants.api.enchantment.ExcellentEnchant;
import su.nightexpress.excellentenchants.config.Config;
import su.nightexpress.excellentenchants.manager.type.ObtainType;
import java.util.*;
import java.util.stream.Collectors;
public class EnchantPopulator {
private final ObtainType obtainType;
private final ItemStack item;
private final Map<EnchantTier, Set<ExcellentEnchant>> enchants;
public EnchantPopulator(@NotNull ObtainType obtainType, @NotNull ItemStack item) {
this.obtainType = obtainType;
this.item = item;
this.enchants = Config.getTiers().stream()
.collect(Collectors.toMap(k -> k, v -> v.getEnchants(obtainType, item), (prev, add) -> add, HashMap::new));
}
public boolean isEmpty() {
return this.getEnchants().isEmpty() || this.getEnchants().values().stream().allMatch(Set::isEmpty);
}
public boolean isEmpty(@NotNull EnchantTier tier) {
return this.getEnchants(tier).isEmpty();
}
public void purge(@NotNull EnchantTier tier) {
this.getEnchants().remove(tier);
}
public void purge(@NotNull EnchantTier tier, @NotNull ExcellentEnchant enchant) {
this.getEnchants(tier).remove(enchant);
this.getEnchants().keySet().removeIf(this::isEmpty);
}
@NotNull
public ObtainType getObtainType() {
return obtainType;
}
@NotNull
public ItemStack getItem() {
return item;
}
@NotNull
public Map<EnchantTier, Set<ExcellentEnchant>> getEnchants() {
return this.enchants;
}
@NotNull
public Set<ExcellentEnchant> getEnchants(@NotNull EnchantTier tier) {
return this.getEnchants().getOrDefault(tier, new HashSet<>());
}
@Nullable
public EnchantTier getTierByChance() {
Map<EnchantTier, Double> map = this.getEnchants().keySet().stream()
.collect(Collectors.toMap(k -> k, v -> v.getChance(this.getObtainType())));
return Rnd.get(map);
}
@Nullable
public ExcellentEnchant getEnchantByChance(@NotNull EnchantTier tier) {
Map<ExcellentEnchant, Double> map = this.getEnchants(tier).stream()
.collect(Collectors.toMap(k -> k, v -> v.getObtainChance(this.getObtainType())));
return map.isEmpty() ? null : Rnd.get(map);
}
}

View File

@ -4,7 +4,6 @@ import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import su.nexmedia.engine.utils.StringUtil;
import su.nexmedia.engine.utils.random.Rnd;
import su.nightexpress.excellentenchants.api.enchantment.ExcellentEnchant;
import su.nightexpress.excellentenchants.manager.type.ObtainType;
@ -73,22 +72,10 @@ public class EnchantTier {
@NotNull
public Set<ExcellentEnchant> getEnchants(@NotNull ObtainType obtainType, @Nullable ItemStack item) {
Set<ExcellentEnchant> set = this.getEnchants().stream()
.filter(en -> en.getObtainChance(obtainType) > 0)
.filter(en -> item == null || en.canEnchantItem(item)).collect(Collectors.toSet());
set.removeIf(en -> obtainType == ObtainType.ENCHANTING && en.isTreasure());
.filter(enchant -> enchant.getObtainChance(obtainType) > 0)
.filter(enchant -> item == null || enchant.canEnchantItem(item))
.collect(Collectors.toCollection(HashSet::new));
set.removeIf(enchant -> obtainType == ObtainType.ENCHANTING && enchant.isTreasure());
return set;
}
@Nullable
public ExcellentEnchant getEnchant(@NotNull ObtainType obtainType) {
return getEnchant(obtainType, null);
}
@Nullable
public ExcellentEnchant getEnchant(@NotNull ObtainType obtainType, @Nullable ItemStack item) {
Map<ExcellentEnchant, Double> map = this.getEnchants(obtainType).stream()
.filter(en -> item == null || en.canEnchantItem(item))
.collect(Collectors.toMap(k -> k, v -> v.getObtainChance(obtainType)));
return map.isEmpty() ? null : Rnd.get(map);
}
}

View File

@ -1,44 +1,31 @@
package su.nightexpress.excellentenchants.manager.tasks;
import org.bukkit.Material;
import org.bukkit.entity.LivingEntity;
import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.NotNull;
import su.nexmedia.engine.api.task.AbstractTask;
import su.nexmedia.engine.utils.EntityUtil;
import su.nexmedia.engine.utils.ItemUtil;
import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.api.enchantment.ExcellentEnchant;
import su.nightexpress.excellentenchants.config.Config;
import su.nightexpress.excellentenchants.manager.EnchantManager;
import java.util.*;
import java.util.Collection;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
@Deprecated
public abstract class AbstractEnchantPassiveTask extends AbstractTask<ExcellentEnchants> {
public AbstractEnchantPassiveTask(@NotNull ExcellentEnchants plugin, long interval, boolean async) {
super(plugin, interval, async);
}
protected abstract void apply(@NotNull LivingEntity entity, @NotNull ItemStack armor, @NotNull ItemMeta meta);
protected abstract void apply(@NotNull LivingEntity entity, @NotNull Map<ExcellentEnchant, Integer> enchants);
@Override
public void action() {
for (LivingEntity entity : this.getEntities()) {
List<ItemStack> list = new ArrayList<>(Arrays.asList(EntityUtil.getArmor(entity)));
EntityEquipment equipment = entity.getEquipment();
if (equipment != null && !ItemUtil.isArmor(equipment.getItemInMainHand())) {
list.add(equipment.getItemInMainHand());
}
list.removeIf(armor -> armor == null || armor.getType().isAir() || armor.getType() == Material.ENCHANTED_BOOK);
for (ItemStack armor : list) {
ItemMeta meta = armor.getItemMeta();
if (meta == null) continue;
this.apply(entity, armor, meta);
}
this.apply(entity, EnchantManager.getEquippedEnchantsMax(entity));
}
}

View File

@ -1,28 +1,22 @@
package su.nightexpress.excellentenchants.manager.tasks;
import org.bukkit.entity.LivingEntity;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.NotNull;
import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.api.enchantment.IEnchantPotionTemplate;
import su.nightexpress.excellentenchants.api.enchantment.type.PassiveEnchant;
import su.nightexpress.excellentenchants.api.enchantment.ExcellentEnchant;
import su.nightexpress.excellentenchants.config.Config;
import su.nightexpress.excellentenchants.manager.EnchantManager;
import java.util.Map;
public class EnchantEffectPassiveTask extends AbstractEnchantPassiveTask {
public EnchantEffectPassiveTask(@NotNull ExcellentEnchants plugin) {
super(plugin, Config.TASKS_PASSIVE_ENCHANTS_TICKS_INTERVAL, false);
super(plugin, Config.TASKS_PASSIVE_POTION_EFFECTS_APPLY_INTERVAL.get(), false);
}
@Override
protected void apply(@NotNull LivingEntity entity, @NotNull ItemStack armor, @NotNull ItemMeta meta) {
meta.getEnchants().forEach((enchantment, level) -> {
if (level < 1) return;
if (!(enchantment instanceof PassiveEnchant passiveEnchant)) return;
if (!(enchantment instanceof IEnchantPotionTemplate)) return;
passiveEnchant.use(entity, level);
});
protected void apply(@NotNull LivingEntity entity, @NotNull Map<ExcellentEnchant, Integer> enchants) {
EnchantManager.updateEquippedEnchantEffects(entity);
}
}

View File

@ -20,9 +20,6 @@ General:
Arrow_Trails:
# Defines the ticks interval (20 ticks = 1 second) for the arrow particle effect spawning.
Ticks_Interval: 1
Passive_Enchants:
# Defines the ticks interval (20 ticks = 1 second) for the passive enchantment effects to trigger.
Ticks_Interval: 100
# Enchantment global settings.
Enchantments:
# List of disabled custom enchantments.

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>ExcellentEnchants</artifactId>
<groupId>su.nightexpress.excellentenchants</groupId>
<version>3.2.7</version>
<version>3.2.8</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -2,12 +2,39 @@ package su.nightexpress.excellentenchants.nms;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.LivingEntity;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.potion.PotionEffect;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import su.nexmedia.engine.utils.EntityUtil;
import java.util.Arrays;
import java.util.Set;
public interface EnchantNMS {
// TODO Move in 'API' module?
@Deprecated
static int getEnchantmentLevel(@NotNull ItemStack item, @NotNull Enchantment enchant) {
ItemMeta meta = item.getItemMeta();
if (meta == null) return 0;
return meta.getEnchantLevel(enchant);
}
// TODO Move in 'API' module?
@Deprecated
static int getEquippedEnchantLevel(@NotNull LivingEntity entity, @NotNull Enchantment enchant) {
return Arrays.stream(EntityUtil.getEquipment(entity)).filter(enchant::canEnchantItem)
.map(item -> getEnchantmentLevel(item, enchant)).max(Integer::compareTo).orElse(0);
}
void addEnchantmentEffect(@NotNull LivingEntity entity, @NotNull Enchantment enchant, @NotNull PotionEffect effect);
@Nullable Enchantment getEnchantmentByEffect(@NotNull LivingEntity entity, @NotNull PotionEffect type);
@NotNull Set<Block> handleFlameWalker(@NotNull LivingEntity entity, @NotNull Location location, int level);
}

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>ExcellentEnchants</artifactId>
<groupId>su.nightexpress.excellentenchants</groupId>
<version>3.2.7</version>
<version>3.2.8</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@ -26,7 +26,7 @@
<dependency>
<groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>NMS</artifactId>
<version>3.2.7</version>
<version>3.2.8</version>
</dependency>
</dependencies>

View File

@ -0,0 +1,39 @@
package su.nightexpress.excellentenchants.nms.v1_17_R1;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.entity.LivingEntity;
import org.bukkit.enchantments.Enchantment;
import org.jetbrains.annotations.NotNull;
import su.nexmedia.engine.utils.Reflex;
import su.nightexpress.excellentenchants.nms.EnchantNMS;
public class CustomEffectInstance extends MobEffectInstance {
private static final int MIN = 60 * 60 * 20;
private final Enchantment enchantment;
public CustomEffectInstance(MobEffect effect, int amplifier, @NotNull Enchantment enchantment) {
super(effect, Integer.MAX_VALUE, amplifier);
this.enchantment = enchantment;
}
@NotNull
public Enchantment getEnchantment() {
return enchantment;
}
public boolean tick(LivingEntity entity, Runnable runnable) {
if (EnchantNMS.getEquippedEnchantLevel((org.bukkit.entity.LivingEntity) entity.getBukkitEntity(), this.getEnchantment()) <= 0) {
return false;
}
if (super.tick(entity, runnable)) {
if (this.getDuration() <= MIN) {
Reflex.setFieldValue(this, "c", Integer.MAX_VALUE);
}
return true;
}
return false;
}
}

View File

@ -1,7 +1,9 @@
package su.nightexpress.excellentenchants.nms;
package su.nightexpress.excellentenchants.nms.v1_17_R1;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.LiquidBlock;
@ -12,14 +14,36 @@ import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_17_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_17_R1.entity.CraftLivingEntity;
import org.bukkit.craftbukkit.v1_17_R1.event.CraftEventFactory;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.entity.EntityPotionEffectEvent;
import org.bukkit.potion.PotionEffect;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import su.nightexpress.excellentenchants.nms.EnchantNMS;
import java.util.HashSet;
import java.util.Set;
public class V1_17_R1 implements EnchantNMS {
@Override
public void addEnchantmentEffect(@NotNull LivingEntity entity, @NotNull Enchantment enchant, @NotNull PotionEffect effect) {
net.minecraft.world.entity.LivingEntity entity1 = ((CraftLivingEntity)entity).getHandle();
entity1.addEffect(new CustomEffectInstance(MobEffect.byId(effect.getType().getId()), effect.getAmplifier(), enchant), EntityPotionEffectEvent.Cause.PLUGIN);
}
@Override
@Nullable
public Enchantment getEnchantmentByEffect(@NotNull LivingEntity entity, @NotNull PotionEffect type) {
net.minecraft.world.entity.LivingEntity entity1 = ((CraftLivingEntity)entity).getHandle();
MobEffectInstance handle = entity1.getEffect(MobEffect.byId(type.getType().getId()));
if (handle instanceof CustomEffectInstance instance) {
return instance.getEnchantment();
}
return null;
}
@Override
@NotNull
public Set<Block> handleFlameWalker(@NotNull LivingEntity bukkitEntity, @NotNull Location location, int level) {

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>ExcellentEnchants</artifactId>
<groupId>su.nightexpress.excellentenchants</groupId>
<version>3.2.7</version>
<version>3.2.8</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@ -26,7 +26,7 @@
<dependency>
<groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>NMS</artifactId>
<version>3.2.7</version>
<version>3.2.8</version>
</dependency>
</dependencies>

View File

@ -0,0 +1,39 @@
package su.nightexpress.excellentenchants.nms.v1_18_R2;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.entity.LivingEntity;
import org.bukkit.enchantments.Enchantment;
import org.jetbrains.annotations.NotNull;
import su.nexmedia.engine.utils.Reflex;
import su.nightexpress.excellentenchants.nms.EnchantNMS;
public class CustomEffectInstance extends MobEffectInstance {
private static final int MIN = 60 * 60 * 20;
private final Enchantment enchantment;
public CustomEffectInstance(MobEffect effect, int amplifier, @NotNull Enchantment enchantment) {
super(effect, Integer.MAX_VALUE, amplifier);
this.enchantment = enchantment;
}
@NotNull
public Enchantment getEnchantment() {
return enchantment;
}
public boolean tick(LivingEntity entity, Runnable runnable) {
if (EnchantNMS.getEquippedEnchantLevel((org.bukkit.entity.LivingEntity) entity.getBukkitEntity(), this.getEnchantment()) <= 0) {
return false;
}
if (super.tick(entity, runnable)) {
if (this.getDuration() <= MIN) {
Reflex.setFieldValue(this, "c", Integer.MAX_VALUE);
}
return true;
}
return false;
}
}

View File

@ -1,7 +1,9 @@
package su.nightexpress.excellentenchants.nms;
package su.nightexpress.excellentenchants.nms.v1_18_R2;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.LiquidBlock;
@ -12,14 +14,36 @@ import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_18_R2.CraftWorld;
import org.bukkit.craftbukkit.v1_18_R2.entity.CraftLivingEntity;
import org.bukkit.craftbukkit.v1_18_R2.event.CraftEventFactory;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.entity.EntityPotionEffectEvent;
import org.bukkit.potion.PotionEffect;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import su.nightexpress.excellentenchants.nms.EnchantNMS;
import java.util.HashSet;
import java.util.Set;
public class V1_18_R2 implements EnchantNMS {
@Override
public void addEnchantmentEffect(@NotNull LivingEntity entity, @NotNull Enchantment enchant, @NotNull PotionEffect effect) {
net.minecraft.world.entity.LivingEntity entity1 = ((CraftLivingEntity)entity).getHandle();
entity1.addEffect(new CustomEffectInstance(MobEffect.byId(effect.getType().getId()), effect.getAmplifier(), enchant), EntityPotionEffectEvent.Cause.PLUGIN);
}
@Override
@Nullable
public Enchantment getEnchantmentByEffect(@NotNull LivingEntity entity, @NotNull PotionEffect type) {
net.minecraft.world.entity.LivingEntity entity1 = ((CraftLivingEntity)entity).getHandle();
MobEffectInstance handle = entity1.getEffect(MobEffect.byId(type.getType().getId()));
if (handle instanceof CustomEffectInstance instance) {
return instance.getEnchantment();
}
return null;
}
@Override
@NotNull
public Set<Block> handleFlameWalker(@NotNull LivingEntity bukkitEntity, @NotNull Location location, int level) {

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>ExcellentEnchants</artifactId>
<groupId>su.nightexpress.excellentenchants</groupId>
<version>3.2.7</version>
<version>3.2.8</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@ -26,7 +26,7 @@
<dependency>
<groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>NMS</artifactId>
<version>3.2.7</version>
<version>3.2.8</version>
</dependency>
</dependencies>

View File

@ -0,0 +1,39 @@
package su.nightexpress.excellentenchants.nms.v1_19_R1;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.entity.LivingEntity;
import org.bukkit.enchantments.Enchantment;
import org.jetbrains.annotations.NotNull;
import su.nexmedia.engine.utils.Reflex;
import su.nightexpress.excellentenchants.nms.EnchantNMS;
public class CustomEffectInstance extends MobEffectInstance {
private static final int MIN = 60 * 60 * 20;
private final Enchantment enchantment;
public CustomEffectInstance(MobEffect effect, int amplifier, @NotNull Enchantment enchantment) {
super(effect, Integer.MAX_VALUE, amplifier);
this.enchantment = enchantment;
}
@NotNull
public Enchantment getEnchantment() {
return enchantment;
}
public boolean tick(LivingEntity entity, Runnable runnable) {
if (EnchantNMS.getEquippedEnchantLevel((org.bukkit.entity.LivingEntity) entity.getBukkitEntity(), this.getEnchantment()) <= 0) {
return false;
}
if (super.tick(entity, runnable)) {
if (this.getDuration() <= MIN) {
Reflex.setFieldValue(this, "c", Integer.MAX_VALUE);
}
return true;
}
return false;
}
}

View File

@ -1,7 +1,9 @@
package su.nightexpress.excellentenchants.nms;
package su.nightexpress.excellentenchants.nms.v1_19_R1;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.LiquidBlock;
@ -12,14 +14,36 @@ import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_19_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_19_R1.entity.CraftLivingEntity;
import org.bukkit.craftbukkit.v1_19_R1.event.CraftEventFactory;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.entity.EntityPotionEffectEvent;
import org.bukkit.potion.PotionEffect;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import su.nightexpress.excellentenchants.nms.EnchantNMS;
import java.util.HashSet;
import java.util.Set;
public class V1_19_R1 implements EnchantNMS {
@Override
public void addEnchantmentEffect(@NotNull LivingEntity entity, @NotNull Enchantment enchant, @NotNull PotionEffect effect) {
net.minecraft.world.entity.LivingEntity entity1 = ((CraftLivingEntity)entity).getHandle();
entity1.addEffect(new CustomEffectInstance(MobEffect.byId(effect.getType().getId()), effect.getAmplifier(), enchant), EntityPotionEffectEvent.Cause.PLUGIN);
}
@Override
@Nullable
public Enchantment getEnchantmentByEffect(@NotNull LivingEntity entity, @NotNull PotionEffect type) {
net.minecraft.world.entity.LivingEntity entity1 = ((CraftLivingEntity)entity).getHandle();
MobEffectInstance handle = entity1.getEffect(MobEffect.byId(type.getType().getId()));
if (handle instanceof CustomEffectInstance instance) {
return instance.getEnchantment();
}
return null;
}
@Override
@NotNull
public Set<Block> handleFlameWalker(@NotNull LivingEntity bukkitEntity, @NotNull Location location, int level) {

View File

@ -7,7 +7,7 @@
<groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>ExcellentEnchants</artifactId>
<packaging>pom</packaging>
<version>3.2.7</version>
<version>3.2.8</version>
<modules>
<module>Core</module>
<module>NMS</module>
@ -25,7 +25,7 @@
<dependency>
<groupId>su.nexmedia</groupId>
<artifactId>NexEngine</artifactId>
<version>2.2.6</version>
<version>2.2.7</version>
</dependency>
</dependencies>