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

The following examples show how to use org.bukkit.Bukkit#getOnlineMode() . 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: Metrics.java    From TAB with Apache License 2.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 = plugin.getOnlinePlayers().length;
	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 2
Source File: Metrics.java    From MapManager 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 = org.bukkit.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 3
Source File: Metrics.java    From NickNamer 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 = org.bukkit.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 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: Skins.java    From tabbed with MIT License 5 votes vote down vote up
/**
 * Get a Minecraft user's skin.
 * @param username
 * @return
 */
public static Skin getPlayer(String username) {
    if (!Bukkit.getOnlineMode()) {
        Tabbed.log(Level.SEVERE, "online-mode must be true to fetch skins");
        return DEFAULT_SKIN;
    }
    return getPlayer(Bukkit.getOfflinePlayer(username).getUniqueId());
}
 
Example 7
Source File: BStats.java    From FunnyGuilds with Apache License 2.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 = Bukkit.getOnlinePlayers().size();
    int onlineMode = Bukkit.getOnlineMode() ? 1 : 0;
    String bukkitVersion = org.bukkit.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 8
Source File: BStatsMetricsLite.java    From Sentinel 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 9
Source File: UUIDRegistry.java    From Modern-LWC with MIT License 4 votes vote down vote up
/**
 * Get the UUID for the given name. If it is not already known, it will be retrieved from the account servers.
 *
 * @param name
 * @return
 * @throws Exception
 */
@SuppressWarnings("deprecation")
public static UUID getUUID(String name) {
    String nameLower = name.toLowerCase();

    try {
        if (nameToUUIDCache.containsKey(nameLower)) {
            return nameToUUIDCache.get(nameLower).getUUID();
        }

        if (isValidUUID(name)) {
            return UUID.fromString(name);
        }

        if (Bukkit.getOnlineMode()) {
            Map<String, UUID> results = new UUIDFetcher(Arrays.asList(nameLower)).call();

            // The returned name is the exact casing; so we need to look for it
            // in the case-insensitive version
            for (String key : results.keySet()) {
                if (key.equalsIgnoreCase(name)) {
                    UUID uuid = results.get(key);
                    updateCache(uuid, key);
                    return uuid;
                }
            }
        } else {
            OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(name);

            if (offlinePlayer != null && offlinePlayer.getUniqueId() != null) {
                if (offlinePlayer.getName() != null) {
                    name = offlinePlayer.getName();
                }

                updateCache(offlinePlayer.getUniqueId(), name);
                return offlinePlayer.getUniqueId();
            }
        }

        nameToUUIDCache.put(nameLower, null);
        return null;
    } catch (Exception e) {
        nameToUUIDCache.put(nameLower, null);
        return null;
    }
}
 
Example 10
Source File: Metrics.java    From MineableSpawners 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 11
Source File: Metrics.java    From SubServers-2 with Apache License 2.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 = org.bukkit.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 12
Source File: Metrics.java    From RedProtect 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 13
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 14
Source File: FaweBukkit.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean isOnlineMode() {
    return Bukkit.getOnlineMode();
}
 
Example 15
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 16
Source File: Metrics.java    From UltimateChat 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 17
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 18
Source File: Metrics.java    From Crazy-Auctions 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 19
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 20
Source File: TabListImpl.java    From NovaGuilds with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void send() {
	try {
		if(!getPlayer().isOnline()) {
			return;
		}

		TabUtils.fillVars(this);
		final List<Packet> packets = new ArrayList<>();

		Packet addPlayerPacket = new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER);
		Packet updateNamePacket = new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.UPDATE_DISPLAY_NAME);
		List<Object> addPlayerList = new ArrayList<>();
		List<Object> updateNameList = new ArrayList<>();

		//Texture
		Object targetProfile = null;

		if(Bukkit.getOnlineMode()) {
			String name = Config.TABLIST_TEXTURE.getString();
			Player online = Bukkit.getPlayerExact(name);

			if(online != null) {
				targetProfile = entityPlayerGetProfileMethod.invoke(Reflections.getHandle(online));
			}
			else {
				targetProfile = craftOfflinePlayerGetProfileMethod.invoke(Bukkit.getOfflinePlayer(name));
			}

			if(Iterables.getFirst(propertyMapGetMethod.invoke(gameProfileGetPropertiesMethod.invoke(targetProfile), "textures"), null) == null) {
				Object server = minecraftServerGetMinecraftServerMethod.invoke(null);
				Object service = minecraftServerMinecraftSessionServiceField.get(server);
				targetProfile = minecraftSessionServiceFillProfilePropertiesMethod.invoke(service, targetProfile, true);
			}
		}

		for(int i = 0; i < 80; i++) {
			String line;
			if(i < lines.size()) {
				line = lines.get(i);
			}
			else {
				line = "";
			}

			if(profiles[i] == null) {
				profiles[i] = gameProfileConstructor.newInstance(
						UUID.fromString(String.format(uuid, digit(i))),
						token + digit(i)
				);
			}

			line = StringUtils.replaceVarKeyMap(line, getVars());
			line = StringUtils.fixColors(line);

			Object gameProfile = profiles[i];
			Object gameMode = enumGamemodeClass.getEnumConstants()[0];
			Object lineCompound = Array.get(craftChatMessageFromStringMethod.invoke(null, line), 0);

			if(targetProfile != null) {
				propertyMapPutAllMethod.invoke(gameProfileGetPropertiesMethod.invoke(gameProfile), gameProfileGetPropertiesMethod.invoke(targetProfile));
			}

			Object playerInfoData = playerInfoDataConstructor.newInstance(
					null,
					gameProfile,
					0,
					gameMode,
					lineCompound
			);

			if(first) {
				addPlayerList.add(playerInfoData);
			}

			updateNameList.add(playerInfoData);
		}

		if(first) {
			first = false;
		}

		packets.add(addPlayerPacket);
		packets.add(updateNamePacket);

		if(!Config.TABLIST_HEADER.isEmpty() || !Config.TABLIST_FOOTER.isEmpty()) {
			packets.add(new PacketPlayOutPlayerListHeaderFooter(
					Config.TABLIST_HEADER.vars(getVars()).getString(),
					Config.TABLIST_FOOTER.vars(getVars()).getString())
			);
		}

		packetPlayerOutPlayerInfoBField.set(addPlayerPacket.getPacket(), addPlayerList);
		packetPlayerOutPlayerInfoBField.set(updateNamePacket.getPacket(), updateNameList);
		PacketSender.sendPacket(getPlayer().getPlayer(), packets.toArray());
	}
	catch(IllegalAccessException | InvocationTargetException | InstantiationException e) {
		LoggerUtils.exception(e);
	}
}