diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/BoosterHandlers.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/BoosterHandlers.kt index 22025eb..ef16806 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/BoosterHandlers.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/BoosterHandlers.kt @@ -56,12 +56,12 @@ fun Player.activateBooster(booster: Booster): Boolean { Bukkit.broadcastMessage(activationMessage) } - plugin.scheduler.runLater ({ + plugin.scheduler.runLater(booster.duration.toLong()) { for (expiryMessage in booster.getExpiryMessages()) { Bukkit.broadcastMessage(expiryMessage) } Bukkit.getServer().activeBooster = null - }, booster.duration.toLong()) + } active = booster diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/BoostersPlugin.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/BoostersPlugin.kt index deb0c96..b4277d4 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/BoostersPlugin.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/BoostersPlugin.kt @@ -30,7 +30,7 @@ class BoostersPlugin : EcoPlugin() { } override fun getMinimumEcoVersion(): String { - return "6.12.0" + return "6.24.0" } init { diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/boosters/Booster.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/boosters/Booster.kt index 1be437c..7e73a67 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/boosters/Booster.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/boosters/Booster.kt @@ -10,10 +10,10 @@ import org.bukkit.event.Listener abstract class Booster( private val plugin: BoostersPlugin, val id: String -): Listener { +) : Listener { abstract val duration: Int - val dataKey = PersistentDataKey( + val dataKey = PersistentDataKey( plugin.namespacedKeyFactory.create(id), PersistentDataKeyType.INT, 0 @@ -35,6 +35,10 @@ abstract class Booster( return other.id == this.id } + override fun hashCode(): Int { + return this.id.hashCode() + } + fun getActivationMessages(player: Player): List { val messages = mutableListOf() diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/commands/CommandBoosters.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/commands/CommandBoosters.kt index ea5f43a..da9ea3f 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/commands/CommandBoosters.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/commands/CommandBoosters.kt @@ -2,7 +2,6 @@ package com.willfp.boosters.commands import com.willfp.boosters.gui.BoosterGUI import com.willfp.eco.core.EcoPlugin -import com.willfp.eco.core.command.CommandHandler import com.willfp.eco.core.command.impl.PluginCommand import org.bukkit.command.CommandSender import org.bukkit.entity.Player @@ -20,14 +19,12 @@ class CommandBoosters(plugin: EcoPlugin) : .addSubcommand(CommandReload(plugin)) } - override fun getHandler(): CommandHandler { - return CommandHandler { sender: CommandSender, _: List -> - if (sender !is Player) { - sender.sendMessage(this.plugin.langYml.getMessage("not-player")) - return@CommandHandler - } - - BoosterGUI.open(sender) + override fun onExecute(sender: CommandSender, args: List) { + if (sender !is Player) { + sender.sendMessage(this.plugin.langYml.getMessage("not-player")) + return } + + BoosterGUI.open(sender) } -} \ No newline at end of file +} diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/commands/CommandGive.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/commands/CommandGive.kt index 7afc076..2232e3f 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/commands/CommandGive.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/commands/CommandGive.kt @@ -4,8 +4,6 @@ import com.willfp.boosters.boosters.Boosters import com.willfp.boosters.getAmountOfBooster import com.willfp.boosters.setAmountOfBooster import com.willfp.eco.core.EcoPlugin -import com.willfp.eco.core.command.CommandHandler -import com.willfp.eco.core.command.TabCompleteHandler import com.willfp.eco.core.command.impl.Subcommand import com.willfp.eco.util.StringUtils import org.bukkit.Bukkit @@ -19,69 +17,66 @@ class CommandGive(plugin: EcoPlugin) : "boosters.command.give", false ) { - override fun getHandler(): CommandHandler { - return CommandHandler { sender: CommandSender, args: List -> - if (args.isEmpty()) { - sender.sendMessage(plugin.langYml.getMessage("requires-player")) - return@CommandHandler + + override fun onExecute(sender: CommandSender, args: List) { + if (args.isEmpty()) { + sender.sendMessage(plugin.langYml.getMessage("requires-player")) + return + } + + if (args.size == 1) { + sender.sendMessage(plugin.langYml.getMessage("requires-booster")) + return + } + + val booster = Boosters.getById(args[1].lowercase()) + + if (booster == null) { + sender.sendMessage(plugin.langYml.getMessage("invalid-booster")) + return + } + + this.plugin.scheduler.runAsync { + @Suppress("DEPRECATION") + val player = Bukkit.getOfflinePlayer(args[0]) + if (!player.hasPlayedBefore()) { + sender.sendMessage(plugin.langYml.getMessage("invalid-player")) + return@runAsync } - if (args.size == 1) { - sender.sendMessage(plugin.langYml.getMessage("requires-booster")) - return@CommandHandler + this.plugin.scheduler.run { + player.setAmountOfBooster(booster, player.getAmountOfBooster(booster) + 1) } - val booster = Boosters.getById(args[1].lowercase()) - - if (booster == null) { - sender.sendMessage(plugin.langYml.getMessage("invalid-booster")) - return@CommandHandler - } - - this.plugin.scheduler.runAsync { - @Suppress("DEPRECATION") - val player = Bukkit.getOfflinePlayer(args[0]) - if (!player.hasPlayedBefore()) { - sender.sendMessage(plugin.langYml.getMessage("invalid-player")) - return@runAsync - } - - this.plugin.scheduler.run { - player.setAmountOfBooster(booster, player.getAmountOfBooster(booster) + 1) - } - - sender.sendMessage( - plugin.langYml.getMessage("gave-booster", StringUtils.FormatOption.WITHOUT_PLACEHOLDERS) - .replace("%player%", player.name?: return@runAsync) - .replace("%booster%", booster.id) - ) - } + sender.sendMessage( + plugin.langYml.getMessage("gave-booster", StringUtils.FormatOption.WITHOUT_PLACEHOLDERS) + .replace("%player%", player.name ?: return@runAsync) + .replace("%booster%", booster.id) + ) } } - override fun getTabCompleter(): TabCompleteHandler { - return TabCompleteHandler { _, args -> - val completions = mutableListOf() + override fun tabComplete(sender: CommandSender, args: List): List { + val completions = mutableListOf() - if (args.size == 1) { - StringUtil.copyPartialMatches( - args[0], - Bukkit.getOnlinePlayers().map { player -> player.name }.toCollection(ArrayList()), - completions - ) - return@TabCompleteHandler completions - } - - if (args.size == 2) { - StringUtil.copyPartialMatches( - args[1], - Boosters.names(), - completions - ) - return@TabCompleteHandler completions - } - - return@TabCompleteHandler emptyList() + if (args.size == 1) { + StringUtil.copyPartialMatches( + args[0], + Bukkit.getOnlinePlayers().map { player -> player.name }.toCollection(ArrayList()), + completions + ) + return completions } + + if (args.size == 2) { + StringUtil.copyPartialMatches( + args[1], + Boosters.names(), + completions + ) + return completions + } + + return emptyList() } -} \ No newline at end of file +} diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/commands/CommandReload.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/commands/CommandReload.kt index b440cee..e2f1ac4 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/commands/CommandReload.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/commands/CommandReload.kt @@ -1,7 +1,6 @@ package com.willfp.boosters.commands import com.willfp.eco.core.EcoPlugin -import com.willfp.eco.core.command.CommandHandler import com.willfp.eco.core.command.impl.Subcommand import org.bukkit.command.CommandSender @@ -12,10 +11,9 @@ class CommandReload(plugin: EcoPlugin) : "boosters.command.reload", false ) { - override fun getHandler(): CommandHandler { - return CommandHandler { sender: CommandSender, _: List -> - plugin.reload() - sender.sendMessage(plugin.langYml.getMessage("reloaded")) - } + + override fun onExecute(sender: CommandSender, args: List) { + plugin.reload() + sender.sendMessage(plugin.langYml.getMessage("reloaded")) } } \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/gui/BoosterGUI.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/gui/BoosterGUI.kt index bde5a49..7a9349f 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/gui/BoosterGUI.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/gui/BoosterGUI.kt @@ -6,12 +6,13 @@ import com.willfp.boosters.activeBooster import com.willfp.boosters.boosters.Booster import com.willfp.boosters.boosters.Boosters import com.willfp.boosters.getAmountOfBooster -import com.willfp.eco.core.gui.menu.Menu +import com.willfp.eco.core.gui.menu +import com.willfp.eco.core.gui.slot import com.willfp.eco.core.gui.slot.FillerMask -import com.willfp.eco.core.gui.slot.Slot import com.willfp.eco.core.gui.slot.functional.SlotHandler import com.willfp.eco.core.items.builder.SkullBuilder import com.willfp.eco.util.StringUtils +import com.willfp.eco.util.formatEco import com.willfp.ecoskills.tryAsPlayer import org.bukkit.Bukkit import org.bukkit.Material @@ -51,8 +52,8 @@ object BoosterGUI { } } - private val gui = Menu.builder(3) - .setMask( + private val gui = menu(3) { + setMask( FillerMask( Material.BLACK_STAINED_GLASS_PANE, "111111111", @@ -60,16 +61,16 @@ object BoosterGUI { "111111111" ) ) - .setSlot( + setSlot( 2, 2, - Slot.builder( + slot( SkullBuilder() .setSkullTexture("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYTM0YjI3YmZjYzhmOWI5NjQ1OTRiNjE4YjExNDZhZjY5ZGUyNzhjZTVlMmUzMDEyY2I0NzFhOWEzY2YzODcxIn19fQ==") .build() - ) - .setModifier { player, _, previous -> - val meta = previous.itemMeta ?: return@setModifier + ) { + setUpdater { player, _, previous -> + val meta = previous.itemMeta ?: return@setUpdater previous val lore = mutableListOf() lore.add("") @@ -87,25 +88,23 @@ object BoosterGUI { meta.setDisplayName(StringUtils.format("&d1.5x Sell Multiplier")) - meta.lore = lore.apply { - replaceAll { StringUtils.format(it) } - } + meta.lore = lore.formatEco() previous.itemMeta = meta - + previous } - .onLeftClick(makeHandler(Boosters.SELL_MULTIPLIER_LOW)) - .build() - ) - .setSlot( + onLeftClick(makeHandler(Boosters.SELL_MULTIPLIER_LOW)) + }) + + setSlot( 2, 5, - Slot.builder( + slot( SkullBuilder() .setSkullTexture("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYjBhN2I5NGM0ZTU4MWI2OTkxNTlkNDg4NDZlYzA5MTM5MjUwNjIzN2M4OWE5N2M5MzI0OGEwZDhhYmM5MTZkNSJ9fX0=") .build() - ) - .setModifier { player, _, previous -> - val meta = previous.itemMeta ?: return@setModifier + ) { + setUpdater { player, _, previous -> + val meta = previous.itemMeta ?: return@setUpdater previous val lore = mutableListOf() lore.add("") @@ -127,21 +126,22 @@ object BoosterGUI { replaceAll { StringUtils.format(it) } } previous.itemMeta = meta - + previous } - .onLeftClick(makeHandler(Boosters.SELL_MULTIPLIER_HIGH)) - .build() + onLeftClick(makeHandler(Boosters.SELL_MULTIPLIER_HIGH)) + build() + } ) - .setSlot( + setSlot( 2, 8, - Slot.builder( + slot( SkullBuilder() .setSkullTexture("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvODkyNmMxZjJjM2MxNGQwODZjNDBjZmMyMzVmZTkzODY5NGY0YTUxMDY3YWRhNDcyNmI0ODZlYTFjODdiMDNlMiJ9fX0=") .build() - ) - .setModifier { player, _, previous -> - val meta = previous.itemMeta ?: return@setModifier + ) { + setUpdater { player, _, previous -> + val meta = previous.itemMeta ?: return@setUpdater previous val lore = mutableListOf() lore.add("") @@ -163,13 +163,13 @@ object BoosterGUI { replaceAll { StringUtils.format(it) } } previous.itemMeta = meta - + previous } - .onLeftClick(makeHandler(Boosters.SKILL_XP)) - .build() + onLeftClick(makeHandler(Boosters.SKILL_XP)) + } ) - .setTitle("Boosters") - .build() + setTitle("Boosters") + } fun open(player: Player) { gui.open(player) diff --git a/eco-core/core-plugin/src/main/resources/plugin.yml b/eco-core/core-plugin/src/main/resources/plugin.yml index b4b7af9..e30fb53 100644 --- a/eco-core/core-plugin/src/main/resources/plugin.yml +++ b/eco-core/core-plugin/src/main/resources/plugin.yml @@ -10,8 +10,6 @@ depend: - PlaceholderAPI - EcoSkills - ShopGUIPlus -libraries: - - org.jetbrains.kotlin:kotlin-stdlib:1.5.21 commands: boosters: diff --git a/gradle.properties b/gradle.properties index efa3f79..18e68f7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ -version = 1.1.2 +version = 1.2.0 plugin-name = Boosters \ No newline at end of file