mirror of
https://github.com/Artillex-Studios/AxMinions.git
synced 2024-12-01 13:03:43 +01:00
Island limits, fix NPE from SuperiorSkyBlock2 island deletion hook
This commit is contained in:
parent
4b242a31ae
commit
c35bae34da
@ -30,6 +30,8 @@ class Config(file: File, stream: InputStream) {
|
||||
@JvmStatic
|
||||
fun CAN_BREAK_TOOLS() = AxMinionsAPI.INSTANCE.getConfig().get("can-break-tools", true)
|
||||
@JvmStatic
|
||||
fun ISLAND_LIMIT() = AxMinionsAPI.INSTANCE.getConfig().get("island-limit", 0)
|
||||
@JvmStatic
|
||||
fun USE_DURABILITY() = AxMinionsAPI.INSTANCE.getConfig().get("use-durability", true)
|
||||
@JvmStatic
|
||||
fun DATABASE_TYPE() = AxMinionsAPI.INSTANCE.getConfig().get("database.type", "H2")
|
||||
|
@ -47,6 +47,8 @@ class Messages(file: File, stream: InputStream) {
|
||||
@JvmStatic
|
||||
fun PLACE_MISSING_PERMISSION() = AxMinionsAPI.INSTANCE.getMessages().get<String>("place.missing-permission")
|
||||
@JvmStatic
|
||||
fun ISLAND_LIMIT_REACHED() = AxMinionsAPI.INSTANCE.getMessages().get<String>("place.island-limit-reached")
|
||||
@JvmStatic
|
||||
fun STATISTICS() = AxMinionsAPI.INSTANCE.getMessages().get<String>("statistics")
|
||||
@JvmStatic
|
||||
fun LEVEL_COLOR(level: Int = 1) = AxMinionsAPI.INSTANCE.getMessages().get("levels.$level", "<#33FF33>")
|
||||
|
@ -16,7 +16,7 @@ class PreMinionPickupEvent(private val player: Player, minion: Minion) : MinionE
|
||||
private var isCancelled = false
|
||||
|
||||
override fun getHandlers(): HandlerList {
|
||||
return PreMinionPickupEvent.handlerList
|
||||
return handlerList
|
||||
}
|
||||
|
||||
fun getPlayer(): Player {
|
||||
|
@ -18,7 +18,7 @@ class PreMinionPlaceEvent(private val player: Player, private val location: Loca
|
||||
private var shouldOverridePlayerLimit = false
|
||||
|
||||
override fun getHandlers(): HandlerList {
|
||||
return PreMinionPlaceEvent.handlerList
|
||||
return handlerList
|
||||
}
|
||||
|
||||
override fun isCancelled(): Boolean {
|
||||
|
@ -1,9 +1,6 @@
|
||||
package com.artillexstudios.axminions.api.integrations
|
||||
|
||||
import com.artillexstudios.axminions.api.integrations.types.EconomyIntegration
|
||||
import com.artillexstudios.axminions.api.integrations.types.PricesIntegration
|
||||
import com.artillexstudios.axminions.api.integrations.types.ProtectionIntegrations
|
||||
import com.artillexstudios.axminions.api.integrations.types.StackerIntegration
|
||||
import com.artillexstudios.axminions.api.integrations.types.*
|
||||
|
||||
interface Integrations {
|
||||
|
||||
@ -13,6 +10,8 @@ interface Integrations {
|
||||
|
||||
fun getEconomyIntegration(): EconomyIntegration?
|
||||
|
||||
fun getIslandIntegration(): IslandIntegration?
|
||||
|
||||
fun getProtectionIntegration(): ProtectionIntegrations
|
||||
|
||||
fun reload()
|
||||
|
@ -0,0 +1,9 @@
|
||||
package com.artillexstudios.axminions.api.integrations.types
|
||||
|
||||
import com.artillexstudios.axminions.api.integrations.Integration
|
||||
import org.bukkit.entity.Player
|
||||
|
||||
interface IslandIntegration : Integration {
|
||||
|
||||
fun getIslandPlaced(player: Player): Int
|
||||
}
|
@ -6,11 +6,7 @@ import com.artillexstudios.axminions.api.config.Config
|
||||
import com.artillexstudios.axminions.api.exception.InvalidIntegrationException
|
||||
import com.artillexstudios.axminions.api.integrations.Integration
|
||||
import com.artillexstudios.axminions.api.integrations.Integrations
|
||||
import com.artillexstudios.axminions.api.integrations.types.EconomyIntegration
|
||||
import com.artillexstudios.axminions.api.integrations.types.PricesIntegration
|
||||
import com.artillexstudios.axminions.api.integrations.types.ProtectionIntegration
|
||||
import com.artillexstudios.axminions.api.integrations.types.ProtectionIntegrations
|
||||
import com.artillexstudios.axminions.api.integrations.types.StackerIntegration
|
||||
import com.artillexstudios.axminions.api.integrations.types.*
|
||||
import com.artillexstudios.axminions.integrations.economy.PlayerPointsIntegration
|
||||
import com.artillexstudios.axminions.integrations.economy.VaultIntegration
|
||||
import com.artillexstudios.axminions.integrations.placeholder.PlaceholderAPIIntegration
|
||||
@ -38,6 +34,7 @@ class Integrations : Integrations {
|
||||
private lateinit var stackerIntegration: StackerIntegration
|
||||
private var pricesIntegration: PricesIntegration? = null
|
||||
private var economyIntegration: EconomyIntegration? = null
|
||||
private var islandIntegration: IslandIntegration? = null
|
||||
private val protectionIntegrations = com.artillexstudios.axminions.integrations.protection.ProtectionIntegrations()
|
||||
internal var kGeneratorsIntegration = false
|
||||
internal var itemsAdderIntegration = false
|
||||
@ -54,6 +51,10 @@ class Integrations : Integrations {
|
||||
return economyIntegration
|
||||
}
|
||||
|
||||
override fun getIslandIntegration(): IslandIntegration? {
|
||||
return islandIntegration
|
||||
}
|
||||
|
||||
override fun getProtectionIntegration(): ProtectionIntegrations {
|
||||
return protectionIntegrations
|
||||
}
|
||||
@ -198,6 +199,12 @@ class Integrations : Integrations {
|
||||
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
|
||||
PlaceholderAPIIntegration().register()
|
||||
}
|
||||
|
||||
if (Config.ISLAND_LIMIT() > 0) {
|
||||
if (Bukkit.getPluginManager().getPlugin("SuperiorSkyBlock2") != null) {
|
||||
register(com.artillexstudios.axminions.integrations.island.SuperiorSkyBlock2Integration())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun register(integration: Integration) {
|
||||
@ -218,6 +225,10 @@ class Integrations : Integrations {
|
||||
pricesIntegration = integration
|
||||
}
|
||||
|
||||
is IslandIntegration -> {
|
||||
islandIntegration = integration
|
||||
}
|
||||
|
||||
else -> {
|
||||
throw InvalidIntegrationException("There is no builtin integration that the following class extends: ${integration::class.java}")
|
||||
}
|
||||
|
@ -0,0 +1,22 @@
|
||||
package com.artillexstudios.axminions.integrations.island
|
||||
|
||||
import com.artillexstudios.axminions.api.AxMinionsAPI
|
||||
import com.artillexstudios.axminions.api.integrations.types.IslandIntegration
|
||||
import com.bgsoftware.superiorskyblock.api.SuperiorSkyblockAPI
|
||||
import org.bukkit.entity.Player
|
||||
|
||||
class SuperiorSkyBlock2Integration : IslandIntegration {
|
||||
|
||||
override fun getIslandPlaced(player: Player): Int {
|
||||
var placed = 0
|
||||
SuperiorSkyblockAPI.getPlayer(player.uniqueId).island?.getIslandMembers(true)?.forEach {
|
||||
placed += AxMinionsAPI.INSTANCE.getDataHandler().getMinionAmount(it.uniqueId)
|
||||
}
|
||||
|
||||
return placed
|
||||
}
|
||||
|
||||
override fun register() {
|
||||
|
||||
}
|
||||
}
|
@ -75,6 +75,29 @@ class MinionPlaceListener : Listener {
|
||||
AxMinionsPlugin.dataQueue.submit {
|
||||
val placed = AxMinionsPlugin.dataHandler.getMinionAmount(event.player.uniqueId)
|
||||
|
||||
val islandLimit = Config.ISLAND_LIMIT()
|
||||
var islandPlaced = 0
|
||||
if (islandLimit > 0 && AxMinionsAPI.INSTANCE.getIntegrations().getIslandIntegration() != null) {
|
||||
islandPlaced = AxMinionsAPI.INSTANCE.getIntegrations().getIslandIntegration()!!.getIslandPlaced(event.player)
|
||||
|
||||
if (islandPlaced >= islandLimit && !event.player.hasPermission("axminions.limit.*")) {
|
||||
event.player.sendMessage(
|
||||
StringUtils.formatToString(
|
||||
Messages.PREFIX() + Messages.ISLAND_LIMIT_REACHED(),
|
||||
Placeholder.unparsed("placed", islandPlaced.toString()),
|
||||
Placeholder.unparsed("max", islandLimit.toString())
|
||||
)
|
||||
)
|
||||
|
||||
Scheduler.get().run { _ ->
|
||||
meta = item.itemMeta!!
|
||||
meta.persistentDataContainer.remove(Keys.PLACED)
|
||||
item.itemMeta = meta
|
||||
}
|
||||
return@submit
|
||||
}
|
||||
}
|
||||
|
||||
if (placed >= maxMinions && !prePlaceEvent.getShouldOverridePlayerLimit() && !event.player.hasPermission("axminions.limit.*")) {
|
||||
event.player.sendMessage(
|
||||
StringUtils.formatToString(
|
||||
@ -146,7 +169,9 @@ class MinionPlaceListener : Listener {
|
||||
Messages.PREFIX() + Messages.PLACE_SUCCESS(),
|
||||
Placeholder.unparsed("type", minionType.getName()),
|
||||
Placeholder.unparsed("placed", (placed + 1).toString()),
|
||||
Placeholder.unparsed("max", (maxMinions).toString())
|
||||
Placeholder.unparsed("max", maxMinions.toString()),
|
||||
Placeholder.unparsed("island-placed", islandPlaced.toString()),
|
||||
Placeholder.unparsed("island-max", islandLimit.toString()),
|
||||
)
|
||||
)
|
||||
}
|
||||
|
@ -13,12 +13,16 @@ class SuperiorSkyBlock2Listener : Listener {
|
||||
val minions = Minions.getMinions()
|
||||
|
||||
Environment.entries.forEach { entry ->
|
||||
event.island.getAllChunksAsync(entry, true) {}.forEach { chunk ->
|
||||
minions.forEach { minion ->
|
||||
if (minion.getLocation().chunk == chunk) {
|
||||
minion.remove()
|
||||
try {
|
||||
event.island.getAllChunksAsync(entry, true) { }.forEach { chunk ->
|
||||
minions.forEach { minion ->
|
||||
if (minion.getLocation().chunk == chunk) {
|
||||
minion.remove()
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (_: NullPointerException) {
|
||||
// SuperiorSkyBlock api does it this way aswell
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,9 @@ display-warnings: true
|
||||
# If set to false, the minion can break the tool
|
||||
can-break-tools: true
|
||||
|
||||
# The limit to use for islands
|
||||
island-limit: 10
|
||||
|
||||
# If the minion should be able to take durability from it's held item
|
||||
use-durability: true
|
||||
|
||||
@ -126,4 +129,4 @@ gui:
|
||||
debug: false
|
||||
|
||||
# Do not change!
|
||||
config-version: 8
|
||||
config-version: 9
|
||||
|
@ -3,10 +3,11 @@ prefix: "<gradient:#00aaff:#00ccff>AxMinions</gradient> <gray>»</gray> "
|
||||
reload: "<green>Plugin successfully reloaded in <white><time></white>ms!"
|
||||
|
||||
place:
|
||||
success: "<green>Successfully placed a new <type> minion! <gray>(<placed>/<max>)"
|
||||
success: "<green>Successfully placed a new <type> minion! <gray>(<placed>/<max>)" # There also is island-placed and island-max for island limits
|
||||
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!"
|
||||
missing-permission: "<red>You do not have the required permissions to place this minion!"
|
||||
island-limit-reached: "<red>You have reached the island limit for minions! <gray>(<placed>/<max>)"
|
||||
|
||||
pickup:
|
||||
success: "<green>Successfully picked up a minion! <gray>(<placed>/<max>)"
|
||||
@ -74,4 +75,4 @@ tools:
|
||||
wrong-tool: "<red>You can't place this item as the tool if this minion!"
|
||||
|
||||
# Do not change!
|
||||
config-version: 4
|
||||
config-version: 6
|
Loading…
Reference in New Issue
Block a user