-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bug of null pointer exception when requesting event context (caus…
…e by mistake method name 'arising', should be 'arise'). Fix bug of all events failures when no contexts registered. Update gradle version to '8.11' . Update dependencies versions. Prepared to release new fix version.
- Loading branch information
Showing
16 changed files
with
207 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Kotlin script | ||
Conium supported to run kotlin script in game running, called to 'Conium script'. | ||
|
||
Directly write and put the '.kts' file to ```/saves/<world>/datapacks/<pack-name>/data/script```. | ||
|
||
## Events | ||
Conium script can handles game event used to complete what you need. | ||
|
||
Use ```request``` to subscribe an event, first parameter is the type of event, for all events, see [Event types](/document/script/kotlin/event/README.md#event-types). | ||
|
||
Then other parameters is the context args, for all args type, see [Context arg types](/document/script/kotlin/event/README.md#context-args). | ||
|
||
### Arising | ||
``` kts | ||
// Shorter schema. | ||
request( | ||
SERVER_TICK, | ||
SERVER | ||
) { _, server -> | ||
// Do something here. | ||
|
||
// Here must return a boolean. | ||
// True means this event is succeed, false then means failures. | ||
true | ||
} | ||
|
||
// Full schema. | ||
// The 'arise' call be shorter as missing, but 'presage' cannot. | ||
request( | ||
SERVER_TICK, | ||
SERVER | ||
).arise { _, server -> | ||
// Do something here. | ||
|
||
// Here must return a boolean. | ||
// True means this event is succeed, false then means failures. | ||
true | ||
} | ||
``` | ||
|
||
### Presaging | ||
|
||
``` kts | ||
request( | ||
SERVER_TICK, | ||
SERVER | ||
) { _, server -> | ||
// Do something here. | ||
true | ||
}.presage { | ||
// Here must return a boolean. | ||
// The presaging is called before the event really happening, | ||
// the whole event will be canceled when the result is false. | ||
// (whole mean the event after events, like 'PLACED_BLOCK' is the after event of 'PLACE_BLOCK') | ||
true | ||
} | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
# Events in kotlin script | ||
|
||
## Event types | ||
|
||
| Key | Notes | | ||
|------------------:|:-----------------------------------:| | ||
| SERVER_TICK | Trigger in every server tick | | ||
| ITEM_USE_ON_BLOCK | Trigger when an item use on a block | | ||
| BREAK_BLOCK | Trigger when breaking block | | ||
| PLACE_BLOCK | Trigger when placing block | | ||
| PLACED_BLOCK | Trigger when block placed | | ||
| USE_BLOCK | Trigger when using block | | ||
| USED_BLOCK | Trigger when block used | | ||
|
||
## Context args | ||
|
||
Context args is the parameters starting from the second parameter in ```request```. | ||
|
||
For example: | ||
|
||
``` kts | ||
request( | ||
// This is the event type. | ||
PLACE_BLOCK, | ||
// This is the conext args. | ||
SERVER_WORLD, | ||
// This also. | ||
BLOCK_POS, | ||
// This also. | ||
ITEM_STACK | ||
) { _, world, pos, stack -> | ||
// When you defines how many context args in 'request', | ||
// then you must defines they in arising context as consistent order and quantity. | ||
true | ||
} | ||
|
||
request( | ||
// This is the event type. | ||
PLACE_BLOCK, | ||
// This is the conext args. | ||
SERVER_WORLD, | ||
// This also. | ||
ITEM_STACK | ||
) { _, world, stack -> | ||
// Here missing 'BLOCK_POS', so arising context also must missing it. | ||
// Arising context should match to 'request' required args. | ||
true | ||
} | ||
``` | ||
|
||
## Dynamic args | ||
|
||
If you are reading the source code, maybe you take seen some args doesn't pushed to ```ConiumEventContext```,\ | ||
but the required args still able to get in scripts. | ||
|
||
This is the ```DynamicArgs``` transform(or adapter) mechanism, dynamic args use other presenting args try to found required arg. | ||
|
||
For details, see [ConiumEventArgTypes](/src/main/java/com/github/cao/awa/conium/event/type/ConiumEventArgTypes.kt) and [DynamicArgsBuilder#transform](/src/main/java/com/github/cao/awa/conium/parameter/DynamicArgsBuilder.kt). | ||
|
||
If required arg is still unable to found when the dynamic args for-each to all other args and runs all transform presets,\ | ||
then this ```request``` of this event will not be arising, because the parameters of arising and presaging don't receive null value. | ||
|
||
Avoid the trouble of guessing yourself, all args possible to uses for every event is here, \ | ||
if you are finding not rarely used parameters, then you need read the ```ConiumEventArgTypes```. | ||
|
||
### SERVER_TICK | ||
|
||
SERVER | ||
|
||
### ITEM_USE_ON_BLOCK | ||
|
||
### BREAK_BLOCK | ||
|
||
### PLACE_BLOCK | ||
|
||
```ITEM_PLACEMENT_CONTEXT``` () | ||
|
||
```WORLD``` (transform from ```ITEM_PLACEMENT_CONTEXT```) \ | ||
```SERVER_WORLD``` (transform from ```ITEM_PLACEMENT_CONTEXT```) \ | ||
```CLIENT_WORLD``` (transform from ```ITEM_PLACEMENT_CONTEXT```) \ | ||
```ITEM_STACK``` (transform from ```ITEM_PLACEMENT_CONTEXT```) \ | ||
```PLAYER``` (transform from ```ITEM_PLACEMENT_CONTEXT```) \ | ||
```SERVER_PLAYER``` (transform from ```ITEM_PLACEMENT_CONTEXT```) \ | ||
```CLIENT_PLAYER``` (transform from ```ITEM_PLACEMENT_CONTEXT```) \ | ||
```BLOCK_POS``` (transform from ```ITEM_PLACEMENT_CONTEXT```) | ||
|
||
### PLACED_BLOCK | ||
|
||
### USE_BLOCK | ||
|
||
### USED_BLOCK |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.