org.bukkit.metadata.MetadataValue.asBoolean()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(2.7k)|赞(0)|评价(0)|浏览(78)

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

MetadataValue.asBoolean介绍

[英]Attempts to convert the value of this metadata item into a boolean.
[中]尝试将此元数据项的值转换为布尔值。

代码示例

代码示例来源:origin: EngineHub/CommandHelper

@Override
public boolean asBoolean() {
  return this.value.asBoolean();
}

代码示例来源:origin: marcelo-mason/PreciousStones

public boolean isVanished(Player player) {
  List<MetadataValue> values = player.getMetadata("vanished");
  for (MetadataValue value : values) {
    if (value.asBoolean()) {
      return true;
    }
  }
  return false;
}

代码示例来源:origin: elBukkit/MagicPlugin

@Override
public boolean isVanished(Entity entity) {
  if (entity == null) return false;
  for (MetadataValue meta : entity.getMetadata("vanished")) {
    return meta.asBoolean();
  }
  return false;
}

代码示例来源:origin: EngineHub/CommandBook

/**
 * Check to see if god mode is enabled for a player.
 *
 * @param player The player to check
 * @return Whether the player has godmode
 */
public boolean hasGodMode(Player player) {
  List<MetadataValue> values = player.getMetadata(METADATA_KEY);
  switch (values.size()) {
  case 0:
    return false;
  case 1:
    return values.get(0).asBoolean();
  default:
    for (MetadataValue val : values) {
      if (val.asBoolean()) {
        return true;
      }
    }
    return false;
  }
}

代码示例来源:origin: marcelo-mason/SimpleClans

public static boolean isVanished(Player player) {
  if (player != null && player.hasMetadata("vanished") && !player.getMetadata("vanished").isEmpty()) {
    return player.getMetadata("vanished").get(0).asBoolean();
  }
  return false;
}

代码示例来源:origin: mcMMO-Dev/mcMMO

public MobHealthDisplayUpdaterTask(LivingEntity target) {
  if (target.isValid()) {
    this.target = target;
    this.oldName = target.getMetadata(mcMMO.customNameKey).get(0).asString();
    this.oldNameVisible = target.getMetadata(mcMMO.customVisibleKey).get(0).asBoolean();
  }
}

代码示例来源:origin: mcMMO-Dev/mcMMO

/**
 * Monitor EntityDeath events.
 *
 * @param event
 *            The event to watch
 */
@EventHandler(priority = EventPriority.LOWEST)
public void onEntityDeathLowest(EntityDeathEvent event) {
  /* WORLD BLACKLIST CHECK */
  if(WorldBlacklist.isWorldBlacklisted(event.getEntity().getWorld()))
    return;
  LivingEntity entity = event.getEntity();
  if (Misc.isNPCEntity(entity)) {
    return;
  }
  if (entity.hasMetadata(mcMMO.customNameKey)) {
    entity.setCustomName(entity.getMetadata(mcMMO.customNameKey).get(0).asString());
    entity.removeMetadata(mcMMO.customNameKey, plugin);
  }
  if (entity.hasMetadata(mcMMO.customVisibleKey)) {
    entity.setCustomNameVisible(entity.getMetadata(mcMMO.customVisibleKey).get(0).asBoolean());
    entity.removeMetadata(mcMMO.customVisibleKey, plugin);
  }
  if (entity.hasMetadata(mcMMO.entityMetadataKey)) {
    entity.removeMetadata(mcMMO.entityMetadataKey, plugin);
  }
}

相关文章