Skip to content

Commit

Permalink
#521 Removed block selection listeners.
Browse files Browse the repository at this point in the history
  • Loading branch information
Shynixn committed Aug 9, 2024
1 parent 19a2656 commit 730fbf5
Show file tree
Hide file tree
Showing 13 changed files with 283 additions and 311 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.2")

// Custom dependencies
implementation("com.github.shynixn.mcutils:common:2024.19")
implementation("com.github.shynixn.mcutils:packet:2024.32")
implementation("com.github.shynixn.mcutils:common:2024.20")
implementation("com.github.shynixn.mcutils:packet:2024.33")
implementation("com.github.shynixn.mcutils:database:2024.2")
implementation("com.github.shynixn.mcutils:sign:2024.3")
implementation("com.github.shynixn.mcutils:guice:2024.2")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import com.fasterxml.jackson.core.type.TypeReference
import com.github.shynixn.blockball.contract.*
import com.github.shynixn.blockball.entity.SoccerArena
import com.github.shynixn.blockball.entity.PlayerInformation
import com.github.shynixn.blockball.enumeration.Permission
import com.github.shynixn.blockball.impl.service.*
import com.github.shynixn.mccoroutine.bukkit.launch
import com.github.shynixn.mccoroutine.bukkit.minecraftDispatcher
import com.github.shynixn.mcutils.common.ConfigurationService
import com.github.shynixn.mcutils.common.ConfigurationServiceImpl
import com.github.shynixn.mcutils.common.CoroutineExecutor
Expand All @@ -15,6 +17,7 @@ import com.github.shynixn.mcutils.common.repository.CacheRepository
import com.github.shynixn.mcutils.common.repository.CachedRepositoryImpl
import com.github.shynixn.mcutils.common.repository.Repository
import com.github.shynixn.mcutils.common.repository.YamlFileRepositoryImpl
import com.github.shynixn.mcutils.common.selection.AreaSelectionService
import com.github.shynixn.mcutils.common.sound.SoundService
import com.github.shynixn.mcutils.common.sound.SoundServiceImpl
import com.github.shynixn.mcutils.database.api.CachePlayerRepository
Expand All @@ -23,14 +26,17 @@ import com.github.shynixn.mcutils.database.impl.AutoSavePlayerDataRepositoryImpl
import com.github.shynixn.mcutils.database.impl.CachePlayerDataRepositoryImpl
import com.github.shynixn.mcutils.database.impl.ConfigSelectedRepositoryImpl
import com.github.shynixn.mcutils.guice.DependencyInjectionModule
import com.github.shynixn.mcutils.packet.api.Packet
import com.github.shynixn.mcutils.packet.api.PacketService
import com.github.shynixn.mcutils.packet.api.RayTracingService
import com.github.shynixn.mcutils.packet.impl.service.ChatMessageServiceImpl
import com.github.shynixn.mcutils.packet.impl.service.ItemServiceImpl
import com.github.shynixn.mcutils.packet.impl.service.PacketServiceImpl
import com.github.shynixn.mcutils.packet.impl.service.RayTracingServiceImpl
import com.github.shynixn.mcutils.packet.nms.v1_21_R1.AreaSelectionServiceImpl
import com.github.shynixn.mcutils.sign.SignService
import com.github.shynixn.mcutils.sign.SignServiceImpl
import kotlinx.coroutines.CoroutineDispatcher
import org.bukkit.Bukkit
import org.bukkit.plugin.Plugin
import java.util.logging.Level
Expand Down Expand Up @@ -101,7 +107,25 @@ class BlockBallDependencyInjectionModule(
addService<ChatMessageService>(ChatMessageServiceImpl(plugin))
addService<HubGameForcefieldService, HubGameForcefieldServiceImpl>()
addService<SoccerBallFactory, SoccerBallFactoryImpl>()
addService<BlockSelectionService, BlockSelectionServiceImpl>()
addService<AreaSelectionService> {
AreaSelectionServiceImpl(
Permission.EDIT_GAME.permission,
plugin,
getService<ItemService>(),
getService<PacketService>(),
object : CoroutineExecutor {
override fun execute(f: suspend () -> Unit) {
plugin.launch { f.invoke() }
}
},
plugin.minecraftDispatcher as CoroutineDispatcher,
object : CoroutineExecutor {
override fun execute(f: suspend () -> Unit) {
plugin.launch { f.invoke() }
}
}
)
}
addService<RayTracingService, RayTracingServiceImpl>()

if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ object BlockBallLanguageImpl : BlockBallLanguage {
/** &0&l[&f&lBlockBall&0&l]&c Team %1$1s does not exist. **/
override var teamDoesNotExistMessage : String = "&0&l[&f&lBlockBall&0&l]&c Team %1$1s does not exist."

/** &0&l[&f&lBlockBall&0&l]&c This selection type is not known. **/
override var selectionTypeDoesNotExistMessage : String = "&0&l[&f&lBlockBall&0&l]&c This selection type is not known. "

/** &0&l[&f&lBlockBall&0&l]&7 Reloaded game %1$1s. **/
override var reloadedGameMessage : String = "&0&l[&f&lBlockBall&0&l]&7 Reloaded game %1$1s."

Expand Down Expand Up @@ -75,6 +78,9 @@ object BlockBallLanguageImpl : BlockBallLanguage {
/** 60 **/
override var winBlueStay : String = "60"

/** Updates a location selection of a part of the arena. **/
override var commandSelectionToolTip : String = "Updates a location selection of a part of the arena."

/** &0&l[&f&lBlockBall&0&l]&7 Created game %1$1s. **/
override var gameCreatedMessage : String = "&0&l[&f&lBlockBall&0&l]&7 Created game %1$1s."

Expand Down Expand Up @@ -114,9 +120,6 @@ object BlockBallLanguageImpl : BlockBallLanguage {
/** All commands for the BlockBall plugin. **/
override var commandDescription : String = "All commands for the BlockBall plugin."

/** &0&l[&f&lBlockBall&0&l]&c This location type is not known. For more locations, open the arena.yml. **/
override var locationTypeDoesNotExistMessage : String = "&0&l[&f&lBlockBall&0&l]&c This location type is not known. For more locations, open the arena.yml."

/** &0&l[&f&lBlockBall&0&l]&c You do not have permission. **/
override var noPermissionMessage : String = "&0&l[&f&lBlockBall&0&l]&c You do not have permission."

Expand Down Expand Up @@ -144,6 +147,9 @@ object BlockBallLanguageImpl : BlockBallLanguage {
/** &aJoin **/
override var gameStatusJoinAble : String = "&aJoin"

/** Gives you the BlockBall selection axe. **/
override var commandAxeToolTip : String = "Gives you the BlockBall selection axe."

/** Lets the player executing the command join the game. The optional team argument allows to directly join a specific team. If the team is full, the other team will be chosen. If no team is specified, a random team will be selected. **/
override var commandJoinToolTip : String = "Lets the player executing the command join the game. The optional team argument allows to directly join a specific team. If the team is full, the other team will be chosen. If no team is specified, a random team will be selected."

Expand All @@ -159,12 +165,18 @@ object BlockBallLanguageImpl : BlockBallLanguage {
/** &9[Team Blue] **/
override var hubGameJoinBlue : String = "&9[Team Blue]"

/** Updates the location of a part of the arena. **/
override var commandLocationToolTip : String = "Updates the location of a part of the arena."

/** &9Team Blue **/
override var winBlueTitle : String = "&9Team Blue"

/** Toggles highlighting the important areas of your arena. **/
override var commandHighlightToolTip : String = "Toggles highlighting the important areas of your arena."

/** Sets a selected location for your arena. **/
override var commandSelectToolTip : String = "Sets a selected location for your arena."

/** &0&l[&f&lBlockBall&0&l]&7 Selection %1$1s was set. **/
override var selectionSetMessage : String = "&0&l[&f&lBlockBall&0&l]&7 Selection %1$1s was set."

/** 60 **/
override var winDrawStay : String = "60"

Expand All @@ -174,11 +186,14 @@ object BlockBallLanguageImpl : BlockBallLanguage {
/** &4Disabled **/
override var gameStatusDisabled : String = "&4Disabled"

/** &0&l[&f&lBlockBall&0&l]&c You need to select a location using the BlockBall axe with left click. **/
override var noLeftClickSelectionMessage : String = "&0&l[&f&lBlockBall&0&l]&c You need to select a location using the BlockBall axe with left click."

/** &0&l[&f&lBlockBall&0&l]&7 Updated inventory of game. **/
override var updatedInventoryMessage : String = "&0&l[&f&lBlockBall&0&l]&7 Updated inventory of game."

/** &0&l[&f&lBlockBall&0&l]&7 Location %1$1s was set on %2$1s. **/
override var spawnPointSetMessage : String = "&0&l[&f&lBlockBall&0&l]&7 Location %1$1s was set on %2$1s."
/** &0&l[&f&lBlockBall&0&l]&c You need to select a location using the BlockBall axe with right click. **/
override var noRightClickSelectionMessage : String = "&0&l[&f&lBlockBall&0&l]&c You need to select a location using the BlockBall axe with right click."

/** 20 **/
override var scoreBlueFadeIn : String = "20"
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/com/github/shynixn/blockball/BlockBallPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.github.shynixn.mcutils.common.ConfigurationService
import com.github.shynixn.mcutils.common.Version
import com.github.shynixn.mcutils.common.reloadTranslation
import com.github.shynixn.mcutils.common.repository.Repository
import com.github.shynixn.mcutils.common.selection.AreaSelectionService
import com.github.shynixn.mcutils.database.api.CachePlayerRepository
import com.github.shynixn.mcutils.database.api.PlayerDataRepository
import com.github.shynixn.mcutils.guice.DependencyInjectionModule
Expand All @@ -24,11 +25,9 @@ import org.bstats.bukkit.Metrics
import org.bukkit.Bukkit
import org.bukkit.plugin.ServicePriority
import org.bukkit.plugin.java.JavaPlugin
import java.io.File
import java.nio.file.Files
import java.nio.file.Paths
import java.nio.file.StandardCopyOption
import java.util.UUID
import java.util.*
import java.util.logging.Level

/**
Expand Down Expand Up @@ -105,7 +104,6 @@ class BlockBallPlugin : JavaPlugin() {
Bukkit.getPluginManager().registerEvents(module.getService<HubgameListener>(), this)
Bukkit.getPluginManager().registerEvents(module.getService<MinigameListener>(), this)
Bukkit.getPluginManager().registerEvents(module.getService<BallListener>(), this)
Bukkit.getPluginManager().registerEvents(module.getService<BlockSelectionListener>(), this)

// Register CommandExecutor
module.getService<BlockBallCommandExecutor>()
Expand Down Expand Up @@ -229,6 +227,7 @@ class BlockBallPlugin : JavaPlugin() {
}

module.getService<PacketService>().close()
module.getService<AreaSelectionService>().close()

val playerDataRepository = module.getService<CachePlayerRepository<PlayerInformation>>()
runBlocking {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ interface BlockBallLanguage {
/** &0&l[&f&lBlockBall&0&l]&c Team %1$1s does not exist. **/
var teamDoesNotExistMessage : String

/** &0&l[&f&lBlockBall&0&l]&c This selection type is not known. **/
var selectionTypeDoesNotExistMessage : String

/** &0&l[&f&lBlockBall&0&l]&7 Reloaded game %1$1s. **/
var reloadedGameMessage : String

Expand Down Expand Up @@ -73,6 +76,9 @@ interface BlockBallLanguage {
/** 60 **/
var winBlueStay : String

/** Updates a location selection of a part of the arena. **/
var commandSelectionToolTip : String

/** &0&l[&f&lBlockBall&0&l]&7 Created game %1$1s. **/
var gameCreatedMessage : String

Expand Down Expand Up @@ -112,9 +118,6 @@ interface BlockBallLanguage {
/** All commands for the BlockBall plugin. **/
var commandDescription : String

/** &0&l[&f&lBlockBall&0&l]&c This location type is not known. For more locations, open the arena.yml. **/
var locationTypeDoesNotExistMessage : String

/** &0&l[&f&lBlockBall&0&l]&c You do not have permission. **/
var noPermissionMessage : String

Expand Down Expand Up @@ -142,6 +145,9 @@ interface BlockBallLanguage {
/** &aJoin **/
var gameStatusJoinAble : String

/** Gives you the BlockBall selection axe. **/
var commandAxeToolTip : String

/** Lets the player executing the command join the game. The optional team argument allows to directly join a specific team. If the team is full, the other team will be chosen. If no team is specified, a random team will be selected. **/
var commandJoinToolTip : String

Expand All @@ -157,12 +163,18 @@ interface BlockBallLanguage {
/** &9[Team Blue] **/
var hubGameJoinBlue : String

/** Updates the location of a part of the arena. **/
var commandLocationToolTip : String

/** &9Team Blue **/
var winBlueTitle : String

/** Toggles highlighting the important areas of your arena. **/
var commandHighlightToolTip : String

/** Sets a selected location for your arena. **/
var commandSelectToolTip : String

/** &0&l[&f&lBlockBall&0&l]&7 Selection %1$1s was set. **/
var selectionSetMessage : String

/** 60 **/
var winDrawStay : String

Expand All @@ -172,11 +184,14 @@ interface BlockBallLanguage {
/** &4Disabled **/
var gameStatusDisabled : String

/** &0&l[&f&lBlockBall&0&l]&c You need to select a location using the BlockBall axe with left click. **/
var noLeftClickSelectionMessage : String

/** &0&l[&f&lBlockBall&0&l]&7 Updated inventory of game. **/
var updatedInventoryMessage : String

/** &0&l[&f&lBlockBall&0&l]&7 Location %1$1s was set on %2$1s. **/
var spawnPointSetMessage : String
/** &0&l[&f&lBlockBall&0&l]&c You need to select a location using the BlockBall axe with right click. **/
var noRightClickSelectionMessage : String

/** 20 **/
var scoreBlueFadeIn : String
Expand Down
32 changes: 16 additions & 16 deletions src/main/java/com/github/shynixn/blockball/entity/Selection.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,38 @@ open class Selection {

/** [upperCorner] of the selected square soccerArena. */
@JsonProperty("corner1")
final var upperCorner: Vector3d = Vector3d()
var upperCorner: Vector3d? = null

/** [lowerCorner] of the selected square soccerArena. */
@JsonProperty("corner2")
final var lowerCorner: Vector3d = Vector3d()
var lowerCorner: Vector3d? = null

/** [center] of the soccerArena */
val center: Vector3d
get() {
return Vector3d(
this.lowerCorner.world!!,
(this.lowerCorner.blockX + this.offsetX / 2).toDouble(),
(this.lowerCorner.blockY + offsetX / 2).toDouble(), (this.lowerCorner.blockZ + offsetZ / 2).toDouble()
this.lowerCorner!!.world!!,
(this.lowerCorner!!.blockX + this.offsetX / 2).toDouble(),
(this.lowerCorner!!.blockY + offsetX / 2).toDouble(), (this.lowerCorner!!.blockZ + offsetZ / 2).toDouble()
)
}

/** Length of the x axe. */
val offsetX: Int
get() {
return this.upperCorner.blockX - this.lowerCorner.blockX + 1
return this.upperCorner!!.blockX - this.lowerCorner!!.blockX + 1
}

/** Length of the y axe. */
val offsetY: Int
get() {
return this.upperCorner.blockY - this.lowerCorner.blockY + 1
return this.upperCorner!!.blockY - this.lowerCorner!!.blockY + 1
}

/** Length of the z axe. */
val offsetZ: Int
get() {
return this.upperCorner.blockZ - this.lowerCorner.blockZ
return this.upperCorner!!.blockZ - this.lowerCorner!!.blockZ
}


Expand All @@ -55,10 +55,10 @@ open class Selection {
* Is location inside of this selection.
*/
fun isLocationInSelection(location: Vector3d): Boolean {
if (location.world != null && location.world == this.upperCorner.world) {
if (this.upperCorner.x >= location.x && this.lowerCorner.x <= location.x) {
if (this.upperCorner.y >= location.y + 1 && this.lowerCorner.y <= location.y + 1) {
if (this.upperCorner.z >= location.z && this.lowerCorner.z <= location.z) {
if (location.world != null && location.world == this.upperCorner!!.world) {
if (this.upperCorner!!.x >= location.x && this.lowerCorner!!.x <= location.x) {
if (this.upperCorner!!.y >= location.y + 1 && this.lowerCorner!!.y <= location.y + 1) {
if (this.upperCorner!!.z >= location.z && this.lowerCorner!!.z <= location.z) {
return true
}
}
Expand All @@ -72,19 +72,19 @@ open class Selection {
* in which the soccerArena can be reached.
*/
fun getRelativeBlockDirectionToLocation(location: Vector3d): BlockDirection {
if (location.blockX >= upperCorner.blockX && this.upperCorner.z >= location.z && this.lowerCorner.z <= location.z) {
if (location.blockX >= upperCorner!!.blockX && this.upperCorner!!.z >= location.z && this.lowerCorner!!.z <= location.z) {
return BlockDirection.WEST
}

if (location.blockX <= lowerCorner.blockX && this.upperCorner.z >= location.z && this.lowerCorner.z <= location.z) {
if (location.blockX <= lowerCorner!!.blockX && this.upperCorner!!.z >= location.z && this.lowerCorner!!.z <= location.z) {
return BlockDirection.EAST
}

if (location.blockZ >= upperCorner.blockZ && this.upperCorner.x >= location.x && this.lowerCorner.x <= location.x) {
if (location.blockZ >= upperCorner!!.blockZ && this.upperCorner!!.x >= location.x && this.lowerCorner!!.x <= location.x) {
return BlockDirection.NORTH
}

if (location.blockZ <= lowerCorner.blockZ && this.upperCorner.x >= location.x && this.lowerCorner.x <= location.x) {
if (location.blockZ <= lowerCorner!!.blockZ && this.upperCorner!!.x >= location.x && this.lowerCorner!!.x <= location.x) {
return BlockDirection.SOUTH
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.github.shynixn.blockball.enumeration

enum class SelectionType {
FIELD,
BALL,
RED_GOAL,
BLUE_GOAL
}
Loading

0 comments on commit 730fbf5

Please sign in to comment.