diff --git a/pom.xml b/pom.xml index 195cf6eb..6dd9d590 100644 --- a/pom.xml +++ b/pom.xml @@ -141,7 +141,7 @@ io.lumine MythicLib-dist - 1.3-R27-SNAPSHOT + 1.3-R28-SNAPSHOT provided diff --git a/src/main/java/net/Indyuce/mmoitems/MMOItems.java b/src/main/java/net/Indyuce/mmoitems/MMOItems.java index 3f9ff739..1290af10 100644 --- a/src/main/java/net/Indyuce/mmoitems/MMOItems.java +++ b/src/main/java/net/Indyuce/mmoitems/MMOItems.java @@ -151,6 +151,7 @@ public class MMOItems extends LuminePlugin { public void enable() { new SpigotPlugin(39267, this).checkForUpdate(); new MMOItemsMetrics(); + MMOItemUIFilter.register(); RecipeBrowserGUI.registerNativeRecipes(); skillManager.initialize(false); @@ -215,7 +216,6 @@ public class MMOItems extends LuminePlugin { if (Bukkit.getPluginManager().getPlugin("PhatLoots") != null) { Bukkit.getPluginManager().registerEvents(new PhatLootsHook(), this); } - MMOItemUIFilter.register(); Bukkit.getScheduler().runTaskTimer(this, () -> Bukkit.getOnlinePlayers().forEach(player -> PlayerData.get(player).updateStats()), 100, 20); diff --git a/src/main/java/net/Indyuce/mmoitems/api/item/build/MMOItemBuilder.java b/src/main/java/net/Indyuce/mmoitems/api/item/build/MMOItemBuilder.java index 4cf1fe0f..aa519fe6 100644 --- a/src/main/java/net/Indyuce/mmoitems/api/item/build/MMOItemBuilder.java +++ b/src/main/java/net/Indyuce/mmoitems/api/item/build/MMOItemBuilder.java @@ -17,6 +17,7 @@ import net.Indyuce.mmoitems.stat.type.ItemStat; import net.Indyuce.mmoitems.stat.type.NameData; import net.Indyuce.mmoitems.stat.type.StatHistory; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.*; @@ -41,12 +42,12 @@ public class MMOItemBuilder { * have. If no tier is given, item uses the default capacity * formula given in the main config file */ - public MMOItemBuilder(MMOItemTemplate template, int level, ItemTier tier) { + public MMOItemBuilder(MMOItemTemplate template, int level, @Nullable ItemTier tier) { this.level = level; this.tier = tier; // Either use provided tier or look into the template base data - tier = tier != null ? tier : template.getBaseItemData().containsKey(ItemStats.TIER) ? MMOItems.plugin.getTiers().getOrThrow(template.getBaseItemData().get(ItemStats.TIER).toString()) : null; + tier = tier != null ? tier : template.getBaseItemData().containsKey(ItemStats.TIER) ? MMOItems.plugin.getTiers().get(template.getBaseItemData().get(ItemStats.TIER).toString()) : null; // Capacity is not final as it keeps lowering as modifiers are selected double capacity = (tier != null && tier.hasCapacity() ? tier.getModifierCapacity() : MMOItems.plugin.getLanguage().defaultItemCapacity).calculate(level); diff --git a/src/main/java/net/Indyuce/mmoitems/api/item/util/identify/IdentifiedItem.java b/src/main/java/net/Indyuce/mmoitems/api/item/util/identify/IdentifiedItem.java index c328a76c..3bbe8a1b 100644 --- a/src/main/java/net/Indyuce/mmoitems/api/item/util/identify/IdentifiedItem.java +++ b/src/main/java/net/Indyuce/mmoitems/api/item/util/identify/IdentifiedItem.java @@ -3,6 +3,7 @@ package net.Indyuce.mmoitems.api.item.util.identify; import java.io.ByteArrayInputStream; import java.io.IOException; +import net.Indyuce.mmoitems.api.item.mmoitem.LiveMMOItem; import org.bukkit.inventory.ItemStack; import org.bukkit.util.io.BukkitObjectInputStream; import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder; @@ -28,9 +29,25 @@ public class IdentifiedItem { try { ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Coder.decodeLines(data)); BukkitObjectInputStream dataInput = new BukkitObjectInputStream(inputStream); - ItemStack item = (ItemStack) dataInput.readObject(); + ItemStack stack = (ItemStack) dataInput.readObject(); dataInput.close(); - return item; + + /* + * For some reason, unidentified items keep having slightly different NBT tags + * than items generated from mob drops or the GUI, I suppose it has to do with + * the serialization-deserialization, It seems to get fixed when rebuilding + * the item stack though. + * + * Its annoying because it prevents stacking. + */ + NBTItem toRebuild = NBTItem.get(stack); + if (toRebuild.hasType()) { + + // Rebuild + LiveMMOItem rebuilt = new LiveMMOItem(stack); + return rebuilt.newBuilder().build(); } + + return stack; } catch (ClassNotFoundException | IOException e) { e.printStackTrace(); return null; diff --git a/src/main/java/net/Indyuce/mmoitems/comp/mythicmobs/mechanics/MMOItemsArrowVolleyMechanic.java b/src/main/java/net/Indyuce/mmoitems/comp/mythicmobs/mechanics/MMOItemsArrowVolleyMechanic.java index 4ce616f8..2ff0c91f 100644 --- a/src/main/java/net/Indyuce/mmoitems/comp/mythicmobs/mechanics/MMOItemsArrowVolleyMechanic.java +++ b/src/main/java/net/Indyuce/mmoitems/comp/mythicmobs/mechanics/MMOItemsArrowVolleyMechanic.java @@ -2,6 +2,10 @@ package net.Indyuce.mmoitems.comp.mythicmobs.mechanics; import io.lumine.mythic.lib.api.crafting.uimanager.ProvidedUIFilter; import io.lumine.mythic.lib.api.crafting.uimanager.UIFilterManager; +import io.lumine.mythic.lib.api.util.ui.FriendlyFeedbackCategory; +import io.lumine.mythic.lib.api.util.ui.FriendlyFeedbackMessage; +import io.lumine.mythic.lib.api.util.ui.FriendlyFeedbackProvider; +import io.lumine.mythic.lib.api.util.ui.SilentNumbers; import io.lumine.xikage.mythicmobs.adapters.AbstractEntity; import io.lumine.xikage.mythicmobs.adapters.AbstractLocation; import io.lumine.xikage.mythicmobs.adapters.SkillAdapter; @@ -12,6 +16,7 @@ import io.lumine.xikage.mythicmobs.skills.placeholders.parsers.PlaceholderDouble import io.lumine.xikage.mythicmobs.skills.placeholders.parsers.PlaceholderFloat; import io.lumine.xikage.mythicmobs.skills.placeholders.parsers.PlaceholderInt; import net.Indyuce.mmoitems.MMOItems; +import net.Indyuce.mmoitems.api.util.message.FFPMMOItems; import net.Indyuce.mmoitems.listener.ItemUse; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -40,7 +45,7 @@ public class MMOItemsArrowVolleyMechanic extends SkillMechanic implements ITarge @NotNull PlaceholderFloat velocity, scale; @NotNull PlaceholderDouble xOffset, yOffset, zOffset, fOffset, sOffset; - @Nullable ItemStack arrowItem; + @Nullable ItemStack arrowItem = null; boolean fullEvent; boolean scalePerArrow; boolean fromOrigin; @@ -62,8 +67,11 @@ public class MMOItemsArrowVolleyMechanic extends SkillMechanic implements ITarge //region Get Arrow Item String itemFilter = mlc.getString(new String[] {"arrowitem", "item", "ai"}, null); + //DBG//MMOItems.log("Found In Config " + itemFilter); if (itemFilter != null) { - ProvidedUIFilter uiFilter = UIFilterManager.getUIFilter(itemFilter, null); + //DBG//FriendlyFeedbackProvider ffp = new FriendlyFeedbackProvider(FFPMMOItems.get()); + ProvidedUIFilter uiFilter = UIFilterManager.getUIFilter(itemFilter.replace("<&sp>", " ").replace("\"", ""), null); + //DBG//MMOItems.log("Errors Result: " + SilentNumbers.collapseList(SilentNumbers.transcribeList(ffp.getFeedbackOf(FriendlyFeedbackCategory.ERROR), message -> { if (message instanceof FriendlyFeedbackMessage) { return ((FriendlyFeedbackMessage) message).forConsole(FFPMMOItems.get()); } return ""; }), "")); if (uiFilter != null) { if (uiFilter.isValid(null) && uiFilter.getParent().fullyDefinesItem()) { uiFilter.setAmount(1); @@ -71,8 +79,11 @@ public class MMOItemsArrowVolleyMechanic extends SkillMechanic implements ITarge // Generate Item arrowItem = uiFilter.getItemStack(null); } + //DBG// else{ MMOItems.log("Invalid\u00a73 " + uiFilter.toString()); } } } + + //DBG//MMOItems.log("Generated Item " + SilentNumbers.getItemName(arrowItem)); //endregion // Offsets @@ -121,6 +132,9 @@ public class MMOItemsArrowVolleyMechanic extends SkillMechanic implements ITarge public void executeMIVolley(@NotNull SkillCaster caster, @NotNull SkillMetadata data, @NotNull AbstractLocation t, int amount, float velocity, float spread, int fireTicks, int removeDelay, @NotNull PlaceholderFloat statsMultiplier) { + // Cancel infinite loops + if (syncEventBlock) { return; } + // Skill caster MUST be a player if (!(caster.getEntity().getBukkitEntity() instanceof Player)) { return; } Player player = (Player) caster.getEntity().getBukkitEntity(); @@ -147,6 +161,7 @@ public class MMOItemsArrowVolleyMechanic extends SkillMechanic implements ITarge // Player bow item is held?? ItemStack bowItem = player.getInventory().getItemInMainHand().clone(); ItemStack localArrowItem = (arrowItem != null ? arrowItem.clone() : new ItemStack(Material.ARROW)); + //DBG//MMOItems.log("Deployed Item " + SilentNumbers.getItemName(arrowItem)); ItemUse use = new ItemUse(); // Parse @@ -164,8 +179,10 @@ public class MMOItemsArrowVolleyMechanic extends SkillMechanic implements ITarge a.setShooter(player); // Run Event + syncEventBlock = true; EntityShootBowEvent shootBowEvent = new EntityShootBowEvent(player, bowItem, localArrowItem, a, EquipmentSlot.HAND, arrowForce, false); if (fullEvent) { Bukkit.getPluginManager().callEvent(shootBowEvent); } else { use.handleCustomBows(shootBowEvent); } + syncEventBlock = false; // Cancelled??? if (shootBowEvent.isCancelled()) { a.remove(); continue; } @@ -184,4 +201,6 @@ public class MMOItemsArrowVolleyMechanic extends SkillMechanic implements ITarge Bukkit.getScheduler().scheduleSyncDelayedTask(MMOItems.plugin, () -> { for (Arrow a : arrowList) { a.remove(); }arrowList.clear(); }, removeDelay); } + + static boolean syncEventBlock = false; } diff --git a/src/main/java/net/Indyuce/mmoitems/listener/ItemUse.java b/src/main/java/net/Indyuce/mmoitems/listener/ItemUse.java index ff0be531..cb8e307e 100644 --- a/src/main/java/net/Indyuce/mmoitems/listener/ItemUse.java +++ b/src/main/java/net/Indyuce/mmoitems/listener/ItemUse.java @@ -100,7 +100,6 @@ public class ItemUse implements Listener { UntargetedWeapon weapon = (UntargetedWeapon) useItem; if ((event.getAction().name().contains("RIGHT_CLICK") && weapon.getWeaponType() == WeaponType.RIGHT_CLICK) || (event.getAction().name().contains("LEFT_CLICK") && weapon.getWeaponType() == WeaponType.LEFT_CLICK)) { - MMOItems.log("Running from \u00a7cUNTARGETTED"); // Run attack event MMOItemsSpecialWeaponAttack attackEvent = new MMOItemsSpecialWeaponAttack(player, useItem, weapon.untargetedTargetTrace(EquipmentSlot.fromBukkit(event.getHand()))); @@ -199,7 +198,7 @@ public class ItemUse implements Listener { // Special staff attack if (weapon instanceof Staff) { - MMOItems.log("Running from \u00a7aSTAFF"); + // Run attack event MMOItemsSpecialWeaponAttack attackEvent = new MMOItemsSpecialWeaponAttack(player, weapon, target); Bukkit.getPluginManager().callEvent(attackEvent); @@ -213,7 +212,6 @@ public class ItemUse implements Listener { // Special gauntlet attack if (weapon instanceof Gauntlet) { - MMOItems.log("Running from \u00a7bGAUNTLET"); // Run attack event MMOItemsSpecialWeaponAttack attackEvent = new MMOItemsSpecialWeaponAttack(player, weapon, target); diff --git a/src/main/java/net/Indyuce/mmoitems/manager/EntityManager.java b/src/main/java/net/Indyuce/mmoitems/manager/EntityManager.java index 867cb180..5b4043f3 100644 --- a/src/main/java/net/Indyuce/mmoitems/manager/EntityManager.java +++ b/src/main/java/net/Indyuce/mmoitems/manager/EntityManager.java @@ -7,6 +7,7 @@ import io.lumine.mythic.lib.player.PlayerMetadata; import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.api.ElementalAttack; import net.Indyuce.mmoitems.api.ItemAttackMetadata; +import net.Indyuce.mmoitems.api.event.MMOItemsProjectileFireEvent; import net.Indyuce.mmoitems.api.interaction.projectile.ArrowParticles; import net.Indyuce.mmoitems.api.interaction.projectile.EntityData; import net.Indyuce.mmoitems.api.interaction.projectile.ProjectileData; @@ -22,10 +23,8 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDeathEvent; -import org.bukkit.event.entity.EntityShootBowEvent; import org.bukkit.event.entity.ProjectileHitEvent; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.util.HashMap; import java.util.Map; @@ -145,6 +144,12 @@ public class EntityManager implements Listener { } event.setDamage(damage); + + // Remove projectile if it has no piercing anymore + if (projectile instanceof AbstractArrow) { + + if (((AbstractArrow) projectile).getPierceLevel() > 1) { return; } } + unregisterCustomProjectile(projectile); } // Unregister custom projectiles from the map diff --git a/src/main/java/net/Indyuce/mmoitems/stat/ItemSetStat.java b/src/main/java/net/Indyuce/mmoitems/stat/ItemSetStat.java index c2f99f8a..6db1d88b 100644 --- a/src/main/java/net/Indyuce/mmoitems/stat/ItemSetStat.java +++ b/src/main/java/net/Indyuce/mmoitems/stat/ItemSetStat.java @@ -45,7 +45,9 @@ public class ItemSetStat extends StringStat { // Display in lore ItemSet set = MMOItems.plugin.getSets().get(data.toString()); - item.getLore().insert("set", set.getLoreTag()); + + // Apply lore + if (set != null) { item.getLore().insert("set", set.getLoreTag()); } // Add NBT item.addItemTag(getAppliedNBT(data));