Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

Commit

Permalink
Update to generate wrappers from paper-userdev
Browse files Browse the repository at this point in the history
  • Loading branch information
0ffz committed Apr 23, 2022
1 parent 672b27e commit 70ad4df
Show file tree
Hide file tree
Showing 18 changed files with 148 additions and 259 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/gradle-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ jobs:
with:
submodules: 'true'

- name: Set up JDK 16
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
distribution: adopt
java-version: 16
java-version: 17
cache: gradle

- name: Grant execute permission for gradlew
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/publish-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ jobs:
with:
submodules: 'true'

- name: Set up JDK 16
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
distribution: adopt
java-version: 16
java-version: 17
cache: gradle

- name: Grant execute permission for gradlew
Expand All @@ -43,5 +43,6 @@ jobs:
prerelease: false
automatic_release_tag: v${{ steps.extract_version.outputs.version }}
files: |
protocolburrito-plugin/build/libs/ProtocolBurrito-*.jar
protocolburrito-plugin/build/libs/protocolburrito-plugin*.jar
!*-dev*
26 changes: 8 additions & 18 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
plugins {
kotlin("jvm")
id("com.github.johnrengelman.shadow") version "7.0.0"
id("com.mineinabyss.conventions.publication")
id("de.undercouch.download") version "4.1.2"
id("com.mineinabyss.conventions.kotlin")
id("com.mineinabyss.conventions.nms")
id("com.google.devtools.ksp") version "1.6.10-1.0.2"
id("com.mineinabyss.conventions.publication")
id("com.github.johnrengelman.shadow") version "7.0.0"
}

