Skip to content

Commit

Permalink
chore: Fixed several code deps
Browse files Browse the repository at this point in the history
  • Loading branch information
CoasterFreakDE committed Jun 11, 2024
1 parent 241c1f7 commit 251814d
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public void classloader(PluginClasspathBuilder classpathBuilder) {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(
Objects.requireNonNull(getClass().getClassLoader().getResourceAsStream(".dependencies"))))) {
reader.lines().forEach(dependency -> {
LOGGER.log(Level.INFO, "Adding dependency: " + dependency);
maven.addDependency(new Dependency(new DefaultArtifact(dependency), null));
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ internal class BlockDataListener : Listener {
fun <K, V> reverse(map: Map<K, V>): Map<K, V> {
val reversed = LinkedHashMap<K, V>()
val keys = ArrayList(map.keys)
Collections.reverse(keys)
keys.forEach { key -> reversed[key] = map[key]!! }
keys.reverse()
keys.forEach { key -> reversed[key] = map[key] ?: error("Key not found") }
return reversed
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class CustomBlockData(
return block.chunk.persistentDataContainer.has(getKey(plugin, block), PersistentDataType.TAG_CONTAINER)
}

fun getBlocksWithCustomData(plugin: Plugin, chunk: Chunk): Collection<Block>? {
fun getBlocksWithCustomData(plugin: Plugin, chunk: Chunk): Collection<Block> {
val dummy = NamespacedKey(plugin, "dummy")
return getBlocksWithCustomData(chunk, dummy)
}
Expand All @@ -102,7 +102,7 @@ class CustomBlockData(
}.filterNotNull().toList()
}

fun getBlocksWithCustomData(namespace: String, chunk: Chunk): List<Block>? {
fun getBlocksWithCustomData(namespace: String, chunk: Chunk): List<Block> {
val dummy = NamespacedKey(namespace, "dummy")
return getBlocksWithCustomData(chunk, dummy)
}
Expand Down Expand Up @@ -133,7 +133,7 @@ class CustomBlockData(

private fun getPersistentDataContainer(): PersistentDataContainer {
val chunkPDC: PersistentDataContainer = chunk.persistentDataContainer
val blockPDC: PersistentDataContainer? = chunkPDC.get(getKey(plugin, block), PersistentDataType.TAG_CONTAINER)
val blockPDC: PersistentDataContainer? = chunkPDC[getKey(plugin, block), PersistentDataType.TAG_CONTAINER]
return blockPDC ?: chunkPDC.adapterContext.newPersistentDataContainer()
}

Expand All @@ -144,10 +144,10 @@ class CustomBlockData(

private fun save() {
setDirty(plugin, blockEntry)
if (pdc.isEmpty()) {
if (pdc.isEmpty) {
chunk.persistentDataContainer.remove(getKey(plugin, block))
} else {
chunk.persistentDataContainer.set(getKey(plugin, block), PersistentDataType.TAG_CONTAINER, pdc)
chunk.persistentDataContainer[getKey(plugin, block), PersistentDataType.TAG_CONTAINER] = pdc
}
}

Expand All @@ -158,17 +158,13 @@ class CustomBlockData(
if (key == null) return@forEach
val dataType: PersistentDataType<*, *>? = getDataType(this, key)
if (dataType != null) {
newCbd.set(
key,
dataType as PersistentDataType<Any, Any>,
this[key, dataType] as Any
)
newCbd[key, dataType as PersistentDataType<Any, Any>] = this[key, dataType] as Any
}
}
}

override fun <T, Z> set(key: NamespacedKey, type: PersistentDataType<T, Z>, value: Z & Any) {
pdc.set(key, type, value)
pdc[key, type] = value
save()
}

Expand Down Expand Up @@ -205,7 +201,7 @@ class CustomBlockData(
}

override fun isEmpty(): Boolean {
return pdc.isEmpty()
return pdc.isEmpty
}

override fun copyTo(pdc: PersistentDataContainer, replace: Boolean) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ package com.liamxsage.energeticstorage.extensions
import com.liamxsage.energeticstorage.NETWORK_INTERFACE_NAMESPACE
import com.liamxsage.energeticstorage.items.ItemBuilder
import org.bukkit.Material
import org.bukkit.inventory.ItemStack
import org.bukkit.NamespacedKey
import org.bukkit.block.Block
import org.bukkit.inventory.ItemStack
import org.bukkit.persistence.PersistentDataType

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.liamxsage.energeticstorage.items.mineskin.SkinTexture
import com.liamxsage.energeticstorage.listeners.ItemClickListener
import com.mojang.authlib.GameProfile
import com.mojang.authlib.properties.Property
import dev.fruxz.ascend.extension.forceCastOrNull
import dev.fruxz.ascend.extension.logging.getItsLogger
import dev.fruxz.stacked.text
import net.kyori.adventure.text.Component
Expand Down Expand Up @@ -68,7 +69,7 @@ class ItemBuilder(material: Material, count: Int = 1, dsl: ItemBuilder.() -> Uni
* @return The updated ItemBuilder instance.
*/
fun <T : ItemMeta> meta(dsl: T.() -> Unit): ItemBuilder {
val meta = itemStack.itemMeta as T // TODO <- forceCastOrNull() please! :)
val meta = itemStack.itemMeta.forceCastOrNull<T>() ?: return this
dsl.invoke(meta)
itemStack.itemMeta = meta
return this
Expand All @@ -83,7 +84,7 @@ class ItemBuilder(material: Material, count: Int = 1, dsl: ItemBuilder.() -> Uni
*/
fun addPersistentData(key: NamespacedKey, value: String): ItemBuilder {
val meta = itemStack.itemMeta
meta.persistentDataContainer.set(key, PersistentDataType.STRING, value)
meta.persistentDataContainer[key, PersistentDataType.STRING] = value
itemStack.itemMeta = meta
return this
}
Expand Down Expand Up @@ -118,7 +119,7 @@ class ItemBuilder(material: Material, count: Int = 1, dsl: ItemBuilder.() -> Uni
fun addPersistentDataIf(key: NamespacedKey, value: String, condition: Boolean = false): ItemBuilder {
if (condition) {
val meta = itemStack.itemMeta
meta.persistentDataContainer.set(key, PersistentDataType.STRING, value)
meta.persistentDataContainer[key, PersistentDataType.STRING] = value
itemStack.itemMeta = meta
return this
}
Expand Down Expand Up @@ -160,7 +161,6 @@ class ItemBuilder(material: Material, count: Int = 1, dsl: ItemBuilder.() -> Uni
*
* @param T the type of the item to perform the operation on
*/
@FunctionalInterface
fun interface Performer<T> {
fun perform(itemBuilder: T): T
}
Expand Down Expand Up @@ -201,11 +201,7 @@ class ItemBuilder(material: Material, count: Int = 1, dsl: ItemBuilder.() -> Uni
* @return The updated ItemBuilder object.
*/
fun setOwner(uuid: UUID): ItemBuilder {
if (itemStack.type != Material.PLAYER_HEAD) return this
val skullMeta = itemStack.itemMeta as SkullMeta
skullMeta.owningPlayer = Bukkit.getOfflinePlayer(uuid)
itemStack.itemMeta = skullMeta
return this
return owner(uuid)
}

/**
Expand Down Expand Up @@ -271,7 +267,7 @@ class ItemBuilder(material: Material, count: Int = 1, dsl: ItemBuilder.() -> Uni
val skullMeta = itemStack.itemMeta as SkullMeta
val profileField: Field = skullMeta.javaClass.getDeclaredField("profile")
profileField.isAccessible = true
profileField.set(skullMeta, profile)
profileField[skullMeta] = profile
itemStack.setItemMeta(skullMeta)
} catch (e1: NoSuchFieldException) {
e1.printStackTrace()
Expand All @@ -291,7 +287,7 @@ class ItemBuilder(material: Material, count: Int = 1, dsl: ItemBuilder.() -> Uni
*/
fun textureFromMineSkin(mineSkinUUID: String): ItemBuilder {
if (textureCache.containsKey(mineSkinUUID)) {
return textureFromSkinTexture(textureCache[mineSkinUUID]!!)
return textureFromSkinTexture(textureCache[mineSkinUUID] ?: return this)
}

val target = URL("https://api.mineskin.org/get/uuid/$mineSkinUUID")
Expand Down Expand Up @@ -541,32 +537,7 @@ class ItemBuilder(material: Material, count: Int = 1, dsl: ItemBuilder.() -> Uni
}
return this
}


/**
* Sets the material of the item stack.
*
* @param material the material to set
* @return the ItemBuilder instance
*/
fun type(material: Material): ItemBuilder {
itemStack.type = material
return this
}

/**
* Sets the type of the material in the ItemBuilder, if the given condition is true.
*
* @param material The material to set.
* @param condition The condition that determines whether the type should be set.
* @return The ItemBuilder instance.
*/
fun typeIf(material: Material, condition: Boolean = false): ItemBuilder {
if (condition) {
itemStack.type = material
}
return this
}


/**
* Creates a deep copy of the current ItemBuilder object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import com.liamxsage.energeticstorage.network.getNetworkInterfaceType
import org.bukkit.Material
import org.bukkit.block.Block
import org.bukkit.block.data.type.ChiseledBookshelf
import org.bukkit.entity.Player
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.block.BlockPlaceEvent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.liamxsage.energeticstorage.listeners

import com.liamxsage.energeticstorage.DISK_ID_NAMESPACE
import com.liamxsage.energeticstorage.DISK_DRIVE_ID_NAMESPACE
import com.liamxsage.energeticstorage.DISK_ID_NAMESPACE
import com.liamxsage.energeticstorage.cache.DiskCache
import com.liamxsage.energeticstorage.cache.DiskDriveCache
import com.liamxsage.energeticstorage.database.saveToDB
Expand All @@ -13,7 +13,6 @@ import com.liamxsage.energeticstorage.network.getConnectedNetworkInterfaces
import com.liamxsage.energeticstorage.network.getNetworkInterfaceType
import org.bukkit.Material
import org.bukkit.block.Block
import org.bukkit.block.data.type.ChiseledBookshelf
import org.bukkit.entity.Player
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.liamxsage.energeticstorage.listeners.BlockBreakListener
import com.liamxsage.energeticstorage.listeners.BlockPlaceListener
import com.liamxsage.energeticstorage.listeners.ItemClickListener
import com.liamxsage.energeticstorage.listeners.PlayerInteractListener
import dev.fruxz.ascend.extension.forceCastOrNull
import org.bukkit.Bukkit
import org.bukkit.command.CommandExecutor
import org.bukkit.command.PluginCommand
Expand All @@ -35,7 +36,7 @@ object RegisterManager {
try {
val loadedClass = classInfo.load().kotlin
if (clazzType.isInstance(loadedClass.javaObjectType.getDeclaredConstructor().newInstance())) {
classes.add(loadedClass as KClass<out T>)
classes.add(loadedClass.forceCastOrNull<KClass<out T>>() ?: continue)
}
} catch (_: Exception) {
// Ignore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import java.io.ByteArrayOutputStream
import java.io.IOException


private const val UNABLE_TO_SAVE_ITEM_STACKS = "Unable to save item stacks."
private const val UNABLE_TO_DECODE_CLASS_TYPE = "Unable to decode class type."

object ItemStackConverter {


Expand Down Expand Up @@ -61,7 +64,7 @@ object ItemStackConverter {
dataOutput.close()
Base64Coder.encodeLines(outputStream.toByteArray())
} catch (e: Exception) {
throw IllegalStateException("Unable to save item stacks.", e)
throw IllegalStateException(UNABLE_TO_SAVE_ITEM_STACKS, e)
}
}

Expand Down Expand Up @@ -92,7 +95,7 @@ object ItemStackConverter {
dataOutput.close()
Base64Coder.encodeLines(outputStream.toByteArray())
} catch (e: Exception) {
throw IllegalStateException("Unable to save item stacks.", e)
throw IllegalStateException(UNABLE_TO_SAVE_ITEM_STACKS, e)
}
}

Expand Down Expand Up @@ -129,7 +132,7 @@ object ItemStackConverter {
dataOutput.close()
Base64Coder.encodeLines(outputStream.toByteArray())
} catch (e: Exception) {
throw IllegalStateException("Unable to save item stacks.", e)
throw IllegalStateException(UNABLE_TO_SAVE_ITEM_STACKS, e)
}
}

Expand Down Expand Up @@ -168,7 +171,7 @@ object ItemStackConverter {
dataInput.close()
inventory
} catch (e: ClassNotFoundException) {
throw IOException("Unable to decode class type.", e)
throw IOException(UNABLE_TO_DECODE_CLASS_TYPE, e)
}
}

Expand Down Expand Up @@ -198,7 +201,7 @@ object ItemStackConverter {
dataInput.close()
items
} catch (e: ClassNotFoundException) {
throw IOException("Unable to decode class type.", e)
throw IOException(UNABLE_TO_DECODE_CLASS_TYPE, e)
}
}

Expand Down Expand Up @@ -227,7 +230,7 @@ object ItemStackConverter {
dataInput.close()
item
} catch (e: ClassNotFoundException) {
throw IOException("Unable to decode class type.", e)
throw IOException(UNABLE_TO_DECODE_CLASS_TYPE, e)
}
}

Expand Down

0 comments on commit 251814d

Please sign in to comment.