Reload feature, vault integration, complete all
- /shop - /shop reload - Buy Item by left click - Sell Item by right click - Sell all with middle/shift click - Items to execute commands - Automatic pages - Automatic menu rowmaster
parent
1e4f3dab01
commit
3a5cd8cda1
@ -1,6 +1,81 @@
|
||||
package pw.hamzantal.shopreborn
|
||||
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.ChatColor
|
||||
import org.bukkit.Material
|
||||
import org.bukkit.configuration.ConfigurationSection
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.inventory.Inventory
|
||||
import org.bukkit.inventory.ItemStack
|
||||
|
||||
val String.c
|
||||
get() = ChatColor.translateAlternateColorCodes('&', this)
|
||||
val String.c: String
|
||||
get() = ChatColor.translateAlternateColorCodes('&', this)
|
||||
|
||||
fun Material.prettyName() = name.split("_").joinToString(" ") { it.toLowerCase().capitalize() }
|
||||
|
||||
fun ItemStack.setLore(s: String): ItemStack {
|
||||
return apply {
|
||||
itemMeta = itemMeta.apply {
|
||||
lore = listOf(s.c)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun ItemStack.addLore(s: String): ItemStack {
|
||||
return apply {
|
||||
itemMeta = itemMeta.apply {
|
||||
lore = lore + s.c
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun makeInventory(size: Int, title: String, menuRow: Int = -1, items: List<ShopConfig.Block>, page: Int): Inventory {
|
||||
return Bukkit.createInventory(null, size, title.c).apply {
|
||||
if (menuRow > 0) {
|
||||
val buttons = GlobalConfig.main.buttons
|
||||
for (i in menuRow until menuRow + 9) {
|
||||
setItem(i, buttons.pane)
|
||||
}
|
||||
setItem(menuRow, buttons.previous)
|
||||
setItem(menuRow + 4, buttons.menu)
|
||||
setItem(menuRow + 8, buttons.forward)
|
||||
}
|
||||
|
||||
val dropping = (page - 1) * (size - kotlin.math.max(0, menuRow))
|
||||
items.drop(dropping).forEach {
|
||||
if (firstEmpty() != -1) setItem(firstEmpty(), it.item)
|
||||
else return@apply
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun String.mixPlaceholder(amount: Int = 0, price: Double = 0.0): String =
|
||||
replace("%AMOUNT%", amount.toString())
|
||||
.replace(
|
||||
"%PRICE%",
|
||||
price.withCurrency()
|
||||
)
|
||||
.c
|
||||
|
||||
fun Double.withCurrency() = String.format("%s%.2f", GlobalConfig.messages.currency, this)
|
||||
|
||||
fun ConfigurationSection.asItem(buy: Double = -1.0, sell: Double = -1.0): ItemStack {
|
||||
val material = Material.valueOf(getString("material").toUpperCase())
|
||||
val item = ItemStack(material, getInt("quantity", 1), getInt("damage", 0).toShort())
|
||||
|
||||
item.itemMeta = item.itemMeta.apply {
|
||||
displayName = getString("name", "").c
|
||||
val configLore = getStringList("lore").map { it.c }.toMutableList()
|
||||
val messages = GlobalConfig.messages
|
||||
|
||||
if (buy > 0) configLore += messages.buyLore.mixPlaceholder(price = buy)
|
||||
if (sell > 0) configLore += messages.sellLore.mixPlaceholder(price = sell)
|
||||
|
||||
lore = configLore
|
||||
}
|
||||
return item
|
||||
}
|
||||
|
||||
infix fun Player.containing(item: ItemStack): Int {
|
||||
return inventory.contents.sumBy { if (it?.isSimilar(item) == true) it.amount else 0 }
|
||||
}
|
Loading…
Reference in New Issue