org.bukkit.Bukkit.isPrimaryThread()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(249)

本文整理了Java中org.bukkit.Bukkit.isPrimaryThread()方法的一些代码示例,展示了Bukkit.isPrimaryThread()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bukkit.isPrimaryThread()方法的具体详情如下:
包路径:org.bukkit.Bukkit
类名称:Bukkit
方法名:isPrimaryThread

Bukkit.isPrimaryThread介绍

暂无

代码示例

代码示例来源:origin: NoCheatPlus/NoCheatPlus

@Override
  public boolean isPrimaryThread() {
    return Bukkit.isPrimaryThread();
  }
};

代码示例来源:origin: aadnk/ProtocolLib

/**
 * Determine if we are executing the packet event in an asynchronous thread.
 * <p>
 * If so, you must synchronize all calls to the Bukkit API.
 * <p>
 * Generally, most server packets are executed on the main thread, whereas client packets
 * are all executed asynchronously.
 * @return TRUE if we are, FALSE otherwise.
 */
public boolean isAsync() {
  return !Bukkit.isPrimaryThread();
}

代码示例来源:origin: NoCheatPlus/NoCheatPlus

@Override
protected final boolean isPrimaryThread() {
  return Bukkit.isPrimaryThread();
}

代码示例来源:origin: aikar/TaskChain

@Override
public boolean isMainThread() {
  return Bukkit.isPrimaryThread();
}

代码示例来源:origin: games647/LagMonitor

public void checkBlockingAction(String event) {
  if (!Bukkit.isPrimaryThread()) {
    return;
  }
  String message = "Plugin {0} is performing a blocking I/O operation ({1}) on the main thread. " +
      "This could affect the server performance, because the thread pauses until it gets the response. " +
      "Such operations should be performed asynchronous from the main thread. " +
      "Keep in mind to keep the code thread-safe. ";
  logCurrentStack(message, event);
}

代码示例来源:origin: aadnk/ProtocolLib

@Override
  public void run() {
    try {
      // Prevent infinite loops
      if (!Bukkit.isPrimaryThread())
        throw new IllegalStateException("Scheduled task was not executed on the main thread!");
      sendServerPacket(receiver, packet, copy, filters);
    } catch (Exception e) {
      reporter.reportMinimal(library, "sendServerPacket-run()", e);
    }
  }
});

代码示例来源:origin: Bkm016/TabooLib

public static void sendTo(Plugin plugin, String path, CommandSender sender, String... args) {
  TabooLib.debug(plugin, "TLocaleLoader.sendTo: " + plugin + ", path: " + path + ", sender: " + sender + ", args: " + Arrays.asList(args));
  if (Bukkit.isPrimaryThread()) {
    Optional.ofNullable(map.get(plugin.getName())).ifPresent(localeInstance -> localeInstance.sendTo(path, sender, args));
  } else {
    synchronized (TLocaleLoader.class) {
      Optional.ofNullable(map.get(plugin.getName())).ifPresent(localeInstance -> localeInstance.sendTo(path, sender, args));
    }
  }
}

代码示例来源:origin: NoCheatPlus/NoCheatPlus

private void registerFrequentPlayerTask() {
  if (Bukkit.isPrimaryThread()) {
    registerFrequentPlayerTaskPrimaryThread();
  }
  else {
    registerFrequentPlayerTaskAsynchronous();
  }
}

代码示例来源:origin: NoCheatPlus/NoCheatPlus

@Override
public void requestPermissionUpdate(final RegisteredPermission registeredPermission) {
  if (Bukkit.isPrimaryThread()) {
    requestPermissionUpdatePrimaryThread(registeredPermission);
  }
  else {
    requestPermissionUpdateAsynchronous(registeredPermission);
  }
}

代码示例来源:origin: NoCheatPlus/NoCheatPlus

private void requestLazyPermissionsUpdateNonEmpty(final RegisteredPermission... registeredPermissions) {
  if (Bukkit.isPrimaryThread()) {
    requestLazyPermissionUpdatePrimaryThread(registeredPermissions);
  }
  else {
    requestLazyPermissionUpdateAsynchronous(registeredPermissions);
  }
}

代码示例来源:origin: games647/LagMonitor

public void checkThreadSafety(String eventName) {
  if (Bukkit.isPrimaryThread()) {
    return;
  }
  logCurrentStack("Plugin {0} triggered an synchronous event {1} from an asynchronous Thread. ", eventName);
  plugin.getLogger().info(THREAD_SAFETY_NOTICE);
  plugin.getLogger().info("Use runTask* (no Async*), scheduleSync* or callSyncMethod to run on the main thread.");
}

代码示例来源:origin: NoCheatPlus/NoCheatPlus

