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

Commit e88c90f

Browse files
committed
thingy thing
1 parent 7a2fe8b commit e88c90f

File tree

5 files changed

+73
-19
lines changed

5 files changed

+73
-19
lines changed

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ jobs:
2525
repo_token: "${{ secrets.GITHUB_TOKEN }}"
2626
automatic_release_tag: "latest"
2727
prerelease: false
28-
title: "Release"
28+
title: "Latest Release"
2929
files: ./target/Linky.jar

pom.xml

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<java.version>1.8</java.version>
1818
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1919
<kotlin.version>1.8.0</kotlin.version>
20+
<serialization.version>1.5.0</serialization.version>
2021
</properties>
2122
<url>linky.astrid.sh</url>
2223

@@ -25,24 +26,30 @@
2526
<sourceDirectory>src/main/kotlin</sourceDirectory>
2627
<plugins>
2728
<plugin>
28-
<artifactId>kotlin-maven-plugin</artifactId>
29-
<configuration>
30-
<jvmTarget>${maven.compiler.target}</jvmTarget>
31-
</configuration>
3229
<groupId>org.jetbrains.kotlin</groupId>
30+
<artifactId>kotlin-maven-plugin</artifactId>
3331
<version>${kotlin.version}</version>
3432
<executions>
3533
<execution>
3634
<id>compile</id>
3735
<phase>compile</phase>
38-
<goals> <goal>compile</goal> </goals>
39-
</execution>
40-
<execution>
41-
<id>test-compile</id>
42-
<phase>test-compile</phase>
43-
<goals> <goal>test-compile</goal> </goals>
36+
<goals>
37+
<goal>compile</goal>
38+
</goals>
4439
</execution>
4540
</executions>
41+
<configuration>
42+
<compilerPlugins>
43+
<plugin>kotlinx-serialization</plugin>
44+
</compilerPlugins>
45+
</configuration>
46+
<dependencies>
47+
<dependency>
48+
<groupId>org.jetbrains.kotlin</groupId>
49+
<artifactId>kotlin-maven-serialization</artifactId>
50+
<version>${kotlin.version}</version>
51+
</dependency>
52+
</dependencies>
4653
</plugin>
4754
<plugin>
4855
<groupId>org.apache.maven.plugins</groupId>
@@ -89,7 +96,6 @@
8996
</resource>
9097
</resources>
9198
</build>
92-
9399
<repositories>
94100
<repository>
95101
<id>papermc-repo</id>
@@ -133,10 +139,20 @@
133139
<artifactId>kotlin-stdlib-jdk8</artifactId>
134140
<version>${kotlin.version}</version>
135141
</dependency>
142+
<dependency>
143+
<groupId>org.jetbrains.kotlinx</groupId>
144+
<artifactId>kotlinx-serialization-json</artifactId>
145+
<version>${serialization.version}</version>
146+
</dependency>
136147
<dependency>
137148
<groupId>com.moandjiezana.toml</groupId>
138149
<artifactId>toml4j</artifactId>
139150
<version>0.7.2</version>
140151
</dependency>
152+
<dependency>
153+
<groupId>com.pusher</groupId>
154+
<artifactId>pusher-java-client</artifactId>
155+
<version>2.4.4</version>
156+
</dependency>
141157
</dependencies>
142158
</project>

src/main/kotlin/com/github/linkymc/Linky.kt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
11
package com.github.linkymc;
22

3+
import com.pusher.client.Pusher
4+
import com.pusher.client.PusherOptions
35
import me.aroze.arozeutils.minecraft.FancyPlugin
46
import me.honkling.commando.CommandManager
57
import java.io.File
8+
import kotlinx.serialization.decodeFromString
9+
import kotlinx.serialization.Serializable
10+
import kotlinx.serialization.json.Json
11+
612

713
class Linky : FancyPlugin() {
814
companion object {
915
lateinit var instance: Linky
1016
}
1117

18+
@Serializable
19+
data class SuccessfulLinkResponse(
20+
val event: String,
21+
val data: String,
22+
val channel: String,
23+
)
24+
1225
override fun onEnable() {
1326
saveDefaultConfig()
1427

@@ -23,5 +36,18 @@ class Linky : FancyPlugin() {
2336

2437
val commandManager = CommandManager(instance)
2538
commandManager.registerCommands("com.github.linkymc.commands")
39+
40+
val options = PusherOptions()
41+
options.setCluster("us2")
42+
43+
val pusher = Pusher("059a2227841692b516e0", options)
44+
pusher.connect()
45+
46+
val channel = pusher.subscribe(config.getString("token"))
47+
channel.bind("successful-verify") { event ->
48+
val response: SuccessfulLinkResponse = Json.decodeFromString(event.data.toString())
49+
50+
logger.info("Received event with data: $response")
51+
}
2652
}
2753
}

src/main/kotlin/com/github/linkymc/commands/Book.kt renamed to src/main/kotlin/com/github/linkymc/commands/Link.kt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
11
@file:Command(
2-
"book",
2+
"link",
33
permission = "linky.link"
44
)
55

66
package com.github.linkymc.commands
77

8+
import com.github.linkymc.lib.generateRandomString
89
import com.github.linkymc.lib.getMessage
9-
import me.aroze.arozeutils.minecraft.generic.centerTextToChat
10-
import me.aroze.arozeutils.minecraft.generic.coloured
10+
import me.aroze.arozeutils.kotlin.extension.replacePlaceholders
1111
import me.honkling.commando.lib.Command
1212
import net.kyori.adventure.inventory.Book
1313
import net.kyori.adventure.text.Component
1414
import net.kyori.adventure.text.minimessage.MiniMessage
1515
import org.bukkit.entity.Player
1616

17-
fun book(executor: Player) {
17+
fun link(executor: Player) {
1818
val mm = MiniMessage.miniMessage()
1919

2020
val lines = getMessage("lines") ?: "Invalid lines"
2121

22-
val bookPages: MutableList<Component> = mutableListOf(
23-
mm.deserialize(lines.coloured())
22+
val placeholders = hashMapOf(
23+
"code" to generateRandomString(),
2424
)
2525

26-
executor.sendMessage(centerTextToChat(lines))
26+
val bookPages: MutableList<Component> = mutableListOf(
27+
mm.deserialize(lines.replacePlaceholders(placeholders))
28+
)
2729

2830
val myBook: Book = Book.book(
2931
mm.deserialize("<aqua>Linking Book"),
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.github.linkymc.lib
2+
3+
import kotlin.random.Random
4+
5+
fun generateRandomString(length: Int = 4): String {
6+
val chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
7+
return (1..length)
8+
.map { chars[Random.nextInt(0, chars.length)] }
9+
.joinToString("")
10+
}

0 commit comments

Comments
 (0)