本文整理匯總了Java中org.bukkit.block.BlockState類的典型用法代碼示例。如果您正苦於以下問題:Java BlockState類的具體用法?Java BlockState怎麽用?Java BlockState使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
BlockState類屬於org.bukkit.block包,在下文中一共展示了BlockState類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onBlockBreak
import org.bukkit.block.BlockState; //導入依賴的package包/類
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onBlockBreak(BlockBreakEvent event) {
Block block = event.getBlock();
if (isDeathSign(block)) {
BlockState state = block.getState();
Sign sign = (Sign) state;
ItemStack stack = new ItemStack(Material.SIGN, 1);
ItemMeta meta = stack.getItemMeta();
meta.setDisplayName(DEATH_SIGN_ITEM_NAME);
meta.setLore(Arrays.asList(sign.getLines()));
stack.setItemMeta(meta);
Player player = event.getPlayer();
World world = player.getWorld();
if (player.getGameMode() != GameMode.CREATIVE && world.isGameRule("doTileDrops")) {
world.dropItemNaturally(block.getLocation(), stack);
}
// Manually handle the dropping
event.setCancelled(true);
block.setType(Material.AIR);
state.update();
}
}
示例2: onBlockIgnite
import org.bukkit.block.BlockState; //導入依賴的package包/類
@EventWrapper
public void onBlockIgnite(final BlockIgniteEvent event) {
// Flint & steel generates a BlockPlaceEvent
if(event.getCause() == BlockIgniteEvent.IgniteCause.FLINT_AND_STEEL) return;
BlockState oldState = event.getBlock().getState();
BlockState newState = BlockStateUtils.cloneWithMaterial(event.getBlock(), Material.FIRE);
ParticipantState igniter = null;
if(event.getIgnitingEntity() != null) {
// The player themselves using flint & steel, or any of
// several types of owned entity starting or spreading a fire.
igniter = entityResolver.getOwner(event.getIgnitingEntity());
} else if(event.getIgnitingBlock() != null) {
// Fire, lava, or flint & steel in a dispenser
igniter = blockResolver.getOwner(event.getIgnitingBlock());
}
callEvent(event, oldState, newState, igniter);
}
示例3: getCropState
import org.bukkit.block.BlockState; //導入依賴的package包/類
public String getCropState(BlockState blockState) {
switch (blockState.getType()) { // .getBlock().getType()) {
case COCOA:
return ((CocoaPlant) blockState.getData()).getSize().toString();
case NETHER_WARTS:
return ((NetherWarts) blockState.getData()).getState().toString();
case MELON_STEM:
return (int) blockState.getBlock().getData() + "";
case PUMPKIN_STEM:
return (int) blockState.getBlock().getData() + "";
case CACTUS:
return null;
case BROWN_MUSHROOM:
return null;
case RED_MUSHROOM:
return null;
case SUGAR_CANE_BLOCK:
return null;
default:
//CropControl.getPlugin().debug("Unable to find CropState match for {0}", blockState);
return ((Crops) blockState.getData()).getState().toString();
}
}
示例4: onTreeGrow
import org.bukkit.block.BlockState; //導入依賴的package包/類
/**
* Prevents trees from growing outside of the protected area.
*
* @param e
*/
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onTreeGrow(final StructureGrowEvent e) {
if (DEBUG) {
plugin.getLogger().info(e.getEventName());
}
// Check world
if (!Util.inWorld(e.getLocation())) {
return;
}
// Check if this is on an island
Island island = plugin.getIslands().getIslandAt(e.getLocation());
if (island == null || island.isSpawn()) {
return;
}
Iterator<BlockState> it = e.getBlocks().iterator();
while (it.hasNext()) {
BlockState b = it.next();
if (b.getType() == Material.LOG || b.getType() == Material.LOG_2
|| b.getType() == Material.LEAVES || b.getType() == Material.LEAVES_2) {
if (!island.onIsland(b.getLocation())) {
it.remove();
}
}
}
}
示例5: onTreeGrow
import org.bukkit.block.BlockState; //導入依賴的package包/類
/**
* Converts trees to gravel and glowstone
*
* @param e
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onTreeGrow(final StructureGrowEvent e) {
if (DEBUG)
plugin.getLogger().info("DEBUG: " + e.getEventName());
if (!Settings.netherTrees) {
return;
}
if (!Settings.netherGenerate || IslandWorld.getNetherWorld() == null) {
return;
}
// Check world
if (!e.getLocation().getWorld().equals(IslandWorld.getNetherWorld())) {
return;
}
for (BlockState b : e.getBlocks()) {
if (b.getType() == Material.LOG || b.getType() == Material.LOG_2) {
b.setType(Material.GRAVEL);
} else if (b.getType() == Material.LEAVES || b.getType() == Material.LEAVES_2) {
b.setType(Material.GLOWSTONE);
}
}
}
示例6: checkItemFrameRotate
import org.bukkit.block.BlockState; //導入依賴的package包/類
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void checkItemFrameRotate(PlayerInteractEntityEvent event) {
if(event.getRightClicked() instanceof ItemFrame) {
ItemFrame itemFrame = (ItemFrame) event.getRightClicked();
if(itemFrame.getItem() != null) {
// If frame contains an item, right-click will rotate it, which is handled as a "use" event
this.handleUse(event, getHangingBlockState(itemFrame), this.match.getParticipant(event.getPlayer()));
} else if(event.getPlayer().getItemInHand() != null) {
// If the frame is empty and it's right clicked with an item, this will place the item in the frame,
// which is handled as a "place" event, with the placed item as the block material
BlockState blockState = BlockStateUtils.cloneWithMaterial(itemFrame.getLocation().getBlock(),
event.getPlayer().getItemInHand().getData());
this.handleHangingPlace(event, blockState, event.getPlayer());
}
}
}
示例7: handleUse
import org.bukkit.block.BlockState; //導入依賴的package包/類
private void handleUse(Event event, BlockState blockState, MatchPlayer player) {
if(!player.canInteract()) return;
PlayerBlockEventQuery query = new PlayerBlockEventQuery(player, event, blockState);
for(EventRule rule : this.ruleContext.get(EventRuleScope.USE)) {
if(rule.region().contains(blockState)) {
if(processQuery(rule, query)) {
if(query.getEvent() instanceof PlayerInteractEvent && ((PlayerInteractEvent) query.getEvent()).isCancelled()) {
PlayerInteractEvent pie = (PlayerInteractEvent) query.getEvent();
pie.setCancelled(false);
pie.setUseItemInHand(Event.Result.ALLOW);
pie.setUseInteractedBlock(Event.Result.DENY);
if(rule.message() != null) {
player.sendWarning(rule.message(), false);
}
}
if(this.useRegionPriority) {
break;
}
}
}
}
}
示例8: setTileEntityNBTTagCompound
import org.bukkit.block.BlockState; //導入依賴的package包/類
public static void setTileEntityNBTTagCompound(BlockState tile, Object nbtTag) {
Object pos = toBlockPosition(new BlockPos() {
@Override
public int getX() {
return tile.getX();
}
@Override
public int getY() {
return tile.getY();
}
@Override
public int getZ() {
return tile.getZ();
}
});
Object nmsWorld = getWorldServer(tile.getWorld());
if (nmsWorld == null || pos == null) return;
Object nmsTile = getDeclaredMethod("getTileEntity", nmsWorld.getClass(), pos.getClass()).invoke(nmsWorld, true, pos);
getDeclaredMethod("a", getNmsClass("TileEntity"), getNmsClass("NBTTagCompound")).invoke(nmsTile, true, nbtTag);
}
示例9: onBlockPlace
import org.bukkit.block.BlockState; //導入依賴的package包/類
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onBlockPlace(BlockPlaceEvent event) {
ItemStack stack = event.getItemInHand();
BlockState state = event.getBlock().getState();
if (state instanceof Sign && stack.hasItemMeta()) {
ItemMeta meta = stack.getItemMeta();
if (meta.hasDisplayName() && meta.getDisplayName().equals(DEATH_SIGN_ITEM_NAME)) {
Sign sign = (Sign) state;
List<String> lore = meta.getLore();
int count = 0;
for (String loreLine : lore) {
sign.setLine(count++, loreLine);
if (count == 4)
break;
}
sign.update();
//sign.setEditible(false);
}
}
}
示例10: onBlockBreak
import org.bukkit.block.BlockState; //導入依賴的package包/類
@EventHandler(ignoreCancelled=true, priority=EventPriority.HIGHEST)
public void onBlockBreak(BlockBreakEvent event)
{
Block block = event.getBlock();
if (isEventSign(block))
{
BlockState state = block.getState();
Sign sign = (Sign)state;
ItemStack stack = new ItemStack(Material.SIGN, 1);
ItemMeta meta = stack.getItemMeta();
meta.setDisplayName(EVENT_SIGN_ITEM_NAME);
meta.setLore(Arrays.asList(sign.getLines()));
stack.setItemMeta(meta);
Player player = event.getPlayer();
World world = player.getWorld();
Location blockLocation = block.getLocation();
if ((player.getGameMode() != GameMode.CREATIVE) && (world.isGameRule("doTileDrops"))) {
world.dropItemNaturally(blockLocation, stack);
}
event.setCancelled(true);
block.setType(Material.AIR);
state.update();
}
}
示例11: placeStanding
import org.bukkit.block.BlockState; //導入依賴的package包/類
public static boolean placeStanding(Location location, BannerMeta meta) {
Block block = location.getBlock();
block.setType(Material.STANDING_BANNER, false);
final BlockState state = block.getState();
if(state instanceof Banner) {
Banner banner = (Banner) block.getState();
applyToBlock(banner, meta);
org.bukkit.material.Banner material = (org.bukkit.material.Banner) banner.getData();
material.setFacingDirection(BlockFaces.yawToFace(location.getYaw()));
banner.setData(material);
banner.update(true);
return true;
}
return false;
}
示例12: canRenew
import org.bukkit.block.BlockState; //導入依賴的package包/類
public boolean canRenew(BlockState original, BlockState current) {
// Original block must be in the region and match the renewable filter
if(!region.contains(original)) return false;
BlockQuery originalQuery = new BlockQuery(original);
if(!renewableBlocks.query(originalQuery).isAllowed()) return false;
MaterialData originalMaterial = original.getMaterialData();
MaterialData currentMaterial = current.getMaterialData();
// If current material matches the original, block is already renewed
if(originalMaterial.equals(currentMaterial)) return false;
// If the original and current blocks are both shuffleable, block is already renewed
if(shuffleableBlocks.query(originalQuery).isAllowed() && shuffleableBlocks.query(new BlockQuery(current)).isAllowed()) {
return false;
}
// Otherwise, block is eligible to be renewed
return true;
}
示例13: onBlockBurn
import org.bukkit.block.BlockState; //導入依賴的package包/類
@EventWrapper
public void onBlockBurn(final BlockBurnEvent event) {
Match match = PGM.getMatchManager().getMatch(event.getBlock().getWorld());
if(match == null) return;
BlockState oldState = event.getBlock().getState();
BlockState newState = BlockStateUtils.toAir(oldState);
MatchPlayerState igniterState = null;
for(BlockFace face : NEIGHBORS) {
Block neighbor = oldState.getBlock().getRelative(face);
if(neighbor.getType() == Material.FIRE) {
igniterState = blockResolver.getOwner(neighbor);
if(igniterState != null) break;
}
}
this.callEvent(event, oldState, newState, igniterState);
}
示例14: renew
import org.bukkit.block.BlockState; //導入依賴的package包/類
boolean renew(BlockVector pos, MaterialData material) {
// We need to do the entity check here rather than canRenew, because we are not
// notified when entities move in our out of the way.
if(!isClearOfEntities(pos)) return false;
Location location = pos.toLocation(match.getWorld());
Block block = location.getBlock();
BlockState newState = location.getBlock().getState();
newState.setMaterialData(material);
BlockRenewEvent event = new BlockRenewEvent(block, newState, this);
match.callEvent(event); // Our own handler will get this and remove the block from the pool
if(event.isCancelled()) return false;
newState.update(true, true);
if(definition.particles) {
NMSHacks.playBlockBreakEffect(match.getWorld(), pos, material.getItemType());
}
if(definition.sound) {
NMSHacks.playBlockPlaceSound(match.getWorld(), pos, material.getItemType(), 1f);
}
return true;
}
示例15: onBlockPlace
import org.bukkit.block.BlockState; //導入依賴的package包/類
@EventHandler(ignoreCancelled=true, priority=EventPriority.HIGHEST)
public void onBlockPlace(BlockPlaceEvent event)
{
ItemStack stack = event.getItemInHand();
BlockState state = event.getBlock().getState();
if (((state instanceof Sign)) && (stack.hasItemMeta()))
{
ItemMeta meta = stack.getItemMeta();
if ((meta.hasDisplayName()) && (meta.getDisplayName().equals(EVENT_SIGN_ITEM_NAME)))
{
Sign sign = (Sign)state;
List<String> lore = meta.getLore();
int count = 0;
for (String loreLine : lore)
{
sign.setLine(count++, loreLine);
if (count == 4) {
break;
}
}
sign.update();
}
}
}