From 15f367c22f621e24b09fbee17f875f801d4c34e9 Mon Sep 17 00:00:00 2001 From: nulli0n Date: Tue, 16 May 2023 01:53:13 +0600 Subject: [PATCH] v3.4.0 --- Core/pom.xml | 14 ++-- .../excellentenchants/ExcellentEnchants.java | 6 +- .../enchantment/EnchantRegistry.java | 14 +++- .../enchantment/impl/ExcellentEnchant.java | 3 + .../impl/armor/EnchantFlameWalker.java | 29 ++++++- .../impl/armor/EnchantIceShield.java | 2 +- .../impl/bow/EnchantElectrifiedArrows.java | 2 +- ...oFishEnchant.java => AutoReelEnchant.java} | 7 +- .../impl/fishing/CurseOfDrownedEnchant.java | 72 +++++++++++++++++ .../impl/fishing/DoubleCatchEnchant.java | 61 +++++++++++++++ .../impl/fishing/RiverMasterEnchant.java | 68 ++++++++++++++++ .../impl/fishing/SeasonedAnglerEnchant.java | 61 +++++++++++++++ .../impl/fishing/SurvivalistEnchant.java | 78 +++++++++++++++++++ .../impl/meta/PotionImplementation.java | 6 +- .../impl/weapon/EnchantDecapitator.java | 2 +- .../impl/weapon/EnchantIceAspect.java | 2 +- .../impl/weapon/EnchantThrifty.java | 13 +--- .../listener/EnchantGenericListener.java | 5 +- .../listener/EnchantHandlerListener.java | 14 ++-- .../enchantment/util/EnchantUtils.java | 20 ++++- NMS/pom.xml | 2 +- .../excellentenchants/nms/EnchantNMS.java | 3 + V1_17_R1/pom.xml | 4 +- .../nms/v1_17_R1/V1_17_R1.java | 14 ++++ V1_18_R2/pom.xml | 4 +- .../nms/v1_18_R2/V1_18_R2.java | 14 ++++ V1_19_R1/pom.xml | 4 +- .../nms/v1_19_R1/V1_19_R1.java | 14 ++++ V1_19_R2/pom.xml | 4 +- .../nms/v1_19_R2/V1_19_R2.java | 14 ++++ V1_19_R3/pom.xml | 4 +- .../nms/v1_19_R3/V1_19_R3.java | 14 ++++ pom.xml | 2 +- 33 files changed, 513 insertions(+), 63 deletions(-) rename Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/{AutoFishEnchant.java => AutoReelEnchant.java} (84%) create mode 100644 Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/CurseOfDrownedEnchant.java create mode 100644 Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/DoubleCatchEnchant.java create mode 100644 Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/RiverMasterEnchant.java create mode 100644 Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/SeasonedAnglerEnchant.java create mode 100644 Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/SurvivalistEnchant.java diff --git a/Core/pom.xml b/Core/pom.xml index 60fd057..374e291 100644 --- a/Core/pom.xml +++ b/Core/pom.xml @@ -5,7 +5,7 @@ ExcellentEnchants su.nightexpress.excellentenchants - 3.3.4 + 3.4.0 4.0.0 @@ -72,32 +72,32 @@ su.nightexpress.excellentenchants NMS - 3.3.4 + 3.4.0 su.nightexpress.excellentenchants V1_19_R3 - 3.3.4 + 3.4.0 su.nightexpress.excellentenchants V1_19_R2 - 3.3.4 + 3.4.0 su.nightexpress.excellentenchants V1_19_R1 - 3.3.4 + 3.4.0 su.nightexpress.excellentenchants V1_18_R2 - 3.3.4 + 3.4.0 su.nightexpress.excellentenchants V1_17_R1 - 3.3.4 + 3.4.0 fr.neatmonster diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/ExcellentEnchants.java b/Core/src/main/java/su/nightexpress/excellentenchants/ExcellentEnchants.java index 458eaa6..966f7d6 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/ExcellentEnchants.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/ExcellentEnchants.java @@ -29,9 +29,9 @@ import su.nightexpress.excellentenchants.tier.TierManager; public class ExcellentEnchants extends NexPlugin { private EnchantRegistry enchantRegistry; - private EnchantManager enchantManager; - private EnchantNMS enchantNMS; - private TierManager tierManager; + private EnchantManager enchantManager; + private EnchantNMS enchantNMS; + private TierManager tierManager; @Override @NotNull diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/EnchantRegistry.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/EnchantRegistry.java index dd8e386..1cc3cb8 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/EnchantRegistry.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/EnchantRegistry.java @@ -10,7 +10,7 @@ import su.nightexpress.excellentenchants.config.Config; import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.enchantment.impl.armor.*; import su.nightexpress.excellentenchants.enchantment.impl.bow.*; -import su.nightexpress.excellentenchants.enchantment.impl.fishing.AutoFishEnchant; +import su.nightexpress.excellentenchants.enchantment.impl.fishing.*; import su.nightexpress.excellentenchants.enchantment.impl.tool.*; import su.nightexpress.excellentenchants.enchantment.impl.universal.EnchantCurseOfFragility; import su.nightexpress.excellentenchants.enchantment.impl.weapon.*; @@ -35,14 +35,22 @@ public class EnchantRegistry { public void setup() { // Prevent to register enchantments during the runtime. if (this.isLocked) { - REGISTRY_MAP.values().forEach(ExcellentEnchant::loadSettings); + REGISTRY_MAP.values().forEach(enchant -> { + enchant.loadSettings(); + enchant.registerListeners(); + }); return; } Reflex.setFieldValue(Enchantment.class, "acceptingNew", true); // Fising Enchants - this.register(AutoFishEnchant.ID,() -> new AutoFishEnchant(plugin)); + this.register(AutoReelEnchant.ID,() -> new AutoReelEnchant(plugin)); + this.register(DoubleCatchEnchant.ID, () -> new DoubleCatchEnchant(plugin)); + this.register(SeasonedAnglerEnchant.ID, () -> new SeasonedAnglerEnchant(plugin)); + this.register(SurvivalistEnchant.ID, () -> new SurvivalistEnchant(plugin)); + this.register(CurseOfDrownedEnchant.ID, () -> new CurseOfDrownedEnchant(plugin)); + this.register(RiverMasterEnchant.ID, () -> new RiverMasterEnchant(plugin)); // Tool enchants this.register(EnchantBlastMining.ID, () -> new EnchantBlastMining(plugin)); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/ExcellentEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/ExcellentEnchant.java index e8c6755..718688b 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/ExcellentEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/ExcellentEnchant.java @@ -97,6 +97,9 @@ public abstract class ExcellentEnchant extends Enchantment implements IEnchantme @NotNull public PlaceholderMap getPlaceholders(int level) { + if (level > this.getMaxLevel()) level = this.getMaxLevel(); + if (level < this.getStartLevel()) level = this.getStartLevel(); + return this.placeholdersMap.get(level); } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantFlameWalker.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantFlameWalker.java index 5cb4a01..61363e8 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantFlameWalker.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantFlameWalker.java @@ -20,6 +20,7 @@ import org.jetbrains.annotations.NotNull; import su.nexmedia.engine.api.manager.ICleanable; import su.nexmedia.engine.api.particle.SimpleParticle; import su.nexmedia.engine.api.server.AbstractTask; +import su.nexmedia.engine.utils.Pair; import su.nexmedia.engine.utils.random.Rnd; import su.nightexpress.excellentenchants.ExcellentEnchants; import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler; @@ -29,6 +30,7 @@ import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.TimeUnit; import java.util.stream.Stream; public class EnchantFlameWalker extends ExcellentEnchant implements ICleanable { @@ -36,7 +38,7 @@ public class EnchantFlameWalker extends ExcellentEnchant implements ICleanable { public static final String ID = "flame_walker"; private static final BlockFace[] FACES = {BlockFace.SOUTH, BlockFace.NORTH, BlockFace.EAST, BlockFace.WEST}; - private static final Map BLOCKS_TO_DESTROY = new ConcurrentHashMap<>(); + private static final Map> BLOCKS_TO_DESTROY = new ConcurrentHashMap<>(); private EnchantScaler blockDecayTime; private BlockTickTask blockTickTask; @@ -70,7 +72,7 @@ public class EnchantFlameWalker extends ExcellentEnchant implements ICleanable { } public static void addBlock(@NotNull Block block, double seconds) { - BLOCKS_TO_DESTROY.put(block, (long) (System.currentTimeMillis() + seconds * 1000L)); + BLOCKS_TO_DESTROY.put(block, Pair.of(System.currentTimeMillis() + (long) seconds * 1000L, Rnd.get(100))); } @Override @@ -148,13 +150,32 @@ public class EnchantFlameWalker extends ExcellentEnchant implements ICleanable { BLOCKS_TO_DESTROY.keySet().removeIf(block -> { if (block.isEmpty()) return true; - long time = BLOCKS_TO_DESTROY.get(block); + Pair pair = BLOCKS_TO_DESTROY.get(block); + long time = pair.getFirst(); if (now >= time) { + block.getWorld().getPlayers().forEach(player -> { + player.sendBlockDamage(block.getLocation(), 0F, pair.getSecond()); + }); + block.setType(Material.LAVA); - SimpleParticle.of(Particle.BLOCK_CRACK, Material.MAGMA_BLOCK) + + SimpleParticle.of(Particle.BLOCK_CRACK, Material.MAGMA_BLOCK.createBlockData()) .play(block.getLocation(), 0.5, 0.7, 0.5, 0.03, 30); + return true; } + else { + long diff = TimeUnit.MILLISECONDS.toSeconds(time - now); + + float progress = (float) (1D - Math.min(1D, diff / 5D)); + if (progress > 1F) progress = 1F; + if (progress < 0F) progress = 0F; + + float finalProgress = progress; + block.getWorld().getPlayers().forEach(player -> { + player.sendBlockDamage(block.getLocation(), finalProgress, pair.getSecond()); + }); + } return false; }); } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantIceShield.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantIceShield.java index d65bccb..06bbc66 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantIceShield.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/armor/EnchantIceShield.java @@ -74,7 +74,7 @@ public class EnchantIceShield extends ExcellentEnchant implements Chanced, Potio damager.setFreezeTicks(damager.getMaxFreezeTicks()); if (this.hasVisualEffects()) { - SimpleParticle.of(Particle.BLOCK_CRACK, Material.ICE) + SimpleParticle.of(Particle.BLOCK_CRACK, Material.ICE.createBlockData()) .play(damager.getEyeLocation(), 0.25, 0.1, 20); } return true; diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantElectrifiedArrows.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantElectrifiedArrows.java index 8f7dc00..d959a48 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantElectrifiedArrows.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/bow/EnchantElectrifiedArrows.java @@ -92,7 +92,7 @@ public class EnchantElectrifiedArrows extends ExcellentEnchant implements Chance block.getWorld().strikeLightning(block.getLocation()).setMetadata(META_NO_ITEM_DAMAGE, new FixedMetadataValue(plugin, true)); if (this.hasVisualEffects()) { Location center = LocationUtil.getCenter(block.getLocation()); - SimpleParticle.of(Particle.BLOCK_CRACK, block.getType()).play(center, 1, 0.05, 120); + SimpleParticle.of(Particle.BLOCK_CRACK, block.getType().createBlockData()).play(center, 1, 0.05, 120); SimpleParticle.of(Particle.FIREWORKS_SPARK).play(center, 1, 0.05, 120); } return true; diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/AutoFishEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/AutoReelEnchant.java similarity index 84% rename from Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/AutoFishEnchant.java rename to Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/AutoReelEnchant.java index 473469b..4e13cde 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/AutoFishEnchant.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/AutoReelEnchant.java @@ -9,11 +9,11 @@ import su.nightexpress.excellentenchants.api.enchantment.type.FishingEnchant; import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; -public class AutoFishEnchant extends ExcellentEnchant implements FishingEnchant { +public class AutoReelEnchant extends ExcellentEnchant implements FishingEnchant { - public static final String ID = "auto_fish"; + public static final String ID = "auto_reel"; - public AutoFishEnchant(@NotNull ExcellentEnchants plugin) { + public AutoReelEnchant(@NotNull ExcellentEnchants plugin) { super(plugin, ID, EnchantPriority.MEDIUM); this.getDefaults().setDescription("Automatically reels in a hook on bite."); this.getDefaults().setLevelMax(1); @@ -29,6 +29,7 @@ public class AutoFishEnchant extends ExcellentEnchant implements FishingEnchant @Override public boolean onFishing(@NotNull PlayerFishEvent event, @NotNull ItemStack item, int level) { if (event.getState() != PlayerFishEvent.State.BITE) return false; + if (!this.isAvailableToUse(event.getPlayer())) return false; this.plugin.runTask(task -> { if (event.isCancelled()) return; diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/CurseOfDrownedEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/CurseOfDrownedEnchant.java new file mode 100644 index 0000000..e265a41 --- /dev/null +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/CurseOfDrownedEnchant.java @@ -0,0 +1,72 @@ +package su.nightexpress.excellentenchants.enchantment.impl.fishing; + +import org.bukkit.Particle; +import org.bukkit.Sound; +import org.bukkit.enchantments.EnchantmentTarget; +import org.bukkit.entity.Drowned; +import org.bukkit.entity.FishHook; +import org.bukkit.event.player.PlayerFishEvent; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; +import su.nexmedia.engine.api.particle.SimpleParticle; +import su.nexmedia.engine.utils.MessageUtil; +import su.nightexpress.excellentenchants.ExcellentEnchants; +import su.nightexpress.excellentenchants.Placeholders; +import su.nightexpress.excellentenchants.api.enchantment.meta.Chanced; +import su.nightexpress.excellentenchants.api.enchantment.type.FishingEnchant; +import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; +import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation; +import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; + +public class CurseOfDrownedEnchant extends ExcellentEnchant implements FishingEnchant, Chanced { + + public static final String ID = "curse_of_drowned"; + + private ChanceImplementation chanceImplementation; + + public CurseOfDrownedEnchant(@NotNull ExcellentEnchants plugin) { + super(plugin, ID, EnchantPriority.HIGHEST); + this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to fish up a Drowned Zombie."); + this.getDefaults().setLevelMax(5); + this.getDefaults().setTier(0D); + } + + @Override + public void loadSettings() { + super.loadSettings(); + this.chanceImplementation = ChanceImplementation.create(this, + "5.0 + " + Placeholders.ENCHANTMENT_LEVEL); + } + + @NotNull + @Override + public ChanceImplementation getChanceImplementation() { + return chanceImplementation; + } + + @NotNull + @Override + public EnchantmentTarget getItemTarget() { + return EnchantmentTarget.FISHING_ROD; + } + + @Override + public boolean onFishing(@NotNull PlayerFishEvent event, @NotNull ItemStack item, int level) { + if (event.getState() != PlayerFishEvent.State.CAUGHT_FISH) return false; + if (!this.isAvailableToUse(event.getPlayer())) return false; + if (!this.checkTriggerChance(level)) return false; + + FishHook hook = event.getHook(); + Drowned drowned = hook.getWorld().spawn(hook.getLocation(), Drowned.class); + hook.setHookedEntity(drowned); + hook.pullHookedEntity(); + + event.setCancelled(true); + + if (this.hasVisualEffects()) { + SimpleParticle.of(Particle.WATER_SPLASH).play(hook.getLocation(), 0.5, 0.1, 50); + MessageUtil.sound(event.getPlayer(), Sound.ENTITY_DROWNED_AMBIENT); + } + return true; + } +} diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/DoubleCatchEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/DoubleCatchEnchant.java new file mode 100644 index 0000000..f793cbf --- /dev/null +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/DoubleCatchEnchant.java @@ -0,0 +1,61 @@ +package su.nightexpress.excellentenchants.enchantment.impl.fishing; + +import org.bukkit.enchantments.EnchantmentTarget; +import org.bukkit.entity.Item; +import org.bukkit.event.player.PlayerFishEvent; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; +import su.nightexpress.excellentenchants.ExcellentEnchants; +import su.nightexpress.excellentenchants.Placeholders; +import su.nightexpress.excellentenchants.api.enchantment.meta.Chanced; +import su.nightexpress.excellentenchants.api.enchantment.type.FishingEnchant; +import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; +import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation; +import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; + +public class DoubleCatchEnchant extends ExcellentEnchant implements FishingEnchant, Chanced { + + public static final String ID = "double_catch"; + + private ChanceImplementation chanceImplementation; + + public DoubleCatchEnchant(@NotNull ExcellentEnchants plugin) { + super(plugin, ID, EnchantPriority.LOWEST); + this.getDefaults().setDescription("Increases amount of caught item by x2 with " + Placeholders.ENCHANTMENT_CHANCE + "% chance."); + this.getDefaults().setLevelMax(3); + this.getDefaults().setTier(0.5); + } + + @Override + public void loadSettings() { + super.loadSettings(); + this.chanceImplementation = ChanceImplementation.create(this, + "10.0 * " + Placeholders.ENCHANTMENT_LEVEL); + } + + @NotNull + @Override + public EnchantmentTarget getItemTarget() { + return EnchantmentTarget.FISHING_ROD; + } + + @Override + @NotNull + public ChanceImplementation getChanceImplementation() { + return this.chanceImplementation; + } + + @Override + public boolean onFishing(@NotNull PlayerFishEvent event, @NotNull ItemStack item, int level) { + if (event.getState() != PlayerFishEvent.State.CAUGHT_FISH) return false; + if (!(event.getCaught() instanceof Item drop)) return false; + if (!this.isAvailableToUse(event.getPlayer())) return false; + if (!this.checkTriggerChance(level)) return false; + + ItemStack stack = drop.getItemStack(); + stack.setAmount(Math.min(stack.getMaxStackSize(), stack.getAmount() * 2)); + drop.setItemStack(stack); + + return true; + } +} diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/RiverMasterEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/RiverMasterEnchant.java new file mode 100644 index 0000000..4057e1a --- /dev/null +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/RiverMasterEnchant.java @@ -0,0 +1,68 @@ +package su.nightexpress.excellentenchants.enchantment.impl.fishing; + +import org.bukkit.enchantments.EnchantmentTarget; +import org.bukkit.entity.FishHook; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.entity.ProjectileLaunchEvent; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; +import su.nightexpress.excellentenchants.ExcellentEnchants; +import su.nightexpress.excellentenchants.Placeholders; +import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler; +import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; +import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; +import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; + +public class RiverMasterEnchant extends ExcellentEnchant { + + public static final String ID = "river_master"; + + private EnchantScaler distanceMod; + + public RiverMasterEnchant(@NotNull ExcellentEnchants plugin) { + super(plugin, ID, EnchantPriority.MEDIUM); + this.getDefaults().setDescription("Increases casting distance."); + this.getDefaults().setLevelMax(5); + this.getDefaults().setTier(0.1); + } + + @Override + public void loadSettings() { + super.loadSettings(); + this.distanceMod = EnchantScaler.read(this, "Settings.Distance_Modifier", + "1.25 + " + Placeholders.ENCHANTMENT_LEVEL + " / 5", + "Multiplies the casted fish hook's velocity by specified value.", + "Setting too high values will result in hook auto removal by vanilla game/server mechanics."); + } + + @NotNull + @Override + public EnchantmentTarget getItemTarget() { + return EnchantmentTarget.FISHING_ROD; + } + + public double getDistanceMod(int level) { + return this.distanceMod.getValue(level); + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onHookLaunch(ProjectileLaunchEvent event) { + if (!(event.getEntity() instanceof FishHook hook)) return; + if (!(hook.getShooter() instanceof Player player)) return; + if (!this.isAvailableToUse(player)) return; + + ItemStack rod = EnchantUtils.getFishingRod(player); + if (rod == null) return; + + int level = EnchantUtils.getLevel(rod, this); + if (level < 1) return; + + if (this.isOutOfCharges(rod)) return; + + hook.setVelocity(hook.getVelocity().multiply(this.getDistanceMod(level))); + + this.consumeCharges(rod); + } +} diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/SeasonedAnglerEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/SeasonedAnglerEnchant.java new file mode 100644 index 0000000..7a2d0c5 --- /dev/null +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/SeasonedAnglerEnchant.java @@ -0,0 +1,61 @@ +package su.nightexpress.excellentenchants.enchantment.impl.fishing; + +import org.bukkit.enchantments.EnchantmentTarget; +import org.bukkit.event.player.PlayerFishEvent; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; +import su.nexmedia.engine.utils.NumberUtil; +import su.nightexpress.excellentenchants.ExcellentEnchants; +import su.nightexpress.excellentenchants.Placeholders; +import su.nightexpress.excellentenchants.api.enchantment.type.FishingEnchant; +import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler; +import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; +import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; + +public class SeasonedAnglerEnchant extends ExcellentEnchant implements FishingEnchant { + + public static final String ID = "seasoned_angler"; + + private EnchantScaler expMod; + + public SeasonedAnglerEnchant(@NotNull ExcellentEnchants plugin) { + super(plugin, ID, EnchantPriority.MEDIUM); + this.getDefaults().setDescription("Increases amount of XP gained from fishing by " + Placeholders.GENERIC_AMOUNT + "%."); + this.getDefaults().setLevelMax(4); + this.getDefaults().setTier(0.1); + } + + @Override + public void loadSettings() { + super.loadSettings(); + this.expMod = EnchantScaler.read(this, "Settings.Exp_Percent", + "25.0 * " + Placeholders.ENCHANTMENT_LEVEL, + "Amount (in percent) of additional XP from fishing."); + + this.addPlaceholder(Placeholders.GENERIC_AMOUNT, level -> NumberUtil.format(this.getExpPercent(level))); + } + + public int getExpPercent(int level) { + return (int) this.expMod.getValue(level); + } + + @NotNull + @Override + public EnchantmentTarget getItemTarget() { + return EnchantmentTarget.FISHING_ROD; + } + + @Override + public boolean onFishing(@NotNull PlayerFishEvent event, @NotNull ItemStack item, int level) { + if (event.getState() != PlayerFishEvent.State.CAUGHT_FISH) return false; + if (!this.isAvailableToUse(event.getPlayer())) return false; + if (event.getExpToDrop() == 0) return false; + + int expDrop = event.getExpToDrop(); + int expPercent = this.getExpPercent(level); + int expModified = (int) Math.ceil(expDrop * (1D + expPercent / 100D)); + + event.setExpToDrop(expModified); + return true; + } +} diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/SurvivalistEnchant.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/SurvivalistEnchant.java new file mode 100644 index 0000000..e40c3c0 --- /dev/null +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/fishing/SurvivalistEnchant.java @@ -0,0 +1,78 @@ +package su.nightexpress.excellentenchants.enchantment.impl.fishing; + +import org.bukkit.enchantments.EnchantmentTarget; +import org.bukkit.entity.Item; +import org.bukkit.event.player.PlayerFishEvent; +import org.bukkit.inventory.CookingRecipe; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; +import su.nightexpress.excellentenchants.ExcellentEnchants; +import su.nightexpress.excellentenchants.api.enchantment.meta.Chanced; +import su.nightexpress.excellentenchants.api.enchantment.type.FishingEnchant; +import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; +import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation; +import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; + +import java.util.HashSet; +import java.util.Set; + +public class SurvivalistEnchant extends ExcellentEnchant implements FishingEnchant, Chanced { + + public static final String ID = "survivalist"; + + private final Set> cookingRecipes; + + private ChanceImplementation chanceImplementation; + + public SurvivalistEnchant(@NotNull ExcellentEnchants plugin) { + super(plugin, ID, EnchantPriority.HIGH); + this.getDefaults().setDescription("Automatically cooks fish if what is caught is raw."); + this.getDefaults().setLevelMax(1); + this.getDefaults().setTier(0.4); + + this.cookingRecipes = new HashSet<>(); + } + + @Override + public void loadSettings() { + super.loadSettings(); + this.chanceImplementation = ChanceImplementation.create(this, "100"); + + this.cookingRecipes.clear(); + this.plugin.getServer().recipeIterator().forEachRemaining(recipe -> { + if (recipe instanceof CookingRecipe cookingRecipe) { + this.cookingRecipes.add(cookingRecipe); + } + }); + } + + @NotNull + @Override + public ChanceImplementation getChanceImplementation() { + return chanceImplementation; + } + + @NotNull + @Override + public EnchantmentTarget getItemTarget() { + return EnchantmentTarget.FISHING_ROD; + } + + @Override + public boolean onFishing(@NotNull PlayerFishEvent event, @NotNull ItemStack item, int level) { + if (event.getState() != PlayerFishEvent.State.CAUGHT_FISH) return false; + if (!this.isAvailableToUse(event.getPlayer())) return false; + if (!this.checkTriggerChance(level)) return false; + if (!(event.getCaught() instanceof Item drop)) return false; + + ItemStack stack = drop.getItemStack(); + + CookingRecipe recipe = this.cookingRecipes.stream().filter(r -> r.getInput().isSimilar(stack)).findFirst().orElse(null); + if (recipe == null) return false; + + ItemStack cooked = recipe.getResult(); + cooked.setAmount(stack.getAmount()); + drop.setItemStack(cooked); + return false; + } +} diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/meta/PotionImplementation.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/meta/PotionImplementation.java index d089168..5f8f885 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/meta/PotionImplementation.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/meta/PotionImplementation.java @@ -13,7 +13,7 @@ import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler; public final class PotionImplementation implements Potioned { - //private final ExcellentEnchant enchant; + private final ExcellentEnchant enchant; private final PotionEffectType effectType; private final Scaler duration; private final Scaler amplifier; @@ -22,7 +22,7 @@ public final class PotionImplementation implements Potioned { private PotionImplementation(@NotNull ExcellentEnchant enchant, @NotNull PotionEffectType effectType, boolean isPermanent, @NotNull EnchantScaler duration, @NotNull EnchantScaler amplifier) { - //this.enchant = enchant; + this.enchant = enchant; this.effectType = effectType; this.duration = duration; this.amplifier = amplifier; @@ -82,7 +82,7 @@ public final class PotionImplementation implements Potioned { int duration = this.getEffectDuration(level); int amplifier = Math.max(0, this.getEffectAmplifier(level) - 1); - return new PotionEffect(this.getEffectType(), duration, amplifier, false, false); + return new PotionEffect(this.getEffectType(), duration, amplifier, false, this.enchant.hasVisualEffects()); } public boolean addEffect(@NotNull LivingEntity target, int level) { diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantDecapitator.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantDecapitator.java index 7937fe2..5535a43 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantDecapitator.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantDecapitator.java @@ -233,7 +233,7 @@ public class EnchantDecapitator extends ExcellentEnchant implements Chanced, Dea entity.getWorld().dropItemNaturally(entity.getLocation(), item); if (this.hasVisualEffects()) { - SimpleParticle.of(Particle.BLOCK_CRACK, Material.REDSTONE_BLOCK).play(entity.getEyeLocation(), 0.25, 0.15, 30); + SimpleParticle.of(Particle.BLOCK_CRACK, Material.REDSTONE_BLOCK.createBlockData()).play(entity.getEyeLocation(), 0.25, 0.15, 30); } return true; } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantIceAspect.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantIceAspect.java index 368790f..6aa4805 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantIceAspect.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantIceAspect.java @@ -69,7 +69,7 @@ public class EnchantIceAspect extends ExcellentEnchant implements Chanced, Potio victim.setFreezeTicks(victim.getMaxFreezeTicks()); if (this.hasVisualEffects()) { - SimpleParticle.of(Particle.BLOCK_CRACK, Material.ICE).play(victim.getEyeLocation(), 0.25, 0.15, 30); + SimpleParticle.of(Particle.BLOCK_CRACK, Material.ICE.createBlockData()).play(victim.getEyeLocation(), 0.25, 0.15, 30); } return true; } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantThrifty.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantThrifty.java index 5a303f2..019ad66 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantThrifty.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/impl/weapon/EnchantThrifty.java @@ -1,6 +1,5 @@ package su.nightexpress.excellentenchants.enchantment.impl.weapon; -import org.bukkit.Material; import org.bukkit.NamespacedKey; import org.bukkit.enchantments.EnchantmentTarget; import org.bukkit.entity.EntityType; @@ -89,16 +88,10 @@ public class EnchantThrifty extends ExcellentEnchant implements Chanced, DeathEn if (PDCUtil.getBoolean(entity, this.keyEntityIgnored).orElse(false)) return false; if (!this.checkTriggerChance(level)) return false; - Material material = Material.getMaterial(entity.getType().name() + "_SPAWN_EGG"); - if (material == null) { - if (entity.getType() == EntityType.MUSHROOM_COW) { - material = Material.MOOSHROOM_SPAWN_EGG; - } - else return false; - } + ItemStack eggItem = plugin.getEnchantNMS().getSpawnEgg(entity); + if (eggItem == null) return false; - ItemStack egg = new ItemStack(material); - e.getDrops().add(egg); + e.getDrops().add(eggItem); return true; } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/listener/EnchantGenericListener.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/listener/EnchantGenericListener.java index 821d90a..73902b8 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/listener/EnchantGenericListener.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/listener/EnchantGenericListener.java @@ -144,8 +144,11 @@ public class EnchantGenericListener extends AbstractListener boolean expReward = recipe.hasExperienceReward(); int villagerExperience = recipe.getVillagerExperience(); float priceMultiplier = recipe.getPriceMultiplier(); + int demand = recipe.getDemand(); + int specialPrice = recipe.getSpecialPrice(); - MerchantRecipe recipe2 = new MerchantRecipe(result, uses, maxUses, expReward, villagerExperience, priceMultiplier); + MerchantRecipe recipe2 = new MerchantRecipe(result, uses, maxUses, expReward, villagerExperience, + priceMultiplier, demand, specialPrice); recipe2.setIngredients(recipe.getIngredients()); e.setRecipe(recipe2); } diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/listener/EnchantHandlerListener.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/listener/EnchantHandlerListener.java index da4dc34..2b5b22b 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/listener/EnchantHandlerListener.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/listener/EnchantHandlerListener.java @@ -18,7 +18,6 @@ import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.player.PlayerFishEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.EntityEquipment; -import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; import org.bukkit.metadata.FixedMetadataValue; import org.jetbrains.annotations.NotNull; @@ -26,10 +25,10 @@ import org.jetbrains.annotations.Nullable; import su.nexmedia.engine.api.manager.AbstractListener; import su.nexmedia.engine.utils.EntityUtil; import su.nightexpress.excellentenchants.ExcellentEnchants; -import su.nightexpress.excellentenchants.enchantment.util.EnchantDropContainer; -import su.nightexpress.excellentenchants.api.enchantment.type.*; import su.nightexpress.excellentenchants.api.enchantment.meta.Arrowed; +import su.nightexpress.excellentenchants.api.enchantment.type.*; import su.nightexpress.excellentenchants.enchantment.EnchantManager; +import su.nightexpress.excellentenchants.enchantment.util.EnchantDropContainer; import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; public class EnchantHandlerListener extends AbstractListener { @@ -211,14 +210,11 @@ public class EnchantHandlerListener extends AbstractListener public void onEnchantFishing(PlayerFishEvent event) { Player player = event.getPlayer(); - ItemStack item; - ItemStack main = player.getInventory().getItem(EquipmentSlot.HAND); - ItemStack off = player.getInventory().getItem(EquipmentSlot.OFF_HAND); - if (main != null && main.getType() == Material.FISHING_ROD) item = main; - else if (off != null && off.getType() == Material.FISHING_ROD) item = off; - else return; + ItemStack item = EnchantUtils.getFishingRod(player); + if (item == null) return; EnchantUtils.getExcellents(item, FishingEnchant.class).forEach((enchant, level) -> { + if (event.isCancelled()) return; // Check if event was cancelled by some enchantment. if (enchant.isOutOfCharges(item)) return; if (enchant.onFishing(event, item, level)) { enchant.consumeCharges(item); diff --git a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/util/EnchantUtils.java b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/util/EnchantUtils.java index b0fd032..f38ce2e 100644 --- a/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/util/EnchantUtils.java +++ b/Core/src/main/java/su/nightexpress/excellentenchants/enchantment/util/EnchantUtils.java @@ -5,6 +5,7 @@ import org.bukkit.NamespacedKey; import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.EnchantmentTarget; import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; @@ -102,14 +103,14 @@ public class EnchantUtils { ExcellentEnchant enchant = populator.getEnchantByChance(tier); // В тире нет подходящих чар (вообще) для итема, исключаем и идем дальше. if (enchant == null) { - populator.getEnchants().remove(tier); + populator.purge(tier); continue; } // Среди уже добавленных чар есть конфликты с тем, что нашли. // Исключаем, идем дальше. if (enchantsToAdd.keySet().stream().anyMatch(has -> has.conflictsWith(enchant) || enchant.conflictsWith(has))) { - populator.getEnchants(tier).remove(enchant); + populator.purge(tier, enchant); continue; } @@ -117,12 +118,12 @@ public class EnchantUtils { // Исключаем, идем дальше. int level = levelFunc.apply(enchant); if (level < enchant.getStartLevel()) { - populator.getEnchants(tier).remove(enchant); + populator.purge(tier, enchant); continue; } // Добавляем чар, засчитываем попытку. - populator.getEnchants(tier).remove(enchant); + populator.purge(tier, enchant); enchantsToAdd.put(enchant, level); enchRoll--; } @@ -202,6 +203,17 @@ public class EnchantUtils { return true; } + @Nullable + public static ItemStack getFishingRod(@NotNull Player player) { + ItemStack main = player.getInventory().getItem(EquipmentSlot.HAND); + if (main != null && main.getType() == Material.FISHING_ROD) return main; + + ItemStack off = player.getInventory().getItem(EquipmentSlot.OFF_HAND); + if (off != null && off.getType() == Material.FISHING_ROD) return off; + + return null; + } + @NotNull public static Map getAll(@NotNull ItemStack item) { ItemMeta meta = item.getItemMeta(); diff --git a/NMS/pom.xml b/NMS/pom.xml index 881f994..5879297 100644 --- a/NMS/pom.xml +++ b/NMS/pom.xml @@ -5,7 +5,7 @@ ExcellentEnchants su.nightexpress.excellentenchants - 3.3.4 + 3.4.0 4.0.0 diff --git a/NMS/src/main/java/su/nightexpress/excellentenchants/nms/EnchantNMS.java b/NMS/src/main/java/su/nightexpress/excellentenchants/nms/EnchantNMS.java index 8bc10ba..2cd518d 100644 --- a/NMS/src/main/java/su/nightexpress/excellentenchants/nms/EnchantNMS.java +++ b/NMS/src/main/java/su/nightexpress/excellentenchants/nms/EnchantNMS.java @@ -7,6 +7,7 @@ import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.Set; @@ -16,5 +17,7 @@ public interface EnchantNMS { void retrieveHook(@NotNull FishHook hook, @NotNull ItemStack item); + @Nullable ItemStack getSpawnEgg(@NotNull LivingEntity entity); + @NotNull Set handleFlameWalker(@NotNull LivingEntity entity, @NotNull Location location, int level); } diff --git a/V1_17_R1/pom.xml b/V1_17_R1/pom.xml index fec6efa..8e7f38f 100644 --- a/V1_17_R1/pom.xml +++ b/V1_17_R1/pom.xml @@ -5,7 +5,7 @@ ExcellentEnchants su.nightexpress.excellentenchants - 3.3.4 + 3.4.0 4.0.0 @@ -26,7 +26,7 @@ su.nightexpress.excellentenchants NMS - 3.3.4 + 3.4.0 diff --git a/V1_17_R1/src/main/java/su/nightexpress/excellentenchants/nms/v1_17_R1/V1_17_R1.java b/V1_17_R1/src/main/java/su/nightexpress/excellentenchants/nms/v1_17_R1/V1_17_R1.java index 6d64803..552eb7e 100644 --- a/V1_17_R1/src/main/java/su/nightexpress/excellentenchants/nms/v1_17_R1/V1_17_R1.java +++ b/V1_17_R1/src/main/java/su/nightexpress/excellentenchants/nms/v1_17_R1/V1_17_R1.java @@ -5,6 +5,7 @@ import net.minecraft.network.protocol.game.ClientboundAnimatePacket; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.projectile.FishingHook; +import net.minecraft.world.item.SpawnEggItem; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.LiquidBlock; import net.minecraft.world.level.block.state.BlockState; @@ -22,6 +23,7 @@ import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import su.nightexpress.excellentenchants.nms.EnchantNMS; import java.util.HashSet; @@ -44,6 +46,18 @@ public class V1_17_R1 implements EnchantNMS { handle.retrieve(CraftItemStack.asNMSCopy(item)); } + @Override + @Nullable + public ItemStack getSpawnEgg(@NotNull LivingEntity entity) { + CraftLivingEntity craftLivingEntity = (CraftLivingEntity) entity; + net.minecraft.world.entity.LivingEntity livingEntity = craftLivingEntity.getHandle(); + + SpawnEggItem eggItem = SpawnEggItem.byId(livingEntity.getType()); + if (eggItem == null) return null; + + return CraftItemStack.asBukkitCopy(eggItem.getDefaultInstance()); + } + @Override @NotNull public Set handleFlameWalker(@NotNull LivingEntity bukkitEntity, @NotNull Location location, int level) { diff --git a/V1_18_R2/pom.xml b/V1_18_R2/pom.xml index 113c38c..6f81230 100644 --- a/V1_18_R2/pom.xml +++ b/V1_18_R2/pom.xml @@ -5,7 +5,7 @@ ExcellentEnchants su.nightexpress.excellentenchants - 3.3.4 + 3.4.0 4.0.0 @@ -26,7 +26,7 @@ su.nightexpress.excellentenchants NMS - 3.3.4 + 3.4.0 diff --git a/V1_18_R2/src/main/java/su/nightexpress/excellentenchants/nms/v1_18_R2/V1_18_R2.java b/V1_18_R2/src/main/java/su/nightexpress/excellentenchants/nms/v1_18_R2/V1_18_R2.java index 42bd1da..32a1472 100644 --- a/V1_18_R2/src/main/java/su/nightexpress/excellentenchants/nms/v1_18_R2/V1_18_R2.java +++ b/V1_18_R2/src/main/java/su/nightexpress/excellentenchants/nms/v1_18_R2/V1_18_R2.java @@ -5,6 +5,7 @@ import net.minecraft.network.protocol.game.ClientboundAnimatePacket; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.projectile.FishingHook; +import net.minecraft.world.item.SpawnEggItem; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.LiquidBlock; import net.minecraft.world.level.block.state.BlockState; @@ -22,6 +23,7 @@ import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import su.nightexpress.excellentenchants.nms.EnchantNMS; import java.util.HashSet; @@ -44,6 +46,18 @@ public class V1_18_R2 implements EnchantNMS { handle.retrieve(CraftItemStack.asNMSCopy(item)); } + @Override + @Nullable + public ItemStack getSpawnEgg(@NotNull LivingEntity entity) { + CraftLivingEntity craftLivingEntity = (CraftLivingEntity) entity; + net.minecraft.world.entity.LivingEntity livingEntity = craftLivingEntity.getHandle(); + + SpawnEggItem eggItem = SpawnEggItem.byId(livingEntity.getType()); + if (eggItem == null) return null; + + return CraftItemStack.asBukkitCopy(eggItem.getDefaultInstance()); + } + @Override @NotNull public Set handleFlameWalker(@NotNull LivingEntity bukkitEntity, @NotNull Location location, int level) { diff --git a/V1_19_R1/pom.xml b/V1_19_R1/pom.xml index e2121b0..cae16e3 100644 --- a/V1_19_R1/pom.xml +++ b/V1_19_R1/pom.xml @@ -5,7 +5,7 @@ ExcellentEnchants su.nightexpress.excellentenchants - 3.3.4 + 3.4.0 4.0.0 @@ -26,7 +26,7 @@ su.nightexpress.excellentenchants NMS - 3.3.4 + 3.4.0 diff --git a/V1_19_R1/src/main/java/su/nightexpress/excellentenchants/nms/v1_19_R1/V1_19_R1.java b/V1_19_R1/src/main/java/su/nightexpress/excellentenchants/nms/v1_19_R1/V1_19_R1.java index 841aab7..0cd82d6 100644 --- a/V1_19_R1/src/main/java/su/nightexpress/excellentenchants/nms/v1_19_R1/V1_19_R1.java +++ b/V1_19_R1/src/main/java/su/nightexpress/excellentenchants/nms/v1_19_R1/V1_19_R1.java @@ -5,6 +5,7 @@ import net.minecraft.network.protocol.game.ClientboundAnimatePacket; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.projectile.FishingHook; +import net.minecraft.world.item.SpawnEggItem; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.LiquidBlock; import net.minecraft.world.level.block.state.BlockState; @@ -22,6 +23,7 @@ import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import su.nightexpress.excellentenchants.nms.EnchantNMS; import java.util.HashSet; @@ -44,6 +46,18 @@ public class V1_19_R1 implements EnchantNMS { handle.retrieve(CraftItemStack.asNMSCopy(item)); } + @Override + @Nullable + public ItemStack getSpawnEgg(@NotNull LivingEntity entity) { + CraftLivingEntity craftLivingEntity = (CraftLivingEntity) entity; + net.minecraft.world.entity.LivingEntity livingEntity = craftLivingEntity.getHandle(); + + SpawnEggItem eggItem = SpawnEggItem.byId(livingEntity.getType()); + if (eggItem == null) return null; + + return CraftItemStack.asBukkitCopy(eggItem.getDefaultInstance()); + } + @Override @NotNull public Set handleFlameWalker(@NotNull LivingEntity bukkitEntity, @NotNull Location location, int level) { diff --git a/V1_19_R2/pom.xml b/V1_19_R2/pom.xml index 10cd8f8..8d443db 100644 --- a/V1_19_R2/pom.xml +++ b/V1_19_R2/pom.xml @@ -5,7 +5,7 @@ ExcellentEnchants su.nightexpress.excellentenchants - 3.3.4 + 3.4.0 4.0.0 @@ -26,7 +26,7 @@ su.nightexpress.excellentenchants NMS - 3.3.4 + 3.4.0 diff --git a/V1_19_R2/src/main/java/su/nightexpress/excellentenchants/nms/v1_19_R2/V1_19_R2.java b/V1_19_R2/src/main/java/su/nightexpress/excellentenchants/nms/v1_19_R2/V1_19_R2.java index 3a1de22..9542b37 100644 --- a/V1_19_R2/src/main/java/su/nightexpress/excellentenchants/nms/v1_19_R2/V1_19_R2.java +++ b/V1_19_R2/src/main/java/su/nightexpress/excellentenchants/nms/v1_19_R2/V1_19_R2.java @@ -5,6 +5,7 @@ import net.minecraft.network.protocol.game.ClientboundAnimatePacket; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.projectile.FishingHook; +import net.minecraft.world.item.SpawnEggItem; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.LiquidBlock; import net.minecraft.world.level.block.state.BlockState; @@ -22,6 +23,7 @@ import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import su.nightexpress.excellentenchants.nms.EnchantNMS; import java.util.HashSet; @@ -44,6 +46,18 @@ public class V1_19_R2 implements EnchantNMS { handle.retrieve(CraftItemStack.asNMSCopy(item)); } + @Override + @Nullable + public ItemStack getSpawnEgg(@NotNull LivingEntity entity) { + CraftLivingEntity craftLivingEntity = (CraftLivingEntity) entity; + net.minecraft.world.entity.LivingEntity livingEntity = craftLivingEntity.getHandle(); + + SpawnEggItem eggItem = SpawnEggItem.byId(livingEntity.getType()); + if (eggItem == null) return null; + + return CraftItemStack.asBukkitCopy(eggItem.getDefaultInstance()); + } + @Override @NotNull public Set handleFlameWalker(@NotNull LivingEntity bukkitEntity, @NotNull Location location, int level) { diff --git a/V1_19_R3/pom.xml b/V1_19_R3/pom.xml index 00991b8..d94498d 100644 --- a/V1_19_R3/pom.xml +++ b/V1_19_R3/pom.xml @@ -5,7 +5,7 @@ ExcellentEnchants su.nightexpress.excellentenchants - 3.3.4 + 3.4.0 4.0.0 @@ -26,7 +26,7 @@ su.nightexpress.excellentenchants NMS - 3.3.4 + 3.4.0 diff --git a/V1_19_R3/src/main/java/su/nightexpress/excellentenchants/nms/v1_19_R3/V1_19_R3.java b/V1_19_R3/src/main/java/su/nightexpress/excellentenchants/nms/v1_19_R3/V1_19_R3.java index 5da9592..d451be8 100644 --- a/V1_19_R3/src/main/java/su/nightexpress/excellentenchants/nms/v1_19_R3/V1_19_R3.java +++ b/V1_19_R3/src/main/java/su/nightexpress/excellentenchants/nms/v1_19_R3/V1_19_R3.java @@ -5,6 +5,7 @@ import net.minecraft.network.protocol.game.ClientboundAnimatePacket; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.projectile.FishingHook; +import net.minecraft.world.item.SpawnEggItem; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.LiquidBlock; import net.minecraft.world.level.block.state.BlockState; @@ -22,6 +23,7 @@ import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import su.nightexpress.excellentenchants.nms.EnchantNMS; import java.util.HashSet; @@ -44,6 +46,18 @@ public class V1_19_R3 implements EnchantNMS { handle.retrieve(CraftItemStack.asNMSCopy(item)); } + @Override + @Nullable + public ItemStack getSpawnEgg(@NotNull LivingEntity entity) { + CraftLivingEntity craftLivingEntity = (CraftLivingEntity) entity; + net.minecraft.world.entity.LivingEntity livingEntity = craftLivingEntity.getHandle(); + + SpawnEggItem eggItem = SpawnEggItem.byId(livingEntity.getType()); + if (eggItem == null) return null; + + return CraftItemStack.asBukkitCopy(eggItem.getDefaultInstance()); + } + @Override @NotNull public Set handleFlameWalker(@NotNull LivingEntity bukkitEntity, @NotNull Location location, int level) { diff --git a/pom.xml b/pom.xml index 9743b28..dec9a7b 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ su.nightexpress.excellentenchants ExcellentEnchants pom - 3.3.4 + 3.4.0 Core NMS