Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: GUI management #135

Open
wants to merge 48 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
f94d77c
feat(gui): Begin first implementation of guis
Distractic Dec 14, 2023
9431249
chore: Remove unused property
Distractic Dec 14, 2023
a960c11
fix: Stack overflow when close gui
Distractic Dec 14, 2023
c532cf8
fix: Add way to create inventory from scratch
Distractic Dec 14, 2023
0fc9c14
fix: Use requireOpen function
Distractic Dec 14, 2023
74cd704
chore: Format
Distractic Dec 14, 2023
96d23fb
fix: Change scope property
Distractic Dec 14, 2023
85c1f89
fix: Safe open by multiple check
Distractic Dec 15, 2023
8b0980d
test(gui-listener): Begin test about close GUI
Distractic Dec 15, 2023
e058f80
chore: Return boolean when open GUI
Distractic Dec 15, 2023
b42ba7c
test: GUI on click
Distractic Dec 15, 2023
b613270
test: Begin test for PersonalGUI close
Distractic Dec 15, 2023
c8d302c
fix(personal-gui): Create custom inventory for personal GUI
Distractic Dec 15, 2023
2efa65c
fix: Click on item when inventory open
Distractic Dec 15, 2023
8cd1bab
test: Fix test about call suspending event
Distractic Dec 15, 2023
e3890f1
test: Add test to trigger call event
Distractic Dec 15, 2023
a93e84e
test: Implement tests for Personal GUI
Distractic Dec 15, 2023
7301933
fix: Use mutex to avoid async issue
Distractic Dec 15, 2023
0237770
chore: Remove import
Distractic Dec 15, 2023
a47a1dc
test: Open GUI for Personal GUI
Distractic Dec 15, 2023
5368455
feat: Dedicate GUI for player or language
Distractic Dec 16, 2023
ef66b2c
chore: Rename classes
Distractic Dec 16, 2023
0bc8fd1
feat: Loading GUI (#134)
Distractic Dec 19, 2023
6778670
feat: Implement update function
Distractic Dec 19, 2023
d25ea07
test: Add tests about update method
Distractic Dec 19, 2023
1059883
chore: Move clear inventory out of Job
Distractic Dec 19, 2023
9921afd
doc: Add missing property documentation
Distractic Dec 19, 2023
72cf8a3
fix: Use UNIT as singleton value
Distractic Dec 19, 2023
84af5c9
fix: Avoid unnecessary operation if shift is 0
Distractic Dec 19, 2023
134ccf6
test: Begin test about shift inventory animation
Distractic Dec 19, 2023
8173489
chore: Optimize and create new function for Client
Distractic Dec 19, 2023
b885923
test: Add tests about inventory management
Distractic Dec 19, 2023
55f8c45
fix: Add dedicated function to simplify management
Distractic Dec 20, 2023
5e5305d
fix: Keep loading state if animation end
Distractic Dec 20, 2023
a54555d
fix: Avoid useless shift for animation
Distractic Dec 20, 2023
1358911
test: Add tests about fill animation
Distractic Dec 20, 2023
8f530e7
test: Add verification for close GUI
Distractic Dec 20, 2023
58e4ec9
test: Add test about update for single GUI
Distractic Dec 20, 2023
5b83371
test: Add test about shift constructor
Distractic Dec 20, 2023
f21da9c
chore: Remove property exception
Distractic Dec 20, 2023
94bc53b
test: Add check test about stop animation
Distractic Dec 20, 2023
b35071d
fix: Rollback scope API plugin
Distractic Dec 20, 2023
728ae87
chore: Remove unused method
Distractic Dec 20, 2023
3259de4
fix: remove & move right click item on click inventory
Distractic Dec 21, 2023
2fd2115
chore: Remove await cancellation
Distractic Dec 23, 2023
0ad4fa6
refactor: Add suspend modifier to 'createInventory' across multiple c…
cizetux Jan 3, 2024
c465130
refactor: Add data colors to each GameState
cizetux Sep 7, 2024
8f7281d
refactor: Add 'permanent' field to handle games that are in permanent…
cizetux Sep 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import io.gitlab.arturbosch.detekt.Detekt
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
Expand Down Expand Up @@ -130,6 +131,16 @@ tasks {
targetCompatibility = javaVersionString
}

withType<Detekt>().configureEach {
reports {
html.required.set(true)
xml.required.set(true)
txt.required.set(false)
sarif.required.set(false)
md.required.set(false)
}
}

test {
useJUnitPlatform()
}
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-rc-1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 2 additions & 0 deletions src/main/kotlin/com/github/rushyverse/api/APIPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.github.rushyverse.api

import com.github.rushyverse.api.extension.registerListener
import com.github.rushyverse.api.game.SharedGameData
import com.github.rushyverse.api.gui.GUIManager
import com.github.rushyverse.api.koin.CraftContext
import com.github.rushyverse.api.koin.loadModule
import com.github.rushyverse.api.listener.api.LanguageListener
Expand Down Expand Up @@ -37,6 +38,7 @@ public class APIPlugin : JavaPlugin() {
single { ScoreboardManager() }
single { LanguageManager() }
single { SharedGameData() }
single { GUIManager() }
}

registerListener { LanguageListener() }
Expand Down
15 changes: 13 additions & 2 deletions src/main/kotlin/com/github/rushyverse/api/Plugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.github.rushyverse.api.configuration.reader.IFileReader
import com.github.rushyverse.api.configuration.reader.YamlFileReader
import com.github.rushyverse.api.extension.asComponent
import com.github.rushyverse.api.extension.registerListener
import com.github.rushyverse.api.gui.GUIListener
import com.github.rushyverse.api.koin.CraftContext
import com.github.rushyverse.api.koin.inject
import com.github.rushyverse.api.koin.loadModule
Expand All @@ -16,11 +17,21 @@ import com.github.rushyverse.api.player.Client
import com.github.rushyverse.api.player.ClientManager
import com.github.rushyverse.api.player.ClientManagerImpl
import com.github.rushyverse.api.player.language.LanguageManager
import com.github.rushyverse.api.serializer.*
import com.github.rushyverse.api.serializer.ComponentSerializer
import com.github.rushyverse.api.serializer.DyeColorSerializer
import com.github.rushyverse.api.serializer.EnchantmentSerializer
import com.github.rushyverse.api.serializer.ItemStackSerializer
import com.github.rushyverse.api.serializer.LocationSerializer
import com.github.rushyverse.api.serializer.MaterialSerializer
import com.github.rushyverse.api.serializer.NamespacedSerializer
import com.github.rushyverse.api.serializer.PatternSerializer
import com.github.rushyverse.api.serializer.PatternTypeSerializer
import com.github.rushyverse.api.serializer.RangeDoubleSerializer
import com.github.rushyverse.api.translation.ResourceBundleTranslator
import com.github.rushyverse.api.translation.Translator
import com.github.rushyverse.api.translation.registerResourceBundleForSupportedLocales
import com.github.shynixn.mccoroutine.bukkit.SuspendingJavaPlugin
import java.util.*
import kotlinx.serialization.modules.SerializersModule
import kotlinx.serialization.modules.SerializersModuleBuilder
import kotlinx.serialization.modules.contextual
Expand All @@ -29,7 +40,6 @@ import org.bukkit.entity.Player
import org.jetbrains.annotations.Blocking
import org.koin.core.module.Module
import org.koin.dsl.bind
import java.util.*

/**
* Represents the base functionality required to create a plugin.
Expand Down Expand Up @@ -70,6 +80,7 @@ public abstract class Plugin(

registerListener { PlayerListener(this) }
registerListener { VillagerListener(this) }
registerListener { GUIListener(this) }
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

package com.github.rushyverse.api.extension

import java.math.BigInteger
import java.util.*
import net.kyori.adventure.text.Component
import net.kyori.adventure.text.TextComponent
import net.kyori.adventure.text.format.NamedTextColor
import net.kyori.adventure.text.minimessage.MiniMessage
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver
import net.kyori.adventure.text.minimessage.tag.standard.StandardTags
import java.math.BigInteger
import java.util.*

/**
* MiniMessage instance to deserialize components without strict mode.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
package com.github.rushyverse.api.extension.event

import com.github.shynixn.mccoroutine.bukkit.callSuspendingEvent
import kotlinx.coroutines.joinAll
import org.bukkit.Bukkit
import org.bukkit.block.BlockFace
import org.bukkit.entity.Damageable
import org.bukkit.entity.Player
import org.bukkit.event.block.Action
import org.bukkit.event.entity.EntityDamageEvent
import org.bukkit.event.player.PlayerInteractEvent
import org.bukkit.inventory.ItemStack
import org.bukkit.plugin.Plugin

/**
* Future life of the damaged entity.
Expand All @@ -15,3 +24,31 @@ public fun EntityDamageEvent.finalDamagedHealth(): Double? {
null
}
}

/**
* Create a [PlayerInteractEvent] to simulate a right click with an item for a player and call it.
* @param plugin Plugin to call the event.
* @param player Player who clicked.
* @param item Item that was clicked.
*/
public suspend fun callRightClickOnItemEvent(plugin: Plugin, player: Player, item: ItemStack) {
val rightClickWithItemEvent = createRightClickEventWithItem(player, item)
Bukkit.getPluginManager().callSuspendingEvent(rightClickWithItemEvent, plugin).joinAll()
}

/**
* Create a PlayerInteractEvent to simulate a right click with an item.
* @param player Player who clicked.
* @param item Item that was clicked.
* @return The new event.
*/
private fun createRightClickEventWithItem(
player: Player,
item: ItemStack
) = PlayerInteractEvent(
player,
Action.RIGHT_CLICK_AIR,
item,
null,
BlockFace.NORTH // random value not null
)
1 change: 1 addition & 0 deletions src/main/kotlin/com/github/rushyverse/api/game/GameData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ public data class GameData(
val id: Int,
var players: Int = 0,
var state: GameState = GameState.WAITING,
val permanent: Boolean = false
)
17 changes: 12 additions & 5 deletions src/main/kotlin/com/github/rushyverse/api/game/GameState.kt
Original file line number Diff line number Diff line change
@@ -1,33 +1,40 @@
package com.github.rushyverse.api.game

import net.kyori.adventure.text.format.NamedTextColor

/**
* Represents the various states a game can be in at any given moment.
* Each state corresponds to a different phase in the game's lifecycle.
*/
public enum class GameState {
public enum class GameState(
public val color: NamedTextColor,
public val miniColor: String,
) {

NOT_STARTED(NamedTextColor.BLUE, "<blue>"),

/**
* Represents the state where the game is waiting for necessary conditions to start.
* This could be waiting for more players to join, or waiting for some setup process to finish.
*/
WAITING,
WAITING(NamedTextColor.GOLD, "<gold>"),

/**
* Represents the state when the game is in the process of starting.
* This is a transitional phase, initialization of game resources,
* a countdown timer before the game starts, etc.
*/
STARTING,
STARTING(NamedTextColor.YELLOW, "<yellow>"),

/**
* Represents the state where the game has officially started.
* Gameplay is active during this state.
*/
STARTED,
STARTED(NamedTextColor.GREEN, "<green>"),

/**
* Represents the state when the game is in the process of ending.
* This is a transitional phase, where final scores might be calculated, game resources might be cleaned up, etc.
*/
ENDING;
ENDED(NamedTextColor.RED, "<red>");
}
Loading
Loading