Java Code Examples for org.bukkit.Bukkit#getVersion()

The following examples show how to use org.bukkit.Bukkit#getVersion() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GriefDefenderPlugin.java    From GriefDefender with MIT License 6 votes vote down vote up
public static int getMajorMinecraftVersion() {
    final String version = Bukkit.getVersion();
    if (version.contains("1.8.8")) {
        return 8;
    } else if (version.contains("1.12")) {
        return 12;
    } else if (version.contains("1.13")) {
        return 13;
    } else if (version.contains("1.14")) {
        return 14;
    } else if (version.contains("1.15")) {
        return 15;
    } else if (version.contains("1.16")) {
        return 16;
    }

    return -1;
}
 
Example 2
Source File: VersionCommand.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
private void obtainVersion() {
    String version = Bukkit.getVersion();
    if (version == null) version = "Custom";
    if (version.startsWith("git-Kettle-")) {
        String[] parts = version.substring("git-Kettle-".length()).split("[-\\s]");
        int distance = getDistance(null, parts[0]);
        switch (distance) {
            case -1:
                setVersionMessage("Error obtaining version information");
                break;
            case 0:
                setVersionMessage("You are running the latest version");
                break;
            case -2:
                setVersionMessage("Unknown version");
                break;
            default:
                setVersionMessage("You are " + distance + " version(s) behind");
        }
    } else if (version.startsWith("git-Bukkit-")) {
        version = version.substring("git-Bukkit-".length());
        int cbVersions = getDistance("craftbukkit", version.substring(0, version.indexOf(' ')));
        if (cbVersions == -1) {
            setVersionMessage("Error obtaining version information");
        } else {
            if (cbVersions == 0) {
                setVersionMessage("You are running the latest version");
            } else {
                setVersionMessage("You are " + cbVersions + " version(s) behind");
            }
        }
    } else {
        setVersionMessage("Unknown version, custom build?");
    }
}
 
Example 3
Source File: Metrics.java    From NametagEdit with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Gets the server specific data.
 *
 * @return The server specific data.
 */
private JSONObject getServerData() {
    // Minecraft specific data
    int playerAmount;
    try {
        // Around MC 1.8 the return type was changed to a collection from an array,
        // This fixes java.lang.NoSuchMethodError: org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection;
        Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers");
        playerAmount = onlinePlayersMethod.getReturnType().equals(Collection.class)
                ? ((Collection<?>) onlinePlayersMethod.invoke(Bukkit.getServer())).size()
                : ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length;
    } catch (Exception e) {
        playerAmount = Bukkit.getOnlinePlayers().size(); // Just use the new method if the Reflection failed
    }
    int onlineMode = Bukkit.getOnlineMode() ? 1 : 0;
    String bukkitVersion = Bukkit.getVersion();

    // OS/Java specific data
    String javaVersion = System.getProperty("java.version");
    String osName = System.getProperty("os.name");
    String osArch = System.getProperty("os.arch");
    String osVersion = System.getProperty("os.version");
    int coreCount = Runtime.getRuntime().availableProcessors();

    JSONObject data = new JSONObject();

    data.put("serverUUID", serverUUID);

    data.put("playerAmount", playerAmount);
    data.put("onlineMode", onlineMode);
    data.put("bukkitVersion", bukkitVersion);

    data.put("javaVersion", javaVersion);
    data.put("osName", osName);
    data.put("osArch", osArch);
    data.put("osVersion", osVersion);
    data.put("coreCount", coreCount);

    return data;
}
 
Example 4
Source File: MetricsLite.java    From skript-yaml with MIT License 5 votes vote down vote up
/**
 * Gets the server specific data.
 *
 * @return The server specific data.
 */
