From d9dfa21592e5366f45738a409a9d424fda9e73d9 Mon Sep 17 00:00:00 2001 From: Indyuce Date: Sat, 12 Mar 2022 14:06:16 +0100 Subject: [PATCH] Support for MM 5.0.1 --- pom.xml | 4 +- .../comp/mythicmobs/LootsplosionListener.java | 155 +++++++++--------- .../mythicmobs/MythicMobsCompatibility.java | 28 ++-- .../crafting/MythicItemIngredient.java | 68 ++++---- .../crafting/MythicMobsSkillTrigger.java | 13 +- .../MMOItemsArrowVolleyMechanic.java | 124 ++++++++------ .../mechanics/MMOItemsOnShootAura.java | 107 ++++++++---- .../comp/mythicmobs/stat/FactionDamage.java | 4 +- 8 files changed, 284 insertions(+), 219 deletions(-) diff --git a/pom.xml b/pom.xml index 01301df3..e359e726 100644 --- a/pom.xml +++ b/pom.xml @@ -193,8 +193,8 @@ io.lumine - MythicMobs-Dist - 5.0.0-SNAPSHOT + Mythic-Dist + 5.0.1 provided diff --git a/src/main/java/net/Indyuce/mmoitems/comp/mythicmobs/LootsplosionListener.java b/src/main/java/net/Indyuce/mmoitems/comp/mythicmobs/LootsplosionListener.java index 269dc02a..404a47bc 100644 --- a/src/main/java/net/Indyuce/mmoitems/comp/mythicmobs/LootsplosionListener.java +++ b/src/main/java/net/Indyuce/mmoitems/comp/mythicmobs/LootsplosionListener.java @@ -1,9 +1,10 @@ package net.Indyuce.mmoitems.comp.mythicmobs; -import java.util.ArrayList; -import java.util.List; -import java.util.Random; - +import io.lumine.mythic.bukkit.events.MythicMobDeathEvent; +import io.lumine.mythic.lib.MythicLib; +import io.lumine.mythic.lib.api.item.NBTItem; +import net.Indyuce.mmoitems.MMOItems; +import net.Indyuce.mmoitems.api.ItemTier; import org.bukkit.Bukkit; import org.bukkit.Color; import org.bukkit.Particle; @@ -16,98 +17,96 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.util.Vector; -import io.lumine.xikage.mythicmobs.api.bukkit.events.MythicMobDeathEvent; -import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.api.ItemTier; -import io.lumine.mythic.lib.MythicLib; -import io.lumine.mythic.lib.api.item.NBTItem; +import java.util.ArrayList; +import java.util.List; +import java.util.Random; public class LootsplosionListener implements Listener { - private static final Random random = new Random(); + private static final Random random = new Random(); - private final boolean colored; + private final boolean colored; - public LootsplosionListener() { - colored = MMOItems.plugin.getConfig().getBoolean("lootsplosion.color"); - } + public LootsplosionListener() { + colored = MMOItems.plugin.getConfig().getBoolean("lootsplosion.color"); + } - @EventHandler(priority = EventPriority.HIGH) - public void b(MythicMobDeathEvent event) { - if (event.getMob().getVariables().has("Lootsplosion")) - new LootsplosionHandler(event); - } + @EventHandler(priority = EventPriority.HIGH) + public void b(MythicMobDeathEvent event) { + if (event.getMob().getVariables().has("Lootsplosion")) + new LootsplosionHandler(event); + } - public class LootsplosionHandler implements Listener { - private final List drops; + public class LootsplosionHandler implements Listener { + private final List drops; - /* - * Y coordinate offset so the velocity is not directly negated when the - * item spawns on the ground - */ - private final double offset; + /* + * Y coordinate offset so the velocity is not directly negated when the + * item spawns on the ground + */ + private final double offset; - public LootsplosionHandler(MythicMobDeathEvent event) { - offset = event.getEntity().getHeight() / 2; - drops = new ArrayList<>(event.getDrops()); + public LootsplosionHandler(MythicMobDeathEvent event) { + offset = event.getEntity().getHeight() / 2; + drops = new ArrayList<>(event.getDrops()); - Bukkit.getPluginManager().registerEvents(this, MMOItems.plugin); - } + Bukkit.getPluginManager().registerEvents(this, MMOItems.plugin); + } - private void close() { - ItemSpawnEvent.getHandlerList().unregister(this); - } + private void close() { + ItemSpawnEvent.getHandlerList().unregister(this); + } - @EventHandler - public void a(ItemSpawnEvent event) { - Item item = event.getEntity(); - if (!drops.contains(item.getItemStack())) { - close(); - return; - } + @EventHandler + public void a(ItemSpawnEvent event) { + Item item = event.getEntity(); + if (!drops.contains(item.getItemStack())) { + close(); + return; + } - drops.remove(item.getItemStack()); - item.teleport(item.getLocation().add(0, offset, 0)); - item.setVelocity(randomVector()); + drops.remove(item.getItemStack()); + item.teleport(item.getLocation().add(0, offset, 0)); + item.setVelocity(randomVector()); - if (colored) - Bukkit.getScheduler().runTask(MMOItems.plugin, () -> { - NBTItem nbt = MythicLib.plugin.getVersion().getWrapper().getNBTItem(item.getItemStack()); - if (nbt.hasTag("MMOITEMS_TIER")) { - ItemTier tier = MMOItems.plugin.getTiers().get(nbt.getString("MMOITEMS_TIER")); - if (tier.hasColor()) - new LootColor(item, tier.getColor().toBukkit()); - } - }); - } - } + if (colored) + Bukkit.getScheduler().runTask(MMOItems.plugin, () -> { + NBTItem nbt = MythicLib.plugin.getVersion().getWrapper().getNBTItem(item.getItemStack()); + if (nbt.hasTag("MMOITEMS_TIER")) { + ItemTier tier = MMOItems.plugin.getTiers().get(nbt.getString("MMOITEMS_TIER")); + if (tier.hasColor()) + new LootColor(item, tier.getColor().toBukkit()); + } + }); + } + } - private Vector randomVector() { - double offset = MMOItems.plugin.getConfig().getDouble("lootsplosion.offset"), - height = MMOItems.plugin.getConfig().getDouble("lootsplosion.height"); - return new Vector(Math.cos(random.nextDouble() * Math.PI * 2) * offset, height, Math.sin(random.nextDouble() * Math.PI * 2) * offset); - } + private Vector randomVector() { + double offset = MMOItems.plugin.getConfig().getDouble("lootsplosion.offset"), + height = MMOItems.plugin.getConfig().getDouble("lootsplosion.height"); + return new Vector(Math.cos(random.nextDouble() * Math.PI * 2) * offset, height, Math.sin(random.nextDouble() * Math.PI * 2) * offset); + } - public class LootColor extends BukkitRunnable { - private final Item item; - private final Color color; + public class LootColor extends BukkitRunnable { + private final Item item; + private final Color color; - private int j = 0; + private int j = 0; - public LootColor(Item item, Color color) { - this.item = item; - this.color = color; + public LootColor(Item item, Color color) { + this.item = item; + this.color = color; - runTaskTimer(MMOItems.plugin, 0, 1); - } + runTaskTimer(MMOItems.plugin, 0, 1); + } - @Override - public void run() { - if (j++ > 100 || item.isDead() || item.isOnGround()) { - cancel(); - return; - } + @Override + public void run() { + if (j++ > 100 || item.isDead() || item.isOnGround()) { + cancel(); + return; + } - item.getWorld().spawnParticle(Particle.REDSTONE, item.getLocation(), 1, new Particle.DustOptions(color, 1.3f)); - } - } + item.getWorld().spawnParticle(Particle.REDSTONE, item.getLocation(), 1, new Particle.DustOptions(color, 1.3f)); + } + } } diff --git a/src/main/java/net/Indyuce/mmoitems/comp/mythicmobs/MythicMobsCompatibility.java b/src/main/java/net/Indyuce/mmoitems/comp/mythicmobs/MythicMobsCompatibility.java index 755fc426..994072ab 100644 --- a/src/main/java/net/Indyuce/mmoitems/comp/mythicmobs/MythicMobsCompatibility.java +++ b/src/main/java/net/Indyuce/mmoitems/comp/mythicmobs/MythicMobsCompatibility.java @@ -1,11 +1,10 @@ package net.Indyuce.mmoitems.comp.mythicmobs; -import io.lumine.xikage.mythicmobs.MythicMobs; -import io.lumine.xikage.mythicmobs.api.bukkit.events.MythicMechanicLoadEvent; -import io.lumine.xikage.mythicmobs.api.bukkit.events.MythicReloadedEvent; -import io.lumine.xikage.mythicmobs.mobs.MythicMob; +import io.lumine.mythic.api.mobs.MythicMob; +import io.lumine.mythic.bukkit.MythicBukkit; +import io.lumine.mythic.bukkit.events.MythicMechanicLoadEvent; +import io.lumine.mythic.bukkit.events.MythicReloadedEvent; import net.Indyuce.mmoitems.MMOItems; -import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem; import net.Indyuce.mmoitems.api.player.PlayerData; import net.Indyuce.mmoitems.comp.mythicmobs.mechanics.MMOItemsArrowVolleyMechanic; import net.Indyuce.mmoitems.comp.mythicmobs.mechanics.MMOItemsOnShootAura; @@ -16,7 +15,10 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; -import java.util.*; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; public class MythicMobsCompatibility implements Listener { @@ -39,12 +41,13 @@ public class MythicMobsCompatibility implements Listener { // Switch Mechanic ig switch (event.getMechanicName().toLowerCase()) { case "mmoitemsvolley": - event.register(new MMOItemsArrowVolleyMechanic(event.getContainer().getConfigLine(), event.getConfig())); + event.register(new MMOItemsArrowVolleyMechanic(event.getContainer().getManager(), event.getContainer().getConfigLine(), event.getConfig())); break; case "onmmoitemuse": - event.register(new MMOItemsOnShootAura(event.getContainer().getConfigLine(), event.getConfig())); + event.register(new MMOItemsOnShootAura(event.getContainer().getManager(), event.getContainer().getConfigLine(), event.getConfig())); + break; + default: break; - default: break; } } @@ -61,15 +64,16 @@ public class MythicMobsCompatibility implements Listener { // Reload the abilities of online players... for (Player p : Bukkit.getOnlinePlayers()) { PlayerData data = PlayerData.get(p); - data.updateInventory(); } + data.updateInventory(); + } } private Set getFactions() { Set allFactions = new HashSet<>(); // Collects all mythic mobs + edited vanilla mobs in mythic mobs. - List mobs = new ArrayList<>(MythicMobs.inst().getMobManager().getVanillaTypes()); - mobs.addAll(MythicMobs.inst().getMobManager().getMobTypes()); + List mobs = new ArrayList<>(MythicBukkit.inst().getMobManager().getVanillaTypes()); + mobs.addAll(MythicBukkit.inst().getMobManager().getMobTypes()); // Adds their faction to the set if it is set. for (MythicMob mob : mobs) diff --git a/src/main/java/net/Indyuce/mmoitems/comp/mythicmobs/crafting/MythicItemIngredient.java b/src/main/java/net/Indyuce/mmoitems/comp/mythicmobs/crafting/MythicItemIngredient.java index 225293ea..67c9dcd2 100644 --- a/src/main/java/net/Indyuce/mmoitems/comp/mythicmobs/crafting/MythicItemIngredient.java +++ b/src/main/java/net/Indyuce/mmoitems/comp/mythicmobs/crafting/MythicItemIngredient.java @@ -1,9 +1,9 @@ package net.Indyuce.mmoitems.comp.mythicmobs.crafting; +import io.lumine.mythic.bukkit.BukkitAdapter; +import io.lumine.mythic.bukkit.MythicBukkit; +import io.lumine.mythic.core.items.MythicItem; import io.lumine.mythic.lib.api.MMOLineConfig; -import io.lumine.xikage.mythicmobs.MythicMobs; -import io.lumine.xikage.mythicmobs.adapters.bukkit.BukkitAdapter; -import io.lumine.xikage.mythicmobs.items.MythicItem; import net.Indyuce.mmoitems.api.crafting.ingredient.Ingredient; import net.Indyuce.mmoitems.api.player.RPGPlayer; import org.apache.commons.lang.Validate; @@ -20,44 +20,44 @@ import java.util.Optional; */ @Deprecated public class MythicItemIngredient extends Ingredient { - private final MythicItem mythicitem; + private final MythicItem mythicitem; - private final String display; + private final String display; - public MythicItemIngredient(MMOLineConfig config) { - super("mythicitem", config); + public MythicItemIngredient(MMOLineConfig config) { + super("mythicitem", config); - config.validate("item"); - Optional mmitem = MythicMobs.inst().getItemManager().getItem(config.getString("item")); - Validate.isTrue(mmitem.isPresent(), "Could not find MM Item with ID '" + config.getString("item") + "'"); + config.validate("item"); + Optional mmitem = MythicBukkit.inst().getItemManager().getItem(config.getString("item")); + Validate.isTrue(mmitem.isPresent(), "Could not find MM Item with ID '" + config.getString("item") + "'"); - display = config.contains("display") ? config.getString("display") : mmitem.get().getDisplayName(); - mythicitem = mmitem.get(); - } + display = config.contains("display") ? config.getString("display") : mmitem.get().getDisplayName(); + mythicitem = mmitem.get(); + } - @Override - public String getKey() { - return "mythicitem:" + mythicitem.getInternalName().toLowerCase(); - } + @Override + public String getKey() { + return "mythicitem:" + mythicitem.getInternalName().toLowerCase(); + } - @Override - public String formatDisplay(String s) { - return s.replace("#item#", display).replace("#amount#", "" + getAmount()); - } + @Override + public String formatDisplay(String s) { + return s.replace("#item#", display).replace("#amount#", "" + getAmount()); + } - @Override - public boolean matches(MythicItemPlayerIngredient playerIngredient) { - return false; - } + @Override + public boolean matches(MythicItemPlayerIngredient playerIngredient) { + return false; + } - @NotNull - @Override - public ItemStack generateItemStack(@NotNull RPGPlayer player) { - return BukkitAdapter.adapt(mythicitem.generateItemStack(getAmount())); - } + @NotNull + @Override + public ItemStack generateItemStack(@NotNull RPGPlayer player) { + return BukkitAdapter.adapt(mythicitem.generateItemStack(getAmount())); + } - @Override - public String toString() { - return getKey(); - } + @Override + public String toString() { + return getKey(); + } } diff --git a/src/main/java/net/Indyuce/mmoitems/comp/mythicmobs/crafting/MythicMobsSkillTrigger.java b/src/main/java/net/Indyuce/mmoitems/comp/mythicmobs/crafting/MythicMobsSkillTrigger.java index bdcc4b92..c827c528 100644 --- a/src/main/java/net/Indyuce/mmoitems/comp/mythicmobs/crafting/MythicMobsSkillTrigger.java +++ b/src/main/java/net/Indyuce/mmoitems/comp/mythicmobs/crafting/MythicMobsSkillTrigger.java @@ -1,10 +1,10 @@ package net.Indyuce.mmoitems.comp.mythicmobs.crafting; -import io.lumine.xikage.mythicmobs.MythicMobs; -import io.lumine.xikage.mythicmobs.skills.Skill; +import io.lumine.mythic.api.skills.Skill; +import io.lumine.mythic.bukkit.MythicBukkit; +import io.lumine.mythic.lib.api.MMOLineConfig; import net.Indyuce.mmoitems.api.crafting.trigger.Trigger; import net.Indyuce.mmoitems.api.player.PlayerData; -import io.lumine.mythic.lib.api.MMOLineConfig; import org.apache.commons.lang.Validate; import org.bukkit.entity.Entity; @@ -13,7 +13,6 @@ import java.util.List; import java.util.Optional; public class MythicMobsSkillTrigger extends Trigger { - private final Skill skill; public MythicMobsSkillTrigger(MMOLineConfig config) { @@ -21,16 +20,16 @@ public class MythicMobsSkillTrigger extends Trigger { config.validate("id"); String id = config.getString("id"); - Optional opt = MythicMobs.inst().getSkillManager().getSkill(id); + Optional opt = MythicBukkit.inst().getSkillManager().getSkill(id); Validate.isTrue(opt.isPresent(), "Could not find MM skill " + id); skill = opt.get(); } @Override public void whenCrafting(PlayerData data) { - if(!data.isOnline()) return; + if (!data.isOnline()) return; List targets = new ArrayList<>(); targets.add(data.getPlayer()); - MythicMobs.inst().getAPIHelper().castSkill(data.getPlayer(), this.skill.getInternalName(), data.getPlayer(), data.getPlayer().getEyeLocation(), targets, null, 1); + MythicBukkit.inst().getAPIHelper().castSkill(data.getPlayer(), this.skill.getInternalName(), data.getPlayer(), data.getPlayer().getEyeLocation(), targets, null, 1); } } 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 00d39798..484d5878 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 @@ -1,16 +1,18 @@ package net.Indyuce.mmoitems.comp.mythicmobs.mechanics; +import io.lumine.mythic.api.adapters.AbstractEntity; +import io.lumine.mythic.api.adapters.AbstractLocation; +import io.lumine.mythic.api.adapters.SkillAdapter; +import io.lumine.mythic.api.config.MythicLineConfig; +import io.lumine.mythic.api.skills.*; +import io.lumine.mythic.api.skills.placeholders.PlaceholderDouble; +import io.lumine.mythic.api.skills.placeholders.PlaceholderFloat; +import io.lumine.mythic.api.skills.placeholders.PlaceholderInt; +import io.lumine.mythic.bukkit.BukkitAdapter; +import io.lumine.mythic.core.skills.SkillExecutor; +import io.lumine.mythic.core.skills.SkillMechanic; import io.lumine.mythic.lib.api.crafting.uimanager.ProvidedUIFilter; import io.lumine.mythic.lib.api.crafting.uimanager.UIFilterManager; -import io.lumine.xikage.mythicmobs.adapters.AbstractEntity; -import io.lumine.xikage.mythicmobs.adapters.AbstractLocation; -import io.lumine.xikage.mythicmobs.adapters.SkillAdapter; -import io.lumine.xikage.mythicmobs.adapters.bukkit.BukkitAdapter; -import io.lumine.xikage.mythicmobs.io.MythicLineConfig; -import io.lumine.xikage.mythicmobs.skills.*; -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.listener.ItemUse; import org.bukkit.Bukkit; @@ -37,34 +39,38 @@ import java.util.ArrayList; */ public class MMOItemsArrowVolleyMechanic extends SkillMechanic implements ITargetedEntitySkill, ITargetedLocationSkill { - @NotNull PlaceholderInt amount, spread, fireTicks, removeDelay; - @NotNull PlaceholderFloat velocity, scale; - @NotNull PlaceholderDouble xOffset, yOffset, zOffset, fOffset, sOffset; + @NotNull + PlaceholderInt amount, spread, fireTicks, removeDelay; + @NotNull + PlaceholderFloat velocity, scale; + @NotNull + PlaceholderDouble xOffset, yOffset, zOffset, fOffset, sOffset; - @Nullable ItemStack arrowItem; + @Nullable + ItemStack arrowItem; boolean fullEvent; boolean scalePerArrow; boolean fromOrigin; boolean allowPickup; - public MMOItemsArrowVolleyMechanic(String line, MythicLineConfig mlc) { - super(line, mlc); + public MMOItemsArrowVolleyMechanic(SkillExecutor manager, String line, MythicLineConfig mlc) { + super(manager, line, mlc); threadSafetyLevel = ThreadSafetyLevel.SYNC_ONLY; - amount = mlc.getPlaceholderInteger(new String[] {"amount", "arrows", "a"}, 20); - spread = mlc.getPlaceholderInteger(new String[] {"spread", "s"}, 45); - fireTicks = mlc.getPlaceholderInteger(new String[] {"fireticks", "ft", "f"}, 0); - removeDelay = mlc.getPlaceholderInteger(new String[] {"removedelay", "rd", "r"}, 200); - velocity = mlc.getPlaceholderFloat(new String[] {"velocity", "v"}, 20); - scale = mlc.getPlaceholderFloat(new String[] {"statsscale", "ss"}, 1); + amount = mlc.getPlaceholderInteger(new String[]{"amount", "arrows", "a"}, 20); + spread = mlc.getPlaceholderInteger(new String[]{"spread", "s"}, 45); + fireTicks = mlc.getPlaceholderInteger(new String[]{"fireticks", "ft", "f"}, 0); + removeDelay = mlc.getPlaceholderInteger(new String[]{"removedelay", "rd", "r"}, 200); + velocity = mlc.getPlaceholderFloat(new String[]{"velocity", "v"}, 20); + scale = mlc.getPlaceholderFloat(new String[]{"statsscale", "ss"}, 1); - fullEvent = mlc.getBoolean(new String[] {"fullevent", "fe"}, false); - scalePerArrow = mlc.getBoolean(new String[] {"scaleperarrow", "spa"}, false); - fromOrigin = mlc.getBoolean(new String[] {"fromorigin", "fo"}, false); - allowPickup = mlc.getBoolean(new String[] {"allowpickup", "ap"}, false); + fullEvent = mlc.getBoolean(new String[]{"fullevent", "fe"}, false); + scalePerArrow = mlc.getBoolean(new String[]{"scaleperarrow", "spa"}, false); + fromOrigin = mlc.getBoolean(new String[]{"fromorigin", "fo"}, false); + allowPickup = mlc.getBoolean(new String[]{"allowpickup", "ap"}, false); //region Get Arrow Item - String itemFilter = mlc.getString(new String[] {"arrowitem", "item", "ai"}, null); + String itemFilter = mlc.getString(new String[]{"arrowitem", "item", "ai"}, null); //DBG//MMOItems.log("Found In Config " + itemFilter); if (itemFilter != null) { //DBG//FriendlyFeedbackProvider ffp = new FriendlyFeedbackProvider(FFPMMOItems.get()); @@ -85,16 +91,16 @@ public class MMOItemsArrowVolleyMechanic extends SkillMechanic implements ITarge //endregion // Offsets - xOffset = mlc.getPlaceholderDouble(new String[] {"startxoffset", "sxo"}, 0); - yOffset = mlc.getPlaceholderDouble(new String[] {"startyoffset", "syo"}, 3); - zOffset = mlc.getPlaceholderDouble(new String[] {"startzoffset", "szo"}, 0); - fOffset = mlc.getPlaceholderDouble(new String[] {"startfoffset", "sfo"}, 0); - sOffset = mlc.getPlaceholderDouble(new String[] {"startsoffset", "sso"}, 0); + xOffset = mlc.getPlaceholderDouble(new String[]{"startxoffset", "sxo"}, 0); + yOffset = mlc.getPlaceholderDouble(new String[]{"startyoffset", "syo"}, 3); + zOffset = mlc.getPlaceholderDouble(new String[]{"startzoffset", "szo"}, 0); + fOffset = mlc.getPlaceholderDouble(new String[]{"startfoffset", "sfo"}, 0); + sOffset = mlc.getPlaceholderDouble(new String[]{"startsoffset", "sso"}, 0); } @Override - public boolean castAtLocation(SkillMetadata data, AbstractLocation target) { + public SkillResult castAtLocation(SkillMetadata data, AbstractLocation target) { // Caster must be a player if (data.getCaster().getEntity().getBukkitEntity() instanceof Player) { @@ -107,34 +113,38 @@ public class MMOItemsArrowVolleyMechanic extends SkillMechanic implements ITarge // Run as normal mythicmobs arrow volley SkillAdapter.get().executeVolley(data.getCaster(), target, amount.get(data), velocity.get(data) * 0.1F, spread.get(data), fireTicks.get(data), removeDelay.get(data)); } - return true; + return SkillResult.SUCCESS; } @Override - public boolean castAtEntity(SkillMetadata data, AbstractEntity target) { + public SkillResult castAtEntity(SkillMetadata data, AbstractEntity target) { // Caster must be a player if (data.getCaster().getEntity().getBukkitEntity() instanceof Player) { // MMOItems Volley! - executeMIVolley(data.getCaster(), data, target.getLocation(), amount.get(data,target), velocity.get(data) * 0.1F, spread.get(data), fireTicks.get(data), removeDelay.get(data), scale); + executeMIVolley(data.getCaster(), data, target.getLocation(), amount.get(data, target), velocity.get(data) * 0.1F, spread.get(data), fireTicks.get(data), removeDelay.get(data), scale); } else { // Run as normal mythicmobs arrow volley - SkillAdapter.get().executeVolley(data.getCaster(), target.getLocation(), amount.get(data,target), velocity.get(data) * 0.1F, spread.get(data), fireTicks.get(data), removeDelay.get(data)); + SkillAdapter.get().executeVolley(data.getCaster(), target.getLocation(), amount.get(data, target), velocity.get(data) * 0.1F, spread.get(data), fireTicks.get(data), removeDelay.get(data)); } - return true; + return SkillResult.SUCCESS; } - 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) { + 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; } + if (syncEventBlock) { + return; + } // Skill caster MUST be a player - if (!(caster.getEntity().getBukkitEntity() instanceof Player)) { return; } + if (!(caster.getEntity().getBukkitEntity() instanceof Player)) { + return; + } Player player = (Player) caster.getEntity().getBukkitEntity(); // Target yeah @@ -170,11 +180,14 @@ public class MMOItemsArrowVolleyMechanic extends SkillMechanic implements ITarge for (int i = 0; i < amount; i++) { // Spawn Arrow - Arrow a = player.getWorld().spawnArrow(spawn, v, velocity, (spread/10.0F)); + Arrow a = player.getWorld().spawnArrow(spawn, v, velocity, (spread / 10.0F)); a.setVelocity(a.getVelocity()); - if (allowPickup) { a.setPickupStatus(AbstractArrow.PickupStatus.ALLOWED); } - else { a.setPickupStatus(AbstractArrow.PickupStatus.DISALLOWED); } + if (allowPickup) { + a.setPickupStatus(AbstractArrow.PickupStatus.ALLOWED); + } else { + a.setPickupStatus(AbstractArrow.PickupStatus.DISALLOWED); + } // Identify arrow as the player's a.setShooter(player); @@ -182,25 +195,40 @@ public class MMOItemsArrowVolleyMechanic extends SkillMechanic implements ITarge // 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); } + if (fullEvent) { + Bukkit.getPluginManager().callEvent(shootBowEvent); + } else { + use.handleCustomBows(shootBowEvent); + } syncEventBlock = false; // Cancelled??? - if (shootBowEvent.isCancelled()) { a.remove(); continue; } + if (shootBowEvent.isCancelled()) { + a.remove(); + continue; + } // Set on fire I guess - if(fireTicks > 0) { a.setFireTicks(fireTicks); } + if (fireTicks > 0) { + a.setFireTicks(fireTicks); + } // Add to list arrowList.add(a); // Recalculate - if (scalePerArrow) { arrowForce = statsMultiplier.get(data); } + if (scalePerArrow) { + arrowForce = statsMultiplier.get(data); + } } // Remove after delay Bukkit.getScheduler().scheduleSyncDelayedTask(MMOItems.plugin, () -> { - for (Arrow a : arrowList) { a.remove(); }arrowList.clear(); }, removeDelay); + for (Arrow a : arrowList) { + a.remove(); + } + arrowList.clear(); + }, removeDelay); } static boolean syncEventBlock; diff --git a/src/main/java/net/Indyuce/mmoitems/comp/mythicmobs/mechanics/MMOItemsOnShootAura.java b/src/main/java/net/Indyuce/mmoitems/comp/mythicmobs/mechanics/MMOItemsOnShootAura.java index 4a259768..068e1cc2 100644 --- a/src/main/java/net/Indyuce/mmoitems/comp/mythicmobs/mechanics/MMOItemsOnShootAura.java +++ b/src/main/java/net/Indyuce/mmoitems/comp/mythicmobs/mechanics/MMOItemsOnShootAura.java @@ -1,14 +1,15 @@ package net.Indyuce.mmoitems.comp.mythicmobs.mechanics; -import io.lumine.xikage.mythicmobs.MythicMobs; -import io.lumine.xikage.mythicmobs.adapters.AbstractEntity; -import io.lumine.xikage.mythicmobs.adapters.bukkit.BukkitAdapter; -import io.lumine.xikage.mythicmobs.io.MythicLineConfig; -import io.lumine.xikage.mythicmobs.mobs.GenericCaster; -import io.lumine.xikage.mythicmobs.skills.*; -import io.lumine.xikage.mythicmobs.skills.auras.Aura; -import io.lumine.xikage.mythicmobs.skills.placeholders.parsers.PlaceholderString; -import io.lumine.xikage.mythicmobs.utils.Events; +import io.lumine.mythic.api.adapters.AbstractEntity; +import io.lumine.mythic.api.config.MythicLineConfig; +import io.lumine.mythic.api.mobs.GenericCaster; +import io.lumine.mythic.api.skills.*; +import io.lumine.mythic.api.skills.placeholders.PlaceholderString; +import io.lumine.mythic.bukkit.BukkitAdapter; +import io.lumine.mythic.bukkit.MythicBukkit; +import io.lumine.mythic.core.skills.SkillExecutor; +import io.lumine.mythic.core.skills.auras.Aura; +import io.lumine.mythic.utils.Events; import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.api.event.item.SpecialWeaponAttackEvent; import net.Indyuce.mmoitems.api.interaction.weapon.Gauntlet; @@ -24,22 +25,26 @@ import java.util.Optional; /** * Sure there is the 'onShoot' aura for bows, but what about * musket and crossbow and lute and...? - * + *

* This Aura will cover all of those. * * @author Gunging */ public class MMOItemsOnShootAura extends Aura implements ITargetedEntitySkill { - @NotNull PlaceholderString skillName; - @NotNull String weaponTypes; - @Nullable Skill metaskill; + @NotNull + PlaceholderString skillName; + @NotNull + String weaponTypes; + @Nullable + Skill metaskill; boolean cancelEvent; boolean forceAsPower; - @NotNull final ArrayList auraWeapons = new ArrayList<>(); + @NotNull + final ArrayList auraWeapons = new ArrayList<>(); - public MMOItemsOnShootAura(String skill, MythicLineConfig mlc) { - super(skill, mlc); + public MMOItemsOnShootAura(SkillExecutor manager, String skill, MythicLineConfig mlc) { + super(manager, skill, mlc); skillName = mlc.getPlaceholderString(new String[]{"skill", "s", "ondamagedskill", "ondamaged", "od", "onhitskill", "onhit", "oh", "meta", "m", "mechanics", "$", "()"}, "skill not found"); weaponTypes = mlc.getString(new String[]{"weapons", "weapon", "w"}, "MUSKET"); metaskill = GetSkill(skillName.get()); @@ -47,7 +52,11 @@ public class MMOItemsOnShootAura extends Aura implements ITargetedEntitySkill { // Parse weapon types ArrayList weaponTypesUnparsed = new ArrayList<>(); - if (weaponTypes.contains(",")) { weaponTypesUnparsed.addAll(Arrays.asList(weaponTypes.split(","))); } else { weaponTypesUnparsed.add(weaponTypes); } + if (weaponTypes.contains(",")) { + weaponTypesUnparsed.addAll(Arrays.asList(weaponTypes.split(","))); + } else { + weaponTypesUnparsed.add(weaponTypes); + } for (String weapon : weaponTypesUnparsed) { // Try to get @@ -59,7 +68,8 @@ public class MMOItemsOnShootAura extends Aura implements ITargetedEntitySkill { // Yes auraWeapons.add(weap); - } catch (IllegalArgumentException ignored) {} + } catch (IllegalArgumentException ignored) { + } } // Attempt to fix meta skill @@ -78,16 +88,16 @@ public class MMOItemsOnShootAura extends Aura implements ITargetedEntitySkill { } } - public boolean castAtEntity(SkillMetadata data, AbstractEntity target) { + public SkillResult castAtEntity(SkillMetadata data, AbstractEntity target) { // Find caster SkillCaster caster; // Will be caster of the skill, as a mythicmob - if (MythicMobs.inst().getMobManager().isActiveMob(target)) { + if (MythicBukkit.inst().getMobManager().isActiveMob(target)) { //SOM//OotilityCeption.Log("\u00a73 * \u00a77Target as ActiveMob"); // Just pull the mythicmob - caster = MythicMobs.inst().getMobManager().getMythicMobInstance(target); + caster = MythicBukkit.inst().getMobManager().getMythicMobInstance(target); // If its a player or some other non-mythicmob } else { @@ -98,10 +108,10 @@ public class MMOItemsOnShootAura extends Aura implements ITargetedEntitySkill { } new MMOItemsOnShootAura.Tracker(caster, data, target); - return true; + return SkillResult.SUCCESS; } - private class Tracker extends AuraTracker implements IParentSkill, Runnable { + private class Tracker extends Aura.AuraTracker implements IParentSkill, Runnable { public Tracker(SkillCaster caster, SkillMetadata data, AbstractEntity entity) { super(caster, entity, data); this.start(); @@ -113,14 +123,21 @@ public class MMOItemsOnShootAura extends Aura implements ITargetedEntitySkill { //SOM//OotilityCeption.Log("\u00a7cStep 3 \u00a77Subscribe Run: " + getName(event.getEntity()) + "\u00a77 vs " + getName(this.entity.get()) + "\u00a78 ~\u00a7e " + event.getEntity().getUniqueId().equals(this.entity.get().getUniqueId())); // Player is the one who has the aura applied, right? - if (!event.getPlayer().getUniqueId().equals(this.entity.get().getUniqueId())) { return false; } + if (!event.getPlayer().getUniqueId().equals(this.entity.get().getUniqueId())) { + return false; + } // All custom weapons fire it if none specified. - if (auraWeapons.size() == 0) { return true; } + if (auraWeapons.size() == 0) { + return true; + } // Okay go through all weapon types, must match one for (UseItemTypes weap : auraWeapons) { - if (weap.getInst().isInstance(event.getWeapon())) { return true; } } + if (weap.getInst().isInstance(event.getWeapon())) { + return true; + } + } // None matched return false; @@ -131,7 +148,9 @@ public class MMOItemsOnShootAura extends Aura implements ITargetedEntitySkill { SkillMetadata meta = this.skillMetadata.deepClone(); // Refresh - if (metaskill == null) { metaskill = GetSkill(skillName.get(meta, meta.getCaster().getEntity())); } + if (metaskill == null) { + metaskill = GetSkill(skillName.get(meta, meta.getCaster().getEntity())); + } // Target obviously the projectile AbstractEntity target = BukkitAdapter.adapt(event.getTarget()); @@ -142,7 +161,9 @@ public class MMOItemsOnShootAura extends Aura implements ITargetedEntitySkill { this.consumeCharge(); - if (cancelEvent) { event.setCancelled(true); } + if (cancelEvent) { + event.setCancelled(true); + } } })); @@ -150,22 +171,30 @@ public class MMOItemsOnShootAura extends Aura implements ITargetedEntitySkill { } } - @Nullable public static Skill GetSkill(String skillName) { + @Nullable + public static Skill GetSkill(String skillName) { if (SkillExists(skillName)) { - Optional mSkillFk = MythicMobs.inst().getSkillManager().getSkill(skillName); - if (mSkillFk == null) { return null; } - if (mSkillFk.isPresent()) { return mSkillFk.get(); } + Optional mSkillFk = MythicBukkit.inst().getSkillManager().getSkill(skillName); + if (mSkillFk == null) { + return null; + } + if (mSkillFk.isPresent()) { + return mSkillFk.get(); + } } return null; } + public static boolean SkillExists(String skillName) { // If null no - if (skillName == null) { return false; } + if (skillName == null) { + return false; + } - Optional mSkillFk = MythicMobs.inst().getSkillManager().getSkill(skillName); + Optional mSkillFk = MythicBukkit.inst().getSkillManager().getSkill(skillName); // Is there a skill of that name? if (mSkillFk.isPresent()) { @@ -202,8 +231,14 @@ public class MMOItemsOnShootAura extends Aura implements ITargetedEntitySkill { /** * @return Class to use InstanceOf and identify a weapon. */ - @NotNull public Class getInst() { return inst; } - @NotNull final Class inst; + @NotNull + public Class getInst() { + return inst; + } + + @NotNull + final Class inst; + UseItemTypes(@NotNull Class inst) { this.inst = inst; } diff --git a/src/main/java/net/Indyuce/mmoitems/comp/mythicmobs/stat/FactionDamage.java b/src/main/java/net/Indyuce/mmoitems/comp/mythicmobs/stat/FactionDamage.java index 3ae12354..645a3b6e 100644 --- a/src/main/java/net/Indyuce/mmoitems/comp/mythicmobs/stat/FactionDamage.java +++ b/src/main/java/net/Indyuce/mmoitems/comp/mythicmobs/stat/FactionDamage.java @@ -1,12 +1,12 @@ package net.Indyuce.mmoitems.comp.mythicmobs.stat; -import net.Indyuce.mmoitems.stat.type.DoubleStat; import io.lumine.mythic.lib.version.VersionMaterial; +import net.Indyuce.mmoitems.stat.type.DoubleStat; public class FactionDamage extends DoubleStat { public FactionDamage(String faction) { - super("FACTION_DAMAGE_" + faction.toUpperCase(), VersionMaterial.RED_DYE.toMaterial(), faction + " Faction Damage", new String[] { "Deals additional damage to mobs", "from the " + faction + " faction in %." }, new String[] { "!block", "all" }); + super("FACTION_DAMAGE_" + faction.toUpperCase(), VersionMaterial.RED_DYE.toMaterial(), faction + " Faction Damage", new String[]{"Deals additional damage to mobs", "from the " + faction + " faction in %."}, new String[]{"!block", "all"}); } }