Skip to content

Commit

Permalink
Merge pull request #10 from Shynixn/development
Browse files Browse the repository at this point in the history
Merge changes to master. --release
  • Loading branch information
Shynixn authored Oct 13, 2020
2 parents 61d8e75 + 8dc29d7 commit fb2d0b1
Show file tree
Hide file tree
Showing 23 changed files with 14 additions and 582 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ before_install:
- gpg2 --batch --cipher-algo AES256 --passphrase $SIGNING_KEYPASSWORD travis_secret_key.gpg
script:
- ./gradlew clean build
after_success:
- ./gradlew jacocoRootReport
- if [[ $TRAVIS_COMMIT_MESSAGE == *"--snapshot"* ]]; then ./gradlew publish > /dev/null; fi ;
- if [[ $TRAVIS_COMMIT_MESSAGE == *"--release"* && $TRAVIS_BRANCH == *"master"* ]]; then ./gradlew clean publishToNexus > /dev/null; fi ;
- if [[ $TRAVIS_COMMIT_MESSAGE == *"--release"* && $TRAVIS_BRANCH == *"master"* ]]; then ./gradlew closeAndReleaseRepository; fi ;
- if [[ $TRAVIS_BRANCH == *"master"* ]]; then rm -rf docs/build && rm -rf docs/apidocs; fi ;
- if [[ $TRAVIS_BRANCH == *"master"* ]]; then ./gradlew generateJavaDocPages > /dev/null; fi ;
- if [[ $TRAVIS_BRANCH == *"master"* ]]; then git add docs && git commit --message "Travis build $TRAVIS_BUILD_NUMBER [skip travis-ci]"; fi ;
- if [[ $TRAVIS_BRANCH == *"master"* ]]; then git push --quiet https://Shynixn:[email protected]/Shynixn/MCCoroutine.git HEAD:master; fi ;
after_success:
- ./gradlew jacocoRootReport
- bash <(curl -s https://codecov.io/bash)
- ./travis-status.sh success $DISCORD_TOKEN
after_failure:
Expand Down
95 changes: 2 additions & 93 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ suspend fun onPlayerJoinEvent(playerJoinEvent: PlayerJoinEvent) {

* Full implementation of Kotlin Coroutines (async/await)
* Extension functions for already established functions
* Connection to events, commands, schedulers and packet stream
* Connection to events, commands, schedulers
* Coroutine LifeCycle scope for plugins (supports plugin reloading)
* No NMS
* Support for Minecraft 1.7 - Latest
Expand Down Expand Up @@ -60,25 +60,6 @@ dependencies {

[MCCoroutine.jar](http://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&g=com.github.shynixn.mccoroutine&a=mccoroutine-bukkit-api&v=LATEST)

**If you want to do packet level manipulation, add the following dependency**

**Maven**
```xml
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.1.52.Final</version>
<scope>provided</scope>
</dependency>
```
**Gradle**

```xml
dependencies {
compileOnly("io.netty:netty-all:4.1.52.Final")
}
```

## Getting started

**Introduction**
Expand All @@ -92,7 +73,7 @@ Source:

**Notes**

This library was created for my plugins **PetBlocks** and **BlockBall** as I had to deal with sometimes short, sometimes long running async operations and packet manipulation. Caching
This library was created for my plugins **PetBlocks** and **BlockBall** as I had to deal with sometimes short, sometimes long running async operations. Caching
database results is an essential component of both and a cache miss should not block the server in any way.

## Code Examples
Expand Down Expand Up @@ -202,71 +183,6 @@ Plugin plugin
val scope = plugin.scope
```

##### Listening to incoming and outgoing packets

* Register all packets you want to watch.

```kotlin
import com.github.shynixn.mccoroutine.findClazz
import com.github.shynixn.mccoroutine.registerPackets

Plugin plugin
server.pluginManager.registerPackets(listOf(findClazz("net.minecraft.server.VERSION.PacketPlayInFlying\$PacketPlayInPositionLook")),plugin)
```

* Create and register a listener as seen above.
* Add the PlayerPacketEvent.

```kotlin
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.player.PlayerJoinEvent
import com.github.shynixn.mccoroutine.PlayerPacketEvent

class PlayerPacketListener : Listener {
@EventHandler
suspend fun onPlayerPacketEvent(playerPacketEvent: PlayerPacketEvent) {
// Access the NMS packet
// (not recommend, use the byteData and create your own packet instances as seen below)
val handle = playerPacketEvent.packet

// However, you use it to find out the type of the packet.
if(playerPacketEvent.packet.javaClass.simpleName != "PacketPlayInPositionLook"){
return
}

// Access the byte buffer (Requires io.netty dependency mentioned above)
val packet = MyPacketPlayInPositionLooks(playerPacketEvent.byteData)

// Do something with packet ...
}
}
```

* Create a new class which takes the byte buffer, so you can work with version independet data.

```kotlin
class MyPacketPlayInPositionLooks(private val byteBuf: ByteBuf) {
val x: Double
val y: Double
val z: Double
val yaw: Float
val pitch: Float
val f: Boolean
val hasPos: Boolean = true
val hasLook: Boolean = true

init {
x = byteBuf.readDouble()
y = byteBuf.readDouble()
z = byteBuf.readDouble()
yaw = byteBuf.readFloat()
pitch = byteBuf.readFloat()
f = byteBuf.readUnsignedByte().toInt() != 0
}
}
```

### Recommend extension methods (These will be used later in this guide)

As you may have noticed, almost every call to the api needs a plugin instance which kind of
Expand Down Expand Up @@ -503,12 +419,6 @@ class PlaceHolderApiConnector(private val cache : UserDataCache) {
<version>1.x.x</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.1.52.Final</version>
<scope>provided</scope>
</dependency>
```
**Gradle**

Expand All @@ -517,7 +427,6 @@ dependencies {
implementation("com.github.shynixn.mccoroutine:mccoroutine-bukkit-core:0.0.4")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.x.x")
implementation("org.jetbrains.kotlin:kotlin-reflect:1.x.x")
compileOnly("io.netty:netty-all:4.1.52.Final")
}
```

Expand Down
1 change: 0 additions & 1 deletion mccoroutine-bukkit-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ repositories {
}

dependencies {
compileOnly("io.netty:netty-all:4.1.52.Final")
compileOnly("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9")
compileOnly("org.jetbrains.kotlin:kotlin-reflect:1.3.72")
compileOnly("org.spigotmc:spigot-api:1.16.3-R0.1-SNAPSHOT")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package com.github.shynixn.mccoroutine

import com.github.shynixn.mccoroutine.contract.MCCoroutine
import io.netty.buffer.ByteBuf
import kotlinx.coroutines.CoroutineScope
import org.bukkit.Bukkit
import org.bukkit.command.PluginCommand
import org.bukkit.entity.Player
import org.bukkit.event.Listener
import org.bukkit.plugin.Plugin
import org.bukkit.plugin.PluginManager
Expand Down Expand Up @@ -118,13 +115,6 @@ fun PluginManager.registerSuspendingEvents(listener: Listener, plugin: Plugin) {
return mcCoroutine.getCoroutineSession(plugin).eventService.registerSuspendListener(listener)
}

/**
* Registers the given packets for event listening.
*/
fun PluginManager.registerPackets(packets: List<Class<*>>, plugin: Plugin) {
mcCoroutine.getCoroutineSession(plugin).protocolService.registerPackets(packets)
}

/**
* Registers an command executor with suspending function.
* Does exactly the same as PluginCommand.setExecutor.
Expand All @@ -138,23 +128,6 @@ fun PluginCommand.setSuspendingExecutor(
)
}

/**
* Sends a native minecraft packet to the player client.
*/
fun <P> Player.sendPacket(plugin: Plugin, packet: P) {
require(packet is Any)
return mcCoroutine.getCoroutineSession(plugin).protocolService.sendPacket(this, packet)
}

/**
* Sends the bytebuffer packet to the player client.
* @param clazz NMS Packet class.
* @param buf Byte buffer serialized.
*/
fun Player.sendPacket(plugin: Plugin, clazz: Class<*>, buf: ByteBuf) {
return mcCoroutine.getCoroutineSession(plugin).protocolService.sendBytePacket(this, clazz, buf)
}

/**
* Finds the version compatible class.
*/
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ interface CoroutineSession {
*/
val eventService: EventService

/**
* Gets the protocol service.
*/
val protocolService: ProtocolService

/**
* Gets the command service.
*/
Expand Down

This file was deleted.

2 changes: 0 additions & 2 deletions mccoroutine-bukkit-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@ repositories {
dependencies {
implementation(project(":mccoroutine-bukkit-api"))

compileOnly("io.netty:netty-all:4.1.52.Final")
compileOnly("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9")
compileOnly("org.jetbrains.kotlin:kotlin-reflect:1.3.72")
compileOnly("org.spigotmc:spigot-api:1.16.3-R0.1-SNAPSHOT")

testCompile("io.netty:netty-all:4.1.52.Final")
testCompile("org.jetbrains.kotlin:kotlin-reflect:1.3.72")
testCompile("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9")
testCompile("org.spigotmc:spigot-api:1.16.3-R0.1-SNAPSHOT")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import com.github.shynixn.mccoroutine.contract.CoroutineSession
import com.github.shynixn.mccoroutine.contract.MCCoroutine
import com.github.shynixn.mccoroutine.service.CoroutineSessionImpl
import com.github.shynixn.mccoroutine.listener.PluginListener
import org.bukkit.Bukkit
import org.bukkit.plugin.Plugin

class MCCoroutineImpl : MCCoroutine {
Expand Down Expand Up @@ -44,11 +43,6 @@ class MCCoroutineImpl : MCCoroutine {

val pluginListener = PluginListener(this, plugin)
items[plugin] = CoroutineSessionImpl(plugin)

for (player in plugin.server.onlinePlayers) {
getCoroutineSession(plugin).protocolService.register(player)
}

plugin.server.pluginManager.registerEvents(pluginListener, plugin)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package com.github.shynixn.mccoroutine.listener
import com.github.shynixn.mccoroutine.contract.MCCoroutine
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.player.PlayerJoinEvent
import org.bukkit.event.player.PlayerQuitEvent
import org.bukkit.event.server.PluginDisableEvent
import org.bukkit.plugin.Plugin

Expand All @@ -20,20 +18,4 @@ internal class PluginListener(private val mcCoroutine: MCCoroutine, private val

mcCoroutine.disable(pluginEvent.plugin)
}

/**
* Gets called when a player joins the server.
*/
@EventHandler
fun onPlayerJoinEvent(event: PlayerJoinEvent) {
mcCoroutine.getCoroutineSession(plugin).protocolService.register(event.player)
}

/**
* Gets called when a player quits the server.
*/
@EventHandler
fun onPlayerQuitEvent(event: PlayerQuitEvent) {
mcCoroutine.getCoroutineSession(plugin).protocolService.unRegister(event.player)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal class CommandServiceImpl(private val plugin: Plugin, private val corout
// If the result is delayed we can automatically assume it is true.
var success = true

coroutineSession.launch(plugin.minecraftDispatcher) {
coroutineSession.launch(coroutineSession.dispatcherMinecraft) {
success = commandExecutor.onCommand(p0, p1, p2, p3)
}

Expand Down
Loading

0 comments on commit fb2d0b1

Please sign in to comment.