Fixed mmdroptable{..}

This commit is contained in:
Indyuce 2022-03-12 14:01:09 +01:00
parent d1a241a60f
commit 57aaa7228a
4 changed files with 52 additions and 44 deletions

View File

@ -14,7 +14,6 @@ import net.Indyuce.mmocore.loot.droptable.condition.WorldCondition;
import net.Indyuce.mmocore.loot.droptable.dropitem.DropItem;
import net.Indyuce.mmocore.loot.droptable.dropitem.DropTableDropItem;
import net.Indyuce.mmocore.loot.droptable.dropitem.GoldDropItem;
import net.Indyuce.mmocore.loot.droptable.dropitem.MMDropTableDropItem;
import net.Indyuce.mmocore.loot.droptable.dropitem.NoteDropItem;
import net.Indyuce.mmocore.loot.droptable.dropitem.VanillaDropItem;
import net.Indyuce.mmocore.experience.source.BrewPotionExperienceSource;
@ -88,9 +87,6 @@ public class DefaultMMOLoader extends 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;
}

View File

@ -7,6 +7,7 @@ import net.Indyuce.mmocore.api.quest.trigger.Trigger;
import net.Indyuce.mmocore.comp.mythicmobs.load.*;
import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser;
import net.Indyuce.mmocore.experience.source.type.ExperienceSource;
import net.Indyuce.mmocore.loot.droptable.dropitem.DropItem;
import org.bukkit.configuration.ConfigurationSection;
public class MythicMobsMMOLoader extends MMOLoader {
@ -20,6 +21,15 @@ public class MythicMobsMMOLoader extends MMOLoader {
return null;
}
@Override
public DropItem loadDropItem(MMOLineConfig config) {
if (config.getKey().equals("mmdroptable"))
return new MMDropTableDropItem(config);
return null;
}
@Override
public Objective loadObjective(MMOLineConfig config, ConfigurationSection section) {

View File

@ -0,0 +1,42 @@
package net.Indyuce.mmocore.comp.mythicmobs.load;
import io.lumine.mythic.api.drops.DropMetadata;
import io.lumine.mythic.api.drops.IItemDrop;
import io.lumine.mythic.bukkit.BukkitAdapter;
import io.lumine.mythic.bukkit.MythicBukkit;
import io.lumine.mythic.core.drops.Drop;
import io.lumine.mythic.core.drops.DropMetadataImpl;
import io.lumine.mythic.core.drops.DropTable;
import io.lumine.mythic.core.drops.LootBag;
import io.lumine.mythic.lib.api.MMOLineConfig;
import net.Indyuce.mmocore.loot.LootBuilder;
import net.Indyuce.mmocore.loot.droptable.dropitem.DropItem;
import java.util.NoSuchElementException;
public class MMDropTableDropItem extends DropItem {
private final DropTable dropTable;
private static final DropMetadata DROP_METADATA = new DropMetadataImpl(null, null);
public MMDropTableDropItem(MMOLineConfig config) {
super(config);
config.validate("id");
String id = config.getString("id");
try {
dropTable = MythicBukkit.inst().getDropManager().getDropTable(id).orElse(null);
} catch (NoSuchElementException exception) {
throw new IllegalArgumentException("Could not find MM drop table with ID '" + id + "'");
}
}
@Override
public void collect(LootBuilder builder) {
LootBag lootBag = dropTable.generate(DROP_METADATA);
for (Drop type : lootBag.getDrops())
if (type instanceof IItemDrop)
builder.addLoot(BukkitAdapter.adapt(((IItemDrop) type).getDrop(DROP_METADATA, 1)));
}
}

View File

@ -1,40 +0,0 @@
package net.Indyuce.mmocore.loot.droptable.dropitem;
import java.util.NoSuchElementException;
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.loot.LootBuilder;
import io.lumine.mythic.lib.api.MMOLineConfig;
public class MMDropTableDropItem extends DropItem {
private final DropTable dropTable;
private static final 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).orElse(null);
} catch (NoSuchElementException exception) {
throw new IllegalArgumentException("Could not find MM drop table with ID '" + id + "'");
}
}
@Override
public void collect(LootBuilder builder) {
LootBag lootBag = dropTable.generate(metadata);
for (Drop type : lootBag.getDrops())
if (type instanceof IItemDrop)
builder.addLoot(BukkitAdapter.adapt(((IItemDrop) type).getDrop(metadata)));
}
}