private JSONObject getServerData() {
  // Minecraft specific data
  int playerAmount = Bukkit.getOnlinePlayers().size();
  int onlineMode = Bukkit.getOnlineMode() ? 1 : 0;
  String bukkitVersion = Bukkit.getVersion();
  bukkitVersion = bukkitVersion.substring(bukkitVersion.indexOf("MC: ") + 4, bukkitVersion.length() - 1);

  // OS/Java specific data
  String javaVersion = System.getProperty("java.version");
  String osName = System.getProperty("os.name");
  String osArch = System.getProperty("os.arch");
  String osVersion = System.getProperty("os.version");
  int coreCount = Runtime.getRuntime().availableProcessors();

  JSONObject data = new JSONObject();

  data.put("serverUUID", serverUUID);

  data.put("playerAmount", playerAmount);
  data.put("onlineMode", onlineMode);
  data.put("bukkitVersion", bukkitVersion);

  data.put("javaVersion", javaVersion);
  data.put("osName", osName);
  data.put("osArch", osArch);
  data.put("osVersion", osVersion);
  data.put("coreCount", coreCount);

  return data;
}
 
Example 5
Source File: Metrics.java    From skript-yaml with MIT License 5 votes vote down vote up
/**
 * Gets the server specific data.
 *
 * @return The server specific data.
 */
private JSONObject getServerData() {
    // Minecraft specific data
    int playerAmount;
    try {
        // Around MC 1.8 the return type was changed to a collection from an array,
        // This fixes java.lang.NoSuchMethodError: org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection;
        Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers");
        playerAmount = onlinePlayersMethod.getReturnType().equals(Collection.class)
                ? ((Collection<?>) onlinePlayersMethod.invoke(Bukkit.getServer())).size()
                : ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length;
    } catch (Exception e) {
        playerAmount = Bukkit.getOnlinePlayers().size(); // Just use the new method if the Reflection failed
    }
    int onlineMode = Bukkit.getOnlineMode() ? 1 : 0;
    String bukkitVersion = Bukkit.getVersion();

    // OS/Java specific data
    String javaVersion = System.getProperty("java.version");
    String osName = System.getProperty("os.name");
    String osArch = System.getProperty("os.arch");
    String osVersion = System.getProperty("os.version");
    int coreCount = Runtime.getRuntime().availableProcessors();

    JSONObject data = new JSONObject();

    data.put("serverUUID", serverUUID);

    data.put("playerAmount", playerAmount);
    data.put("onlineMode", onlineMode);
    data.put("bukkitVersion", bukkitVersion);

    data.put("javaVersion", javaVersion);
    data.put("osName", osName);
    data.put("osArch", osArch);
    data.put("osVersion", osVersion);
    data.put("coreCount", coreCount);

    return data;
}
 
Example 6
Source File: Metrics.java    From Crazy-Crates with MIT License 4 votes vote down vote up
/**
 * Gets the server specific data.
 *
 * @return The server specific data.
 */
private JsonObject getServerData() {
    // Minecraft specific data
    int playerAmount;
    try {
        // Around MC 1.8 the return type was changed to a collection from an array,
        // This fixes java.lang.NoSuchMethodError: org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection;
        Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers");
        playerAmount = onlinePlayersMethod.getReturnType().equals(Collection.class)
        ? ((Collection<?>) onlinePlayersMethod.invoke(Bukkit.getServer())).size()
        : ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length;
    } catch (Exception e) {
        playerAmount = Bukkit.getOnlinePlayers().size(); // Just use the new method if the Reflection failed
    }
    int onlineMode = Bukkit.getOnlineMode() ? 1 : 0;
    String bukkitVersion = Bukkit.getVersion();
    String bukkitName = Bukkit.getName();
    
    // OS/Java specific data
    String javaVersion = System.getProperty("java.version");
    String osName = System.getProperty("os.name");
    String osArch = System.getProperty("os.arch");
    String osVersion = System.getProperty("os.version");
    int coreCount = Runtime.getRuntime().availableProcessors();
    
    JsonObject data = new JsonObject();
    
    data.addProperty("serverUUID", serverUUID);
    
    data.addProperty("playerAmount", playerAmount);
    data.addProperty("onlineMode", onlineMode);
    data.addProperty("bukkitVersion", bukkitVersion);
    data.addProperty("bukkitName", bukkitName);
    
    data.addProperty("javaVersion", javaVersion);
    data.addProperty("osName", osName);
    data.addProperty("osArch", osArch);
    data.addProperty("osVersion", osVersion);
    data.addProperty("coreCount", coreCount);
    
    return data;
}
 
