File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # GetEffects
2+
3+ Return list of object contain ` EffectType ` class and ` Effecf ` class. This will allow us to get the effect identifier when ` Effect ` class doesn't have ` typeId ` property.
4+
5+ ## How to use?
6+
7+ ``` js
8+ import { system } from " @minecraft/server" ;
9+ import getEffects from " ./getEffects" ;
10+
11+ // Check if player has absorbtion effect
12+ system .runInterval (() => {
13+ for (const player of world .getPlayers ()) {
14+ const absorbtion = getEffects (player)
15+ .find ((eff ) => eff .effectType .getName () === " minecraft:absorbtion" );
16+ if (! absorbtion) continue ;
17+
18+ console .warn (` ${ player .name } has absorbtion` )
19+ }
20+ }, 20 )
21+ ```
22+
23+ ## Properties
24+
25+ - ` effectType: EffectType `
26+ Get effect identifier
27+ ` return ` : [ EffectType] ( https://learn.microsoft.com/en-us/minecraft/creator/scriptapi/minecraft/server/effecttype )
28+
29+ - ` effect: Effect `
30+ Get effect amplifier and duration
31+ ` return ` : [ Effect] ( https://learn.microsoft.com/en-us/minecraft/creator/scriptapi/minecraft/server/effect )
Original file line number Diff line number Diff line change 1+ // Script example for ScriptAPI
2+ // Author: FrankyRayMS <https://github.com/FrankyRay>
3+ // Project: https://github.com/JaylyDev/ScriptAPI
4+
5+ import {
6+ world ,
7+ MinecraftEffectTypes ,
8+ /* Typings only */
9+ Entity ,
10+ Player ,
11+ Effect ,
12+ EffectType
13+ } from "@minecraft/server" ;
14+
15+ /**
16+ * Get every effect from the entity
17+ *
18+ * @param {Entity|Player } entity
19+ * Entity or Player class
20+ *
21+ * @return {{ effectType: EffectType, effect: Effect }[] }
22+ */
23+ export function getEffects ( entity ) {
24+ const effectList = [ ] ;
25+ for ( const eff of Object . values ( MinecraftEffectTypes ) ) {
26+ const effect = entity . getEffect ( eff ) ;
27+ if ( ! effect ) continue ;
28+ effectList . push ( {
29+ effectType : eff ,
30+ effect : effect
31+ } ) ;
32+ } ;
33+
34+ return effectList ;
35+ } ;
You can’t perform that action at this time.
0 commit comments