當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。