Example 7
Source File: Metrics.java    From PacketListenerAPI with MIT License 4 votes vote down vote up
/**
 * Gets the server specific data.
 *
 * @return The server specific data.
 */
private JsonObject getServerData() {
	// Minecraft specific data
	int playerAmount;
	try {
		// Around MC 1.8 the return type was changed to a collection from an array,
		// This fixes java.lang.NoSuchMethodError: org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection;
		Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers");
		playerAmount = onlinePlayersMethod.getReturnType().equals(Collection.class)
				? ((Collection<?>) onlinePlayersMethod.invoke(Bukkit.getServer())).size()
				: ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length;
	} catch (Exception e) {
		playerAmount = Bukkit.getOnlinePlayers().size(); // Just use the new method if the Reflection failed
	}
	int onlineMode = Bukkit.getOnlineMode() ? 1 : 0;
	String bukkitVersion = Bukkit.getVersion();
	String bukkitName = Bukkit.getName();

	// OS/Java specific data
	String javaVersion = System.getProperty("java.version");
	String osName = System.getProperty("os.name");
	String osArch = System.getProperty("os.arch");
	String osVersion = System.getProperty("os.version");
	int coreCount = Runtime.getRuntime().availableProcessors();

	JsonObject data = new JsonObject();

	data.addProperty("serverUUID", serverUUID);

	data.addProperty("playerAmount", playerAmount);
	data.addProperty("onlineMode", onlineMode);
	data.addProperty("bukkitVersion", bukkitVersion);
	data.addProperty("bukkitName", bukkitName);

	data.addProperty("javaVersion", javaVersion);
	data.addProperty("osName", osName);
	data.addProperty("osArch", osArch);
	data.addProperty("osVersion", osVersion);
	data.addProperty("coreCount", coreCount);

	return data;
}
 
Example 8
Source File: ItemBuilder.java    From ProRecipes with GNU General Public License v2.0 4 votes vote down vote up
public static String getVersion(){
	String s = Bukkit.getVersion();
	int index = s.indexOf("(MC: ");
	return s.substring(index + 4, s.length()-1);
}
 
Example 9
Source File: Metrics.java    From ClaimChunk with MIT License 4 votes vote down vote up
/**
 * Gets the server specific data.
 *
 * @return The server specific data.
 */
private JsonObject getServerData() {
    // Minecraft specific data
    int playerAmount;
    try {
        // Around MC 1.8 the return type was changed to a collection from an array,
        // This fixes java.lang.NoSuchMethodError: org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection;
        Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers");
        playerAmount = onlinePlayersMethod.getReturnType().equals(Collection.class)
                ? ((Collection<?>) onlinePlayersMethod.invoke(Bukkit.getServer())).size()
                : ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length;
    } catch (Exception e) {
        playerAmount = Bukkit.getOnlinePlayers().size(); // Just use the new method if the Reflection failed
    }
    int onlineMode = Bukkit.getOnlineMode() ? 1 : 0;
    String bukkitVersion = Bukkit.getVersion();
    String bukkitName = Bukkit.getName();

    // OS/Java specific data
    String javaVersion = System.getProperty("java.version");
    String osName = System.getProperty("os.name");
    String osArch = System.getProperty("os.arch");
    String osVersion = System.getProperty("os.version");
    int coreCount = Runtime.getRuntime().availableProcessors();

    JsonObject data = new JsonObject();

    data.addProperty("serverUUID", serverUUID);

    data.addProperty("playerAmount", playerAmount);
    data.addProperty("onlineMode", onlineMode);
    data.addProperty("bukkitVersion", bukkitVersion);
    data.addProperty("bukkitName", bukkitName);

    data.addProperty("javaVersion", javaVersion);
    data.addProperty("osName", osName);
    data.addProperty("osArch", osArch);
    data.addProperty("osVersion", osVersion);
    data.addProperty("coreCount", coreCount);

    return data;
}
 
