diff --git a/api/src/main/kotlin/com/artillexstudios/axminions/api/config/Config.kt b/api/src/main/kotlin/com/artillexstudios/axminions/api/config/Config.kt index 2f1eb3c..f3bb70c 100644 --- a/api/src/main/kotlin/com/artillexstudios/axminions/api/config/Config.kt +++ b/api/src/main/kotlin/com/artillexstudios/axminions/api/config/Config.kt @@ -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
("charge.items") + @JvmStatic fun TIMER_FORMAT() = AxMinionsAPI.INSTANCE.getConfig().get("timer-format", 1) @JvmStatic fun GUI_SIZE() = AxMinionsAPI.INSTANCE.getConfig().get("gui.size") @@ -105,6 +108,10 @@ class Config(file: File, stream: InputStream) { } } + fun save() { + this.config.save() + } + fun get(route: String?): T { return this.config.get(route) } diff --git a/api/src/main/kotlin/com/artillexstudios/axminions/api/config/Messages.kt b/api/src/main/kotlin/com/artillexstudios/axminions/api/config/Messages.kt index dedb2d6..1f20cef 100644 --- a/api/src/main/kotlin/com/artillexstudios/axminions/api/config/Messages.kt +++ b/api/src/main/kotlin/com/artillexstudios/axminions/api/config/Messages.kt @@ -77,6 +77,8 @@ class Messages(file: File, stream: InputStream) { fun LINK_START() = AxMinionsAPI.INSTANCE.getMessages().get("link.start") @JvmStatic fun UPGRADE_FAIL() = AxMinionsAPI.INSTANCE.getMessages().get("upgrades.fail") + @JvmStatic + fun LOCATION_FORMAT() = AxMinionsAPI.INSTANCE.getMessages().get("location-format") } private val config = Config( diff --git a/common/src/main/kotlin/com/artillexstudios/axminions/commands/AxMinionsCommand.kt b/common/src/main/kotlin/com/artillexstudios/axminions/commands/AxMinionsCommand.kt index 728e906..661d31c 100644 --- a/common/src/main/kotlin/com/artillexstudios/axminions/commands/AxMinionsCommand.kt +++ b/common/src/main/kotlin/com/artillexstudios/axminions/commands/AxMinionsCommand.kt @@ -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") diff --git a/common/src/main/kotlin/com/artillexstudios/axminions/listeners/MinionInventoryListener.kt b/common/src/main/kotlin/com/artillexstudios/axminions/listeners/MinionInventoryListener.kt index cca3191..07d9ab6 100644 --- a/common/src/main/kotlin/com/artillexstudios/axminions/listeners/MinionInventoryListener.kt +++ b/common/src/main/kotlin/com/artillexstudios/axminions/listeners/MinionInventoryListener.kt @@ -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()) { diff --git a/common/src/main/kotlin/com/artillexstudios/axminions/minions/Minion.kt b/common/src/main/kotlin/com/artillexstudios/axminions/minions/Minion.kt index 7377eed..e4b0c95 100644 --- a/common/src/main/kotlin/com/artillexstudios/axminions/minions/Minion.kt +++ b/common/src/main/kotlin/com/artillexstudios/axminions/minions/Minion.kt @@ -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("", location.world!!.name).replace("", location.blockX.toString()).replace("", location.blockY.toString()).replace("", location.blockZ.toString()) } ) item = ItemBuilder( diff --git a/common/src/main/resources/config.yml b/common/src/main/resources/config.yml index 57a86af..a2bd36b 100644 --- a/common/src/main/resources/config.yml +++ b/common/src/main/resources/config.yml @@ -76,6 +76,11 @@ charge: max-charge: 1440 # in minutes price: 10000 minimum-charge: 30 # in seconds + items: + 1: + type: coal + name: "Fuel" + charge: 1000 # In seconds # 1 - HH:MM:SS, for example 01:25:35 # 2 - short format, for example 20m diff --git a/common/src/main/resources/messages.yml b/common/src/main/resources/messages.yml index 5cf6c97..e3264e8 100644 --- a/common/src/main/resources/messages.yml +++ b/common/src/main/resources/messages.yml @@ -74,5 +74,7 @@ charge: tools: wrong-tool: "You can't place this item as the tool if this minion!" +location-format: ";;;" + # Do not change! -config-version: 6 \ No newline at end of file +config-version: 7 \ No newline at end of file