From c5d26d60cc327f71f0b15f3d4de1646fd2425d45 Mon Sep 17 00:00:00 2001 From: Aria Date: Tue, 15 Oct 2019 12:50:48 +0200 Subject: [PATCH] Support for MM droptables using 'mmdroptable{id=droptable}' --- .../dropitem/MMDropTableDropItem.java | 46 +++++++++++++++++++ .../mmocore/api/load/DefaultMMOLoader.java | 4 ++ 2 files changed, 50 insertions(+) create mode 100644 src/main/java/net/Indyuce/mmocore/api/droptable/dropitem/MMDropTableDropItem.java diff --git a/src/main/java/net/Indyuce/mmocore/api/droptable/dropitem/MMDropTableDropItem.java b/src/main/java/net/Indyuce/mmocore/api/droptable/dropitem/MMDropTableDropItem.java new file mode 100644 index 00000000..73068550 --- /dev/null +++ b/src/main/java/net/Indyuce/mmocore/api/droptable/dropitem/MMDropTableDropItem.java @@ -0,0 +1,46 @@ +package net.Indyuce.mmocore.api.droptable.dropitem; + +import java.util.List; +import java.util.NoSuchElementException; +import java.util.logging.Level; + +import org.bukkit.inventory.ItemStack; + +import io.lumine.xikage.mythicmobs.MythicMobs; +import io.lumine.xikage.mythicmobs.adapters.bukkit.BukkitAdapter; +import io.lumine.xikage.mythicmobs.drops.Drop; +import io.lumine.xikage.mythicmobs.drops.DropMetadata; +import io.lumine.xikage.mythicmobs.drops.DropTable; +import io.lumine.xikage.mythicmobs.drops.IItemDrop; +import io.lumine.xikage.mythicmobs.drops.LootBag; +import net.Indyuce.mmocore.MMOCore; +import net.Indyuce.mmocore.api.load.MMOLineConfig; + +public class MMDropTableDropItem extends DropItem { + private DropTable dropTable; + private DropMetadata metadata = new DropMetadata(null, null); + + public MMDropTableDropItem(MMOLineConfig config) { + super(config); + + config.validate("id"); + String id = config.getString("id"); + + try { + dropTable = MythicMobs.inst().getDropManager().getDropTable(id).get(); + } catch(NoSuchElementException e) { + MMOCore.log(Level.WARNING, "Could not find MM drop table" + id); + } + } + + @Override + public void collect(List total) { + LootBag lootBag = dropTable.generate(metadata); + + for(Drop type : lootBag.getDrops()) { + if(type instanceof IItemDrop) { + total.add(BukkitAdapter.adapt(((IItemDrop)type).getDrop(metadata))); + } + } + } +} diff --git a/src/main/java/net/Indyuce/mmocore/api/load/DefaultMMOLoader.java b/src/main/java/net/Indyuce/mmocore/api/load/DefaultMMOLoader.java index e5c2454e..d6d1e0a4 100644 --- a/src/main/java/net/Indyuce/mmocore/api/load/DefaultMMOLoader.java +++ b/src/main/java/net/Indyuce/mmocore/api/load/DefaultMMOLoader.java @@ -7,6 +7,7 @@ import net.Indyuce.mmocore.api.droptable.condition.WorldCondition; import net.Indyuce.mmocore.api.droptable.dropitem.DropItem; import net.Indyuce.mmocore.api.droptable.dropitem.DropTableDropItem; import net.Indyuce.mmocore.api.droptable.dropitem.GoldDropItem; +import net.Indyuce.mmocore.api.droptable.dropitem.MMDropTableDropItem; import net.Indyuce.mmocore.api.droptable.dropitem.NoteDropItem; import net.Indyuce.mmocore.api.droptable.dropitem.VanillaDropItem; import net.Indyuce.mmocore.api.experience.Profession; @@ -74,6 +75,9 @@ public class DefaultMMOLoader implements MMOLoader { if (config.getKey().equals("gold") || config.getKey().equals("coin")) return new GoldDropItem(config); + if (config.getKey().equals("mmdroptable")) + return new MMDropTableDropItem(config); + return null; }