Location formatting, item fuels, some fixes

This commit is contained in:
TomTom 2024-05-18 16:11:19 +02:00
parent c35bae34da
commit f01db6ede0
7 changed files with 76 additions and 9 deletions

View File

@ -1,6 +1,7 @@
package com.artillexstudios.axminions.api.config
import com.artillexstudios.axapi.config.Config
import com.artillexstudios.axapi.libs.boostedyaml.boostedyaml.block.implementation.Section
import com.artillexstudios.axapi.libs.boostedyaml.boostedyaml.dvs.versioning.BasicVersioning
import com.artillexstudios.axapi.libs.boostedyaml.boostedyaml.settings.dumper.DumperSettings
import com.artillexstudios.axapi.libs.boostedyaml.boostedyaml.settings.general.GeneralSettings
@ -52,6 +53,8 @@ class Config(file: File, stream: InputStream) {
@JvmStatic
fun MINIMUM_CHARGE() = AxMinionsAPI.INSTANCE.getConfig().get("charge.minimum-charge", 30)
@JvmStatic
fun CHARGE_ITEMS() = AxMinionsAPI.INSTANCE.getConfig().get<Section>("charge.items")
@JvmStatic
fun TIMER_FORMAT() = AxMinionsAPI.INSTANCE.getConfig().get("timer-format", 1)
@JvmStatic
fun GUI_SIZE() = AxMinionsAPI.INSTANCE.getConfig().get<Int>("gui.size")
@ -105,6 +108,10 @@ class Config(file: File, stream: InputStream) {
}
}
fun save() {
this.config.save()
}
fun <T> get(route: String?): T {
return this.config.get(route)
}

View File

