Skip to content

Commit d9fcea6

Browse files
committed
feat: impl Requester for velocity and bungeecord
1 parent 3fdd8f7 commit d9fcea6

12 files changed

Lines changed: 224 additions & 19 deletions

File tree

build.gradle.kts

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,14 @@ repositories {
2828
maven(field.get(null))
2929
}
3030
}
31-
maven {
32-
url = uri("https://repo.neverstopgaming.net/repository/maven-internal/")
33-
credentials {
34-
this.username = System.getenv("repoName") ?: System.getenv("NEXUS_USER") ?: System.getProperty("publishName")
35-
this.password = System.getenv("repoPassword") ?: System.getenv("NEXUS_PASSWORD") ?: System.getProperty("publishPassword")
36-
}
37-
}
3831
}
3932

4033
dependencies {
4134
testImplementation(kotlin("test"))
42-
compileOnly(getDependency("simplecloud", "plugin"))
43-
compileOnly(getDependency("nsg", "api"))
44-
compileOnly(getDependency("nsg", "core"))
45-
compileOnly(getDependency("components", "minimessage"))
35+
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0")
36+
implementation("com.squareup.okhttp3:okhttp:4.9.3")
37+
compileOnly(getDependency("minecraft","velocity"))
38+
compileOnly(getDependency("minecraft","bungee"))
4639
}
4740

