The GUI is always opened by the server, it sends the packet to the client telling it to open the GUI. 
The GUI code is fine, it's the Inventory and setting the state I'm worried about.