当前位置: 首页>>代码示例>>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;未经允许,请勿转载。