public void exempt(final CheckType checkType, final ExemptionContext context) {
  final PlayerCheckTypeTreeNode node = getNode(checkType);
  if (node == null) {
    throw new IllegalArgumentException("Invalid check type.");
  }
  if (Bukkit.isPrimaryThread()) {
    exemptPrimaryThread(node, context);
  }
  else {
    exemptAsynchronous(node, context);
  }
}

代码示例来源:origin: NoCheatPlus/NoCheatPlus

public void unexempt(final CheckType checkType, final ExemptionContext context) {
  final PlayerCheckTypeTreeNode node = getNode(checkType);
  if (node == null) {
    throw new IllegalArgumentException("Invalid check type.");
  }
  if (Bukkit.isPrimaryThread()) {
    unexemptPrimaryThread(node, context);
  }
  else {
    unexemptAsynchronous(node, context);
  }
}

代码示例来源:origin: NoCheatPlus/NoCheatPlus

public void unexemptAll(final CheckType checkType, final ExemptionContext context) {
  final PlayerCheckTypeTreeNode node = getNode(checkType);
  if (node == null) {
    throw new IllegalArgumentException("Invalid check type.");
  }
  if (Bukkit.isPrimaryThread()) {
    unexemptAllPrimaryThread(node, context);
  }
  else {
    unexemptAllAsynchronous(node, context);
  }
}

代码示例来源:origin: NoCheatPlus/NoCheatPlus

public boolean isExempted(final CheckType checkType, final ExemptionContext context) {
  final PlayerCheckTypeTreeNode node = getNode(checkType);
  if (node == null) {
    throw new IllegalArgumentException("Invalid check type.");
  }
  if (Bukkit.isPrimaryThread()) {
    return isExemptedPrimaryThread(node, context);
  }
  else {
    return isExemptedAsynchronous(node, context);
  }
}

代码示例来源:origin: Co0sh/BetonQuest

private void save(final String message, final File file, final LogType type) {
  // if the thread isn't primary then it's unsafe to access the file.
  // schedule it to be done on next tick
  if (Bukkit.isPrimaryThread()) {
    sync(message, file, type);
  } else {
    new BukkitRunnable() {
      @Override
      public void run() {
        sync(message, file, type);
      }
    }.runTask(BetonQuest.getInstance());
  }
}

代码示例来源:origin: PyvesB/AdvancedAchievements

@Override
public long getStatisticForNormalCategory(UUID player, NormalAchievements category) {
  validateNotNull(player, "Player");
  validateNotNull(category, "Category");
  // Underlying structures do not support concurrent write operations and are only modified by the main server
  // thread. Do not use cache if player is offline.
  if (Bukkit.isPrimaryThread() && isPlayerOnline(player)) {
    return cacheManager.getAndIncrementStatisticAmount(category, player, 0);
  } else {
    return databaseManager.getNormalAchievementAmount(player, category);
  }
}

代码示例来源:origin: PyvesB/AdvancedAchievements

@Override
public boolean hasPlayerReceivedAchievement(UUID player, String achievementName) {
  validateNotNull(player, "Player");
  validateNotEmpty(achievementName, "Achievement Name");
  // Underlying structures do not support concurrent operations and are only used by the main server thread. Not
  // thread-safe to modify or read them asynchronously. Do not use cached data if player is offline.
  if (Bukkit.isPrimaryThread() && isPlayerOnline(player)) {
    return cacheManager.hasPlayerAchievement(player, achievementName);
  } else {
    return databaseManager.hasPlayerAchievement(player, achievementName);
  }
}

代码示例来源:origin: PyvesB/AdvancedAchievements

@Override
public long getStatisticForMultipleCategory(UUID player, MultipleAchievements category, String subcategory) {
  validateNotNull(player, "Player");
  validateNotNull(category, "Category");
  validateNotEmpty(subcategory, "Sub-category");
  // Underlying structures do not support concurrent write operations and are only modified by the main server
  // thread. Do not use cache if player is offline.
  if (Bukkit.isPrimaryThread() && isPlayerOnline(player)) {
    return cacheManager.getAndIncrementStatisticAmount(category, subcategory, player, 0);
  } else {
    return databaseManager.getMultipleAchievementAmount(player, category, subcategory);
  }
}

代码示例来源:origin: filoghost/HolographicDisplays

public Hologram createHologram(Plugin plugin, Location source) {
  Validator.notNull(plugin, "plugin");
  Validator.notNull(source, "source");
  Validator.notNull(source.getWorld(), "source's world");
  Validator.isTrue(Bukkit.isPrimaryThread(), "Async hologram creation");
  
  PluginHologram hologram = new PluginHologram(source, plugin);
  PluginHologramManager.addHologram(hologram);
  
  return hologram;
}

相关文章