diff --git a/src/main/java/com/github/cao/awa/conium/Conium.kt b/src/main/java/com/github/cao/awa/conium/Conium.kt index 3a8ffc3..1ea1d63 100644 --- a/src/main/java/com/github/cao/awa/conium/Conium.kt +++ b/src/main/java/com/github/cao/awa/conium/Conium.kt @@ -30,7 +30,7 @@ class Conium : ModInitializer { val isClient: Boolean get() = ConiumClient.initialized @JvmField - var VERSION = "1.0.0-alpha5-fix1" + var VERSION = "1.0.0-alpha6" @JvmField var LANGUAGE_TRANSLATOR_VERSION: String = LanguageTranslator.getVersion() diff --git a/src/main/java/com/github/cao/awa/conium/annotation/bedrock/BedrockScriptApi.kt b/src/main/java/com/github/cao/awa/conium/annotation/bedrock/BedrockScriptApi.kt new file mode 100644 index 0000000..f8c427d --- /dev/null +++ b/src/main/java/com/github/cao/awa/conium/annotation/bedrock/BedrockScriptApi.kt @@ -0,0 +1,3 @@ +package com.github.cao.awa.conium.annotation.bedrock + +annotation class BedrockScriptApi diff --git a/src/main/java/com/github/cao/awa/conium/bedrock/BedrockScriptApiFacade.kt b/src/main/java/com/github/cao/awa/conium/annotation/bedrock/BedrockScriptApiFacade.kt similarity index 56% rename from src/main/java/com/github/cao/awa/conium/bedrock/BedrockScriptApiFacade.kt rename to src/main/java/com/github/cao/awa/conium/annotation/bedrock/BedrockScriptApiFacade.kt index ad1eab8..860447a 100644 --- a/src/main/java/com/github/cao/awa/conium/bedrock/BedrockScriptApiFacade.kt +++ b/src/main/java/com/github/cao/awa/conium/annotation/bedrock/BedrockScriptApiFacade.kt @@ -1,3 +1,3 @@ -package com.github.cao.awa.conium.bedrock +package com.github.cao.awa.conium.annotation.bedrock annotation class BedrockScriptApiFacade(vararg val sapiType: String) diff --git a/src/main/java/com/github/cao/awa/conium/bedrock/BedrockScriptApi.kt b/src/main/java/com/github/cao/awa/conium/bedrock/BedrockScriptApi.kt deleted file mode 100644 index c42d15e..0000000 --- a/src/main/java/com/github/cao/awa/conium/bedrock/BedrockScriptApi.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.github.cao.awa.conium.bedrock - -annotation class BedrockScriptApi diff --git a/src/main/java/com/github/cao/awa/conium/bedrock/event/BedrockBeforeEvents.kt b/src/main/java/com/github/cao/awa/conium/bedrock/event/BedrockBeforeEvents.kt index ac6496e..93a11f8 100644 --- a/src/main/java/com/github/cao/awa/conium/bedrock/event/BedrockBeforeEvents.kt +++ b/src/main/java/com/github/cao/awa/conium/bedrock/event/BedrockBeforeEvents.kt @@ -1,7 +1,7 @@ package com.github.cao.awa.conium.bedrock.event -import com.github.cao.awa.conium.bedrock.BedrockScriptApi -import com.github.cao.awa.conium.bedrock.BedrockScriptApiFacade +import com.github.cao.awa.conium.annotation.bedrock.BedrockScriptApi +import com.github.cao.awa.conium.annotation.bedrock.BedrockScriptApiFacade import com.github.cao.awa.conium.bedrock.event.item.use.BedrockItemUseOnBeforeEvent @BedrockScriptApi diff --git a/src/main/java/com/github/cao/awa/conium/bedrock/event/context/item/use/BedrockItemUseOnEventContext.kt b/src/main/java/com/github/cao/awa/conium/bedrock/event/context/item/use/BedrockItemUseOnEventContext.kt index bb2bfb2..2f6b8ee 100644 --- a/src/main/java/com/github/cao/awa/conium/bedrock/event/context/item/use/BedrockItemUseOnEventContext.kt +++ b/src/main/java/com/github/cao/awa/conium/bedrock/event/context/item/use/BedrockItemUseOnEventContext.kt @@ -1,7 +1,7 @@ package com.github.cao.awa.conium.bedrock.event.context.item.use -import com.github.cao.awa.conium.bedrock.BedrockScriptApi -import com.github.cao.awa.conium.bedrock.BedrockScriptApiFacade +import com.github.cao.awa.conium.annotation.bedrock.BedrockScriptApi +import com.github.cao.awa.conium.annotation.bedrock.BedrockScriptApiFacade import com.github.cao.awa.conium.bedrock.event.context.BedrockEventContext import com.github.cao.awa.conium.bedrock.item.stack.BedrockItemStack import com.github.cao.awa.conium.bedrock.item.stack.toBedrock diff --git a/src/main/java/com/github/cao/awa/conium/bedrock/event/item/use/BedrockItemUseOnBeforeEvent.kt b/src/main/java/com/github/cao/awa/conium/bedrock/event/item/use/BedrockItemUseOnBeforeEvent.kt index 61ebe51..4d8b5cf 100644 --- a/src/main/java/com/github/cao/awa/conium/bedrock/event/item/use/BedrockItemUseOnBeforeEvent.kt +++ b/src/main/java/com/github/cao/awa/conium/bedrock/event/item/use/BedrockItemUseOnBeforeEvent.kt @@ -1,7 +1,7 @@ package com.github.cao.awa.conium.bedrock.event.item.use -import com.github.cao.awa.conium.bedrock.BedrockScriptApi -import com.github.cao.awa.conium.bedrock.BedrockScriptApiFacade +import com.github.cao.awa.conium.annotation.bedrock.BedrockScriptApi +import com.github.cao.awa.conium.annotation.bedrock.BedrockScriptApiFacade import com.github.cao.awa.conium.bedrock.event.context.BedrockEventContext import com.github.cao.awa.conium.bedrock.event.context.item.use.BedrockItemUseOnEventContext import com.github.cao.awa.conium.bedrock.event.context.item.use.toBedrock diff --git a/src/main/java/com/github/cao/awa/conium/bedrock/item/stack/BedrockItemStack.kt b/src/main/java/com/github/cao/awa/conium/bedrock/item/stack/BedrockItemStack.kt index 7a95161..699bf50 100644 --- a/src/main/java/com/github/cao/awa/conium/bedrock/item/stack/BedrockItemStack.kt +++ b/src/main/java/com/github/cao/awa/conium/bedrock/item/stack/BedrockItemStack.kt @@ -1,7 +1,7 @@ package com.github.cao.awa.conium.bedrock.item.stack -import com.github.cao.awa.conium.bedrock.BedrockScriptApi -import com.github.cao.awa.conium.bedrock.BedrockScriptApiFacade +import com.github.cao.awa.conium.annotation.bedrock.BedrockScriptApi +import com.github.cao.awa.conium.annotation.bedrock.BedrockScriptApiFacade import net.minecraft.item.ItemStack import net.minecraft.registry.Registries diff --git a/src/main/java/com/github/cao/awa/conium/bedrock/script/BedrockScriptAnonymousObjectMap.kt b/src/main/java/com/github/cao/awa/conium/bedrock/script/BedrockScriptAnonymousObjectMap.kt index c27b510..e9bc5f2 100644 --- a/src/main/java/com/github/cao/awa/conium/bedrock/script/BedrockScriptAnonymousObjectMap.kt +++ b/src/main/java/com/github/cao/awa/conium/bedrock/script/BedrockScriptAnonymousObjectMap.kt @@ -1,7 +1,7 @@ package com.github.cao.awa.conium.bedrock.script -import com.github.cao.awa.conium.bedrock.BedrockScriptApi -import com.github.cao.awa.conium.bedrock.BedrockScriptApiFacade +import com.github.cao.awa.conium.annotation.bedrock.BedrockScriptApi +import com.github.cao.awa.conium.annotation.bedrock.BedrockScriptApiFacade import com.github.cao.awa.conium.parameter.DynamicArgType import com.github.cao.awa.conium.parameter.type.DynamicArgTypeBuilder.arg import com.github.cao.awa.sinuatum.util.collection.CollectionFactor diff --git a/src/main/java/com/github/cao/awa/conium/bedrock/system/AbstractBedrockSystem.kt b/src/main/java/com/github/cao/awa/conium/bedrock/system/AbstractBedrockSystem.kt index c920266..f9e37a5 100644 --- a/src/main/java/com/github/cao/awa/conium/bedrock/system/AbstractBedrockSystem.kt +++ b/src/main/java/com/github/cao/awa/conium/bedrock/system/AbstractBedrockSystem.kt @@ -1,7 +1,7 @@ package com.github.cao.awa.conium.bedrock.system import com.github.cao.awa.catheter.receptacle.IntegerReceptacle -import com.github.cao.awa.conium.bedrock.BedrockScriptApiFacade +import com.github.cao.awa.conium.annotation.bedrock.BedrockScriptApiFacade @BedrockScriptApiFacade("System") abstract class AbstractBedrockSystem { diff --git a/src/main/java/com/github/cao/awa/conium/bedrock/system/BedrockSystem.kt b/src/main/java/com/github/cao/awa/conium/bedrock/system/BedrockSystem.kt index fcd3a0f..7125ff7 100644 --- a/src/main/java/com/github/cao/awa/conium/bedrock/system/BedrockSystem.kt +++ b/src/main/java/com/github/cao/awa/conium/bedrock/system/BedrockSystem.kt @@ -1,7 +1,7 @@ package com.github.cao.awa.conium.bedrock.system import com.github.cao.awa.catheter.receptacle.IntegerReceptacle -import com.github.cao.awa.conium.bedrock.BedrockScriptApi +import com.github.cao.awa.conium.annotation.bedrock.BedrockScriptApi import com.github.cao.awa.conium.bedrock.system.task.ConiumTask import com.github.cao.awa.sinuatum.util.collection.CollectionFactor import net.minecraft.server.MinecraftServer diff --git a/src/main/java/com/github/cao/awa/conium/bedrock/world/AbstractBedrockWorld.kt b/src/main/java/com/github/cao/awa/conium/bedrock/world/AbstractBedrockWorld.kt index 70c131b..2a1974a 100644 --- a/src/main/java/com/github/cao/awa/conium/bedrock/world/AbstractBedrockWorld.kt +++ b/src/main/java/com/github/cao/awa/conium/bedrock/world/AbstractBedrockWorld.kt @@ -1,6 +1,6 @@ package com.github.cao.awa.conium.bedrock.world -import com.github.cao.awa.conium.bedrock.BedrockScriptApiFacade +import com.github.cao.awa.conium.annotation.bedrock.BedrockScriptApiFacade import com.github.cao.awa.conium.bedrock.event.BedrockBeforeEvents import com.github.cao.awa.conium.bedrock.world.player.delegate.BedrockPlayerDelegate diff --git a/src/main/java/com/github/cao/awa/conium/bedrock/world/BedrockWorld.kt b/src/main/java/com/github/cao/awa/conium/bedrock/world/BedrockWorld.kt index f11bde6..c4c6ddc 100644 --- a/src/main/java/com/github/cao/awa/conium/bedrock/world/BedrockWorld.kt +++ b/src/main/java/com/github/cao/awa/conium/bedrock/world/BedrockWorld.kt @@ -1,6 +1,6 @@ package com.github.cao.awa.conium.bedrock.world -import com.github.cao.awa.conium.bedrock.BedrockScriptApi +import com.github.cao.awa.conium.annotation.bedrock.BedrockScriptApi import com.github.cao.awa.conium.bedrock.world.player.delegate.BedrockPlayerDelegate import net.minecraft.world.World diff --git a/src/main/java/com/github/cao/awa/conium/bedrock/world/dimension/BedrockDimensionLocation.kt b/src/main/java/com/github/cao/awa/conium/bedrock/world/dimension/BedrockDimensionLocation.kt index ef86e7c..de38438 100644 --- a/src/main/java/com/github/cao/awa/conium/bedrock/world/dimension/BedrockDimensionLocation.kt +++ b/src/main/java/com/github/cao/awa/conium/bedrock/world/dimension/BedrockDimensionLocation.kt @@ -1,7 +1,7 @@ package com.github.cao.awa.conium.bedrock.world.dimension -import com.github.cao.awa.conium.bedrock.BedrockScriptApi -import com.github.cao.awa.conium.bedrock.BedrockScriptApiFacade +import com.github.cao.awa.conium.annotation.bedrock.BedrockScriptApi +import com.github.cao.awa.conium.annotation.bedrock.BedrockScriptApiFacade @BedrockScriptApi @BedrockScriptApiFacade("DimensionLocation") diff --git a/src/main/java/com/github/cao/awa/conium/bedrock/world/player/BedrockPlayer.kt b/src/main/java/com/github/cao/awa/conium/bedrock/world/player/BedrockPlayer.kt index 4a61d3e..f159ff2 100644 --- a/src/main/java/com/github/cao/awa/conium/bedrock/world/player/BedrockPlayer.kt +++ b/src/main/java/com/github/cao/awa/conium/bedrock/world/player/BedrockPlayer.kt @@ -1,7 +1,7 @@ package com.github.cao.awa.conium.bedrock.world.player -import com.github.cao.awa.conium.bedrock.BedrockScriptApi -import com.github.cao.awa.conium.bedrock.BedrockScriptApiFacade +import com.github.cao.awa.conium.annotation.bedrock.BedrockScriptApi +import com.github.cao.awa.conium.annotation.bedrock.BedrockScriptApiFacade import com.github.cao.awa.conium.bedrock.world.player.screen.BedrockOnScreenDisplay import net.minecraft.entity.player.PlayerEntity diff --git a/src/main/java/com/github/cao/awa/conium/bedrock/world/player/delegate/BedrockPlayerDelegate.kt b/src/main/java/com/github/cao/awa/conium/bedrock/world/player/delegate/BedrockPlayerDelegate.kt index e6dcf62..5df0755 100644 --- a/src/main/java/com/github/cao/awa/conium/bedrock/world/player/delegate/BedrockPlayerDelegate.kt +++ b/src/main/java/com/github/cao/awa/conium/bedrock/world/player/delegate/BedrockPlayerDelegate.kt @@ -1,7 +1,7 @@ package com.github.cao.awa.conium.bedrock.world.player.delegate -import com.github.cao.awa.conium.bedrock.BedrockScriptApi -import com.github.cao.awa.conium.bedrock.BedrockScriptApiFacade +import com.github.cao.awa.conium.annotation.bedrock.BedrockScriptApi +import com.github.cao.awa.conium.annotation.bedrock.BedrockScriptApiFacade import com.github.cao.awa.conium.bedrock.world.player.BedrockPlayer import com.github.cao.awa.conium.bedrock.world.player.toBedrock import net.minecraft.world.World diff --git a/src/main/java/com/github/cao/awa/conium/bedrock/world/player/screen/BedrockOnScreenDisplay.kt b/src/main/java/com/github/cao/awa/conium/bedrock/world/player/screen/BedrockOnScreenDisplay.kt index 9dda680..c2f55b1 100644 --- a/src/main/java/com/github/cao/awa/conium/bedrock/world/player/screen/BedrockOnScreenDisplay.kt +++ b/src/main/java/com/github/cao/awa/conium/bedrock/world/player/screen/BedrockOnScreenDisplay.kt @@ -1,7 +1,7 @@ package com.github.cao.awa.conium.bedrock.world.player.screen -import com.github.cao.awa.conium.bedrock.BedrockScriptApi -import com.github.cao.awa.conium.bedrock.BedrockScriptApiFacade +import com.github.cao.awa.conium.annotation.bedrock.BedrockScriptApi +import com.github.cao.awa.conium.annotation.bedrock.BedrockScriptApiFacade import com.github.cao.awa.conium.bedrock.script.BedrockScriptAnonymousObjectMap import com.github.cao.awa.conium.bedrock.world.player.BedrockPlayer import com.github.cao.awa.conium.bedrock.world.player.screen.title.BedrockScreenDisplayTitle diff --git a/src/main/java/com/github/cao/awa/conium/block/ConiumBlock.kt b/src/main/java/com/github/cao/awa/conium/block/ConiumBlock.kt index 5ced1fb..44fcc60 100644 --- a/src/main/java/com/github/cao/awa/conium/block/ConiumBlock.kt +++ b/src/main/java/com/github/cao/awa/conium/block/ConiumBlock.kt @@ -16,10 +16,10 @@ class ConiumBlock(private val setting: ConiumBlockSettings) : Block(setting.vani fun create(builder: ConiumBlockBuilder, settings: ConiumBlockSettings): ConiumBlock { builder.templates.forEach { it.prepare(settings) } - return ConiumBlock(settings).also { block: ConiumBlock -> - builder.templates.forEach { it.attach(block) } + return ConiumBlock(settings).apply { + builder.templates.forEach { it.attach(this) } - builder.templates.forEach { it.complete(block) } + builder.templates.forEach { it.complete(this) } } } } diff --git a/src/main/java/com/github/cao/awa/conium/block/entity/event/shulker/open/ConiumShulkerBoxOpeningEvent.kt b/src/main/java/com/github/cao/awa/conium/block/entity/event/shulker/open/ConiumShulkerBoxOpeningEvent.kt index 21a8dde..618a9f0 100644 --- a/src/main/java/com/github/cao/awa/conium/block/entity/event/shulker/open/ConiumShulkerBoxOpeningEvent.kt +++ b/src/main/java/com/github/cao/awa/conium/block/entity/event/shulker/open/ConiumShulkerBoxOpeningEvent.kt @@ -48,7 +48,7 @@ class ConiumShulkerBoxOpeningEvent : ConiumEvent if (blockEntity is ShulkerBoxBlockEntity && blockEntity.world != null && !blockEntity.isRemoved && block == blockEntity.cachedState.block) { // Request the opening shulker box context. diff --git a/src/main/java/com/github/cao/awa/conium/datapack/item/ConiumItemManager.kt b/src/main/java/com/github/cao/awa/conium/datapack/item/ConiumItemManager.kt index 541701c..d92711d 100644 --- a/src/main/java/com/github/cao/awa/conium/datapack/item/ConiumItemManager.kt +++ b/src/main/java/com/github/cao/awa/conium/datapack/item/ConiumItemManager.kt @@ -58,9 +58,7 @@ class ConiumItemManager( ) if (json["schema_style"]?.asString == "conium") { - ConiumSchemaItemBuilder.deserialize(json, this.registryLookup).register { - // TODO enchanting - } + ConiumSchemaItemBuilder.deserialize(json, this.registryLookup).register() } else { BedrockSchemaItemBuilder.deserialize(json, this.registryLookup).register() } diff --git a/src/main/java/com/github/cao/awa/conium/event/context/ConiumEventContext.kt b/src/main/java/com/github/cao/awa/conium/event/context/ConiumEventContext.kt index 29a0a08..28411e6 100644 --- a/src/main/java/com/github/cao/awa/conium/event/context/ConiumEventContext.kt +++ b/src/main/java/com/github/cao/awa/conium/event/context/ConiumEventContext.kt @@ -35,7 +35,6 @@ class ConiumEventContext

( private val args: MutableMap, Any?> = CollectionFactor.hashMap() private val attaches: MutableList> = CollectionFactor.arrayList() private val attachesDynamic: MutableList

= CollectionFactor.arrayList() - private var lastIdentity: Any? = null private var targetedIdentity: ParameterSelective1 = ParameterSelective1 { true } @@ -112,8 +111,6 @@ class ConiumEventContext

( return true } - this.lastIdentity = identity - var success: Boolean = this.presageTrigger == null || this.dynamicArgs.arising(identity, this.args, this.presageTrigger!!) for (attach: ConiumEventContext<*> in this.attaches) { if (attach.hasPresaging()) { @@ -132,8 +129,6 @@ class ConiumEventContext

( return true } - this.lastIdentity = identity - var success: Boolean = this.ariseTrigger == null || this.dynamicArgs.arising(identity, this.args, this.ariseTrigger!!) for (attach: ConiumEventContext<*> in this.attaches) { if (attach.hasArising()) { @@ -152,7 +147,6 @@ class ConiumEventContext

( } fun inherit(context: ConiumEventContext<*>): ConiumEventContext

{ - this.lastIdentity = context.lastIdentity return resetArgs(context.args) } } diff --git a/src/main/java/com/github/cao/awa/conium/event/context/ConiumEventContextBuilder.kt b/src/main/java/com/github/cao/awa/conium/event/context/ConiumEventContextBuilder.kt index f958988..370438a 100644 --- a/src/main/java/com/github/cao/awa/conium/event/context/ConiumEventContextBuilder.kt +++ b/src/main/java/com/github/cao/awa/conium/event/context/ConiumEventContextBuilder.kt @@ -3,43 +3,174 @@ package com.github.cao.awa.conium.event.context import com.github.cao.awa.conium.Conium +import com.github.cao.awa.conium.datapack.script.ConiumScriptManager import com.github.cao.awa.conium.event.ConiumEvent +import com.github.cao.awa.conium.event.type.ConiumEventArgTypes import com.github.cao.awa.conium.event.type.ConiumEventType import com.github.cao.awa.conium.parameter.* - +import com.github.cao.awa.conium.script.interaction.NamedInteractionScript + +/** + * Building the event contexts. + * + * @see ConiumEvent + * @see ConiumEventContext + * @see DynamicArgs + * @see DynamicArgType + * @see DynamicArgsBuilder + * @see ParameterSelective + * @see DynamicArgsLifecycle + * @see NamedInteractionScript + * @see ConiumScriptManager + * + * @author cao_awa + * @author 草二号机 + * + * @since 1.0.0 + */ object ConiumEventContextBuilder { + /** + * Make an event context that should only call in event [requirement][ConiumEvent.requirement]. + * + * The event context be the base context to arise attached contexts with no argument provided. + * + * @see ConiumEvent + * @see ConiumEventContext + * @see DynamicArgs + * @see ParameterSelective + * @see DynamicArgsLifecycle + * + * @return The context instance with [ONCE][DynamicArgsLifecycle.ONCE] lifecycle. + * + * @author cao_awa + * + * @since 1.0.0 + */ @JvmStatic @SuppressWarnings("UNCHECKED_CAST") - fun requires(): ConiumEventContext> { - return ConiumEventContext(DynamicArgsBuilder.force()) - } - + fun requires(): ConiumEventContext> = ConiumEventContext(DynamicArgsBuilder.force()) + + /** + * Make an event context that should only call in event [requirement][ConiumEvent.requirement]. + * + * The event context be the base context to arise attached contexts with no argument provided. + * + * @param P1 Type of first parameter + * @param arg1 First parameter will input to attached contexts + * + * @see ConiumEvent + * @see ConiumEventContext + * @see DynamicArgs + * @see DynamicArgType + * @see ParameterSelective + * @see DynamicArgsLifecycle + * + * @return The context instance with [ONCE][DynamicArgsLifecycle.ONCE] lifecycle. + * + * @author cao_awa + * @author 草二号机 + * + * @since 1.0.0 + */ @JvmStatic @SuppressWarnings("UNCHECKED_CAST") fun requires( arg1: DynamicArgType - ): ConiumEventContext> { - return ConiumEventContext(DynamicArgsBuilder.requires(arg1, true)) - } - + ): ConiumEventContext> = ConiumEventContext(DynamicArgsBuilder.requires(arg1, true)) + + /** + * Make an event context that should only call in event [requirement][ConiumEvent.requirement]. + * + * The event context be the base context to arise attached contexts with no argument provided. + * + * @param P1 Type of first parameter + * @param arg1 First parameter will input to attached contexts + * @param P2 Type of second parameter + * @param arg2 Second parameter will input to attached contexts + * + * @see ConiumEvent + * @see ConiumEventContext + * @see DynamicArgs + * @see DynamicArgType + * @see ParameterSelective + * @see DynamicArgsLifecycle + * + * @return The context instance with [ONCE][DynamicArgsLifecycle.ONCE] lifecycle. + * + * @author cao_awa + * @author 草二号机 + * + * @since 1.0.0 + */ @JvmStatic @SuppressWarnings("UNCHECKED_CAST") fun requires( arg1: DynamicArgType, arg2: DynamicArgType - ): ConiumEventContext> { - return ConiumEventContext(DynamicArgsBuilder.requires(arg1, arg2, true)) - } - + ): ConiumEventContext> = ConiumEventContext(DynamicArgsBuilder.requires(arg1, arg2, true)) + + /** + * Make an event context that should only call in event [requirement][ConiumEvent.requirement]. + * + * The event context be the base context to arise attached contexts with no argument provided. + * + * @param P1 Type of first parameter + * @param arg1 First parameter will input to attached contexts + * @param P2 Type of second parameter + * @param arg2 Second parameter will input to attached contexts + * @param P3 Type of third parameter + * @param arg3 Third parameter will input to attached contexts + * + * @see ConiumEvent + * @see ConiumEventContext + * @see DynamicArgs + * @see DynamicArgType + * @see ParameterSelective + * @see DynamicArgsLifecycle + * + * @return The context instance with [ONCE][DynamicArgsLifecycle.ONCE] lifecycle. + * + * @author cao_awa + * @author 草二号机 + * + * @since 1.0.0 + */ + @JvmStatic @SuppressWarnings("UNCHECKED_CAST") fun requires( arg1: DynamicArgType, arg2: DynamicArgType, arg3: DynamicArgType - ): ConiumEventContext> { - return ConiumEventContext(DynamicArgsBuilder.requires(arg1, arg2, arg3, true)) - } - + ): ConiumEventContext> = ConiumEventContext(DynamicArgsBuilder.requires(arg1, arg2, arg3, true)) + + /** + * Make an event context that should only call in event [requirement][ConiumEvent.requirement]. + * + * The event context be the base context to arise attached contexts with no argument provided. + * + * @param P1 Type of first parameter + * @param arg1 First parameter will input to attached contexts + * @param P2 Type of second parameter + * @param arg2 Second parameter will input to attached contexts + * @param P3 Type of third parameter + * @param arg3 Third parameter will input to attached contexts + * @param P4 Type of fourth parameter + * @param arg4 Fourth parameter will input to attached contexts + * + * @see ConiumEvent + * @see ConiumEventContext + * @see DynamicArgs + * @see DynamicArgType + * @see ParameterSelective + * @see DynamicArgsLifecycle + * + * @return The context instance with [ONCE][DynamicArgsLifecycle.ONCE] lifecycle. + * + * @author cao_awa + * @author 草二号机 + * + * @since 1.0.0 + */ @JvmStatic @SuppressWarnings("UNCHECKED_CAST") fun requires( @@ -47,10 +178,38 @@ object ConiumEventContextBuilder { arg2: DynamicArgType, arg3: DynamicArgType, arg4: DynamicArgType - ): ConiumEventContext> { - return ConiumEventContext(DynamicArgsBuilder.requires(arg1, arg2, arg3, arg4, true)) - } - + ): ConiumEventContext> = ConiumEventContext(DynamicArgsBuilder.requires(arg1, arg2, arg3, arg4, true)) + + /** + * Make an event context that should only call in event [requirement][ConiumEvent.requirement]. + * + * The event context be the base context to arise attached contexts with no argument provided. + * + * @param P1 Type of first parameter + * @param arg1 First parameter will input to attached contexts + * @param P2 Type of second parameter + * @param arg2 Second parameter will input to attached contexts + * @param P3 Type of third parameter + * @param arg3 Third parameter will input to attached contexts + * @param P4 Type of fourth parameter + * @param arg4 Fourth parameter will input to attached contexts + * @param P5 Type of fifth parameter + * @param arg5 Fifth parameter will input to attached contexts + * + * @see ConiumEvent + * @see ConiumEventContext + * @see DynamicArgs + * @see DynamicArgType + * @see ParameterSelective + * @see DynamicArgsLifecycle + * + * @return The context instance with [ONCE][DynamicArgsLifecycle.ONCE] lifecycle. + * + * @author cao_awa + * @author 草二号机 + * + * @since 1.0.0 + */ @JvmStatic @SuppressWarnings("UNCHECKED_CAST") fun requires( @@ -59,10 +218,40 @@ object ConiumEventContextBuilder { arg3: DynamicArgType, arg4: DynamicArgType, arg5: DynamicArgType - ): ConiumEventContext> { - return ConiumEventContext(DynamicArgsBuilder.requires(arg1, arg2, arg3, arg4, arg5, true)) - } - + ): ConiumEventContext> = ConiumEventContext(DynamicArgsBuilder.requires(arg1, arg2, arg3, arg4, arg5, true)) + + /** + * Make an event context that should only call in event [requirement][ConiumEvent.requirement]. + * + * The event context be the base context to arise attached contexts with no argument provided. + * + * @param P1 Type of first parameter + * @param arg1 First parameter will input to attached contexts + * @param P2 Type of second parameter + * @param arg2 Second parameter will input to attached contexts + * @param P3 Type of third parameter + * @param arg3 Third parameter will input to attached contexts + * @param P4 Type of fourth parameter + * @param arg4 Fourth parameter will input to attached contexts + * @param P5 Type of fifth parameter + * @param arg5 Fifth parameter will input to attached contexts + * @param P6 Type of sixth parameter + * @param arg6 Sixth parameter will input to attached contexts + * + * @see ConiumEvent + * @see ConiumEventContext + * @see DynamicArgs + * @see DynamicArgType + * @see ParameterSelective + * @see DynamicArgsLifecycle + * + * @return The context instance with [ONCE][DynamicArgsLifecycle.ONCE] lifecycle. + * + * @author cao_awa + * @author 草二号机 + * + * @since 1.0.0 + */ @JvmStatic @SuppressWarnings("UNCHECKED_CAST") fun requires( @@ -72,10 +261,42 @@ object ConiumEventContextBuilder { arg4: DynamicArgType, arg5: DynamicArgType, arg6: DynamicArgType - ): ConiumEventContext> { - return ConiumEventContext(DynamicArgsBuilder.requires(arg1, arg2, arg3, arg4, arg5, arg6, true)) - } - + ): ConiumEventContext> = ConiumEventContext(DynamicArgsBuilder.requires(arg1, arg2, arg3, arg4, arg5, arg6, true)) + + /** + * Make an event context that should only call in event [requirement][ConiumEvent.requirement]. + * + * The event context be the base context to arise attached contexts with no argument provided. + * + * @param P1 Type of first parameter + * @param arg1 First parameter will input to attached contexts + * @param P2 Type of second parameter + * @param arg2 Second parameter will input to attached contexts + * @param P3 Type of third parameter + * @param arg3 Third parameter will input to attached contexts + * @param P4 Type of fourth parameter + * @param arg4 Fourth parameter will input to attached contexts + * @param P5 Type of fifth parameter + * @param arg5 Fifth parameter will input to attached contexts + * @param P6 Type of sixth parameter + * @param arg6 Sixth parameter will input to attached contexts + * @param P6 Type of seventh parameter + * @param arg6 Seventh parameter will input to attached contexts + * + * @see ConiumEvent + * @see ConiumEventContext + * @see DynamicArgs + * @see DynamicArgType + * @see ParameterSelective + * @see DynamicArgsLifecycle + * + * @return The context instance with [ONCE][DynamicArgsLifecycle.ONCE] lifecycle. + * + * @author cao_awa + * @author 草二号机 + * + * @since 1.0.0 + */ @JvmStatic @SuppressWarnings("UNCHECKED_CAST") fun requires( @@ -86,48 +307,118 @@ object ConiumEventContextBuilder { arg5: DynamicArgType, arg6: DynamicArgType, arg7: DynamicArgType - ): ConiumEventContext> { - return ConiumEventContext(DynamicArgsBuilder.requires(arg1, arg2, arg3, arg4, arg5, arg6, arg7, true)) + ): ConiumEventContext> = ConiumEventContext(DynamicArgsBuilder.requires(arg1, arg2, arg3, arg4, arg5, arg6, arg7, true)) + + private fun

forever(eventType: ConiumEventType, dynamicArgs: DynamicArgs): ConiumEventContext

{ + return ConiumEventContext(dynamicArgs).apply { + // Attach this context to event. + ConiumEvent.forever(eventType, this) + } } + /** + * Make a sub context of specified event type that only trigger presaging in the context with no arguments, then auto attach to forever lifecycle of the event type. + * + * The context will arise when event base context arising and invalidate when reload events. + * + * @param I The specified input identity instance, see reified type of [ConiumEventType][ConiumEventType] + * @param eventType The event type that will be attaching + * @param presaging The presaging trigger, default is always successes + * + * @see ConiumEvent + * @see ConiumEventContext + * @see DynamicArgs + * @see DynamicArgType + * @see ParameterSelective + * @see DynamicArgsLifecycle + * + * @return The context instance with [FOREVER][DynamicArgsLifecycle.FOREVER] lifecycle. + * + * @author cao_awa + * + * @since 1.0.0 + */ @JvmStatic @SuppressWarnings("UNCHECKED_CAST") fun preRequest( eventType: ConiumEventType, presaging: ParameterSelective1 = ParameterSelective1 { _ -> true } ): ConiumEventContext> { - val context = ConiumEventContext( + return forever( + eventType, + // Require a no argument dynamic args and contract to forever lifecycle. DynamicArgsBuilder.requires(true).lifecycle(DynamicArgsLifecycle.FOREVER) - ) - - ConiumEvent.forever(eventType, context) - - context.presage { - (it as? I)?.let(presaging::arise) ?: true + ).apply { + // Attach presage trigger, this is event cancelable when parameter selective returns false. + presage { + (it as? I)?.let(presaging::arise) ?: true + } } - - return context } + /** + * Make a sub context of specified event type that only trigger arising in the context with no arguments, then auto attach to forever lifecycle of the event type. + * + * The context will arise when event base context arising and invalidate when reload events. + * + * @param I The specified input identity instance, see reified type of [ConiumEventType][ConiumEventType] + * @param eventType The event type that will be attaching + * @param arising The arising trigger, default is always successes + * + * @see ConiumEvent + * @see ConiumEventContext + * @see DynamicArgs + * @see DynamicArgType + * @see ParameterSelective + * @see DynamicArgsLifecycle + * + * @return The context instance with [FOREVER][DynamicArgsLifecycle.FOREVER] lifecycle. + * + * @author cao_awa + * + * @since 1.0.0 + */ @JvmStatic @SuppressWarnings("UNCHECKED_CAST") fun request( eventType: ConiumEventType, arising: ParameterSelective1 = ParameterSelective1 { _ -> true } ): ConiumEventContext> { - val context = ConiumEventContext( + return forever( + eventType, + // Require a no argument dynamic args and contract to forever lifecycle. DynamicArgsBuilder.requires(true).lifecycle(DynamicArgsLifecycle.FOREVER) - ) - - ConiumEvent.forever(eventType, context) - - context.arise { - (it as? I)?.let(arising::arise) ?: true + ).apply { + // Attach arise trigger, not event cancelable. + arise { + (it as? I)?.let(arising::arise) ?: true + } } - - return context } + /** + * Make a sub context of specified event type with no arguments, then auto attach to forever lifecycle of the event type. + * + * The context will arise when event base context arising and invalidate when reload events. + * + * @param I The specified input identity instance, see reified type of [ConiumEventType][ConiumEventType] + * @param eventType The event type that will be attaching + * @param arising The arising trigger, default is always successes + * @param presaging The presaging trigger, default is always successes + * + * @see ConiumEvent + * @see ConiumEventContext + * @see DynamicArgs + * @see DynamicArgType + * @see ParameterSelective + * @see DynamicArgsLifecycle + * + * @return The context instance with [FOREVER][DynamicArgsLifecycle.FOREVER] lifecycle. + * + * @author cao_awa + * + * @since 1.0.0 + */ @JvmStatic @SuppressWarnings("UNCHECKED_CAST") fun request( @@ -135,23 +426,48 @@ object ConiumEventContextBuilder { arising: ParameterSelective1 = ParameterSelective1 { _ -> true }, presaging: ParameterSelective1 = ParameterSelective1 { _ -> true }, ): ConiumEventContext> { - val context = ConiumEventContext( + return forever( + eventType, + // Require a no argument dynamic args and contract to forever lifecycle. DynamicArgsBuilder.requires(true).lifecycle(DynamicArgsLifecycle.FOREVER) - ) - - ConiumEvent.forever(eventType, context) - - context.arise { - (it as? I)?.let(arising::arise) ?: true + ).apply { + // Attach presage trigger, this is event cancelable when parameter selective returns false. + presage { + (it as? I)?.let(presaging::arise) ?: true + } + + // Attach arise trigger, not event cancelable. + arise { + (it as? I)?.let(arising::arise) ?: true + } } - - context.presage { - (it as? I)?.let(presaging::arise) ?: true - } - - return context } + /** + * Make a sub context of specified event type that only trigger presaging in the context with one argument, then auto attach to forever lifecycle of the event type. + * + * The context will arise when event base context arising and invalidate when reload events. + * + * @param I The specified input identity instance, see reified type of [ConiumEventType][ConiumEventType] + * @param P1 Type of first parameter + * @param arg1 The first parameter that will be input to the parameter selective instance + * @param eventType The event type that will be attaching + * @param presaging The presaging trigger, default is always successes + * + * @see ConiumEvent + * @see ConiumEventContext + * @see DynamicArgs + * @see DynamicArgType + * @see ConiumEventArgTypes + * @see ParameterSelective + * @see DynamicArgsLifecycle + * + * @return The context instance with [FOREVER][DynamicArgsLifecycle.FOREVER] lifecycle. + * + * @author cao_awa + * + * @since 1.0.0 + */ @JvmStatic @SuppressWarnings("UNCHECKED_CAST") fun preRequest( @@ -159,22 +475,46 @@ object ConiumEventContextBuilder { arg1: DynamicArgType, presaging: ParameterSelective2 = ParameterSelective2 { _, _ -> true } ): ConiumEventContext> { - val context = ConiumEventContext( + return forever( + eventType, + // Require a one argument dynamic args and contract to forever lifecycle. DynamicArgsBuilder.requires( arg1, true ).lifecycle(DynamicArgsLifecycle.FOREVER) - ) - - ConiumEvent.forever(eventType, context) - - context.presage { i, p1 -> - (i as? I)?.let { presaging(it, p1) } ?: true + ).apply { + // Attach presage trigger, this is event cancelable when parameter selective returns false. + presage { i: Any, p1: P1 -> + (i as? I)?.let { presaging(it, p1) } ?: true + } } - - return context } + /** + * Make a sub context of specified event type that only trigger arising in the context with one argument, then auto attach to forever lifecycle of the event type. + * + * The context will arise when event base context arising and invalidate when reload events. + * + * @param I The specified input identity instance, see reified type of [ConiumEventType][ConiumEventType] + * @param P1 Type of first parameter + * @param arg1 The first parameter that will be input to the parameter selective instance + * @param eventType The event type that will be attaching + * @param arising The arising trigger, default is always successes + * + * @see ConiumEvent + * @see ConiumEventContext + * @see DynamicArgs + * @see DynamicArgType + * @see ConiumEventArgTypes + * @see ParameterSelective + * @see DynamicArgsLifecycle + * + * @return The context instance with [FOREVER][DynamicArgsLifecycle.FOREVER] lifecycle. + * + * @author cao_awa + * + * @since 1.0.0 + */ @JvmStatic @SuppressWarnings("UNCHECKED_CAST") fun request( @@ -182,22 +522,47 @@ object ConiumEventContextBuilder { arg1: DynamicArgType, arising: ParameterSelective2 = ParameterSelective2 { _, _ -> true } ): ConiumEventContext> { - val context = ConiumEventContext( + return forever( + eventType, + // Require a one argument dynamic args and contract to forever lifecycle. DynamicArgsBuilder.requires( arg1, true ).lifecycle(DynamicArgsLifecycle.FOREVER) - ) - - ConiumEvent.forever(eventType, context) - - context.arise { i, p1 -> - (i as? I)?.let { arising(it, p1) } ?: true + ).apply { + // Attach arise trigger, not event cancelable. + arise { i: Any, p1: P1 -> + (i as? I)?.let { arising(it, p1) } ?: true + } } - - return context } + /** + * Make a sub context of specified event type with one argument, then auto attach to forever lifecycle of the event type. + * + * The context will arise when event base context arising and invalidate when reload events. + * + * @param I The specified input identity instance, see reified type of [ConiumEventType][ConiumEventType] + * @param P1 Type of first parameter + * @param arg1 The first parameter that will be input to the parameter selective instance + * @param eventType The event type that will be attaching + * @param arising The arising trigger, default is always successes + * @param presaging The presaging trigger, default is always successes + * + * @see ConiumEvent + * @see ConiumEventContext + * @see DynamicArgs + * @see DynamicArgType + * @see ConiumEventArgTypes + * @see ParameterSelective + * @see DynamicArgsLifecycle + * + * @return The context instance with [FOREVER][DynamicArgsLifecycle.FOREVER] lifecycle. + * + * @author cao_awa + * + * @since 1.0.0 + */ @JvmStatic @SuppressWarnings("UNCHECKED_CAST") fun request( @@ -206,26 +571,53 @@ object ConiumEventContextBuilder { arising: ParameterSelective2 = ParameterSelective2 { _, _ -> true }, presaging: ParameterSelective2 = ParameterSelective2 { _, _ -> true } ): ConiumEventContext> { - val context = ConiumEventContext( + return forever( + eventType, + // Require a one argument dynamic args and contract to forever lifecycle. DynamicArgsBuilder.requires( arg1, true ).lifecycle(DynamicArgsLifecycle.FOREVER) - ) - - ConiumEvent.forever(eventType, context) - - context.arise { i, p1 -> - (i as? I)?.let { arising(it, p1) } ?: true - } - - context.presage { i, p1 -> - (i as? I)?.let { presaging(it, p1) } ?: true + ).apply { + // Attach presage trigger, this is event cancelable when parameter selective returns false. + presage { i: Any, p1: P1 -> + (i as? I)?.let { presaging(it, p1) } ?: true + } + + // Attach arise trigger, not event cancelable. + arise { i: Any, p1: P1 -> + (i as? I)?.let { arising(it, p1) } ?: true + } } - - return context } + /** + * Make a sub context of specified event type that only trigger presaging in the context with two arguments, then auto attach to forever lifecycle of the event type. + * + * The context will arise when event base context arising and invalidate when reload events. + * + * @param I The specified input identity instance, see reified type of [ConiumEventType][ConiumEventType] + * @param P1 Type of first parameter + * @param arg1 The first parameter that will be input to the parameter selective instance + * @param P2 Type of second parameter + * @param arg2 The second parameter that will be input to the parameter selective instance + * @param eventType The event type that will be attaching + * @param presaging The presaging trigger, default is always successes + * + * @see ConiumEvent + * @see ConiumEventContext + * @see DynamicArgs + * @see DynamicArgType + * @see ConiumEventArgTypes + * @see ParameterSelective + * @see DynamicArgsLifecycle + * + * @return The context instance with [FOREVER][DynamicArgsLifecycle.FOREVER] lifecycle. + * + * @author cao_awa + * + * @since 1.0.0 + */ @JvmStatic @SuppressWarnings("UNCHECKED_CAST") fun preRequest( @@ -234,23 +626,49 @@ object ConiumEventContextBuilder { arg2: DynamicArgType, presaging: ParameterSelective3 = ParameterSelective3 { _, _, _ -> true } ): ConiumEventContext> { - val context = ConiumEventContext( + return forever( + eventType, + // Require a two argument dynamic args and contract to forever lifecycle. DynamicArgsBuilder.requires( arg1, arg2, true ).lifecycle(DynamicArgsLifecycle.FOREVER) - ) - - ConiumEvent.forever(eventType, context) - - context.presage { i, p1, p2 -> - (i as? I)?.let { presaging(it, p1, p2) } ?: true + ).apply { + // Attach presage trigger, this is event cancelable when parameter selective returns false. + presage { i: Any, p1: P1, p2: P2 -> + (i as? I)?.let { presaging(it, p1, p2) } ?: true + } } - - return context } + /** + * Make a sub context of specified event type that only trigger arising in the context with two arguments, then auto attach to forever lifecycle of the event type. + * + * The context will arise when event base context arising and invalidate when reload events. + * + * @param I The specified input identity instance, see reified type of [ConiumEventType][ConiumEventType] + * @param P1 Type of first parameter + * @param arg1 The first parameter that will be input to the parameter selective instance + * @param P2 Type of second parameter + * @param arg2 The second parameter that will be input to the parameter selective instance + * @param eventType The event type that will be attaching + * @param arising The arising trigger, default is always successes + * + * @see ConiumEvent + * @see ConiumEventContext + * @see DynamicArgs + * @see DynamicArgType + * @see ConiumEventArgTypes + * @see ParameterSelective + * @see DynamicArgsLifecycle + * + * @return The context instance with [FOREVER][DynamicArgsLifecycle.FOREVER] lifecycle. + * + * @author cao_awa + * + * @since 1.0.0 + */ @JvmStatic @SuppressWarnings("UNCHECKED_CAST") fun request( @@ -259,23 +677,50 @@ object ConiumEventContextBuilder { arg2: DynamicArgType, arising: ParameterSelective3 = ParameterSelective3 { _, _, _ -> true } ): ConiumEventContext> { - val context = ConiumEventContext( + return forever( + eventType, + // Require a two argument dynamic args and contract to forever lifecycle. DynamicArgsBuilder.requires( arg1, arg2, true ).lifecycle(DynamicArgsLifecycle.FOREVER) - ) - - ConiumEvent.forever(eventType, context) - - context.arise { i, p1, p2 -> - (i as? I)?.let { arising(it, p1, p2) } ?: true + ).apply { + // Attach arise trigger, not event cancelable. + arise { i: Any, p1: P1, p2: P2 -> + (i as? I)?.let { arising(it, p1, p2) } ?: true + } } - - return context } + /** + * Make a sub context of specified event type with two arguments, then auto attach to forever lifecycle of the event type. + * + * The context will arise when event base context arising and invalidate when reload events. + * + * @param I The specified input identity instance, see reified type of [ConiumEventType][ConiumEventType] + * @param P1 Type of first parameter + * @param arg1 The first parameter that will be input to the parameter selective instance + * @param P2 Type of second parameter + * @param arg2 The second parameter that will be input to the parameter selective instance + * @param eventType The event type that will be attaching + * @param arising The arising trigger, default is always successes + * @param presaging The presaging trigger, default is always successes + * + * @see ConiumEvent + * @see ConiumEventContext + * @see DynamicArgs + * @see DynamicArgType + * @see ConiumEventArgTypes + * @see ParameterSelective + * @see DynamicArgsLifecycle + * + * @return The context instance with [FOREVER][DynamicArgsLifecycle.FOREVER] lifecycle. + * + * @author cao_awa + * + * @since 1.0.0 + */ @JvmStatic @SuppressWarnings("UNCHECKED_CAST") fun request( @@ -285,27 +730,56 @@ object ConiumEventContextBuilder { arising: ParameterSelective3 = ParameterSelective3 { _, _, _ -> true }, presaging: ParameterSelective3 = ParameterSelective3 { _, _, _ -> true }, ): ConiumEventContext> { - val context = ConiumEventContext( + return forever( + eventType, + // Require a two argument dynamic args and contract to forever lifecycle. DynamicArgsBuilder.requires( arg1, arg2, true ).lifecycle(DynamicArgsLifecycle.FOREVER) - ) - - ConiumEvent.forever(eventType, context) - - context.arise { i, p1, p2 -> - (i as? I)?.let { arising(it, p1, p2) } ?: true + ).apply { + // Attach presage trigger, this is event cancelable when parameter selective returns false. + presage { i: Any, p1: P1, p2: P2 -> + (i as? I)?.let { presaging(it, p1, p2) } ?: true + } + + // Attach arise trigger, not event cancelable. + arise { i: Any, p1: P1, p2: P2 -> + (i as? I)?.let { arising(it, p1, p2) } ?: true + } } - - context.presage { i, p1, p2 -> - (i as? I)?.let { presaging(it, p1, p2) } ?: true - } - - return context } + /** + * Make a sub context of specified event type that only trigger presaging in the context with three arguments, then auto attach to forever lifecycle of the event type. + * + * The context will arise when event base context arising and invalidate when reload events. + * + * @param I The specified input identity instance, see reified type of [ConiumEventType][ConiumEventType] + * @param P1 Type of first parameter + * @param arg1 The first parameter that will be input to the parameter selective instance + * @param P2 Type of second parameter + * @param arg2 The second parameter that will be input to the parameter selective instance + * @param P3 Type of third parameter + * @param arg3 The third parameter that will be input to the parameter selective instance + * @param eventType The event type that will be attaching + * @param presaging The presaging trigger, default is always successes + * + * @see ConiumEvent + * @see ConiumEventContext + * @see DynamicArgs + * @see DynamicArgType + * @see ConiumEventArgTypes + * @see ParameterSelective + * @see DynamicArgsLifecycle + * + * @return The context instance with [FOREVER][DynamicArgsLifecycle.FOREVER] lifecycle. + * + * @author cao_awa + * + * @since 1.0.0 + */ @JvmStatic @SuppressWarnings("UNCHECKED_CAST") fun preRequest( @@ -315,24 +789,52 @@ object ConiumEventContextBuilder { arg3: DynamicArgType, presaging: ParameterSelective4 = ParameterSelective4 { _, _, _, _ -> true } ): ConiumEventContext> { - val context = ConiumEventContext( + return forever( + eventType, + // Require a three argument dynamic args and contract to forever lifecycle. DynamicArgsBuilder.requires( arg1, arg2, arg3, true ).lifecycle(DynamicArgsLifecycle.FOREVER) - ) - - ConiumEvent.forever(eventType, context) - - context.presage { i, p1, p2, p3 -> - (i as? I)?.let { presaging(it, p1, p2, p3) } ?: true + ).apply { + // Attach presage trigger, this is event cancelable when parameter selective returns false. + presage { i: Any, p1: P1, p2: P2, p3: P3 -> + (i as? I)?.let { presaging(it, p1, p2, p3) } ?: true + } } - - return context } + /** + * Make a sub context of specified event type that only trigger arising in the context with three arguments, then auto attach to forever lifecycle of the event type. + * + * The context will arise when event base context arising and invalidate when reload events. + * + * @param I The specified input identity instance, see reified type of [ConiumEventType][ConiumEventType] + * @param P1 Type of first parameter + * @param arg1 The first parameter that will be input to the parameter selective instance + * @param P2 Type of second parameter + * @param arg2 The second parameter that will be input to the parameter selective instance + * @param P3 Type of third parameter + * @param arg3 The third parameter that will be input to the parameter selective instance + * @param eventType The event type that will be attaching + * @param arising The arising trigger, default is always successes + * + * @see ConiumEvent + * @see ConiumEventContext + * @see DynamicArgs + * @see DynamicArgType + * @see ConiumEventArgTypes + * @see ParameterSelective + * @see DynamicArgsLifecycle + * + * @return The context instance with [FOREVER][DynamicArgsLifecycle.FOREVER] lifecycle. + * + * @author cao_awa + * + * @since 1.0.0 + */ @JvmStatic @SuppressWarnings("UNCHECKED_CAST") fun request( @@ -342,24 +844,53 @@ object ConiumEventContextBuilder { arg3: DynamicArgType, arising: ParameterSelective4 = ParameterSelective4 { _, _, _, _ -> true } ): ConiumEventContext> { - val context = ConiumEventContext( + return forever( + eventType, + // Require a three argument dynamic args and contract to forever lifecycle. DynamicArgsBuilder.requires( arg1, arg2, arg3, true ).lifecycle(DynamicArgsLifecycle.FOREVER) - ) - - ConiumEvent.forever(eventType, context) - - context.arise { i, p1, p2, p3 -> - (i as? I)?.let { arising(it, p1, p2, p3) } ?: true + ).apply { + // Attach arise trigger, not event cancelable. + arise { i, p1, p2, p3 -> + (i as? I)?.let { arising(it, p1, p2, p3) } ?: true + } } - - return context } + /** + * Make a sub context of specified event type with three arguments, then auto attach to forever lifecycle of the event type. + * + * The context will arise when event base context arising and invalidate when reload events. + * + * @param I The specified input identity instance, see reified type of [ConiumEventType][ConiumEventType] + * @param P1 Type of first parameter + * @param arg1 The first parameter that will be input to the parameter selective instance + * @param P2 Type of second parameter + * @param arg2 The second parameter that will be input to the parameter selective instance + * @param P3 Type of third parameter + * @param arg3 The third parameter that will be input to the parameter selective instance + * @param eventType The event type that will be attaching + * @param arising The arising trigger, default is always successes + * @param presaging The presaging trigger, default is always successes + * + * @see ConiumEvent + * @see ConiumEventContext + * @see DynamicArgs + * @see DynamicArgType + * @see ConiumEventArgTypes + * @see ParameterSelective + * @see DynamicArgsLifecycle + * + * @return The context instance with [FOREVER][DynamicArgsLifecycle.FOREVER] lifecycle. + * + * @author cao_awa + * + * @since 1.0.0 + */ @JvmStatic @SuppressWarnings("UNCHECKED_CAST") fun request( @@ -370,28 +901,59 @@ object ConiumEventContextBuilder { arising: ParameterSelective4 = ParameterSelective4 { _, _, _, _ -> true }, presaging: ParameterSelective4 = ParameterSelective4 { _, _, _, _ -> true } ): ConiumEventContext> { - val context = ConiumEventContext( + return forever( + eventType, + // Require a three argument dynamic args and contract to forever lifecycle. DynamicArgsBuilder.requires( arg1, arg2, arg3, true ).lifecycle(DynamicArgsLifecycle.FOREVER) - ) - - ConiumEvent.forever(eventType, context) - - context.arise { i, p1, p2, p3 -> - (i as? I)?.let { arising(it, p1, p2, p3) } ?: true - } - - context.presage { i, p1, p2, p3 -> - (i as? I)?.let { presaging(it, p1, p2, p3) } ?: true + ).apply { + // Attach presage trigger, this is event cancelable when parameter selective returns false. + presage { i: Any, p1: P1, p2: P2, p3: P3 -> + (i as? I)?.let { presaging(it, p1, p2, p3) } ?: true + } + + // Attach arise trigger, not event cancelable. + arise { i: Any, p1: P1, p2: P2, p3: P3 -> + (i as? I)?.let { arising(it, p1, p2, p3) } ?: true + } } - - return context } + /** + * Make a sub context of specified event type that only trigger presaging in the context with four arguments, then auto attach to forever lifecycle of the event type. + * + * The context will arise when event base context arising and invalidate when reload events. + * + * @param I The specified input identity instance, see reified type of [ConiumEventType][ConiumEventType] + * @param P1 Type of first parameter + * @param arg1 The first parameter that will be input to the parameter selective instance + * @param P2 Type of second parameter + * @param arg2 The second parameter that will be input to the parameter selective instance + * @param P3 Type of third parameter + * @param arg3 The fourth parameter that will be input to the parameter selective instance + * @param P4 Type of fourth parameter + * @param arg4 The third parameter that will be input to the parameter selective instance + * @param eventType The event type that will be attaching + * @param presaging The presaging trigger, default is always successes + * + * @see ConiumEvent + * @see ConiumEventContext + * @see DynamicArgs + * @see DynamicArgType + * @see ConiumEventArgTypes + * @see ParameterSelective + * @see DynamicArgsLifecycle + * + * @return The context instance with [FOREVER][DynamicArgsLifecycle.FOREVER] lifecycle. + * + * @author cao_awa + * + * @since 1.0.0 + */ @JvmStatic @SuppressWarnings("UNCHECKED_CAST") fun preRequest( @@ -402,7 +964,9 @@ object ConiumEventContextBuilder { arg4: DynamicArgType, presaging: ParameterSelective5 = ParameterSelective5 { _, _, _, _, _ -> true } ): ConiumEventContext> { - val context = ConiumEventContext( + return forever( + eventType, + // Require a four argument dynamic args and contract to forever lifecycle. DynamicArgsBuilder.requires( arg1, arg2, @@ -410,18 +974,45 @@ object ConiumEventContextBuilder { arg4, true ).lifecycle(DynamicArgsLifecycle.FOREVER) - ) - - ConiumEvent.forever(eventType, context) - - context.presage { i, p1, p2, p3, p4 -> - (i as? I)?.let { presaging(it, p1, p2, p3, p4) } ?: true + ).apply { + // Attach presage trigger, this is event cancelable when parameter selective returns false. + presage { i: Any, p1: P1, p2: P2, p3: P3, p4: P4 -> + (i as? I)?.let { presaging(it, p1, p2, p3, p4) } ?: true + } } - - return context } - + /** + * Make a sub context of specified event type that only trigger arising in the context with four arguments, then auto attach to forever lifecycle of the event type. + * + * The context will arise when event base context arising and invalidate when reload events. + * + * @param I The specified input identity instance, see reified type of [ConiumEventType][ConiumEventType] + * @param P1 Type of first parameter + * @param arg1 The first parameter that will be input to the parameter selective instance + * @param P2 Type of second parameter + * @param arg2 The second parameter that will be input to the parameter selective instance + * @param P3 Type of third parameter + * @param arg3 The third parameter that will be input to the parameter selective instance + * @param P4 Type of fourth parameter + * @param arg4 The fourth parameter that will be input to the parameter selective instance + * @param eventType The event type that will be attaching + * @param arising The arising trigger, default is always successes + * + * @see ConiumEvent + * @see ConiumEventContext + * @see DynamicArgs + * @see DynamicArgType + * @see ConiumEventArgTypes + * @see ParameterSelective + * @see DynamicArgsLifecycle + * + * @return The context instance with [FOREVER][DynamicArgsLifecycle.FOREVER] lifecycle. + * + * @author cao_awa + * + * @since 1.0.0 + */ @JvmStatic @SuppressWarnings("UNCHECKED_CAST") fun request( @@ -432,7 +1023,9 @@ object ConiumEventContextBuilder { arg4: DynamicArgType, arising: ParameterSelective5 = ParameterSelective5 { _, _, _, _, _ -> true } ): ConiumEventContext> { - val context = ConiumEventContext( + return forever( + eventType, + // Require a four argument dynamic args and contract to forever lifecycle. DynamicArgsBuilder.requires( arg1, arg2, @@ -440,17 +1033,46 @@ object ConiumEventContextBuilder { arg4, true ).lifecycle(DynamicArgsLifecycle.FOREVER) - ) - - ConiumEvent.forever(eventType, context) - - context.arise { i, p1, p2, p3, p4 -> - (i as? I)?.let { arising(it, p1, p2, p3, p4) } ?: true + ).apply { + // Attach arise trigger, not event cancelable. + arise { i: Any, p1: P1, p2: P2, p3: P3, p4: P4 -> + (i as? I)?.let { arising(it, p1, p2, p3, p4) } ?: true + } } - - return context } + /** + * Make a sub context of specified event type with four arguments, then auto attach to forever lifecycle of the event type. + * + * The context will arise when event base context arising and invalidate when reload events. + * + * @param I The specified input identity instance, see reified type of [ConiumEventType][ConiumEventType] + * @param P1 Type of first parameter + * @param arg1 The first parameter that will be input to the parameter selective instance + * @param P2 Type of second parameter + * @param arg2 The second parameter that will be input to the parameter selective instance + * @param P3 Type of third parameter + * @param arg3 The third parameter that will be input to the parameter selective instance + * @param P4 Type of fourth parameter + * @param arg4 The fourth parameter that will be input to the parameter selective instance + * @param eventType The event type that will be attaching + * @param arising The arising trigger, default is always successes + * @param presaging The presaging trigger, default is always successes + * + * @see ConiumEvent + * @see ConiumEventContext + * @see DynamicArgs + * @see DynamicArgType + * @see ConiumEventArgTypes + * @see ParameterSelective + * @see DynamicArgsLifecycle + * + * @return The context instance with [FOREVER][DynamicArgsLifecycle.FOREVER] lifecycle. + * + * @author cao_awa + * + * @since 1.0.0 + */ @JvmStatic @SuppressWarnings("UNCHECKED_CAST") fun request( @@ -462,7 +1084,9 @@ object ConiumEventContextBuilder { arising: ParameterSelective5 = ParameterSelective5 { _, _, _, _, _ -> true }, presaging: ParameterSelective5 = ParameterSelective5 { _, _, _, _, _ -> true } ): ConiumEventContext> { - val context = ConiumEventContext( + return forever( + eventType, + // Require a four argument dynamic args and contract to forever lifecycle. DynamicArgsBuilder.requires( arg1, arg2, @@ -470,21 +1094,52 @@ object ConiumEventContextBuilder { arg4, true ).lifecycle(DynamicArgsLifecycle.FOREVER) - ) - - ConiumEvent.forever(eventType, context) - - context.arise { i, p1, p2, p3, p4 -> - (i as? I)?.let { arising(it, p1, p2, p3, p4) } ?: true - } - - context.presage { i, p1, p2, p3, p4 -> - (i as? I)?.let { presaging(it, p1, p2, p3, p4) } ?: true + ).apply { + // Attach presage trigger, this is event cancelable when parameter selective returns false. + presage { i: Any, p1: P1, p2: P2, p3: P3, p4: P4 -> + (i as? I)?.let { presaging(it, p1, p2, p3, p4) } ?: true + } + + // Attach arise trigger, not event cancelable. + arise { i: Any, p1: P1, p2: P2, p3: P3, p4: P4 -> + (i as? I)?.let { arising(it, p1, p2, p3, p4) } ?: true + } } - - return context } + /** + * Make a sub context of specified event type that only trigger presaging in the context with five arguments, then auto attach to forever lifecycle of the event type. + * + * The context will arise when event base context arising and invalidate when reload events. + * + * @param I The specified input identity instance, see reified type of [ConiumEventType][ConiumEventType] + * @param P1 Type of first parameter + * @param arg1 The first parameter that will be input to the parameter selective instance + * @param P2 Type of second parameter + * @param arg2 The second parameter that will be input to the parameter selective instance + * @param P3 Type of third parameter + * @param arg3 The third parameter that will be input to the parameter selective instance + * @param P4 Type of fourth parameter + * @param arg4 The fourth parameter that will be input to the parameter selective instance + * @param P5 Type of fifth parameter + * @param arg5 The fifth parameter that will be input to the parameter selective instance + * @param eventType The event type that will be attaching + * @param presaging The presaging trigger, default is always successes + * + * @see ConiumEvent + * @see ConiumEventContext + * @see DynamicArgs + * @see DynamicArgType + * @see ConiumEventArgTypes + * @see ParameterSelective + * @see DynamicArgsLifecycle + * + * @return The context instance with [FOREVER][DynamicArgsLifecycle.FOREVER] lifecycle. + * + * @author cao_awa + * + * @since 1.0.0 + */ @JvmStatic @SuppressWarnings("UNCHECKED_CAST") fun preRequest( @@ -496,7 +1151,9 @@ object ConiumEventContextBuilder { arg5: DynamicArgType, presaging: ParameterSelective6 = ParameterSelective6 { _, _, _, _, _, _ -> true } ): ConiumEventContext> { - val context = ConiumEventContext( + return forever( + eventType, + // Require a five argument dynamic args and contract to forever lifecycle. DynamicArgsBuilder.requires( arg1, arg2, @@ -505,17 +1162,47 @@ object ConiumEventContextBuilder { arg5, true ).lifecycle(DynamicArgsLifecycle.FOREVER) - ) - - ConiumEvent.forever(eventType, context) - - context.presage { i, p1, p2, p3, p4, p5 -> - (i as? I)?.let { presaging(it, p1, p2, p3, p4, p5) } ?: true + ).apply { + // Attach presage trigger, this is event cancelable when parameter selective returns false. + presage { i: Any, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5 -> + (i as? I)?.let { presaging(it, p1, p2, p3, p4, p5) } ?: true + } } - - return context } + /** + * Make a sub context of specified event type that only trigger arising in the context with five arguments, then auto attach to forever lifecycle of the event type. + * + * The context will arise when event base context arising and invalidate when reload events. + * + * @param I The specified input identity instance, see reified type of [ConiumEventType][ConiumEventType] + * @param P1 Type of first parameter + * @param arg1 The first parameter that will be input to the parameter selective instance + * @param P2 Type of second parameter + * @param arg2 The second parameter that will be input to the parameter selective instance + * @param P3 Type of third parameter + * @param arg3 The third parameter that will be input to the parameter selective instance + * @param P4 Type of fourth parameter + * @param arg4 The fourth parameter that will be input to the parameter selective instance + * @param P5 Type of fifth parameter + * @param arg5 The fifth parameter that will be input to the parameter selective instance + * @param eventType The event type that will be attaching + * @param arising The arising trigger, default is always successes + * + * @see ConiumEvent + * @see ConiumEventContext + * @see DynamicArgs + * @see DynamicArgType + * @see ConiumEventArgTypes + * @see ParameterSelective + * @see DynamicArgsLifecycle + * + * @return The context instance with [FOREVER][DynamicArgsLifecycle.FOREVER] lifecycle. + * + * @author cao_awa + * + * @since 1.0.0 + */ @JvmStatic @SuppressWarnings("UNCHECKED_CAST") fun request( @@ -527,7 +1214,9 @@ object ConiumEventContextBuilder { arg5: DynamicArgType, arising: ParameterSelective6 = ParameterSelective6 { _, _, _, _, _, _ -> true } ): ConiumEventContext> { - val context = ConiumEventContext( + return forever( + eventType, + // Require a five argument dynamic args and contract to forever lifecycle. DynamicArgsBuilder.requires( arg1, arg2, @@ -536,17 +1225,48 @@ object ConiumEventContextBuilder { arg5, true ).lifecycle(DynamicArgsLifecycle.FOREVER) - ) - - ConiumEvent.forever(eventType, context) - - context.arise { i, p1, p2, p3, p4, p5 -> - (i as? I)?.let { arising(it, p1, p2, p3, p4, p5) } ?: true + ).apply { + // Attach arise trigger, not event cancelable. + arise { i: Any, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5 -> + (i as? I)?.let { arising(it, p1, p2, p3, p4, p5) } ?: true + } } - - return context } + /** + * Make a sub context of specified event type with five arguments, then auto attach to forever lifecycle of the event type. + * + * The context will arise when event base context arising and invalidate when reload events. + * + * @param I The specified input identity instance, see reified type of [ConiumEventType][ConiumEventType] + * @param P1 Type of first parameter + * @param arg1 The first parameter that will be input to the parameter selective instance + * @param P2 Type of second parameter + * @param arg2 The second parameter that will be input to the parameter selective instance + * @param P3 Type of third parameter + * @param arg3 The third parameter that will be input to the parameter selective instance + * @param P4 Type of fourth parameter + * @param arg4 The fourth parameter that will be input to the parameter selective instance + * @param P5 Type of fifth parameter + * @param arg5 The fifth parameter that will be input to the parameter selective instance + * @param eventType The event type that will be attaching + * @param arising The arising trigger, default is always successes + * @param presaging The presaging trigger, default is always successes + * + * @see ConiumEvent + * @see ConiumEventContext + * @see DynamicArgs + * @see DynamicArgType + * @see ConiumEventArgTypes + * @see ParameterSelective + * @see DynamicArgsLifecycle + * + * @return The context instance with [FOREVER][DynamicArgsLifecycle.FOREVER] lifecycle. + * + * @author cao_awa + * + * @since 1.0.0 + */ @JvmStatic @SuppressWarnings("UNCHECKED_CAST") fun request( @@ -559,7 +1279,9 @@ object ConiumEventContextBuilder { arising: ParameterSelective6 = ParameterSelective6 { _, _, _, _, _, _ -> true }, presaging: ParameterSelective6 = ParameterSelective6 { _, _, _, _, _, _ -> true } ): ConiumEventContext> { - val context = ConiumEventContext( + return forever( + eventType, + // Require a five argument dynamic args and contract to forever lifecycle. DynamicArgsBuilder.requires( arg1, arg2, @@ -568,21 +1290,54 @@ object ConiumEventContextBuilder { arg5, true ).lifecycle(DynamicArgsLifecycle.FOREVER) - ) - - ConiumEvent.forever(eventType, context) - - context.arise { i, p1, p2, p3, p4, p5 -> - (i as? I)?.let { arising(it, p1, p2, p3, p4, p5) } ?: true + ).apply { + // Attach presage trigger, this is event cancelable when parameter selective returns false. + presage { i: Any, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5 -> + (i as? I)?.let { presaging(it, p1, p2, p3, p4, p5) } ?: true + } + + // Attach arise trigger, not event cancelable. + arise { i: Any, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5 -> + (i as? I)?.let { arising(it, p1, p2, p3, p4, p5) } ?: true + } } - - context.presage { i, p1, p2, p3, p4, p5 -> - (i as? I)?.let { presaging(it, p1, p2, p3, p4, p5) } ?: true - } - - return context } + /** + * Make a sub context of specified event type that only trigger presaging in the context with six arguments, then auto attach to forever lifecycle of the event type. + * + * The context will arise when event base context arising and invalidate when reload events. + * + * @param I The specified input identity instance, see reified type of [ConiumEventType][ConiumEventType] + * @param P1 Type of first parameter + * @param arg1 The first parameter that will be input to the parameter selective instance + * @param P2 Type of second parameter + * @param arg2 The second parameter that will be input to the parameter selective instance + * @param P3 Type of third parameter + * @param arg3 The third parameter that will be input to the parameter selective instance + * @param P4 Type of fourth parameter + * @param arg4 The fourth parameter that will be input to the parameter selective instance + * @param P5 Type of fifth parameter + * @param arg5 The fifth parameter that will be input to the parameter selective instance + * @param P6 Type of sixth parameter + * @param arg6 The sixth parameter that will be input to the parameter selective instance + * @param eventType The event type that will be attaching + * @param presaging The presaging trigger, default is always successes + * + * @see ConiumEvent + * @see ConiumEventContext + * @see DynamicArgs + * @see DynamicArgType + * @see ConiumEventArgTypes + * @see ParameterSelective + * @see DynamicArgsLifecycle + * + * @return The context instance with [FOREVER][DynamicArgsLifecycle.FOREVER] lifecycle. + * + * @author cao_awa + * + * @since 1.0.0 + */ @JvmStatic @SuppressWarnings("UNCHECKED_CAST") fun preRequest( @@ -595,7 +1350,9 @@ object ConiumEventContextBuilder { arg6: DynamicArgType, presaging: ParameterSelective7 = ParameterSelective7 { _, _, _, _, _, _, _ -> true } ): ConiumEventContext> { - val context = ConiumEventContext( + return forever( + eventType, + // Require a six argument dynamic args and contract to forever lifecycle. DynamicArgsBuilder.requires( arg1, arg2, @@ -605,17 +1362,49 @@ object ConiumEventContextBuilder { arg6, true ).lifecycle(DynamicArgsLifecycle.FOREVER) - ) - - ConiumEvent.forever(eventType, context) - - context.presage { i, p1, p2, p3, p4, p5, p6 -> - (i as? I)?.let { presaging(it, p1, p2, p3, p4, p5, p6) } ?: true + ).apply { + // Attach presage trigger, this is event cancelable when parameter selective returns false. + presage { i: Any, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6 -> + (i as? I)?.let { presaging(it, p1, p2, p3, p4, p5, p6) } ?: true + } } - - return context } + /** + * Make a sub context of specified event type that only trigger arising in the context with six arguments, then auto attach to forever lifecycle of the event type. + * + * The context will arise when event base context arising and invalidate when reload events. + * + * @param I The specified input identity instance, see reified type of [ConiumEventType][ConiumEventType] + * @param P1 Type of first parameter + * @param arg1 The first parameter that will be input to the parameter selective instance + * @param P2 Type of second parameter + * @param arg2 The second parameter that will be input to the parameter selective instance + * @param P3 Type of third parameter + * @param arg3 The third parameter that will be input to the parameter selective instance + * @param P4 Type of fourth parameter + * @param arg4 The fourth parameter that will be input to the parameter selective instance + * @param P5 Type of fifth parameter + * @param arg5 The fifth parameter that will be input to the parameter selective instance + * @param P6 Type of sixth parameter + * @param arg6 The sixth parameter that will be input to the parameter selective instance + * @param eventType The event type that will be attaching + * @param arising The arising trigger, default is always successes + * + * @see ConiumEvent + * @see ConiumEventContext + * @see DynamicArgs + * @see DynamicArgType + * @see ConiumEventArgTypes + * @see ParameterSelective + * @see DynamicArgsLifecycle + * + * @return The context instance with [FOREVER][DynamicArgsLifecycle.FOREVER] lifecycle. + * + * @author cao_awa + * + * @since 1.0.0 + */ @JvmStatic @SuppressWarnings("UNCHECKED_CAST") fun request( @@ -628,7 +1417,9 @@ object ConiumEventContextBuilder { arg6: DynamicArgType, arising: ParameterSelective7 = ParameterSelective7 { _, _, _, _, _, _, _ -> true } ): ConiumEventContext> { - val context = ConiumEventContext( + return forever( + eventType, + // Require a six argument dynamic args and contract to forever lifecycle. DynamicArgsBuilder.requires( arg1, arg2, @@ -638,17 +1429,50 @@ object ConiumEventContextBuilder { arg6, true ).lifecycle(DynamicArgsLifecycle.FOREVER) - ) - - ConiumEvent.forever(eventType, context) - - context.arise { i, p1, p2, p3, p4, p5, p6 -> - (i as? I)?.let { arising(it, p1, p2, p3, p4, p5, p6) } ?: true + ).apply { + // Attach arise trigger, not event cancelable. + arise { i: Any, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6 -> + (i as? I)?.let { arising(it, p1, p2, p3, p4, p5, p6) } ?: true + } } - - return context } + /** + * Make a sub context of specified event type with six arguments, then auto attach to forever lifecycle of the event type. + * + * The context will arise when event base context arising and invalidate when reload events. + * + * @param I The specified input identity instance, see reified type of [ConiumEventType][ConiumEventType] + * @param P1 Type of first parameter + * @param arg1 The first parameter that will be input to the parameter selective instance + * @param P2 Type of second parameter + * @param arg2 The second parameter that will be input to the parameter selective instance + * @param P3 Type of third parameter + * @param arg3 The third parameter that will be input to the parameter selective instance + * @param P4 Type of fourth parameter + * @param arg4 The fourth parameter that will be input to the parameter selective instance + * @param P5 Type of fifth parameter + * @param arg5 The fifth parameter that will be input to the parameter selective instance + * @param P6 Type of sixth parameter + * @param arg6 The sixth parameter that will be input to the parameter selective instance + * @param eventType The event type that will be attaching + * @param arising The arising trigger, default is always successes + * @param presaging The presaging trigger, default is always successes + * + * @see ConiumEvent + * @see ConiumEventContext + * @see DynamicArgs + * @see DynamicArgType + * @see ConiumEventArgTypes + * @see ParameterSelective + * @see DynamicArgsLifecycle + * + * @return The context instance with [FOREVER][DynamicArgsLifecycle.FOREVER] lifecycle. + * + * @author cao_awa + * + * @since 1.0.0 + */ @JvmStatic @SuppressWarnings("UNCHECKED_CAST") fun request( @@ -662,7 +1486,9 @@ object ConiumEventContextBuilder { arising: ParameterSelective7 = ParameterSelective7 { _, _, _, _, _, _, _ -> true }, presaging: ParameterSelective7 = ParameterSelective7 { _, _, _, _, _, _, _ -> true } ): ConiumEventContext> { - val context = ConiumEventContext( + return forever( + eventType, + // Require a six argument dynamic args and contract to forever lifecycle. DynamicArgsBuilder.requires( arg1, arg2, @@ -672,21 +1498,56 @@ object ConiumEventContextBuilder { arg6, true ).lifecycle(DynamicArgsLifecycle.FOREVER) - ) - - ConiumEvent.forever(eventType, context) - - context.arise { i, p1, p2, p3, p4, p5, p6 -> - (i as? I)?.let { arising(it, p1, p2, p3, p4, p5, p6) } ?: true - } - - context.presage { i, p1, p2, p3, p4, p5, p6 -> - (i as? I)?.let { presaging(it, p1, p2, p3, p4, p5, p6) } ?: true + ).apply { + // Attach presage trigger, this is event cancelable when parameter selective returns false. + presage { i: Any, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6 -> + (i as? I)?.let { presaging(it, p1, p2, p3, p4, p5, p6) } ?: true + } + + // Attach arise trigger, not event cancelable. + arise { i: Any, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6 -> + (i as? I)?.let { arising(it, p1, p2, p3, p4, p5, p6) } ?: true + } } - - return context } + /** + * Make a sub context of specified event type that only trigger presaging in the context with seven arguments, then auto attach to forever lifecycle of the event type. + * + * The context will arise when event base context arising and invalidate when reload events. + * + * @param I The specified input identity instance, see reified type of [ConiumEventType][ConiumEventType] + * @param P1 Type of first parameter + * @param arg1 The first parameter that will be input to the parameter selective instance + * @param P2 Type of second parameter + * @param arg2 The second parameter that will be input to the parameter selective instance + * @param P3 Type of third parameter + * @param arg3 The third parameter that will be input to the parameter selective instance + * @param P4 Type of fourth parameter + * @param arg4 The fourth parameter that will be input to the parameter selective instance + * @param P5 Type of fifth parameter + * @param arg5 The fifth parameter that will be input to the parameter selective instance + * @param P6 Type of sixth parameter + * @param arg6 The sixth parameter that will be input to the parameter selective instance + * @param P7 Type of seventh parameter + * @param arg7 The seventh parameter that will be input to the parameter selective instance + * @param eventType The event type that will be attaching + * @param presaging The presaging trigger, default is always successes + * + * @see ConiumEvent + * @see ConiumEventContext + * @see DynamicArgs + * @see DynamicArgType + * @see ConiumEventArgTypes + * @see ParameterSelective + * @see DynamicArgsLifecycle + * + * @return The context instance with [FOREVER][DynamicArgsLifecycle.FOREVER] lifecycle. + * + * @author cao_awa + * + * @since 1.0.0 + */ @JvmStatic @SuppressWarnings("UNCHECKED_CAST") fun preRequest( @@ -700,7 +1561,9 @@ object ConiumEventContextBuilder { arg7: DynamicArgType, presaging: ParameterSelective8 = ParameterSelective8 { _, _, _, _, _, _, _, _ -> true } ): ConiumEventContext> { - val context = ConiumEventContext( + return forever( + eventType, + // Require a seven argument dynamic args and contract to forever lifecycle. DynamicArgsBuilder.requires( arg1, arg2, @@ -711,17 +1574,51 @@ object ConiumEventContextBuilder { arg7, true ).lifecycle(DynamicArgsLifecycle.FOREVER) - ) - - ConiumEvent.forever(eventType, context) - - context.presage { i, p1, p2, p3, p4, p5, p6, p7 -> - (i as? I)?.let { presaging(it, p1, p2, p3, p4, p5, p6, p7) } ?: true + ).apply { + // Attach presage trigger, this is event cancelable when parameter selective returns false. + presage { i: Any, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7 -> + (i as? I)?.let { presaging(it, p1, p2, p3, p4, p5, p6, p7) } ?: true + } } - - return context } + /** + * Make a sub context of specified event type that only trigger arising in the context with seven arguments, then auto attach to forever lifecycle of the event type. + * + * The context will arise when event base context arising and invalidate when reload events. + * + * @param I The specified input identity instance, see reified type of [ConiumEventType][ConiumEventType] + * @param P1 Type of first parameter + * @param arg1 The first parameter that will be input to the parameter selective instance + * @param P2 Type of second parameter + * @param arg2 The second parameter that will be input to the parameter selective instance + * @param P3 Type of third parameter + * @param arg3 The third parameter that will be input to the parameter selective instance + * @param P4 Type of fourth parameter + * @param arg4 The fourth parameter that will be input to the parameter selective instance + * @param P5 Type of fifth parameter + * @param arg5 The fifth parameter that will be input to the parameter selective instance + * @param P6 Type of sixth parameter + * @param arg6 The sixth parameter that will be input to the parameter selective instance + * @param P7 Type of seventh parameter + * @param arg7 The seventh parameter that will be input to the parameter selective instance + * @param eventType The event type that will be attaching + * @param arising The arising trigger, default is always successes + * + * @see ConiumEvent + * @see ConiumEventContext + * @see DynamicArgs + * @see DynamicArgType + * @see ConiumEventArgTypes + * @see ParameterSelective + * @see DynamicArgsLifecycle + * + * @return The context instance with [FOREVER][DynamicArgsLifecycle.FOREVER] lifecycle. + * + * @author cao_awa + * + * @since 1.0.0 + */ @JvmStatic @SuppressWarnings("UNCHECKED_CAST") fun request( @@ -735,7 +1632,9 @@ object ConiumEventContextBuilder { arg7: DynamicArgType, arising: ParameterSelective8 = ParameterSelective8 { _, _, _, _, _, _, _, _ -> true } ): ConiumEventContext> { - val context = ConiumEventContext( + return forever( + eventType, + // Require a seven argument dynamic args and contract to forever lifecycle. DynamicArgsBuilder.requires( arg1, arg2, @@ -746,17 +1645,52 @@ object ConiumEventContextBuilder { arg7, true ).lifecycle(DynamicArgsLifecycle.FOREVER) - ) - - ConiumEvent.forever(eventType, context) - - context.arise { i, p1, p2, p3, p4, p5, p6, p7 -> - (i as? I)?.let { arising(it, p1, p2, p3, p4, p5, p6, p7) } ?: true + ).apply { + // Attach arise trigger, not event cancelable. + arise { i: Any, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7 -> + (i as? I)?.let { arising(it, p1, p2, p3, p4, p5, p6, p7) } ?: true + } } - - return context } + /** + * Make a sub context of specified event type with seven arguments, then auto attach to forever lifecycle of the event type. + * + * The context will arise when event base context arising and invalidate when reload events. + * + * @param I The specified input identity instance, see reified type of [ConiumEventType][ConiumEventType] + * @param P1 Type of first parameter + * @param arg1 The first parameter that will be input to the parameter selective instance + * @param P2 Type of second parameter + * @param arg2 The second parameter that will be input to the parameter selective instance + * @param P3 Type of third parameter + * @param arg3 The third parameter that will be input to the parameter selective instance + * @param P4 Type of fourth parameter + * @param arg4 The fourth parameter that will be input to the parameter selective instance + * @param P5 Type of fifth parameter + * @param arg5 The fifth parameter that will be input to the parameter selective instance + * @param P6 Type of sixth parameter + * @param arg6 The sixth parameter that will be input to the parameter selective instance + * @param P7 Type of seventh parameter + * @param arg7 The seventh parameter that will be input to the parameter selective instance + * @param eventType The event type that will be attaching + * @param arising The arising trigger, default is always successes + * @param presaging The presaging trigger, default is always successes + * + * @see ConiumEvent + * @see ConiumEventContext + * @see DynamicArgs + * @see DynamicArgType + * @see ConiumEventArgTypes + * @see ParameterSelective + * @see DynamicArgsLifecycle + * + * @return The context instance with [FOREVER][DynamicArgsLifecycle.FOREVER] lifecycle. + * + * @author cao_awa + * + * @since 1.0.0 + */ @JvmStatic @SuppressWarnings("UNCHECKED_CAST") fun request( @@ -771,7 +1705,9 @@ object ConiumEventContextBuilder { arising: ParameterSelective8 = ParameterSelective8 { _, _, _, _, _, _, _, _ -> true }, presaging: ParameterSelective8 = ParameterSelective8 { _, _, _, _, _, _, _, _ -> true } ): ConiumEventContext> { - val context = ConiumEventContext( + return forever( + eventType, + // Require a seven argument dynamic args and contract to forever lifecycle. DynamicArgsBuilder.requires( arg1, arg2, @@ -782,21 +1718,46 @@ object ConiumEventContextBuilder { arg7, true ).lifecycle(DynamicArgsLifecycle.FOREVER) - ) - - ConiumEvent.forever(eventType, context) - - context.arise { i, p1, p2, p3, p4, p5, p6, p7 -> - (i as? I)?.let { arising(it, p1, p2, p3, p4, p5, p6, p7) } ?: true + ).apply { + // Attach presage trigger, this is event cancelable when parameter selective returns false. + presage { i: Any, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7 -> + (i as? I)?.let { presaging(it, p1, p2, p3, p4, p5, p6, p7) } ?: true + } + + // Attach arise trigger, not event cancelable. + arise { i: Any, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7 -> + (i as? I)?.let { arising(it, p1, p2, p3, p4, p5, p6, p7) } ?: true + } } - - context.presage { i, p1, p2, p3, p4, p5, p6, p7 -> - (i as? I)?.let { presaging(it, p1, p2, p3, p4, p5, p6, p7) } ?: true - } - - return context } + /** + * Make a sub context of specified event type that changes a variable every time trigger with no arguments, then auto attach to forever lifecycle of the event type. + * + * The context will arise when event base context arising and invalidate when reload events. + * + * @param I The specified input identity instance, see reified type of [ConiumEventType][ConiumEventType] + * @param R The result type of the parameter selective + * @param name The name of this exporting context + * @param defaultResult The default value when failure + * @param eventType The event type that will be attaching + * @param arising The arising trigger, default is always successes + * + * @see ConiumEvent + * @see ConiumEventContext + * @see DynamicArgs + * @see DynamicArgType + * @see ParameterSelective + * @see DynamicArgsLifecycle + * @see NamedInteractionScript + * + * @return The context instance with [FOREVER][DynamicArgsLifecycle.FOREVER] lifecycle. + * + * @author cao_awa + * @author 草二号机 + * + * @since 1.0.0 + */ @JvmStatic @SuppressWarnings("UNCHECKED_CAST") fun export( @@ -805,27 +1766,57 @@ object ConiumEventContextBuilder { eventType: ConiumEventType, arising: ParameterSelective1 ): ConiumEventContext> { - val context = ConiumEventContext( + return forever( + eventType, + // Require a no argument dynamic args and contract to forever lifecycle. DynamicArgsBuilder.requires(true).lifecycle(DynamicArgsLifecycle.FOREVER) - ) - - ConiumEvent.forever(eventType, context) - - var result: R = defaultResult - - Conium.scriptManager!!.export(name, context) { result } - - context.arise { i: Any -> - result = (i as? I)?.let { - arising(i) - } ?: defaultResult - true + ).apply { + var result: R = defaultResult + + // Export to script manager, let data driven frameworks can access the context. + Conium.scriptManager!!.export(name, this) { result } + + // Attach arise trigger, not event cancelable. + arise { i: Any -> + // Change the result variable. + result = (i as? I)?.let { + arising(i) + } ?: defaultResult + true + } } - - return context } - + /** + * Make a sub context of specified event type that changes a variable every time trigger with one argument, then auto attach to forever lifecycle of the event type. + * + * The context will arise when event base context arising and invalidate when reload events. + * + * @param I The specified input identity instance, see reified type of [ConiumEventType][ConiumEventType] + * @param R The result type of the parameter selective + * @param P1 Type of first parameter + * @param arg1 The first parameter that will be input to the parameter selective instance + * @param name The name of this exporting context + * @param defaultResult The default value when failure + * @param eventType The event type that will be attaching + * @param arising The arising trigger, default is always successes + * + * @see ConiumEvent + * @see ConiumEventContext + * @see DynamicArgs + * @see DynamicArgType + * @see ConiumEventArgTypes + * @see ParameterSelective + * @see DynamicArgsLifecycle + * @see NamedInteractionScript + * + * @return The context instance with [FOREVER][DynamicArgsLifecycle.FOREVER] lifecycle. + * + * @author cao_awa + * @author 草二号机 + * + * @since 1.0.0 + */ @JvmStatic @SuppressWarnings("UNCHECKED_CAST") fun export( @@ -835,26 +1826,59 @@ object ConiumEventContextBuilder { arg1: DynamicArgType, arising: ParameterSelective2 ): ConiumEventContext> { - val context = ConiumEventContext( + return forever( + eventType, + // Require a one argument dynamic args and contract to forever lifecycle. DynamicArgsBuilder.requires(arg1, true).lifecycle(DynamicArgsLifecycle.FOREVER) - ) - - ConiumEvent.forever(eventType, context) - - var result: R = defaultResult - - Conium.scriptManager!!.export(name, context) { result } - - context.arise { i: Any, p1: P1 -> - result = (i as? I)?.let { - arising(i, p1) - } ?: defaultResult - true + ).apply { + var result: R = defaultResult + + // Export to script manager, let data driven frameworks can access the context. + Conium.scriptManager!!.export(name, this) { result } + + // Attach arise trigger, not event cancelable. + arise { i: Any, p1: P1 -> + // Change the result variable. + result = (i as? I)?.let { + arising(i, p1) + } ?: defaultResult + true + } } - - return context } + /** + * Make a sub context of specified event type that changes a variable every time trigger with two arguments, then auto attach to forever lifecycle of the event type. + * + * The context will arise when event base context arising and invalidate when reload events. + * + * @param I The specified input identity instance, see reified type of [ConiumEventType][ConiumEventType] + * @param R The result type of the parameter selective + * @param P1 Type of first parameter + * @param arg1 The first parameter that will be input to the parameter selective instance + * @param P2 Type of second parameter + * @param arg2 The second parameter that will be input to the parameter selective instance + * @param name The name of this exporting context + * @param defaultResult The default value when failure + * @param eventType The event type that will be attaching + * @param arising The arising trigger, default is always successes + * + * @see ConiumEvent + * @see ConiumEventContext + * @see DynamicArgs + * @see DynamicArgType + * @see ConiumEventArgTypes + * @see ParameterSelective + * @see DynamicArgsLifecycle + * @see NamedInteractionScript + * + * @return The context instance with [FOREVER][DynamicArgsLifecycle.FOREVER] lifecycle. + * + * @author cao_awa + * @author 草二号机 + * + * @since 1.0.0 + */ @JvmStatic @SuppressWarnings("UNCHECKED_CAST") fun export( @@ -865,26 +1889,61 @@ object ConiumEventContextBuilder { arg2: DynamicArgType, arising: ParameterSelective3 ): ConiumEventContext> { - val context = ConiumEventContext( + return forever( + eventType, + // Require a two argument dynamic args and contract to forever lifecycle. DynamicArgsBuilder.requires(arg1, arg2, true).lifecycle(DynamicArgsLifecycle.FOREVER) - ) - - ConiumEvent.forever(eventType, context) - - var result: R = defaultResult - - Conium.scriptManager!!.export(name, context) { result } - - context.arise { i: Any, p1: P1, p2: P2 -> - result = (i as? I)?.let { - arising(i, p1, p2) - } ?: defaultResult - true + ).apply { + var result: R = defaultResult + + // Export to script manager, let data driven frameworks can access the context. + Conium.scriptManager!!.export(name, this) { result } + + // Attach arise trigger, not event cancelable. + arise { i: Any, p1: P1, p2: P2 -> + // Change the result variable. + result = (i as? I)?.let { + arising(i, p1, p2) + } ?: defaultResult + true + } } - - return context } + /** + * Make a sub context of specified event type that changes a variable every time trigger with three arguments, then auto attach to forever lifecycle of the event type. + * + * The context will arise when event base context arising and invalidate when reload events. + * + * @param I The specified input identity instance, see reified type of [ConiumEventType][ConiumEventType] + * @param R The result type of the parameter selective + * @param P1 Type of first parameter + * @param arg1 The first parameter that will be input to the parameter selective instance + * @param P2 Type of second parameter + * @param arg2 The second parameter that will be input to the parameter selective instance + * @param P3 Type of third parameter + * @param arg3 The third parameter that will be input to the parameter selective instance + * @param name The name of this exporting context + * @param defaultResult The default value when failure + * @param eventType The event type that will be attaching + * @param arising The arising trigger, default is always successes + * + * @see ConiumEvent + * @see ConiumEventContext + * @see DynamicArgs + * @see DynamicArgType + * @see ConiumEventArgTypes + * @see ParameterSelective + * @see DynamicArgsLifecycle + * @see NamedInteractionScript + * + * @return The context instance with [FOREVER][DynamicArgsLifecycle.FOREVER] lifecycle. + * + * @author cao_awa + * @author 草二号机 + * + * @since 1.0.0 + */ @JvmStatic @SuppressWarnings("UNCHECKED_CAST") fun export( @@ -896,26 +1955,63 @@ object ConiumEventContextBuilder { arg3: DynamicArgType, arising: ParameterSelective4 ): ConiumEventContext> { - val context = ConiumEventContext( + return forever( + eventType, + // Require a three argument dynamic args and contract to forever lifecycle. DynamicArgsBuilder.requires(arg1, arg2, arg3, true).lifecycle(DynamicArgsLifecycle.FOREVER) - ) - - ConiumEvent.forever(eventType, context) - - var result: R = defaultResult - - Conium.scriptManager!!.export(name, context) { result } - - context.arise { i: Any, p1: P1, p2: P2, p3: P3 -> - result = (i as? I)?.let { - arising(i, p1, p2, p3) - } ?: defaultResult - true + ).apply { + var result: R = defaultResult + + // Export to script manager, let data driven frameworks can access the context. + Conium.scriptManager!!.export(name, this) { result } + + // Attach arise trigger, not event cancelable. + arise { i: Any, p1: P1, p2: P2, p3: P3 -> + // Change the result variable. + result = (i as? I)?.let { + arising(i, p1, p2, p3) + } ?: defaultResult + true + } } - - return context } + /** + * Make a sub context of specified event type that changes a variable every time trigger with four arguments, then auto attach to forever lifecycle of the event type. + * + * The context will arise when event base context arising and invalidate when reload events. + * + * @param I The specified input identity instance, see reified type of [ConiumEventType][ConiumEventType] + * @param R The result type of the parameter selective + * @param P1 Type of first parameter + * @param arg1 The first parameter that will be input to the parameter selective instance + * @param P2 Type of second parameter + * @param arg2 The second parameter that will be input to the parameter selective instance + * @param P3 Type of third parameter + * @param arg3 The third parameter that will be input to the parameter selective instance + * @param P4 Type of fourth parameter + * @param arg4 The fourth parameter that will be input to the parameter selective instance + * @param name The name of this exporting context + * @param defaultResult The default value when failure + * @param eventType The event type that will be attaching + * @param arising The arising trigger, default is always successes + * + * @see ConiumEvent + * @see ConiumEventContext + * @see DynamicArgs + * @see DynamicArgType + * @see ConiumEventArgTypes + * @see ParameterSelective + * @see DynamicArgsLifecycle + * @see NamedInteractionScript + * + * @return The context instance with [FOREVER][DynamicArgsLifecycle.FOREVER] lifecycle. + * + * @author cao_awa + * @author 草二号机 + * + * @since 1.0.0 + */ @JvmStatic @SuppressWarnings("UNCHECKED_CAST") fun export( @@ -928,26 +2024,65 @@ object ConiumEventContextBuilder { arg4: DynamicArgType, arising: ParameterSelective5 ): ConiumEventContext> { - val context = ConiumEventContext( + return forever( + eventType, + // Require a four argument dynamic args and contract to forever lifecycle. DynamicArgsBuilder.requires(arg1, arg2, arg3, arg4, true).lifecycle(DynamicArgsLifecycle.FOREVER) - ) - - ConiumEvent.forever(eventType, context) - - var result: R = defaultResult - - Conium.scriptManager!!.export(name, context) { result } - - context.arise { i: Any, p1: P1, p2: P2, p3: P3, p4: P4 -> - result = (i as? I)?.let { - arising(i, p1, p2, p3, p4) - } ?: defaultResult - true + ).apply { + var result: R = defaultResult + + // Export to script manager, let data driven frameworks can access the context. + Conium.scriptManager!!.export(name, this) { result } + + // Attach arise trigger, not event cancelable. + arise { i: Any, p1: P1, p2: P2, p3: P3, p4: P4 -> + // Change the result variable. + result = (i as? I)?.let { + arising(i, p1, p2, p3, p4) + } ?: defaultResult + true + } } - - return context } + /** + * Make a sub context of specified event type that changes a variable every time trigger with five arguments, then auto attach to forever lifecycle of the event type. + * + * The context will arise when event base context arising and invalidate when reload events. + * + * @param I The specified input identity instance, see reified type of [ConiumEventType][ConiumEventType] + * @param R The result type of the parameter selective + * @param P1 Type of first parameter + * @param arg1 The first parameter that will be input to the parameter selective instance + * @param P2 Type of second parameter + * @param arg2 The second parameter that will be input to the parameter selective instance + * @param P3 Type of third parameter + * @param arg3 The third parameter that will be input to the parameter selective instance + * @param P4 Type of fourth parameter + * @param arg4 The fourth parameter that will be input to the parameter selective instance + * @param P5 Type of fifth parameter + * @param arg5 The fifth parameter that will be input to the parameter selective instance + * @param name The name of this exporting context + * @param defaultResult The default value when failure + * @param eventType The event type that will be attaching + * @param arising The arising trigger, default is always successes + * + * @see ConiumEvent + * @see ConiumEventContext + * @see DynamicArgs + * @see DynamicArgType + * @see ConiumEventArgTypes + * @see ParameterSelective + * @see DynamicArgsLifecycle + * @see NamedInteractionScript + * + * @return The context instance with [FOREVER][DynamicArgsLifecycle.FOREVER] lifecycle. + * + * @author cao_awa + * @author 草二号机 + * + * @since 1.0.0 + */ @JvmStatic @SuppressWarnings("UNCHECKED_CAST") fun export( @@ -961,26 +2096,67 @@ object ConiumEventContextBuilder { arg5: DynamicArgType, arising: ParameterSelective6 ): ConiumEventContext> { - val context = ConiumEventContext( + return forever( + eventType, + // Require a five argument dynamic args and contract to forever lifecycle. DynamicArgsBuilder.requires(arg1, arg2, arg3, arg4, arg5, true).lifecycle(DynamicArgsLifecycle.FOREVER) - ) - - ConiumEvent.forever(eventType, context) - - var result: R = defaultResult - - Conium.scriptManager!!.export(name, context) { result } - - context.arise { i: Any, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5 -> - result = (i as? I)?.let { - arising(i, p1, p2, p3, p4, p5) - } ?: defaultResult - true + ).apply { + var result: R = defaultResult + + // Export to script manager, let data driven frameworks can access the context. + Conium.scriptManager!!.export(name, this) { result } + + // Attach arise trigger, not event cancelable. + arise { i: Any, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5 -> + // Change the result variable. + result = (i as? I)?.let { + arising(i, p1, p2, p3, p4, p5) + } ?: defaultResult + true + } } - - return context } + /** + * Make a sub context of specified event type that changes a variable every time trigger with six arguments, then auto attach to forever lifecycle of the event type. + * + * The context will arise when event base context arising and invalidate when reload events. + * + * @param I The specified input identity instance, see reified type of [ConiumEventType][ConiumEventType] + * @param R The result type of the parameter selective + * @param P1 Type of first parameter + * @param arg1 The first parameter that will be input to the parameter selective instance + * @param P2 Type of second parameter + * @param arg2 The second parameter that will be input to the parameter selective instance + * @param P3 Type of third parameter + * @param arg3 The third parameter that will be input to the parameter selective instance + * @param P4 Type of fourth parameter + * @param arg4 The fourth parameter that will be input to the parameter selective instance + * @param P5 Type of fifth parameter + * @param arg5 The fifth parameter that will be input to the parameter selective instance + * @param P6 Type of sixth parameter + * @param arg6 The sixth parameter that will be input to the parameter selective instance + * @param name The name of this exporting context + * @param defaultResult The default value when failure + * @param eventType The event type that will be attaching + * @param arising The arising trigger, default is always successes + * + * @see ConiumEvent + * @see ConiumEventContext + * @see DynamicArgs + * @see DynamicArgType + * @see ConiumEventArgTypes + * @see ParameterSelective + * @see DynamicArgsLifecycle + * @see NamedInteractionScript + * + * @return The context instance with [FOREVER][DynamicArgsLifecycle.FOREVER] lifecycle. + * + * @author cao_awa + * @author 草二号机 + * + * @since 1.0.0 + */ @JvmStatic @SuppressWarnings("UNCHECKED_CAST") fun export( @@ -995,26 +2171,69 @@ object ConiumEventContextBuilder { arg6: DynamicArgType, arising: ParameterSelective7 ): ConiumEventContext> { - val context = ConiumEventContext( + return forever( + eventType, + // Require a six argument dynamic args and contract to forever lifecycle. DynamicArgsBuilder.requires(arg1, arg2, arg3, arg4, arg5, arg6, true).lifecycle(DynamicArgsLifecycle.FOREVER) - ) - - ConiumEvent.forever(eventType, context) - - var result: R = defaultResult - - Conium.scriptManager!!.export(name, context) { result } - - context.arise { i: Any, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6 -> - result = (i as? I)?.let { - arising(i, p1, p2, p3, p4, p5, p6) - } ?: defaultResult - true + ).apply { + var result: R = defaultResult + + // Export to script manager, let data driven frameworks can access the context. + Conium.scriptManager!!.export(name, this) { result } + + // Attach arise trigger, not event cancelable. + arise { i: Any, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6 -> + // Change the result variable. + result = (i as? I)?.let { + arising(i, p1, p2, p3, p4, p5, p6) + } ?: defaultResult + true + } } - - return context } + /** + * Make a sub context of specified event type that changes a variable every time trigger with seven arguments, then auto attach to forever lifecycle of the event type. + * + * The context will arise when event base context arising and invalidate when reload events. + * + * @param I The specified input identity instance, see reified type of [ConiumEventType][ConiumEventType] + * @param R The result type of the parameter selective + * @param P1 Type of first parameter + * @param arg1 The first parameter that will be input to the parameter selective instance + * @param P2 Type of second parameter + * @param arg2 The second parameter that will be input to the parameter selective instance + * @param P3 Type of third parameter + * @param arg3 The third parameter that will be input to the parameter selective instance + * @param P4 Type of fourth parameter + * @param arg4 The fourth parameter that will be input to the parameter selective instance + * @param P5 Type of fifth parameter + * @param arg5 The fifth parameter that will be input to the parameter selective instance + * @param P6 Type of sixth parameter + * @param arg6 The sixth parameter that will be input to the parameter selective instance + * @param P7 Type of seventh parameter + * @param arg7 The seventh parameter that will be input to the parameter selective instance + * @param name The name of this exporting context + * @param defaultResult The default value when failure + * @param eventType The event type that will be attaching + * @param arising The arising trigger, default is always successes + * + * @see ConiumEvent + * @see ConiumEventContext + * @see DynamicArgs + * @see DynamicArgType + * @see ConiumEventArgTypes + * @see ParameterSelective + * @see DynamicArgsLifecycle + * @see NamedInteractionScript + * + * @return The context instance with [FOREVER][DynamicArgsLifecycle.FOREVER] lifecycle. + * + * @author cao_awa + * @author 草二号机 + * + * @since 1.0.0 + */ @JvmStatic @SuppressWarnings("UNCHECKED_CAST") fun export( @@ -1030,62 +2249,149 @@ object ConiumEventContextBuilder { arg7: DynamicArgType, arising: ParameterSelective8 ): ConiumEventContext> { - val context = ConiumEventContext( + return forever( + eventType, + // Require a seven argument dynamic args and contract to forever lifecycle. DynamicArgsBuilder.requires(arg1, arg2, arg3, arg4, arg5, arg6, arg7, true).lifecycle(DynamicArgsLifecycle.FOREVER) - ) - - ConiumEvent.forever(eventType, context) - - var result: R = defaultResult - - Conium.scriptManager!!.export(name, context) { result } - - context.arise { i: Any, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7 -> - result = (i as? I)?.let { - arising(i, p1, p2, p3, p4, p5, p6, p7) - } ?: defaultResult - true + ).apply { + var result: R = defaultResult + + // Export to script manager, let data driven frameworks can access the context. + Conium.scriptManager!!.export(name, this) { result } + + // Attach arise trigger, not event cancelable. + arise { i: Any, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7 -> + // Change the result variable. + result = (i as? I)?.let { + arising(i, p1, p2, p3, p4, p5, p6, p7) + } ?: defaultResult + true + } } - - return context } + /** + * Make an unnamed event context with no arguments, it should manually attach to the events that needs to attach. + * + * The context lifecycle only related to the lifecycle of it attached event context. + * + * @param P1 Type of first parameter + * @param arg1 The first parameter that will be input to the parameter selective instance + * @param P2 Type of second parameter + * @param arg2 The second parameter that will be input to the parameter selective instance + * @param P3 Type of third parameter + * @param arg3 The third parameter that will be input to the parameter selective instance + * @param arising The arising trigger, default is always successes + * + * @see ConiumEvent + * @see ConiumEventContext + * @see DynamicArgs + * @see DynamicArgType + * @see ConiumEventArgTypes + * @see ParameterSelective + * @see DynamicArgsLifecycle + * @see NamedInteractionScript + * @see ConiumScriptManager.acquire + * @see ConiumScriptManager.acquireResult + * + * @return The context instance with [UNNAMED][DynamicArgsLifecycle.UNNAMED] lifecycle. + * + * @author cao_awa + * @author 草二号机 + * + * @since 1.0.0 + */ @JvmStatic @SuppressWarnings("UNCHECKED_CAST") fun unnamed( arising: ParameterSelective1 ): ConiumEventContext> { - val context = ConiumEventContext( + return ConiumEventContext( + // Require a no argument dynamic args and contract to unnamed lifecycle. DynamicArgsBuilder.requires(true).lifecycle(DynamicArgsLifecycle.UNNAMED) - ) - - context.arise { i: Any -> - i.let(arising::arise) - true + ).apply { + // Attach arise trigger, not event cancelable. + arise { i: Any -> + i.let(arising::arise) + true + } } - - return context } - + /** + * Make an unnamed event context with one argument, it should manually attach to the events that needs to attach. + * + * The context lifecycle only related to the lifecycle of it attached event context. + * + * @param P1 Type of first parameter + * @param arg1 The first parameter that will be input to the parameter selective instance + * @param arising The arising trigger, default is always successes + * + * @see ConiumEvent + * @see ConiumEventContext + * @see DynamicArgs + * @see DynamicArgType + * @see ConiumEventArgTypes + * @see ParameterSelective + * @see DynamicArgsLifecycle + * @see NamedInteractionScript + * @see ConiumScriptManager.acquire + * @see ConiumScriptManager.acquireResult + * + * @return The context instance with [UNNAMED][DynamicArgsLifecycle.UNNAMED] lifecycle. + * + * @author cao_awa + * @author 草二号机 + * + * @since 1.0.0 + */ @JvmStatic @SuppressWarnings("UNCHECKED_CAST") fun unnamed( arg1: DynamicArgType, arising: ParameterSelective2 ): ConiumEventContext> { - val context = ConiumEventContext( + return ConiumEventContext( + // Require a one argument dynamic args and contract to unnamed lifecycle. DynamicArgsBuilder.requires(arg1, true).lifecycle(DynamicArgsLifecycle.UNNAMED) - ) - - context.arise { i: Any, p1: P1 -> - arising(i, p1) - true + ).apply { + // Attach arise trigger, not event cancelable. + arise { i: Any, p1: P1 -> + arising(i, p1) + true + } } - - return context } + /** + * Make an unnamed event context with two arguments, it should manually attach to the events that needs to attach. + * + * The context lifecycle only related to the lifecycle of it attached event context. + * + * @param P1 Type of first parameter + * @param arg1 The first parameter that will be input to the parameter selective instance + * @param P2 Type of second parameter + * @param arg2 The second parameter that will be input to the parameter selective instance + * @param arising The arising trigger, default is always successes + * + * @see ConiumEvent + * @see ConiumEventContext + * @see DynamicArgs + * @see DynamicArgType + * @see ConiumEventArgTypes + * @see ParameterSelective + * @see DynamicArgsLifecycle + * @see NamedInteractionScript + * @see ConiumScriptManager.acquire + * @see ConiumScriptManager.acquireResult + * + * @return The context instance with [UNNAMED][DynamicArgsLifecycle.UNNAMED] lifecycle. + * + * @author cao_awa + * @author 草二号机 + * + * @since 1.0.0 + */ @JvmStatic @SuppressWarnings("UNCHECKED_CAST") fun unnamed( @@ -1093,18 +2399,49 @@ object ConiumEventContextBuilder { arg2: DynamicArgType, arising: ParameterSelective3 ): ConiumEventContext> { - val context = ConiumEventContext( + return ConiumEventContext( + // Require a two argument dynamic args and contract to unnamed lifecycle. DynamicArgsBuilder.requires(arg1, arg2, true).lifecycle(DynamicArgsLifecycle.UNNAMED) - ) - - context.arise { i: Any, p1: P1, p2: P2 -> - arising(i, p1, p2) - true + ).apply { + // Attach arise trigger, not event cancelable. + arise { i: Any, p1: P1, p2: P2 -> + arising(i, p1, p2) + true + } } - - return context } + /** + * Make an unnamed event context with three arguments, it should manually attach to the events that needs to attach. + * + * The context lifecycle only related to the lifecycle of it attached event context. + * + * @param P1 Type of first parameter + * @param arg1 The first parameter that will be input to the parameter selective instance + * @param P2 Type of second parameter + * @param arg2 The second parameter that will be input to the parameter selective instance + * @param P3 Type of third parameter + * @param arg3 The third parameter that will be input to the parameter selective instance + * @param arising The arising trigger, default is always successes + * + * @see ConiumEvent + * @see ConiumEventContext + * @see DynamicArgs + * @see DynamicArgType + * @see ConiumEventArgTypes + * @see ParameterSelective + * @see DynamicArgsLifecycle + * @see NamedInteractionScript + * @see ConiumScriptManager.acquire + * @see ConiumScriptManager.acquireResult + * + * @return The context instance with [UNNAMED][DynamicArgsLifecycle.UNNAMED] lifecycle. + * + * @author cao_awa + * @author 草二号机 + * + * @since 1.0.0 + */ @JvmStatic @SuppressWarnings("UNCHECKED_CAST") fun unnamed( @@ -1113,18 +2450,51 @@ object ConiumEventContextBuilder { arg3: DynamicArgType, arising: ParameterSelective4 ): ConiumEventContext> { - val context = ConiumEventContext( + return ConiumEventContext( + // Require a three argument dynamic args and contract to unnamed lifecycle. DynamicArgsBuilder.requires(arg1, arg2, arg3, true).lifecycle(DynamicArgsLifecycle.UNNAMED) - ) - - context.arise { i: Any, p1: P1, p2: P2, p3: P3 -> - arising(i, p1, p2, p3) - true + ).apply { + // Attach arise trigger, not event cancelable. + arise { i: Any, p1: P1, p2: P2, p3: P3 -> + arising(i, p1, p2, p3) + true + } } - - return context } + /** + * Make an unnamed event context with four arguments, it should manually attach to the events that needs to attach. + * + * The context lifecycle only related to the lifecycle of it attached event context. + * + * @param P1 Type of first parameter + * @param arg1 The first parameter that will be input to the parameter selective instance + * @param P2 Type of second parameter + * @param arg2 The second parameter that will be input to the parameter selective instance + * @param P3 Type of third parameter + * @param arg3 The third parameter that will be input to the parameter selective instance + * @param P4 Type of fourth parameter + * @param arg4 The fourth parameter that will be input to the parameter selective instance + * @param arising The arising trigger, default is always successes + * + * @see ConiumEvent + * @see ConiumEventContext + * @see DynamicArgs + * @see DynamicArgType + * @see ConiumEventArgTypes + * @see ParameterSelective + * @see DynamicArgsLifecycle + * @see NamedInteractionScript + * @see ConiumScriptManager.acquire + * @see ConiumScriptManager.acquireResult + * + * @return The context instance with [UNNAMED][DynamicArgsLifecycle.UNNAMED] lifecycle. + * + * @author cao_awa + * @author 草二号机 + * + * @since 1.0.0 + */ @JvmStatic @SuppressWarnings("UNCHECKED_CAST") fun unnamed( @@ -1134,18 +2504,53 @@ object ConiumEventContextBuilder { arg4: DynamicArgType, arising: ParameterSelective5 ): ConiumEventContext> { - val context = ConiumEventContext( + return ConiumEventContext( + // Require a four argument dynamic args and contract to unnamed lifecycle. DynamicArgsBuilder.requires(arg1, arg2, arg3, arg4, true).lifecycle(DynamicArgsLifecycle.UNNAMED) - ) - - context.arise { i: Any, p1: P1, p2: P2, p3: P3, p4: P4 -> - arising(i, p1, p2, p3, p4) - true + ).apply { + // Attach arise trigger, not event cancelable. + arise { i: Any, p1: P1, p2: P2, p3: P3, p4: P4 -> + arising(i, p1, p2, p3, p4) + true + } } - - return context } + /** + * Make an unnamed event context with five arguments, it should manually attach to the events that needs to attach. + * + * The context lifecycle only related to the lifecycle of it attached event context. + * + * @param P1 Type of first parameter + * @param arg1 The first parameter that will be input to the parameter selective instance + * @param P2 Type of second parameter + * @param arg2 The second parameter that will be input to the parameter selective instance + * @param P3 Type of third parameter + * @param arg3 The third parameter that will be input to the parameter selective instance + * @param P4 Type of fourth parameter + * @param arg4 The fourth parameter that will be input to the parameter selective instance + * @param P5 Type of fifth parameter + * @param arg5 The fifth parameter that will be input to the parameter selective instance + * @param arising The arising trigger, default is always successes + * + * @see ConiumEvent + * @see ConiumEventContext + * @see DynamicArgs + * @see DynamicArgType + * @see ConiumEventArgTypes + * @see ParameterSelective + * @see DynamicArgsLifecycle + * @see NamedInteractionScript + * @see ConiumScriptManager.acquire + * @see ConiumScriptManager.acquireResult + * + * @return The context instance with [UNNAMED][DynamicArgsLifecycle.UNNAMED] lifecycle. + * + * @author cao_awa + * @author 草二号机 + * + * @since 1.0.0 + */ @JvmStatic @SuppressWarnings("UNCHECKED_CAST") fun unnamed( @@ -1156,18 +2561,55 @@ object ConiumEventContextBuilder { arg5: DynamicArgType, arising: ParameterSelective6 ): ConiumEventContext> { - val context = ConiumEventContext( + return ConiumEventContext( + // Require a five argument dynamic args and contract to unnamed lifecycle. DynamicArgsBuilder.requires(arg1, arg2, arg3, arg4, arg5, true).lifecycle(DynamicArgsLifecycle.UNNAMED) - ) - - context.arise { i: Any, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5 -> - arising(i, p1, p2, p3, p4, p5) - true + ).apply { + // Attach arise trigger, not event cancelable. + arise { i: Any, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5 -> + arising(i, p1, p2, p3, p4, p5) + true + } } - - return context } + /** + * Make an unnamed event context with six arguments, it should manually attach to the events that needs to attach. + * + * The context lifecycle only related to the lifecycle of it attached event context. + * + * @param P1 Type of first parameter + * @param arg1 The first parameter that will be input to the parameter selective instance + * @param P2 Type of second parameter + * @param arg2 The second parameter that will be input to the parameter selective instance + * @param P3 Type of third parameter + * @param arg3 The third parameter that will be input to the parameter selective instance + * @param P4 Type of fourth parameter + * @param arg4 The fourth parameter that will be input to the parameter selective instance + * @param P5 Type of fifth parameter + * @param arg5 The fifth parameter that will be input to the parameter selective instance + * @param P6 Type of sixth parameter + * @param arg6 The sixth parameter that will be input to the parameter selective instance + * @param arising The arising trigger, default is always successes + * + * @see ConiumEvent + * @see ConiumEventContext + * @see DynamicArgs + * @see DynamicArgType + * @see ConiumEventArgTypes + * @see ParameterSelective + * @see DynamicArgsLifecycle + * @see NamedInteractionScript + * @see ConiumScriptManager.acquire + * @see ConiumScriptManager.acquireResult + * + * @return The context instance with [UNNAMED][DynamicArgsLifecycle.UNNAMED] lifecycle. + * + * @author cao_awa + * @author 草二号机 + * + * @since 1.0.0 + */ @JvmStatic @SuppressWarnings("UNCHECKED_CAST") fun unnamed( @@ -1179,18 +2621,57 @@ object ConiumEventContextBuilder { arg6: DynamicArgType, arising: ParameterSelective7 ): ConiumEventContext> { - val context = ConiumEventContext( + return ConiumEventContext( + // Require a six argument dynamic args and contract to unnamed lifecycle. DynamicArgsBuilder.requires(arg1, arg2, arg3, arg4, arg5, arg6, true).lifecycle(DynamicArgsLifecycle.UNNAMED) - ) - - context.arise { i: Any, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6 -> - arising(i, p1, p2, p3, p4, p5, p6) - true + ).apply { + // Attach arise trigger, not event cancelable. + arise { i: Any, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6 -> + arising(i, p1, p2, p3, p4, p5, p6) + true + } } - - return context } + /** + * Make an unnamed event context with seven arguments, it should manually attach to the events that needs to attach. + * + * The context lifecycle only related to the lifecycle of it attached event context. + * + * @param P1 Type of first parameter + * @param arg1 The first parameter that will be input to the parameter selective instance + * @param P2 Type of second parameter + * @param arg2 The second parameter that will be input to the parameter selective instance + * @param P3 Type of third parameter + * @param arg3 The third parameter that will be input to the parameter selective instance + * @param P4 Type of fourth parameter + * @param arg4 The fourth parameter that will be input to the parameter selective instance + * @param P5 Type of fifth parameter + * @param arg5 The fifth parameter that will be input to the parameter selective instance + * @param P6 Type of sixth parameter + * @param arg6 The sixth parameter that will be input to the parameter selective instance + * @param P7 Type of seventh parameter + * @param arg7 The seventh parameter that will be input to the parameter selective instance + * @param arising The arising trigger, default is always successes + * + * @see ConiumEvent + * @see ConiumEventContext + * @see DynamicArgs + * @see DynamicArgType + * @see ConiumEventArgTypes + * @see ParameterSelective + * @see DynamicArgsLifecycle + * @see NamedInteractionScript + * @see ConiumScriptManager.acquire + * @see ConiumScriptManager.acquireResult + * + * @return The context instance with [UNNAMED][DynamicArgsLifecycle.UNNAMED] lifecycle. + * + * @author cao_awa + * @author 草二号机 + * + * @since 1.0.0 + */ @JvmStatic @SuppressWarnings("UNCHECKED_CAST") fun unnamed( @@ -1203,15 +2684,15 @@ object ConiumEventContextBuilder { arg7: DynamicArgType, arising: ParameterSelective8 ): ConiumEventContext> { - val context = ConiumEventContext( + return ConiumEventContext( + // Require a seven argument dynamic args and contract to unnamed lifecycle. DynamicArgsBuilder.requires(arg1, arg2, arg3, arg4, arg5, arg6, arg7, true).lifecycle(DynamicArgsLifecycle.UNNAMED) - ) - - context.arise { i: Any, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7 -> - arising(i, p1, p2, p3, p4, p5, p6, p7) - true + ).apply { + // Attach arise trigger, not event cancelable. + arise { i: Any, p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7 -> + arising(i, p1, p2, p3, p4, p5, p6, p7) + true + } } - - return context } } diff --git a/src/main/java/com/github/cao/awa/conium/item/ConiumItem.kt b/src/main/java/com/github/cao/awa/conium/item/ConiumItem.kt index 0541fe6..22d565b 100644 --- a/src/main/java/com/github/cao/awa/conium/item/ConiumItem.kt +++ b/src/main/java/com/github/cao/awa/conium/item/ConiumItem.kt @@ -1,6 +1,7 @@ package com.github.cao.awa.conium.item import com.github.cao.awa.conium.item.builder.ConiumItemBuilder +import com.github.cao.awa.conium.item.setting.ConiumItemSettings import com.github.cao.awa.conium.kotlin.extent.component.acquire import com.github.cao.awa.conium.kotlin.extent.item.components import com.github.cao.awa.conium.random.ConiumRandom @@ -14,29 +15,24 @@ import net.minecraft.item.ItemStack import net.minecraft.util.math.BlockPos import net.minecraft.world.World import org.apache.logging.log4j.LogManager +import org.apache.logging.log4j.Logger -class ConiumItem(settings: Settings) : Item(settings) { +class ConiumItem(private val settings: ConiumItemSettings) : Item(settings.vanillaSettings) { companion object { - private val LOGGER = LogManager.getLogger("ConiumItem") + private val LOGGER: Logger = LogManager.getLogger("ConiumItem") - fun create(builder: ConiumItemBuilder, settings: Settings): ConiumItem { + fun create(builder: ConiumItemBuilder, settings: ConiumItemSettings): ConiumItem { builder.templates.forEach { - it.settings(settings) + it.prepare(settings) } - forceOverrideSettings(settings) + forceOverrideSettings(settings.vanillaSettings) - val item = ConiumItem(settings) + return ConiumItem(settings).apply { + builder.templates.forEach { it.attach(this) } - builder.templates.forEach { - it.attach(item) - } - - builder.templates.forEach { - it.complete(item) + builder.templates.forEach { it.complete(this) } } - - return item } private fun forceOverrideSettings(settings: Settings) { @@ -46,34 +42,6 @@ class ConiumItem(settings: Settings) : Item(settings) { } } - /** - * The predicate to checks the block that can be mined by this item, in vanilla is always mineable if not specify. - * - * @author cao_awa - * - * @see canMine - * - * @since 1.0.0 - */ - var canMinePredicate: (Item, BlockState, World, BlockPos, PlayerEntity) -> Boolean = { _, _, _, _, _ -> true } - - /** - * A mark that marked a tool item be a weapon, used in durability decrements when hitting entity. - * - * In vanilla has a difference to decrements durability amounts which item is weapon or non-weapon. - * - * @author cao_awa - * - * @see postDamageEntity - * - * @since 1.0.0 - */ - var isWeapon: Boolean = false - var shouldPostHit: Boolean = false - var durabilityDamageChance: IntRange? = null - - val durabilityDamageEntityAmount: Int get() = if (this.isWeapon) 1 else 2 - /** * Check the item is allowing to break blocks when player holding this item. * @@ -88,7 +56,7 @@ class ConiumItem(settings: Settings) : Item(settings) { * * @return whether a player can break a block while holding the item */ - override fun canMine(state: BlockState, world: World, pos: BlockPos, miner: PlayerEntity): Boolean = this.canMinePredicate(this, state, world, pos, miner) + override fun canMine(state: BlockState, world: World, pos: BlockPos, miner: PlayerEntity): Boolean = this.settings.canMinePredicate(this, state, world, pos, miner) /** * Called on the server when the item is used to break a block. @@ -112,7 +80,7 @@ class ConiumItem(settings: Settings) : Item(settings) { */ override fun postMine(stack: ItemStack, world: World, state: BlockState, pos: BlockPos, miner: LivingEntity): Boolean { // If damage chance present, then try to roll a chance, or else direct allow to damage the item. - val canDamage: Boolean = this.durabilityDamageChance?.let { + val canDamage: Boolean = this.settings.durabilityDamageChance?.let { // Rolling chance using world random. ConiumRandom.tryChance(it, world.random) } ?: true @@ -136,7 +104,7 @@ class ConiumItem(settings: Settings) : Item(settings) { * * @return whether the item's use stat should be incremented */ - override fun postHit(stack: ItemStack, target: LivingEntity, attacker: LivingEntity): Boolean = this.shouldPostHit + override fun postHit(stack: ItemStack, target: LivingEntity, attacker: LivingEntity): Boolean = this.settings.shouldPostHit /** * Make the tool item durability decrement, for vanilla behaviors, decrement amount in weapon is 1, in non-weapon tool is 2. @@ -152,9 +120,17 @@ class ConiumItem(settings: Settings) : Item(settings) { override fun postDamageEntity(stack: ItemStack, target: LivingEntity, attacker: LivingEntity) { // Apply durability decrement for this tool stack. stack.damage( - this.durabilityDamageEntityAmount, + this.settings.durabilityDamageEntityAmount, attacker, EquipmentSlot.MAINHAND ) } + + override fun getMiningSpeed(stack: ItemStack, state: BlockState): Float { + return if (this.settings.forceMiningSpeed == -1F) { + super.getMiningSpeed(stack, state) + } else { + this.settings.forceMiningSpeed + } + } } diff --git a/src/main/java/com/github/cao/awa/conium/item/setting/ConiumItemSettings.kt b/src/main/java/com/github/cao/awa/conium/item/setting/ConiumItemSettings.kt new file mode 100644 index 0000000..e4e35ac --- /dev/null +++ b/src/main/java/com/github/cao/awa/conium/item/setting/ConiumItemSettings.kt @@ -0,0 +1,114 @@ +package com.github.cao.awa.conium.item.setting + +import com.github.cao.awa.conium.item.template.ConiumItemTemplate +import com.github.cao.awa.conium.item.template.durability.ConiumDurabilityTemplate +import com.github.cao.awa.conium.setting.ConiumSettings +import net.minecraft.block.BlockState +import net.minecraft.entity.player.PlayerEntity +import net.minecraft.item.Item +import net.minecraft.util.math.BlockPos +import net.minecraft.world.World + +object ConiumItemSettingsValue { + val canMinePredicate: (Item, BlockState, World, BlockPos, PlayerEntity) -> Boolean = { _, _, _, _, _ -> true } + val isWeapon: Boolean = false + val shouldPostHit: Boolean = false + val durabilityDamageChance: IntRange = ConiumDurabilityTemplate.defaultChance + val forceMiningSpeed: Float = -1F +} + +abstract class ConiumAbstractItemSettings>(val vanillaSettings: Item.Settings) : ConiumSettings, B>() { + /** + * The predicate to checks the block that can be mined by this item, in vanilla is always mineable if not specify. + * + * @author cao_awa + * + * @see canMine + * + * @since 1.0.0 + */ + var canMinePredicate: (Item, BlockState, World, BlockPos, PlayerEntity) -> Boolean + get() = this._canMinePredicate ?: ConiumItemSettingsValue.canMinePredicate + set(value) { + this._canMinePredicate = value + } + + // The delegate. + private var _canMinePredicate: ((Item, BlockState, World, BlockPos, PlayerEntity) -> Boolean)? = null + + /** + * A mark that marked a tool item be a weapon, used in durability decrements when hitting entity. + * + * In vanilla has a difference to decrements durability amounts which item is weapon or non-weapon. + * + * @author cao_awa + * + * @see postDamageEntity + * + * @since 1.0.0 + */ + var isWeapon: Boolean + get() = this._isWeapon ?: ConiumItemSettingsValue.isWeapon + set(value) { + this._isWeapon = value + } + + // The delegate. + private var _isWeapon: Boolean? = null + + var shouldPostHit: Boolean + get() = this._shouldPostHit ?: ConiumItemSettingsValue.shouldPostHit + set(value) { + this._shouldPostHit = value + } + + // The delegate. + private var _shouldPostHit: Boolean? = null + + var durabilityDamageChance: IntRange + get() = this._durabilityDamageChance ?: ConiumItemSettingsValue.durabilityDamageChance + set(value) { + this._durabilityDamageChance = value + } + + // The delegate. + private var _durabilityDamageChance: IntRange? = null + + val durabilityDamageEntityAmount: Int + get() = if (this.isWeapon) 1 else 2 + + var forceMiningSpeed: Float + get() = this._forceMiningSpeed ?: ConiumItemSettingsValue.forceMiningSpeed + set(value) { + this._forceMiningSpeed = value + } + + // The delegate. + private var _forceMiningSpeed: Float? = null + + override fun migrateTo(settings: B): B { + return settings.also { + // Apply settings(only configured, no default). + this._canMinePredicate?.apply { it.canMinePredicate = this } + this._isWeapon?.apply { it.isWeapon = this } + this._shouldPostHit?.apply { it.shouldPostHit = this } + this._durabilityDamageChance?.apply { it.durabilityDamageChance = this } + this._forceMiningSpeed?.apply { it.forceMiningSpeed = this } + } + } +} + +class ConiumItemSettings(vanillaSettings: Item.Settings) : ConiumAbstractItemSettings(vanillaSettings) { + companion object { + @JvmStatic + fun create(templates: MutableList, settings: Item.Settings): ConiumItemSettings { + return ConiumItemSettings(settings).also { + templates.forEach { template -> + template.prepare(it) + } + } + } + } + + override fun newInstance(): ConiumItemSettings = ConiumItemSettings(this.vanillaSettings) +} diff --git a/src/main/java/com/github/cao/awa/conium/item/template/ConiumItemTemplate.kt b/src/main/java/com/github/cao/awa/conium/item/template/ConiumItemTemplate.kt index d7810f7..dc16516 100644 --- a/src/main/java/com/github/cao/awa/conium/item/template/ConiumItemTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/item/template/ConiumItemTemplate.kt @@ -1,12 +1,13 @@ package com.github.cao.awa.conium.item.template import com.github.cao.awa.conium.item.ConiumItem +import com.github.cao.awa.conium.item.setting.ConiumItemSettings import com.github.cao.awa.conium.template.ConiumTemplate import net.minecraft.item.Item import net.minecraft.item.consume.UseAction import net.minecraft.util.Rarity -abstract class ConiumItemTemplate(isClient: Boolean = false, name: String) : ConiumTemplate(isClient, name) { +abstract class ConiumItemTemplate(isClient: Boolean = false, name: String) : ConiumTemplate(isClient, name) { companion object { fun createRarity(name: String): Rarity { return when (name) { @@ -50,7 +51,8 @@ abstract class ConiumItemTemplate(isClient: Boolean = false, name: String) : Con // Do nothing. } - override fun prepare(target: Item.Settings) { + override fun prepare(target: ConiumItemSettings) { + settings(target.vanillaSettings) settings(target) } @@ -59,4 +61,10 @@ abstract class ConiumItemTemplate(isClient: Boolean = false, name: String) : Con open fun settings(settings: Item.Settings) { // Do nothing. } + + // Do not call settings directly. + // Use 'prepare'. + open fun settings(settings: ConiumItemSettings) { + // Do nothing. + } } diff --git a/src/main/java/com/github/cao/awa/conium/item/template/tool/mining/ConiumForceMiningSpeedTemplate.kt b/src/main/java/com/github/cao/awa/conium/item/template/tool/mining/ConiumForceMiningSpeedTemplate.kt new file mode 100644 index 0000000..4550694 --- /dev/null +++ b/src/main/java/com/github/cao/awa/conium/item/template/tool/mining/ConiumForceMiningSpeedTemplate.kt @@ -0,0 +1,19 @@ +package com.github.cao.awa.conium.item.template.tool.mining + +import com.github.cao.awa.conium.item.setting.ConiumItemSettings +import com.github.cao.awa.conium.item.template.ConiumItemTemplate +import com.github.cao.awa.conium.template.ConiumTemplates.Item +import com.google.gson.JsonElement +import net.minecraft.registry.RegistryWrapper.WrapperLookup + +open class ConiumForceMiningSpeedTemplate(private val miningSpeed: Int) : ConiumItemTemplate(name = Item.FORCE_MINING_SPEED) { + companion object { + @JvmStatic + fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumForceMiningSpeedTemplate = ConiumForceMiningSpeedTemplate(element.asInt) + } + + override fun settings(settings: ConiumItemSettings) { + // Set mining speed. + settings.forceMiningSpeed = this.miningSpeed + } +} diff --git a/src/main/java/com/github/cao/awa/conium/kotlin/extent/block/ConiumBlockKotlinExtents.kt b/src/main/java/com/github/cao/awa/conium/kotlin/extent/block/ConiumBlockKotlinExtents.kt index 92f2d23..ff9380b 100644 --- a/src/main/java/com/github/cao/awa/conium/kotlin/extent/block/ConiumBlockKotlinExtents.kt +++ b/src/main/java/com/github/cao/awa/conium/kotlin/extent/block/ConiumBlockKotlinExtents.kt @@ -14,7 +14,7 @@ fun ConiumBlockBuilder.register(afterAction: (ConiumBlock) -> Unit) { afterAction( Blocks.register( blockKeyOf(this.identifier), - { settings -> + { settings: AbstractBlock.Settings -> build( ConiumBlockSettings.create( this.templates, diff --git a/src/main/java/com/github/cao/awa/conium/kotlin/extent/item/ConiumItemKotlinExtents.kt b/src/main/java/com/github/cao/awa/conium/kotlin/extent/item/ConiumItemKotlinExtents.kt index 0888e3c..3b1301a 100644 --- a/src/main/java/com/github/cao/awa/conium/kotlin/extent/item/ConiumItemKotlinExtents.kt +++ b/src/main/java/com/github/cao/awa/conium/kotlin/extent/item/ConiumItemKotlinExtents.kt @@ -12,10 +12,9 @@ import net.minecraft.item.Items import net.minecraft.registry.RegistryKey import net.minecraft.registry.RegistryKeys import net.minecraft.registry.entry.RegistryEntry -import net.minecraft.registry.tag.TagKey import net.minecraft.util.Identifier -fun ConiumSchemaItemBuilder.register(tagProvider: (MutableSet>) -> Unit = { }) { +fun ConiumSchemaItemBuilder.register() { registerItem(this.identifier, ::build) } diff --git a/src/main/java/com/github/cao/awa/conium/network/packet/client/configuration/registry/SynchronizeRegistryPayload.kt b/src/main/java/com/github/cao/awa/conium/network/packet/client/configuration/registry/SynchronizeRegistryPayload.kt index 28ae304..c1d4f64 100644 --- a/src/main/java/com/github/cao/awa/conium/network/packet/client/configuration/registry/SynchronizeRegistryPayload.kt +++ b/src/main/java/com/github/cao/awa/conium/network/packet/client/configuration/registry/SynchronizeRegistryPayload.kt @@ -70,22 +70,22 @@ class SynchronizeRegistryPayload : ConiumClientConfigurationPacket(IDENTIFIER) { Conium.pendingDatapack.datapacks.let { datapacks -> datapacks[ConiumRegistryKeys.ITEM.value]?.let { datapack -> + Conium.coniumItemManager!!.resetRegistries() for ((identifier: Identifier, content: String) in datapack.contents) { - Conium.coniumItemManager!!.resetRegistries() Conium.coniumItemManager!!.load(identifier, JsonParser.parseString(content).asJsonObject) } } datapacks[ConiumRegistryKeys.BLOCK.value]?.let { datapack -> + Conium.coniumBlockManager!!.resetRegistries() for ((identifier: Identifier, content: String) in datapack.contents) { - Conium.coniumBlockManager!!.resetRegistries() Conium.coniumBlockManager!!.load(identifier, JsonParser.parseString(content).asJsonObject) } } datapacks[ConiumRegistryKeys.ENTITY.value]?.let { datapack -> + Conium.coniumEntityManager!!.resetRegistries() for ((identifier: Identifier, content: String) in datapack.contents) { - Conium.coniumEntityManager!!.resetRegistries() Conium.coniumEntityManager!!.load(identifier, JsonParser.parseString(content).asJsonObject) } } diff --git a/src/main/java/com/github/cao/awa/conium/parameter/DynamicArgsLifecycle.kt b/src/main/java/com/github/cao/awa/conium/parameter/DynamicArgsLifecycle.kt index 78ca033..82c017a 100644 --- a/src/main/java/com/github/cao/awa/conium/parameter/DynamicArgsLifecycle.kt +++ b/src/main/java/com/github/cao/awa/conium/parameter/DynamicArgsLifecycle.kt @@ -1,8 +1,39 @@ package com.github.cao.awa.conium.parameter enum class DynamicArgsLifecycle { + /** + * The once contract mean the dynamic args should invalidate after once arising. + * + * @author cao_awa + * + * @since 1.0.0 + */ ONCE, + + /** + * The transform contract mean the dynamic args should only arise in args transforming. + * + * @author cao_awa + * + * @since 1.0.0 + */ TRANSFORM, + + /** + * The forever contract mean the dynamic args will always reusable until the environment reset. + * + * @author cao_awa + * + * @since 1.0.0 + */ FOREVER, + + /** + * The unnamed contract mean the dynamic args should only arise in something attaches or additional arising. + * + * @author cao_awa + * + * @since 1.0.0 + */ UNNAMED; } diff --git a/src/main/java/com/github/cao/awa/conium/parameter/ParameterSelective.kt b/src/main/java/com/github/cao/awa/conium/parameter/ParameterSelective.kt index bb9334a..e203c90 100644 --- a/src/main/java/com/github/cao/awa/conium/parameter/ParameterSelective.kt +++ b/src/main/java/com/github/cao/awa/conium/parameter/ParameterSelective.kt @@ -1,3 +1,24 @@ package com.github.cao.awa.conium.parameter -interface ParameterSelective +/** + * The parameter selectable and arise-able interface, that contract some arguments and let context arises. + * + * @see DynamicArgs + * @see DynamicArgType + * @see DynamicArgsBuilder + * @see DynamicArgsLifecycle + * @see ParameterSelective0 + * @see ParameterSelective1 + * @see ParameterSelective2 + * @see ParameterSelective3 + * @see ParameterSelective4 + * @see ParameterSelective5 + * @see ParameterSelective6 + * @see ParameterSelective7 + * @see ParameterSelective8 + * + * @author cao_awa + * + * @since 1.0.0 + */ +interface ParameterSelective \ No newline at end of file diff --git a/src/main/java/com/github/cao/awa/conium/template/ConiumTemplates.kt b/src/main/java/com/github/cao/awa/conium/template/ConiumTemplates.kt index 40e0f8d..a806fb1 100644 --- a/src/main/java/com/github/cao/awa/conium/template/ConiumTemplates.kt +++ b/src/main/java/com/github/cao/awa/conium/template/ConiumTemplates.kt @@ -47,6 +47,7 @@ import com.github.cao.awa.conium.item.template.rarity.epic.ConiumUncommonRarityT import com.github.cao.awa.conium.item.template.stack.count.ConiumStackMaxCountTemplate import com.github.cao.awa.conium.item.template.tool.ConiumItemToolTemplate import com.github.cao.awa.conium.item.template.tool.axe.* +import com.github.cao.awa.conium.item.template.tool.mining.ConiumForceMiningSpeedTemplate import com.github.cao.awa.conium.item.template.tool.pickaxe.* import com.github.cao.awa.conium.recipe.template.bedrock.furnace.ConiumBedrockRecipeFurnaceTemplate import com.github.cao.awa.conium.recipe.template.bedrock.shape.ConiumBedrockRecipeShapedTemplate @@ -106,6 +107,9 @@ object ConiumTemplates { const val DIAMOND_PICKAXE: String = "diamond_pickaxe" const val NETHERITE_PICKAXE: String = "netherite_pickaxe" + // Mining speed + const val FORCE_MINING_SPEED: String = "force_mining_speed" + fun initItemTemplates() { // Spawn egg. registerItem( @@ -198,6 +202,12 @@ object ConiumTemplates { ConiumItemNetheritePickaxeTemplate::create ) + // Mining speed. + registerItem( + FORCE_MINING_SPEED, + ConiumForceMiningSpeedTemplate::create + ) + // Rarity. registerItem( RARITY,