Skip to content

Commit

Permalink
Fixed something ig
Browse files Browse the repository at this point in the history
  • Loading branch information
byPixelTV committed May 11, 2024
1 parent 27e78b0 commit 857bea4
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package de.bypixeltv.skcloudnet.elements.effects.services

import ch.njol.skript.Skript
import ch.njol.skript.lang.Effect
import ch.njol.skript.lang.Expression
import ch.njol.skript.lang.SkriptParser
import ch.njol.util.Kleenean
import eu.cloudnetservice.driver.inject.InjectionLayer
import eu.cloudnetservice.driver.provider.ServiceTaskProvider
import eu.cloudnetservice.driver.service.ServiceConfiguration
import org.bukkit.event.Event


class EffCreateCloudnetServiceWithId : Effect() {

private val serviceTaskProvider: ServiceTaskProvider = InjectionLayer.ext().instance(ServiceTaskProvider::class.java)

companion object{
init {
Skript.registerEffect(EffCreateCloudnetServiceWithId::class.java, "create [a] [cloudnet] service by [the task] %string% with (the id|id) %int%")
}
}

private var taskExpression: Expression<String>? = null
private var idExpression: Expression<Int>? = null

@Suppress("UNCHECKED_CAST")
override fun init(
expressions: Array<Expression<*>>,
matchedPattern: Int,
isDelayed: Kleenean,
parser: SkriptParser.ParseResult
): Boolean {
this.taskExpression = expressions[0] as Expression<String>
this.idExpression = expressions[1] as Expression<Int>
return true
}

override fun toString(event: Event?, debug: Boolean): String {
return "create cloudnet service by task ${taskExpression.toString()} with id ${idExpression.toString()}"
}

override fun execute(event: Event?) {
val taskExpr = taskExpression?.getSingle(event)
val idExpr = idExpression?.getSingle(event) ?: -1
val serviceTask = serviceTaskProvider.serviceTask(taskExpr.toString())
val serviceInfoSnapshot = serviceTask?.let { ServiceConfiguration.builder(it).taskId(idExpr).build().createNewServiceAsync() }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class EffCreateStartedCloudnetService : Effect() {

companion object{
init {
Skript.registerEffect(EffCreateStartedCloudnetService::class.java, "create [a] started [cloudnet] service by [the] [task] %string%")
Skript.registerEffect(EffCreateStartedCloudnetService::class.java, "create [a] started [cloudnet] service by [the task] %string%")
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package de.bypixeltv.skcloudnet.elements.effects.services

import ch.njol.skript.Skript
import ch.njol.skript.lang.Effect
import ch.njol.skript.lang.Expression
import ch.njol.skript.lang.SkriptParser
import ch.njol.util.Kleenean
import eu.cloudnetservice.driver.inject.InjectionLayer
import eu.cloudnetservice.driver.provider.ServiceTaskProvider
import eu.cloudnetservice.driver.service.ServiceConfiguration
import org.bukkit.event.Event


class EffCreateStartedCloudnetServiceWithId : Effect() {

private val serviceTaskProvider: ServiceTaskProvider = InjectionLayer.ext().instance(ServiceTaskProvider::class.java)

companion object{
init {
Skript.registerEffect(EffCreateStartedCloudnetServiceWithId::class.java, "create [a] started [cloudnet] service by [the task] %string% with (the id|id) %int%")
}
}

private var taskExpression: Expression<String>? = null
private var idExpression: Expression<Int>? = null

@Suppress("UNCHECKED_CAST")
override fun init(
expressions: Array<Expression<*>>,
matchedPattern: Int,
isDelayed: Kleenean,
parser: SkriptParser.ParseResult
): Boolean {
this.taskExpression = expressions[0] as Expression<String>
this.idExpression = expressions[1] as Expression<Int>
return true
}

override fun toString(event: Event?, debug: Boolean): String {
return "create started cloudnet service by task ${taskExpression.toString()} with id ${idExpression.toString()}"
}

override fun execute(event: Event?) {
val taskExpr = taskExpression?.getSingle(event)
val idExpr = idExpression?.getSingle(event) ?: -1
val serviceTask = serviceTaskProvider.serviceTask(taskExpr.toString())
val serviceInfoSnapshot = serviceTask?.let { ServiceConfiguration.builder(it).taskId(idExpr).build().createNewService() }
serviceInfoSnapshot?.serviceInfo()?.provider()?.startAsync()
}
}

0 comments on commit 857bea4

Please sign in to comment.