From 54276dbab161ffd389a9ab41f139f1fdef2262eb Mon Sep 17 00:00:00 2001 From: Niklas Date: Sat, 7 Dec 2019 15:59:21 +0100 Subject: [PATCH] initial commit --- .gitignore | 71 +++++++++++++++++++++++++++++++++++++ .idea/.gitignore | 2 ++ .idea/artifacts/pid_jar.xml | 9 +++++ .idea/misc.xml | 6 ++++ .idea/modules.xml | 8 +++++ .idea/vcs.xml | 6 ++++ pid.iml | 22 ++++++++++++ src/pid/Main.java | 50 ++++++++++++++++++++++++++ src/plugin.yml | 5 +++ 9 files changed, 179 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/.gitignore create mode 100644 .idea/artifacts/pid_jar.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 pid.iml create mode 100644 src/pid/Main.java create mode 100644 src/plugin.yml 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