Add messages.yml and functionality to purchase GUI
The plugin now has a functioning messages.yml that has the options to set messages (improving customisability), as well as the shop now has a working buy menu where u can see the price changes and what not. Supports prices and rounding to 2 decimal places.master
parent
34008d5d6b
commit
1e4f3dab01
@ -0,0 +1,44 @@
|
|||||||
|
package pw.hamzantal.shopreborn
|
||||||
|
|
||||||
|
import hazae41.minecraft.kutils.bukkit.ConfigFile
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
class Messages(file: File, pl: ShopReborn) : ConfigFile(file) {
|
||||||
|
val currency by string("currency", "$")
|
||||||
|
|
||||||
|
val buyLore by string("buyLore")
|
||||||
|
val sellLore by string("stringLore")
|
||||||
|
val itemLore by string("itemLore")
|
||||||
|
|
||||||
|
val set1 by string("set1")
|
||||||
|
val sub10 by string("sub10")
|
||||||
|
val sub1 by string("sub1")
|
||||||
|
|
||||||
|
val add1 by string("add1")
|
||||||
|
val add10 by string("add10")
|
||||||
|
val set64 by string("set64")
|
||||||
|
|
||||||
|
val sellConfirm by string("sell.confirm")
|
||||||
|
val sellAll by string("sell.sellAll")
|
||||||
|
val sellAllLore by string("sell.sellAllLore")
|
||||||
|
|
||||||
|
val buyConfirm by string("buy.confirm")
|
||||||
|
|
||||||
|
val cancel by string("cancel")
|
||||||
|
|
||||||
|
init {
|
||||||
|
if (!file.exists()) {
|
||||||
|
val messages = pl.getResource("messages.yml").bufferedReader().readLines().joinToString("\n")
|
||||||
|
file.createNewFile()
|
||||||
|
file.writeText(messages)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun String.mixPlaceholder(amount: Int = 0, price: Double = 0.0): String =
|
||||||
|
replace("%AMOUNT%", amount.toString())
|
||||||
|
.replace(
|
||||||
|
"%PRICE%",
|
||||||
|
String.format("%s%.2f", GlobalConfig.messages.currency, price)
|
||||||
|
)
|
||||||
|
.c
|
@ -0,0 +1,47 @@
|
|||||||
|
package pw.hamzantal.shopreborn
|
||||||
|
|
||||||
|
import org.bukkit.Material
|
||||||
|
import org.bukkit.inventory.ItemStack
|
||||||
|
|
||||||
|
object PurchaseItems {
|
||||||
|
fun paneStack(damage: Int, name: String): ItemStack {
|
||||||
|
return ItemStack(Material.STAINED_GLASS_PANE, 1, damage.toShort()).apply {
|
||||||
|
itemMeta = itemMeta.apply {
|
||||||
|
displayName = name.c
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun blockStack(damage: Int, name: String): ItemStack {
|
||||||
|
return ItemStack(Material.STAINED_GLASS, 1, damage.toShort()).apply {
|
||||||
|
itemMeta = itemMeta.apply {
|
||||||
|
displayName = name.c
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
val msgs = GlobalConfig.messages
|
||||||
|
val set1 = paneStack(14, msgs.set1)
|
||||||
|
val sub10 = paneStack(14, msgs.sub10)
|
||||||
|
val sub1 = paneStack(14, msgs.sub1)
|
||||||
|
|
||||||
|
val add1 = paneStack(5, msgs.add1)
|
||||||
|
val add10 = paneStack(5, msgs.add10)
|
||||||
|
val set64 = paneStack(5, msgs.set64)
|
||||||
|
|
||||||
|
val sellConfirm = blockStack(5, msgs.sellConfirm)
|
||||||
|
val sellAll = blockStack(5, msgs.sellAll)
|
||||||
|
|
||||||
|
val buyConfirm = blockStack(5, msgs.buyConfirm)
|
||||||
|
|
||||||
|
val cancel = blockStack(14, msgs.cancel)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun ItemStack.setLore(s: String): ItemStack {
|
||||||
|
return apply {
|
||||||
|
itemMeta = itemMeta.apply {
|
||||||
|
lore = listOf(s.c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
currency: "$"
|
||||||
|
|
||||||
|
buyLore: "&6Buy price: &c%PRICE%"
|
||||||
|
sellLore: "&6Sell price: &c%PRICE%"
|
||||||
|
itemLore: "&6Left click to buy, Right click to sell"
|
||||||
|
|
||||||
|
set1: "&c&lSet to 1"
|
||||||
|
sub10: "&c&lRemove 10"
|
||||||
|
sub1: "&c&lRemove 1"
|
||||||
|
|
||||||
|
add1: "&a&lAdd 1"
|
||||||
|
add10: "&a&lAdd 10"
|
||||||
|
set64: "&a&lSet 64"
|
||||||
|
|
||||||
|
# Confirm for selling/buying (after selecting the item)
|
||||||
|
sell:
|
||||||
|
confirm: "&a&lConfirm"
|
||||||
|
sellAll: "&a&lSell all"
|
||||||
|
sellAllLore: "&7Sell all for &a%PRICE%"
|
||||||
|
buy:
|
||||||
|
confirm: "&a&lConfirm"
|
||||||
|
cancel: "&c&lCancel"
|
Loading…
Reference in New Issue