invui-kotlin module

This commit is contained in:
NichtStudioCode 2023-01-28 12:32:16 +01:00
parent f8f2dfc95e
commit 60ce81909f
7 changed files with 218 additions and 0 deletions

65
invui-kotlin/pom.xml Normal file

@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>de.studiocode.invui</groupId>
<artifactId>InvUI-Parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>invui-kotlin</artifactId>
<properties>
<kotlin.version>1.8.0</kotlin.version>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.19.3-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>de.studiocode.invui</groupId>
<artifactId>invui</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-api</artifactId>
<version>4.12.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<sourceDirectory>src/main/kotlin/</sourceDirectory>
<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>compile</id>
<phase>process-sources</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

@ -0,0 +1,72 @@
@file:Suppress("PackageDirectoryMismatch")
package de.studiocode.invui.gui
import de.studiocode.invui.item.Item
/**
* Gets the [SlotElement] placed on that slot.
*
* @param slot The slot index
* @return The [SlotElement] placed on that slot or null if there is none
*/
operator fun GUI.get(slot: Int): SlotElement? = getSlotElement(slot)
/**
* Gets the [SlotElement] placed on these coordinates.
*
* @param x The x coordinate of the slot
* @param y The y coordinate of the slot
* @return The [SlotElement] placed on that slot or null if there is none
*/
operator fun GUI.get(x: Int, y: Int): SlotElement? = getSlotElement(x, y)
/**
* Sets the [SlotElement] on that slot.
*
* @param slot The slot index
* @param element The [SlotElement] to set or null to remove the current one
*/
operator fun GUI.set(slot: Int, element: SlotElement?) = setSlotElement(slot, element)
/**
* Sets the [SlotElement] on these coordinates.
*
* @param x The x coordinate of the slot
* @param y The y coordinate of the slot
* @param element The [SlotElement] to set or null to remove the current one
*/
operator fun GUI.set(x: Int, y: Int, element: SlotElement?) = setSlotElement(x, y, element)
/**
* Sets the [Item] on that slot.
*
* @param slot The slot index
* @param item The [Item] to set or null to remove the current one
*/
operator fun GUI.set(slot: Int, item: Item?) = setItem(slot, item)
/**
* Sets the [Item] on these coordinates.
*
* @param x The x coordinate of the slot
* @param y The y coordinate of the slot
* @param item The [Item] to set or null to remove the current one
*/
operator fun GUI.set(x: Int, y: Int, item: Item?) = setItem(x, y, item)
/**
* Adds the given [elements].
*
* @param elements The [SlotElements][SlotElement] to add.
*/
@JvmName("plusAssignSlotElements")
operator fun GUI.plusAssign(elements: Iterable<SlotElement>) = elements.forEach { addSlotElements(it) }
/**
* Adds the given [items].
*
* @param items The [Items][Item] to add.
*/
@JvmName("plusAssignItems")
operator fun GUI.plusAssign(items: Iterable<Item>) = items.forEach { addItems(it) }

@ -0,0 +1,12 @@
@file:Suppress("PackageDirectoryMismatch")
package de.studiocode.invui.item.builder
import de.studiocode.inventoryaccess.component.BaseComponentWrapper
import de.studiocode.invui.util.ComponentUtils
import net.md_5.bungee.api.chat.BaseComponent
/**
* Sets the lore of the item stack.
*/
fun <T> BaseItemBuilder<T>.setLore(lore: List<Array<BaseComponent>>): T = setLore(lore.map { BaseComponentWrapper(ComponentUtils.withoutPreFormatting(*it)) })

@ -0,0 +1,8 @@
@file:Suppress("PackageDirectoryMismatch")
package de.studiocode.invui.item
/**
* Calls [Item.notifyWindows] for all items in this [Iterable].
*/
fun Iterable<Item>.notifyWindows() = forEach { it.notifyWindows() }

@ -0,0 +1,29 @@
@file:Suppress("PackageDirectoryMismatch")
package de.studiocode.invui.virtualinventory
import org.bukkit.inventory.ItemStack
/**
* Gets a copy of [ItemStack] placed on that [slot].
*/
operator fun VirtualInventory.get(slot: Int): ItemStack? = getItemStack(slot)
/**
* Adds the given [items] to the inventory.
*/
operator fun VirtualInventory.plusAssign(items: Iterable<ItemStack>) {
items.forEach { addItem(null, it) }
}
/**
* Adds the given [item] to the inventory.
*/
operator fun VirtualInventory.plusAssign(item: ItemStack) {
addItem(null, item)
}
/**
* Checks if the [VirtualInventory] contains an [ItemStack] similar to the given [item].
*/
operator fun VirtualInventory.contains(item: ItemStack) = containsSimilar(item)

@ -0,0 +1,21 @@
@file:Suppress("PackageDirectoryMismatch")
package de.studiocode.invui.item.builder
import de.studiocode.inventoryaccess.component.AdventureComponentWrapper
import net.kyori.adventure.text.Component
/**
* Sets the display name of the item stack.
*/
fun <T> BaseItemBuilder<T>.setDisplayName(displayName: Component): T = setDisplayName(AdventureComponentWrapper(displayName))
/**
* Sets the lore the item stack.
*/
fun <T> BaseItemBuilder<T>.setLore(lore: List<Component>): T = setLore(lore.map { AdventureComponentWrapper(it) })
/**
* Adds lore lines to the item stack.
*/
fun <T> BaseItemBuilder<T>.addLoreLines(vararg components: Component): T = addLoreLines(*components.map { AdventureComponentWrapper(it) }.toTypedArray())

@ -0,0 +1,11 @@
@file:Suppress("PackageDirectoryMismatch")
package de.studiocode.invui.window.type.context
import de.studiocode.inventoryaccess.component.AdventureComponentWrapper
import net.kyori.adventure.text.Component
/**
* Sets the title of the window.
*/
fun AbstractWindowContext<*>.setTitle(title: Component) = setTitle(AdventureComponentWrapper(title))