Example 10
Source File: Metrics.java    From UhcCore with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Gets the server specific data.
 *
 * @return The server specific data.
 */
private JsonObject getServerData() {
    // Minecraft specific data
    int playerAmount;
    try {
        // Around MC 1.8 the return type was changed to a collection from an array,
        // This fixes java.lang.NoSuchMethodError: org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection;
        Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers");
        playerAmount = onlinePlayersMethod.getReturnType().equals(Collection.class)
                ? ((Collection<?>) onlinePlayersMethod.invoke(Bukkit.getServer())).size()
                : ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length;
    } catch (Exception e) {
        playerAmount = Bukkit.getOnlinePlayers().size(); // Just use the new method if the Reflection failed
    }
    int onlineMode = Bukkit.getOnlineMode() ? 1 : 0;
    String bukkitVersion = Bukkit.getVersion();
    String bukkitName = Bukkit.getName();

    // OS/Java specific data
    String javaVersion = System.getProperty("java.version");
    String osName = System.getProperty("os.name");
    String osArch = System.getProperty("os.arch");
    String osVersion = System.getProperty("os.version");
    int coreCount = Runtime.getRuntime().availableProcessors();

    JsonObject data = new JsonObject();

    data.addProperty("serverUUID", serverUUID);

    data.addProperty("playerAmount", playerAmount);
    data.addProperty("onlineMode", onlineMode);
    data.addProperty("bukkitVersion", bukkitVersion);
    data.addProperty("bukkitName", bukkitName);

    data.addProperty("javaVersion", javaVersion);
    data.addProperty("osName", osName);
    data.addProperty("osArch", osArch);
    data.addProperty("osVersion", osVersion);
    data.addProperty("coreCount", coreCount);

    return data;
}
 
Example 11
Source File: MetricsLite.java    From bStats-Metrics with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Gets the server specific data.
 *
 * @return The server specific data.
 */
private JsonObject getServerData() {
    // Minecraft specific data
    int playerAmount;
    try {
        // Around MC 1.8 the return type was changed to a collection from an array,
        // This fixes java.lang.NoSuchMethodError: org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection;
        Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers");
        playerAmount = onlinePlayersMethod.getReturnType().equals(Collection.class)
                ? ((Collection<?>) onlinePlayersMethod.invoke(Bukkit.getServer())).size()
                : ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length;
    } catch (Exception e) {
        playerAmount = Bukkit.getOnlinePlayers().size(); // Just use the new method if the Reflection failed
    }
    int onlineMode = Bukkit.getOnlineMode() ? 1 : 0;
    String bukkitVersion = Bukkit.getVersion();
    String bukkitName = Bukkit.getName();

    // OS/Java specific data
    String javaVersion = System.getProperty("java.version");
    String osName = System.getProperty("os.name");
    String osArch = System.getProperty("os.arch");
    String osVersion = System.getProperty("os.version");
    int coreCount = Runtime.getRuntime().availableProcessors();

    JsonObject data = new JsonObject();

    data.addProperty("serverUUID", serverUUID);

    data.addProperty("playerAmount", playerAmount);
    data.addProperty("onlineMode", onlineMode);
    data.addProperty("bukkitVersion", bukkitVersion);
    data.addProperty("bukkitName", bukkitName);

    data.addProperty("javaVersion", javaVersion);
    data.addProperty("osName", osName);
    data.addProperty("osArch", osArch);
    data.addProperty("osVersion", osVersion);
    data.addProperty("coreCount", coreCount);

    return data;
}
 
Example 12
Source File: Metrics.java    From Quests with MIT License 4 votes vote down vote up
/**
 * Gets the server specific data.
 *
 * @return The server specific data.
 */
