org.bukkit.event.entity.EntityDespawnInVoidEvent#org.bukkit.entity.FallingBlock源码实例Demo

下面列出了org.bukkit.event.entity.EntityDespawnInVoidEvent#org.bukkit.entity.FallingBlock 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: GriefDefender   文件: BlockEventTracker.java
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockFalling(EntitySpawnEvent event) {
    final Entity entity = event.getEntity();
    final World world = entity.getWorld();
    if (entity instanceof FallingBlock) {
        // add owner
        final Location location = entity.getLocation();
        final Block block = world.getBlockAt(location.getBlockX(), location.getBlockY(), location.getBlockZ());
        final GDClaimManager claimWorldManager = GriefDefenderPlugin.getInstance().dataStore.getClaimWorldManager(location.getWorld().getUID());
        final GDChunk gdChunk = claimWorldManager.getChunk(location.getChunk());
        final UUID ownerUniqueId = gdChunk.getBlockOwnerUUID(block.getLocation());
        if (ownerUniqueId != null) {
            final GDEntity gdEntity = new GDEntity(event.getEntity().getEntityId());
            gdEntity.setOwnerUUID(ownerUniqueId);
            gdEntity.setNotifierUUID(ownerUniqueId);
            EntityTracker.addTempEntity(gdEntity);
        }
    }
}
 
源代码2 项目: ProjectAres   文件: FallingBlocksMatchModule.java
@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));
    }
}
 
源代码3 项目: Skript   文件: DefaultComparators.java
@Override
public Relation compare(final DamageCause dc, final EntityData e) {
	switch (dc) {
		case ENTITY_ATTACK:
			return Relation.get(e.isSupertypeOf(EntityData.fromClass(Entity.class)));
		case PROJECTILE:
			return Relation.get(e.isSupertypeOf(EntityData.fromClass(Projectile.class)));
		case WITHER:
			return Relation.get(e.isSupertypeOf(EntityData.fromClass(Wither.class)));
		case FALLING_BLOCK:
			return Relation.get(e.isSupertypeOf(EntityData.fromClass(FallingBlock.class)));
			//$CASES-OMITTED$
		default:
			return Relation.NOT_EQUAL;
	}
}
 
源代码4 项目: ce   文件: Molotov.java
@SuppressWarnings("deprecation")
   @Override
public void effect(Event e, ItemStack item, final int level) {
	if(e instanceof EntityDamageByEntityEvent) {
	EntityDamageByEntityEvent event = (EntityDamageByEntityEvent) e;
	Entity target = event.getEntity();

	World world = target.getWorld();
	world.playEffect(target.getLocation(), Effect.POTION_BREAK, 10);
	double boundaries = 0.1*level;
	for(double x = boundaries; x >= -boundaries; x-=0.1)
		for(double z = boundaries; z >= -boundaries; z-=0.1) {
			FallingBlock b = world.spawnFallingBlock(target.getLocation(), Material.FIRE.getId(), (byte) 0x0);
			b.setVelocity(new Vector(x, 0.1, z));
			b.setDropItem(false);
		}
	}
}
 
源代码5 项目: GriefDefender   文件: BlockEventTracker.java
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockSpawnFalling(EntityChangeBlockEvent event) {
    final Entity entity = event.getEntity();
    if (entity instanceof FallingBlock) {
        final GDEntity gdEntity = EntityTracker.getCachedEntity(event.getEntity().getEntityId());
        if (gdEntity != null) {
            final GDPermissionUser user = PermissionHolderCache.getInstance().getOrCreateUser(gdEntity.getOwnerUUID());
            final GDClaimManager claimWorldManager = GriefDefenderPlugin.getInstance().dataStore.getClaimWorldManager(event.getBlock().getWorld().getUID());
            final GDChunk gdChunk = claimWorldManager.getChunk(event.getBlock().getChunk());
            gdChunk.addTrackedBlockPosition(event.getBlock(), user.getUniqueId(), PlayerTracker.Type.OWNER);
        }
    }
}
 
