initial commit

This commit is contained in:
Niklas 2019-12-07 15:59:21 +01:00
commit 54276dbab1
9 changed files with 179 additions and 0 deletions

71
.gitignore vendored Normal file
View File

@ -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

2
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
# Default ignored files
/workspace.xml

View File

@ -0,0 +1,9 @@
<component name="ArtifactManager">
<artifact type="jar" name="pid:jar">
<output-path>$PROJECT_DIR$/out/artifacts/pid_jar</output-path>
<root id="archive" name="pid.jar">
<element id="module-output" name="pid" />
<element id="file-copy" path="$PROJECT_DIR$/src/plugin.yml" />
</root>
</artifact>
</component>

6
.idea/misc.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/pid.iml" filepath="$PROJECT_DIR$/pid.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

22
pid.iml Normal file
View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../deps/spigot.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$MODULE_DIR$/../deps/spigot.jar!/" />
</SOURCES>
</library>
</orderEntry>
</component>
</module>

50
src/pid/Main.java Normal file
View File

@ -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");
}
}

5
src/plugin.yml Normal file
View File

@ -0,0 +1,5 @@
name: PID
version: 1.0.0
description: Creates a PID file in /run/bukkit.pid
author: Djeeberjr
main: pid.Main