Skip to content

Commit

Permalink
add MythicMobs item database.
Browse files Browse the repository at this point in the history
  • Loading branch information
toxicity188 committed Nov 19, 2023
1 parent 99b9d70 commit 419d711
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.Unmodifiable;

import java.util.Collection;

public interface ItemDatabase {

@NotNull Collection<@NotNull String> getKeys();
@Unmodifiable
@NotNull
Collection<@NotNull String> getKeys();
@Nullable
ItemStack getItem(@NotNull String name);

@Unmodifiable
@NotNull
Collection<@NotNull ItemPair> getItems();
void reload();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ class PaperPlatformAdapter: PlatformAdapter {
}

override fun getItemName(itemStack: ItemStack): Component {
return (itemStack.itemMeta?.displayName() ?: Component.text(itemStack.type.toString().lowercase())).append(
Component.space()).append(Component.text("x${DecimalFormat.getInstance().format(itemStack.amount)}").color(NamedTextColor.GREEN).decorate(
TextDecoration.BOLD,
TextDecoration.ITALIC)).hoverEvent(itemStack)
return (itemStack.itemMeta?.displayName() ?: Component.text(itemStack.type.toString().lowercase()))
.append(Component.space())
.append(Component.text("x${DecimalFormat.getInstance().format(itemStack.amount)}").color(NamedTextColor.GREEN).decorate(TextDecoration.BOLD, TextDecoration.ITALIC)).hoverEvent(itemStack)
}

override fun getLore(itemMeta: ItemMeta): List<Component> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package kor.toxicity.questadder.platform

import net.kyori.adventure.text.Component
import net.kyori.adventure.text.format.NamedTextColor
import net.kyori.adventure.text.format.TextDecoration
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer
import org.bukkit.Bukkit
import org.bukkit.Location
Expand Down Expand Up @@ -36,7 +38,9 @@ class SpigotPlatformAdapter: PlatformAdapter {
}

override fun getItemName(itemStack: ItemStack): Component {
return Component.text("${itemStack.itemMeta?.displayName ?: itemStack.type.toString().lowercase()} x${DecimalFormat.getInstance().format(itemStack.amount)}")
return Component.text(itemStack.itemMeta?.displayName ?: itemStack.type.toString().lowercase())
.append(Component.space())
.append(Component.text("x${DecimalFormat.getInstance().format(itemStack.amount)}").color(NamedTextColor.GREEN).decorate(TextDecoration.BOLD, TextDecoration.ITALIC))
}

override fun getLore(itemMeta: ItemMeta): List<Component> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package kor.toxicity.questadder.hooker.item

import io.lumine.mythic.bukkit.BukkitAdapter
import io.lumine.mythic.bukkit.MythicBukkit
import kor.toxicity.questadder.api.item.ItemDatabase
import kor.toxicity.questadder.api.item.ItemPair
import org.bukkit.inventory.ItemStack

class MythicMobsItemDatabase: ItemDatabase {
override fun getKeys(): Collection<String> {
return MythicBukkit.inst().itemManager.itemGroupNames
}

override fun getItem(name: String): ItemStack? {
return MythicBukkit.inst().itemManager.getItemStack(name)
}

override fun getItems(): Collection<ItemPair> {
return MythicBukkit.inst().itemManager.items.map {
ItemPair(it.internalName, BukkitAdapter.adapt(it.generateItemStack(1)))
}
}

override fun reload() {
MythicBukkit.inst().itemManager.reload()
}

override fun requiredPlugin(): String {
return "MythicMobs"
}

}
38 changes: 26 additions & 12 deletions plugin/src/main/java/kor/toxicity/questadder/manager/ItemManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ import kor.toxicity.questadder.api.item.JsonItemDatabase
import kor.toxicity.questadder.command.CommandAPI
import kor.toxicity.questadder.command.SenderType
import kor.toxicity.questadder.extension.*
import kor.toxicity.questadder.hooker.item.ItemsAdderItemDatabase
import kor.toxicity.questadder.hooker.item.MMOItemsItemDatabase
import kor.toxicity.questadder.hooker.item.MythicCrucibleItemDatabase
import kor.toxicity.questadder.hooker.item.OraxenItemDatabase
import kor.toxicity.questadder.hooker.item.*
import kor.toxicity.questadder.mechanic.sender.ItemDialogSender
import org.bukkit.Bukkit
import org.bukkit.entity.Player
Expand All @@ -38,11 +35,19 @@ object ItemManager: QuestAdderManager {
val n = matcher.group("name")
val j = JsonParser.parseString(matcher.group("argument") ?: "{}").asJsonObject
val a = j.getAsJsonPrimitive("amount")?.asInt?.coerceAtLeast(1) ?: 1
return (itemMap[n]?.get() ?: itemDatabaseList.firstNotNullOfOrNull {
when (it) {
is JsonItemDatabase -> it.getItemStack(n, j)
else -> it.getItem(n)
val p = j.getAsJsonPrimitive("plugin")?.asString
fun parse(target: ItemDatabase): ItemStack? {
return when (target) {
is JsonItemDatabase -> target.getItemStack(n, j)
else -> target.getItem(n)
}
}
return (itemMap[n]?.get() ?: if (p != null) itemDatabaseList.firstOrNull {
it.requiredPlugin() == p
}?.let {
parse(it)
} else itemDatabaseList.firstNotNullOfOrNull {
parse(it)
})?.apply {
amount = a
}
Expand All @@ -63,20 +68,28 @@ object ItemManager: QuestAdderManager {
val n = matcher.group("name")
val j = JsonParser.parseString(matcher.group("argument") ?: "{}").asJsonObject
val a = j.getAsJsonPrimitive("amount")?.asInt?.coerceAtLeast(1) ?: 1
return itemMap[n] ?: itemDatabaseList.firstNotNullOfOrNull {
when (it) {
val p = j.getAsJsonPrimitive("plugin")?.asString
fun parse(target: ItemDatabase): ItemSupplier? {
return when (target) {
is JsonItemDatabase -> if (a > 1) {
it.getItemSupplier(n, j)?.let {
target.getItemSupplier(n, j)?.let {
ItemSupplier {
it.get().apply {
amount = a
}
}
}
} else it.getItemSupplier(n, j)
} else target.getItemSupplier(n, j)
else -> null
}
}
return itemMap[n] ?: if (p != null) itemDatabaseList.firstOrNull {
it.requiredPlugin() == p
}?.let {
parse(it)
} else itemDatabaseList.firstNotNullOfOrNull {
parse(it)
}
}
} catch (ex: Exception) {
QuestAdderBukkit.warn("unable to get this item: $name")
Expand All @@ -90,6 +103,7 @@ object ItemManager: QuestAdderManager {
if (isPluginEnabled("ItemsAdder")) itemDatabaseList.add(ItemsAdderItemDatabase())
if (isPluginEnabled("Oraxen")) itemDatabaseList.add(OraxenItemDatabase())
if (isPluginEnabled("MMOItems")) itemDatabaseList.add(MMOItemsItemDatabase())
if (isPluginEnabled("MythicMobs")) itemDatabaseList.add(MythicMobsItemDatabase())
if (isPluginEnabled("MythicCrucible")) itemDatabaseList.add(MythicCrucibleItemDatabase())
registerEvents(object : Listener {
@EventHandler
Expand Down

0 comments on commit 419d711

Please sign in to comment.