Jump to content

[SOLVED] [1.7.10] Maps and Lists clearing after startup


Recommended Posts

Posted

The subject basically says my problem. Basically I have an ArrayList that stores all of my commands for my mod and HashMaps that store the details for each command. Then there's a registry class that loops through each command and registers it with Forge. However, instead of processing the command in the processCommand() method with Forge I use a command listener which has a few checks before it passes the arguments to the command method. This is where my problem comes in. The whole beginning part works perfectly, however once I get to actually using the command for some reason the ArrayList and HashMaps have no data stored in them anymore. I can't for the life of my figure out why and I'm hoping it's something stupid that I'm just not seeing.

 

Here's my CommandManager class:

http://pastebin.com/mYTrdfmq

And then my CommandHandler class:

http://pastebin.com/9ADGSr5Z

And the class I use to loop through and register each command:

http://pastebin.com/jHMWkBLV

 

The method getLengths() is only for debug as well as most of the logging you'll see.

Posted

CommandHandler extends CommandManager

* Handler is supposed to act on data held in Manager

* You are using e.g:

if(!commands.contains(command))

The "commands" is an ArrayList that is currently in THIS CommandHandler (more precisely in Manager which you are extending).

 

CommandRegistry extends CommandManager

* Is yet another instance of Manager

* This one actually holds your registered classes/data.

 

You messed up this/other.

 

UNLESS - Note: There is possibility that I am not seeing code that is responsible for actually being exact opposite of what I am saying above (meaning: I am wrong and you just provided too few classes, you should ALWAYS post @Mod class and proxies if they are used).

 

EDIT

 

PLEASE USE 'static" keyword! This will save you from instances and is much more prefered in this case.

1.7.10 is no longer supported by forge, you are on your own.

Posted

Here's my @Mod main class. You can see I register my commands in during FMLServerStartingEvent

http://pastebin.com/uNiNQys1

And here's my CommandWrapper class:

http://pastebin.com/LKLWw4ZS

 

I think I see what you're saying.. CommandRegistry and CommandHandler are running on different instances of CommandManager and the data was only stored during the CommandRegistry instance?

 

Also are you saying I should be making all of the Maps and Lists static?

Posted

Ahh never mind I think I get what you are saying. Haha I kind of feel stupid that I didn't think of just making them static, but I guess that's how it often is. Thank you very much!

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.