Last active
October 17, 2016 15:17
-
-
Save csh/fcb8cec6c97cd259bb72 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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