diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecocrates/EcoCratesPlugin.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecocrates/EcoCratesPlugin.kt index eddda21..2904057 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecocrates/EcoCratesPlugin.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecocrates/EcoCratesPlugin.kt @@ -11,6 +11,7 @@ import com.willfp.ecocrates.converters.Converters import com.willfp.ecocrates.converters.impl.CrateReloadedConverter import com.willfp.ecocrates.converters.impl.CrazyCratesConverter import com.willfp.ecocrates.converters.impl.ExcellentCratesConverter +import com.willfp.ecocrates.converters.impl.SpecializedCratesConverter import com.willfp.ecocrates.crate.CrateKeyListener import com.willfp.ecocrates.crate.placed.CrateDisplay import com.willfp.ecocrates.crate.placed.PlacedCrates @@ -61,6 +62,9 @@ class EcoCratesPlugin : EcoPlugin() { }, IntegrationLoader("CrazyCrates") { Converters.registerConverter(CrazyCratesConverter(this)) + }, + IntegrationLoader("SpecializedCrates") { + Converters.registerConverter(SpecializedCratesConverter(this)) } ) } diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecocrates/converters/impl/SpecializedCratesConverter.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecocrates/converters/impl/SpecializedCratesConverter.kt new file mode 100644 index 0000000..0f7a040 --- /dev/null +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecocrates/converters/impl/SpecializedCratesConverter.kt @@ -0,0 +1,134 @@ +package com.willfp.ecocrates.converters.impl + +import com.willfp.eco.core.config.BuildableConfig +import com.willfp.eco.core.config.interfaces.Config +import com.willfp.ecocrates.EcoCratesPlugin +import com.willfp.ecocrates.converters.Converter +import com.willfp.ecocrates.converters.util.ConversionHelpers +import com.willfp.ecocrates.converters.util.toLookupString +import com.willfp.ecocrates.crate.Crates +import com.willfp.ecocrates.crate.placed.PlacedCrates +import me.PM2.customcrates.crates.Crate +import me.PM2.customcrates.crates.PlacedCrate +import me.PM2.customcrates.crates.options.rewards.Reward +import org.bukkit.Location + +class SpecializedCratesConverter(private val plugin: EcoCratesPlugin, + override val id: String = "SpecializedCrates") : Converter { + override fun convert() { + val newCrates = Crate.getLoadedCrates().map { convertCrate(it.value) } + + val crates = plugin.cratesYml.getSubsections("crates").toMutableList() + + crates.addAll(newCrates) + + plugin.cratesYml.set("crates", crates) + plugin.cratesYml.save() + plugin.rewardsYml.save() + plugin.reload() + + val pCrates = PlacedCrate.getPlacedCrates().map { PCrate(it.key, Crates.getByID(it.value.crate.name.lowercase())!!) } + + val toDelete = ArrayList(PlacedCrate.getPlacedCrates().values) + + toDelete.forEach { it.delete() } + + pCrates.forEach { + PlacedCrates.setAsCrate(it.location, it.crate) + } + } + + private data class PCrate(val location: Location, val crate: com.willfp.ecocrates.crate.Crate) + + private fun convertCrate(crate: Crate): Config { + val result = ConversionHelpers.createEmptyCrate() + + val id = crate.name.lowercase() + + result.set("id", id) + result.set("name", crate.name) + result.set("preview.title", crate.settings.crateInventoryName) + result.set("key.item", crate.settings.keyItemHandler.item.stack.toLookupString()) + result.set("key.lore", crate.settings.keyItemHandler.item.lore) + result.set("keygui.item", "tripwire_hook unbreaking:1 hide_enchants name:\"${crate.name}\"") + result.set("keygui.lore", mutableListOf( + "${crate.name}", + "&fYou have %keys% keys", + "&fGet more at &astore.example.net" + )) + result.set("keygui.shift-left-click-messsage", mutableListOf( + "Buy a ${crate.name}&r key here! &astore.example.net" + )) + result.set("placed.hologram.height", crate.settings.hologramOffset) + result.set("placed.hologram.frames", mutableListOf( + BuildableConfig() + .add("tick", 0) + .add("lines", crate.settings.hologram.lines) + )) + result.set("open.broadcasts", mutableListOf("%player%&f is opening the ${crate.name}!")) + result.set("finish.broadcasts", mutableListOf("%player%&f won %reward%&f from the ${crate.name}!")) + + if (crate.settings.reward != null) { + val newRewards = mutableListOf() + var row = 2 + var col = 2 + var counter = 1 + crate.settings.reward.crateRewards.forEach { + val salt = id + "_" + counter + newRewards.add(convertReward(it, salt, row, col)) + col++ + if (col >= 8) { + col = 2 + row++ + } + if (row >= 5) { + row = 2 + } + counter++ + } + + val rewards = plugin.rewardsYml.getSubsections("rewards").toMutableList() + + rewards.addAll(newRewards) + + plugin.rewardsYml.set("rewards", rewards) + result.set("rewards", newRewards.map { it.getString("id") }) + } + + return result + } + + private fun convertReward(reward: Reward, salt: String, row: Int, col: Int): Config { + val result = ConversionHelpers.createEmptyReward() + + result.set("id", salt) + + result.set("commands", reward.commands + .map { it.replace( + "{name}", "%player%" + ) } + ) + if (reward.isGiveDisplayItem) { + val item = reward.displayBuilder.stack + val meta = item.itemMeta!! + meta.lore = if (reward.isGiveDisplayItemLore) { + reward.displayBuilder.lore + } else { + mutableListOf() + } + meta.setDisplayName(reward.displayBuilder.getDisplayName(true)) + result.set("items", mutableListOf(item.toLookupString())) + } + + result.set("weight.actual", reward.chance) + result.set("weight.display", reward.chance) + + result.set("display.name", reward.displayBuilder.getDisplayName(false)) + result.set("display.item", reward.displayBuilder.stack.toLookupString()) + result.set("display.lore", reward.displayBuilder.lore) + result.set("display.row", row) + result.set("display.column", col) + + return result + } +} \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/resources/plugin.yml b/eco-core/core-plugin/src/main/resources/plugin.yml index 8386522..66f4d13 100644 --- a/eco-core/core-plugin/src/main/resources/plugin.yml +++ b/eco-core/core-plugin/src/main/resources/plugin.yml @@ -12,6 +12,7 @@ softdepend: - CrateReloaded - ExcellentCrates - CrazyCrates + - SpecializedCrates commands: ecocrates: diff --git a/lib/SpecializedCrates.jar b/lib/SpecializedCrates.jar new file mode 100644 index 0000000..c0f36bb Binary files /dev/null and b/lib/SpecializedCrates.jar differ