Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fishing Hook NPCs cause an NPE if used #1702

Open
mcmonkey4eva opened this Issue Feb 16, 2019 · 0 comments

Comments

Projects
None yet
1 participant
@mcmonkey4eva
Copy link
Member

mcmonkey4eva commented Feb 16, 2019

Transferring and detailing user error from error log posted on Discord

Citizens version: Citizens v2.0.24-SNAPSHOT (build 1617)
Spigot version: 1.13.2 - Paper build 524

(Both latest at time of posting)

User error message report (snipped for length):


[00:00:51] java.lang.reflect.InvocationTargetException
(...)
net.citizensnpcs.nms.v1_13_R2.entity.MobEntityController.createEntityFromClass(MobEntityController.java:42)
[00:00:51] at net.citizensnpcs.nms.v1_13_R2.entity.MobEntityController.createEntity(MobEntityController.java:27)
[00:00:51] at net.citizensnpcs.npc.AbstractEntityController.spawn(AbstractEntityController.java:41)
[00:00:51] at net.citizensnpcs.npc.CitizensNPC.spawn(CitizensNPC.java:209)
[00:00:51] at net.citizensnpcs.npc.CitizensNPC.load(CitizensNPC.java:143)
[00:00:51] at net.citizensnpcs.api.npc.SimpleNPCDataStore.loadInto(SimpleNPCDataStore.java:59)
[00:00:51] at net.citizensnpcs.Citizens$3.run(Citizens.java:331)
[00:00:51] at org.bukkit.craftbukkit.v1_13_R2.scheduler.CraftTask.run(CraftTask.java:82)
(...)
[00:00:51] Caused by: java.lang.NullPointerException
[00:00:51] at net.minecraft.server.v1_13_R2.EntityFishingHook.a(EntityFishingHook.java:43)
[00:00:51] at net.minecraft.server.v1_13_R2.EntityFishingHook.<init>(EntityFishingHook.java:35)
[00:00:51] at net.citizensnpcs.nms.v1_13_R2.entity.nonliving.FishingHookController$EntityFishingHookNPC.<init>(FishingHookController.java:38)
[00:00:51] ... 18 more
[00:00:51] [Citizens] Task #66 for Citizens v2.0.24-SNAPSHOT (build 1617) generated an exception
[00:00:51] java.lang.NullPointerException: null
[00:00:51] at net.citizensnpcs.nms.v1_13_R2.entity.MobEntityController.createEntity(MobEntityController.java:29) ~[?:?]
[00:00:51] at net.citizensnpcs.npc.AbstractEntityController.spawn(AbstractEntityController.java:41) ~[?:?]
[00:00:51] at net.citizensnpcs.npc.CitizensNPC.spawn(CitizensNPC.java:209) ~[?:?]
[00:00:51] at net.citizensnpcs.npc.CitizensNPC.load(CitizensNPC.java:143) ~[?:?]
[00:00:51] at net.citizensnpcs.api.npc.SimpleNPCDataStore.loadInto(SimpleNPCDataStore.java:59) ~[?:?]
[00:00:51] at net.citizensnpcs.Citizens$3.run(Citizens.java:331) ~[?:?]
[00:00:51] at org.bukkit.craftbukkit.v1_13_R2.scheduler.CraftTask.run(CraftTask.java:82) ~[patched_1.13.2.jar:git-Paper-524]
(...)

Source tracing:

This code is invalid:

public EntityFishingHookNPC(World world) {
this(world, null);
}
public EntityFishingHookNPC(World world, NPC npc) {
super(world, null);
this.npc = (CitizensNPC) npc;
}

The super(world, null); calls to this NMS method:

    public EntityFishingHook(World world, EntityHuman entityhuman) {
        this(world);
        this.a(entityhuman);
        this.k();
    }
    private void a(EntityHuman entityhuman) {
        this.setSize(0.25F, 0.25F);
        this.ak = true;
        this.owner = entityhuman;
        this.owner.hookedFish = this;
    }

Note that it necessarily requires the entityhuman input to be non-null on the very last line (setting owner.hookedFish, where owner is set as entityhuman.
Since the Citizens code always feeds null, it is always an error.

The only other constructor available for EntityFishingHook is:

    private EntityFishingHook(World world) {
        super(EntityTypes.FISHING_BOBBER, world);
        this.ay = EntityFishingHook.HookState.FLYING;
    }

Which is private (making it rather difficult to use).
The a(...) method is also private, making it unavailable to override.

Possible solutions:

  • A placeholder / fake EntityHuman object to feed to the superconstructor to avoid the NPE (doesn't need to be spawned into the world I'm pretty sure, just have a Java object of that type)

Methods throughout the inside of EntityFishingHook require owner be a valid EntityHuman, so having a placeholder human to send in is probably the best solution here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.