Fixed talisman bag breaking on join
This commit is contained in:
@@ -62,7 +62,7 @@ allprojects {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compileOnly 'com.willfp:eco:6.36.3'
|
compileOnly 'com.willfp:eco:6.37.2'
|
||||||
implementation 'com.willfp:libreforge:3.75.0'
|
implementation 'com.willfp:libreforge:3.75.0'
|
||||||
implementation 'org.joml:joml:1.10.4'
|
implementation 'org.joml:joml:1.10.4'
|
||||||
|
|
||||||
|
|||||||
@@ -17,16 +17,14 @@ import org.bukkit.event.Listener
|
|||||||
class TalismansPlugin : LibReforgePlugin() {
|
class TalismansPlugin : LibReforgePlugin() {
|
||||||
val talismansYml = TalismansYml(this)
|
val talismansYml = TalismansYml(this)
|
||||||
|
|
||||||
/** Internal constructor called by bukkit on plugin load. */
|
|
||||||
init {
|
init {
|
||||||
instance = this
|
instance = this
|
||||||
registerHolderProvider { TalismanChecks.getTalismansOnPlayer(it) }
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun handleEnableAdditional() {
|
TalismanChecks.registerItemStackProvider {
|
||||||
TalismanChecks.regsiterItemStackProvider {
|
|
||||||
TalismanBag.getTalismans(it)
|
TalismanBag.getTalismans(it)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
registerHolderProvider { TalismanChecks.getTalismansOnPlayer(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun handleReloadAdditional() {
|
override fun handleReloadAdditional() {
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import com.willfp.talismans.talismans.util.TalismanChecks
|
|||||||
import org.bukkit.Material
|
import org.bukkit.Material
|
||||||
import org.bukkit.entity.Player
|
import org.bukkit.entity.Player
|
||||||
import org.bukkit.inventory.ItemStack
|
import org.bukkit.inventory.ItemStack
|
||||||
import java.util.UUID
|
import java.util.*
|
||||||
import kotlin.math.ceil
|
import kotlin.math.ceil
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
|
|
||||||
@@ -133,6 +133,13 @@ object TalismanBag {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun getTalismans(player: Player): List<ItemStack> {
|
fun getTalismans(player: Player): List<ItemStack> {
|
||||||
|
if (!savedItems.contains(player.uniqueId)) {
|
||||||
|
savedItems[player.uniqueId] = player.profile.read(key)
|
||||||
|
.map { Items.lookup(it).item }
|
||||||
|
.filterNot { EmptyTestableItem().matches(it) }
|
||||||
|
.filter { TalismanChecks.getTalismanOnItem(it) != null }
|
||||||
|
}
|
||||||
|
|
||||||
return savedItems[player.uniqueId] ?: emptyList()
|
return savedItems[player.uniqueId] ?: emptyList()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,11 +13,9 @@ import com.willfp.talismans.talismans.util.TalismanUtils.getLimit
|
|||||||
import com.willfp.talismans.talismans.util.TalismanUtils.isTalismanMaterial
|
import com.willfp.talismans.talismans.util.TalismanUtils.isTalismanMaterial
|
||||||
import org.bukkit.block.ShulkerBox
|
import org.bukkit.block.ShulkerBox
|
||||||
import org.bukkit.entity.Player
|
import org.bukkit.entity.Player
|
||||||
import org.bukkit.inventory.Inventory
|
|
||||||
import org.bukkit.inventory.ItemStack
|
import org.bukkit.inventory.ItemStack
|
||||||
import org.bukkit.inventory.meta.BlockStateMeta
|
import org.bukkit.inventory.meta.BlockStateMeta
|
||||||
import org.bukkit.persistence.PersistentDataType
|
import org.bukkit.persistence.PersistentDataType
|
||||||
import java.util.*
|
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
import java.util.function.Function
|
import java.util.function.Function
|
||||||
|
|
||||||
@@ -32,8 +30,6 @@ object TalismanChecks {
|
|||||||
|
|
||||||
private val PROVIDERS: MutableSet<Function<Player, List<ItemStack>>> = HashSet()
|
private val PROVIDERS: MutableSet<Function<Player, List<ItemStack>>> = HashSet()
|
||||||
|
|
||||||
private var readInventory = true
|
|
||||||
private var readEnderChest = true
|
|
||||||
private var readShulkerBoxes = true
|
private var readShulkerBoxes = true
|
||||||
private var offhandOnly = false
|
private var offhandOnly = false
|
||||||
|
|
||||||
@@ -89,7 +85,6 @@ object TalismanChecks {
|
|||||||
* Get all talismans ItemStacks that a player has active.
|
* Get all talismans ItemStacks that a player has active.
|
||||||
*
|
*
|
||||||
* @param player The player to query.
|
* @param player The player to query.
|
||||||
* @param useCache If the cache should be checked.
|
|
||||||
* @param extra Bonus items.
|
* @param extra Bonus items.
|
||||||
* @return A set of all found talismans.
|
* @return A set of all found talismans.
|
||||||
*/
|
*/
|
||||||
@@ -102,19 +97,6 @@ object TalismanChecks {
|
|||||||
val contents = mutableListOf<ItemStack>()
|
val contents = mutableListOf<ItemStack>()
|
||||||
val rawContents = mutableListOf<ItemStack?>()
|
val rawContents = mutableListOf<ItemStack?>()
|
||||||
|
|
||||||
if (readInventory) {
|
|
||||||
rawContents.addAll(it.inventory.contents)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (readEnderChest) {
|
|
||||||
val enderChest = it.enderChest as Inventory?
|
|
||||||
|
|
||||||
// Not always true, bug reported where it was null.
|
|
||||||
if (enderChest != null) {
|
|
||||||
rawContents.addAll(enderChest.contents)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (offhandOnly) {
|
if (offhandOnly) {
|
||||||
rawContents.clear()
|
rawContents.clear()
|
||||||
rawContents.add(it.inventory.itemInOffHand)
|
rawContents.add(it.inventory.itemInOffHand)
|
||||||
@@ -129,20 +111,21 @@ object TalismanChecks {
|
|||||||
if (rawContent == null) {
|
if (rawContent == null) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if (readShulkerBoxes) {
|
if (readShulkerBoxes) {
|
||||||
val meta = rawContent.itemMeta
|
val meta = rawContent.itemMeta
|
||||||
if (meta is BlockStateMeta) {
|
if (meta is BlockStateMeta) {
|
||||||
val shulkerMeta = meta
|
if (!meta.hasBlockState()) {
|
||||||
if (!shulkerMeta.hasBlockState()) {
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
val state = shulkerMeta.blockState
|
val state = meta.blockState
|
||||||
if (state is ShulkerBox) {
|
if (state is ShulkerBox) {
|
||||||
contents.addAll(state.inventory.contents)
|
contents.addAll(state.inventory.contents)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
contents.add(rawContent)
|
contents.add(rawContent)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -206,7 +189,7 @@ object TalismanChecks {
|
|||||||
* @param provider The provider.
|
* @param provider The provider.
|
||||||
*/
|
*/
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun regsiterItemStackProvider(provider: Function<Player, List<ItemStack>>) {
|
fun registerItemStackProvider(provider: Function<Player, List<ItemStack>>) {
|
||||||
PROVIDERS.add(provider)
|
PROVIDERS.add(provider)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -233,8 +216,19 @@ object TalismanChecks {
|
|||||||
@ConfigUpdater
|
@ConfigUpdater
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun reload(plugin: EcoPlugin) {
|
fun reload(plugin: EcoPlugin) {
|
||||||
readInventory = plugin.configYml.getBool("read-inventory")
|
if (plugin.configYml.getBool("read-inventory")) {
|
||||||
readEnderChest = plugin.configYml.getBool("read-enderchest")
|
registerItemStackProvider {
|
||||||
|
it.inventory.contents.filterNotNull()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (plugin.configYml.getBool("read-enderchest")) {
|
||||||
|
registerItemStackProvider {
|
||||||
|
@Suppress("UNNECESSARY_SAFE_CALL", "USELESS_ELVIS") // Was null once
|
||||||
|
it.enderChest?.contents?.filterNotNull() ?: emptyList()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
readShulkerBoxes = plugin.configYml.getBool("read-shulkerboxes")
|
readShulkerBoxes = plugin.configYml.getBool("read-shulkerboxes")
|
||||||
offhandOnly = plugin.configYml.getBool("offhand-only")
|
offhandOnly = plugin.configYml.getBool("offhand-only")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user