private JsonObject getServerData() {
    // Minecraft specific data
    int playerAmount;
    try {
        // Around MC 1.8 the return type was changed to a collection from an array,
        // This fixes java.lang.NoSuchMethodError: org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection;
        Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers");
        playerAmount = onlinePlayersMethod.getReturnType().equals(Collection.class)
                ? ((Collection<?>) onlinePlayersMethod.invoke(Bukkit.getServer())).size()
                : ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length;
    } catch (Exception e) {
        playerAmount = Bukkit.getOnlinePlayers().size(); // Just use the new method if the Reflection failed
    }
    int onlineMode = Bukkit.getOnlineMode() ? 1 : 0;
    String bukkitVersion = Bukkit.getVersion();
    String bukkitName = Bukkit.getName();

    // OS/Java specific data
    String javaVersion = System.getProperty("java.version");
    String osName = System.getProperty("os.name");
    String osArch = System.getProperty("os.arch");
    String osVersion = System.getProperty("os.version");
    int coreCount = Runtime.getRuntime().availableProcessors();

    JsonObject data = new JsonObject();

    data.addProperty("serverUUID", serverUUID);

    data.addProperty("playerAmount", playerAmount);
    data.addProperty("onlineMode", onlineMode);
    data.addProperty("bukkitVersion", bukkitVersion);
    data.addProperty("bukkitName", bukkitName);

    data.addProperty("javaVersion", javaVersion);
    data.addProperty("osName", osName);
    data.addProperty("osArch", osArch);
    data.addProperty("osVersion", osVersion);
    data.addProperty("coreCount", coreCount);

    return data;
}
 
Example 13
Source File: BStats.java    From DiscordSRV with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Gets the server specific data.
 *
 * @return The server specific data.
 */
private JsonObject getServerData() {
    // Minecraft specific data
    int playerAmount;
    try {
        // Around MC 1.8 the return type was changed to a collection from an array,
        // This fixes java.lang.NoSuchMethodError: org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection;
        Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers");
        playerAmount = onlinePlayersMethod.getReturnType().equals(Collection.class)
                ? ((Collection<?>) onlinePlayersMethod.invoke(Bukkit.getServer())).size()
                : ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length;
    } catch (Exception e) {
        playerAmount = Bukkit.getOnlinePlayers().size(); // Just use the new method if the Reflection failed
    }
    int onlineMode = Bukkit.getOnlineMode() ? 1 : 0;
    String bukkitVersion = Bukkit.getVersion();
    String bukkitName = Bukkit.getName();

    // OS/Java specific data
    String javaVersion = System.getProperty("java.version");
    String osName = System.getProperty("os.name");
    String osArch = System.getProperty("os.arch");
    String osVersion = System.getProperty("os.version");
    int coreCount = Runtime.getRuntime().availableProcessors();

    JsonObject data = new JsonObject();

    data.addProperty("serverUUID", serverUUID);

    data.addProperty("playerAmount", playerAmount);
    data.addProperty("onlineMode", onlineMode);
    data.addProperty("bukkitVersion", bukkitVersion);
    data.addProperty("bukkitName", bukkitName);

    data.addProperty("javaVersion", javaVersion);
    data.addProperty("osName", osName);
    data.addProperty("osArch", osArch);
    data.addProperty("osVersion", osVersion);
    data.addProperty("coreCount", coreCount);

    return data;
}
 
Example 14
Source File: BStats.java    From TabooLib with MIT License 4 votes vote down vote up
/**
 * Gets the server specific data.
 *
 * @return The server specific data.
 */
