Switch Language
  1. PowerNukkitX
  2. Get Started
  3. Config

    1. server.properties
    2. nukkit.yml
    3. pnx-cli-config.ini
    4. Anti-xray
    5. Resource Encryption
    6. Compression Acceleration
    7. PNX with WaterDogPE
    8. Flat World
  4. FAQ

    1. To Newcomers
    2. How to use PNX-CLI
    3. Common Questions
    4. Terra Questions
    5. Spawn-point Questions
    6. Convert Worlds
  5. For Devs

    1. Java

      1. Goto JavaDoc
      2. Mod API

        1. Custom Block
        2. Custom Item
        3. Custom Entity
        4. Custom Enchantment
      3. Entity AI

        1. Behavior
        2. Memory
        3. Sensor
        4. Motion Controller
        5. Navigator
        6. Behavior Group
        7. Work Cycle
    2. JavaScript

      1. setup dev env
      2. Base LLSELib dev
      3. Hello World
      4. Basic knowledge
      5. Event Listener
      6. FAQ
    3. Resources

      1. Event List
      2. IDs(block & item)

Common Development Issues

1. invokeMember (getDamager) on cn.nukkit.event.entity.EntityDamageEvent failed due to: Unknown identifier: getDamager

This is caused by mistakenly treating the EntityDamageEvent event as an EntityDamageByEntityEvent and executing the getDamager method, usually It is caused by listening to cn.nukkit.event.entity.EntityDamageByEntityEvent, but some plugins will mix up the events.

Solution: Use instanceof to determine the event type in the event callback function.

import { PowerNukkitX, EventPriority } from ":powernukkitx";
import { EntityDamageByEntityEvent } from "cn.nukkit.event.entity.EntityDamageByEntityEvent";

PowerNukkitX.listenEvent("cn.nukkit.event.entity.EntityDamageByEntityEvent", EventPriority.NORMAL, e => {
    if (e instanceof EntityDamageByEntityEvent) {
        // ......

2. Server.getLevel returns null

This is usually caused by two problems:

3. Some considerations when importing modules from other JS plugins

Each PNX-JS plugin runs in a separate Context, which means that if you import a module of another plugin using import, it will completely reload the module of the plugin being imported once.
For example, the following example is based on the LLSE-Lib library.

Observe the following code. According to the NK plugin loading rules, the APlugin plugin will be loaded before the BPlugin plugin APlugin.js

export var A;
console.log("this is A plugin");


import {A} from "APlugin.js";

where the APlugin.js console.log("this is A plugin"); will be executed twice, in the load APlugin will output once, and then load BPlugin, because the B plugin imported the APlugin plugin A variable, this will be in the B plugin Context completely loaded once A plugin which is output once again.

The onlyOnceExecute from the LLSE-Lib library is designed to solve this problem. The first parameter of onlyOnceExecute passes a callback function and the second parameter passes a UUID as a unique identifier, and this callback function will only be executed once, no matter how many plugins import the plugin.

But since each JS plugin of PNXJS is a separate Context, the B plugin imports the A variable of the APlugin plugin, which is not initialized, while the Context of the B plugin loads the A plugin completely once, but since onlyOnceExecute will only be executed once globally, the A variable in the B plugin's Context will not be initialized

© PowerNukkitX Dev team