Support for MM droptables using 'mmdroptable{id=droptable}'

This commit is contained in:
Aria 2019-10-15 12:50:48 +02:00
parent 11dcf97f9a
commit c5d26d60cc
2 changed files with 50 additions and 0 deletions

View File

@ -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<ItemStack> total) {
LootBag lootBag = dropTable.generate(metadata);
for(Drop type : lootBag.getDrops()) {
if(type instanceof IItemDrop) {
total.add(BukkitAdapter.adapt(((IItemDrop)type).getDrop(metadata)));
}
}
}
}

View File

@ -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;
}