当前位置: 首页>>代码示例>>Java>>正文


Java Block.getState方法代码示例

本文整理汇总了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.");
                }
            }
        }
    }
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:24,代码来源:CrowbarListener.java

示例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();
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:24,代码来源:Uncarried.java

示例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
        }
    }
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:18,代码来源:PearlGlitchListener.java

示例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();
}
 
开发者ID:NyaaCat,项目名称:CapCat,代码行数:10,代码来源:SignCommands.java

示例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;
}
 
开发者ID:Syst3ms,项目名称:QuarSK,代码行数:8,代码来源:ExprBeaconTier.java

示例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);
	}
}
 
开发者ID:thekeenant,项目名称:mczone,代码行数:13,代码来源:GeneralEvents.java

示例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();
            }
        }
    }
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:33,代码来源:ProjectileMatchModule.java

示例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();
              }
          }
      }
  }
 
开发者ID:thekeenant,项目名称:mczone,代码行数:41,代码来源:GameEvents.java

示例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;
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:11,代码来源:EventSignListener.java

示例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;
}
 
开发者ID:thekeenant,项目名称:mczone,代码行数:8,代码来源:Lobby.java

示例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());
    }
}
 
开发者ID:MinecraftMarket,项目名称:MinecraftMarket-Plugin,代码行数:13,代码来源:SkullUtils.java

示例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;
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:10,代码来源:BlockMaterialMap.java

示例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;
		}
	}
}
 
开发者ID:ThEWiZ76,项目名称:KingdomFactions,代码行数:29,代码来源:PlayerInteractEventListener.java

示例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;
}
 
开发者ID:Syst3ms,项目名称:QuarSK,代码行数:7,代码来源:SExprBeaconFuel.java

示例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());
            }
        }
    }
}
 
开发者ID:tastybento,项目名称:bskyblock,代码行数:54,代码来源:IslandBlock.java


注:本文中的org.bukkit.block.Block.getState方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。