Jump to content

Recommended Posts

Posted

I'm getting a null pointer exception in this function:

 

public void processCommand(ICommandSender sender, String[] args) {

        if(args.length == 0){

            PlayerWallet wallet = PlayerWallet.get((EntityPlayer) sender);

            ((EntityPlayer) sender).addChatComponentMessage(new ChatComponentText("£" + wallet.getWallet()));

 

        }

   

i know the error occurs at "wallet.getWallet()". i just can't work out what is causing the error :/

 

suggestions?

 

the Player wallet class:

 

public class PlayerWallet implements IExtendedEntityProperties {

 

    public final static String EXT_PROP_NAME = "PlayerWallet";

    private double funds;

 

 

    public void init(Entity entity, World world){

 

        funds = 0;

 

    }

 

 

 

    public void loadNBTData(NBTTagCompound nbt){

 

        NBTTagCompound properties = (NBTTagCompound) nbt.getTag(EXT_PROP_NAME);

        properties.getDouble("funds");

    }

 

 

    public void saveNBTData(NBTTagCompound nbt){

        NBTTagCompound properties = new NBTTagCompound();

        properties.setDouble("funds", funds);

        nbt.setTag(EXT_PROP_NAME, properties);

    }

 

 

    public static final PlayerWallet get(EntityPlayer player)

    {

        return (PlayerWallet) player.getExtendedProperties(EXT_PROP_NAME);

    }

 

 

    public static final void register(EntityPlayer player)

    {

        player.registerExtendedProperties(PlayerWallet.EXT_PROP_NAME, new PlayerWallet());

    }

 

    public double getWallet(){

 

        return funds;

    }

    public double addFunds(double f){

 

        funds += f;

        return getWallet();

    }

    public double setFunds(double f){

        funds = f;

        return funds;

    }

    public double removeFunds(double f){

        funds -=f;

        return funds;

    }

 

}

 

The Event handler class:

 

public class MconomyEventHandler {

 

    @EventHandler

    public void onEntityConstructing(EntityEvent.EntityConstructing event)

    {

/*

Be sure to check if the entity being constructed is the correct type for the extended properties you're about to add! The null check may not be necessary - I only use it to make sure properties are only registered once per entity

*/

        if (event.entity instanceof EntityPlayer && PlayerWallet.get((EntityPlayer) event.entity) == null)

// This is how extended properties are registered using our convenient method from earlier

            PlayerWallet.register((EntityPlayer) event.entity);

// That will call the constructor as well as cause the init() method

// to be called automatically

    }

 

 

}

 

the event is registered here:

 

@EventHandler

    public void init(FMLInitializationEvent event)

    {

// some example code

        MinecraftForge.EVENT_BUS.register(new MconomyEventHandler());

    }

 

 

i would really appreciate if anyone can solve this problem for me :)

Posted

I added those 2 bits of code to the end of the first post

@EventHandler is only for the FML events involved in the mod loading process - all other events use @SubscribeEvent.

 

Next time something doesn't seem to be working, put a println statement inside and watch your console - if it doesn't print, you then have more knowledge of what the problem might be.

 

E.g.

@EventHandler
public void onEntityConstructing(EntityConstructing event) {
System.out.println("Entity is constructing."); // Doesn't print, so you know the problem has to do with your event
}

 

