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