本文整理汇总了Java中org.bukkit.event.block.BlockPlaceEvent.canBuild方法的典型用法代码示例。如果您正苦于以下问题:Java BlockPlaceEvent.canBuild方法的具体用法?Java BlockPlaceEvent.canBuild怎么用?Java BlockPlaceEvent.canBuild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bukkit.event.block.BlockPlaceEvent
的用法示例。
在下文中一共展示了BlockPlaceEvent.canBuild方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ignite
import org.bukkit.event.block.BlockPlaceEvent; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
public boolean ignite(Player igniter, Location loc, IgniteCause cause) {
Random rand = new Random();
loc.add(0.5, 0.5, 0.5);
BlockIgniteEvent igniteEvent = new BlockIgniteEvent(loc.getBlock(),
cause, (org.bukkit.entity.Entity) igniter);
Bukkit.getServer().getPluginManager().callEvent(igniteEvent);
if (igniteEvent.isCancelled()) {
return false;
}
BlockState blockState = loc.getBlock().getState();
BlockPlaceEvent placeEvent = new BlockPlaceEvent(loc.getBlock(),
blockState, loc.getBlock(), igniter.getItemInHand(), igniter, true);
Bukkit.getServer().getPluginManager().callEvent(placeEvent);
if (placeEvent.isCancelled() || !placeEvent.canBuild()) {
placeEvent.getBlockPlaced().setTypeIdAndData(0, (byte) 0, false);
return false;
}
loc.getWorld().playSound(loc, Sound.ITEM_FLINTANDSTEEL_USE, 1.0F, rand.nextFloat() * 0.4F + 0.8F);
loc.getBlock().setType(Material.FIRE);
return true;
}
示例2: ignite
import org.bukkit.event.block.BlockPlaceEvent; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
public boolean ignite(Player igniter, Location loc, IgniteCause cause) {
Random rand = new Random();
loc.add(0.5, 0.5, 0.5);
BlockIgniteEvent igniteEvent = new BlockIgniteEvent(loc.getBlock(),
cause, (org.bukkit.entity.Entity) igniter);
Bukkit.getServer().getPluginManager().callEvent(igniteEvent);
if (igniteEvent.isCancelled()) {
return false;
}
List<Location> locations = new ArrayList<Location>();
for(double x = loc.getX() - 2;x <= loc.getX() + 2;x++)
{
for(double y = loc.getY() - 1;y <= loc.getY() + 1;y++)
{
for(double z = loc.getZ() - 2;z <= loc.getZ() + 2;z++)
{
locations.add(new Location(loc.getWorld(),x,y,z));
}
}
}
for(Location l : locations)
{
BlockIgniteEvent igniteEvent2 = new BlockIgniteEvent(l.getBlock(),
cause, (org.bukkit.entity.Entity) igniter);
Bukkit.getServer().getPluginManager().callEvent(igniteEvent2);
if (igniteEvent2.isCancelled()) {
continue;
}
BlockState blockState = l.getBlock().getState();
BlockPlaceEvent placeEvent = new BlockPlaceEvent(l.getBlock(),
blockState, l.getBlock(), igniter.getItemInHand(), igniter, true);
Bukkit.getServer().getPluginManager().callEvent(placeEvent);
if (placeEvent.isCancelled() || !placeEvent.canBuild()) {
continue;
}
if(l.getBlock() == null || l.getBlock().getType() == Material.AIR)
l.getBlock().setType(Material.FIRE);
}
loc.getWorld().playSound(loc, Sound.ITEM_FIRECHARGE_USE, 1.0F, rand.nextFloat() * 0.4F + 0.8F);
return true;
}
示例3: handle
import org.bukkit.event.block.BlockPlaceEvent; //导入方法依赖的package包/类
@Override
public void handle( ConnectionHandler connectionHandler, MessageC1FBlockPlacement message ) {
FlexPlayer player = connectionHandler.getPlayer();
synchronized ( player.getInventory() ) {
int heldSlot = player.getHeldItemSlot();
ItemStack stack = player.getInventory().getItem( heldSlot );
if( stack != null ) {
stack.setAmount( stack.getAmount() - 1 );
if( stack.getAmount() <= 0 ) {
stack = null;
} else {
ItemStack itemInHand = player.getItemInHand();
Vector3i position = message.getPosition();
switch ( message.getFace() ) {
case 0:
position.modify( 0,-1,0 );
break;
case 1:
position.modify( 0, 1, 0 );
break;
case 2:
position.modify( 0, 0, -1 );
break;
case 3:
position.modify( 0, 0, 1 );
break;
case 4:
position.modify( -1, 0, 0 );
break;
case 5:
position.modify( 1, 0, 0 );
break;
default:
return;
}
BlockPlaceEvent event = new BlockPlaceEvent( player.getWorld().getBlock0( position.getX(), position.getY(), position.getZ(), true ), null, null, itemInHand, player, true, EquipmentSlot.HAND );
BlockState pr = new BlockState( event.getBlock().getType(), event.getBlock().getData() );
EventFactory.call( event );
if( !event.isCancelled() && event.canBuild() ) {
player.getWorld().setBlock( position, new BlockState( stack.getType(), stack.getDurability() ) );
} else {
player.getWorld().setBlock( position, pr );
}
}
}
player.getInventory().setItem( heldSlot, stack );
}
}