Idlehumor/FullServerAFKRelief — pull request #1 by jmhertlein (2013-04-12 21:54:08+00:00)
Title: Improves efficiency and thread safety

I made three major changes:
* Switched from using native arrays (and resizing them by copying) to using Collections only
* Removed most of the checks for activity. Now only checks movement and chat actions.
* Provided for thread safety by getting intrinsic lock of collections before modifying them

Reasoning:
* Resizing arrays by copying all but the last element, then deleting the old array, is both time and memory expensive, and also results in more work for the garbage collector. Switching to using a hash map makes adding/removing elements O(1) and has minimal overhead for the gc.
* While it would be ideal to let literally any action update the player's last activity time, in the name of efficiency it's better to pick a few very important ones and only listen to them. Since most things in minecraft either involve moving or talking, it's better to just listen for movement and chat events.
* I've also moved location checking onto a task, rather than listening for a PlayerMoveEvent. This generates significantly less overhead (only checking locations every 10 seconds, as opposed to however often PlayerMoveEvent will fire when a player is moving continuously.)
* Since chat events are now async, modifying resources used by the task (which is run on the main server thread) from the chat thread requires careful treatment. I've fixed this by getting the intrinsic lock with the synchronized keyword before modifying objects that are shared between threads.

I've tested this a bit, and it works as far as I can tell.