下面列出了org.bukkit.event.entity.EntityDespawnInVoidEvent#org.bukkit.entity.FallingBlock 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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);
}
}
}
@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));
}
}
@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;
}
}
@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);
}
}
}
@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);
}
}
}
@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);
}
}
}
@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
}
}
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);
}
}
@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);
}
}
}
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);
}
}
@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;
}
@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;
}
@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());
}
@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;
}
@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);
}
});
}
@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);
}
});
}
@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;
}
@Override
public boolean checkMaterial(FallingBlock fb, Material mat) {
if (fb.getMaterial().equals(mat)) {
return true;
}
return false;
}
@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;
}
@Override
public boolean checkMaterial(FallingBlock fb, Material mat) {
if (fb.getMaterial().equals(mat)) {
return true;
}
return false;
}
@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;
}
@Override
public boolean checkMaterial(FallingBlock fb, Material mat) {
if (fb.getMaterial().equals(mat)) {
return true;
}
return false;
}
@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;
}
@Override
public boolean checkMaterial(FallingBlock fb, Material mat) {
if (fb.getMaterial().equals(mat)) {
return true;
}
return false;
}
@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;
}
@Override
public boolean checkMaterial(FallingBlock fb, Material mat) {
if (fb.getMaterial().equals(mat)) {
return true;
}
return false;
}
@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;
}
@Override
public boolean checkMaterial(FallingBlock fb, Material mat) {
if (fb.getMaterial().equals(mat)) {
return true;
}
return false;
}
@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));
}
}
}
@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());
}
};
}