Skip to content

Instantly share code, notes, and snippets.

@csh
Last active October 17, 2016 15:17
Show Gist options
  • Save csh/fcb8cec6c97cd259bb72 to your computer and use it in GitHub Desktop.
Save csh/fcb8cec6c97cd259bb72 to your computer and use it in GitHub Desktop.
package ninja.smirking.demo.shutdown;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.logging.Level;
import java.util.regex.Pattern;
/**
* @author Connor Spencer Harries
*/
public class ShutdownDetector extends JavaPlugin {
private static final Pattern SERVER_CLASS_PATTERN = Pattern.compile("net\.minecraft\.server\.v[0-9]_[0-9]_R[0-9]\.MinecraftServer");
@Override
public void onDisable() {
StackTraceElement[] elements = Thread.currentThread().getStackTrace();
if(elements.length >= 7) {
StackTraceElement element = elements[7];
if(element.getMethodName().equals("stop") && SERVER_CLASS_PATTERN.matcher(element.getClassName()).matches()) {
getLogger().log(Level.INFO, "Bukkit is shutting down.");
return;
}
}
getLogger().log(Level.INFO, "Bukkit isn't shutting down.");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment