Ok, this is a very weird bug. First the code: Code: javax.swing.Timer timer = new javax.swing.Timer(1000, new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { if (ongame == true) { //some non-related code temp -=1; if (temp== 0) { plugin.getServer().shutdown(); } } } }); Sometimes the servers closes before the time gets to 0. I don't understand why, but it's totally random and i am a bit confused about this
Schedulers was designed for these purposes, use what is provided https://blogs.oracle.com/dholmes/entry/inside_the_hotspot_vm_clocks
Additionally, the Timer object executes its code through a background thread. From the javadocs: A lot of issues can occur when executing from anything but the main thread. Like gomeow said, use what is provided.