eco 6.17.0 migration
This commit is contained in:
@@ -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<String>) {
|
||||
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<String>()
|
||||
override fun tabComplete(sender: CommandSender, args: List<String>): List<String> {
|
||||
val completions = mutableListOf<String>()
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<String>) {
|
||||
sender.sendMessage(
|
||||
plugin.langYml.getMessage("reloaded")
|
||||
.replace("%time%", plugin.reloadWithTime().toString() + "")
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -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<String>) {
|
||||
sender.sendMessage(
|
||||
plugin.langYml.getMessage("invalid-command")
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
class TalismansYml(plugin: EcoPlugin) : BaseConfig("talismans", plugin, false, ConfigType.YAML)
|
||||
Reference in New Issue
Block a user