Skip to content

Commit

Permalink
Fixed some bugs with the Lifecycle conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
byPixelTV committed Apr 12, 2024
1 parent 24a1452 commit ced809d
Show file tree
Hide file tree
Showing 6 changed files with 242 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package de.bypixeltv.skcloudnet.elements.conditions.services

import ch.njol.skript.Skript
import ch.njol.skript.doc.Description
import ch.njol.skript.doc.Examples
import ch.njol.skript.doc.Name
import ch.njol.skript.doc.Since
import ch.njol.skript.lang.Condition
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.CloudServiceProvider
import org.bukkit.event.Event


@Name("CloudNet Service Deleted")
@Description("Returns if a CloudNet service is deleted or not")
@Examples("if cloudnet service \"Lobby-1\" is deleted: send \"Lobby-1 is deleted\"")
@Since("1.1")

class CondCloudnetServiceDeleted : Condition() {

val cnServiceProvider: CloudServiceProvider = InjectionLayer.ext().instance(CloudServiceProvider::class.java)

companion object{
init {
Skript.registerCondition(CondCloudnetServiceDeleted::class.java, "[lifecycle] [of] [cloudnet] service %string% (1¦is|2¦is(n't| not)) deleted")
}
}

private var service: Expression<String>? = null

override fun init(
expressions: Array<Expression<*>>,
matchedPattern: Int,
isDelayed: Kleenean?,
parser: SkriptParser.ParseResult
): Boolean {
this.service = expressions[0] as Expression<String>?
isNegated = parser.mark === 1
return true
}

override fun check(e: Event?): Boolean {
val service = service?.getSingle(e) ?: return isNegated
return if (cnServiceProvider.serviceByName(service)?.lifeCycle()?.name == "DELETED") {
!isNegated
} else {
isNegated
}
}

override fun toString(e: Event?, debug: Boolean): String {
return "${service.toString()} is deleted"
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package de.bypixeltv.skcloudnet.elements.conditions.services

import ch.njol.skript.Skript
import ch.njol.skript.doc.Description
import ch.njol.skript.doc.Examples
import ch.njol.skript.doc.Name
import ch.njol.skript.doc.Since
import ch.njol.skript.lang.Condition
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.CloudServiceProvider
import org.bukkit.event.Event


@Name("CloudNet Service Prepared")
@Description("Returns if a CloudNet service is prepared or not")
@Examples("if cloudnet service \"Lobby-1\" is prepared: send \"Lobby-1 is prepared\"")
@Since("1.1")

class CondCloudnetServicePrepared : Condition() {

val cnServiceProvider: CloudServiceProvider = InjectionLayer.ext().instance(CloudServiceProvider::class.java)

companion object{
init {
Skript.registerCondition(CondCloudnetServicePrepared::class.java, "[lifecycle] [of] [cloudnet] service %string% (1¦is|2¦is(n't| not)) prepared")
}
}

private var service: Expression<String>? = null

override fun init(
expressions: Array<Expression<*>>,
matchedPattern: Int,
isDelayed: Kleenean?,
parser: SkriptParser.ParseResult
): Boolean {
this.service = expressions[0] as Expression<String>?
isNegated = parser.mark === 1
return true
}

override fun check(e: Event?): Boolean {
val service = service?.getSingle(e) ?: return isNegated
return if (cnServiceProvider.serviceByName(service)?.lifeCycle()?.name == "PREPARED") {
!isNegated
} else {
isNegated
}
}

override fun toString(e: Event?, debug: Boolean): String {
return "${service.toString()} is prepared"
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class CondCloudnetServiceRunning : Condition() {

companion object{
init {
Skript.registerCondition(CondCloudnetServiceRunning::class.java, "[cloudnet] service %string% (1¦is|2¦is(n't| not)) running")
Skript.registerCondition(CondCloudnetServiceRunning::class.java, "[lifecycle] [of] [cloudnet] service %string% (1¦is|2¦is(n't| not)) (running|started)")
}
}

Expand All @@ -43,9 +43,12 @@ class CondCloudnetServiceRunning : Condition() {
}

override fun check(e: Event?): Boolean {
val service = service?.getSingle(e)
if (service == null) return isNegated
return if (cnServiceProvider.runningServices().any { it.name() == service }) isNegated else !isNegated
val service = service?.getSingle(e) ?: return isNegated
return if (cnServiceProvider.serviceByName(service)?.lifeCycle()?.name == "RUNNING") {
!isNegated
} else {
isNegated
}
}

override fun toString(e: Event?, debug: Boolean): String {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package de.bypixeltv.skcloudnet.elements.conditions.services

import ch.njol.skript.Skript
import ch.njol.skript.doc.Description
import ch.njol.skript.doc.Examples
import ch.njol.skript.doc.Name
import ch.njol.skript.doc.Since
import ch.njol.skript.lang.Condition
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.CloudServiceProvider
import org.bukkit.event.Event


@Name("CloudNet Service Stopping")
@Description("Returns if a CloudNet service is stopping or not")
@Examples("if cloudnet service \"Lobby-1\" is stopping: send \"Lobby-1 is stopping\"")
@Since("1.1")

class CondCloudnetServiceStopping : Condition() {

val cnServiceProvider: CloudServiceProvider = InjectionLayer.ext().instance(CloudServiceProvider::class.java)

companion object{
init {
Skript.registerCondition(CondCloudnetServiceStopping::class.java, "[lifecycle] [of] [cloudnet] service %string% (1¦is|2¦is(n't| not)) stopping")
}
}

private var service: Expression<String>? = null

override fun init(
expressions: Array<Expression<*>>,
matchedPattern: Int,
isDelayed: Kleenean?,
parser: SkriptParser.ParseResult
): Boolean {
this.service = expressions[0] as Expression<String>?
isNegated = parser.mark === 1
return true
}

override fun check(e: Event?): Boolean {
val service = service?.getSingle(e) ?: return isNegated
return if (cnServiceProvider.serviceByName(service)?.lifeCycle()?.name == "STOPPING") {
!isNegated
} else {
isNegated
}
}

override fun toString(e: Event?, debug: Boolean): String {
return "${service.toString()} is stopping"
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ExprAllCloudnetServices : SimpleExpression<String>() {
init {
Skript.registerExpression(
ExprAllCloudnetServices::class.java, String::class.java,
ExpressionType.SIMPLE, "[(all [[of] the]|the)] [running] cloudnet services")
ExpressionType.SIMPLE, "[(all [[of] the]|the)] [cloudnet] services")
}
}

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

import ch.njol.skript.Skript
import ch.njol.skript.doc.Description
import ch.njol.skript.doc.Examples
import ch.njol.skript.doc.Name
import ch.njol.skript.doc.Since
import ch.njol.skript.lang.Expression
import ch.njol.skript.lang.ExpressionType
import ch.njol.skript.lang.SkriptParser
import ch.njol.skript.lang.util.SimpleExpression
import ch.njol.util.Kleenean
import eu.cloudnetservice.driver.inject.InjectionLayer
import eu.cloudnetservice.driver.provider.CloudServiceProvider
import org.bukkit.event.Event


@Name("All Running Services")
@Description("Returns all running CloudNet services")
@Examples("loop all cloudnet services:\n" + "\tsend \"%loop-value%\"")
@Since("1.0")

class ExprAllRunningCloudnetServices : SimpleExpression<String>() {

private val cnServiceProvider: CloudServiceProvider = InjectionLayer.ext().instance(CloudServiceProvider::class.java)

companion object{
init {
Skript.registerExpression(
ExprAllRunningCloudnetServices::class.java, String::class.java,
ExpressionType.SIMPLE, "[(all [[of] the]|the)] running [cloudnet] services")
}
}

override fun isSingle(): Boolean {
return false
}

override fun init(
exprs: Array<Expression<*>?>?,
matchedPattern: Int,
isDelayed: Kleenean?,
parseResult: SkriptParser.ParseResult?
): Boolean {
return true
}

override fun get(e: Event?): Array<String?> {
return cnServiceProvider.runningServices().map { it.name() }.toTypedArray()
}

override fun getReturnType(): Class<out String> {
return String::class.java
}

override fun toString(e: Event?, debug: Boolean): String {
return "all running cloudnet services"
}

}

0 comments on commit ced809d

Please sign in to comment.