本文整理汇总了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.");
}
示例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();
}
}
示例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);
}
}
}
}
}
示例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();
}
}
示例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));
}
}
示例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);
}
}
示例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;
}
示例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);
}
}
示例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 + ".");
}
示例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.");
}
示例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();
}
}
}
}
示例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();
}
}
}
}
示例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);
}
}
}
示例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);
}
示例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);
}
}