private JSONObject getServerData() {
    // Minecraft specific data
    int playerAmount;
    try {
        // Around MC 1.8 the return type was changed to a collection from an array,
        // This fixes java.lang.NoSuchMethodError: org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection;
        Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers");
        playerAmount = onlinePlayersMethod.getReturnType().equals(Collection.class)
                ? ((Collection<?>) onlinePlayersMethod.invoke(Bukkit.getServer())).size()
                : ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length;
    } catch (Exception e) {
        playerAmount = Bukkit.getOnlinePlayers().size(); // Just use the new method if the Reflection failed
    }
    int onlineMode = Bukkit.getOnlineMode() ? 1 : 0;
    String bukkitVersion = Bukkit.getVersion();
    bukkitVersion = bukkitVersion.substring(bukkitVersion.indexOf("MC: ") + 4, bukkitVersion.length() - 1);

    // OS/Java specific data
    String javaVersion = System.getProperty("java.version");
    String osName = System.getProperty("os.name");
    String osArch = System.getProperty("os.arch");
    String osVersion = System.getProperty("os.version");
    int coreCount = Runtime.getRuntime().availableProcessors();

    JSONObject data = new JSONObject();

    data.put("serverUUID", serverUUID);

    data.put("playerAmount", playerAmount);
    data.put("onlineMode", onlineMode);
    data.put("bukkitVersion", bukkitVersion);

    data.put("javaVersion", javaVersion);
    data.put("osName", osName);
    data.put("osArch", osArch);
    data.put("osVersion", osVersion);
    data.put("coreCount", coreCount);

    return data;
}
 
Example 15
Source File: CStats.java    From TabooLib with MIT License 4 votes vote down vote up
/**
 * Gets the server specific data.
 *
 * @return The server specific data.
 */
private JsonObject getServerData() {
    // Minecraft specific data
    int playerAmount;
    try {
        // Around MC 1.8 the return type was changed to a collection from an array,
        // This fixes java.lang.NoSuchMethodError: org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection;
        Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers");
        playerAmount = onlinePlayersMethod.getReturnType().equals(Collection.class)
                ? ((Collection<?>) onlinePlayersMethod.invoke(Bukkit.getServer())).size()
                : ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length;
    } catch (Exception e) {
        playerAmount = Bukkit.getOnlinePlayers().size(); // Just use the new method if the Reflection failed
    }
    int onlineMode = Bukkit.getOnlineMode() ? 1 : 0;
    String bukkitVersion = Bukkit.getVersion();
    String bukkitName = Bukkit.getName();

    // OS/Java specific data
    String javaVersion = System.getProperty("java.version");
    String osName = System.getProperty("os.name");
    String osArch = System.getProperty("os.arch");
    String osVersion = System.getProperty("os.version");
    int coreCount = Runtime.getRuntime().availableProcessors();

    JsonObject data = new JsonObject();

    data.addProperty("serverUUID", serverUUID);

    data.addProperty("playerAmount", playerAmount);
    data.addProperty("onlineMode", onlineMode);
    data.addProperty("bukkitVersion", bukkitVersion);
    data.addProperty("bukkitName", bukkitName);

    data.addProperty("javaVersion", javaVersion);
    data.addProperty("osName", osName);
    data.addProperty("osArch", osArch);
    data.addProperty("osVersion", osVersion);
    data.addProperty("coreCount", coreCount);

    return data;
}
 
Example 16
Source File: Metrics.java    From Harbor with MIT License 4 votes vote down vote up
/**
 * Gets the server specific data.
 *
 * @return The server specific data.
 */
