From c908139609fe7cbcd18d8720c4743d03b3917c5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Szab=C3=B3?= Date: Thu, 4 Jul 2024 11:10:55 +0200 Subject: [PATCH 1/5] Add entity loot type --- .../api/event/loot/LootDropEvent.java | 25 +++++++++++ .../hooks/mythicmobs/MythicMobsHook.java | 5 +++ .../loot/MythicEntityLootParser.java | 19 ++++++++ .../mythicmobs/loot/MythicEntitySupplier.java | 34 +++++++++++++++ .../auraskills/bukkit/loot/LootLoader.java | 4 ++ .../auraskills/bukkit/loot/LootManager.java | 11 +++++ .../bukkit/loot/LootTableManager.java | 2 + .../bukkit/loot/entity/EntityProperties.java | 26 +++++++++++ .../bukkit/loot/entity/EntitySupplier.java | 20 +++++++++ .../loot/entity/VanillaEntityParser.java | 20 +++++++++ .../loot/entity/VanillaEntitySupplier.java | 43 +++++++++++++++++++ .../loot/handler/FishingLootHandler.java | 3 ++ .../bukkit/loot/handler/LootHandler.java | 34 +++++++++++++++ .../loot/parser/CustomEntityParser.java | 8 ++++ .../bukkit/loot/parser/CustomItemParser.java | 6 +-- .../bukkit/loot/parser/CustomParser.java | 7 +++ .../bukkit/loot/parser/EntityLootParser.java | 38 ++++++++++++++++ .../bukkit/loot/type/EntityLoot.java | 18 ++++++++ 18 files changed, 318 insertions(+), 5 deletions(-) create mode 100644 bukkit/src/main/java/dev/aurelium/auraskills/bukkit/hooks/mythicmobs/loot/MythicEntityLootParser.java create mode 100644 bukkit/src/main/java/dev/aurelium/auraskills/bukkit/hooks/mythicmobs/loot/MythicEntitySupplier.java create mode 100644 bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/entity/EntityProperties.java create mode 100644 bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/entity/EntitySupplier.java create mode 100644 bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/entity/VanillaEntityParser.java create mode 100644 bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/entity/VanillaEntitySupplier.java create mode 100644 bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/parser/CustomEntityParser.java create mode 100644 bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/parser/CustomParser.java create mode 100644 bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/parser/EntityLootParser.java create mode 100644 bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/type/EntityLoot.java diff --git a/api-bukkit/src/main/java/dev/aurelium/auraskills/api/event/loot/LootDropEvent.java b/api-bukkit/src/main/java/dev/aurelium/auraskills/api/event/loot/LootDropEvent.java index ee3072e50..f74523aa8 100644 --- a/api-bukkit/src/main/java/dev/aurelium/auraskills/api/event/loot/LootDropEvent.java +++ b/api-bukkit/src/main/java/dev/aurelium/auraskills/api/event/loot/LootDropEvent.java @@ -2,12 +2,15 @@ import dev.aurelium.auraskills.api.user.SkillsUser; import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * Called when AuraSkills drops extra loot from mechanics like Fishing, Luck, and custom loot tables. @@ -22,6 +25,7 @@ public class LootDropEvent extends Event implements Cancellable { private Location location; private final Cause cause; private boolean toInventory; + private Entity entity; private boolean cancelled = false; public LootDropEvent(Player player, SkillsUser user, ItemStack item, Location location, Cause cause, boolean toInventory) { @@ -33,6 +37,26 @@ public LootDropEvent(Player player, SkillsUser user, ItemStack item, Location lo this.toInventory = toInventory; } + public LootDropEvent(Player player, SkillsUser user, Entity entity, Location location, Cause cause) { + this.player = player; + this.user = user; + this.location = location; + this.cause = cause; + this.toInventory = false; + this.entity = entity; + // Let's not break things and make the item not nullable still + this.item = new ItemStack(Material.AIR); + } + + /** + * Gets the spawned entity if the loot was an entity. + * + * @return the entity + */ + public @Nullable Entity getEntity() { + return entity; + } + /** * Gets the player that caused the loot drop. * @@ -53,6 +77,7 @@ public SkillsUser getUser() { /** * Gets the item that will be dropped by the event. + * If the drop is an entity, this will be AIR. * * @return the item */ diff --git a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/hooks/mythicmobs/MythicMobsHook.java b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/hooks/mythicmobs/MythicMobsHook.java index 4664aea98..57bd8937d 100644 --- a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/hooks/mythicmobs/MythicMobsHook.java +++ b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/hooks/mythicmobs/MythicMobsHook.java @@ -4,6 +4,7 @@ import dev.aurelium.auraskills.bukkit.AuraSkills; import dev.aurelium.auraskills.bukkit.damage.DamageHandler; import dev.aurelium.auraskills.bukkit.damage.DamageResult; +import dev.aurelium.auraskills.bukkit.hooks.mythicmobs.loot.MythicEntityLootParser; import dev.aurelium.auraskills.common.hooks.Hook; import dev.aurelium.auraskills.api.damage.DamageType; import io.lumine.mythic.api.adapters.AbstractEntity; @@ -30,6 +31,10 @@ public MythicMobsHook(AuraSkills plugin, ConfigurationNode config) { super(plugin, config); this.plugin = plugin; this.damageHandler = new DamageHandler(); + + // Wait for loot manager to be created, but add parser before it is loaded + plugin.getScheduler().executeSync(() -> + plugin.getLootTableManager().getLootManager().registerCustomEntityParser(new MythicEntityLootParser())); } @EventHandler(priority = EventPriority.HIGH) diff --git a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/hooks/mythicmobs/loot/MythicEntityLootParser.java b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/hooks/mythicmobs/loot/MythicEntityLootParser.java new file mode 100644 index 000000000..c05a9801f --- /dev/null +++ b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/hooks/mythicmobs/loot/MythicEntityLootParser.java @@ -0,0 +1,19 @@ +package dev.aurelium.auraskills.bukkit.hooks.mythicmobs.loot; + +import dev.aurelium.auraskills.bukkit.loot.entity.EntityProperties; +import dev.aurelium.auraskills.bukkit.loot.entity.EntitySupplier; +import dev.aurelium.auraskills.bukkit.loot.parser.CustomEntityParser; +import org.spongepowered.configurate.ConfigurationNode; + +public class MythicEntityLootParser implements CustomEntityParser { + + @Override + public EntitySupplier getEntitySupplier(ConfigurationNode config) { + return new MythicEntitySupplier(EntityProperties.fromConfig(config)); + } + + @Override + public boolean shouldUseParser(ConfigurationNode config) { + return config.node("entity").getString().startsWith("mythicmobs:"); + } +} diff --git a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/hooks/mythicmobs/loot/MythicEntitySupplier.java b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/hooks/mythicmobs/loot/MythicEntitySupplier.java new file mode 100644 index 000000000..ccbec7744 --- /dev/null +++ b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/hooks/mythicmobs/loot/MythicEntitySupplier.java @@ -0,0 +1,34 @@ +package dev.aurelium.auraskills.bukkit.hooks.mythicmobs.loot; + +import dev.aurelium.auraskills.bukkit.AuraSkills; +import dev.aurelium.auraskills.bukkit.loot.entity.EntityProperties; +import dev.aurelium.auraskills.bukkit.loot.entity.EntitySupplier; +import io.lumine.mythic.bukkit.BukkitAdapter; +import io.lumine.mythic.bukkit.MythicBukkit; +import io.lumine.mythic.core.mobs.ActiveMob; +import org.bukkit.Location; +import org.bukkit.entity.Entity; + +public class MythicEntitySupplier extends EntitySupplier { + public MythicEntitySupplier(EntityProperties entityProperties) { + super(entityProperties); + } + + @Override + public Entity spawnEntity(AuraSkills plugin, Location location) { + ActiveMob activeMob; + + if(getEntityProperties().level() != null) { + activeMob = MythicBukkit.inst().getMobManager().spawnMob(getEntityProperties().entityId(), location, getEntityProperties().level()); + } else { + activeMob = MythicBukkit.inst().getMobManager().spawnMob(getEntityProperties().entityId(), location); + } + + return BukkitAdapter.adapt(activeMob.getEntity()); + } + + @Override + public void removeEntity(Entity entity) { + MythicBukkit.inst().getMobManager().getActiveMob(entity.getUniqueId()).ifPresent(ActiveMob::remove); + } +} diff --git a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/LootLoader.java b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/LootLoader.java index 3512470bf..75804c441 100644 --- a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/LootLoader.java +++ b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/LootLoader.java @@ -3,6 +3,7 @@ import dev.aurelium.auraskills.api.loot.*; import dev.aurelium.auraskills.api.registry.NamespacedId; import dev.aurelium.auraskills.bukkit.loot.parser.CommandLootParser; +import dev.aurelium.auraskills.bukkit.loot.parser.EntityLootParser; import dev.aurelium.auraskills.bukkit.loot.parser.ItemLootParser; import dev.aurelium.auraskills.bukkit.loot.parser.LootParsingContextImpl; import dev.aurelium.auraskills.bukkit.util.VersionUtils; @@ -70,6 +71,9 @@ public LootTable loadLootTable(NamespacedId id, File file, ConfigurationNode con // Command loot else if (lootType.equalsIgnoreCase("command")) { loot = new CommandLootParser().parse(context, lootNode); + // Entity loot, mainly for fishing + } else if (lootType.equalsIgnoreCase("entity")) { + loot = new EntityLootParser(manager).parse(context, lootNode); } else { // Parse custom loot registered from API LootParser customParser = manager.getCustomLootParsers().get(lootType); diff --git a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/LootManager.java b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/LootManager.java index d3692c1a2..b4e76da91 100644 --- a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/LootManager.java +++ b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/LootManager.java @@ -3,6 +3,7 @@ import dev.aurelium.auraskills.api.loot.LootParser; import dev.aurelium.auraskills.bukkit.AuraSkills; import dev.aurelium.auraskills.bukkit.loot.context.ContextProvider; +import dev.aurelium.auraskills.bukkit.loot.parser.CustomEntityParser; import dev.aurelium.auraskills.bukkit.loot.parser.CustomItemParser; import org.jetbrains.annotations.Nullable; @@ -16,6 +17,7 @@ public class LootManager { private final Set lootOptionKeys; private final Set poolOptionKeys; private final List customItemParsers; + private final List customEntityParsers; private final Map customLootParsers; public LootManager(AuraSkills plugin) { @@ -24,6 +26,7 @@ public LootManager(AuraSkills plugin) { this.contextProviders = new HashMap<>(); this.lootOptionKeys = new HashSet<>(); this.poolOptionKeys = new HashSet<>(); + this.customEntityParsers = new ArrayList<>(); this.customItemParsers = new ArrayList<>(); this.customLootParsers = new HashMap<>(); } @@ -77,10 +80,18 @@ public List getCustomItemParsers() { return customItemParsers; } + public List getCustomEntityParsers() { + return customEntityParsers; + } + public void registerCustomItemParser(CustomItemParser customItemParser) { customItemParsers.add(customItemParser); } + public void registerCustomEntityParser(CustomEntityParser customEntityParser) { + customEntityParsers.add(customEntityParser); + } + public Map getCustomLootParsers() { return customLootParsers; } diff --git a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/LootTableManager.java b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/LootTableManager.java index 2e0833896..9d1e189fd 100644 --- a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/LootTableManager.java +++ b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/LootTableManager.java @@ -8,6 +8,7 @@ import dev.aurelium.auraskills.bukkit.AuraSkills; import dev.aurelium.auraskills.bukkit.loot.context.MobContextProvider; import dev.aurelium.auraskills.bukkit.loot.context.SourceContextProvider; +import dev.aurelium.auraskills.bukkit.loot.entity.VanillaEntityParser; import dev.aurelium.auraskills.bukkit.util.ItemUtils; import dev.aurelium.auraskills.common.api.ApiAuraSkills; import dev.aurelium.auraskills.common.config.ConfigurateLoader; @@ -44,6 +45,7 @@ public void initLootManager() { lootManager.registerContextProvider(new SourceContextProvider(plugin)); lootManager.registerContextProvider(new MobContextProvider()); lootManager.registerCustomItemParser(new ItemKeyParser(plugin)); + lootManager.registerCustomEntityParser(new VanillaEntityParser()); lootManager.addLootOptionKeys("xp"); lootManager.addPoolOptionKeys("chance_per_luck", "require_open_water"); } diff --git a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/entity/EntityProperties.java b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/entity/EntityProperties.java new file mode 100644 index 000000000..8b6ceb51e --- /dev/null +++ b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/entity/EntityProperties.java @@ -0,0 +1,26 @@ +package dev.aurelium.auraskills.bukkit.loot.entity; + +import org.spongepowered.configurate.ConfigurationNode; + +public record EntityProperties(String entityId, + String name, + Integer level, + Double health, + Double damage, + Float horizontalVelocity, + Float verticalVelocity) { + + public static EntityProperties fromConfig(ConfigurationNode config) { + String[] id = config.node("entity").getString().split(":"); + + return new EntityProperties( + id.length > 1 ? id[1] : id[0], + config.node("name").getString(), + config.node("level").empty() ? null :config.node("level").getInt(), + config.node("health").empty() ? null : config.node("health").getDouble(), + config.node("damage").empty() ? null :config.node("damage").getDouble(), + config.node("velocity", "horizontal").empty() ? null : config.node("velocity", "horizontal").getFloat(), + config.node("velocity", "vertical").empty() ? null : config.node("velocity", "vertical").getFloat() + ); + } +} diff --git a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/entity/EntitySupplier.java b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/entity/EntitySupplier.java new file mode 100644 index 000000000..2749532e1 --- /dev/null +++ b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/entity/EntitySupplier.java @@ -0,0 +1,20 @@ +package dev.aurelium.auraskills.bukkit.loot.entity; + +import dev.aurelium.auraskills.bukkit.AuraSkills; +import org.bukkit.Location; +import org.bukkit.entity.Entity; + +public abstract class EntitySupplier { + private final EntityProperties entityProperties; + + public EntitySupplier(EntityProperties entityProperties) { + this.entityProperties = entityProperties; + } + + public abstract Entity spawnEntity(AuraSkills plugin, Location location); + public abstract void removeEntity(Entity entity); + + public EntityProperties getEntityProperties() { + return entityProperties; + } +} diff --git a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/entity/VanillaEntityParser.java b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/entity/VanillaEntityParser.java new file mode 100644 index 000000000..eb9cf59b2 --- /dev/null +++ b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/entity/VanillaEntityParser.java @@ -0,0 +1,20 @@ +package dev.aurelium.auraskills.bukkit.loot.entity; + +import dev.aurelium.auraskills.bukkit.loot.parser.CustomEntityParser; +import org.spongepowered.configurate.ConfigurationNode; + +public class VanillaEntityParser implements CustomEntityParser { + @Override + public EntitySupplier getEntitySupplier(ConfigurationNode config) { + return new VanillaEntitySupplier(EntityProperties.fromConfig(config)); + } + + @Override + public boolean shouldUseParser(ConfigurationNode config) { + String entity = config.node("entity").getString(); + + // If it has a colon, it's a custom entity + // But if it starts with minecraft:, it's a vanilla entity stated explicitly + return !entity.contains(":") || config.node("entity").getString().startsWith("minecraft:"); + } +} diff --git a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/entity/VanillaEntitySupplier.java b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/entity/VanillaEntitySupplier.java new file mode 100644 index 000000000..f4ee49c3b --- /dev/null +++ b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/entity/VanillaEntitySupplier.java @@ -0,0 +1,43 @@ +package dev.aurelium.auraskills.bukkit.loot.entity; + +import dev.aurelium.auraskills.bukkit.AuraSkills; +import org.bukkit.Location; +import org.bukkit.attribute.Attribute; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.LivingEntity; + +public class VanillaEntitySupplier extends EntitySupplier { + + public VanillaEntitySupplier(EntityProperties entityProperties) { + super(entityProperties); + } + + @Override + public Entity spawnEntity(AuraSkills plugin, Location location) { + Entity entity = location.getWorld().spawnEntity(location, EntityType.valueOf(getEntityProperties().entityId().toUpperCase())); + + if (entity instanceof LivingEntity livingEntity) { + if (getEntityProperties().health() != null) { + livingEntity.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(getEntityProperties().health()); + livingEntity.setHealth(getEntityProperties().health()); + } + if (getEntityProperties().damage() != null) { + livingEntity.getAttribute(Attribute.GENERIC_ATTACK_DAMAGE).setBaseValue(getEntityProperties().damage()); + } + } + + if (getEntityProperties().name() != null) { + entity.setCustomName(plugin.getMessageProvider().applyFormatting(getEntityProperties().name())); + entity.setCustomNameVisible(true); + } + + + return entity; + } + + @Override + public void removeEntity(Entity entity) { + entity.remove(); + } +} diff --git a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/handler/FishingLootHandler.java b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/handler/FishingLootHandler.java index a8398bf82..8cbd41469 100644 --- a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/handler/FishingLootHandler.java +++ b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/handler/FishingLootHandler.java @@ -15,6 +15,7 @@ import dev.aurelium.auraskills.api.loot.LootTable; import dev.aurelium.auraskills.bukkit.loot.context.SourceContext; import dev.aurelium.auraskills.bukkit.loot.type.CommandLoot; +import dev.aurelium.auraskills.bukkit.loot.type.EntityLoot; import dev.aurelium.auraskills.bukkit.loot.type.ItemLoot; import dev.aurelium.auraskills.bukkit.source.FishingLeveler; import dev.aurelium.auraskills.bukkit.util.VersionUtils; @@ -103,6 +104,8 @@ public void onFish(PlayerFishEvent event) { giveFishingItemLoot(player, itemLoot, event, source, skill, cause, table); } else if (selectedLoot instanceof CommandLoot commandLoot) { giveCommandLoot(player, commandLoot, source, skill); + } else if (selectedLoot instanceof EntityLoot entityLoot) { + giveFishingEntityLoot(player, entityLoot, event, source, skill, cause, table); } break; // Stop iterating pools } diff --git a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/handler/LootHandler.java b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/handler/LootHandler.java index d34eb5363..0a8619956 100644 --- a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/handler/LootHandler.java +++ b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/handler/LootHandler.java @@ -15,6 +15,7 @@ import dev.aurelium.auraskills.bukkit.loot.context.MobContext; import dev.aurelium.auraskills.bukkit.loot.context.SourceContext; import dev.aurelium.auraskills.bukkit.loot.type.CommandLoot; +import dev.aurelium.auraskills.bukkit.loot.type.EntityLoot; import dev.aurelium.auraskills.bukkit.loot.type.ItemLoot; import dev.aurelium.auraskills.bukkit.util.ItemUtils; import dev.aurelium.auraskills.common.commands.CommandExecutor; @@ -26,9 +27,12 @@ import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.block.Block; +import org.bukkit.entity.Entity; import org.bukkit.entity.Item; import org.bukkit.entity.Player; +import org.bukkit.util.Vector; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.player.PlayerFishEvent; import org.bukkit.inventory.ItemStack; @@ -116,6 +120,36 @@ protected void giveFishingItemLoot(Player player, ItemLoot loot, PlayerFishEvent giveXp(player, loot, source, skill); } + protected void giveFishingEntityLoot(Player player, EntityLoot loot, PlayerFishEvent event, @Nullable XpSource source, Skill skill, LootDropEvent.Cause cause, LootTable table) { + if (!(event.getCaught() instanceof Item itemEntity)) return; + + Location location = event.getHook().getLocation(); + Entity entity = loot.getEntity().spawnEntity(plugin, event.getHook().getLocation()); + + LootDropEvent dropEvent = new LootDropEvent(player, plugin.getUser(player).toApi(), entity, event.getHook().getLocation(), cause); + Bukkit.getPluginManager().callEvent(dropEvent); + + if (dropEvent.isCancelled()) { + loot.getEntity().removeEntity(entity); + return; + } + + itemEntity.setItemStack(new ItemStack(Material.AIR)); + + Float hVelocity = loot.getEntity().getEntityProperties().horizontalVelocity(); + if(hVelocity == null) hVelocity = 1.2f; + + Float vVelocity = loot.getEntity().getEntityProperties().verticalVelocity(); + if(vVelocity == null) vVelocity = 1.3f; + + Vector vector = player.getLocation().subtract(location).toVector().multiply(hVelocity - 1); + vector.setY((vector.getY() + 0.2) * vVelocity); + entity.setVelocity(vector); + + attemptSendMessage(player, loot); + giveXp(player, loot, source, skill); + } + @Nullable protected Loot selectLoot(LootPool pool, @NotNull LootContext providedContext) { return pool.rollLoot(loot -> { diff --git a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/parser/CustomEntityParser.java b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/parser/CustomEntityParser.java new file mode 100644 index 000000000..e64e2f55d --- /dev/null +++ b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/parser/CustomEntityParser.java @@ -0,0 +1,8 @@ +package dev.aurelium.auraskills.bukkit.loot.parser; + +import dev.aurelium.auraskills.bukkit.loot.entity.EntitySupplier; +import org.spongepowered.configurate.ConfigurationNode; + +public interface CustomEntityParser extends CustomParser { + EntitySupplier getEntitySupplier(ConfigurationNode config); +} diff --git a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/parser/CustomItemParser.java b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/parser/CustomItemParser.java index 392a77f41..73790e86a 100644 --- a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/parser/CustomItemParser.java +++ b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/parser/CustomItemParser.java @@ -3,10 +3,6 @@ import org.bukkit.inventory.ItemStack; import org.spongepowered.configurate.ConfigurationNode; -public interface CustomItemParser { - - boolean shouldUseParser(ConfigurationNode config); - +public interface CustomItemParser extends CustomParser { ItemStack parseCustomItem(ConfigurationNode config); - } diff --git a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/parser/CustomParser.java b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/parser/CustomParser.java new file mode 100644 index 000000000..8aad997c1 --- /dev/null +++ b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/parser/CustomParser.java @@ -0,0 +1,7 @@ +package dev.aurelium.auraskills.bukkit.loot.parser; + +import org.spongepowered.configurate.ConfigurationNode; + +public interface CustomParser { + boolean shouldUseParser(ConfigurationNode config); +} diff --git a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/parser/EntityLootParser.java b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/parser/EntityLootParser.java new file mode 100644 index 000000000..f208b881e --- /dev/null +++ b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/parser/EntityLootParser.java @@ -0,0 +1,38 @@ +package dev.aurelium.auraskills.bukkit.loot.parser; + +import dev.aurelium.auraskills.api.loot.Loot; +import dev.aurelium.auraskills.api.loot.LootParser; +import dev.aurelium.auraskills.api.loot.LootParsingContext; +import dev.aurelium.auraskills.bukkit.loot.LootManager; +import dev.aurelium.auraskills.bukkit.loot.entity.EntitySupplier; +import dev.aurelium.auraskills.bukkit.loot.type.EntityLoot; +import dev.aurelium.auraskills.common.util.data.Validate; +import org.spongepowered.configurate.ConfigurationNode; +import org.spongepowered.configurate.serialize.SerializationException; + + +public class EntityLootParser implements LootParser { + protected final LootManager manager; + + public EntityLootParser(LootManager manager) { + this.manager = manager; + } + + @Override + public Loot parse(LootParsingContext context, ConfigurationNode config) throws SerializationException { + String entityType = config.node("entity").getString(); + Validate.notNull(entityType, "Entity loot must specify an entity type"); + + EntitySupplier entity = null; + for (CustomEntityParser parser : manager.getCustomEntityParsers()) { + if (parser.shouldUseParser(config)) { + entity = parser.getEntitySupplier(config); + break; + } + } + + Validate.notNull(entity, "Couldn't parse entity loot with entity type: " + entityType); + + return new EntityLoot(context.parseValues(config), entity); + } +} diff --git a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/type/EntityLoot.java b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/type/EntityLoot.java new file mode 100644 index 000000000..0c2168c92 --- /dev/null +++ b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/type/EntityLoot.java @@ -0,0 +1,18 @@ +package dev.aurelium.auraskills.bukkit.loot.type; + +import dev.aurelium.auraskills.api.loot.Loot; +import dev.aurelium.auraskills.api.loot.LootValues; +import dev.aurelium.auraskills.bukkit.loot.entity.EntitySupplier; + +public class EntityLoot extends Loot { + private final EntitySupplier entity; + + public EntityLoot(LootValues values, EntitySupplier entity) { + super(values); + this.entity = entity; + } + + public EntitySupplier getEntity() { + return entity; + } +} From 4f14d666f55bd9793aa206d4d6d7309ad87a380f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Szab=C3=B3?= Date: Thu, 4 Jul 2024 11:17:08 +0200 Subject: [PATCH 2/5] Fix code formatting --- .../bukkit/hooks/mythicmobs/loot/MythicEntitySupplier.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/hooks/mythicmobs/loot/MythicEntitySupplier.java b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/hooks/mythicmobs/loot/MythicEntitySupplier.java index ccbec7744..cd15eb13d 100644 --- a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/hooks/mythicmobs/loot/MythicEntitySupplier.java +++ b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/hooks/mythicmobs/loot/MythicEntitySupplier.java @@ -18,7 +18,7 @@ public MythicEntitySupplier(EntityProperties entityProperties) { public Entity spawnEntity(AuraSkills plugin, Location location) { ActiveMob activeMob; - if(getEntityProperties().level() != null) { + if (getEntityProperties().level() != null) { activeMob = MythicBukkit.inst().getMobManager().spawnMob(getEntityProperties().entityId(), location, getEntityProperties().level()); } else { activeMob = MythicBukkit.inst().getMobManager().spawnMob(getEntityProperties().entityId(), location); From b59b08def093462bdb6e5b0208543656ea007760 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Szab=C3=B3?= Date: Fri, 5 Jul 2024 09:02:07 +0200 Subject: [PATCH 3/5] Add level property to entity metadata for better 3rd party integration --- .../bukkit/loot/entity/VanillaEntitySupplier.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/entity/VanillaEntitySupplier.java b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/entity/VanillaEntitySupplier.java index f4ee49c3b..e82cfed7d 100644 --- a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/entity/VanillaEntitySupplier.java +++ b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/entity/VanillaEntitySupplier.java @@ -2,10 +2,14 @@ import dev.aurelium.auraskills.bukkit.AuraSkills; import org.bukkit.Location; +import org.bukkit.NamespacedKey; import org.bukkit.attribute.Attribute; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.LivingEntity; +import org.bukkit.metadata.FixedMetadataValue; +import org.bukkit.metadata.MetadataValue; +import org.bukkit.persistence.PersistentDataType; public class VanillaEntitySupplier extends EntitySupplier { @@ -32,6 +36,9 @@ public Entity spawnEntity(AuraSkills plugin, Location location) { entity.setCustomNameVisible(true); } + if (getEntityProperties().level() != null) { + entity.setMetadata("aura_skills_level", new FixedMetadataValue(plugin, getEntityProperties().level())); + } return entity; } From 6ebc1fb3477b3985483f0f75fb0af94ab7d57e79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Szab=C3=B3?= Date: Fri, 5 Jul 2024 09:13:51 +0200 Subject: [PATCH 4/5] Added code format changes --- .../bukkit/hooks/mythicmobs/loot/MythicEntitySupplier.java | 1 + .../auraskills/bukkit/loot/entity/EntityProperties.java | 4 ++-- .../auraskills/bukkit/loot/entity/EntitySupplier.java | 2 ++ .../auraskills/bukkit/loot/entity/VanillaEntitySupplier.java | 5 +---- .../aurelium/auraskills/bukkit/loot/handler/LootHandler.java | 4 ++-- .../auraskills/bukkit/loot/parser/EntityLootParser.java | 1 + .../dev/aurelium/auraskills/bukkit/loot/type/EntityLoot.java | 1 + 7 files changed, 10 insertions(+), 8 deletions(-) diff --git a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/hooks/mythicmobs/loot/MythicEntitySupplier.java b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/hooks/mythicmobs/loot/MythicEntitySupplier.java index cd15eb13d..934b67b14 100644 --- a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/hooks/mythicmobs/loot/MythicEntitySupplier.java +++ b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/hooks/mythicmobs/loot/MythicEntitySupplier.java @@ -10,6 +10,7 @@ import org.bukkit.entity.Entity; public class MythicEntitySupplier extends EntitySupplier { + public MythicEntitySupplier(EntityProperties entityProperties) { super(entityProperties); } diff --git a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/entity/EntityProperties.java b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/entity/EntityProperties.java index 8b6ceb51e..95918fb9e 100644 --- a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/entity/EntityProperties.java +++ b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/entity/EntityProperties.java @@ -16,9 +16,9 @@ public static EntityProperties fromConfig(ConfigurationNode config) { return new EntityProperties( id.length > 1 ? id[1] : id[0], config.node("name").getString(), - config.node("level").empty() ? null :config.node("level").getInt(), + config.node("level").empty() ? null : config.node("level").getInt(), config.node("health").empty() ? null : config.node("health").getDouble(), - config.node("damage").empty() ? null :config.node("damage").getDouble(), + config.node("damage").empty() ? null : config.node("damage").getDouble(), config.node("velocity", "horizontal").empty() ? null : config.node("velocity", "horizontal").getFloat(), config.node("velocity", "vertical").empty() ? null : config.node("velocity", "vertical").getFloat() ); diff --git a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/entity/EntitySupplier.java b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/entity/EntitySupplier.java index 2749532e1..8bd3fe448 100644 --- a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/entity/EntitySupplier.java +++ b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/entity/EntitySupplier.java @@ -5,6 +5,7 @@ import org.bukkit.entity.Entity; public abstract class EntitySupplier { + private final EntityProperties entityProperties; public EntitySupplier(EntityProperties entityProperties) { @@ -12,6 +13,7 @@ public EntitySupplier(EntityProperties entityProperties) { } public abstract Entity spawnEntity(AuraSkills plugin, Location location); + public abstract void removeEntity(Entity entity); public EntityProperties getEntityProperties() { diff --git a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/entity/VanillaEntitySupplier.java b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/entity/VanillaEntitySupplier.java index e82cfed7d..56c9086a7 100644 --- a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/entity/VanillaEntitySupplier.java +++ b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/entity/VanillaEntitySupplier.java @@ -2,14 +2,11 @@ import dev.aurelium.auraskills.bukkit.AuraSkills; import org.bukkit.Location; -import org.bukkit.NamespacedKey; import org.bukkit.attribute.Attribute; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.LivingEntity; import org.bukkit.metadata.FixedMetadataValue; -import org.bukkit.metadata.MetadataValue; -import org.bukkit.persistence.PersistentDataType; public class VanillaEntitySupplier extends EntitySupplier { @@ -37,7 +34,7 @@ public Entity spawnEntity(AuraSkills plugin, Location location) { } if (getEntityProperties().level() != null) { - entity.setMetadata("aura_skills_level", new FixedMetadataValue(plugin, getEntityProperties().level())); + entity.setMetadata("auraskills_level", new FixedMetadataValue(plugin, getEntityProperties().level())); } return entity; diff --git a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/handler/LootHandler.java b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/handler/LootHandler.java index 0a8619956..a33787009 100644 --- a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/handler/LootHandler.java +++ b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/handler/LootHandler.java @@ -137,10 +137,10 @@ protected void giveFishingEntityLoot(Player player, EntityLoot loot, PlayerFishE itemEntity.setItemStack(new ItemStack(Material.AIR)); Float hVelocity = loot.getEntity().getEntityProperties().horizontalVelocity(); - if(hVelocity == null) hVelocity = 1.2f; + if (hVelocity == null) hVelocity = 1.2f; Float vVelocity = loot.getEntity().getEntityProperties().verticalVelocity(); - if(vVelocity == null) vVelocity = 1.3f; + if (vVelocity == null) vVelocity = 1.3f; Vector vector = player.getLocation().subtract(location).toVector().multiply(hVelocity - 1); vector.setY((vector.getY() + 0.2) * vVelocity); diff --git a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/parser/EntityLootParser.java b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/parser/EntityLootParser.java index f208b881e..eccfd79f3 100644 --- a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/parser/EntityLootParser.java +++ b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/parser/EntityLootParser.java @@ -12,6 +12,7 @@ public class EntityLootParser implements LootParser { + protected final LootManager manager; public EntityLootParser(LootManager manager) { diff --git a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/type/EntityLoot.java b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/type/EntityLoot.java index 0c2168c92..deb3acd16 100644 --- a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/type/EntityLoot.java +++ b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/type/EntityLoot.java @@ -5,6 +5,7 @@ import dev.aurelium.auraskills.bukkit.loot.entity.EntitySupplier; public class EntityLoot extends Loot { + private final EntitySupplier entity; public EntityLoot(LootValues values, EntitySupplier entity) { From 10208152e85218a834c4a2bda691a741dfcbf516 Mon Sep 17 00:00:00 2001 From: Archy-X <63976867+Archy-X@users.noreply.github.com> Date: Fri, 5 Jul 2024 21:49:05 -0700 Subject: [PATCH 5/5] Fix null safety warnings and format --- .../loot/MythicEntityLootParser.java | 2 +- .../bukkit/loot/entity/EntityProperties.java | 2 +- .../loot/entity/VanillaEntityParser.java | 5 ++++- .../loot/entity/VanillaEntitySupplier.java | 19 +++++++++++++++---- .../loot/handler/FishingLootHandler.java | 2 +- .../bukkit/loot/handler/LootHandler.java | 4 +++- .../loot/parser/CustomEntityParser.java | 2 ++ .../bukkit/loot/parser/CustomItemParser.java | 2 ++ .../bukkit/loot/parser/CustomParser.java | 2 ++ .../bukkit/loot/parser/EntityLootParser.java | 1 - 10 files changed, 31 insertions(+), 10 deletions(-) diff --git a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/hooks/mythicmobs/loot/MythicEntityLootParser.java b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/hooks/mythicmobs/loot/MythicEntityLootParser.java index c05a9801f..cd4e8d20a 100644 --- a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/hooks/mythicmobs/loot/MythicEntityLootParser.java +++ b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/hooks/mythicmobs/loot/MythicEntityLootParser.java @@ -14,6 +14,6 @@ public EntitySupplier getEntitySupplier(ConfigurationNode config) { @Override public boolean shouldUseParser(ConfigurationNode config) { - return config.node("entity").getString().startsWith("mythicmobs:"); + return config.node("entity").getString("").startsWith("mythicmobs:"); } } diff --git a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/entity/EntityProperties.java b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/entity/EntityProperties.java index 95918fb9e..633a1b717 100644 --- a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/entity/EntityProperties.java +++ b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/entity/EntityProperties.java @@ -11,7 +11,7 @@ public record EntityProperties(String entityId, Float verticalVelocity) { public static EntityProperties fromConfig(ConfigurationNode config) { - String[] id = config.node("entity").getString().split(":"); + String[] id = config.node("entity").getString("").split(":"); return new EntityProperties( id.length > 1 ? id[1] : id[0], diff --git a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/entity/VanillaEntityParser.java b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/entity/VanillaEntityParser.java index eb9cf59b2..ac1c8c91e 100644 --- a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/entity/VanillaEntityParser.java +++ b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/entity/VanillaEntityParser.java @@ -4,6 +4,7 @@ import org.spongepowered.configurate.ConfigurationNode; public class VanillaEntityParser implements CustomEntityParser { + @Override public EntitySupplier getEntitySupplier(ConfigurationNode config) { return new VanillaEntitySupplier(EntityProperties.fromConfig(config)); @@ -13,8 +14,10 @@ public EntitySupplier getEntitySupplier(ConfigurationNode config) { public boolean shouldUseParser(ConfigurationNode config) { String entity = config.node("entity").getString(); + if (entity == null) return false; + // If it has a colon, it's a custom entity // But if it starts with minecraft:, it's a vanilla entity stated explicitly - return !entity.contains(":") || config.node("entity").getString().startsWith("minecraft:"); + return !entity.contains(":") || entity.startsWith("minecraft:"); } } diff --git a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/entity/VanillaEntitySupplier.java b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/entity/VanillaEntitySupplier.java index 56c9086a7..6580a060b 100644 --- a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/entity/VanillaEntitySupplier.java +++ b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/entity/VanillaEntitySupplier.java @@ -2,7 +2,9 @@ import dev.aurelium.auraskills.bukkit.AuraSkills; import org.bukkit.Location; +import org.bukkit.World; import org.bukkit.attribute.Attribute; +import org.bukkit.attribute.AttributeInstance; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.LivingEntity; @@ -16,15 +18,24 @@ public VanillaEntitySupplier(EntityProperties entityProperties) { @Override public Entity spawnEntity(AuraSkills plugin, Location location) { - Entity entity = location.getWorld().spawnEntity(location, EntityType.valueOf(getEntityProperties().entityId().toUpperCase())); + World world = location.getWorld(); + if (world == null) return null; + + Entity entity = world.spawnEntity(location, EntityType.valueOf(getEntityProperties().entityId().toUpperCase())); if (entity instanceof LivingEntity livingEntity) { if (getEntityProperties().health() != null) { - livingEntity.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(getEntityProperties().health()); - livingEntity.setHealth(getEntityProperties().health()); + AttributeInstance attribute = livingEntity.getAttribute(Attribute.GENERIC_MAX_HEALTH); + if (attribute != null) { + attribute.setBaseValue(getEntityProperties().health()); + livingEntity.setHealth(Math.min(getEntityProperties().health(), attribute.getValue())); + } } if (getEntityProperties().damage() != null) { - livingEntity.getAttribute(Attribute.GENERIC_ATTACK_DAMAGE).setBaseValue(getEntityProperties().damage()); + AttributeInstance attribute = livingEntity.getAttribute(Attribute.GENERIC_ATTACK_DAMAGE); + if (attribute != null) { + attribute.setBaseValue(getEntityProperties().damage()); + } } } diff --git a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/handler/FishingLootHandler.java b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/handler/FishingLootHandler.java index 8cbd41469..9df92261a 100644 --- a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/handler/FishingLootHandler.java +++ b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/handler/FishingLootHandler.java @@ -105,7 +105,7 @@ public void onFish(PlayerFishEvent event) { } else if (selectedLoot instanceof CommandLoot commandLoot) { giveCommandLoot(player, commandLoot, source, skill); } else if (selectedLoot instanceof EntityLoot entityLoot) { - giveFishingEntityLoot(player, entityLoot, event, source, skill, cause, table); + giveFishingEntityLoot(player, entityLoot, event, source, skill, cause); } break; // Stop iterating pools } diff --git a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/handler/LootHandler.java b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/handler/LootHandler.java index a33787009..3808609d1 100644 --- a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/handler/LootHandler.java +++ b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/handler/LootHandler.java @@ -120,12 +120,14 @@ protected void giveFishingItemLoot(Player player, ItemLoot loot, PlayerFishEvent giveXp(player, loot, source, skill); } - protected void giveFishingEntityLoot(Player player, EntityLoot loot, PlayerFishEvent event, @Nullable XpSource source, Skill skill, LootDropEvent.Cause cause, LootTable table) { + protected void giveFishingEntityLoot(Player player, EntityLoot loot, PlayerFishEvent event, @Nullable XpSource source, Skill skill, LootDropEvent.Cause cause) { if (!(event.getCaught() instanceof Item itemEntity)) return; Location location = event.getHook().getLocation(); Entity entity = loot.getEntity().spawnEntity(plugin, event.getHook().getLocation()); + if (entity == null) return; + LootDropEvent dropEvent = new LootDropEvent(player, plugin.getUser(player).toApi(), entity, event.getHook().getLocation(), cause); Bukkit.getPluginManager().callEvent(dropEvent); diff --git a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/parser/CustomEntityParser.java b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/parser/CustomEntityParser.java index e64e2f55d..e7fdbf58a 100644 --- a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/parser/CustomEntityParser.java +++ b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/parser/CustomEntityParser.java @@ -4,5 +4,7 @@ import org.spongepowered.configurate.ConfigurationNode; public interface CustomEntityParser extends CustomParser { + EntitySupplier getEntitySupplier(ConfigurationNode config); + } diff --git a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/parser/CustomItemParser.java b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/parser/CustomItemParser.java index 73790e86a..b9cb017cc 100644 --- a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/parser/CustomItemParser.java +++ b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/parser/CustomItemParser.java @@ -4,5 +4,7 @@ import org.spongepowered.configurate.ConfigurationNode; public interface CustomItemParser extends CustomParser { + ItemStack parseCustomItem(ConfigurationNode config); + } diff --git a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/parser/CustomParser.java b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/parser/CustomParser.java index 8aad997c1..a11c6fa70 100644 --- a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/parser/CustomParser.java +++ b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/parser/CustomParser.java @@ -3,5 +3,7 @@ import org.spongepowered.configurate.ConfigurationNode; public interface CustomParser { + boolean shouldUseParser(ConfigurationNode config); + } diff --git a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/parser/EntityLootParser.java b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/parser/EntityLootParser.java index eccfd79f3..06eadc204 100644 --- a/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/parser/EntityLootParser.java +++ b/bukkit/src/main/java/dev/aurelium/auraskills/bukkit/loot/parser/EntityLootParser.java @@ -10,7 +10,6 @@ import org.spongepowered.configurate.ConfigurationNode; import org.spongepowered.configurate.serialize.SerializationException; - public class EntityLootParser implements LootParser { protected final LootManager manager;