diff --git a/build.gradle.kts b/build.gradle.kts index a3757bf85..7b091aa8a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,12 +4,12 @@ import java.util.* import java.io.* plugins { - id("org.jetbrains.kotlin.jvm") version ("1.6.10") + id("org.jetbrains.kotlin.jvm") version ("1.9.25") id("com.github.johnrengelman.shadow") version ("7.0.0") } group = "com.github.shynixn" -version = "9.14.1" +version = "9.15.0" repositories { mavenCentral() @@ -31,10 +31,10 @@ dependencies { compileOnly("com.arcaniax:HeadDatabase-API:1.3.1") // Library dependencies with legacy compatibility, we can use more up-to-date version in the plugin.yml - implementation("com.github.shynixn.mccoroutine:mccoroutine-bukkit-api:2.18.0") - implementation("com.github.shynixn.mccoroutine:mccoroutine-bukkit-core:2.18.0") - runtimeOnly("com.github.shynixn.mccoroutine:mccoroutine-folia-api:2.18.0") - runtimeOnly("com.github.shynixn.mccoroutine:mccoroutine-folia-core:2.18.0") + implementation("com.github.shynixn.mccoroutine:mccoroutine-bukkit-api:2.20.0") + implementation("com.github.shynixn.mccoroutine:mccoroutine-bukkit-core:2.20.0") + runtimeOnly("com.github.shynixn.mccoroutine:mccoroutine-folia-api:2.20.0") + runtimeOnly("com.github.shynixn.mccoroutine:mccoroutine-folia-core:2.20.0") implementation("com.google.inject:guice:5.0.1") implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.3.0") implementation("com.fasterxml.jackson.core:jackson-databind:2.2.3") @@ -46,9 +46,9 @@ dependencies { // Custom dependencies implementation("com.github.shynixn.shygui:shygui:1.0.1") - implementation("com.github.shynixn.mcutils:common:2024.23") - implementation("com.github.shynixn.mcutils:packet:2024.38") - implementation("com.github.shynixn.mcutils:database:2024.3") + implementation("com.github.shynixn.mcutils:common:2024.25") + implementation("com.github.shynixn.mcutils:packet:2024.43") + implementation("com.github.shynixn.mcutils:database:2024.8") implementation("com.github.shynixn.mcutils:pathfinder:2024.3") implementation("com.github.shynixn.mcutils:guice:2024.2") @@ -112,6 +112,7 @@ tasks.register("relocatePluginJar", com.github.jengelman.gradle.plugins.shadow.t from(zipTree(File("./build/libs/" + (tasks.getByName("shadowJar") as Jar).archiveFileName.get()))) archiveFileName.set("${archiveBaseName.get()}-${archiveVersion.get()}-relocate.${archiveExtension.get()}") relocate("com.github.shynixn.mcutils", "com.github.shynixn.petblocks.lib.com.github.shynixn.mcutils") + relocate("com.fasterxml", "com.github.shynixn.petblocks.lib.com.fasterxml") relocate("com.github.shynixn.shygui", "com.github.shynixn.petblocks.lib.com.github.shynixn.shygui") } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 48c0a02ca..84d1f85fd 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/com/github/shynixn/petblocks/PetBlocksDependencyInjectionModule.kt b/src/main/java/com/github/shynixn/petblocks/PetBlocksDependencyInjectionModule.kt index 9fc152be1..f48a53d7a 100644 --- a/src/main/java/com/github/shynixn/petblocks/PetBlocksDependencyInjectionModule.kt +++ b/src/main/java/com/github/shynixn/petblocks/PetBlocksDependencyInjectionModule.kt @@ -2,6 +2,7 @@ package com.github.shynixn.petblocks import com.fasterxml.jackson.core.type.TypeReference import com.github.shynixn.mccoroutine.bukkit.minecraftDispatcher +import com.github.shynixn.mccoroutine.bukkit.scope import com.github.shynixn.mcutils.common.ConfigurationService import com.github.shynixn.mcutils.common.ConfigurationServiceImpl import com.github.shynixn.mcutils.common.chat.ChatMessageService @@ -11,7 +12,6 @@ import com.github.shynixn.mcutils.common.physic.PhysicObjectDispatcherImpl import com.github.shynixn.mcutils.common.physic.PhysicObjectService import com.github.shynixn.mcutils.common.physic.PhysicObjectServiceImpl import com.github.shynixn.mcutils.common.placeholder.PlaceHolderService -import com.github.shynixn.mcutils.common.placeholder.PlaceHolderServiceImpl import com.github.shynixn.mcutils.common.repository.CacheRepository import com.github.shynixn.mcutils.common.repository.CachedRepositoryImpl import com.github.shynixn.mcutils.common.repository.Repository @@ -73,7 +73,7 @@ class PetBlocksDependencyInjectionModule( object : TypeReference() {}, plugin.minecraftDispatcher ) val playerDataRepository = AutoSavePlayerDataRepositoryImpl( - 1000 * 60L * autoSaveMinutes, CachePlayerDataRepositoryImpl(configSelectedRepository, plugin), plugin + 1000 * 60L * autoSaveMinutes, CachePlayerDataRepositoryImpl(configSelectedRepository, plugin.minecraftDispatcher), plugin.scope, plugin.minecraftDispatcher ) addService>(playerDataRepository) addService>(playerDataRepository) diff --git a/src/main/java/com/github/shynixn/petblocks/PetBlocksPlugin.kt b/src/main/java/com/github/shynixn/petblocks/PetBlocksPlugin.kt index 028e14de1..9bf1f6b1c 100644 --- a/src/main/java/com/github/shynixn/petblocks/PetBlocksPlugin.kt +++ b/src/main/java/com/github/shynixn/petblocks/PetBlocksPlugin.kt @@ -78,9 +78,10 @@ class PetBlocksPlugin : JavaPlugin() { Version.VERSION_1_20_R3, Version.VERSION_1_20_R4, Version.VERSION_1_21_R1, + Version.VERSION_1_21_R2, ) } else { - listOf(Version.VERSION_1_21_R1) + listOf(Version.VERSION_1_21_R2) } if (!Version.serverVersion.isCompatible(*versions.toTypedArray())) { diff --git a/src/main/java/com/github/shynixn/petblocks/impl/listener/PetListener.kt b/src/main/java/com/github/shynixn/petblocks/impl/listener/PetListener.kt index fcf0fca34..94c6a6d79 100644 --- a/src/main/java/com/github/shynixn/petblocks/impl/listener/PetListener.kt +++ b/src/main/java/com/github/shynixn/petblocks/impl/listener/PetListener.kt @@ -9,6 +9,7 @@ import com.github.shynixn.mcutils.common.Version import com.github.shynixn.mcutils.common.physic.PhysicObjectService 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.meta.enumeration.PacketVersion import com.github.shynixn.mcutils.packet.api.packet.PacketInInteractEntity import com.github.shynixn.mcutils.packet.api.packet.PacketInSteerVehicle import com.github.shynixn.petblocks.contract.PetActionExecutionService @@ -18,6 +19,7 @@ import com.github.shynixn.petblocks.impl.service.PetActionExecutionServiceImpl import com.google.inject.Inject import kotlinx.coroutines.delay import org.bukkit.Bukkit +import org.bukkit.entity.Player import org.bukkit.event.EventHandler import org.bukkit.event.Listener import org.bukkit.event.player.PlayerJoinEvent @@ -34,6 +36,7 @@ class PetListener @Inject constructor( private val configurationService: ConfigurationService ) : Listener { private val petsToReceiveOnJoinKey = "pet.receivePetsOnJoin" + private val steerVehicleCache = HashMap() /** * Gets called when a player joins the server. @@ -75,6 +78,7 @@ class PetListener @Inject constructor( plugin.launch { petService.clearCache(event.player) } + steerVehicleCache.remove(event.player) } @EventHandler @@ -100,10 +104,61 @@ class PetListener @Inject constructor( val packet = event.packet if (packet is PacketInSteerVehicle) { - plugin.launch { - val physicObject = physicObjectService.findPhysicObjectById(packet.entityId) as PetEntityImpl? - physicObject?.ride(event.player, packet.forward, packet.isJumping, packet.isShift) + val player = event.player + + if (packet.version == PacketVersion.V1) { + plugin.launch { + val physicObject = physicObjectService.findPhysicObjectById(packet.entityId) as PetEntityImpl? + physicObject?.ride(player, packet.forward, packet.isJumping, packet.isShift) + } + return } + + if (packet.version == PacketVersion.V2) { + plugin.launch { + val physicObject = + physicObjectService.findPhysicObjectById(packet.entityId) as PetEntityImpl? ?: return@launch + + if (steerVehicleCache.containsKey(player)) { + val vehicleDirection = steerVehicleCache[player] + + if (vehicleDirection == 1 && packet.isForwardMove) { + // Skip + } else if (vehicleDirection == 2 && packet.isForwardMove) { + // Skip + } else { + steerVehicleCache.remove(player) + } + } else { + if (packet.isForwardMove) { + steerVehicleCache[player] = 1 + plugin.launch { + while (player.isOnline && steerVehicleCache.contains(player) && physicObject.pet.isRiding()) { + physicObject.ride(player, 0.5, false, false) + delay(5.ticks) + } + } + } else if (packet.isBackWardMove) { + steerVehicleCache[player] = 2 + plugin.launch { + while (player.isOnline && steerVehicleCache.contains(player) && physicObject.pet.isRiding()) { + physicObject.ride(player, -0.5, false, false) + delay(5.ticks) + } + } + } + } + + if (packet.isShift) { + physicObject.ride(player, 0.0, false, true) + } + + if (packet.isJumping) { + physicObject.ride(player, 0.0, true, false) + } + } + } + return } diff --git a/src/main/resources/plugin-legacy.yml b/src/main/resources/plugin-legacy.yml index 5bbaac1b1..84336dc25 100644 --- a/src/main/resources/plugin-legacy.yml +++ b/src/main/resources/plugin-legacy.yml @@ -1,5 +1,5 @@ name: PetBlocks -version: 9.14.1 +version: 9.15.0 author: Shynixn main: com.github.shynixn.petblocks.PetBlocksPlugin softdepend: [ PlaceholderAPI, HeadDatabase] diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index e81bf1a82..ad2177a36 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,16 +1,14 @@ name: PetBlocks -version: 9.14.1 +version: 9.15.0 author: Shynixn main: com.github.shynixn.petblocks.PetBlocksPlugin softdepend: [ PlaceholderAPI, HeadDatabase] api-version: 1.13 libraries: - - com.github.shynixn.mccoroutine:mccoroutine-bukkit-api:2.16.0 - - com.github.shynixn.mccoroutine:mccoroutine-bukkit-core:2.16.0 - - com.github.shynixn.mccoroutine:mccoroutine-folia-api:2.16.0 - - com.github.shynixn.mccoroutine:mccoroutine-folia-core:2.16.0 - - com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.3.0 - - com.fasterxml.jackson.core:jackson-databind:2.3.0 + - com.github.shynixn.mccoroutine:mccoroutine-bukkit-api:2.20.0 + - com.github.shynixn.mccoroutine:mccoroutine-bukkit-core:2.20.0 + - com.github.shynixn.mccoroutine:mccoroutine-folia-api:2.20.0 + - com.github.shynixn.mccoroutine:mccoroutine-folia-core:2.20.0 - com.google.inject:guice:7.0.0 - com.google.code.gson:gson:2.10.1 - com.zaxxer:HikariCP:5.1.0