-
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.
Fixed some bugs with the Lifecycle conditions
- Loading branch information
Showing
6 changed files
with
242 additions
and
5 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
...kotlin/de/bypixeltv/skcloudnet/elements/conditions/services/CondCloudnetServiceDeleted.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,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" | ||
} | ||
|
||
} |
58 changes: 58 additions & 0 deletions
58
...otlin/de/bypixeltv/skcloudnet/elements/conditions/services/CondCloudnetServicePrepared.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,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" | ||
} | ||
|
||
} |
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
58 changes: 58 additions & 0 deletions
58
...otlin/de/bypixeltv/skcloudnet/elements/conditions/services/CondCloudnetServiceStopping.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,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" | ||
} | ||
|
||
} |
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
60 changes: 60 additions & 0 deletions
60
...n/de/bypixeltv/skcloudnet/elements/expressions/services/ExprAllRunningCloudnetServices.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,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" | ||
} | ||
|
||
} |