Skip to content

Commit 6312f23

Browse files
authored
Merge pull request #73 from Shynixn/development
Merge changes to master --release
2 parents 968ec03 + 6c3468a commit 6312f23

File tree

9 files changed

+58
-21
lines changed

9 files changed

+58
-21
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ tasks.register("printVersion") {
4343

4444
subprojects {
4545
group 'com.github.shynixn.mccoroutine'
46-
version '2.3.0'
46+
version '2.4.0'
4747

4848
sourceCompatibility = 1.8
4949

docs/wiki/docs/installation.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,35 @@ In order to use the MCCoroutine Kotlin API, you need to include the following li
88

99
```groovy
1010
dependencies {
11-
implementation("com.github.shynixn.mccoroutine:mccoroutine-bukkit-api:2.3.0")
12-
implementation("com.github.shynixn.mccoroutine:mccoroutine-bukkit-core:2.3.0")
11+
implementation("com.github.shynixn.mccoroutine:mccoroutine-bukkit-api:2.4.0")
12+
implementation("com.github.shynixn.mccoroutine:mccoroutine-bukkit-core:2.4.0")
1313
}
1414
```
1515

1616
=== "BungeeCord"
1717

1818
```groovy
1919
dependencies {
20-
implementation("com.github.shynixn.mccoroutine:mccoroutine-bungeecord-api:2.3.0")
21-
implementation("com.github.shynixn.mccoroutine:mccoroutine-bungeecord-core:2.3.0")
20+
implementation("com.github.shynixn.mccoroutine:mccoroutine-bungeecord-api:2.4.0")
21+
implementation("com.github.shynixn.mccoroutine:mccoroutine-bungeecord-core:2.4.0")
2222
}
2323
```
2424

2525
=== "Sponge"
2626

2727
```groovy
2828
dependencies {
29-
implementation("com.github.shynixn.mccoroutine:mccoroutine-sponge-api:2.3.0")
30-
implementation("com.github.shynixn.mccoroutine:mccoroutine-sponge-core:2.3.0")
29+
implementation("com.github.shynixn.mccoroutine:mccoroutine-sponge-api:2.4.0")
30+
implementation("com.github.shynixn.mccoroutine:mccoroutine-sponge-core:2.4.0")
3131
}
3232
```
3333

3434
=== "Velocity"
3535

3636
```groovy
3737
dependencies {
38-
implementation("com.github.shynixn.mccoroutine:mccoroutine-velocity-api:2.3.0")
39-
implementation("com.github.shynixn.mccoroutine:mccoroutine-velocity-core:2.3.0")
38+
implementation("com.github.shynixn.mccoroutine:mccoroutine-velocity-api:2.4.0")
39+
implementation("com.github.shynixn.mccoroutine:mccoroutine-velocity-core:2.4.0")
4040
}
4141
```
4242

@@ -60,8 +60,8 @@ dependencies {
6060
**plugin.yml**
6161
```yaml
6262
libraries:
63-
- com.github.shynixn.mccoroutine:mccoroutine-bukkit-api:2.3.0
64-
- com.github.shynixn.mccoroutine:mccoroutine-bukkit-core:2.3.0
63+
- com.github.shynixn.mccoroutine:mccoroutine-bukkit-api:2.4.0
64+
- com.github.shynixn.mccoroutine:mccoroutine-bukkit-core:2.4.0
6565
```
6666

6767
=== "Other Server"

docs/wiki/docs/tasks.md

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ given time.
1414
There is a big difference with ``delay()`` and ``Thread.sleep()``. Consult the official Kotlin Coroutines
1515
documentation for details, however essentially ``Thread.sleep()`` blocks the thread for a given time and
1616
``delay()`` suspends the thread for a given time. When a thread is suspended, it can do other work (e.g. server handles
17-
other operations like players joining or commands) compared to when a thread is blocked, it cannot do other work (e.g. server appears frozen).
18-
17+
other operations like players joining or commands) compared to when a thread is blocked, it cannot do other work (e.g. server appears frozen).
1918

2019
````kotlin
2120
suspend fun sayHello() {
@@ -29,23 +28,34 @@ If you are not in a ``suspend`` function, use ``plugin.launch`` together with ``
2928

3029
````kotlin
3130
fun sayHello() {
32-
plugin.launch {
31+
plugin.launch {
3332
println("Please say hello in 2 seconds")
3433
delay(2000) // Delay for 2000 milliseconds
3534
println("hello")
36-
}
35+
}
3736
}
3837
````
3938

39+
## Delay Ticks
40+
41+
MCCoroutine offers an extension method to use delay together with Bukkit and Sponge ticks.
42+
43+
```kotlin
44+
delay(1.ticks)
45+
```
46+
47+
Prefer using ``delay(1.ticks)`` when delaying on the minecraft main thread instead of ``delay(50)``. The tick extension function is more accurate than using
48+
milliseconds directly. The technical details are explained in this [github issue](https://github.com/Shynixn/MCCoroutine/issues/72).
49+
4050
## Repeating tasks
4151

4252
If you are already in a ``suspend`` function, you can simply use traditional loops with ``delay`` to repeat tasks.
4353

4454
````kotlin
4555
suspend fun sayHello() {
4656
println("Please say hello 10 times every 2 seconds")
47-
48-
for (i in 0 until 10){
57+
58+
for (i in 0 until 10) {
4959
delay(2000) // Delay for 2000 milliseconds
5060
println("hello")
5161
}

mccoroutine-bukkit-api/src/main/java/com/github/shynixn/mccoroutine/bukkit/MCCoroutine.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,20 @@ fun PluginCommand.setSuspendingTabCompleter(context: CoroutineContext, suspendin
195195
)
196196
}
197197

198+
/**
199+
* Converts the number to ticks for being used together with delay(..).
200+
* E.g. delay(1.ticks).
201+
* Minecraft ticks 20 times per second, which means a tick appears every 50 milliseconds. However,
202+
* delay() does not directly work with the BukkitScheduler and needs millisecond manipulation to
203+
* work as expected. Therefore, 1 tick does not equal 50 milliseconds when using this method standalone and only
204+
* sums up to 50 milliseconds if you use it together with delay.
205+
*/
206+
val Int.ticks: Long
207+
get() {
208+
return (this * 50L - 25)
209+
}
210+
211+
198212
interface MCCoroutine {
199213
/**
200214
* Get coroutine session for the given plugin.

mccoroutine-bukkit-api/src/main/java/com/github/shynixn/mccoroutine/bukkit/MCCoroutineExceptionEvent.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import org.bukkit.event.HandlerList
66
import org.bukkit.plugin.Plugin
77

88
/**
9-
* A BungeeCord event which is called when an exception is raised in one of the coroutines managed by MCCoroutine.
9+
* A Bukkit event which is called when an exception is raised in one of the coroutines managed by MCCoroutine.
1010
* Cancelling this exception causes the error to not get logged and offers to possibility for custom logging.
1111
*/
1212
class MCCoroutineExceptionEvent(

mccoroutine-bukkit-sample/src/main/resources/plugin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: MCCoroutine-Sample
2-
version: 2.3.0
2+
version: 2.4.0
33
author: Shynixn
44
main: com.github.shynixn.mccoroutine.bukkit.sample.MCCoroutineSamplePlugin
55
commands:

mccoroutine-bungeecord-sample/src/main/resources/plugin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: MCCoroutine-Sample
2-
version: 2.3.0
2+
version: 2.4.0
33
author: Shynixn
44
main: com.github.shynixn.mccoroutine.bungeecord.sample.MCCoroutineSamplePlugin
55
commands:

mccoroutine-sponge-api/src/main/java/com/github/shynixn/mccoroutine/sponge/MCCoroutine.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,19 @@ fun CommandSpec.Builder.suspendingExecutor(
154154
return this
155155
}
156156

157+
/**
158+
* Converts the number to ticks for being used together with delay(..).
159+
* E.g. delay(1.ticks).
160+
* Minecraft ticks 20 times per second, which means a tick appears every 50 milliseconds. However,
161+
* delay() does not directly work with the SpongeScheduler and needs millisecond manipulation to
162+
* work as expected. Therefore, 1 tick does not equal 50 milliseconds when using this method standalone and only
163+
* sums up to 50 milliseconds if you use it together with delay.
164+
*/
165+
val Int.ticks: Long
166+
get() {
167+
return (this * 50L - 25)
168+
}
169+
157170
interface MCCoroutine {
158171
/**
159172
* Get coroutine session for the given plugin.

mccoroutine-sponge-sample/src/main/resources/mcmod.info

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[{
22
"modid": "mccoroutinesample",
33
"name": "MCCoroutineSample",
4-
"version": "2.3.0",
4+
"version": "2.4.0",
55
"description": "MCCoroutineSample is sample plugin to use MCCoroutine in Sponge.",
66
"authorList": [
77
"Shynixn"

0 commit comments

Comments
 (0)