mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2024-11-22 15:05:18 +01:00
Merge pull request #307
Added /ecoenchants <giverandombook> <player> <type/rarity> <minLevel> <maxLevel> command
This commit is contained in:
commit
8728f080fb
@ -14,5 +14,6 @@ class CommandEcoEnchants(plugin: EcoPlugin) : PluginCommand(plugin, "ecoenchants
|
||||
init {
|
||||
addSubcommand(CommandReload(plugin))
|
||||
.addSubcommand(CommandToggleDescriptions(plugin))
|
||||
.addSubcommand(CommandGiveRandomBook(plugin))
|
||||
}
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
package com.willfp.ecoenchants.commands
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin
|
||||
import com.willfp.eco.core.command.impl.PluginCommand
|
||||
import com.willfp.eco.core.items.builder.EnchantedBookBuilder
|
||||
import com.willfp.ecoenchants.display.getFormattedName
|
||||
import com.willfp.ecoenchants.enchants.EcoEnchants
|
||||
import com.willfp.ecoenchants.enchants.wrap
|
||||
import com.willfp.ecoenchants.rarity.EnchantmentRarities
|
||||
import com.willfp.ecoenchants.rarity.EnchantmentRarity
|
||||
import com.willfp.ecoenchants.type.EnchantmentType
|
||||
import com.willfp.ecoenchants.type.EnchantmentTypes
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.command.CommandSender
|
||||
import org.bukkit.entity.Player
|
||||
|
||||
|
||||
class CommandGiveRandomBook(plugin: EcoPlugin) : PluginCommand(
|
||||
plugin, "giverandombook", "ecoenchants.command.giverandombook", false
|
||||
) {
|
||||
override fun onExecute(sender: CommandSender, args: List<String>) {
|
||||
val player = (args.firstOrNull()?: run { sender
|
||||
.sendMessage(plugin.langYml.getMessage("requires-player")); return }).asPlayer()?: run {
|
||||
sender.sendMessage(plugin.langYml.getMessage("invalid-player"))
|
||||
return
|
||||
}
|
||||
|
||||
val filter = args.getOrNull(1)?.asRarity()?: args.getOrNull(1)?.asType()
|
||||
val minLevel = args.getOrNull(2)?.toIntOrNull()?: 1
|
||||
val maxLevel = args.getOrNull(3)?.toIntOrNull()?: Int.MAX_VALUE
|
||||
|
||||
if (minLevel > maxLevel) {
|
||||
sender.sendMessage(plugin.langYml.getMessage("invalid-levels"))
|
||||
return
|
||||
}
|
||||
|
||||
val enchantment = EcoEnchants.values()
|
||||
.filter {
|
||||
when (filter) {
|
||||
is EnchantmentRarity -> it.enchantmentRarity == filter
|
||||
is EnchantmentType -> it.type == filter
|
||||
else -> true
|
||||
} && it.maxLevel >= minLevel
|
||||
}
|
||||
.randomOrNull()?: run {
|
||||
sender.sendMessage(plugin.langYml.getMessage("no-enchantments-found"))
|
||||
return
|
||||
}
|
||||
|
||||
val level = (minLevel..maxLevel.coerceAtMost(enchantment.maxLevel)).random()
|
||||
|
||||
player.inventory.addItem(EnchantedBookBuilder()
|
||||
.addStoredEnchantment(enchantment, level)
|
||||
.build()).values.forEach {
|
||||
player.world.dropItem(player.location, it)
|
||||
}
|
||||
sender.sendMessage(plugin.langYml.getMessage("random-book-given")
|
||||
.replace("%playername%", player.name)
|
||||
.replace("%enchantment%", enchantment.wrap()
|
||||
.getFormattedName(level)))
|
||||
}
|
||||
|
||||
override fun tabComplete(sender: CommandSender, args: List<String>): List<String> {
|
||||
return when (args.size) {
|
||||
1 -> Bukkit.getOnlinePlayers().map { it.name }
|
||||
2 -> (EnchantmentRarities.values().map { it.id } + EnchantmentTypes.values().map { it.id })
|
||||
3 -> (1..10).map { it.toString() }
|
||||
4 -> ((args[3].toIntOrNull()?: 1)..(args[3].toIntOrNull()?: 1)+10).map { it.toString() }
|
||||
else -> emptyList()
|
||||
}
|
||||
}
|
||||
|
||||
private fun String.asPlayer(): Player? {
|
||||
return Bukkit.getPlayer(this)
|
||||
}
|
||||
|
||||
private fun String.asRarity(): EnchantmentRarity? {
|
||||
return EnchantmentRarities.getByID(this.lowercase())
|
||||
}
|
||||
|
||||
private fun String.asType(): EnchantmentType? {
|
||||
return EnchantmentTypes.getByID(this.lowercase())
|
||||
}
|
||||
}
|
@ -19,7 +19,7 @@ enchantable: true
|
||||
effects:
|
||||
- id: damage_multiplier
|
||||
args:
|
||||
multiplier: "1 + (%distance% / (11 - ceil(%level / 2))) * 0.01 * %level%"
|
||||
multiplier: "1 + (%distance% / (11 - ceil(%level% / 2))) * 0.01 * %level%"
|
||||
triggers:
|
||||
- bow_attack
|
||||
|
||||
|
@ -14,6 +14,9 @@ messages:
|
||||
descriptions-disabled: "&cEnchantment descriptions are disabled on this server."
|
||||
not-found: "&cCannot find an enchantment matching name: &f%name%."
|
||||
missing-enchant: "&cYou must specify an enchantment!"
|
||||
random-book-given: "&fYou have been given &a%playername%&f a &r%enchantment%&f random book!"
|
||||
no-enchantments-found: "&cNo enchantments found!"
|
||||
invalid-levels: "&cMinimum level can't be higher than maximum level!"
|
||||
|
||||
all: "All"
|
||||
no-conflicts: "No Conflicts"
|
@ -45,6 +45,7 @@ permissions:
|
||||
ecoenchants.command.reload: true
|
||||
ecoenchants.command.ecoenchants: true
|
||||
ecoenchants.command.toggledescriptions: true
|
||||
ecoenchants.command.giverandombook: true
|
||||
ecoenchants.command.enchantinfo: true
|
||||
ecoenchants.anvil.*:
|
||||
description: All anvil perks
|
||||
@ -58,6 +59,9 @@ permissions:
|
||||
ecoenchants.command.reload:
|
||||
description: Allows reloading the config
|
||||
default: op
|
||||
ecoenchants.command.giverandombook:
|
||||
description: Allows giving random books
|
||||
default: op
|
||||
ecoenchants.command.ecoenchants:
|
||||
description: Allows the use of /ecoenchants.
|
||||
default: true
|
||||
|
Loading…
Reference in New Issue
Block a user