commit 54276dbab161ffd389a9ab41f139f1fdef2262eb Author: Niklas Date: Sat Dec 7 15:59:21 2019 +0100 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..37be74a --- /dev/null +++ b/.gitignore @@ -0,0 +1,71 @@ +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..5c98b42 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,2 @@ +# Default ignored files +/workspace.xml \ No newline at end of file diff --git a/.idea/artifacts/pid_jar.xml b/.idea/artifacts/pid_jar.xml new file mode 100644 index 0000000..fdea8ab --- /dev/null +++ b/.idea/artifacts/pid_jar.xml @@ -0,0 +1,9 @@ + + + $PROJECT_DIR$/out/artifacts/pid_jar + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..e0844bc --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..050994a --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/pid.iml b/pid.iml new file mode 100644 index 0000000..f6d6452 --- /dev/null +++ b/pid.iml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/pid/Main.java b/src/pid/Main.java new file mode 100644 index 0000000..b5299ae --- /dev/null +++ b/src/pid/Main.java @@ -0,0 +1,50 @@ +package pid; + +import org.bukkit.plugin.java.JavaPlugin; + +import java.io.*; +import java.nio.charset.StandardCharsets; +import java.util.logging.Level; + +public class Main extends JavaPlugin { + @Override + public void onEnable() { + getConfig().addDefault("PIDFile", "~/bukkit.pid"); + saveConfig(); + String pid = getPid(); + savePid(pid); + } + + @Override + public void onDisable() { + removePid(); + } + + private String getPid() { + long pid = ProcessHandle.current().pid(); + return Long.toString(pid); + } + + private void savePid(String pid) { + String pidLocation = getPidFileLocation(); + try { + PrintWriter writer = new PrintWriter(pidLocation, StandardCharsets.UTF_8); + writer.print(pid); + writer.close(); + getLogger().log(Level.INFO, "PID: " + pid); + getLogger().log(Level.INFO, "PIDFile saved in " + pidLocation); + } catch (IOException e) { + getLogger().log(Level.WARNING, "Failed to write to PID file: " + e.toString()); + } + } + + private void removePid() { + String pidLocation = getPidFileLocation(); + File file = new File(pidLocation); + file.deleteOnExit(); + } + + private String getPidFileLocation() { + return (String) getConfig().get("PIDFile"); + } +} diff --git a/src/plugin.yml b/src/plugin.yml new file mode 100644 index 0000000..a8c0036 --- /dev/null +++ b/src/plugin.yml @@ -0,0 +1,5 @@ +name: PID +version: 1.0.0 +description: Creates a PID file in /run/bukkit.pid +author: Djeeberjr +main: pid.Main