private JsonObject getServerData() {
    // Minecraft specific data
    int playerAmount;
    try {
        // Around MC 1.8 the return type was changed to a collection from an array,
        // This fixes java.lang.NoSuchMethodError: org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection;
        Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers");
        playerAmount = onlinePlayersMethod.getReturnType().equals(Collection.class)
                ? ((Collection<?>) onlinePlayersMethod.invoke(Bukkit.getServer())).size()
                : ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length;
    } catch (Exception e) {
        playerAmount = Bukkit.getOnlinePlayers().size(); // Just use the new method if the Reflection failed
    }
    int onlineMode = Bukkit.getOnlineMode() ? 1 : 0;
    String bukkitVersion = Bukkit.getVersion();
    String bukkitName = Bukkit.getName();

    // OS/Java specific data
    String javaVersion = System.getProperty("java.version");
    String osName = System.getProperty("os.name");
    String osArch = System.getProperty("os.arch");
    String osVersion = System.getProperty("os.version");
    int coreCount = Runtime.getRuntime().availableProcessors();

    JsonObject data = new JsonObject();

    data.addProperty("serverUUID", serverUUID);

    data.addProperty("playerAmount", playerAmount);
    data.addProperty("onlineMode", onlineMode);
    data.addProperty("bukkitVersion", bukkitVersion);
    data.addProperty("bukkitName", bukkitName);

    data.addProperty("javaVersion", javaVersion);
    data.addProperty("osName", osName);
    data.addProperty("osArch", osArch);
    data.addProperty("osVersion", osVersion);
    data.addProperty("coreCount", coreCount);

    return data;
}
 
Example 17
Source File: Metrics.java    From QuickShop-Reremake with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Gets the server specific data.
 *
 * @return The server specific data.
 */
private JsonObject getServerData() {
    // Minecraft specific data
    int playerAmount;
    try {
        // Around MC 1.8 the return type was changed to a collection from an array,
        // This fixes java.lang.NoSuchMethodError:
        // org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection;
        Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers");
        playerAmount =
                onlinePlayersMethod.getReturnType().equals(Collection.class)
                        ? ((Collection<?>) onlinePlayersMethod.invoke(Bukkit.getServer())).size()
                        : ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length;
    } catch (Exception e) {
        playerAmount =
                Bukkit.getOnlinePlayers().size(); // Just use the new method if the Reflection failed
    }
    int onlineMode = Bukkit.getOnlineMode() ? 1 : 0;
    String bukkitVersion = Bukkit.getVersion();
    String bukkitName = Bukkit.getName();

    // OS/Java specific data
    String javaVersion = System.getProperty("java.version");
    String osName = System.getProperty("os.name");
    String osArch = System.getProperty("os.arch");
    String osVersion = System.getProperty("os.version");
    int coreCount = Runtime.getRuntime().availableProcessors();

    JsonObject data = new JsonObject();

    data.addProperty("serverUUID", serverUUID);

    data.addProperty("playerAmount", playerAmount);
    data.addProperty("onlineMode", onlineMode);
    data.addProperty("bukkitVersion", bukkitVersion);
    data.addProperty("bukkitName", bukkitName);

    data.addProperty("javaVersion", javaVersion);
    data.addProperty("osName", osName);
    data.addProperty("osArch", osArch);
    data.addProperty("osVersion", osVersion);
    data.addProperty("coreCount", coreCount);

    return data;
}
 
Example 18
Source File: Metrics.java    From PlayerVaults with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Gets the server specific data.
 *
 * @return The server specific data.
 */
private JsonObject getServerData() {
    // Minecraft specific data
    int playerAmount;
    try {
        // Around MC 1.8 the return type was changed to a collection from an array,
        // This fixes java.lang.NoSuchMethodError: org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection;
        Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers");
        playerAmount = onlinePlayersMethod.getReturnType().equals(Collection.class)
                ? ((Collection<?>) onlinePlayersMethod.invoke(Bukkit.getServer())).size()
                : ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length;
    } catch (Exception e) {
        playerAmount = Bukkit.getOnlinePlayers().size(); // Just use the new method if the Reflection failed
    }
    int onlineMode = Bukkit.getOnlineMode() ? 1 : 0;
    String bukkitVersion = Bukkit.getVersion();
    String bukkitName = Bukkit.getName();

    // OS/Java specific data
    String javaVersion = System.getProperty("java.version");
    String osName = System.getProperty("os.name");
    String osArch = System.getProperty("os.arch");
    String osVersion = System.getProperty("os.version");
    int coreCount = Runtime.getRuntime().availableProcessors();

    JsonObject data = new JsonObject();

    data.addProperty("serverUUID", serverUUID);

    data.addProperty("playerAmount", playerAmount);
    data.addProperty("onlineMode", onlineMode);
    data.addProperty("bukkitVersion", bukkitVersion);
    data.addProperty("bukkitName", bukkitName);

    data.addProperty("javaVersion", javaVersion);
    data.addProperty("osName", osName);
    data.addProperty("osArch", osArch);
    data.addProperty("osVersion", osVersion);
    data.addProperty("coreCount", coreCount);

    return data;
}
 
