Skip to content

Commit 94229cd

Browse files
authored
Adding GetEffects (JaylyDev#175)
* Create chat-rank.js * Add files via upload * Update impact_of_removing_runCommand.md * Delete impact_of_removing_runCommand.md * Create index.js * Create README.md * Update index.js
1 parent 70f42d3 commit 94229cd

2 files changed

Lines changed: 66 additions & 0 deletions

File tree

scripts/get-effects/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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)

scripts/get-effects/index.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
};

0 commit comments

Comments
 (0)