org.bukkit.block.Block.getWorld()方法的使用及代码示例

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

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

Block.getWorld介绍

[英]Gets the world which contains this Block
[中]

代码示例

代码示例来源:origin: GlowstoneMC/Glowstone

/**
 * Get the Leash Hitch to which entities should be attached at the block. Useful if multiple
 * Leash Hitches could exist.
 *
 * @param block the Block to get the relevant Leash Hitch for
 * @return either an already existing Leash Hitch, or a newly spawned one
 */
public static LeashHitch getLeashHitchAt(Block block) {
  // Use the oldest leash entity as leash holder
  // If none found, create a new leash hitch
  Stream<LeashHitch> sorted = GlowLeashHitch.getExistingLeashHitches(block).sorted(
    comparingInt(Entity::getTicksLived)
      .reversed()
  );
  Optional<LeashHitch> first = sorted.findFirst();
  return first.orElseGet(
    () -> first.orElse(block.getWorld().spawn(block.getLocation(), LeashHitch.class)));
}

代码示例来源:origin: GlowstoneMC/Glowstone

/**
 * Get all LeashHitch Entities in the specified block.
 *
 * @param block the Block to search LeashHitch Entities in
 * @return a Stream of all found LeashHitch Entities
 */
private static Stream<LeashHitch> getExistingLeashHitches(Block block) {
  Location location = block.getLocation().add(0.5, 0.5, 0.5);
  Collection<Entity> nearbyEntities = block.getWorld()
    .getNearbyEntities(location, 0.49, 0.49, 0.49);
  return nearbyEntities.stream()
    .filter(e -> e instanceof LeashHitch)
    .map(e -> (LeashHitch) e);
}

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

private World getGameWorld(CommandSender sender) {
  if (sender instanceof HumanEntity) {
    World world = ((HumanEntity) sender).getWorld();
    if (world != null) {
      return world;
    }
  } else if (sender instanceof BlockCommandSender) {
    return ((BlockCommandSender) sender).getBlock().getWorld();
  }
  return Bukkit.getWorlds().get(0);
}

代码示例来源:origin: GlowstoneMC/Glowstone

@Override
  protected String disambiguate(Block subject, String metadataKey) {
    return subject.getWorld() + "," + subject.getX() + "," + subject.getY() + "," + subject
        .getZ() + ":" + metadataKey;
  }
}

代码示例来源:origin: GlowstoneMC/Glowstone

/**
 * Returns the world that the given command sender is referring to when not specifying one.
 *
 * @param sender a command sender
 * @return the command sender's world if the sender is a block or entity, or the default world
 *         otherwise
 */
public static GlowWorld getWorld(CommandSender sender) {
  if (sender instanceof ConsoleCommandSender) {
    return getDefaultWorld();
  } else if (sender instanceof Entity) {
    return (GlowWorld) ((Entity) sender).getWorld();
  } else if (sender instanceof BlockCommandSender) {
    return (GlowWorld) ((BlockCommandSender) sender).getBlock().getWorld();
  }
  return getDefaultWorld();
}

代码示例来源:origin: GlowstoneMC/Glowstone

private void setType(Block block, int type, int data) {
    World world = block.getWorld();
    int x = block.getX();
    int y = block.getY();
    int z = block.getZ();
    GlowChunk chunk = (GlowChunk) world.getChunkAt(block);
    chunk.setType(x & 0xf, z & 0xf, y, type);
    chunk.setMetaData(x & 0xf, z & 0xf, y, data);
  }
}

代码示例来源:origin: GlowstoneMC/Glowstone

/**
 * Convert a TNT block into a primed TNT entity with the player who ignited the TNT.
 *
 * @param tntBlock The block to ignite.
 * @param ignitedByExplosion True if another explosion caused this ignition.
 * @param player The player who ignited the TNT.
 */
public static void igniteBlock(
  Block tntBlock, boolean ignitedByExplosion, GlowPlayer player) {
  tntBlock.setType(Material.AIR);
  World world = tntBlock.getWorld();
  GlowTntPrimed tnt = (GlowTntPrimed) world
    .spawnEntity(tntBlock.getLocation().add(0.5, 0, 0.5), EntityType.PRIMED_TNT);
  tnt.setSource(player);
  tnt.setIgnitedByExplosion(ignitedByExplosion);
  world.playSound(tntBlock.getLocation(), Sound.ENTITY_TNT_PRIMED, 1, 1);
}

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

