Geting armor stands on server start

My plugin likes to throw away it’s old armor stands and make new ones every time the server starts, but I’m having trouble getting a list of armor stands and being able to remove them selectively. I’m doing this inside of GameStartedEvent. The code for this is on GitHub for HuskyCrates inside the main class. Mind the mess :stuck_out_tongue:

I don’t understand your problem, do these two if clauses always succeed and result in all ArmorStand being removed?

The issue is that the armor stands don’t “exist” after the server has started.

EntityUniverse#getEntities() can’t find what isn’t loaded - if the chunk that the armour stand is in is not loaded, then the armour stand itself won’t be obtainable. So, it might find things around spawn, but away from spawn, they won’t get found at all.

You might be better off using the SpawnEntityEvent.ChunkLoad event to do this, or one of the other entity construction events.

1 Like

Thanks for the tip spiral. I’ll give that a shot and see how my stuff turns out that way.

removing old, and adding new on chunk loads, and removing on chunk unload is the way to go.

It’s such a common pattern I thought about making some generic collections classes that already had listeners, and could build the objects that needed to track entities.

1 Like

That would be nice. When I’m testing I usually unsafely kill my servers so generally I don’t test the chunk unloading. I’ll have to implement that.