New features, fixes

This commit is contained in:
TomTom 2024-01-30 17:32:19 +01:00
parent 60d1abcf32
commit 5481b8ac4a
15 changed files with 69 additions and 28 deletions

View File

@ -13,6 +13,7 @@
<option value="$PROJECT_DIR$/nms" /> <option value="$PROJECT_DIR$/nms" />
<option value="$PROJECT_DIR$/nms/v1_20_R1" /> <option value="$PROJECT_DIR$/nms/v1_20_R1" />
<option value="$PROJECT_DIR$/nms/v1_20_R2" /> <option value="$PROJECT_DIR$/nms/v1_20_R2" />
<option value="$PROJECT_DIR$/nms/v1_20_R3" />
</set> </set>
</option> </option>
</GradleProjectSettings> </GradleProjectSettings>

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="KotlinJpsPluginSettings"> <component name="KotlinJpsPluginSettings">
<option name="version" value="1.9.0" /> <option name="version" value="1.9.22" />
</component> </component>
</project> </project>

View File

@ -40,6 +40,10 @@ class Config(file: File, stream: InputStream) {
@JvmStatic @JvmStatic
fun GUI_SIZE() = AxMinionsAPI.INSTANCE.getConfig().get<Int>("gui.size") fun GUI_SIZE() = AxMinionsAPI.INSTANCE.getConfig().get<Int>("gui.size")
@JvmStatic @JvmStatic
fun PULL_FROM_CHEST() = AxMinionsAPI.INSTANCE.getConfig().get("pull-tools-from-chest", false)
@JvmStatic
fun PLACE_PERMISSION() = AxMinionsAPI.INSTANCE.getConfig().get("place-permissions", false)
@JvmStatic
fun DEBUG(): Boolean { fun DEBUG(): Boolean {
if (debug === null) { if (debug === null) {
debug = AxMinionsAPI.INSTANCE.getConfig().get("debug", false) debug = AxMinionsAPI.INSTANCE.getConfig().get("debug", false)

View File

@ -35,6 +35,8 @@ class Messages(file: File, stream: InputStream) {
@JvmStatic @JvmStatic
fun PLACE_MINION_AT_LOCATION() = AxMinionsAPI.INSTANCE.getMessages().get<String>("place.minion-at-location") fun PLACE_MINION_AT_LOCATION() = AxMinionsAPI.INSTANCE.getMessages().get<String>("place.minion-at-location")
@JvmStatic @JvmStatic
fun PLACE_MISSING_PERMISSION() = AxMinionsAPI.INSTANCE.getMessages().get<String>("place.missing-permission")
@JvmStatic
fun STATISTICS() = AxMinionsAPI.INSTANCE.getMessages().get<String>("statistics") fun STATISTICS() = AxMinionsAPI.INSTANCE.getMessages().get<String>("statistics")
@JvmStatic @JvmStatic
fun LEVEL_COLOR(level: Int = 1) = AxMinionsAPI.INSTANCE.getMessages().get("levels.$level", "<#33FF33>") fun LEVEL_COLOR(level: Int = 1) = AxMinionsAPI.INSTANCE.getMessages().get("levels.$level", "<#33FF33>")

View File

@ -4,7 +4,7 @@ import com.artillexstudios.axminions.api.minions.Minion
import com.artillexstudios.axminions.api.utils.fastFor import com.artillexstudios.axminions.api.utils.fastFor
import org.bukkit.World import org.bukkit.World
data class ChunkPos(val world: World, var x: Int, var z: Int) { data class ChunkPos(val world: World, val x: Int, val z: Int) {
val minions = arrayListOf<Minion>() val minions = arrayListOf<Minion>()
val worldUUID = world.uid val worldUUID = world.uid

View File

@ -7,7 +7,7 @@ plugins {
} }
group = 'com.artillexstudios.axminions' group = 'com.artillexstudios.axminions'
version = '1.0.1' version = '1.0.2'
repositories { repositories {
mavenCentral() mavenCentral()
@ -126,6 +126,7 @@ allprojects {
implementation("com.artillexstudios.axapi:axapi:1.4.22") implementation("com.artillexstudios.axapi:axapi:1.4.22")
implementation("net.byteflux:libby-bukkit:1.3.0") implementation("net.byteflux:libby-bukkit:1.3.0")
implementation("com.zaxxer:HikariCP:5.1.0") implementation("com.zaxxer:HikariCP:5.1.0")
implementation("org.bstats:bstats-bukkit:3.0.2")
compileOnly 'org.black_ixx:playerpoints:3.2.6' compileOnly 'org.black_ixx:playerpoints:3.2.6'
} }
@ -134,6 +135,7 @@ allprojects {
relocate("org.h2", "com.artillexstudios.axminions.libs.h2") relocate("org.h2", "com.artillexstudios.axminions.libs.h2")
relocate("org.jetbrains.kotlin", "com.artillexstudios.axminions.libs.kotlin") relocate("org.jetbrains.kotlin", "com.artillexstudios.axminions.libs.kotlin")
relocate("com.zaxxer", "com.artillexstudios.axminions.libs.hikaricp") relocate("com.zaxxer", "com.artillexstudios.axminions.libs.hikaricp")
relocate("org.bstats", "com.artillexstudios.axminions.libs.bstats")
} }
} }

View File

@ -2,6 +2,7 @@ package com.artillexstudios.axminions
import com.artillexstudios.axapi.AxPlugin import com.artillexstudios.axapi.AxPlugin
import com.artillexstudios.axapi.data.ThreadedQueue import com.artillexstudios.axapi.data.ThreadedQueue
import com.artillexstudios.axapi.scheduler.Scheduler
import com.artillexstudios.axminions.api.AxMinionsAPI import com.artillexstudios.axminions.api.AxMinionsAPI
import com.artillexstudios.axminions.api.AxMinionsAPIImpl import com.artillexstudios.axminions.api.AxMinionsAPIImpl
import com.artillexstudios.axminions.api.config.Config import com.artillexstudios.axminions.api.config.Config
@ -31,10 +32,9 @@ import com.artillexstudios.axminions.minions.miniontype.MinerMinionType
import com.artillexstudios.axminions.minions.miniontype.SellerMinionType import com.artillexstudios.axminions.minions.miniontype.SellerMinionType
import com.artillexstudios.axminions.minions.miniontype.SlayerMinionType import com.artillexstudios.axminions.minions.miniontype.SlayerMinionType
import java.io.File import java.io.File
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit
import net.byteflux.libby.BukkitLibraryManager import net.byteflux.libby.BukkitLibraryManager
import net.byteflux.libby.Library import net.byteflux.libby.Library
import org.bstats.bukkit.Metrics
import org.bukkit.Bukkit import org.bukkit.Bukkit
import revxrsal.commands.bukkit.BukkitCommandHandler import revxrsal.commands.bukkit.BukkitCommandHandler
@ -65,6 +65,8 @@ class AxMinionsPlugin : AxPlugin() {
} }
override fun enable() { override fun enable() {
Metrics(this, 19043)
AxMinionsPlugin.config = Config(File(dataFolder, "config.yml"), getResource("config.yml")!!) AxMinionsPlugin.config = Config(File(dataFolder, "config.yml"), getResource("config.yml")!!)
messages = Messages(File(dataFolder, "messages.yml"), getResource("messages.yml")!!) messages = Messages(File(dataFolder, "messages.yml"), getResource("messages.yml")!!)
integrations = Integrations() integrations = Integrations()
@ -125,7 +127,7 @@ class AxMinionsPlugin : AxPlugin() {
MinionTicker.startTicking() MinionTicker.startTicking()
Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate({ Scheduler.get().runTimer({
dataQueue.submit { dataQueue.submit {
Minions.get { Minions.get {
it.fastFor { pos -> it.fastFor { pos ->
@ -135,7 +137,7 @@ class AxMinionsPlugin : AxPlugin() {
} }
} }
} }
}, 0, Config.AUTO_SAVE_MINUTES(), TimeUnit.MINUTES) }, 0, Config.AUTO_SAVE_MINUTES() * 20 * 60)
} }
override fun disable() { override fun disable() {

View File

@ -356,8 +356,6 @@ class H2DataHandler : DataHandler {
} }
override fun disable() { override fun disable() {
dataSource.connection.use { connection -> dataSource.connection.prepareStatement("SHUTDOWN DEFRAG;").executeUpdate()
connection.prepareStatement("SHUTDOWN DEFRAG;").executeUpdate()
}
} }
} }

View File

@ -135,6 +135,7 @@ class MinionInventoryListener : Listener {
AxMinionsPlugin.integrations.getEconomyIntegration()?.let { AxMinionsPlugin.integrations.getEconomyIntegration()?.let {
if (it.getBalance(player) < money) { if (it.getBalance(player) < money) {
player.sendMessage(StringUtils.formatToString(Messages.PREFIX() + Messages.UPGRADE_FAIL()))
return return
} }

View File

@ -38,6 +38,11 @@ class MinionPlaceListener : Listener {
if (!AxMinionsPlugin.integrations.getProtectionIntegration().canBuildAt(event.player, event.clickedBlock!!.location)) return if (!AxMinionsPlugin.integrations.getProtectionIntegration().canBuildAt(event.player, event.clickedBlock!!.location)) return
val level = meta.persistentDataContainer.get(Keys.LEVEL, PersistentDataType.INTEGER) ?: 0 val level = meta.persistentDataContainer.get(Keys.LEVEL, PersistentDataType.INTEGER) ?: 0
val stats = meta.persistentDataContainer.get(Keys.STATISTICS, PersistentDataType.LONG) ?: 0 val stats = meta.persistentDataContainer.get(Keys.STATISTICS, PersistentDataType.LONG) ?: 0
if (Config.PLACE_PERMISSION() && !event.player.hasPermission("axminions.place.${minionType.getName()}")) {
event.player.sendMessage(StringUtils.formatToString(Messages.PREFIX() + Messages.PLACE_MISSING_PERMISSION()))
return
}
if (meta.persistentDataContainer.has(Keys.PLACED, PersistentDataType.BYTE)) return if (meta.persistentDataContainer.has(Keys.PLACED, PersistentDataType.BYTE)) return
meta.persistentDataContainer.set(Keys.PLACED, PersistentDataType.BYTE, 0) meta.persistentDataContainer.set(Keys.PLACED, PersistentDataType.BYTE, 0)
item.itemMeta = meta item.itemMeta = meta

View File

@ -25,9 +25,7 @@ import com.artillexstudios.axminions.api.utils.fastFor
import com.artillexstudios.axminions.api.warnings.Warning import com.artillexstudios.axminions.api.warnings.Warning
import com.artillexstudios.axminions.api.warnings.Warnings import com.artillexstudios.axminions.api.warnings.Warnings
import com.artillexstudios.axminions.listeners.LinkingListener import com.artillexstudios.axminions.listeners.LinkingListener
import java.util.HashMap
import java.util.UUID import java.util.UUID
import java.util.concurrent.atomic.AtomicBoolean
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder
import org.bukkit.Bukkit import org.bukkit.Bukkit
import org.bukkit.Location import org.bukkit.Location
@ -498,7 +496,7 @@ class Minion(
} }
override fun addToContainerOrDrop(itemStack: ItemStack) { override fun addToContainerOrDrop(itemStack: ItemStack) {
if (linkedInventory == null) { if (linkedInventory == null) {
AxMinionsPlugin.integrations.getStackerIntegration().dropItemAt(itemStack, itemStack.amount, location) AxMinionsPlugin.integrations.getStackerIntegration().dropItemAt(itemStack, itemStack.amount, location)
return return
} }
@ -595,7 +593,36 @@ class Minion(
if ((tool?.type?.maxDurability ?: return) <= meta.damage + amount) { if ((tool?.type?.maxDurability ?: return) <= meta.damage + amount) {
if (Config.CAN_BREAK_TOOLS()) { if (Config.CAN_BREAK_TOOLS()) {
if (Config.PULL_FROM_CHEST()) {
val allowedTools = arrayListOf<Material>()
getType().getConfig().getStringList("tool.material").fastFor {
allowedTools.add(Material.matchMaterial(it) ?: return@fastFor)
}
linkedInventory?.contents?.fastFor {
if (it == null || it.type !in allowedTools) return@fastFor
setTool(it)
linkedInventory?.remove(it)
return
}
}
setTool(ItemStack(Material.AIR)) setTool(ItemStack(Material.AIR))
} else if (Config.PULL_FROM_CHEST()) {
val allowedTools = arrayListOf<Material>()
getType().getConfig().getStringList("tool.material").fastFor {
allowedTools.add(Material.matchMaterial(it) ?: return@fastFor)
}
linkedInventory?.contents?.fastFor {
if (it == null || it.type !in allowedTools) return@fastFor
linkedInventory?.addItem(getTool())
setTool(it)
linkedInventory?.remove(it)
return
}
} }
} else { } else {
meta.damage += amount meta.damage += amount

View File

@ -70,7 +70,6 @@ object Minions {
lock.write { lock.write {
var pos: ChunkPos? = null var pos: ChunkPos? = null
run breaking@{ run breaking@{
minions.forEach { minions.forEach {
if (world.uid == it.worldUUID && it.x == chunkX && it.z == chunkZ) { if (world.uid == it.worldUUID && it.x == chunkX && it.z == chunkZ) {
pos = it pos = it

View File

@ -60,9 +60,7 @@ class FarmerMinionType : MinionType("farmer", AxMinionsPlugin.INSTANCE.getResour
Material.CACTUS, Material.SUGAR_CANE, Material.BAMBOO -> { Material.CACTUS, Material.SUGAR_CANE, Material.BAMBOO -> {
MinionUtils.getPlant(block).fastFor { MinionUtils.getPlant(block).fastFor {
val blockDrops = it.getDrops(minion.getTool()) val blockDrops = it.getDrops(minion.getTool())
blockDrops.forEach { itemStack -> size++
size += itemStack.amount
}
drops.addAll(blockDrops) drops.addAll(blockDrops)
it.type = Material.AIR it.type = Material.AIR
} }
@ -70,9 +68,7 @@ class FarmerMinionType : MinionType("farmer", AxMinionsPlugin.INSTANCE.getResour
Material.MELON, Material.PUMPKIN -> { Material.MELON, Material.PUMPKIN -> {
val blockDrops = block.getDrops(minion.getTool()) val blockDrops = block.getDrops(minion.getTool())
blockDrops.forEach { itemStack -> size++
size += itemStack.amount
}
drops.addAll(blockDrops) drops.addAll(blockDrops)
block.type = Material.AIR block.type = Material.AIR
} }
@ -81,9 +77,7 @@ class FarmerMinionType : MinionType("farmer", AxMinionsPlugin.INSTANCE.getResour
val ageable = block.blockData as Ageable val ageable = block.blockData as Ageable
if (ageable.age != ageable.maximumAge) return@fastFor if (ageable.age != ageable.maximumAge) return@fastFor
val blockDrops = block.getDrops(minion.getTool()) val blockDrops = block.getDrops(minion.getTool())
blockDrops.forEach { itemStack -> size++
size += itemStack.amount
}
drops.addAll(blockDrops) drops.addAll(blockDrops)
ageable.age = 0 ageable.age = 0
block.blockData = ageable block.blockData = ageable
@ -93,9 +87,7 @@ class FarmerMinionType : MinionType("farmer", AxMinionsPlugin.INSTANCE.getResour
val ageable = block.blockData as Ageable val ageable = block.blockData as Ageable
if (ageable.age != ageable.maximumAge) return@fastFor if (ageable.age != ageable.maximumAge) return@fastFor
val blockDrops = block.getDrops(minion.getTool()) val blockDrops = block.getDrops(minion.getTool())
blockDrops.forEach { itemStack -> size++
size += itemStack.amount
}
drops.addAll(blockDrops) drops.addAll(blockDrops)
ageable.age = 1 ageable.age = 1
block.blockData = ageable block.blockData = ageable

View File

@ -6,6 +6,10 @@ auto-save-minutes: 3
# How far the storage chest can be from the minion # How far the storage chest can be from the minion
max-linking-distance: 30 max-linking-distance: 30
# If players need to have 'axminions.place.<minion>' permission
# to be able to place this minion
place-permissions: false
# The default amount of minions a player can have. # The default amount of minions a player can have.
# This setting can be overwritten by setting the 'axminions.limit.<amount>' permission! # This setting can be overwritten by setting the 'axminions.limit.<amount>' permission!
default-minion-limit: 5 default-minion-limit: 5
@ -32,6 +36,9 @@ can-break-tools: true
# If the minion should be able to take durability from it's held item # If the minion should be able to take durability from it's held item
use-durability: true use-durability: true
# If the minion should pull new tools from the chest it's connected to
pull-tools-from-chest: false
database: database:
# Can be H2 (SqLite support is planned) # Can be H2 (SqLite support is planned)
type: "H2" type: "H2"
@ -83,4 +90,4 @@ gui:
debug: false debug: false
# Do not change! # Do not change!
config-version: 1 config-version: 2

View File

@ -6,6 +6,7 @@ place:
success: "<green>Successfully placed a new <type> minion! <gray>(<placed>/<max>)" success: "<green>Successfully placed a new <type> minion! <gray>(<placed>/<max>)"
limit-reached: "<red>Could not place minion! You have reached the limit! <gray>(<placed>/<max>)" limit-reached: "<red>Could not place minion! You have reached the limit! <gray>(<placed>/<max>)"
minion-at-location: "<red>Could not place minion! There already is a minion at that location!" minion-at-location: "<red>Could not place minion! There already is a minion at that location!"
missing-permission: "<red>You do not have the required permissions to place this minion!"
pickup: pickup:
success: "<green>Successfully picked up a minion! <gray>(<placed>/<max>)" success: "<green>Successfully picked up a minion! <gray>(<placed>/<max>)"
@ -61,4 +62,4 @@ tools:
wrong-tool: "<red>You can't place this item as the tool if this minion!" wrong-tool: "<red>You can't place this item as the tool if this minion!"
# Do not change! # Do not change!
config-version: 1 config-version: 2