Example 19
Source File: MetricsLite.java    From PlayerSQL with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Gets the server specific data.
 *
 * @return The server specific data.
 */
private JSONObject getServerData() {
    // Minecraft specific data
    int playerAmount;
    try {
        // Around MC 1.8 the return type was changed to a collection from an array,
        // This fixes java.lang.NoSuchMethodError: org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection;
        Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers");
        playerAmount = onlinePlayersMethod.getReturnType().equals(Collection.class)
                ? ((Collection<?>) onlinePlayersMethod.invoke(Bukkit.getServer())).size()
                : ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length;
    } catch (Exception e) {
        playerAmount = Bukkit.getOnlinePlayers().size(); // Just use the new method if the Reflection failed
    }
    int onlineMode = Bukkit.getOnlineMode() ? 1 : 0;
    String bukkitVersion = Bukkit.getVersion();
    bukkitVersion = bukkitVersion.substring(bukkitVersion.indexOf("MC: ") + 4, bukkitVersion.length() - 1);

    // OS/Java specific data
    String javaVersion = System.getProperty("java.version");
    String osName = System.getProperty("os.name");
    String osArch = System.getProperty("os.arch");
    String osVersion = System.getProperty("os.version");
    int coreCount = Runtime.getRuntime().availableProcessors();

    JSONObject data = new JSONObject();

    data.put("serverUUID", serverUUID);

    data.put("playerAmount", playerAmount);
    data.put("onlineMode", onlineMode);
    data.put("bukkitVersion", bukkitVersion);

    data.put("javaVersion", javaVersion);
    data.put("osName", osName);
    data.put("osArch", osArch);
    data.put("osVersion", osVersion);
    data.put("coreCount", coreCount);

    return data;
}
 
Example 20
Source File: Metrics.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Gets the server specific data.
 *
 * @return The server specific data.
 */
private JsonObject getServerData() {
    // Minecraft specific data
    int playerAmount;
    try {
        // Around MC 1.8 the return type was changed to a collection from an array,
        // This fixes java.lang.NoSuchMethodError: org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection;
        Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers");
        playerAmount = onlinePlayersMethod.getReturnType().equals(Collection.class)
                ? ((Collection<?>) onlinePlayersMethod.invoke(Bukkit.getServer())).size()
                : ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length;
    } catch (Exception e) {
        playerAmount = Bukkit.getOnlinePlayers().size(); // Just use the new method if the Reflection failed
    }
    int onlineMode = Bukkit.getOnlineMode() ? 1 : 0;
    String bukkitVersion = Bukkit.getVersion();
    String bukkitName = Bukkit.getName();

    // OS/Java specific data
    String javaVersion = System.getProperty("java.version");
    String osName = System.getProperty("os.name");
    String osArch = System.getProperty("os.arch");
    String osVersion = System.getProperty("os.version");
    int coreCount = Runtime.getRuntime().availableProcessors();

    JsonObject data = new JsonObject();

    data.addProperty("serverUUID", serverUUID);

    data.addProperty("playerAmount", playerAmount);
    data.addProperty("onlineMode", onlineMode);
    data.addProperty("bukkitVersion", bukkitVersion);
    data.addProperty("bukkitName", bukkitName);

    data.addProperty("javaVersion", javaVersion);
    data.addProperty("osName", osName);
    data.addProperty("osArch", osArch);
    data.addProperty("osVersion", osVersion);
    data.addProperty("coreCount", coreCount);

    return data;
}