Skip to content

Commit

Permalink
#513 Implemented support for 1.21.
Browse files Browse the repository at this point in the history
  • Loading branch information
Shynixn committed Jun 18, 2024
1 parent 29145a2 commit 07c24b5
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 42 deletions.
5 changes: 3 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.9")
implementation("com.github.shynixn.mcutils:packet:2024.11")
implementation("com.github.shynixn.mcutils:common:2024.17")
implementation("com.github.shynixn.mcutils:packet:2024.27")
implementation("com.github.shynixn.mcutils:database:2024.2")
implementation("com.github.shynixn.mcutils:sign:2024.2")
implementation("com.github.shynixn.mcutils:guice:2024.2")
Expand Down Expand Up @@ -122,6 +122,7 @@ tasks.register("pluginJarLatest", ShadowJar::class.java) {
exclude("com/github/shynixn/blockball/lib/com/github/shynixn/mcutils/packet/nms/v1_20_R1/**")
exclude("com/github/shynixn/blockball/lib/com/github/shynixn/mcutils/packet/nms/v1_20_R2/**")
exclude("com/github/shynixn/blockball/lib/com/github/shynixn/mcutils/packet/nms/v1_20_R3/**")
exclude("com/github/shynixn/blockball/lib/com/github/shynixn/mcutils/packet/nms/v1_20_R4/**")
exclude("com/github/shynixn/mcutils/**")
exclude("com/github/shynixn/mccoroutine/**")
exclude("org/**")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ 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.EntityService
import com.github.shynixn.mcutils.packet.api.PacketService
import com.github.shynixn.mcutils.packet.api.RayTracingService
import com.github.shynixn.mcutils.packet.impl.service.*
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 org.bukkit.Bukkit
import org.bukkit.plugin.Plugin
import java.util.concurrent.Executor
import java.util.logging.Level

class BlockBallDependencyInjectionModule(
Expand Down Expand Up @@ -79,10 +80,7 @@ class BlockBallDependencyInjectionModule(

// Services
addService<CommandService, CommandServiceImpl>()
addService<PacketService>(PacketServiceImpl(
plugin
) { command -> plugin.server.scheduler.runTask(plugin, command) })
addService<EntityService>(EntityServiceImpl())
addService<PacketService>(PacketServiceImpl(plugin))
addService<ScoreboardService, ScoreboardServiceImpl>()
addService<ConfigurationService>(ConfigurationServiceImpl(plugin))
addService<SoundService>(SoundServiceImpl(plugin))
Expand All @@ -93,7 +91,7 @@ class BlockBallDependencyInjectionModule(
addService<GameMiniGameActionService, GameMiniGameActionServiceImpl>()
addService<GameBungeeCordGameActionService, GameBungeeCordGameActionServiceImpl>()
addService<ItemService>(ItemServiceImpl())
addService<ChatMessageService, ChatMessageServiceImpl>()
addService<ChatMessageService>(ChatMessageServiceImpl(plugin))
addService<GameSoccerService, GameSoccerServiceImpl>()
addService<RightclickManageService, RightclickManageServiceImpl>()
addService<HubGameForcefieldService, HubGameForcefieldServiceImpl>()
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/com/github/shynixn/blockball/BlockBallPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ class BlockBallPlugin : JavaPlugin() {
/** Final Prefix of BlockBall in the console */
val PREFIX_CONSOLE: String = ChatColor.BLUE.toString() + "[BlockBall] "
}

private val bstatsPluginId = 1317
private lateinit var module : DependencyInjectionModule
private lateinit var module: DependencyInjectionModule
private var immidiateDisable = false

/**
Expand Down Expand Up @@ -65,10 +66,11 @@ class BlockBallPlugin : JavaPlugin() {
Version.VERSION_1_20_R2,
Version.VERSION_1_20_R3,
Version.VERSION_1_20_R4,
Version.VERSION_1_21_R1,
)
} else {
arrayOf(
Version.VERSION_1_20_R4,
Version.VERSION_1_21_R1,
)
}

Expand Down Expand Up @@ -106,7 +108,7 @@ class BlockBallPlugin : JavaPlugin() {
// Register CommandExecutor
val commandService = module.getService<CommandService>()
commandService.registerCommandExecutor("blockballstop", module.getService<StopCommandExecutor>())
commandService.registerCommandExecutor("blockballreload", module.getService<ReloadCommandExecutor>())
commandService.registerCommandExecutor("blockballreload", module.getService<ReloadCommandExecutor>())
commandService.registerCommandExecutor("blockball", module.getService<ArenaCommandExecutor>())
commandService.registerCommandExecutor(
(config.get("global-spectate") as MemorySection).getValues(false) as Map<String, String>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class BallMeta {
*/
var item: Item = Item().also {
it.typeName = "PLAYER_HEAD,397"
it.durability = 3
it.durability = "3"
it.skinBase64 = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHBzOi8vdGV4dHVyZXMubWluZWNyYWZ0Lm5ldC90ZXh0dXJlLzhlNGE3MGI3YmJjZDdhOGMzMjJkNTIyNTIwNDkxYTI3ZWE2YjgzZDYwZWNmOTYxZDJiNGVmYmJmOWY2MDVkIn19fQ=="
}
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import com.github.shynixn.blockball.contract.HologramProxy
import com.github.shynixn.mcutils.common.Vector3d
import com.github.shynixn.mcutils.common.toLocation
import com.github.shynixn.mcutils.common.toVector3d
import com.github.shynixn.mcutils.packet.api.EntityService
import com.github.shynixn.mcutils.packet.api.PacketService
import com.github.shynixn.mcutils.packet.api.meta.enumeration.EntityType
import com.github.shynixn.mcutils.packet.api.packet.PacketOutEntityDestroy
Expand All @@ -13,7 +12,7 @@ import com.github.shynixn.mcutils.packet.api.packet.PacketOutEntitySpawn
import org.bukkit.Location
import org.bukkit.entity.Player

class PacketHologram(private val entityService: EntityService) : HologramProxy {
class PacketHologram : HologramProxy {
private var position: Vector3d? = null
private var entityIds = ArrayList<Int>()
private var backedLines: List<String> = emptyList()
Expand Down Expand Up @@ -56,7 +55,7 @@ class PacketHologram(private val entityService: EntityService) : HologramProxy {
if (this.backedLines.size != value.size) {
entityIds.clear()
for (i in value.indices) {
entityIds.add(entityService.createNewEntityId())
entityIds.add(packetService.getNextEntityId())
}

this.playerTracker.dispose()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import com.github.shynixn.mcutils.common.toLocation
import com.github.shynixn.mcutils.common.toVector3d
import com.github.shynixn.mcutils.database.api.CachePlayerRepository
import com.github.shynixn.mcutils.packet.api.PacketInType
import com.github.shynixn.mcutils.packet.api.event.PacketEvent
import com.github.shynixn.mcutils.packet.api.event.PacketAsyncEvent
import com.github.shynixn.mcutils.packet.api.meta.enumeration.InteractionType
import com.github.shynixn.mcutils.packet.api.packet.PacketInInteractEntity
import com.google.inject.Inject
Expand Down Expand Up @@ -51,28 +51,30 @@ class GameListener @Inject constructor(
* Gets called when a packet arrives.
*/
@EventHandler
fun onPacketEvent(event: PacketEvent) {
fun onPacketEvent(event: PacketAsyncEvent) {
if (event.packetType != PacketInType.USEENTITY) {
return
}

val game = gameService.getGameFromPlayer(event.player)
plugin.launch {
val game = gameService.getGameFromPlayer(event.player)

if (!game.isPresent) {
return
}
if (!game.isPresent) {
return@launch
}

val packet = event.packet as PacketInInteractEntity
val ball = ballEntityService.findBallByEntityId(packet.entityId) ?: return
val packet = event.packet as PacketInInteractEntity
val ball = ballEntityService.findBallByEntityId(packet.entityId) ?: return@launch

if (game.get().ball != ball) {
return
}
if (game.get().ball != ball) {
return@launch
}

if (packet.actionType == InteractionType.RIGHT_CLICK || packet.actionType == InteractionType.OTHER) {
ball.passByPlayer(event.player)
} else {
ball.kickByPlayer(event.player)
if (packet.actionType == InteractionType.RIGHT_CLICK || packet.actionType == InteractionType.OTHER) {
ball.passByPlayer(event.player)
} else {
ball.kickByPlayer(event.player)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import com.github.shynixn.mccoroutine.bukkit.launch
import com.github.shynixn.mccoroutine.bukkit.ticks
import com.github.shynixn.mcutils.common.item.ItemService
import com.github.shynixn.mcutils.common.toVector3d
import com.github.shynixn.mcutils.packet.api.EntityService
import com.github.shynixn.mcutils.packet.api.PacketService
import com.github.shynixn.mcutils.packet.api.RayTracingService
import com.google.inject.Inject
Expand All @@ -24,8 +23,7 @@ class BallEntityServiceImpl @Inject constructor(
private val packetService: PacketService,
private val itemService: ItemService,
private val rayTracingService: RayTracingService,
private val plugin: Plugin,
private val entityService: EntityService
private val plugin: Plugin
) : BallEntityService {

private val ballHitBoxTracked = HashMap<Int, Ball>()
Expand All @@ -52,12 +50,12 @@ class BallEntityServiceImpl @Inject constructor(
position.yaw = 0.0
position.pitch = 0.0

val ballHitBoxEntity = BallHitboxEntity(entityService.createNewEntityId(), meta.spawnpoint!!)
val ballHitBoxEntity = BallHitboxEntity(packetService.getNextEntityId(), meta.spawnpoint!!)
ballHitBoxEntity.position = position
ballHitBoxEntity.rayTracingService = rayTracingService
ballHitBoxEntity.packetService = packetService

val ballDesignEntity = BallDesignEntity(entityService.createNewEntityId())
val ballDesignEntity = BallDesignEntity(packetService.getNextEntityId())
ballDesignEntity.packetService = packetService
ballDesignEntity.itemService = itemService

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,39 @@ import com.github.shynixn.mcutils.common.ChatColor
import com.github.shynixn.mcutils.common.item.Item
import com.github.shynixn.mcutils.common.item.ItemService
import com.github.shynixn.mcutils.common.translateChatColors
import com.github.shynixn.mcutils.packet.api.PacketService
import com.github.shynixn.mcutils.packet.api.packet.PacketOutDebugMarker
import com.google.inject.Inject
import kotlinx.coroutines.delay
import org.bukkit.Location
import org.bukkit.entity.Player
import org.bukkit.plugin.Plugin
import java.awt.Color
import java.util.*

@Suppress("DEPRECATION", "SENSELESS_COMPARISON")
class BlockSelectionServiceImpl @Inject constructor(
private val plugin: Plugin,
private val itemService: ItemService
private val itemService: ItemService,
private val packetService: PacketService
) : BlockSelectionService {
private val axeName =
ChatColor.WHITE.toString() + ChatColor.BOLD + ">>" + ChatColor.YELLOW + "BlockBall" + ChatColor.WHITE + ChatColor.BOLD + "<<"
private val playerSelection = HashMap<Player, Array<Location?>>()
private val rightClickSelectionCahe = HashSet<Player>()

init {
plugin.launch {
while (true) {
for (player in playerSelection.keys.toTypedArray()) {
updateSelection(player, playerSelection[player]!!)
}
delay(2000)
}
}
}


/**
* Selects the left location internally.
*/
Expand Down Expand Up @@ -116,6 +132,7 @@ class BlockSelectionServiceImpl @Inject constructor(
}

playerSelection[player]!![index] = location
updateSelection(player, playerSelection[player]!!)

return true
}
Expand Down Expand Up @@ -148,6 +165,24 @@ class BlockSelectionServiceImpl @Inject constructor(
player.sendMessage("Take a look into your inventory. Use this golden axe for selection.")
}

private fun updateSelection(player: Player, locations: Array<Location?>) {
for (i in 0 until locations.size) {
if (i == 0 && locations[i] != null) {
packetService.sendPacketOutDebugMarker(
player,
PacketOutDebugMarker(locations[i]!!, 2200, Color.YELLOW.rgb, "BlockBall [LEFT]")
)
}

if (i == 1 && locations[i] != null) {
packetService.sendPacketOutDebugMarker(
player,
PacketOutDebugMarker(locations[i]!!, 2200, Color.YELLOW.rgb, "BlockBall [RIGHT]")
)
}
}
}

/**
* Returns the compaitiblity selection.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import com.github.shynixn.blockball.impl.extension.setSignLines
import com.github.shynixn.mccoroutine.bukkit.launch
import com.github.shynixn.mcutils.common.*
import com.github.shynixn.mcutils.database.api.PlayerDataRepository
import com.github.shynixn.mcutils.packet.api.EntityService
import com.github.shynixn.mcutils.packet.api.PacketService
import com.google.inject.Inject
import org.bukkit.Bukkit
Expand All @@ -35,8 +34,7 @@ class GameActionServiceImpl @Inject constructor(
private val placeholderService: PlaceHolderService,
private val packetService: PacketService,
private val plugin: Plugin,
private val playerDataRepository: PlayerDataRepository<PlayerInformation>,
private val entityService: EntityService
private val playerDataRepository: PlayerDataRepository<PlayerInformation>
) : GameActionService {
/**
* Compatibility reference.
Expand Down Expand Up @@ -347,7 +345,7 @@ class GameActionServiceImpl @Inject constructor(
game.holograms.clear()

game.arena.meta.hologramMetas.forEach { meta ->
val hologram = PacketHologram(entityService)
val hologram = PacketHologram()
hologram.packetService = packetService

hologram.lines = meta.lines
Expand Down

0 comments on commit 07c24b5

Please sign in to comment.