源代码6 项目: PGM   文件: BlockDropsMatchModule.java
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onFallingBlockLand(BlockTransformEvent event) {
  if (event.getCause() instanceof EntityChangeBlockEvent) {
    Entity entity = ((EntityChangeBlockEvent) event.getCause()).getEntity();
    if (entity instanceof FallingBlock && this.fallingBlocksThatWillNotLand.remove(entity)) {
      event.setCancelled(true);
    }
  }
}
 
源代码7 项目: PGM   文件: FallingBlocksMatchModule.java
@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(match.getWorld(), pos);
  BlockState oldState = block.getState();
  block.setType(Material.AIR, false);
  FallingBlock fallingBlock =
      block
          .getWorld()
          .spawnFallingBlock(block.getLocation(), oldState.getType(), oldState.getRawData());

  BlockFallEvent event = new BlockFallEvent(block, fallingBlock);
  match.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 {
    block.setType(
        Material.AIR,
        true); // This is already air, but physics have not been applied yet, so do that now
  }
}
 
源代码8 项目: PGM   文件: EntityTracker.java
public PhysicalInfo createEntity(Entity entity, @Nullable ParticipantState owner) {
  if (entity instanceof ThrownPotion) {
    return new ThrownPotionInfo((ThrownPotion) entity, owner);
  } else if (entity instanceof FallingBlock) {
    return new FallingBlockInfo((FallingBlock) entity, owner);
  } else if (entity instanceof LivingEntity) {
    return new MobInfo((LivingEntity) entity, owner);
  } else {
    return new EntityInfo(entity, owner);
  }
}
 
源代码9 项目: ProjectAres   文件: BlockDropsMatchModule.java
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onFallingBlockLand(BlockTransformEvent event) {
    if(event.getCause() instanceof EntityChangeBlockEvent) {
        Entity entity = ((EntityChangeBlockEvent) event.getCause()).getEntity();
        if(entity instanceof FallingBlock && this.fallingBlocksThatWillNotLand.remove(entity)) {
            event.setCancelled(true);
        }
    }
}
 
源代码10 项目: ProjectAres   文件: EntityTracker.java
public PhysicalInfo createEntity(Entity entity, @Nullable ParticipantState owner) {
    if(entity instanceof ThrownPotion) {
        return new ThrownPotionInfo((ThrownPotion) entity, owner);
    } else if(entity instanceof FallingBlock) {
        return new FallingBlockInfo((FallingBlock) entity, owner);
    } else if(entity instanceof LivingEntity) {
        return new MobInfo((LivingEntity) entity, owner);
    } else {
        return new EntityInfo(entity, owner);
    }
}
 
源代码11 项目: Skript   文件: FallingBlockData.java
@SuppressWarnings("deprecation")
@Override
protected boolean init(final @Nullable Class<? extends FallingBlock> c, final @Nullable FallingBlock e) {
	if (e != null) // TODO material data support
		types = new ItemType[] {new ItemType(BlockCompat.INSTANCE.fallingBlockToState(e))};
	return true;
}
 
源代码12 项目: Skript   文件: FallingBlockData.java
@SuppressWarnings("deprecation")
@Override
protected boolean match(final FallingBlock entity) {
	if (types != null) {
		for (final ItemType t : types) {
			if (t.isOfType(BlockCompat.INSTANCE.fallingBlockToState(entity)))
				return true;
		}
		return false;
	}
	return true;
}
 
源代码13 项目: Skript   文件: FallingBlockData.java
@SuppressWarnings("deprecation")
@Override
@Nullable
public FallingBlock spawn(final Location loc) {
	final ItemType t = CollectionUtils.getRandom(types);
	assert t != null;
	final ItemStack i = t.getRandom();
	if (i == null || i.getType() == Material.AIR || !i.getType().isBlock()) {
		assert false : i;
		return null;
	}
	return loc.getWorld().spawnFallingBlock(loc, i.getType(), (byte) i.getDurability());
}
 