BlockCommandSender blockCommandSender = (BlockCommandSender) source;
if (blockCommandSender.getBlock().getWorld().getGameRuleValue("commandBlockOutput").equalsIgnoreCase("false")) {
  Bukkit.getConsoleSender().sendMessage(result);
  return;

代码示例来源:origin: GlowstoneMC/Glowstone

private void placeBoat(GlowPlayer player, ItemStack holding) {
  Block targetBlock = player.getTargetBlock((Set<Material>) null, 5);
  if (targetBlock != null && !targetBlock.isEmpty()
      && targetBlock.getRelative(BlockFace.UP).isEmpty()) {
    Location location = targetBlock.getRelative(BlockFace.UP).getLocation();
    // center boat on cursor location
    location.add(0.6875f, 0, 0.6875f);
    location.setYaw(player.getLocation().getYaw());
    Boat boat = targetBlock.getWorld().spawn(location, Boat.class);
    boat.setWoodType(woodType);
    if (player.getGameMode() != GameMode.CREATIVE) {
      player.getInventory().removeItem(holding);
    }
  }
}

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

public static int getBlockPlaceHash(final Block block, final Material mat) {
  int hash = getCoordHash(block);
  if (mat != null) {
    hash |= mat.name().hashCode();
  }
  hash |= block.getWorld().getName().hashCode();
  return hash;
}

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

@Override
public synchronized void setTrue(Block block) {
  if (block == null) {
    return;
  }
  setTrue(block.getX(), block.getY(), block.getZ(), block.getWorld());
}

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

@Override
public synchronized boolean isTrue(Block block) {
  if (block == null) {
    return false;
  }
  return isTrue(block.getX(), block.getY(), block.getZ(), block.getWorld());
}

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

@Override
public synchronized void setFalse(Block block) {
  if (block == null) {
    return;
  }
  setFalse(block.getX(), block.getY(), block.getZ(), block.getWorld());
}

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

private boolean isItemAppliedToBlock(ItemStack item, Block clicked) {
  return Materials.isItemAppliedToBlock(item.getType(), clicked.getType())
      && !hasInteractBypass(clicked)
      && !hasInteractBypass(clicked.getWorld(), item);
}

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

@EventHandler(ignoreCancelled = true)
public void onBlockMultiPlace(BlockMultiPlaceEvent event) {
  List<Block> blocks = new ArrayList<>();
  for (BlockState bs : event.getReplacedBlockStates()) {
    blocks.add(bs.getBlock());
  }
  Events.fireToCancel(event, new PlaceBlockEvent(event, create(event.getPlayer()),
      event.getBlock().getWorld(), blocks, event.getBlock().getType()));
}

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

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockGrow(BlockGrowEvent event)
{
  /* WORLD BLACKLIST CHECK */
  if(WorldBlacklist.isWorldBlacklisted(event.getBlock().getWorld()))
    return;
  BlockState blockState = event.getBlock().getState();
  if (!BlockUtils.shouldBeWatched(blockState)) {
    return;
  }
  mcMMO.getPlaceStore().setFalse(blockState);
}

代码示例来源:origin: TheBusyBiscuit/Slimefun4

public static ArmorStand getArmorStand(Block hopper) {
  Location l = new Location(hopper.getWorld(), hopper.getX() + 0.5, hopper.getY() + offset, hopper.getZ() + 0.5);
  
  for (Entity n: l.getChunk().getEntities()) {
    if (n instanceof ArmorStand) {
      if (n.getCustomName() == null && l.distanceSquared(n.getLocation()) < 0.4D) return (ArmorStand) n;
    }
  }
  
  ArmorStand hologram = ArmorStandFactory.createHidden(l);
  hologram.setCustomNameVisible(false);
  hologram.setCustomName(null);
  return hologram;
}

代码示例来源:origin: nsporillo/GlobalWarming

@EventHandler
public void blockFormEvent(BlockFormEvent event) {
  if (event.getNewState().getType() == Material.SNOW) {
    WorldClimateEngine climateEngine = ClimateEngine.getInstance().getClimateEngine(event.getBlock().getWorld().getUID());
    if (climateEngine != null && climateEngine.isEffectEnabled(ClimateEffectType.SNOW_FORMATION)) {
      double temperature = climateEngine.getTemperature();
      if (event.getBlock().getY() < heightMap.getValue(temperature)) {
        event.setCancelled(true);
      }
    }
  }
}

代码示例来源:origin: nsporillo/GlobalWarming

@EventHandler
public void blockFormEvent(BlockFormEvent event) {
  if (event.getNewState().getType() == Material.ICE) {
    WorldClimateEngine climateEngine = ClimateEngine.getInstance().getClimateEngine(event.getBlock().getWorld().getUID());
    if (climateEngine != null && climateEngine.isEffectEnabled(ClimateEffectType.ICE_FORMATION)) {
      if (event.getBlock().getY() < heightMap.getValue(climateEngine.getTemperature())) {
        event.setCancelled(true);
      }
    }
  }
}

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

@EventHandler(ignoreCancelled = true)
public void onBlockDispense(BlockDispenseEvent event) {
  ConfigurationManager cfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager();
  WorldConfiguration wcfg = cfg.get(BukkitAdapter.adapt(event.getBlock().getWorld()));
  if (wcfg.getBlacklist() != null) {
    if (!wcfg.getBlacklist().check(new BlockDispenseBlacklistEvent(null, BukkitAdapter.asBlockVector(event.getBlock().getLocation()),
        createTarget(event.getItem())), false, false)) {
      event.setCancelled(true);
    }
  }
}

相关文章