From fdd2e01ad3a2117b8a1058c3d27ccfe1540631da Mon Sep 17 00:00:00 2001 From: Shynixn Date: Tue, 17 Sep 2024 18:03:48 +0200 Subject: [PATCH 1/2] #552 Fixed ball spawning in minigame lobbies. --- build.gradle.kts | 6 +++--- .../com/github/shynixn/blockball/impl/SoccerMiniGameImpl.kt | 1 + .../impl/service/DependencyPlaceHolderServiceImpl.kt | 6 ++++-- .../shynixn/blockball/impl/service/GameServiceImpl.kt | 4 +++- src/main/resources/plugin-legacy.yml | 2 +- src/main/resources/plugin.yml | 2 +- 6 files changed, 13 insertions(+), 8 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 070d0cc15..2fe093323 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -9,7 +9,7 @@ plugins { } group = "com.github.shynixn" -version = "7.3.0" +version = "7.3.1" repositories { mavenLocal() @@ -26,7 +26,7 @@ tasks.register("printVersion") { dependencies { // Compile Only - compileOnly("me.clip:placeholderapi:2.9.2") + compileOnly("me.clip:placeholderapi:2.11.6") compileOnly("org.spigotmc:spigot-api:1.18.2-R0.1-SNAPSHOT") // Library dependencies with legacy compatibility, we can use more up-to-date version in the plugin.yml @@ -42,7 +42,7 @@ dependencies { // Custom dependencies implementation("com.github.shynixn.mcutils:common:2024.23") - implementation("com.github.shynixn.mcutils:packet:2024.33") + implementation("com.github.shynixn.mcutils:packet:2024.38") implementation("com.github.shynixn.mcutils:database:2024.2") implementation("com.github.shynixn.mcutils:sign:2024.3") implementation("com.github.shynixn.mcutils:guice:2024.2") diff --git a/src/main/java/com/github/shynixn/blockball/impl/SoccerMiniGameImpl.kt b/src/main/java/com/github/shynixn/blockball/impl/SoccerMiniGameImpl.kt index 756eb1585..9caf9d52c 100644 --- a/src/main/java/com/github/shynixn/blockball/impl/SoccerMiniGameImpl.kt +++ b/src/main/java/com/github/shynixn/blockball/impl/SoccerMiniGameImpl.kt @@ -156,6 +156,7 @@ class SoccerMiniGameImpl constructor( playing = true status = GameState.RUNNING matchTimeIndex = -1 + ballEnabled = true switchToNextMatchTime() } } diff --git a/src/main/java/com/github/shynixn/blockball/impl/service/DependencyPlaceHolderServiceImpl.kt b/src/main/java/com/github/shynixn/blockball/impl/service/DependencyPlaceHolderServiceImpl.kt index 17bf4c59c..82c3285cd 100644 --- a/src/main/java/com/github/shynixn/blockball/impl/service/DependencyPlaceHolderServiceImpl.kt +++ b/src/main/java/com/github/shynixn/blockball/impl/service/DependencyPlaceHolderServiceImpl.kt @@ -1,3 +1,5 @@ +@file:Suppress("UselessCallOnNotNull") + package com.github.shynixn.blockball.impl.service import com.github.shynixn.blockball.contract.SoccerGame @@ -58,8 +60,8 @@ class DependencyPlaceHolderServiceImpl @Inject constructor( return "blockball" } - override fun onPlaceholderRequest(player: Player?, params: String?): String? { - if (params == null) { + override fun onPlaceholderRequest(player: Player?, params: String): String? { + if (params.isNullOrBlank()) { return null } diff --git a/src/main/java/com/github/shynixn/blockball/impl/service/GameServiceImpl.kt b/src/main/java/com/github/shynixn/blockball/impl/service/GameServiceImpl.kt index 8f3dcc16d..b167770cc 100644 --- a/src/main/java/com/github/shynixn/blockball/impl/service/GameServiceImpl.kt +++ b/src/main/java/com/github/shynixn/blockball/impl/service/GameServiceImpl.kt @@ -118,7 +118,9 @@ class GameServiceImpl @Inject constructor( scoreboardService, commandService, soccerBallFactory - ) + ).also { + it.ballEnabled = false + } } games.add(game) diff --git a/src/main/resources/plugin-legacy.yml b/src/main/resources/plugin-legacy.yml index 1ac5deb7b..43f6b2cb5 100644 --- a/src/main/resources/plugin-legacy.yml +++ b/src/main/resources/plugin-legacy.yml @@ -1,5 +1,5 @@ name: BlockBall -version: 7.3.0 +version: 7.3.1 author: Shynixn website: https://www.spigotmc.org/members/shynixn.63455/ main: com.github.shynixn.blockball.BlockBallPlugin diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 70d56fff5..281a1018e 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: BlockBall -version: 7.3.0 +version: 7.3.1 author: Shynixn website: https://www.spigotmc.org/members/shynixn.63455/ main: com.github.shynixn.blockball.BlockBallPlugin From ecf709efd2805d76336abb74a44cf4298586e29f Mon Sep 17 00:00:00 2001 From: Shynixn Date: Tue, 17 Sep 2024 18:37:11 +0200 Subject: [PATCH 2/2] #531 Improved region select. --- .../BlockBallCommandExecutor.kt | 64 +++++++++++++++---- .../blockball/impl/service/GameServiceImpl.kt | 6 +- 2 files changed, 54 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/github/shynixn/blockball/impl/commandexecutor/BlockBallCommandExecutor.kt b/src/main/java/com/github/shynixn/blockball/impl/commandexecutor/BlockBallCommandExecutor.kt index 38765ff4f..cc4a91baf 100644 --- a/src/main/java/com/github/shynixn/blockball/impl/commandexecutor/BlockBallCommandExecutor.kt +++ b/src/main/java/com/github/shynixn/blockball/impl/commandexecutor/BlockBallCommandExecutor.kt @@ -27,7 +27,9 @@ import org.bukkit.plugin.Plugin import java.awt.Color import java.util.* import java.util.logging.Level -import kotlin.collections.ArrayList +import kotlin.math.floor +import kotlin.math.max +import kotlin.math.min class BlockBallCommandExecutor @Inject constructor( private val arenaRepository: CacheRepository, @@ -549,14 +551,18 @@ class BlockBallCommandExecutor @Inject constructor( } if (selectionType == SelectionType.FIELD) { - arena.lowerCorner = selectionLeft.toVector3d() - arena.upperCorner = selectionRight.toVector3d() + arena.lowerCorner = convertToOuterLowerCorner(selectionLeft.toVector3d(), selectionRight.toVector3d()) + arena.upperCorner = convertToOuterUpperCorner(selectionLeft.toVector3d(), selectionRight.toVector3d()) } else if (selectionType == SelectionType.RED_GOAL) { - arena.meta.redTeamMeta.goal.lowerCorner = selectionLeft.toVector3d() - arena.meta.redTeamMeta.goal.upperCorner = selectionRight.toVector3d() + arena.meta.redTeamMeta.goal.lowerCorner = + convertToOuterLowerCorner(selectionLeft.toVector3d(), selectionRight.toVector3d()) + arena.meta.redTeamMeta.goal.upperCorner = + convertToOuterUpperCorner(selectionLeft.toVector3d(), selectionRight.toVector3d()) } else if (selectionType == SelectionType.BLUE_GOAL) { - arena.meta.blueTeamMeta.goal.lowerCorner = selectionLeft.toVector3d() - arena.meta.blueTeamMeta.goal.upperCorner = selectionRight.toVector3d() + arena.meta.blueTeamMeta.goal.lowerCorner = + convertToOuterLowerCorner(selectionLeft.toVector3d(), selectionRight.toVector3d()) + arena.meta.blueTeamMeta.goal.upperCorner = + convertToOuterUpperCorner(selectionLeft.toVector3d(), selectionRight.toVector3d()) } } @@ -564,6 +570,29 @@ class BlockBallCommandExecutor @Inject constructor( player.sendMessage(language.selectionSetMessage.format(selectionType.name.lowercase())) } + /** + * The block selection is not precise enough, we want to exact corner location. + */ + private fun convertToOuterUpperCorner(selection1: Vector3d, selection2: Vector3d): Vector3d { + return Vector3d( + selection1.world, + max(selection1.x + 0.99, selection2.x + 0.99), + max(selection1.y + 0.99, selection2.y + 0.99), + max(selection1.z + 0.99, selection2.z + 0.99) + ) + } + + /** + * The block selection is not precise enough, we want to exact corner location. + */ + private fun convertToOuterLowerCorner(selection1: Vector3d, selection2: Vector3d): Vector3d { + return Vector3d( + selection1.world, + min(selection1.x, selection2.x), + min(selection1.y, selection2.y), + min(selection1.z, selection2.z) + ) + } private suspend fun setSign(sender: Player, arena: SoccerArena, signType: SignType) { if (signType == SignType.JOIN) { @@ -678,8 +707,8 @@ class BlockBallCommandExecutor @Inject constructor( if (arena.lowerCorner != null && arena.upperCorner != null) { highLights.add( AreaHighlight( - arena.lowerCorner!!, - arena.upperCorner!!, + roundLocation(arena.lowerCorner!!), + roundLocation(arena.upperCorner!!), Color.BLACK.rgb, "Field", true @@ -689,8 +718,8 @@ class BlockBallCommandExecutor @Inject constructor( if (arena.meta.redTeamMeta.goal.lowerCorner != null && arena.meta.redTeamMeta.goal.upperCorner != null) { highLights.add( AreaHighlight( - arena.meta.redTeamMeta.goal.lowerCorner!!, - arena.meta.redTeamMeta.goal.upperCorner!!, + roundLocation(arena.meta.redTeamMeta.goal.lowerCorner!!), + roundLocation(arena.meta.redTeamMeta.goal.upperCorner!!), Color.RED.rgb, "Red" ) @@ -699,8 +728,8 @@ class BlockBallCommandExecutor @Inject constructor( if (arena.meta.blueTeamMeta.goal.lowerCorner != null && arena.meta.blueTeamMeta.goal.upperCorner != null) { highLights.add( AreaHighlight( - arena.meta.blueTeamMeta.goal.lowerCorner!!, - arena.meta.blueTeamMeta.goal.upperCorner!!, + roundLocation(arena.meta.blueTeamMeta.goal.lowerCorner!!), + roundLocation(arena.meta.blueTeamMeta.goal.upperCorner!!), Color.BLUE.rgb, "Blue" ) @@ -776,4 +805,13 @@ class BlockBallCommandExecutor @Inject constructor( } } } + + private fun roundLocation(vector3d: Vector3d): Vector3d { + return Vector3d( + vector3d.world, + floor(vector3d.x), + floor(vector3d.y), + floor(vector3d.z) + ) + } } diff --git a/src/main/java/com/github/shynixn/blockball/impl/service/GameServiceImpl.kt b/src/main/java/com/github/shynixn/blockball/impl/service/GameServiceImpl.kt index b167770cc..bb042c4c2 100644 --- a/src/main/java/com/github/shynixn/blockball/impl/service/GameServiceImpl.kt +++ b/src/main/java/com/github/shynixn/blockball/impl/service/GameServiceImpl.kt @@ -250,19 +250,19 @@ class GameServiceImpl @Inject constructor( } private fun validateGoalSize(arena: SoccerArena, team: Team, teamMeta: TeamMeta) { - if (abs(teamMeta.goal.upperCorner!!.x - teamMeta.goal.lowerCorner!!.x) < 2) { + if (abs(teamMeta.goal.upperCorner!!.x - teamMeta.goal.lowerCorner!!.x) < 1.8) { throw SoccerGameException( arena, "The goal for team ${team.name} should be at least 2x2x2 for ${arena.name}!" ) } - if (abs(teamMeta.goal.upperCorner!!.y - teamMeta.goal.lowerCorner!!.y) < 2) { + if (abs(teamMeta.goal.upperCorner!!.y - teamMeta.goal.lowerCorner!!.y) < 1.8) { throw SoccerGameException( arena, "The goal for team ${team.name} should be at least 2x2x2 for ${arena.name}!" ) } - if (abs(teamMeta.goal.upperCorner!!.z - teamMeta.goal.lowerCorner!!.z) < 2) { + if (abs(teamMeta.goal.upperCorner!!.z - teamMeta.goal.lowerCorner!!.z) < 1.8) { throw SoccerGameException( arena, "The goal for team ${team.name} should be at least 2x2x2 for ${arena.name}!"