源代码14 项目: Skript   文件: MagicBlockCompat.java
@SuppressWarnings("deprecation")
@Override
public BlockState fallingBlockToState(FallingBlock entity) {
	BlockState state = entity.getWorld().getBlockAt(0, 0, 0).getState();
	state.setType(entity.getMaterial());
	try {
		setRawDataMethod.invokeExact(state, (byte) getBlockDataMethod.invokeExact(entity));
	} catch (Throwable e) {
		Skript.exception(e);
	}
	return state;
}
 
源代码15 项目: FastAsyncWorldedit   文件: AsyncWorld.java
@Override
public FallingBlock spawnFallingBlock(Location location, MaterialData data) throws IllegalArgumentException {
    return TaskManager.IMP.sync(new RunnableVal<FallingBlock>() {
        @Override
        public void run(FallingBlock value) {
            this.value = parent.spawnFallingBlock(location, data);
        }
    });
}
 
源代码16 项目: FastAsyncWorldedit   文件: AsyncWorld.java
@Override
@Deprecated
public FallingBlock spawnFallingBlock(final Location location, final int blockId, final byte blockData) throws IllegalArgumentException {
    return TaskManager.IMP.sync(new RunnableVal<FallingBlock>() {
        @Override
        public void run(FallingBlock value) {
            this.value = parent.spawnFallingBlock(location, blockId, blockData);
        }
    });
}
 
源代码17 项目: SkyWarsReloaded   文件: NMSHandler.java
@SuppressWarnings("deprecation")
@Override
public Entity spawnFallingBlock(Location loc, Material mat, boolean damage) {
	FallingBlock block = loc.getWorld().spawnFallingBlock(loc, mat, (byte) 0);
	block.setDropItem(false);
	EntityFallingBlock fb = ((CraftFallingSand) block).getHandle();
	fb.a(damage);
	return block;
}
 
源代码18 项目: SkyWarsReloaded   文件: NMSHandler.java
@Override
public boolean checkMaterial(FallingBlock fb, Material mat) {
	if (fb.getMaterial().equals(mat)) {
		return true;
	}
	return false;
}
 
源代码19 项目: SkyWarsReloaded   文件: NMSHandler.java
@SuppressWarnings("deprecation")
@Override
public Entity spawnFallingBlock(Location loc, Material mat, boolean damage) {
	FallingBlock block = loc.getWorld().spawnFallingBlock(loc, mat, (byte) 0);
	block.setDropItem(false);
	EntityFallingBlock fb = ((CraftFallingSand) block).getHandle();
	fb.a(damage);
	return block;
}
 
源代码20 项目: SkyWarsReloaded   文件: NMSHandler.java
@Override
public boolean checkMaterial(FallingBlock fb, Material mat) {
	if (fb.getMaterial().equals(mat)) {
		return true;
	}
	return false;
}
 
源代码21 项目: SkyWarsReloaded   文件: NMSHandler.java
@SuppressWarnings("deprecation")
@Override
public Entity spawnFallingBlock(Location loc, Material mat, boolean damage) {
	FallingBlock block = loc.getWorld().spawnFallingBlock(loc, mat, (byte) 0);
	block.setDropItem(false);
	EntityFallingBlock fb = ((CraftFallingSand) block).getHandle();
	fb.a(damage);
	return block;
}
 
源代码22 项目: SkyWarsReloaded   文件: NMSHandler.java
@Override
public boolean checkMaterial(FallingBlock fb, Material mat) {
	if (fb.getMaterial().equals(mat)) {
		return true;
	}
	return false;
}
 
源代码23 项目: SkyWarsReloaded   文件: NMSHandler.java
@SuppressWarnings("deprecation")
@Override
public Entity spawnFallingBlock(Location loc, Material mat, boolean damage) {
	FallingBlock block = loc.getWorld().spawnFallingBlock(loc, mat, (byte) 0);
	block.setDropItem(false);
	EntityFallingBlock fb = ((CraftFallingSand) block).getHandle();
	fb.a(damage);
	return block;
}
 