@ -77,6 +77,8 @@ class Messages(file: File, stream: InputStream) {
fun LINK_START() = AxMinionsAPI.INSTANCE.getMessages().get<String>("link.start")
@JvmStatic
fun UPGRADE_FAIL() = AxMinionsAPI.INSTANCE.getMessages().get<String>("upgrades.fail")
@JvmStatic
fun LOCATION_FORMAT() = AxMinionsAPI.INSTANCE.getMessages().get<String>("location-format")
}
private val config = Config(

View File

@ -1,13 +1,17 @@
package com.artillexstudios.axminions.commands
import com.artillexstudios.axapi.utils.ItemBuilder
import com.artillexstudios.axapi.utils.StringUtils
import com.artillexstudios.axminions.AxMinionsPlugin
import com.artillexstudios.axminions.api.AxMinionsAPI
import com.artillexstudios.axminions.api.config.Config
import com.artillexstudios.axminions.api.config.Messages
import com.artillexstudios.axminions.api.minions.miniontype.MinionType
import com.artillexstudios.axminions.api.minions.miniontype.MinionTypes
import com.artillexstudios.axminions.api.utils.fastFor
import com.artillexstudios.axminions.converter.LitMinionsConverter
import net.kyori.adventure.platform.bukkit.BukkitAudiences
import net.kyori.adventure.text.minimessage.MiniMessage
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder
import org.bukkit.command.CommandSender
import org.bukkit.entity.Player
@ -39,6 +43,28 @@ class AxMinionsCommand {
receiver.inventory.addItem(item)
}
@Subcommand("fuel")
@CommandPermission("axminions.command.fuel")
class Fuel {
@Subcommand("give")
@CommandPermission("axminions.command.fuel.give")
fun give(sender: CommandSender, id: String, receiver: Player, @Default("1") amount: Int) {
val item = ItemBuilder(Config.CHARGE_ITEMS().getSection(id)).get()
item.amount = amount
receiver.inventory.addItem(item)
}
@Subcommand("add")
@CommandPermission("axminions.command.fuel.add")
fun add(player: Player, id: String, charge: Int) {
val item = ItemBuilder(player.inventory.itemInMainHand).serialize(true)
item["charge"] = charge
AxMinionsPlugin.config.getConfig().set("charge.items.$id", item)
}
}
@Subcommand("reset")
@CommandPermission("axminions.command.reset")
@Description("Reset player's minion")

View File

@ -1,5 +1,6 @@
package com.artillexstudios.axminions.listeners
import com.artillexstudios.axapi.utils.ItemBuilder
import com.artillexstudios.axapi.utils.StringUtils
import com.artillexstudios.axminions.AxMinionsPlugin
import com.artillexstudios.axminions.api.AxMinionsAPI
@ -11,6 +12,7 @@ import com.artillexstudios.axminions.api.minions.miniontype.MinionTypes
import com.artillexstudios.axminions.api.utils.CoolDown
import com.artillexstudios.axminions.api.utils.Keys
import com.artillexstudios.axminions.api.utils.fastFor
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver
import java.util.Locale
import net.md_5.bungee.api.ChatMessageType
import net.md_5.bungee.api.chat.TextComponent
@ -200,21 +202,36 @@ class MinionInventoryListener : Listener {
return
}
AxMinionsPlugin.integrations.getEconomyIntegration()?.let {
minion.getOwner()?.let { player ->
it.takeBalance(player, Config.CHARGE_PRICE())
var chargeAmount = Config.CHARGE_AMOUNT()
var itemCharge = false
val section = Config.CHARGE_ITEMS()
for (key in section.keys) {
val item = ItemBuilder(section.getSection(key.toString())).get()
if (player.inventory.containsAtLeast(item, 1)) {
itemCharge = true
chargeAmount = section.getSection(key.toString()).getInt("charge")
player.inventory.removeItem(item)
}
}
if (chargeSeconds + Config.CHARGE_AMOUNT() > Config.MAX_CHARGE() * 60L) {
if (!itemCharge) {
AxMinionsPlugin.integrations.getEconomyIntegration()?.let {
minion.getOwner()?.let { player ->
it.takeBalance(player, Config.CHARGE_PRICE())
}
}
}
if (chargeSeconds + chargeAmount > Config.MAX_CHARGE() * 60L) {
minion.setCharge(System.currentTimeMillis() + Config.MAX_CHARGE() * 60L * 1000L)
return
}
if (minion.getCharge() < System.currentTimeMillis()) {
minion.setCharge(System.currentTimeMillis() + Config.CHARGE_AMOUNT() * 1000)
minion.setCharge(System.currentTimeMillis() + chargeAmount * 1000)
} else {
minion.setCharge(minion.getCharge() + Config.CHARGE_AMOUNT() * 1000)
minion.setCharge(minion.getCharge() + chargeAmount * 1000)
}
if (Messages.CHARGE().isNotBlank()) {

View File

@ -240,6 +240,13 @@ class Minion(
else -> (this.level + 1).toString()
}
)
val nextStorage = Placeholder.parsed(
"next_storage",
if (type.hasReachedMaxLevel(this)) Messages.UPGRADES_MAX_LEVEL_REACHED() else type.getDouble(
"storage",
this.level + 1
).toString()
)
val range = Placeholder.parsed("range", type.getDouble("range", this.level).toString())
val nextRange = Placeholder.parsed(
"next_range",
@ -305,7 +312,8 @@ class Minion(
stored,
actions,
multiplier,
nextMultiplier
nextMultiplier,
nextStorage
).get()
val meta = item.itemMeta!!
@ -329,7 +337,7 @@ class Minion(
val linked = Placeholder.unparsed(
"linked", when (linkedChest) {
null -> "---"
else -> Serializers.LOCATION.serialize(linkedChest)
else -> Messages.LOCATION_FORMAT().replace("<world>", location.world!!.name).replace("<x>", location.blockX.toString()).replace("<y>", location.blockY.toString()).replace("<z>", location.blockZ.toString())
}
)
item = ItemBuilder(

View File

@ -76,6 +76,11 @@ charge:
max-charge: 1440 # in minutes
price: 10000
minimum-charge: 30 # in seconds
items:
1:
type: coal
name: "<red>Fuel"
charge: 1000 # In seconds
# 1 - HH:MM:SS, for example 01:25:35
# 2 - short format, for example 20m

View File

@ -74,5 +74,7 @@ charge:
tools:
wrong-tool: "<red>You can't place this item as the tool if this minion!"
location-format: "<world>;<x>;<y>;<z>"
# Do not change!
config-version: 6
config-version: 7