Also, for code, either use [ code ]code here[ / code ] tags (without spaces) or a service like pastebin - it makes it far more readable.

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • This is my crash log and i dont know what anything means [22:05:56] [main/WARN]:Force-disabling mixin 'features.render.entity.CuboidMixin' as rule 'mixin.features.render.entity' (added by mods [oculus]) disables it and children [22:05:56] [main/WARN]:Force-disabling mixin 'features.render.entity.ModelPartMixin' as rule 'mixin.features.render.entity' (added by mods [oculus]) disables it and children [22:05:56] [main/WARN]:Force-disabling mixin 'features.render.entity.cull.EntityRendererMixin' as rule 'mixin.features.render.entity' (added by mods [oculus]) disables it and children [22:05:56] [main/WARN]:Force-disabling mixin 'features.render.entity.shadows.EntityRenderDispatcherMixin' as rule 'mixin.features.render.entity' (added by mods [oculus]) disables it and children [22:05:56] [main/WARN]:Force-disabling mixin 'features.render.gui.font.GlyphRendererMixin' as rule 'mixin.features.render.gui.font' (added by mods [oculus]) disables it and children [22:05:56] [main/WARN]:Force-disabling mixin 'features.render.world.sky.BackgroundRendererMixin' as rule 'mixin.features.render.world.sky' (added by mods [oculus]) disables it and children [22:05:56] [main/WARN]:Force-disabling mixin 'features.render.world.sky.ClientWorldMixin' as rule 'mixin.features.render.world.sky' (added by mods [oculus]) disables it and children [22:05:56] [main/WARN]:Force-disabling mixin 'features.render.world.sky.WorldRendererMixin' as rule 'mixin.features.render.world.sky' (added by mods [oculus]) disables it and children [22:05:57] [main/INFO]:Patching IForgeItemStack#getEnchantmentLevel [22:05:57] [main/INFO]:Patching IForgeItemStack#getEnchantmentLevel [22:06:00] [main/INFO]:Loaded config for: betterfpsdist.json [22:06:02] [main/WARN]:Error loading class: me/jellysquid/mods/sodium/client/render/vertex/buffer/SodiumBufferBuilder (java.lang.ClassNotFoundException: me.jellysquid.mods.sodium.client.render.vertex.buffer.SodiumBufferBuilder) [22:06:02] [main/WARN]:@Mixin target me.jellysquid.mods.sodium.client.render.vertex.buffer.SodiumBufferBuilder was not found mixins.oculus.compat.sodium.json:vertex_format.MixinSodiumBufferBuilder [22:06:02] [main/WARN]:Error loading class: vazkii/quark/addons/oddities/inventory/BackpackMenu (java.lang.ClassNotFoundException: vazkii.quark.addons.oddities.inventory.BackpackMenu) [22:06:03] [main/INFO]:Initializing MixinExtras via com.llamalad7.mixinextras.service.MixinExtrasServiceImpl(version=0.3.6). [22:06:09] [main/INFO]:Patching IForgeItemStack#getEnchantmentLevel [22:06:09] [main/INFO]:Patching IForgeItemStack#getEnchantmentLevel [22:06:09] [main/INFO]:Patching IForgeItemStack#getEnchantmentLevel [22:06:09] [main/INFO]:Patching IForgeItemStack#getEnchantmentLevel [22:06:14] [main/WARN]:Static binding violation: PRIVATE @Overwrite method m_172993_ in rubidium.mixins.json:core.render.world.WorldRendererMixin cannot reduce visibiliy of PUBLIC target method, visibility will be upgraded.
    • I'm super new to making servers and i literally have no idea what this means LOL, any insight would be appreciated.   for context this is the first time I've loaded up the server and was met immediately with this error. https://cdn.discordapp.com/attachments/878466718425579520/1310810580671795260/image_2024-11-25_213313949.png?ex=674692fc&is=6745417c&hm=22fd87a5727db2cb485a89ecd3cdd133ef86d6995b518a9f8a4ad1e9bc955d09&
    • No, every one of the [REDACTED]'s represent a single word, like a name, or a user ID. For special characters, none of the [REDACTED]'s had any special characters in them. So, in reality, they were all a single entity (string of regular characters, or numbers). Some examples: "1234567abcdefg" or "aNameOfaPerson52".
    • So I had other people in the server go into creative and they are not having any issues, it is only me   
    • [ Five Months Later ] Did you, perchance, make any progress on this?  I'm on 1.21.1 and am experiencing the same inability to find "Direction" in net.minecraft.core -- BlockPos from the same package, fine!  The Direction Enum, nope. I don't think I have the patience to deal with the IntelliJ reporting an increasing number of not-really-errors.
  • Topics

×
×
  • Create New...

Important Information

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