源代码24 项目: SkyWarsReloaded   文件: NMSHandler.java
@Override
public boolean checkMaterial(FallingBlock fb, Material mat) {
	if (fb.getMaterial().equals(mat)) {
		return true;
	}
	return false;
}
 
源代码25 项目: SkyWarsReloaded   文件: NMSHandler.java
@SuppressWarnings("deprecation")
@Override
public Entity spawnFallingBlock(Location loc, Material mat, boolean damage) {
	FallingBlock block = loc.getWorld().spawnFallingBlock(loc, mat, (byte) 0);
	block.setDropItem(false);
	EntityFallingBlock fb = ((CraftFallingBlock) block).getHandle();
	fb.a(damage);
	return block;
}
 
源代码26 项目: SkyWarsReloaded   文件: NMSHandler.java
@Override
public boolean checkMaterial(FallingBlock fb, Material mat) {
	if (fb.getMaterial().equals(mat)) {
		return true;
	}
	return false;
}
 
源代码27 项目: SkyWarsReloaded   文件: NMSHandler.java
@SuppressWarnings("deprecation")
@Override
public Entity spawnFallingBlock(Location loc, Material mat, boolean damage) {
	FallingBlock block = loc.getWorld().spawnFallingBlock(loc, mat, (byte) 0);
	block.setDropItem(false);
	EntityFallingBlock fb = ((CraftFallingSand) block).getHandle();
	fb.a(damage);
	return block;
}
 
源代码28 项目: SkyWarsReloaded   文件: NMSHandler.java
@Override
public boolean checkMaterial(FallingBlock fb, Material mat) {
	if (fb.getMaterial().equals(mat)) {
		return true;
	}
	return false;
}
 
源代码29 项目: Slimefun4   文件: BlockPhysicsListener.java
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onBlockFall(EntityChangeBlockEvent e) {
    if (e.getEntity().getType() == EntityType.FALLING_BLOCK && BlockStorage.hasBlockInfo(e.getBlock())) {
        e.setCancelled(true);
        FallingBlock block = (FallingBlock) e.getEntity();

        if (block.getDropItem()) {
            block.getWorld().dropItemNaturally(block.getLocation(), new ItemStack(block.getBlockData().getMaterial(), 1));
        }
    }
}
 
源代码30 项目: Slimefun4   文件: SeismicAxe.java
@Override
public ItemUseHandler getItemHandler() {
    return e -> {
        Player p = e.getPlayer();
        List<Block> blocks = p.getLineOfSight(null, RANGE);

        for (int i = 2; i < blocks.size(); i++) {
            Block ground = findGround(blocks.get(i));
            Location groundLocation = ground.getLocation();

            ground.getWorld().playEffect(groundLocation, Effect.STEP_SOUND, ground.getType());

            if (ground.getRelative(BlockFace.UP).getType() == Material.AIR) {
                Location loc = ground.getRelative(BlockFace.UP).getLocation().add(0.5, 0.0, 0.5);
                FallingBlock block = ground.getWorld().spawnFallingBlock(loc, ground.getBlockData());
                block.setDropItem(false);
                block.setVelocity(new Vector(0, 0.4 + i * 0.01, 0));
                block.setMetadata("seismic_axe", new FixedMetadataValue(SlimefunPlugin.instance, "fake_block"));
            }

            for (Entity n : ground.getChunk().getEntities()) {
                if (n instanceof LivingEntity && n.getType() != EntityType.ARMOR_STAND && n.getLocation().distance(groundLocation) <= 2.0D && !n.getUniqueId().equals(p.getUniqueId())) {
                    pushEntity(p, n);
                }
            }
        }

        for (int i = 0; i < 4; i++) {
            damageItem(p, e.getItem());
        }
    };
}