repositories {
Expand Down Expand Up @@ -32,32 +31,23 @@ allprojects {

dependencies {
compileOnly("org.spigotmc:spigot-api:1.18.2-R0.1-SNAPSHOT")
implementation(project(":protocolburrito-api"))
api(project(":protocolburrito-api"))
compileOnly(project(":protocolburrito-generator"))
ksp(project(":protocolburrito-generator"))
}


sourceSets["main"].java.srcDir(file("$rootDir/protocolburrito-generator/build/generated/burrito/main"))

tasks {
// val downloadMappings by register<de.undercouch.gradle.tasks.download.Download>("Download mappings") {
// src("https://launcher.mojang.com/v1/objects/f6cae1c5c1255f68ba4834b16a0da6a09621fe13/server.txt")
// dest(file("mappings/server.txt"))
// }
assemble {
dependsOn(reobfJar)
dependsOn(project(":protocolburrito-plugin").tasks.build)
}
shadowJar {
archiveClassifier.set("")
}

sourcesJar {
from(sourceSets.main.get().allSource)
}

// publish {
// dependsOn(downloadMappings)
// }

build {
dependsOn(/*downloadMappings,*/ project(":protocolburrito-plugin").tasks.build)
}
}
9 changes: 3 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
version=0.2
version=0.3
group=com.mineinabyss
kotlinVersion=1.6.10
serverVersion=1.18.2-R0.1-SNAPSHOT
idofrontVersion=0.9.82

# Workaround for Kapt not working on jdk 16
org.gradle.jvmargs=--illegal-access=permit
kapt.use.worker.api=false
idofrontVersion=0.9.83
publishComponentName=java
10 changes: 4 additions & 6 deletions protocolburrito-api/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
plugins {
kotlin("jvm")
}

repositories {
mavenCentral()
id("com.mineinabyss.conventions.kotlin")
id("com.mineinabyss.conventions.papermc")
id("com.mineinabyss.conventions.publication")
}

dependencies {
compileOnly("org.spigotmc:spigot-api:1.17-R0.1-SNAPSHOT")
compileOnly(libs.kotlin.reflect)
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
package com.mineinabyss.protocolburrito

object FieldHelpers {
fun <T : Any> getField(forObject: Any, type: Class<T>, index: Int): T {
inline fun <reified T : Any> getField(forObject: Any, index: Int): T =
getField(T::class.java, forObject, index)

fun <T : Any> getField(type: Class<T>, forObject: Any, index: Int): T {
var id = 0
return forObject::class.java.fields.first { it.type.kotlin == type && index == id++ }.get(forObject) as T
return forObject::class.java.declaredFields.first { it.type.kotlin.javaObjectType == type && index == id++ }
.also {
it.isAccessible = true
}.get(forObject) as T
}

fun <T : Any> setField(forObject: Any, type: Class<T>, index: Int, value: T) {
inline fun <reified T : Any> setField(forObject: Any, index: Int, value: T?) =
setField(T::class.java, forObject, index, value)

fun <T : Any> setField(type: Class<T>, forObject: Any, index: Int, value: T?) {
var id = 0
forObject::class.java.fields.first { it.type == type && index == id++ }.set(forObject, value)
forObject::class.java.declaredFields.first { it.type.kotlin.javaObjectType == type && index == id++ }.also {
it.isAccessible = true
}.set(forObject, value)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.mineinabyss.protocolburrito

import com.comphenix.protocol.PacketType
import com.comphenix.protocol.injector.packet.PacketRegistry

interface WrappedCompanion {
val type: PacketType

fun wrap(any: Any): Any
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
package com.mineinabyss.protocolburrito

import com.comphenix.protocol.PacketType
import com.comphenix.protocol.events.PacketContainer

abstract class WrappedPacket(
val handle: PacketContainer,
val packetType: PacketType? = null,
) {
init {
require(packetType == null || handle.type == packetType) { "${handle.handle} is not a packet of type $packetType" }
}
}
interface WrappedPacket
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,31 @@ import com.comphenix.protocol.events.ListenerPriority
import com.comphenix.protocol.events.PacketAdapter
import com.comphenix.protocol.events.PacketContainer
import com.comphenix.protocol.events.PacketEvent
import com.comphenix.protocol.injector.packet.PacketRegistry
import com.mineinabyss.protocolburrito.WrappedCompanion
import com.mineinabyss.protocolburrito.WrappedPacket
import org.bukkit.Bukkit
import org.bukkit.entity.Entity
import org.bukkit.entity.Player
import org.bukkit.plugin.Plugin
import java.util.*
import kotlin.reflect.KFunction1
import kotlin.reflect.full.companionObject
import kotlin.reflect.full.companionObjectInstance

class ProtocolManagerBurrito(
val protocolManager: ProtocolManager,
val plugin: Plugin
) : ProtocolManager by protocolManager {
inline fun <T> onSend(
crossinline instantiate: (PacketContainer) -> T,
vararg packets: PacketType,
inline fun <reified T: WrappedPacket> onSend(
priority: ListenerPriority = ListenerPriority.NORMAL,
crossinline onSend: T.(event: PacketEvent) -> Unit
crossinline onSend: PacketEvent.(wrapped: T) -> Unit
) {
onSend(*packets, priority = priority) { instantiate(packet).onSend(this) }
val companion = T::class.companionObjectInstance as WrappedCompanion
onSend(companion.type, priority = priority) { onSend(companion.wrap(packet.handle) as T) }
}

inline fun ProtocolManager.onSend(
inline fun onSend(
vararg packets: PacketType,
priority: ListenerPriority = ListenerPriority.NORMAL,
crossinline onSend: PacketEvent.() -> Unit
Expand All @@ -38,16 +43,15 @@ class ProtocolManagerBurrito(
})
}

inline fun <T> onReceive(
crossinline instantiate: (PacketContainer) -> T,
vararg packets: PacketType,
inline fun <reified T> onReceive(
priority: ListenerPriority = ListenerPriority.NORMAL,
crossinline onReceive: T.(event: PacketEvent) -> Unit
crossinline onReceive: PacketEvent.(wrapped: T) -> Unit
) {
onReceive(*packets, priority = priority) { instantiate(packet).onReceive(this) }
val companion = T::class.companionObjectInstance as WrappedCompanion
onReceive(companion.type, priority = priority) { onReceive(companion.wrap(packet.handle) as T) }
}

inline fun ProtocolManager.onReceive(
inline fun onReceive(
vararg packets: PacketType,
priority: ListenerPriority = ListenerPriority.NORMAL,
crossinline onSend: PacketEvent.() -> Unit
Expand Down
9 changes: 3 additions & 6 deletions protocolburrito-generator/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ val serverVersion: String by project

plugins {
kotlin("jvm")
// kotlin("kapt")
// id("com.mineinabyss.conventions.nms")
id("io.papermc.paperweight.userdev")
}

Expand All @@ -19,14 +17,13 @@ dependencies {
paperDevBundle(serverVersion)
implementation(kotlin("reflect"))
implementation("io.papermc.paper:paper-server:userdev-1.18.2-R0.1-SNAPSHOT")
// implementation("com.comphenix.protocol:ProtocolLib:4.7.0")
implementation("com.comphenix.protocol:ProtocolLib:4.7.0")
implementation("com.nfeld.jsonpathkt:jsonpathkt:2.0.0")
implementation("com.squareup:kotlinpoet:1.10.1")
implementation(project(":protocolburrito-api"))

implementation("com.google.devtools.ksp:symbol-processing-api:1.6.10-1.0.2")
compileOnly("com.google.auto.service:auto-service:1.0")
// kapt("com.google.auto.service:auto-service:1.0")
// implementation("com.google.devtools.ksp:symbol-processing-api:1.6.10-1.0.2")
// compileOnly("com.google.auto.service:auto-service:1.0")
implementation("org.reflections:reflections:0.9.12")
implementation(kotlin("reflect"))
}
Expand Down
3 changes: 0 additions & 3 deletions protocolburrito-generator/gradle.properties

This file was deleted.

This file was deleted.

Loading

0 comments on commit 70ad4df

Please sign in to comment.