當前位置: 首頁>>代碼示例>>Java>>正文


Java Bukkit.isPrimaryThread方法代碼示例

本文整理匯總了Java中org.bukkit.Bukkit.isPrimaryThread方法的典型用法代碼示例。如果您正苦於以下問題:Java Bukkit.isPrimaryThread方法的具體用法?Java Bukkit.isPrimaryThread怎麽用?Java Bukkit.isPrimaryThread使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.bukkit.Bukkit的用法示例。


在下文中一共展示了Bukkit.isPrimaryThread方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: sendData

import org.bukkit.Bukkit; //導入方法依賴的package包/類
/**
 * Sends the data to the bStats server.
 *
 * @param data The data to send.
 * @throws Exception If the request failed.
 */
private static void sendData(JSONObject data) throws Exception {
    if (data == null) {
        throw new IllegalArgumentException("Data cannot be null!");
    }
    if (Bukkit.isPrimaryThread()) {
        throw new IllegalAccessException("This method must not be called from the main thread!");
    }
    HttpsURLConnection connection = (HttpsURLConnection) new URL(URL).openConnection();

    // Compress the data to save bandwidth
    byte[] compressedData = compress(data.toString());

    // Add headers
    connection.setRequestMethod("POST");
    connection.addRequestProperty("Accept", "application/json");
    connection.addRequestProperty("Connection", "close");
    connection.addRequestProperty("Content-Encoding", "gzip"); // We gzip our request
    connection.addRequestProperty("Content-Length", String.valueOf(compressedData.length));
    connection.setRequestProperty("Content-Type", "application/json"); // We send our data in JSON format
    connection.setRequestProperty("User-Agent", "MC-Server/" + B_STATS_VERSION);

    // Send data
    connection.setDoOutput(true);
    DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream());
    outputStream.write(compressedData);
    outputStream.flush();
    outputStream.close();

    connection.getInputStream().close(); // We don't care about the response - Just send our data :)
}
 
開發者ID:Chazmondo,項目名稱:RankVouchers,代碼行數:37,代碼來源:MetricUtil.java

示例2: sendData

import org.bukkit.Bukkit; //導入方法依賴的package包/類
/**
 * Sends the data to the bStats server.
 *
 * @param data The data to send.
 * @throws Exception If the request failed.
 */
private static void sendData(JSONObject data) throws Exception {
    if (data == null) {
        throw new IllegalArgumentException("Data cannot be null!");
    }
    if (Bukkit.isPrimaryThread()) {
        throw new IllegalAccessException("This method must not be called from the main thread!");
    }
    final HttpsURLConnection connection = (HttpsURLConnection) new URL(URL).openConnection();

    // Compress the data to save bandwidth
    final byte[] compressedData = compress(data.toString());

    // Add headers
    connection.setRequestMethod("POST");
    connection.addRequestProperty("Accept", "application/json");
    connection.addRequestProperty("Connection", "close");
    connection.addRequestProperty("Content-Encoding", "gzip"); // We gzip our request
    connection.addRequestProperty("Content-Length", String.valueOf(compressedData.length));
    connection.setRequestProperty("Content-Type", "application/json"); // We send our data in JSON format
    connection.setRequestProperty("User-Agent", "MC-Server/" + B_STATS_VERSION);

    // Send data
    connection.setDoOutput(true);
    try (DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream())) {
        outputStream.write(compressedData);
        outputStream.flush();
    }
    connection.getInputStream().close(); // We don't care about the response - Just send our data :)
}
 
開發者ID:Shynixn,項目名稱:AstralEdit,代碼行數:36,代碼來源:Metrics.java

示例3: sendData

import org.bukkit.Bukkit; //導入方法依賴的package包/類
/**
 * Sends the data to the bStats server.
 *
 * @param data The data to send.
 * @throws Exception If the request failed.
 */
private static void sendData(JSONObject data) throws Exception {
	if (data == null) {
		throw new IllegalArgumentException("Data cannot be null!");
	}
	if (Bukkit.isPrimaryThread()) {
		throw new IllegalAccessException("This method must not be called from the main thread!");
	}
	HttpsURLConnection connection = (HttpsURLConnection) new URL(URL).openConnection();
	
	// Compress the data to save bandwidth
	byte[] compressedData = compress(data.toString());
	
	// Add headers
	connection.setRequestMethod("POST");
	connection.addRequestProperty("Accept", "application/json");
	connection.addRequestProperty("Connection", "close");
	connection.addRequestProperty("Content-Encoding", "gzip"); // We gzip our request
	connection.addRequestProperty("Content-Length", String.valueOf(compressedData.length));
	connection.setRequestProperty("Content-Type", "application/json"); // We send our data in JSON format
	connection.setRequestProperty("User-Agent", "MC-Server/" + B_STATS_VERSION);
	
	// Send data
	connection.setDoOutput(true);
	DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream());
	outputStream.write(compressedData);
	outputStream.flush();
	outputStream.close();
	
	connection.getInputStream().close(); // We don't care about the response - Just send our data :)
}
 
開發者ID:RadBuilder,項目名稱:EmojiChat,代碼行數:37,代碼來源:Metrics.java

示例4: sendData

import org.bukkit.Bukkit; //導入方法依賴的package包/類
/**
 * Sends the data to the bStats server.
 *
 * @param data The data to send.
 * @throws Exception If the request failed.
 */
