Posted November 21, 201212 yr I'm making a mod that needs to listen to user events. Instead of checking all events to see if its entity property is X player (I assume it'd be costly), is there a way to add listeners to specific players?
November 22, 201212 yr No it wouldn't be costly as long as you do it right. I assume you want to listen to multiple players? If so, and you are worried about performance, just add the player entityID's to an ArrayList. Register onto the event bus with PlayerEvent(the most specific event for your use available), and do a if(playerList.contains(evt.entityLiving.entityID) ) first, and the performance loss should be negligible.
November 22, 201212 yr Well after reading back over this, I should point at that a HashSet has a much faster .contains lookup due to how the hash key lookup functions. ArrayLists are superior if an ordered system is required, as well as sporting faster full list iterations, however the HashSet uses a hash lookup, which means it has much faster random access. If you only need to check if your list contains the ID, then just address the entityID from the evt, use a HashSet.
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.