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


Java Block.setType方法代码示例

本文整理汇总了Java中org.bukkit.block.Block.setType方法的典型用法代码示例。如果您正苦于以下问题:Java Block.setType方法的具体用法?Java Block.setType怎么用?Java Block.setType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.bukkit.block.Block的用法示例。


在下文中一共展示了Block.setType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: undo

import org.bukkit.block.Block; //导入方法依赖的package包/类
private static void undo(Player p) {
    if (System.currentTimeMillis() - lastUndo < 200) {
        return;
    }
    lastUndo = System.currentTimeMillis();
    if (!configs.containsKey(p.getUniqueId())) {
        p.sendMessage("Nothing to clear.");
        return;
    }
    ArrayList<Object[][]> arr = configs.get(p.getUniqueId()).history;
    if (arr.isEmpty()) {
        p.sendMessage("Nothing to clear.");
        return;
    }
    Object[][] obj = arr.remove(arr.size() - 1);
    for (Object[] o : obj) {
        Block temp = ((World) o[0]).getBlockAt(((Location) o[1]));
        temp.setType((Material) o[2]);
        temp.setData((byte) o[3]);
    }
    p.sendMessage("Undid last paste.");
}
 
开发者ID:edasaki,项目名称:ZentrelaRPG,代码行数:23,代码来源:SchematicManager.java

示例2: onBlockBreak

import org.bukkit.block.Block; //导入方法依赖的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();
  }
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:26,代码来源:EventSignListener.java

示例3: onEntityExplode

import org.bukkit.block.Block; //导入方法依赖的package包/类
@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true)
public void onEntityExplode(EntityExplodeEvent e) {
	Iterator<Block> blocks = e.blockList().iterator();
	while (blocks.hasNext()) {
		Block block = blocks.next();
		SlimefunItem item = BlockStorage.check(block);
   		if (item != null) {
   			blocks.remove();
   			if (!item.getID().equalsIgnoreCase("HARDENED_GLASS") && !item.getID().equalsIgnoreCase("WITHER_PROOF_OBSIDIAN") && !item.getID().equalsIgnoreCase("WITHER_PROOF_GLASS") && !item.getID().equalsIgnoreCase("FORCEFIELD_PROJECTOR") && !item.getID().equalsIgnoreCase("FORCEFIELD_RELAY")) {
   				boolean success = true;
   				if (SlimefunItem.blockhandler.containsKey(item.getID())) {
   					success = SlimefunItem.blockhandler.get(item.getID()).onBreak(null, block, item, UnregisterReason.EXPLODE);
   				}
   				if (success) {
   					BlockStorage.clearBlockInfo(block);
       				block.setType(Material.AIR);
   				}
   			}
   		}
	}
    
}
 
开发者ID:StarWishsama,项目名称:Slimefun4-Chinese-Version,代码行数:23,代码来源:ToolListener.java

示例4: onBlockBreak

import org.bukkit.block.Block; //导入方法依赖的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();
    }
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:25,代码来源:DeathSignListener.java

示例5: fall

