本文整理匯總了Java中org.bukkit.block.BlockState.update方法的典型用法代碼示例。如果您正苦於以下問題:Java BlockState.update方法的具體用法?Java BlockState.update怎麽用?Java BlockState.update使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.bukkit.block.BlockState
的用法示例。
在下文中一共展示了BlockState.update方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: 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;
}
示例3: fall
import org.bukkit.block.BlockState; //導入方法依賴的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));
}
}
示例4: 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();
}
}
示例5: handleBlockSpreadEvent
import org.bukkit.block.BlockState; //導入方法依賴的package包/類
public static void handleBlockSpreadEvent(Block block, Block source, net.minecraft.block.Block type, int data) {
BlockState state = block.getState();
state.setTypeId(net.minecraft.block.Block.getIdFromBlock(type));
state.setRawData((byte) data);
BlockSpreadEvent event = new BlockSpreadEvent(block, source, state);
Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
state.update(true);
}
}
示例6: replaceBlock
import org.bukkit.block.BlockState; //導入方法依賴的package包/類
private void replaceBlock(BlockDrops drops, Block block, MatchPlayer player) {
if(drops.replacement != null) {
EntityChangeBlockEvent event = new EntityChangeBlockEvent(player.getBukkit(), block, drops.replacement);
getMatch().callEvent(event);
if(!event.isCancelled()) {
BlockState state = block.getState();
state.setType(drops.replacement.getItemType());
state.setData(drops.replacement);
state.update(true, true);
}
}
}
示例7: onLeverOrButton
import org.bukkit.block.BlockState; //導入方法依賴的package包/類
@EventHandler
public void onLeverOrButton(PlayerInteractEvent event) {
Block clickedBlock = event.getClickedBlock();
Player player = event.getPlayer();
if (clickedBlock == null)
return;
String chunk = clickedBlock.getLocation().getChunk().getX() + ";"
+ clickedBlock.getLocation().getChunk().getZ();
if (event.getAction() != Action.RIGHT_CLICK_BLOCK)
return;
if (!powerable.containsKey(clickedBlock.getWorld().getName()))
return;
if (powerable.get(clickedBlock.getWorld().getName()).getList(chunk).contains(clickedBlock.getLocation()))
return;
// We cancel; send smoke particles for button, and we just turn off the
// lever (if it was, for some reason, on).
if (clickedBlock.getType() == Material.STONE_BUTTON || clickedBlock.getType() == Material.WOOD_BUTTON) {
clickedBlock.getWorld().spawnParticle(Particle.SMOKE_NORMAL, clickedBlock.getLocation().add(0.5, 1, 0.5), 7,
0, 0.2, 0, 0.03);
player.sendMessage(MortuusTerraCore.NOTI_PREFIX + ChatColor.RED + " There is no generator in range!");
} else if (clickedBlock.getType() == Material.LEVER) {
BlockState state = clickedBlock.getState();
Lever lever = (Lever) state.getData();
lever.setPowered(false);
state.setData(lever);
state.update();
clickedBlock.getWorld().spawnParticle(Particle.SMOKE_NORMAL, clickedBlock.getLocation().add(0.5, 1, 0.5), 7,
0, 0.2, 0, 0.03);
player.sendMessage(MortuusTerraCore.NOTI_PREFIX + ChatColor.RED + " There is no generator in range!");
}
}
示例8: updateList
import org.bukkit.block.BlockState; //導入方法依賴的package包/類
public void updateList() {
for (BlockState state : list) {
state.update(true);
}
}
示例9: setSpawner
import org.bukkit.block.BlockState; //導入方法依賴的package包/類
public void setSpawner(Block block, EntityType ent) {
BlockState blockState = block.getState();
CreatureSpawner spawner = ((CreatureSpawner) blockState);
spawner.setSpawnedType(ent);
blockState.update();
}
示例10: clientNewSign
import org.bukkit.block.BlockState; //導入方法依賴的package包/類
public void clientNewSign(ChannelHandlerContext ctx, int x, int y, int z, int face, String text) {
if (!allowSigns) {
webSocketServerThread.sendLine(ctx.channel(), "T,Writing on signs is not allowed");
// TODO: revert on client
return;
}
BlockFace blockFace;
switch (face) {
case 0: // west
blockFace = BlockFace.WEST;
x -= 1;
break;
case 1: // east
blockFace = BlockFace.EAST;
x += 1;
break;
default:
case 2: // north
blockFace = BlockFace.NORTH;
z -= 1;
break;
case 3: // south
blockFace = BlockFace.SOUTH;
z += 1;
break;
}
org.bukkit.material.Sign signDirection = new org.bukkit.material.Sign();
signDirection.setFacingDirection(blockFace);
Location location = toBukkitLocation(x, y, z);
if (!withinSandboxRange(location)) {
webSocketServerThread.log(Level.FINEST, "client tried to write a sign outside sandbox range");
return;
}
// Create the sign
Block block = location.getWorld().getBlockAt(location);
/*
block.setTypeIdAndData(Material.WALL_SIGN.getId(), data, applyPhysics);
webSocketServerThread.log(Level.FINEST, "setting sign at "+location+" data="+data);
*/
BlockState blockState = block.getState();
blockState.setType(Material.WALL_SIGN);
blockState.setData(signDirection);
boolean force = true;
boolean applyPhysics = false;
blockState.update(force, applyPhysics);
webSocketServerThread.log(Level.FINEST, "setting sign at "+location+" blockFace="+blockFace);
// Set the sign text
blockState = block.getState();
if (!(blockState instanceof Sign)) {
webSocketServerThread.log(Level.WARNING, "failed to place sign at "+location);
return;
}
Sign sign = (Sign) blockState;
// TODO: text lines by 15 characters into 5 lines
sign.setLine(0, text);
sign.update(force, applyPhysics);
webSocketServerThread.log(Level.FINEST, "set sign text="+text+", signDirection="+signDirection+", blockFace="+blockFace+", block="+block+", face="+face);
// SignChangeEvent not posted when signs created programmatically; notify web clients ourselves
notifySignChange(location, block.getType(), block.getState(), sign.getLines());
}