From 461e1cab03cab858dabee875090dca16fdf88e42 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Tue, 14 Dec 2021 10:55:30 +0000 Subject: [PATCH] eco 6.17.0 migration --- .../willfp/talismans/command/CommandGive.kt | 157 +++++++++--------- .../willfp/talismans/command/CommandReload.kt | 13 +- .../talismans/command/CommandTalismans.kt | 11 +- .../willfp/talismans/config/TalismansYml.kt | 4 +- 4 files changed, 90 insertions(+), 95 deletions(-) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/talismans/command/CommandGive.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/talismans/command/CommandGive.kt index 5663d2b..4ca8af8 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/talismans/command/CommandGive.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/talismans/command/CommandGive.kt @@ -1,12 +1,11 @@ package com.willfp.talismans.command 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.talismans.talismans.Talismans import com.willfp.talismans.talismans.Talismans.getByID import org.bukkit.Bukkit +import org.bukkit.command.CommandSender import org.bukkit.util.StringUtil class CommandGive(plugin: EcoPlugin) : Subcommand(plugin, "reload", "talismans.commands.reload", false) { @@ -21,88 +20,84 @@ class CommandGive(plugin: EcoPlugin) : Subcommand(plugin, "reload", "talismans.c "64" ) - override fun getHandler(): CommandHandler? { - return CommandHandler { sender, args -> - if (args.isEmpty()) { - sender.sendMessage(plugin.langYml.getMessage("needs-player")) - return@CommandHandler - } - - if (args.size == 1) { - sender.sendMessage(plugin.langYml.getMessage("needs-talisman")) - return@CommandHandler - } - - var amount = 1 - if (args.size > 2) { - amount = args[2].toIntOrNull() ?: 1 - } - - val recieverName = args[0] - val reciever = Bukkit.getPlayer(recieverName) - - if (reciever == null) { - sender.sendMessage(plugin.langYml.getMessage("invalid-player")) - return@CommandHandler - } - - val talismanName = args[1] - val talisman = getByID(talismanName) - - if (talisman == null) { - sender.sendMessage(plugin.langYml.getMessage("invalid-talisman")) - return@CommandHandler - } - - var message = plugin.langYml.getMessage("give-success") - - message = message.replace("%talisman%", talisman.name).replace("%recipient%", reciever.name) - - sender.sendMessage(message) - - val itemStack = talisman.itemStack - - itemStack.amount = amount - - reciever.inventory.addItem(itemStack) + override fun onExecute(sender: CommandSender, args: List) { + if (args.isEmpty()) { + sender.sendMessage(plugin.langYml.getMessage("needs-player")) + return } + + if (args.size == 1) { + sender.sendMessage(plugin.langYml.getMessage("needs-talisman")) + return + } + + var amount = 1 + if (args.size > 2) { + amount = args[2].toIntOrNull() ?: 1 + } + + val recieverName = args[0] + val reciever = Bukkit.getPlayer(recieverName) + + if (reciever == null) { + sender.sendMessage(plugin.langYml.getMessage("invalid-player")) + return + } + + val talismanName = args[1] + val talisman = getByID(talismanName) + + if (talisman == null) { + sender.sendMessage(plugin.langYml.getMessage("invalid-talisman")) + return + } + + var message = plugin.langYml.getMessage("give-success") + + message = message.replace("%talisman%", talisman.name).replace("%recipient%", reciever.name) + + sender.sendMessage(message) + + val itemStack = talisman.itemStack + + itemStack.amount = amount + + reciever.inventory.addItem(itemStack) } - override fun getTabCompleter(): TabCompleteHandler { - return TabCompleteHandler { _, args -> - val completions = mutableListOf() + override fun tabComplete(sender: CommandSender, args: List): List { + val completions = mutableListOf() - if (args.isEmpty()) { - return@TabCompleteHandler Talismans.values().map { it.id } - } - - if (args.size == 1) { - StringUtil.copyPartialMatches( - args[0], - Bukkit.getOnlinePlayers().map { it.name }, - completions - ) - } - - if (args.size == 2) { - StringUtil.copyPartialMatches( - args[1], - Talismans.values().map { it.id }, - completions - ) - } - - - - if (args.size == 3) { - StringUtil.copyPartialMatches( - args[2], - numbers, - completions - ) - } - - completions + if (args.isEmpty()) { + return Talismans.values().map { it.id } } + + if (args.size == 1) { + StringUtil.copyPartialMatches( + args[0], + Bukkit.getOnlinePlayers().map { it.name }, + completions + ) + } + + if (args.size == 2) { + StringUtil.copyPartialMatches( + args[1], + Talismans.values().map { it.id }, + completions + ) + } + + + + if (args.size == 3) { + StringUtil.copyPartialMatches( + args[2], + numbers, + completions + ) + } + + return completions } -} \ No newline at end of file +} diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/talismans/command/CommandReload.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/talismans/command/CommandReload.kt index ea6acb1..b294d7a 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/talismans/command/CommandReload.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/talismans/command/CommandReload.kt @@ -3,15 +3,14 @@ package com.willfp.talismans.command 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 class CommandReload(plugin: EcoPlugin) : Subcommand(plugin, "reload", "talismans.commands.reload", false) { - override fun getHandler(): CommandHandler { - return CommandHandler { sender, _ -> - sender.sendMessage( - plugin.langYml.getMessage("reloaded") - .replace("%time%", plugin.reloadWithTime().toString() + "") - ) - } + override fun onExecute(sender: CommandSender, args: List) { + sender.sendMessage( + plugin.langYml.getMessage("reloaded") + .replace("%time%", plugin.reloadWithTime().toString() + "") + ) } } \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/talismans/command/CommandTalismans.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/talismans/command/CommandTalismans.kt index 13793e5..6ccc966 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/talismans/command/CommandTalismans.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/talismans/command/CommandTalismans.kt @@ -3,6 +3,7 @@ package com.willfp.talismans.command 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 class CommandTalismans(plugin: EcoPlugin) : PluginCommand(plugin, "talismans", "talismans.command.talismans", false) { @@ -11,11 +12,9 @@ class CommandTalismans(plugin: EcoPlugin) .addSubcommand(CommandGive(plugin)) } - override fun getHandler(): CommandHandler { - return CommandHandler { sender, _ -> - sender.sendMessage( - plugin.langYml.getMessage("invalid-command") - ) - } + override fun onExecute(sender: CommandSender, args: List) { + sender.sendMessage( + plugin.langYml.getMessage("invalid-command") + ) } } \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/talismans/config/TalismansYml.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/talismans/config/TalismansYml.kt index ef59bd7..db992d5 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/talismans/config/TalismansYml.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/talismans/config/TalismansYml.kt @@ -1,6 +1,8 @@ package com.willfp.talismans.config import com.willfp.eco.core.EcoPlugin +import com.willfp.eco.core.config.BaseConfig +import com.willfp.eco.core.config.ConfigType import com.willfp.eco.core.config.yaml.YamlBaseConfig -class TalismansYml(plugin: EcoPlugin) : YamlBaseConfig("talismans", false, plugin) \ No newline at end of file +class TalismansYml(plugin: EcoPlugin) : BaseConfig("talismans", plugin, false, ConfigType.YAML) \ No newline at end of file