diff --git a/build.gradle b/build.gradle deleted file mode 100644 index 2aba9f1..0000000 --- a/build.gradle +++ /dev/null @@ -1,110 +0,0 @@ -buildscript { - repositories { - mavenCentral() - } - - dependencies { - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10" - } -} - -plugins { - id 'java-library' - id 'com.github.johnrengelman.shadow' version '7.0.0' - id 'maven-publish' - id 'java' -} - -dependencies { - implementation project(":eco-core").getSubprojects() -} - -allprojects { - apply plugin: 'kotlin' - apply plugin: 'java' - apply plugin: 'maven-publish' - apply plugin: 'com.github.johnrengelman.shadow' - - repositories { - mavenCentral() - mavenLocal() - maven { url 'https://jitpack.io' } - maven { url 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/' } - maven { url 'https://repo.auxilor.io/repository/maven-public/' } - } - - jar { - onlyIf { !sourceSets.main.allSource.files.isEmpty() } - } - - shadowJar { - relocate('com.willfp.ecomponent', 'com.willfp.ecoshop.ecomponent') - } - - dependencies { - compileOnly 'com.willfp:eco:6.65.4' - implementation 'com.willfp:ecomponent:1.3.0' - compileOnly 'com.github.ben-manes.caffeine:caffeine:3.0.6' - - compileOnly 'org.jetbrains:annotations:23.0.0' - compileOnly 'org.jetbrains.kotlin:kotlin-stdlib:1.7.10' - compileOnly 'com.willfp:libreforge:4.40.0' - } - - tasks.withType(JavaCompile) { - options.deprecation = true - options.encoding = 'UTF-8' - } - - tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all { - kotlinOptions { - jvmTarget = "17" - } - } - - processResources { - filesMatching(["**plugin.yml"]) { - expand projectVersion: project.version - } - } - - compileJava.options.encoding = 'UTF-8' - compileJava.dependsOn clean -} - -tasks.withType(Jar) { - destinationDirectory = file("$rootDir/bin/") -} - -clean.doLast { - file("${rootDir}/bin").deleteDir() -} - -shadowJar { - archiveFileName = findProperty("plugin-name") + " v" + findProperty("version") + ".jar" -} - -jar { - archiveFileName = findProperty("plugin-name") + " v" + findProperty("version") + " " + "unshaded" + ".jar" -} - -group = 'com.willfp' -archivesBaseName = project.name -version = findProperty("version") -java.sourceCompatibility = JavaVersion.VERSION_17 - -compileJava.options.encoding = 'UTF-8' - -build.dependsOn shadowJar - -tasks.register('buyThePlugins') { - dependsOn subprojects.build - - doLast { - println 'If you like the plugin, please consider buying it on Spigot or Polymart!' - println 'Spigot: https://www.spigotmc.org/resources/authors/auxilor.507394/' - println 'Polymart: https://polymart.org/user/auxilor.1107/' - println 'Buying gives you access to support and the plugin auto-updater, and it allows me to keep developing plugins.' - } -} -build.finalizedBy buyThePlugins \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..5ad1ebf --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,86 @@ +plugins { + java + `java-library` + `maven-publish` + kotlin("jvm") version "1.7.10" + id("com.github.johnrengelman.shadow") version "8.0.0" + id("com.willfp.libreforge-gradle-plugin") version "1.0.0" +} + +group = "com.willfp" +version = findProperty("version")!! +val libreforgeVersion = findProperty("libreforge-version") + +base { + archivesName.set(project.name) +} + +dependencies { + project(":eco-core").dependencyProject.subprojects { + implementation(this) + } +} + +allprojects { + apply(plugin = "java") + apply(plugin = "kotlin") + apply(plugin = "maven-publish") + apply(plugin = "com.github.johnrengelman.shadow") + + repositories { + mavenLocal() + mavenCentral() + + maven("https://repo.papermc.io/repository/maven-public/") + maven("https://repo.auxilor.io/repository/maven-public/") + maven("https://jitpack.io") + } + + dependencies { + compileOnly("com.willfp:eco:6.65.4") + compileOnly("org.jetbrains:annotations:23.0.0") + compileOnly("org.jetbrains.kotlin:kotlin-stdlib:1.7.10") + + compileOnly("com.github.ben-manes.caffeine:caffeine:3.1.0") + implementation("com.willfp:ecomponent:1.4.1") + } + + java { + withSourcesJar() + toolchain.languageVersion.set(JavaLanguageVersion.of(17)) + } + + tasks { + shadowJar { + relocate("com.willfp.libreforge.loader", "com.willfp.ecoshop.libreforge.loader") + relocate("com.willfp.ecomponent", "com.willfp.ecoshop.ecomponent") + } + + compileKotlin { + kotlinOptions { + jvmTarget = "17" + } + } + + compileJava { + options.isDeprecation = true + options.encoding = "UTF-8" + + dependsOn(clean) + } + + processResources { + filesMatching(listOf("**plugin.yml", "**eco.yml")) { + expand( + "version" to project.version, + "libreforgeVersion" to libreforgeVersion, + "pluginName" to rootProject.name + ) + } + } + + build { + dependsOn(shadowJar) + } + } +} diff --git a/eco-core/build.gradle b/eco-core/build.gradle deleted file mode 100644 index 50f9ee4..0000000 --- a/eco-core/build.gradle +++ /dev/null @@ -1,2 +0,0 @@ -group 'com.willfp' -version rootProject.version \ No newline at end of file diff --git a/eco-core/build.gradle.kts b/eco-core/build.gradle.kts new file mode 100644 index 0000000..48fdde0 --- /dev/null +++ b/eco-core/build.gradle.kts @@ -0,0 +1,2 @@ +group = "com.willfp" +version = rootProject.version \ No newline at end of file diff --git a/eco-core/core-plugin/build.gradle b/eco-core/core-plugin/build.gradle deleted file mode 100644 index dcbc8e7..0000000 --- a/eco-core/core-plugin/build.gradle +++ /dev/null @@ -1,7 +0,0 @@ -group 'com.willfp' -version rootProject.version - -dependencies { - compileOnly 'org.spigotmc:spigot-api:1.19.1-R0.1-SNAPSHOT' - compileOnly fileTree(dir: '../../lib', include: ['*.jar']) -} \ No newline at end of file diff --git a/eco-core/core-plugin/build.gradle.kts b/eco-core/core-plugin/build.gradle.kts new file mode 100644 index 0000000..953a343 --- /dev/null +++ b/eco-core/core-plugin/build.gradle.kts @@ -0,0 +1,37 @@ +group = "com.willfp" +version = rootProject.version + +dependencies { + compileOnly("io.papermc.paper:paper-api:1.19.3-R0.1-SNAPSHOT") +} + +publishing { + publications { + register("maven") { + groupId = project.group.toString() + version = project.version.toString() + artifactId = rootProject.name + + artifact(rootProject.tasks.shadowJar.get().archiveFile) + } + } + + publishing { + repositories { + maven { + name = "auxilor" + url = uri("https://repo.auxilor.io/repository/maven-releases/") + credentials { + username = System.getenv("MAVEN_USERNAME") + password = System.getenv("MAVEN_PASSWORD") + } + } + } + } +} + +tasks { + build { + dependsOn(publishToMavenLocal) + } +} \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/EcoShopPlugin.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/EcoShopPlugin.kt index e53bf59..481a64f 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/EcoShopPlugin.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/EcoShopPlugin.kt @@ -1,87 +1,48 @@ package com.willfp.ecoshop -import com.willfp.eco.core.EcoPlugin import com.willfp.eco.core.command.impl.PluginCommand -import com.willfp.eco.core.config.ConfigType -import com.willfp.eco.core.config.interfaces.Config -import com.willfp.eco.core.config.readConfig -import com.willfp.eco.core.integrations.IntegrationLoader import com.willfp.eco.core.integrations.shop.ShopManager import com.willfp.ecoshop.commands.CommandEcoShop import com.willfp.ecoshop.commands.CommandSell -import com.willfp.ecoshop.config.UsermadeConfig -import com.willfp.ecoshop.integration.EcoShopAdapter -import com.willfp.ecoshop.integration.libreforge.LibreforgeIntegration +import com.willfp.ecoshop.integrations.EcoShopAdapter +import com.willfp.ecoshop.libreforge.FilterShopItem +import com.willfp.ecoshop.libreforge.TriggerBuyItem +import com.willfp.ecoshop.libreforge.TriggerSellItem +import com.willfp.ecoshop.shop.ShopCategories import com.willfp.ecoshop.shop.Shops import com.willfp.ecoshop.shop.gui.SellGUI +import com.willfp.libreforge.filters.Filters +import com.willfp.libreforge.loader.LibreforgePlugin +import com.willfp.libreforge.loader.configs.ConfigCategory +import com.willfp.libreforge.triggers.Triggers import org.bukkit.event.Listener -import java.io.File -import java.util.zip.ZipFile -class EcoShopPlugin : EcoPlugin() { +class EcoShopPlugin : LibreforgePlugin() { init { instance = this ShopManager.register(EcoShopAdapter) } + override fun loadConfigCategories(): List { + return listOf( + ShopCategories, + Shops + ) + } + override fun handleEnable() { - copyConfigs("categories") - copyConfigs("shops") - Shops.update(this) SellGUI.update(this) + + Filters.register(FilterShopItem) + Triggers.register(TriggerBuyItem) + Triggers.register(TriggerSellItem) } override fun handleReload() { - Shops.update(this) SellGUI.update(this) } - private fun copyConfigs(directory: String) { - val folder = File(this.dataFolder, directory) - if (!folder.exists()) { - val files = mutableListOf() - - try { - for (entry in ZipFile(this.file).entries().asIterator()) { - if (entry.name.startsWith("$directory/")) { - files.add(entry.name.removePrefix("$directory/")) - } - } - } catch (_: Exception) { - // Sometimes, ZipFile likes to completely fail. No idea why, but here's the 'solution'! - } - - files.removeIf { !it.endsWith(".yml") } - files.replaceAll { it.replace(".yml", "") } - - for (configName in files) { - UsermadeConfig(configName, directory, this) - } - } - } - - fun getConfigs(directory: String): Map { - val configs = mutableMapOf() - - for (file in File(this.dataFolder, directory).walk()) { - if (file.nameWithoutExtension == "_example") { - continue - } - - if (!file.name.endsWith(".yml")) { - continue - } - - - val id = file.nameWithoutExtension - val config = file.readConfig(ConfigType.YAML) - configs[id] = config - } - - return configs - } - override fun loadListeners(): List { return listOf( @@ -95,14 +56,8 @@ class EcoShopPlugin : EcoPlugin() { ) } - override fun loadIntegrationLoaders(): List { - return listOf( - IntegrationLoader("libreforge") { LibreforgeIntegration.load() } - ) - } - override fun getMinimumEcoVersion(): String { - return "6.48.0" + return "6.65.0" } companion object { diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/commands/CommandResetBuys.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/commands/CommandResetBuys.kt index 1621df5..dd9cc4a 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/commands/CommandResetBuys.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/commands/CommandResetBuys.kt @@ -34,7 +34,7 @@ class CommandResetBuys(plugin: EcoPlugin) : Subcommand( return } - val item = ShopItems.getByID(args[1]) + val item = ShopItems[args[1]] if (item == null) { sender.sendMessage(plugin.langYml.getMessage("invalid-item")) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/config/UsermadeConfig.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/config/UsermadeConfig.kt deleted file mode 100644 index 7fa7f80..0000000 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/config/UsermadeConfig.kt +++ /dev/null @@ -1,14 +0,0 @@ -package com.willfp.ecoshop.config - -import com.willfp.eco.core.EcoPlugin -import com.willfp.eco.core.config.ConfigType -import com.willfp.eco.core.config.ExtendableConfig - -class UsermadeConfig(name: String, directory: String, plugin: EcoPlugin) : ExtendableConfig( - name, - true, - plugin, - plugin::class.java, - "$directory/", - ConfigType.YAML -) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/integration/libreforge/LibreforgeIntegration.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/integration/libreforge/LibreforgeIntegration.kt deleted file mode 100644 index 56144dc..0000000 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/integration/libreforge/LibreforgeIntegration.kt +++ /dev/null @@ -1,20 +0,0 @@ -package com.willfp.ecoshop.integration.libreforge - -import com.willfp.eco.core.integrations.Integration -import com.willfp.ecoshop.integration.libreforge.impl.FilterShopItem -import com.willfp.ecoshop.integration.libreforge.impl.TriggerBuyItem -import com.willfp.ecoshop.integration.libreforge.impl.TriggerSellItem -import com.willfp.libreforge.filters.Filters -import com.willfp.libreforge.triggers.Triggers - -object LibreforgeIntegration: Integration { - fun load() { - Filters.register(FilterShopItem) - Triggers.register(TriggerBuyItem) - Triggers.register(TriggerSellItem) - } - - override fun getPluginName(): String { - return "libreforge" - } -} diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/integration/EcoShopAdapter.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/integrations/EcoShopAdapter.kt similarity index 96% rename from eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/integration/EcoShopAdapter.kt rename to eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/integrations/EcoShopAdapter.kt index 7c1c430..09a5006 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/integration/EcoShopAdapter.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/integrations/EcoShopAdapter.kt @@ -1,4 +1,4 @@ -package com.willfp.ecoshop.integration +package com.willfp.ecoshop.integrations import com.willfp.eco.core.integrations.shop.ShopIntegration import com.willfp.eco.core.integrations.shop.ShopSellEvent diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/integration/libreforge/impl/FilterShopItem.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/libreforge/FilterShopItem.kt similarity index 93% rename from eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/integration/libreforge/impl/FilterShopItem.kt rename to eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/libreforge/FilterShopItem.kt index b53ede9..819aa00 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/integration/libreforge/impl/FilterShopItem.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/libreforge/FilterShopItem.kt @@ -1,4 +1,4 @@ -package com.willfp.ecoshop.integration.libreforge.impl +package com.willfp.ecoshop.libreforge import com.willfp.eco.core.config.interfaces.Config import com.willfp.ecoshop.event.ShopEvent diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/integration/libreforge/impl/TriggerBuyItem.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/libreforge/TriggerBuyItem.kt similarity index 87% rename from eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/integration/libreforge/impl/TriggerBuyItem.kt rename to eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/libreforge/TriggerBuyItem.kt index c718e6a..c007712 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/integration/libreforge/impl/TriggerBuyItem.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/libreforge/TriggerBuyItem.kt @@ -1,6 +1,7 @@ -package com.willfp.ecoshop.integration.libreforge.impl +package com.willfp.ecoshop.libreforge import com.willfp.ecoshop.event.EcoShopBuyEvent +import com.willfp.libreforge.toDispatcher import com.willfp.libreforge.triggers.Trigger import com.willfp.libreforge.triggers.TriggerData import com.willfp.libreforge.triggers.TriggerParameter @@ -18,7 +19,7 @@ object TriggerBuyItem : Trigger("buy_item") { val player = event.player this.dispatch( - player, + player.toDispatcher(), TriggerData( player = player, location = player.location, diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/integration/libreforge/impl/TriggerSellItem.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/libreforge/TriggerSellItem.kt similarity index 87% rename from eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/integration/libreforge/impl/TriggerSellItem.kt rename to eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/libreforge/TriggerSellItem.kt index 3091fd2..267fa57 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/integration/libreforge/impl/TriggerSellItem.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/libreforge/TriggerSellItem.kt @@ -1,6 +1,7 @@ -package com.willfp.ecoshop.integration.libreforge.impl +package com.willfp.ecoshop.libreforge import com.willfp.ecoshop.event.EcoShopSellEvent +import com.willfp.libreforge.toDispatcher import com.willfp.libreforge.triggers.Trigger import com.willfp.libreforge.triggers.TriggerData import com.willfp.libreforge.triggers.TriggerParameter @@ -18,7 +19,7 @@ object TriggerSellItem : Trigger("sell_item") { val player = event.player this.dispatch( - player, + player.toDispatcher(), TriggerData( player = player, location = player.location, diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/shop/Shop.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/shop/Shop.kt index 47b11e3..6256917 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/shop/Shop.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/shop/Shop.kt @@ -10,6 +10,7 @@ import com.willfp.eco.core.gui.slot.ConfigSlot import com.willfp.eco.core.gui.slot.FillerMask import com.willfp.eco.core.gui.slot.MaskItems import com.willfp.eco.core.items.Items +import com.willfp.eco.core.registry.KRegistrable import com.willfp.eco.core.sound.PlayableSound import com.willfp.eco.util.formatEco import com.willfp.eco.util.savedDisplayName @@ -39,9 +40,9 @@ fun Menu.kickBack(player: Player) = class Shop( val plugin: EcoShopPlugin, - val id: String, + override val id: String, val config: Config -) { +): KRegistrable { val clickSound = config.ifHasOrNull("click-sound") { PlayableSound.create(config.getSubsection(it)) } diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/shop/ShopCategories.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/shop/ShopCategories.kt index 0e6fda0..51062a8 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/shop/ShopCategories.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/shop/ShopCategories.kt @@ -1,37 +1,21 @@ package com.willfp.ecoshop.shop -import com.google.common.collect.HashBiMap -import com.google.common.collect.ImmutableList +import com.willfp.eco.core.config.interfaces.Config import com.willfp.ecoshop.EcoShopPlugin +import com.willfp.libreforge.loader.LibreforgePlugin +import com.willfp.libreforge.loader.configs.RegistrableCategory @Suppress("UNUSED") -object ShopCategories { - private val BY_ID = HashBiMap.create() - - /** - * Get category matching id. - * - * @param id The id to query. - * @return The matching category, or null if not found. - */ - @JvmStatic - fun getByID(id: String): ShopCategory? { - return BY_ID[id] +object ShopCategories : RegistrableCategory("category", "categories") { + override fun clear(plugin: LibreforgePlugin) { + registry.clear() } - /** All shop categories. */ - @JvmStatic - fun values(): List { - return ImmutableList.copyOf(BY_ID.values) - } - - @JvmStatic - internal fun update(plugin: EcoShopPlugin) { + override fun beforeReload(plugin: LibreforgePlugin) { ShopItems.clear() - BY_ID.clear() + } - for ((id, config) in plugin.getConfigs("categories")) { - BY_ID[id] = ShopCategory(plugin, id, config) - } + override fun acceptConfig(plugin: LibreforgePlugin, id: String, config: Config) { + registry.register(ShopCategory(plugin as EcoShopPlugin, id, config)) } } diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/shop/ShopCategory.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/shop/ShopCategory.kt index 209e353..28aa387 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/shop/ShopCategory.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/shop/ShopCategory.kt @@ -14,6 +14,7 @@ import com.willfp.eco.core.gui.slot.MaskItems import com.willfp.eco.core.gui.slot.Slot import com.willfp.eco.core.items.Items import com.willfp.eco.core.items.builder.modify +import com.willfp.eco.core.registry.KRegistrable import com.willfp.eco.util.formatEco import com.willfp.ecomponent.components.pageChangerWithDefault import com.willfp.ecomponent.menuStateVar @@ -30,16 +31,15 @@ fun Stack.popOrNull(): T? = class ShopCategory( val plugin: EcoShopPlugin, - val id: String, + override val id: String, val config: Config -) { - +) : KRegistrable { private val permission = config.getStringOrNull("permission") val items = config.getSubsections("items").mapNotNull { try { val item = ShopItem(plugin, it) - ShopItems.addNewItem(item) + ShopItems.register(item) item } catch (e: InvalidShopItemException) { plugin.logger.warning(e.message) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/shop/ShopItem.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/shop/ShopItem.kt index a17ee28..05c7cf5 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/shop/ShopItem.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/shop/ShopItem.kt @@ -14,6 +14,7 @@ import com.willfp.eco.core.items.Items import com.willfp.eco.core.items.builder.ItemStackBuilder import com.willfp.eco.core.price.CombinedDisplayPrice import com.willfp.eco.core.price.ConfiguredPrice +import com.willfp.eco.core.registry.KRegistrable import com.willfp.eco.util.formatEco import com.willfp.ecoshop.EcoShopPlugin import com.willfp.ecoshop.event.EcoShopBuyEvent @@ -21,6 +22,10 @@ import com.willfp.ecoshop.event.EcoShopSellEvent import com.willfp.ecoshop.shop.gui.BuyMenu import com.willfp.ecoshop.shop.gui.SellMenu import com.willfp.ecoshop.shop.gui.ShopItemSlot +import com.willfp.libreforge.ViolationContext +import com.willfp.libreforge.effects.Effects +import com.willfp.libreforge.toDispatcher +import com.willfp.libreforge.triggers.TriggerData import org.bukkit.Bukkit import org.bukkit.Material import org.bukkit.OfflinePlayer @@ -39,13 +44,18 @@ enum class BuyType { class ShopItem( plugin: EcoShopPlugin, val config: Config -) { - val id = config.getString("id") +) : KRegistrable { + override val id = config.getString("id") val commands = config.getStrings("command") + config.getStrings("commands") val item = if (config.has("item")) Items.lookup(config.getString("item")) else null + val effects = Effects.compileChain( + config.getSubsections("effects"), + ViolationContext(plugin, "shop item $id") + ) + val buyAmount = config.getIntOrNull("buy.amount") ?: 1 private val _displayItem = ItemStackBuilder( @@ -282,6 +292,16 @@ class ShopItem( ) } + effects?.trigger( + player.toDispatcher(), + TriggerData( + player = player, + location = player.location, + item = player.inventory.itemInMainHand, + value = amount.toDouble() + ) + ) + if (buyItemMessage != null) { for (message in buyItemMessage) { player.sendMessage( @@ -304,7 +324,7 @@ class ShopItem( /** Get if a [player] is allowed to sell this item. */ fun getSellStatus(player: Player): SellStatus { - // Can't sell a command + // Can't sell a command or an effect if (item == null || sellPrice == null) { return SellStatus.CANNOT_SELL } @@ -405,7 +425,7 @@ class ShopItem( var amountOfItems = 0 for (itemStack in player.inventory.storageContents) { - if (!item.matches(itemStack)) { + if (!item.matches(itemStack) || itemStack == null) { continue } diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/shop/ShopItems.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/shop/ShopItems.kt index 1575102..2dd3b2a 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/shop/ShopItems.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/shop/ShopItems.kt @@ -1,36 +1,5 @@ package com.willfp.ecoshop.shop -import com.google.common.collect.HashBiMap -import com.google.common.collect.ImmutableList +import com.willfp.eco.core.registry.Registry -@Suppress("UNUSED") -object ShopItems { - private val BY_ID = HashBiMap.create() - - /** - * Get item matching id. - * - * @param id The id to query. - * @return The matching item, or null if not found. - */ - @JvmStatic - fun getByID(id: String): ShopItem? { - return BY_ID[id] - } - - /** All shop items. */ - @JvmStatic - fun values(): List { - return ImmutableList.copyOf(BY_ID.values) - } - - /** Add a new [item]. */ - fun addNewItem(item: ShopItem) { - BY_ID[item.id] = item - } - - /** Clear registry. */ - internal fun clear() { - BY_ID.clear() - } -} +object ShopItems : Registry() \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/shop/Shops.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/shop/Shops.kt index e8f8b32..b0a095c 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/shop/Shops.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/shop/Shops.kt @@ -1,47 +1,16 @@ package com.willfp.ecoshop.shop -import com.google.common.collect.HashBiMap -import com.google.common.collect.ImmutableList -import com.willfp.eco.core.config.updating.ConfigUpdater +import com.willfp.eco.core.config.interfaces.Config import com.willfp.ecoshop.EcoShopPlugin +import com.willfp.libreforge.loader.LibreforgePlugin +import com.willfp.libreforge.loader.configs.RegistrableCategory -@Suppress("UNUSED") -object Shops { - private val BY_ID = HashBiMap.create() - - /** - * Get shop matching id. - * - * @param id The id to query. - * @return The matching shop, or null if not found. - */ - @JvmStatic - fun getByID(id: String): Shop? { - return BY_ID[id] +object Shops : RegistrableCategory("shop", "shops") { + override fun clear(plugin: LibreforgePlugin) { + registry.clear() } - /** - * List of all shops. - * - * @return The shops. - */ - @JvmStatic - fun values(): List { - return ImmutableList.copyOf(BY_ID.values) - } - - @JvmStatic - fun update(plugin: EcoShopPlugin) { - ShopCategories.update(plugin) - - for (shop in values()) { - shop.remove() - } - - BY_ID.clear() - - for ((id, config) in plugin.getConfigs("shops")) { - BY_ID[id] = Shop(plugin, id, config) - } + override fun acceptConfig(plugin: LibreforgePlugin, id: String, config: Config) { + registry.register(Shop(plugin as EcoShopPlugin, id, config)) } } diff --git a/eco-core/core-plugin/src/main/resources/categories/_example.yml b/eco-core/core-plugin/src/main/resources/categories/_example.yml index 03ee47e..4e92af6 100644 --- a/eco-core/core-plugin/src/main/resources/categories/_example.yml +++ b/eco-core/core-plugin/src/main/resources/categories/_example.yml @@ -121,6 +121,26 @@ items: row: 3 # The row. page: 2 # The page. + - id: do_something_cool + + # Effects to run when the player buys the item. + # Read here: https://plugins.auxilor.io/effects/configuring-an-effect + effects: [] + + buy: + value: 65 + type: crystals + display: "&b%value% Crystals ❖" + + gui: + display: + item: nether_star + lore: + - "&fBuy me to do something cool!" + column: 6 # The column. + row: 3 # The row. + page: 2 # The page. + - id: valkyrie_egg item: ecobosses:valkyrie_spawn_egg @@ -152,7 +172,7 @@ items: - "" - "&e&oLeft click to buy with money," - "&e&oRight click to buy with &bCrystals ❖&e&o!" - column: 6 # How far left to right (1-9). + column: 7 # How far left to right (1-9). row: 3 # How far up or down (1-6). page: 1 # The page. diff --git a/eco-core/core-plugin/src/main/resources/eco.yml b/eco-core/core-plugin/src/main/resources/eco.yml index 25373e0..624ccd7 100644 --- a/eco-core/core-plugin/src/main/resources/eco.yml +++ b/eco-core/core-plugin/src/main/resources/eco.yml @@ -1,4 +1,9 @@ -resource-id: 3177 -bstats-id: 16978 -color: 'Lb852' -supports-extensions: false \ No newline at end of file +environment: + - name: libreforge version + value: ${libreforgeVersion} + +options: + resource-id: 3177 + bstats-id: 16978 + color: 'Lb852' + uses-reflective-reload: false diff --git a/gradle.properties b/gradle.properties index 10d490e..dbc8e1f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,5 @@ -version = 1.3.0 -plugin-name = EcoShop \ No newline at end of file +#libreforge-updater +#Tue Nov 21 22:40:58 GMT 2023 +kotlin.code.style=official +libreforge-version=4.44.0 +version=1.4.0 \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 41d9927..7f93135 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ae04661..3fa8f86 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip +networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 1b6c787..1aa94a4 100755 --- a/gradlew +++ b/gradlew @@ -55,7 +55,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. @@ -80,13 +80,11 @@ do esac done -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -APP_NAME="Gradle" +# This is normally unused +# shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -133,22 +131,29 @@ location of your Java installation." fi else JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac case $MAX_FD in #( '' | soft) :;; #( *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -193,11 +198,15 @@ if "$cygwin" || "$msys" ; then done fi -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ @@ -205,6 +214,12 @@ set -- \ org.gradle.wrapper.GradleWrapperMain \ "$@" +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + # Use "xargs" to parse quoted args. # # With -n1 it outputs one arg per line, with the quotes and backslashes removed. diff --git a/gradlew.bat b/gradlew.bat index 107acd3..93e3f59 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -14,7 +14,7 @@ @rem limitations under the License. @rem -@if "%DEBUG%" == "" @echo off +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -25,7 +25,8 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @@ -40,7 +41,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute +if %ERRORLEVEL% equ 0 goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal diff --git a/settings.gradle b/settings.gradle deleted file mode 100644 index 66c4cb4..0000000 --- a/settings.gradle +++ /dev/null @@ -1,5 +0,0 @@ -rootProject.name = 'EcoShop' - -// Core -include ':eco-core' -include ':eco-core:core-plugin' diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000..0d23773 --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,14 @@ +pluginManagement { + repositories { + gradlePluginPortal() + mavenLocal() + maven("https://repo.jpenilla.xyz/snapshots/") + maven("https://repo.auxilor.io/repository/maven-public/") + } +} + +rootProject.name = "EcoShop" + +// Core +include(":eco-core") +include(":eco-core:core-plugin") \ No newline at end of file