private static void sendData(JSONObject data) throws Exception {
    if (data == null) {
        throw new IllegalArgumentException("Data cannot be null!");
    }
    if (Bukkit.isPrimaryThread()) {
        throw new IllegalAccessException("This method must not be called from the main thread!");
    }
    final HttpsURLConnection connection = (HttpsURLConnection) new URL(URL).openConnection();

    // Compress the data to save bandwidth
    final byte[] compressedData = compress(data.toString());

    // Add headers
    connection.setRequestMethod("POST");
    connection.addRequestProperty("Accept", "application/json");
    connection.addRequestProperty("Connection", "close");
    connection.addRequestProperty("Content-Encoding", "gzip"); // We gzip our request
    connection.addRequestProperty("Content-Length", String.valueOf(compressedData.length));
    connection.setRequestProperty("Content-Type", "application/json"); // We send our data in JSON format
    connection.setRequestProperty("User-Agent", "MC-Server/" + B_STATS_VERSION);

    // Send data
    connection.setDoOutput(true);
    try (DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream())) {
        outputStream.write(compressedData);
        outputStream.flush();
    }

    connection.getInputStream().close(); // We don't care about the response - Just send our data :)
}
 
開發者ID:Shynixn,項目名稱:BlockBall,代碼行數:37,代碼來源:Metrics.java

示例5: handleCommand

import org.bukkit.Bukkit; //導入方法依賴的package包/類
/**
 * Tries to run a command. Returns true if the command was found / executed.
 * @param sender
 * @param type
 * @return commandSuccess
 */
public static boolean handleCommand(CommandSender sender, CommandType type, String input) {
    if (!input.startsWith(type.getPrefix()))
        return false; // Not this command type.

    input = input.substring(type.getPrefix().length()); // Remove the prefix.
    input = Chat.filterMessage(input); // Apply filter.
    String[] args = input.split(" ");
    String cmd = args[0];
    Command command = getCommand(type, cmd);
    if (command == null)
        return false; // Not a command.

    if (sender instanceof DiscordSender) // Log all discord sent commands.
        Core.alertStaff(ChatColor.GREEN + sender.getName() + ": " + ChatColor.GRAY + type.getPrefix() + input);

    if (Bukkit.isPrimaryThread()) {
        runCommand(command, sender, cmd, Utils.shift(args));
    } else {
        Bukkit.getScheduler().runTask(Core.getInstance(), () -> runCommand(command, sender, cmd, Utils.shift(args)));
    }
    return true;
}
 
開發者ID:Kneesnap,項目名稱:Kineticraft,代碼行數:29,代碼來源:Commands.java

示例6: startTiming

import org.bukkit.Bukkit; //導入方法依賴的package包/類
@Override
public MCTiming startTiming() {
    if (Bukkit.isPrimaryThread()) {
        timing.startTiming();
    }
    return this;
}
 
開發者ID:aikar,項目名稱:minecraft-timings,代碼行數:8,代碼來源:SpigotTiming.java

示例7: sendData

import org.bukkit.Bukkit; //導入方法依賴的package包/類
/**
 * Sends the data to the bStats server.
 *
 * @param data The data to send.
 * @throws Exception If the request failed.
 */
private static void sendData(JSONObject data) throws Exception {
    if (data == null) {
        throw new IllegalArgumentException("Data cannot be null!");
    }
    if (Bukkit.isPrimaryThread()) {
        throw new IllegalAccessException("This method must not be called from the main thread!");
    }
    HttpsURLConnection connection = (HttpsURLConnection) new URL(URL).openConnection();

    // Compress the data to save bandwidth
    byte[] compressedData = compress(data.toString());

    // Add headers
    connection.setRequestMethod("POST");
    connection.addRequestProperty("Accept", "application/json");
    connection.addRequestProperty("Connection", "close");
    connection.addRequestProperty("Content-Encoding", "gzip"); // We gzip our request
    connection.addRequestProperty("Content-Length", String.valueOf(compressedData.length));
    connection.setRequestProperty("Content-Type", "application/json"); // We send our data in JSON f
    connection.setRequestProperty("MCBUser-Agent", "MC-Server/" + B_STATS_VERSION);

    // Send data
    connection.setDoOutput(true);
    DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream());
    outputStream.write(compressedData);
    outputStream.flush();
    outputStream.close();

    connection.getInputStream().close(); // We don't care about the response - Just send our data :)
}
 
開發者ID:CyR1en,項目名稱:Minecordbot,代碼行數:37,代碼來源:Metrics.java

示例8: canRunImmediately

import org.bukkit.Bukkit; //導入方法依賴的package包/類
@Override
protected boolean canRunImmediately() {
    return !Bukkit.isPrimaryThread();
}
 
開發者ID:Twister915,項目名稱:pl,代碼行數:5,代碼來源:BukkitAsyncWorker.java

示例9: canRunImmediately

import org.bukkit.Bukkit; //導入方法依賴的package包/類
@Override
boolean canRunImmediately() {
    return Bukkit.isPrimaryThread();
}
 
開發者ID:Twister915,項目名稱:pl,代碼行數:5,代碼來源:BukkitSyncWorker.java


注:本文中的org.bukkit.Bukkit.isPrimaryThread方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。