4841
tasks.test {
@@ -53,6 +46,30 @@ tasks.withType<KotlinCompile>() {
5346
kotlinOptions.jvmTarget = "1.8"
5447
}
5548

49+
tasks {
50+
51+
shadowJar {
52+
53+
archiveFileName.set("${project.name}-${Properties.version}-full.jar")
54+
exclude("META-INF/**")
55+
56+
doFirst {
57+
//Set Manifest
58+
manifest {
59+
attributes["Implementation-Title"] = project.name
60+
attributes["Implementation-Version"] = Properties.version
61+
attributes["Specification-Version"] = Properties.version
62+
attributes["Implementation-Vendor"] = "NeverStopGaming.net"
63+
attributes["Built-By"] = System.getProperty("user.name")
64+
attributes["Build-Jdk"] = System.getProperty("java.version")
65+
attributes["Created-By"] = "Gradle ${gradle.gradleVersion}"
66+
attributes["Commit-Hash"] = getCommitHash()
67+
attributes["Launcher-Agent-Class"] = "eu.vironlab.vextension.dependency.DependencyAgent"
68+
}
69+
}
70+
}
71+
}
72+
5673
if (System.getProperty("publishName") != null && System.getProperty("publishPassword") != null) {
5774
publishing {
5875
(components["java"] as AdhocComponentWithVariants).withVariantsFromConfiguration(configurations["shadowRuntimeElements"]) {

buildSrc/src/main/kotlin/DependencyExtension.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ object Properties {
3838
val group = "net.neverstopgaming"
3939

4040
@JvmStatic
41-
val version = "1.0.0-SNAPSHOT"
41+
val version = "1.0"
4242

4343
@JvmStatic
4444
val versions: MutableMap<String, String> = mutableMapOf<String, String>().also {
@@ -75,7 +75,8 @@ object Properties {
7575
)
7676
it["minecraft"] = mutableMapOf(
7777
"bukkit" to "com.destroystokyo.paper:paper-api:1.16.5-R0.1-SNAPSHOT",
78-
"velocity" to "com.velocitypowered:velocity-api:3.0.1"
78+
"velocity" to "com.velocitypowered:velocity-api:3.0.1",
79+
"bungee" to "net.md-5:bungeecord-api:1.16-R0.4",
7980
)
8081
it["simplecloud"] = mutableMapOf(
8182
"api" to "eu.thesimplecloud.simplecloud:simplecloud-api:%version%",

settings.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
rootProject.name = "Template"
1+
rootProject.name = "WebRequest-Plugin"
22

33
//Repositorys for Plugins
44
pluginManagement {

src/main/kotlin/net/neverstopgaming/Main.kt

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package net.neverstopgaming.webrequest.bungee
2+
3+
import net.md_5.bungee.config.Configuration
4+
import net.md_5.bungee.config.ConfigurationProvider
5+
import net.md_5.bungee.config.YamlConfiguration
6+
import net.neverstopgaming.webrequest.core.Config
7+
import java.io.File
8+
9+
10+
class BungeeConfig(private val bungeeMain: BungeeMain) : Config {
11+
12+
private val defaultConfig = """
13+
############################################################################################
14+
# _ _ ____ _ ____ _ #
15+
# | \ | | _____ _____ _ __/ ___|| |_ ___ _ __ / ___| __ _ _ __ ___ (_)_ __ __ _ #
16+
# | \| |/ _ \ \ / / _ \ '__\___ \| __/ _ \| '_ \| | _ / _` | '_ ` _ \| | '_ \ / _` | #
17+
# | |\ | __/\ V / __/ | ___) | || (_) | |_) | |_| | (_| | | | | | | | | | | (_| | #
18+
# |_| \_|\___| \_/ \___|_| |____/ \__\___/| .__/ \____|\__,_|_| |_| |_|_|_| |_|\__, | #
19+
# |_| |___/ #
20+
############################################################################################
21+
22+
urls:
23+
- https://status.neverstopgaming.net/api/push/yourid
24+
25+
# the interval in seconds to request the urls
26+
interval: 60
27+
""".trimMargin()
28+
29+
private var config: Configuration
30+
= ConfigurationProvider.getProvider(YamlConfiguration::class.java).load(getConfigFile())
31+
32+
override val urls: Array<String>
33+
get() = config.getStringList("urls").toTypedArray()
34+
35+
override val interval: Long
36+
get() = config.getLong("interval")
37+
38+
override fun getConfigFile() : File {
39+
40+
val file = File(bungeeMain.dataFolder, "config.yml")
41+
42+
if(!file.exists()) {
43+
44+
bungeeMain.dataFolder.mkdirs()
45+
file.createNewFile()
46+
47+
file.writeText(defaultConfig)
48+
49+
}
50+
51+
return file
52+
}
53+
54+
55+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package net.neverstopgaming.webrequest.bungee
2+
3+
import net.md_5.bungee.api.plugin.Plugin
4+
import net.neverstopgaming.webrequest.core.Requester
5+
6+
class BungeeMain : Plugin() {
7+
8+
private val config = BungeeConfig(this)
9+
10+
override fun onEnable() {
11+
12+
logger.info("Config Loaded")
13+
14+
Requester(config)
15+
logger.info("Requester Loaded")
16+
}
17+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package net.neverstopgaming.webrequest.core
2+
3+
import java.io.File
4+
5+
interface Config{
6+
7+
val urls : Array<String>
8+
9+
val interval: Long
10+
11+
fun getConfigFile(): File
12+
13+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package net.neverstopgaming.webrequest.core
2+
3+
import kotlinx.coroutines.*
4+
import okhttp3.OkHttpClient
5+
import okhttp3.Request
6+
7+
@OptIn(DelicateCoroutinesApi::class)
8+
class Requester(config: Config) {
9+
10+
private val client = OkHttpClient()
11+
12+
init {
13+
14+
GlobalScope.launch {
15+
16+
while (this.isActive){
17+
18+
for(url in config.urls) {
19+
val request = Request.Builder().url(url).build()
20+
21+
client.newCall(request).execute()
22+
23+
delay(config.interval * 1000)
24+
}
25+
}
26+
}
27+
}
28+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package net.neverstopgaming.webrequest.velocity
2+
3+
import com.google.gson.JsonParser
4+
import com.google.gson.stream.JsonWriter
5+
import net.neverstopgaming.webrequest.core.Config
6+
import java.io.File
7+
8+
class VelocityConfig : Config {
9+
10+
private val defaultConfig = """
11+
{
12+
"urls": [
13+
"https://status.neverstopgaming.net/api/push/yourid"
14+
],
15+
"interval": 60
16+
}
17+
""".trimMargin()
18+
19+
private val config = JsonParser.parseString(getConfigFile().readText()).asJsonObject
20+
21+
override val urls: Array<String>
22+
get() = config["urls"].asJsonArray.map { it.asString }.toTypedArray()
23+
24+
override val interval: Long
25+
get() = config["interval"].asLong
26+
27+
override fun getConfigFile(): File {
28+
29+
val file = File("plugins/WebRequest", "config.json")
30+
31+
if (!file.exists()) {
32+
33+
file.parentFile.mkdirs()
34+
file.createNewFile()
35+
36+
file.writeText(defaultConfig)
37+
}
38+
39+
return file
40+
}
41+
42+
43+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package net.neverstopgaming.webrequest.velocity
2+
3+
import com.google.inject.Inject
4+
import com.velocitypowered.api.event.Subscribe
5+
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent
6+
import com.velocitypowered.api.plugin.Plugin
7+
import com.velocitypowered.api.proxy.ProxyServer
8+
import net.neverstopgaming.webrequest.core.Requester
9+
import org.slf4j.Logger
10+
11+
class VelocityMain @Inject constructor(val server: ProxyServer, private val logger: Logger) {
12+
13+
private val config = VelocityConfig()
14+
15+
@Subscribe
16+
fun onReady(e: ProxyInitializeEvent) {
17+
18+
logger.debug("Config loaded")
19+
20+
Requester(config)
21+
logger.debug("Requester loaded")
22+
}
23+
}

0 commit comments

Comments
 (0)