import org.bukkit.block.Block; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
private void fall(long pos, @Nullable ParticipantState breaker) {
    // Block must be removed BEFORE spawning the FallingBlock, or it will not appear on the client
    // https://bugs.mojang.com/browse/MC-72248
    Block block = blockAt(this.getMatch().getWorld(), pos);
    BlockState oldState = block.getState();
    block.setType(Material.AIR, false);
    FallingBlock fallingBlock = oldState.spawnFallingBlock();

    BlockFallEvent event = new BlockFallEvent(block, fallingBlock);
    getMatch().callEvent(breaker == null ? new BlockTransformEvent(event, block, Material.AIR)
                                         : new ParticipantBlockTransformEvent(event, block, Material.AIR, breaker));

    if(event.isCancelled()) {
        fallingBlock.remove();
        oldState.update(true, false); // Restore the old block if the fall is cancelled
    } else {
        // This is already air, but physics have not been applied yet, so do that now
        block.simulateChangeForNeighbors(oldState.getMaterialData(), new MaterialData(Material.AIR));
    }
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:22,代码来源:FallingBlocksMatchModule.java

示例6: bPress

import org.bukkit.block.Block; //导入方法依赖的package包/类
@PuzzleTrigger
public void bPress(CommandBlock cmd) {
    buttons--;

    // Play sound.
    cmd.getBlock().getWorld().playSound(cmd.getBlock().getLocation(), Sound.BLOCK_NOTE_PLING, 1F, 2F);

    // Get rid of button
    for (BlockFace face : Utils.CUBE_FACES) {
        Block bk = cmd.getBlock().getRelative(face, 2);
        if (bk.getType() == Material.WOOD_BUTTON)
            bk.setType(Material.AIR);
    }

    if (buttons == 0) {// If there are no buttons left, activate the gold torch.
        GenericItem iw = new GenericItem(ItemManager.createItem(Material.RED_ROSE, ChatColor.RED + "Red Key"));
        iw.setTagString("id", "d1_red");
        Utils.giveItem(Utils.getNearestPlayer(cmd.getLocation(), 15), iw.generateItem());
        cmd.getBlock().getWorld().playSound(cmd.getBlock().getLocation(), Sound.BLOCK_NOTE_PLING, 1F, 0.5F);
    }
}
 
开发者ID:Kneesnap,项目名称:Kineticraft,代码行数:22,代码来源:GatherPuzzle.java

示例7: setTagCompound

import org.bukkit.block.Block; //导入方法依赖的package包/类
/**
 * Set NBT of Block.
 *
 * @param b Bukkit Block.
 * @return Block with changed tags.
 */
public Block setTagCompound(Block b) {
    setInt("x", b.getX());
    setInt("y", b.getY());
    setInt("z", b.getZ());
    if (hasKey("id")) b.setType(new NBTParser("{id:" + getString("id") + ",Count:1}").toItem().getType());
    if (hasKey("data")) b.setData(getByte("data"));
    Class tileEntity = getClazz(nmsclasses, "TileEntity");
    Class craftWorld = getClazz(cbclasses, "CraftWorld");
    try {
        Object te = craftWorld.getDeclaredMethod("getTileEntityAt", int.class, int.class, int.class).invoke(b.getWorld(), b.getX(), b.getY(), b.getZ());
        if (te != null) tileEntity.getDeclaredMethod("a", getClazz(nmsclasses, "NBTTagCompound")).invoke(te, nbtTagCompound);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return b;
}
 
开发者ID:BurnyDaKath,项目名称:OMGPI,代码行数:23,代码来源:NBTParser.java

示例8: onBlockClick

import org.bukkit.block.Block; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@Override
public void onBlockClick(PlayerInteractEvent evt, Block bk, boolean rightClick) {
    if (!canTrigger() || MetadataManager.updateCooldownSilently(evt.getPlayer(), "lazerBk", 2))
        return;

    int y = getGateLocation().getBlockY();
    Block above = bk.getRelative(BlockFace.UP);
    if (isPuzzle(bk, y, Material.WOOL) && above.getType() == Material.AIR && rightClick) {
        above.setType(Material.DIODE_BLOCK_OFF);
        above.setData((byte) 0);
    }

    // Remove the next
    if (isPuzzle(bk, y + 1, Material.DIODE_BLOCK_OFF)) {
        if (!rightClick) {
            bk.setType(Material.AIR);
            return;
        }

        bk.setData((byte) (bk.getData() >= 3 ? 0 : bk.getData() + 1));
        evt.setCancelled(true);
    }
}
 
开发者ID:Kneesnap,项目名称:Kineticraft,代码行数:25,代码来源:LazerPuzzle.java

示例9: grow

import org.bukkit.block.Block; //导入方法依赖的package包/类
public static void grow(Player p, int radius) {
    Block target = p.getTargetBlock((HashSet<Byte>) null, 100);
    int radius_squared = radius * radius;
    Block toHandle;
    SchematicUserConfig cfg = getConfig(p);
    ArrayList<Block> list = new ArrayList<Block>();
    for (int x = -radius; x <= radius; x++) {
        for (int z = -radius; z <= radius; z++) {
            toHandle = target.getWorld().getHighestBlockAt(target.getX() + x, target.getZ() + z);
            if (toHandle.getType() == Material.AIR && toHandle.getRelative(BlockFace.DOWN).getType() == Material.GRASS) { // Block beneath is grass
                if (target.getLocation().distanceSquared(toHandle.getLocation()) <= radius_squared) { // Block is in radius
                    double rand = Math.random();
                    if (rand < cfg.growDensity * 5 / 6) {
                        toHandle.setType(Material.LONG_GRASS);
                        toHandle.setData((byte) 1);
                        list.add(toHandle);
                    } else if (rand < cfg.growDensity) {
                        toHandle.setType(Material.RED_ROSE); //0 4 5 6 7 8
                        byte data = (byte) (Math.random() * 6);
                        if (data > 0)
                            data += 3; //1 + 3 = 4, 2 + 3 = 5, ..., 5 + 3 = 8
                        toHandle.setData(data);
                        list.add(toHandle);
                    }
                }
            }
        }
    }
    cfg.lastGrow.add(list);
    if (SchematicManager.getConfig(p).verbose)
        p.sendMessage("Grew with radius " + radius + ".");
}
 
开发者ID:edasaki,项目名称:ZentrelaRPG,代码行数:33,代码来源:SchematicManager.java

示例10: undoGrow

import org.bukkit.block.Block; //导入方法依赖的package包/类
public static void undoGrow(Player p) {
    if (System.currentTimeMillis() - lastUndo < 200) {
        return;
    }
    lastUndo = System.currentTimeMillis();
    SchematicUserConfig cfg = getConfig(p);
    if (cfg.lastGrow.size() == 0) {
        p.sendMessage("No grow to undo.");
        return;
    }
    for (Block b : cfg.lastGrow.remove(cfg.lastGrow.size() - 1))
        b.setType(Material.AIR);
    p.sendMessage("Undid last grow.");
}
 
开发者ID:edasaki,项目名称:ZentrelaRPG,代码行数:15,代码来源:SchematicManager.java

示例11: onBlockBreak

import org.bukkit.block.Block; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onBlockBreak(final BlockBreakEvent event) {
    Player player = event.getPlayer();
    if (player.getGameMode() != GameMode.CREATIVE) {
        if (player.hasPermission("hcf.listener.autosmeltore")) {
            ItemStack stack = player.getItemInHand();
            if (stack != null && stack.getType() != Material.AIR
                    && !stack.containsEnchantment(Enchantment.SILK_TOUCH)) {
                Block block = event.getBlock();
                Material dropType = null;
                switch (block.getType()) {
                    case IRON_ORE: {
                        dropType = Material.IRON_INGOT;
                        break;
                    }
                    case GOLD_ORE: {
                        dropType = Material.GOLD_INGOT;
                        break;
                    }
                    default: {
                        return;
                    }
                }
                 Location location = block.getLocation();
                 World world = location.getWorld();
                 ItemStack drop = new ItemStack(dropType, 1);
                world.dropItemNaturally(location, drop);
                block.setType(Material.AIR);
                block.getState().update();
            }
        }
    }
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:34,代码来源:AutoSmeltOreListener.java

示例12: 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

示例13: checkChunk

import org.bukkit.block.Block; //导入方法依赖的package包/类
private void checkChunk(ChunkPosition pos, @Nullable Chunk chunk) {
    if(repairedChunks.add(pos)) {
        if(chunk == null) {
            chunk = pos.getChunk(match.getWorld());
        }

        for(BlockState state : chunk.getTileEntities()) {
            if(state instanceof Skull) {
                if(!NMSHacks.isSkullCached((Skull) state)) {
                    Location loc = state.getLocation();
                    broadcastDeveloperWarning("Uncached skull \"" + ((Skull) state).getOwner() + "\" at " + loc.getBlockX() + ", " + loc.getBlockY() + ", " + loc.getBlockZ());
                }
            }
        }

        // Replace formerly invisible half-iron-door blocks with barriers
        for(Block ironDoor : chunk.getBlocks(Material.IRON_DOOR_BLOCK)) {
            BlockFace half = (ironDoor.getData() & 8) == 0 ? BlockFace.DOWN : BlockFace.UP;
            if(ironDoor.getRelative(half.getOppositeFace()).getType() != Material.IRON_DOOR_BLOCK) {
                ironDoor.setType(Material.BARRIER, false);
            }
        }

        // Remove all block 36 and remember the ones at y=0 so VoidFilter can check them
        for(Block block36 : chunk.getBlocks(Material.PISTON_MOVING_PIECE)) {
            if(block36.getY() == 0) {
                block36Locations.add(block36.getX(), block36.getY(), block36.getZ());
            }
            block36.setType(Material.AIR, false);
        }
    }
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:33,代码来源:WorldProblemMatchModule.java

示例14: paste

import org.bukkit.block.Block; //导入方法依赖的package包/类
public static void paste(String name, Location loc) {
    Schematic schematic = SchematicFile.getSchematic(name);
    List<UndoSave> save = new ArrayList<>();

    for (Schematic.LocationDiff diff : schematic.getBlocks()) {
        Block toEdit = loc.clone().add(diff.getX(), diff.getY(), diff.getZ()).getBlock();

        save.add(new UndoSave(toEdit.getType(), toEdit.getState().getData(), toEdit.getLocation()));

        toEdit.setType(diff.getBlockType());
        toEdit.getState().setData(diff.getBlockData());
    }

    SAVE_MAP.put(name, save);
}
 
开发者ID:AlphaHelixDev,项目名称:AlphaLibary,代码行数:16,代码来源:SchematicManager.java

示例15: setBlock

import org.bukkit.block.Block; //导入方法依赖的package包/类
public static void setBlock(Block block, Boolean fieldOn) {		
	if(fieldOn) {
		hyperspaceBlocks.add(block);
		block.setType(hyperSpaceBlock);
	}
	else {
		hyperspaceBlocks.remove(block);
		block.setType(Material.AIR);
	}		
	
}
 
开发者ID:Maximuspayne,项目名称:NavyCraft2-Lite,代码行数:12,代码来源:Craft_Hyperspace.java


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