Jump to content

[1.8][SOLVED] NullPointerException in IEEP


HappyKiller1O1

Recommended Posts

Alright, so I have created a way of syncing between client and server with packets. It works just fine in game, but when running this code in my event handler:

 

@SubscribeEvent
public void onEntityJoinWorld(EntityJoinWorldEvent event) {
	if(!event.entity.worldObj.isRemote && event.entity instanceof EntityPlayer && ExtendedPlayer.get((EntityPlayer)event.entity) != null) {
		ExtendedPlayer.get((EntityPlayer)event.entity).sync();
	}
}

 

I get this error during me joining:

[01:18:21] [Client thread/FATAL] [FML]: Exception caught executing FutureTask: java.util.concurrent.ExecutionException: java.lang.NullPointerException
java.util.concurrent.ExecutionException: java.lang.NullPointerException
at java.util.concurrent.FutureTask.report(Unknown Source) ~[?:1.8.0_65]
at java.util.concurrent.FutureTask.get(Unknown Source) ~[?:1.8.0_65]
at net.minecraftforge.fml.common.FMLCommonHandler.callFuture(FMLCommonHandler.java:715) [FMLCommonHandler.class:?]
at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1077) [Minecraft.class:?]
at net.minecraft.client.Minecraft.run(Minecraft.java:376) [Minecraft.class:?]
at net.minecraft.client.main.Main.main(Main.java:117) [Main.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_65]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_65]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_65]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_65]
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?]
at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_65]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_65]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_65]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_65]
at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source) [start/:?]
at GradleStart.main(Unknown Source) [start/:?]
Caused by: java.lang.NullPointerException
at com.happykiller.weightlimit.player.ExtendedPlayer.get(ExtendedPlayer.java:35) ~[ExtendedPlayer.class:?]
at com.happykiller.weightlimit.server.packet.packets.PacketSyncPlayerProps$Handler$1.run(PacketSyncPlayerProps.java:47) ~[PacketSyncPlayerProps$Handler$1.class:?]
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:1.8.0_65]
at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:1.8.0_65]
at net.minecraftforge.fml.common.FMLCommonHandler.callFuture(FMLCommonHandler.java:714) ~[FMLCommonHandler.class:?]
... 15 more

 

Here is line 35 of ExtendedPlayer:

public static final ExtendedPlayer get(EntityPlayer player) {
return (ExtendedPlayer)player.getExtendedProperties(EXT_PROP_NAME);
}

 

And here is the packet being sent to update the client:

package com.happykiller.weightlimit.server.packet.packets;

import com.happykiller.weightlimit.player.ExtendedPlayer;

import io.netty.buffer.ByteBuf;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.IThreadListener;
import net.minecraftforge.fml.common.network.ByteBufUtils;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;

public class PacketSyncPlayerProps implements IMessage {

private NBTTagCompound data;

public PacketSyncPlayerProps() {}

public PacketSyncPlayerProps(EntityPlayer player) {
	data = new NBTTagCompound();

	ExtendedPlayer.get(player).saveNBTData(data);
}

public void fromBytes(ByteBuf buf) {
	data = ByteBufUtils.readTag(buf);
}

public void toBytes(ByteBuf buf) {
	ByteBufUtils.writeTag(buf, data);
}

public static class Handler implements IMessageHandler<PacketSyncPlayerProps, IMessage> {

	public IMessage onMessage(final PacketSyncPlayerProps message, MessageContext ctx) {
		IThreadListener mainThread = Minecraft.getMinecraft();

		final EntityPlayer player = Minecraft.getMinecraft().thePlayer;

		mainThread.addScheduledTask(new Runnable() {
			public void run() {
				System.out.println("Loading client player data...");

				ExtendedPlayer.get(player).loadNBTData(message.data);
			}
		});

		return null;
	}
}
}

 

This might just be me missing something obvious, but I am really flustered on why this is happening. Any thoughts?

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.