mastercake10 před 7 roky
rodič
revize
9364b8587b
2 změnil soubory, kde provedl 87 přidání a 4 odebrání
  1. 86 3
      src/de/Linus122/customoregen/Metrics.java
  2. 1 1
      src/plugin.yml

+ 86 - 3
src/de/Linus122/customoregen/Metrics.java

@@ -1,8 +1,15 @@
 package de.Linus122.customoregen;
 
+import java.io.BufferedReader;
 import java.io.DataOutputStream;
-import java.net.HttpURLConnection;
+import java.io.File;
+import java.io.FileReader;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.util.Arrays;
 import java.util.HashMap;
+import java.util.List;
 
 import javax.net.ssl.HttpsURLConnection;
 
@@ -10,6 +17,11 @@ import org.bukkit.plugin.Plugin;
 
 import com.google.gson.Gson;
 
+/*
+ * SpaceIOMetrics main class by Linus122
+ * version: 0.02
+ * 
+ */
 public class Metrics {
 	private Plugin pl;
 	private final Gson gson = new Gson();
@@ -18,6 +30,18 @@ public class Metrics {
 	
 	public Metrics(Plugin pl){
 		this.pl = pl;
+		
+		// check if Metrics are disabled (checks if file "disablemetrics" is added to the plugins's folder
+		try {
+			Files.list(pl.getDataFolder().getParentFile().toPath()).filter(Files::isRegularFile).forEach(v -> {
+				if(v.getFileName().toString().equalsIgnoreCase("disablemetrics")){
+					return;
+				}
+			});
+		} catch (IOException e1) {
+			e1.printStackTrace();
+		}
+
 		URL = String.format(URL, pl.getName());
 		pl.getServer().getScheduler().runTaskTimerAsynchronously(pl, () -> {
 			String dataJson = collectData();
@@ -41,6 +65,12 @@ public class Metrics {
 		// server version
 		data.serverVersion = getVersion();
 		
+		// plugin version
+		data.pluginVersion = pl.getDescription().getVersion();
+		
+		// plugin author
+		data.pluginAuthors = pl.getDescription().getAuthors();
+		
 		// core count
 		data.coreCnt = Runtime.getRuntime().availableProcessors();
 		
@@ -50,6 +80,17 @@ public class Metrics {
 		// online mode
 		data.onlineMode = pl.getServer().getOnlineMode();
 
+		// software information
+		data.osName = System.getProperty("os.name");
+		data.osArch = System.getProperty("os.arch");
+		data.osVersion = System.getProperty("os.version");
+		
+		data.diskSize = new File("/").getTotalSpace();
+		
+		if(data.osName.equals("Linux")){
+			data.linuxDistro = getDistro();
+		}
+		
 		return gson.toJson(data);
 	}
 	private void sendData(String dataJson) throws Exception{
@@ -70,13 +111,55 @@ public class Metrics {
         String packageName = pl.getServer().getClass().getPackage().getName();
         return  packageName.substring(packageName.lastIndexOf('.') + 1);
 	}
-	
+	// method source: http://www.jcgonzalez.com/linux-get-distro-from-java-examples
+	private String getDistro(){
+		 //lists all the files ending with -release in the etc folder
+        File dir = new File("/etc/");
+        File fileList[] = new File[0];
+        if(dir.exists()){
+            fileList =  dir.listFiles(new FilenameFilter() {
+                public boolean accept(File dir, String filename) {
+                    return filename.endsWith("-release");
+                }
+            });
+        }
+        //looks for the version file (not all linux distros)
+        File fileVersion = new File("/proc/version");
+        if(fileVersion.exists()){
+            fileList = Arrays.copyOf(fileList,fileList.length+1);
+            fileList[fileList.length-1] = fileVersion;
+        }       
+        //prints first version-related file
+        for (File f : fileList) {
+            try {
+                BufferedReader myReader = new BufferedReader(new FileReader(f));
+                String strLine = null;
+                while ((strLine = myReader.readLine()) != null) {
+                    return strLine;
+                }
+                myReader.close();
+            } catch (Exception e) {
+                
+            }
+        }
+		return "unknown";    
+	}
 }
 class Data {
 	HashMap<String, String> plugs = new HashMap<String, String>();
 	int onlinePlayers;
+	String pluginVersion;
+	public List<String> pluginAuthors;
 	String serverVersion;
+	
+	long diskSize;
 	int coreCnt;
 	String javaRuntime;
+	
 	boolean onlineMode;
-}
+	
+	String osName;
+	String osArch;
+	String osVersion;
+	String linuxDistro;
+}

+ 1 - 1
src/plugin.yml

@@ -1,5 +1,5 @@
 name: CustomOreGen
-version: 1.2.31
+version: 1.2.32
 description: Controls the Ore-Generator
 author: Linus122
 soft-depends: [ASkyBlock, AcidIsland, uSkyBlock]