Skip to content

Commit

Permalink
#125, #126 Fixed velocity event binding and added folia-test.
Browse files Browse the repository at this point in the history
  • Loading branch information
shynixn committed Oct 3, 2024
1 parent 01b85bd commit 968ca36
Show file tree
Hide file tree
Showing 25 changed files with 465 additions and 51 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ tasks.register("printVersion") {

subprojects {
group 'com.github.shynixn.mccoroutine'
version '2.19.0'
version '2.20.0'

sourceCompatibility = 1.8

Expand Down
36 changes: 18 additions & 18 deletions docs/wiki/docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,62 +8,62 @@ In order to use the MCCoroutine Kotlin API, you need to include the following li

```groovy
dependencies {
implementation("com.github.shynixn.mccoroutine:mccoroutine-bukkit-api:2.19.0")
implementation("com.github.shynixn.mccoroutine:mccoroutine-bukkit-core:2.19.0")
implementation("com.github.shynixn.mccoroutine:mccoroutine-bukkit-api:2.20.0")
implementation("com.github.shynixn.mccoroutine:mccoroutine-bukkit-core:2.20.0")
}
```

=== "BungeeCord"

```groovy
dependencies {
implementation("com.github.shynixn.mccoroutine:mccoroutine-bungeecord-api:2.19.0")
implementation("com.github.shynixn.mccoroutine:mccoroutine-bungeecord-core:2.19.0")
implementation("com.github.shynixn.mccoroutine:mccoroutine-bungeecord-api:2.20.0")
implementation("com.github.shynixn.mccoroutine:mccoroutine-bungeecord-core:2.20.0")
}
```

=== "Fabric"

```groovy
dependencies {
implementation("com.github.shynixn.mccoroutine:mccoroutine-fabric-api:2.19.0")
implementation("com.github.shynixn.mccoroutine:mccoroutine-fabric-core:2.19.0")
implementation("com.github.shynixn.mccoroutine:mccoroutine-fabric-api:2.20.0")
implementation("com.github.shynixn.mccoroutine:mccoroutine-fabric-core:2.20.0")
}
```

=== "Folia"

```groovy
dependencies {
implementation("com.github.shynixn.mccoroutine:mccoroutine-folia-api:2.19.0")
implementation("com.github.shynixn.mccoroutine:mccoroutine-folia-core:2.19.0")
implementation("com.github.shynixn.mccoroutine:mccoroutine-folia-api:2.20.0")
implementation("com.github.shynixn.mccoroutine:mccoroutine-folia-core:2.20.0")
}
```

=== "Minestom"

```groovy
dependencies {
implementation("com.github.shynixn.mccoroutine:mccoroutine-minestom-api:2.19.0")
implementation("com.github.shynixn.mccoroutine:mccoroutine-minestom-core:2.19.0")
implementation("com.github.shynixn.mccoroutine:mccoroutine-minestom-api:2.20.0")
implementation("com.github.shynixn.mccoroutine:mccoroutine-minestom-core:2.20.0")
}
```

=== "Sponge"

```groovy
dependencies {
implementation("com.github.shynixn.mccoroutine:mccoroutine-sponge-api:2.19.0")
implementation("com.github.shynixn.mccoroutine:mccoroutine-sponge-core:2.19.0")
implementation("com.github.shynixn.mccoroutine:mccoroutine-sponge-api:2.20.0")
implementation("com.github.shynixn.mccoroutine:mccoroutine-sponge-core:2.20.0")
}
```

=== "Velocity"

```groovy
dependencies {
implementation("com.github.shynixn.mccoroutine:mccoroutine-velocity-api:2.19.0")
implementation("com.github.shynixn.mccoroutine:mccoroutine-velocity-core:2.19.0")
implementation("com.github.shynixn.mccoroutine:mccoroutine-velocity-api:2.20.0")
implementation("com.github.shynixn.mccoroutine:mccoroutine-velocity-core:2.20.0")
}
```

Expand All @@ -87,17 +87,17 @@ dependencies {
**plugin.yml**
```yaml
libraries:
- com.github.shynixn.mccoroutine:mccoroutine-bukkit-api:2.19.0
- com.github.shynixn.mccoroutine:mccoroutine-bukkit-core:2.19.0
- com.github.shynixn.mccoroutine:mccoroutine-bukkit-api:2.20.0
- com.github.shynixn.mccoroutine:mccoroutine-bukkit-core:2.20.0
```

=== "Folia"

**plugin.yml**
```yaml
libraries:
- com.github.shynixn.mccoroutine:mccoroutine-folia-api:2.19.0
- com.github.shynixn.mccoroutine:mccoroutine-folia-core:2.19.0
- com.github.shynixn.mccoroutine:mccoroutine-folia-api:2.20.0
- com.github.shynixn.mccoroutine:mccoroutine-folia-core:2.20.0
```


Expand Down
23 changes: 16 additions & 7 deletions docs/wiki/docs/unittests.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Unit-Tests with MCCoroutine

(This site is only relevant for Spigot, Paper and CraftBukkit. If you need Unit-Tests support for BungeeCord, Sponge or
Velocity, please submit an issue on GitHub)
Unit-Test support is only available for ``mccoroutine-bukkit`` and ``mccoroutine-folia``. Please create a GitHub ticket, if you want support for other libraries.

If you try to write Unit- or IntegrationTests for your Minecraft plugin, you may need to test suspend functions. These
functions
Expand All @@ -16,11 +15,21 @@ feedback to the real environment.

**Do not** shade this library into your final plugin.jar file. This should only be available during UnitTests.

```kotlin
dependencies {
testImplementation("com.github.shynixn.mccoroutine:mccoroutine-bukkit-test:2.19.0")
}
```
=== "Bukkit"

```kotlin
dependencies {
testImplementation("com.github.shynixn.mccoroutine:mccoroutine-bukkit-test:2.20.0")
}
```

=== "Folia"

```kotlin
dependencies {
testImplementation("com.github.shynixn.mccoroutine:mccoroutine-folia-test:2.20.0")
}
```

### 2. Create a test method

Expand Down
2 changes: 1 addition & 1 deletion mccoroutine-bukkit-sample/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: MCCoroutine-Sample
version: 2.19.0
version: 2.20.0
author: Shynixn
main: com.github.shynixn.mccoroutine.bukkit.sample.MCCoroutineSamplePlugin
commands:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: MCCoroutine-Sample
version: 2.19.0
version: 2.20.0
author: Shynixn
main: com.github.shynixn.mccoroutine.bungeecord.sample.MCCoroutineSamplePlugin
commands:
Expand Down
4 changes: 2 additions & 2 deletions mccoroutine-fabric-sample/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ repositories {
mavenLocal()
}
dependencies {
implementation("com.github.shynixn.mccoroutine:mccoroutine-fabric-api:2.19.0")
implementation("com.github.shynixn.mccoroutine:mccoroutine-fabric-core:2.19.0")
implementation("com.github.shynixn.mccoroutine:mccoroutine-fabric-api:2.20.0")
implementation("com.github.shynixn.mccoroutine:mccoroutine-fabric-core:2.20.0")

minecraft("com.mojang", "minecraft", project.extra["minecraft_version"] as String)
mappings("net.fabricmc", "yarn", project.extra["yarn_mappings"] as String, null, "v2")
Expand Down
2 changes: 1 addition & 1 deletion mccoroutine-folia-sample/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: MCCoroutine-Sample
version: 2.19.0
version: 2.20.0
author: Shynixn
main: com.github.shynixn.mccoroutine.folia.sample.MCCoroutineSamplePlugin
folia-supported: true
Expand Down
30 changes: 30 additions & 0 deletions mccoroutine-folia-test/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

repositories {
maven {
url = uri("https://repo.papermc.io/repository/maven-public/")
}
}


java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}

tasks.withType<KotlinCompile>().configureEach {
kotlinOptions {
jvmTarget = "17"
}
}

dependencies {
implementation(project(":mccoroutine-folia-api"))

compileOnly("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9")
compileOnly("dev.folia:folia-api:1.20.1-R0.1-20230615.235213-1")

testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9")
testImplementation("dev.folia:folia-api:1.20.1-R0.1-20230615.235213-1")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.github.shynixn.mccoroutine.folia.test

import com.github.shynixn.mccoroutine.folia.test.impl.TestMCCoroutineImpl

interface TestMCCoroutine {
companion object {
/**
* The driver to load the test implementation of MCCoroutine.
* Useful for UnitTests.
*/
val Driver = TestMCCoroutineImpl::class.java.name
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.github.shynixn.mccoroutine.folia.test.dispatcher

import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Runnable
import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors
import kotlin.coroutines.CoroutineContext

internal class TestMainCoroutineDispatcher : CoroutineDispatcher() {
private val threadPool: ExecutorService = Executors.newFixedThreadPool(1)
var threadId: Long? = null

init {
threadPool.submit {
Thread.currentThread().name = "[PluginMainThread]"
threadId = Thread.currentThread().id
}
}

override fun isDispatchNeeded(context: CoroutineContext): Boolean {
return Thread.currentThread().id != threadId
}

override fun dispatch(context: CoroutineContext, block: Runnable) {
threadPool.submit {
block.run()
}
}

fun dispose() {
threadPool.shutdown()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.github.shynixn.mccoroutine.folia.test.dispatcher

import kotlinx.coroutines.CoroutineDispatcher
import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors
import kotlin.coroutines.CoroutineContext

internal class TestMultiThreadsCoroutineDispatcher(private val name : String) :
CoroutineDispatcher() {
private val threadPool: ExecutorService = Executors.newFixedThreadPool(4)

override fun isDispatchNeeded(context: CoroutineContext): Boolean {
return true
}

override fun dispatch(context: CoroutineContext, block: Runnable) {
threadPool.submit {
Thread.currentThread().name = name
block.run()
}
}

fun dispose() {
threadPool.shutdown()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.github.shynixn.mccoroutine.folia.test.dispatcher

import kotlinx.coroutines.CoroutineDispatcher
import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors
import kotlin.coroutines.CoroutineContext

internal class TestSingleThreadsCoroutineDispatcher(private val name : String) :
CoroutineDispatcher() {
private val threadPool: ExecutorService = Executors.newFixedThreadPool(1)

override fun isDispatchNeeded(context: CoroutineContext): Boolean {
return true
}

override fun dispatch(context: CoroutineContext, block: Runnable) {
threadPool.submit {
Thread.currentThread().name = name
block.run()
}
}

fun dispose() {
threadPool.shutdown()
}
}
Loading

0 comments on commit 968ca36

Please sign in to comment.