-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
100 additions
and
1 deletion.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
...otlin/de/bypixeltv/skcloudnet/elements/effects/services/EffCreateCloudnetServiceWithId.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...e/bypixeltv/skcloudnet/elements/effects/services/EffCreateStartedCloudnetServiceWithId.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |