Skip to content

Commit

Permalink
feat: Bump InventoryGUI version to 4.6.0
Browse files Browse the repository at this point in the history
Update log:
- Upgrade PaperAPI version to 1.21.1
- Upgrade kotlin version to 2.0.0
- Now InventoryGUI must require to Java 21
- Add toMini() method to deserialize Adventure API MiniMessage
- Add toOriginal() method to serialize Adventure API MiniMessage
- Add Component.compareTo(comp: Component) method to compare two components
- Upgrade shadow plugin version to 8.3.0
- Upgrade dokka plugin version to 1.9.20
- Compare component error fixed
  • Loading branch information
wh64dev committed Aug 12, 2024
1 parent 0dd6ed0 commit 95d24a1
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 80 deletions.
13 changes: 7 additions & 6 deletions InventoryGUI-api/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
Expand All @@ -7,7 +8,7 @@ plugins {

tasks {
withType<KotlinCompile> {
kotlinOptions.jvmTarget = "17"
compilerOptions.jvmTarget.set(JvmTarget.JVM_21)
}

withType<Javadoc> {
Expand Down Expand Up @@ -52,7 +53,7 @@ publishing {
pom {
name.set(rootProject.name)
description.set("This is minecraft gui library")
url.set("https://github.com/devproje/InventoryGUI")
url.set("https://github.com/project-official/InventoryGUI")
licenses {
license {
name.set("GNU General Public License Version 3")
Expand All @@ -62,14 +63,14 @@ publishing {
developers {
developer {
id.set("devproje")
name.set("Project_TL")
name.set("Project_IO")
email.set("[email protected]")
}
}
scm {
connection.set("scm:git:https://github.com/devproje/InventoryGUI.git")
developerConnection.set("scm:git:https://github.com/devproje/InventoryGUI.git")
url.set("https://github.com/devproje/InventoryGUI.git")
connection.set("scm:git:https://github.com/project-official/InventoryGUI.git")
developerConnection.set("scm:git:https://github.com/project-official/InventoryGUI.git")
url.set("https://github.com/project-official/InventoryGUI.git")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Animation(val player: Player, val slotType: InventoryType, val title: Comp
}
running = true
taskId = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, {
if(running) {
if (running) {
if(frames.contains(tick)) {
lastAvailableTicks = tick
val inv = base.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,14 @@ package net.projecttl.inventory

import net.kyori.adventure.text.Component
import net.projecttl.inventory.gui.InventoryBuilder
import net.projecttl.inventory.gui.SimpleInventoryBuilder
import net.projecttl.inventory.gui.LinkedInventoryBuilder
import net.projecttl.inventory.gui.SimpleInventoryBuilder
import net.projecttl.inventory.util.Downstream
import net.projecttl.inventory.util.InventoryType
import org.bukkit.entity.Player
import org.bukkit.inventory.Inventory
import org.bukkit.plugin.InvalidPluginException
import org.bukkit.plugin.Plugin
import org.bukkit.plugin.java.JavaPlugin
import org.bukkit.plugin.java.PluginClassLoader
import java.util.*
import kotlin.collections.HashMap

/**
* InventoryGUI Data
Expand All @@ -30,6 +26,7 @@ object InventoryGUI {
* @throws InvalidPluginException if the current library isn't loaded by a plugin
*/
var plugin: Plugin = Downstream.pullPlugin()
private set
/*
var plugin: JavaPlugin = javaClass.classLoader.run {
fun checkLoader(classLoader: ClassLoader): ClassLoader {
Expand All @@ -51,13 +48,12 @@ object InventoryGUI {
*
* @param title The title of the inventory. This is the text shown at the top of the inventory.
* @param slotType The Inventory's Size. Defaults to 27(3 * 9) if not set.
* @param access Allow click player's storage area.
* @param init Initialize the inventory builder. Creates a default inventory if not set.
*
* @return The built inventory
*/
fun Player.gui(title: Component, slotType: InventoryType = InventoryType.CHEST_27, access: Boolean = false, init: SimpleInventoryBuilder.() -> Unit = {}): Inventory {
return SimpleInventoryBuilder(this, slotType, title, access).apply(init).build()
fun Player.gui(title: Component, slotType: InventoryType = InventoryType.CHEST_27, init: SimpleInventoryBuilder.() -> Unit = {}): Inventory {
return SimpleInventoryBuilder(this, slotType, title).apply(init).build()
}

/**
Expand All @@ -84,4 +80,4 @@ fun Player.linkedGui(title: Component, slotType: InventoryType = InventoryType.C
*/
fun Player.animatedGui(title: Component, slotType: InventoryType = InventoryType.CHEST_27, init: Animation.() -> Unit = {}) : Animation {
return Animation(this, slotType, title).apply(init)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import net.projecttl.inventory.util.InventoryType
import net.projecttl.inventory.util.LinkedSlot
import net.projecttl.inventory.util.ObservableHashMap
import net.projecttl.inventory.util.SlotHandler
import net.projecttl.inventory.util.compareTo
import org.bukkit.Bukkit
import org.bukkit.block.Container
import org.bukkit.entity.Player
Expand Down Expand Up @@ -75,15 +76,15 @@ data class LinkedInventoryBuilder(
}

@EventHandler
private fun listener(event: InventoryClickEvent) {
if(event.view.title() == this.title) {
if (inventoryIds.contains(id) && event.currentItem != null && event.view.player == player) {
if (event.inventory == inventory) {
private fun InventoryClickEvent.listener() {
if (title.compareTo(this.view.title())) {
if (inventoryIds.contains(id) && this.currentItem != null && this.view.player == player) {
if (this.inventory == inventory) {
for (slot in slots.entries) {
if (slot.key == event.rawSlot){
event.isCancelled = true
if (slot.key == this.rawSlot){
this.isCancelled = true
slot.value.handler.click.forEach {
it(event)
it(this)
}
}
}
Expand All @@ -92,28 +93,26 @@ data class LinkedInventoryBuilder(
}
}

@EventHandler
private fun listener2(event: InventoryMoveItemEvent) {
if (inventoryIds.contains(id) && event.source.holder?.inventory?.viewers?.contains(player)!!
&& event.source.holder is Container && (event.source.holder as Container).customName() == this.title
private fun InventoryMoveItemEvent.listener2() {
if (inventoryIds.contains(id) && this.source.holder?.inventory?.viewers?.contains(player)!!
&& this.source.holder is Container && (this.source.holder as Container).customName() == title
)
event.isCancelled = true
this.isCancelled = true
}

@EventHandler
private fun listener3(event: InventoryCloseEvent) {
private fun InventoryCloseEvent.listener3() {
for(closeHandler in closeHandlers) {
closeHandler(event)
closeHandler(this)
}
if (event.view.player == player && inventoryIds.contains(id))
if (this.view.player == player && inventoryIds.contains(id))
inventoryIds.remove(id)
}

@EventHandler
private fun listener4(event: PlayerSwapHandItemsEvent) {
if (event.player.inventory == inventory) {
event.isCancelled = true

private fun PlayerSwapHandItemsEvent.listener4() {
if (this.player.inventory == inventory) {
this.isCancelled = true
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import net.projecttl.inventory.InventoryGUI.inventoryIds
import net.projecttl.inventory.InventoryGUI.plugin
import net.projecttl.inventory.util.InventoryType
import net.projecttl.inventory.util.Slot
import net.projecttl.inventory.util.compareTo
import org.bukkit.Bukkit
import org.bukkit.block.Container
import org.bukkit.entity.Player
Expand All @@ -17,13 +18,11 @@ import org.bukkit.event.player.PlayerSwapHandItemsEvent
import org.bukkit.inventory.Inventory
import org.bukkit.inventory.ItemStack
import java.util.*
import kotlin.collections.HashMap

class SimpleInventoryBuilder(
override val player: Player,
override val slotType: InventoryType,
override val title: Component,
val access: Boolean = false
override val title: Component
) : Listener, InventoryBuilder {
override val slots = HashMap<Int, Slot>()
val closeHandlers = ArrayList<InventoryCloseEvent.() -> Unit>()
Expand All @@ -40,14 +39,14 @@ class SimpleInventoryBuilder(
override fun slot(slot: Int, item: ItemStack, handler: InventoryClickEvent.() -> Unit) {
slots[slot] = Slot(item, handler)
}

override fun onClose(handler: InventoryCloseEvent.() -> Unit) {
closeHandlers.add(handler)
}

override fun slot(slot: Int, item: ItemStack) {
slot(slot, item) {}
}

override fun onClose(handler: InventoryCloseEvent.() -> Unit) {
closeHandlers.add(handler)
}

override fun close() {
if(this::inventory.isInitialized)
Expand All @@ -65,18 +64,14 @@ class SimpleInventoryBuilder(
}

@EventHandler
private fun listener(event: InventoryClickEvent) {
if(event.view.title() == this.title) {
if (inventoryIds.contains(id) && event.currentItem != null && event.view.player == player) {
if (event.inventory == inventory) {
if (!access) {
event.isCancelled = true
}

private fun InventoryClickEvent.listener() {
if (title.compareTo(this.view.title())) {
if (inventoryIds.contains(id) && this.currentItem != null && this.view.player == player) {
if (this.inventory == inventory) {
for (slot in slots.entries) {
if (slot.key == event.rawSlot){
event.isCancelled = true
slot.value.click(event)
if (slot.key == this.rawSlot){
this.isCancelled = true
slot.value.click(this)
}
}
}
Expand All @@ -85,24 +80,24 @@ class SimpleInventoryBuilder(
}

@EventHandler
private fun listener2(event: InventoryMoveItemEvent) {
if (inventoryIds.contains(id) && event.source.holder?.inventory?.viewers?.contains(player)!!
&& event.source.holder is Container && (event.source.holder as Container).customName() == this.title)
event.isCancelled = true
private fun InventoryMoveItemEvent.listener2() {
if (inventoryIds.contains(id) && this.source.holder?.inventory?.viewers?.contains(player)!!
&& this.source.holder is Container && (this.source.holder as Container).customName() == title)
this.isCancelled = true
}

@EventHandler
private fun listener3(event: InventoryCloseEvent) {
private fun InventoryCloseEvent.listener3() {
for(closeHandler in closeHandlers)
closeHandler(event)
if(event.view.player == player && inventoryIds.contains(id))
closeHandler(this)
if(this.view.player == player && inventoryIds.contains(id))
inventoryIds.remove(id)
}

@EventHandler
private fun listener4(event: PlayerSwapHandItemsEvent) {
if (event.player.inventory == inventory) {
event.isCancelled = true
private fun PlayerSwapHandItemsEvent.listener4() {
if (this.player.inventory == inventory) {
this.isCancelled = true
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package net.projecttl.inventory.util

import net.kyori.adventure.text.Component
import net.kyori.adventure.text.minimessage.MiniMessage
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer

fun String.toMini(): Component = MiniMessage.miniMessage().deserialize(this)
fun Component.toOriginal(): String = MiniMessage.miniMessage().serialize(this)

fun Component.compareTo(comp: Component): Boolean {
val original = PlainTextComponentSerializer.plainText().serialize(this)
val target = PlainTextComponentSerializer.plainText().serialize(comp)

return original.contains(target)
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package net.projecttl.inventorygui.test

import io.papermc.paper.event.player.AsyncChatEvent
import net.kyori.adventure.text.Component
import net.kyori.adventure.text.Component.text
import net.kyori.adventure.text.format.NamedTextColor
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer
import net.projecttl.inventory.animatedGui
import net.projecttl.inventory.gui
import net.projecttl.inventory.util.InventoryType
import org.bukkit.Bukkit
import org.bukkit.Material
import org.bukkit.event.EventHandler
Expand All @@ -17,17 +15,20 @@ import org.bukkit.plugin.java.JavaPlugin
import kotlin.random.Random

class InventoryGuiTest : JavaPlugin(), Listener {
lateinit var instance: InventoryGuiTest
private set

override fun onEnable() {
instance = this
server.pluginManager.registerEvents(this, this)
}

@EventHandler
fun chat(event: AsyncChatEvent) {
if(PlainTextComponentSerializer.plainText().serialize(event.message()).contains("animation")) {
println(PlainTextComponentSerializer.plainText().serialize(event.message()))
Bukkit.getScheduler().scheduleSyncDelayedTask(this) {
val anim = event.player.animatedGui(text("Hi", NamedTextColor.GREEN)) {
fun AsyncChatEvent.chat() {
if(PlainTextComponentSerializer.plainText().serialize(this.message()).contains("animation")) {
println(PlainTextComponentSerializer.plainText().serialize(this.message()))
Bukkit.getScheduler().scheduleSyncDelayedTask(instance) {
val anim = this.player.animatedGui(text("Hi", NamedTextColor.GREEN)) {
base {
slot(0, ItemStack(Material.WHITE_STAINED_GLASS_PANE))
slot(1, ItemStack(Material.WHITE_STAINED_GLASS_PANE))
Expand Down Expand Up @@ -83,9 +84,9 @@ class InventoryGuiTest : JavaPlugin(), Listener {
}
anim.start()
}
} else if(PlainTextComponentSerializer.plainText().serialize(event.message()).contains("normal")) {
Bukkit.getScheduler().scheduleSyncDelayedTask(this) {
event.player.gui(text("")) {
} else if(PlainTextComponentSerializer.plainText().serialize(this.message()).contains("normal")) {
Bukkit.getScheduler().scheduleSyncDelayedTask(instance) {
this.player.gui(text("")) {
slot(1, ItemStack(Material.IRON_INGOT))
}
}
Expand Down
14 changes: 7 additions & 7 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
plugins {
java
kotlin("jvm") version "1.9.22"
id("org.jetbrains.dokka") version "1.9.10"
id("com.github.johnrengelman.shadow") version "8.1.1"
kotlin("jvm") version "2.0.0"
id("com.gradleup.shadow") version "8.3.0"
id("org.jetbrains.dokka") version "1.9.20"

`maven-publish`
}

group = "net.projecttl"
version = "4.5.2"
version = "4.6.0"

allprojects {
apply(plugin = "com.github.johnrengelman.shadow")
apply(plugin = "com.gradleup.shadow")
apply(plugin = "org.jetbrains.kotlin.jvm")
apply(plugin = "org.jetbrains.dokka")

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
languageVersion.set(JavaLanguageVersion.of(21))
}
}

Expand All @@ -39,7 +39,7 @@ subprojects {

dependencies {
implementation(kotlin("stdlib"))
compileOnly("io.papermc.paper:paper-api:1.20.4-R0.1-SNAPSHOT")
compileOnly("io.papermc.paper:paper-api:1.21.1-R0.1-SNAPSHOT")
if (this@subprojects.name != "InventoryGUI-api") {
dependencies {
implementation(project(":InventoryGUI-api"))
Expand Down

0 comments on commit 95d24a1

Please sign in to comment.