本文整理匯總了Java中org.bukkit.block.Block.getState方法的典型用法代碼示例。如果您正苦於以下問題:Java Block.getState方法的具體用法?Java Block.getState怎麽用?Java Block.getState使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.bukkit.block.Block
的用法示例。
在下文中一共展示了Block.getState方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onBlockPlace
import org.bukkit.block.Block; //導入方法依賴的package包/類
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onBlockPlace(BlockPlaceEvent event) {
Block block = event.getBlockPlaced();
ItemStack stack = event.getItemInHand();
Player player = event.getPlayer();
if (block.getState() instanceof CreatureSpawner && stack.hasItemMeta()) {
ItemMeta meta = stack.getItemMeta();
if (meta.hasLore() && meta.hasDisplayName()) {
CreatureSpawner spawner = (CreatureSpawner) block.getState();
List<String> lore = meta.getLore();
if (!lore.isEmpty()) {
String spawnerName = ChatColor.stripColor(lore.get(0).toUpperCase());
Optional<EntityType> entityTypeOptional = GuavaCompat.getIfPresent(EntityType.class, spawnerName);
if (entityTypeOptional.isPresent()) {
spawner.setSpawnedType(entityTypeOptional.get());
spawner.update(true, true);
player.sendMessage(ChatColor.AQUA + "Placed a " + ChatColor.BLUE + spawnerName + ChatColor.AQUA + " spawner.");
}
}
}
}
}
示例2: Uncarried
import org.bukkit.block.Block; //導入方法依賴的package包/類
public Uncarried(Flag flag, Post post, @Nullable Location location) {
super(flag, post);
if(location == null) location = flag.getReturnPoint(post);
this.location = new Location(location.getWorld(),
location.getBlockX() + 0.5,
location.getBlockY(),
location.getBlockZ() + 0.5,
location.getYaw(),
location.getPitch());
if(!flag.getMatch().getWorld().equals(this.location.getWorld())) {
throw new IllegalStateException("Tried to place flag in the wrong world");
}
Block block = this.location.getBlock();
if(block.getType() == Material.STANDING_BANNER) {
// Banner may already be here at match start
this.oldBlock = BlockStateUtils.cloneWithMaterial(block, Material.AIR);
} else {
this.oldBlock = block.getState();
}
this.oldBase = block.getRelative(BlockFace.DOWN).getState();
}
示例3: onPlayerInteract
import org.bukkit.block.Block; //導入方法依賴的package包/類
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
public void onPlayerInteract(PlayerInteractEvent event) {
if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.hasItem() && event.getItem().getType() == Material.ENDER_PEARL) {
Block block = event.getClickedBlock();
// Don't prevent opening chests, etc, as these won't throw the Enderpearls anyway
if (block.getType().isSolid() && !(block.getState() instanceof InventoryHolder)) {
Faction factionAt = HCF.getPlugin().getFactionManager().getFactionAt(block.getLocation());
if (!(factionAt instanceof ClaimableFaction)) {
return;
}
event.setCancelled(true);
Player player = event.getPlayer();
player.setItemInHand(event.getItem()); // required to update Enderpearl count
}
}
}
示例4: getSignLookat
import org.bukkit.block.Block; //導入方法依賴的package包/類
public Sign getSignLookat(CommandSender sender) {
Player p = asPlayer(sender);
Block b = p.getTargetBlock((Set<Material>) null, 5);// TODO use nms rayTrace
if (b == null || !b.getType().isBlock() || (b.getType() != Material.WALL_SIGN && b.getType() != Material.SIGN_POST)) {
throw new BadCommandException("user.error.not_sign");
}
return (Sign)b.getState();
}
示例5: convert
import org.bukkit.block.Block; //導入方法依賴的package包/類
@Override
public Number convert(Block b) {
if (b.getState() instanceof Beacon) {
return ((Beacon) b.getState()).getTier();
}
return null;
}
示例6: onSignClick
import org.bukkit.block.Block; //導入方法依賴的package包/類
@EventHandler
public void onSignClick(PlayerInteractEvent event) {
if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_AIR)
return;
Block b = event.getClickedBlock();
if (b.getType() == Material.SIGN_POST || b.getType() == Material.WALL_SIGN) {
Sign sign = (Sign) b.getState();
SignClickEvent ev = new SignClickEvent(event.getPlayer(), sign, event.getClickedBlock(), event.getAction() == Action.RIGHT_CLICK_BLOCK);
Bukkit.getServer().getPluginManager().callEvent(ev);
}
}
示例7: onProjectileHitEvent
import org.bukkit.block.Block; //導入方法依賴的package包/類
@EventHandler
public void onProjectileHitEvent(ProjectileHitEvent event) {
final Projectile projectile = event.getEntity();
final ProjectileDefinition projectileDefinition = Projectiles.getProjectileDefinition(projectile);
if(projectileDefinition == null) return;
final Filter filter = projectileDefinition.destroyFilter();
if(filter == null) return;
final BlockIterator blockIterator = new BlockIterator(projectile.getWorld(), projectile.getLocation().toVector(), projectile.getVelocity().normalize(), 0d, 2);
Block hitBlock = null;
while(blockIterator.hasNext()) {
hitBlock = blockIterator.next();
if(hitBlock.getType() != Material.AIR) break;
}
if(hitBlock != null) {
final MatchPlayer shooter = projectile.getShooter() instanceof Player ? getMatch().getPlayer((Player) projectile.getShooter()) : null;
final IQuery query = shooter != null ? new PlayerBlockEventQuery(shooter, event, hitBlock.getState())
: new BlockEventQuery(event, hitBlock);
if(filter.query(query).isAllowed()) {
final BlockTransformEvent bte = new BlockTransformEvent(event, hitBlock, Material.AIR);
match.callEvent(bte);
if(!bte.isCancelled()) {
hitBlock.setType(Material.AIR);
projectile.remove();
}
}
}
}
示例8: onPlayerMove
import org.bukkit.block.Block; //導入方法依賴的package包/類
@EventHandler(ignoreCancelled = true)
public void onPlayerMove(PlayerMoveEvent event) {
Player p = event.getPlayer();
Location to = event.getTo();
Location from = event.getFrom();
World world = to.getWorld();
if (to.clone().add(0, -1, 0).getBlock().getType() != Material.REDSTONE_LAMP_ON)
return;
if (from.clone().add(0, -1, 0).getBlock().getType() == Material.REDSTONE_LAMP_ON)
return;
for (Block block : getPortalNear(world, to.getBlockX(), to.getBlockY(), to.getBlockZ())) {
for (BlockFace bf : BlockFace.values()) {
Block relative = block.getRelative(bf);
if (relative.getTypeId() == SIGN) {
// Specific server
Sign sign = (Sign) relative.getState();
Portal portal = null;
for (Portal po : Portal.getList()) {
if (WorldUtil.sameBlock(po.getSign().getBlock(), sign.getBlock())) {
portal = po;
break;
}
}
if (portal == null)
return;
if (portal.getCurrent().getStatus() == Status.CLOSED)
Chat.player(p, "&cThat server is currently unavailable!");
else
portal.getCurrent().connect(event.getPlayer());
portal.updateSign();
}
}
}
}
示例9: isEventSign
import org.bukkit.block.Block; //導入方法依賴的package包/類
private boolean isEventSign(Block block)
{
BlockState state = block.getState();
if ((state instanceof Sign))
{
String[] lines = ((Sign)state).getLines();
return (lines.length > 0) && (lines[1] != null) && (lines[1].equals(ChatColor.DARK_PURPLE + "captured by"));
}
return false;
}
示例10: getKitSign
import org.bukkit.block.Block; //導入方法依賴的package包/類
public Sign getKitSign(Sign s) {
for (Block b : kitSigns)
if (b.getX() == s.getX() && b.getY() == s.getY() && b.getZ() == s.getZ())
if (b.getType() == Material.SIGN || b.getType() == Material.WALL_SIGN)
return (Sign) b.getState();
return null;
}
示例11: setSkullWithNonPlayerProfile
import org.bukkit.block.Block; //導入方法依賴的package包/類
@SuppressWarnings("deprecation")
public static void setSkullWithNonPlayerProfile(String skinURL, String name, Block skullBlock) {
if (skullBlock.getState() instanceof Skull) {
Skull skull = (Skull) skullBlock.getState();
try {
setSkullProfile(skull, getNonPlayerProfile(skinURL, name));
} catch (Exception e) {
e.printStackTrace();
}
skullBlock.getWorld().refreshChunk(skullBlock.getChunk().getX(), skullBlock.getChunk().getZ());
}
}
示例12: next
import org.bukkit.block.Block; //導入方法依賴的package包/類
@Override
public BlockState next() {
Block block = BlockUtils.blockAt(world, iter.key());
if(block == null) return null;
BlockState state = block.getState();
state.setTypeId(decodeTypeId(iter.value()));
state.setRawData(decodeMetadata(iter.value()));
return state;
}
示例13: onPlayerInteract
import org.bukkit.block.Block; //導入方法依賴的package包/類
public void onPlayerInteract(PlayerInteractEvent e) {
if (e.isCancelled()) return;
KingdomFactionsPlayer p = PlayerModule.getInstance().getPlayer(e.getPlayer());
if(p.getSettingsProfile().hasAdminMode()) return;
if (e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
if (e.getClickedBlock() == null) return;
Block clickedBlock = e.getClickedBlock();
if (clickedBlock.getType().equals(Material.CHEST) || clickedBlock.getType().equals(Material.TRAPPED_CHEST) || clickedBlock.getType().equals(Material.BEACON)) {
e.setCancelled(!ProtectionModule.getInstance().tryInfluence(p, 500));
return;
}
if (clickedBlock.getType().equals(Material.BURNING_FURNACE) || clickedBlock.getType().equals(Material.FURNACE) || clickedBlock.getType().equals(Material.DISPENSER) || clickedBlock.getType().equals(Material.HOPPER) || clickedBlock.getType().equals(Material.DROPPER)) {
e.setCancelled(!ProtectionModule.getInstance().tryInfluence(p, 150));
return;
}
MaterialData data = clickedBlock.getState() != null ? clickedBlock.getState().getData() : null;
if (data instanceof Openable) {
if (clickedBlock.getType() == Material.IRON_TRAPDOOR || clickedBlock.getType() == Material.IRON_DOOR) return;
e.setCancelled(!ProtectionModule.getInstance().tryInfluence(p, 150));
return;
}
}
}
示例14: convert
import org.bukkit.block.Block; //導入方法依賴的package包/類
@Nullable
@Override
public ItemStack convert(@NotNull Block block) {
BlockState state = block.getState();
return state instanceof BeaconInventory ? ((BeaconInventory) state).getItem() : null;
}
示例15: paste
import org.bukkit.block.Block; //導入方法依賴的package包/類
/**
* Paste this block at blockLoc
* @param nms
* @param blockLoc
*/
//@SuppressWarnings("deprecation")
@SuppressWarnings("deprecation")
public void paste(NMSAbstraction nms, Location blockLoc, boolean usePhysics, Biome biome) {
// Only paste air if it is below the sea level and in the overworld
Block block = new Location(blockLoc.getWorld(), x, y, z).add(blockLoc).getBlock();
block.setBiome(biome);
block.getChunk().load();
nms.setBlockSuperFast(block, typeId, data, usePhysics);
if (signText != null) {
if (block.getTypeId() != typeId) {
block.setTypeId(typeId);
}
// Sign
Sign sign = (Sign) block.getState();
int index = 0;
for (String line : signText) {
sign.setLine(index++, line);
}
sign.update();
} else if (banner != null) {
banner.set(block);
} else if (spawnerBlockType != null) {
if (block.getTypeId() != typeId) {
block.setTypeId(typeId);
}
CreatureSpawner cs = (CreatureSpawner)block.getState();
cs.setSpawnedType(spawnerBlockType);
} else if (!chestContents.isEmpty()) {
if (block.getTypeId() != typeId) {
block.setTypeId(typeId);
}
// Check if this is a double chest
Chest chestBlock = (Chest) block.getState();
InventoryHolder iH = chestBlock.getInventory().getHolder();
if (iH instanceof DoubleChest) {
//Bukkit.getLogger().info("DEBUG: double chest");
DoubleChest doubleChest = (DoubleChest) iH;
for (ItemStack chestItem: chestContents.values()) {
doubleChest.getInventory().addItem(chestItem);
}
} else {
// Single chest
for (Entry<Byte, ItemStack> en : chestContents.entrySet()) {
chestBlock.getInventory().setItem(en.getKey(), en.getValue());
}
}
}
}