mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-23 19:15:32 +01:00
Implement new cause versions of BlockIgniteEvent. Addresses BUKKIT-3609, BUKKIT-3656, BUKKIT-3657
This commit is contained in:
parent
2e6cfdb3cc
commit
a7a5f273e3
@ -3,7 +3,7 @@ package net.minecraft.server;
|
||||
import java.util.Random;
|
||||
|
||||
// CraftBukkit start
|
||||
import org.bukkit.event.block.BlockIgniteEvent;
|
||||
import org.bukkit.craftbukkit.event.CraftEventFactory;
|
||||
import org.bukkit.event.block.BlockBurnEvent;
|
||||
import org.bukkit.event.block.BlockSpreadEvent;
|
||||
// CraftBukkit end
|
||||
@ -111,9 +111,6 @@ public class BlockFire extends Block {
|
||||
// CraftBukkit start - call to stop spread of fire
|
||||
org.bukkit.Server server = world.getServer();
|
||||
org.bukkit.World bworld = world.getWorld();
|
||||
|
||||
BlockIgniteEvent.IgniteCause igniteCause = BlockIgniteEvent.IgniteCause.SPREAD;
|
||||
org.bukkit.block.Block fromBlock = bworld.getBlockAt(i, j, k);
|
||||
// CraftBukkit end
|
||||
|
||||
for (int i1 = i - 1; i1 <= i + 1; ++i1) {
|
||||
@ -143,13 +140,8 @@ public class BlockFire extends Block {
|
||||
}
|
||||
|
||||
// CraftBukkit start - call to stop spread of fire
|
||||
org.bukkit.block.Block block = bworld.getBlockAt(i1, k1, j1);
|
||||
|
||||
if (block.getTypeId() != Block.FIRE.id) {
|
||||
BlockIgniteEvent event = new BlockIgniteEvent(block, igniteCause, null);
|
||||
server.getPluginManager().callEvent(event);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
if (world.getTypeId(i1, k1, j1) != Block.FIRE.id) {
|
||||
if (CraftEventFactory.callBlockIgniteEvent(world, i1, k1, j1, i, j, k).isCancelled()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -157,7 +149,7 @@ public class BlockFire extends Block {
|
||||
blockState.setTypeId(this.id);
|
||||
blockState.setData(new org.bukkit.material.MaterialData(this.id, (byte) k2));
|
||||
|
||||
BlockSpreadEvent spreadEvent = new BlockSpreadEvent(blockState.getBlock(), fromBlock, blockState);
|
||||
BlockSpreadEvent spreadEvent = new BlockSpreadEvent(blockState.getBlock(), bworld.getBlockAt(i, j, k), blockState);
|
||||
server.getPluginManager().callEvent(spreadEvent);
|
||||
|
||||
if (!spreadEvent.isCancelled()) {
|
||||
|
@ -2,10 +2,7 @@ package net.minecraft.server;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
// CraftBukkit start
|
||||
import org.bukkit.craftbukkit.event.CraftEventFactory;
|
||||
import org.bukkit.event.block.BlockIgniteEvent;
|
||||
// CraftBukkit end
|
||||
import org.bukkit.craftbukkit.event.CraftEventFactory; // CraftBukkit
|
||||
|
||||
public class BlockStationary extends BlockFluids {
|
||||
|
||||
@ -42,9 +39,10 @@ public class BlockStationary extends BlockFluids {
|
||||
int i1;
|
||||
int j1;
|
||||
|
||||
// CraftBukkit start - prevent lava putting something on fire
|
||||
org.bukkit.World bworld = world.getWorld();
|
||||
BlockIgniteEvent.IgniteCause igniteCause = BlockIgniteEvent.IgniteCause.LAVA;
|
||||
// CraftBukkit start - prevent lava putting something on fire, remember igniter block coords
|
||||
int x = i;
|
||||
int y = j;
|
||||
int z = k;
|
||||
// CraftBukkit end
|
||||
|
||||
for (i1 = 0; i1 < l; ++i1) {
|
||||
@ -55,9 +53,8 @@ public class BlockStationary extends BlockFluids {
|
||||
if (j1 == 0) {
|
||||
if (this.m(world, i - 1, j, k) || this.m(world, i + 1, j, k) || this.m(world, i, j, k - 1) || this.m(world, i, j, k + 1) || this.m(world, i, j - 1, k) || this.m(world, i, j + 1, k)) {
|
||||
// CraftBukkit start - prevent lava putting something on fire
|
||||
org.bukkit.block.Block block = bworld.getBlockAt(i, j, k);
|
||||
if (block.getTypeId() != Block.FIRE.id) {
|
||||
if (CraftEventFactory.callEvent(new BlockIgniteEvent(block, igniteCause, null)).isCancelled()) {
|
||||
if (world.getTypeId(i, j, k) != Block.FIRE.id) {
|
||||
if (CraftEventFactory.callBlockIgniteEvent(world, i, j, k, x, y, z).isCancelled()) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@ -80,9 +77,8 @@ public class BlockStationary extends BlockFluids {
|
||||
k = j1 + random.nextInt(3) - 1;
|
||||
if (world.isEmpty(i, j + 1, k) && this.m(world, i, j, k)) {
|
||||
// CraftBukkit start - prevent lava putting something on fire
|
||||
org.bukkit.block.Block block = bworld.getBlockAt(i, j + 1, k);
|
||||
if (block.getTypeId() != Block.FIRE.id) {
|
||||
if (CraftEventFactory.callEvent(new BlockIgniteEvent(block, igniteCause, null)).isCancelled()) {
|
||||
if (world.getTypeId(i, j + 1, k) != Block.FIRE.id) {
|
||||
if (CraftEventFactory.callBlockIgniteEvent(world, i, j + 1, k, x, y, z).isCancelled()) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.minecraft.server;
|
||||
|
||||
// CraftBukkit start
|
||||
import org.bukkit.craftbukkit.event.CraftEventFactory;
|
||||
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
import org.bukkit.event.block.BlockDispenseEvent;
|
||||
// CraftBukkit end
|
||||
@ -43,10 +44,14 @@ final class DispenseBehaviorFlintAndSteel extends DispenseBehaviorItem {
|
||||
// CraftBukkit end
|
||||
|
||||
if (world.isEmpty(i, j, k)) {
|
||||
world.setTypeIdUpdate(i, j, k, Block.FIRE.id);
|
||||
if (itemstack.isDamaged(1, world.random)) {
|
||||
itemstack.count = 0;
|
||||
// CraftBukkit - ignition by dispensing flint and steel
|
||||
if (!CraftEventFactory.callBlockIgniteEvent(world, i, j, k, isourceblock.getBlockX(), isourceblock.getBlockY(), isourceblock.getBlockZ()).isCancelled()) {
|
||||
world.setTypeIdUpdate(i, j, k, Block.FIRE.id);
|
||||
if (itemstack.isDamaged(1, world.random)) {
|
||||
itemstack.count = 0;
|
||||
}
|
||||
}
|
||||
// CraftBukkit end
|
||||
} else if (world.getTypeId(i, j, k) == Block.TNT.id) {
|
||||
Block.TNT.postBreak(world, i, j, k, 1);
|
||||
world.setAir(i, j, k);
|
||||
|
@ -33,7 +33,11 @@ public class EntityEnderCrystal extends Entity {
|
||||
int k = MathHelper.floor(this.locZ);
|
||||
|
||||
if (this.world.getTypeId(i, j, k) != Block.FIRE.id) {
|
||||
this.world.setTypeIdUpdate(i, j, k, Block.FIRE.id);
|
||||
// CraftBukkit start
|
||||
if (!org.bukkit.craftbukkit.event.CraftEventFactory.callBlockIgniteEvent(this.world, i, j, k, this).isCancelled()) {
|
||||
this.world.setTypeIdUpdate(i, j, k, Block.FIRE.id);
|
||||
}
|
||||
// CraftBukkit end
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@ package net.minecraft.server;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.event.block.BlockIgniteEvent; // CraftBukkit
|
||||
import org.bukkit.craftbukkit.event.CraftEventFactory; // CraftBukkit
|
||||
|
||||
public class EntityLightning extends EntityWeather {
|
||||
|
||||
@ -11,7 +11,6 @@ public class EntityLightning extends EntityWeather {
|
||||
private int c;
|
||||
|
||||
// CraftBukkit start
|
||||
private org.bukkit.craftbukkit.CraftWorld cworld;
|
||||
public boolean isEffect = false;
|
||||
|
||||
public EntityLightning(World world, double d0, double d1, double d2) {
|
||||
@ -25,7 +24,6 @@ public class EntityLightning extends EntityWeather {
|
||||
|
||||
// CraftBukkit start
|
||||
this.isEffect = isEffect;
|
||||
this.cworld = world.getWorld();
|
||||
// CraftBukkit end
|
||||
|
||||
this.setPositionRotation(d0, d1, d2, 0.0F, 0.0F);
|
||||
@ -41,10 +39,7 @@ public class EntityLightning extends EntityWeather {
|
||||
|
||||
if (world.getTypeId(i, j, k) == 0 && Block.FIRE.canPlace(world, i, j, k)) {
|
||||
// CraftBukkit start
|
||||
BlockIgniteEvent event = new BlockIgniteEvent(this.cworld.getBlockAt(i, j, k), BlockIgniteEvent.IgniteCause.LIGHTNING, null);
|
||||
world.getServer().getPluginManager().callEvent(event);
|
||||
|
||||
if (!event.isCancelled()) {
|
||||
if (!CraftEventFactory.callBlockIgniteEvent(world, i, j, k, this).isCancelled()) {
|
||||
world.setTypeIdUpdate(i, j, k, Block.FIRE.id);
|
||||
}
|
||||
// CraftBukkit end
|
||||
@ -57,11 +52,8 @@ public class EntityLightning extends EntityWeather {
|
||||
|
||||
if (world.getTypeId(j, k, l) == 0 && Block.FIRE.canPlace(world, j, k, l)) {
|
||||
// CraftBukkit start
|
||||
BlockIgniteEvent event = new BlockIgniteEvent(this.cworld.getBlockAt(j, k, l), BlockIgniteEvent.IgniteCause.LIGHTNING, null);
|
||||
world.getServer().getPluginManager().callEvent(event);
|
||||
|
||||
if (!event.isCancelled()) {
|
||||
world.setTypeIdUpdate(j, k, l, Block.FIRE.id);
|
||||
if (!CraftEventFactory.callBlockIgniteEvent(world, j, k, l, this).isCancelled()) {
|
||||
world.setTypeIdUpdate(i, j, k, Block.FIRE.id);
|
||||
}
|
||||
// CraftBukkit end
|
||||
}
|
||||
@ -92,11 +84,8 @@ public class EntityLightning extends EntityWeather {
|
||||
|
||||
if (this.world.getTypeId(i, j, k) == 0 && Block.FIRE.canPlace(this.world, i, j, k)) {
|
||||
// CraftBukkit start
|
||||
BlockIgniteEvent event = new BlockIgniteEvent(this.cworld.getBlockAt(i, j, k), BlockIgniteEvent.IgniteCause.LIGHTNING, null);
|
||||
this.world.getServer().getPluginManager().callEvent(event);
|
||||
|
||||
if (!event.isCancelled()) {
|
||||
this.world.setTypeIdUpdate(i, j, k, Block.FIRE.id);
|
||||
if (!CraftEventFactory.callBlockIgniteEvent(world, i, j, k, this).isCancelled()) {
|
||||
world.setTypeIdUpdate(i, j, k, Block.FIRE.id);
|
||||
}
|
||||
// CraftBukkit end
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package net.minecraft.server;
|
||||
|
||||
// CraftBukkit start
|
||||
import org.bukkit.event.block.BlockIgniteEvent;
|
||||
import org.bukkit.craftbukkit.event.CraftEventFactory;
|
||||
import org.bukkit.event.entity.EntityCombustByEntityEvent;
|
||||
// CraftBukkit end
|
||||
|
||||
@ -67,11 +67,7 @@ public class EntitySmallFireball extends EntityFireball {
|
||||
|
||||
if (this.world.isEmpty(i, j, k)) {
|
||||
// CraftBukkit start
|
||||
org.bukkit.block.Block block = world.getWorld().getBlockAt(i, j, k);
|
||||
BlockIgniteEvent event = new BlockIgniteEvent(block, BlockIgniteEvent.IgniteCause.FIREBALL, null);
|
||||
world.getServer().getPluginManager().callEvent(event);
|
||||
|
||||
if (!event.isCancelled()) {
|
||||
if (!CraftEventFactory.callBlockIgniteEvent(world, i, j, k, this).isCancelled()) {
|
||||
this.world.setTypeIdUpdate(i, j, k, Block.FIRE.id);
|
||||
}
|
||||
// CraftBukkit end
|
||||
|
@ -290,7 +290,10 @@ public class Explosion {
|
||||
int i1 = this.world.getTypeId(i, j - 1, k);
|
||||
|
||||
if (l == 0 && Block.s[i1] && this.j.nextInt(3) == 0) {
|
||||
this.world.setTypeIdUpdate(i, j, k, Block.FIRE.id);
|
||||
// CraftBukkit start - ignition by explosion.
|
||||
if (!org.bukkit.craftbukkit.event.CraftEventFactory.callBlockIgniteEvent(this.world, i, j, k, this).isCancelled()) {
|
||||
this.world.setTypeIdUpdate(i, j, k, Block.FIRE.id);
|
||||
} // CraftBukkit end
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,5 @@
|
||||
package net.minecraft.server;
|
||||
|
||||
// CraftBukkit start
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.BlockIgniteEvent;
|
||||
// CraftBukkit end
|
||||
|
||||
public class ItemFireball extends Item {
|
||||
|
||||
public ItemFireball(int i) {
|
||||
@ -47,13 +42,7 @@ public class ItemFireball extends Item {
|
||||
|
||||
if (i1 == 0) {
|
||||
// CraftBukkit start
|
||||
org.bukkit.block.Block blockClicked = world.getWorld().getBlockAt(i, j, k);
|
||||
Player thePlayer = (Player) entityhuman.getBukkitEntity();
|
||||
|
||||
BlockIgniteEvent eventIgnite = new BlockIgniteEvent(blockClicked, BlockIgniteEvent.IgniteCause.FIREBALL, thePlayer);
|
||||
world.getServer().getPluginManager().callEvent(eventIgnite);
|
||||
|
||||
if (eventIgnite.isCancelled()) {
|
||||
if (org.bukkit.craftbukkit.event.CraftEventFactory.callBlockIgniteEvent(world, i, j, k, org.bukkit.event.block.BlockIgniteEvent.IgniteCause.FIREBALL, entityhuman).isCancelled()) {
|
||||
if (!entityhuman.abilities.canInstantlyBuild) {
|
||||
--itemstack.count;
|
||||
}
|
||||
|
@ -1,10 +1,6 @@
|
||||
package net.minecraft.server;
|
||||
|
||||
// CraftBukkit start
|
||||
import org.bukkit.craftbukkit.block.CraftBlockState;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.BlockIgniteEvent;
|
||||
// CraftBukkit end
|
||||
import org.bukkit.craftbukkit.block.CraftBlockState; // CraftBukkit
|
||||
|
||||
public class ItemFlintAndSteel extends Item {
|
||||
|
||||
@ -49,13 +45,7 @@ public class ItemFlintAndSteel extends Item {
|
||||
|
||||
if (i1 == 0) {
|
||||
// CraftBukkit start - store the clicked block
|
||||
org.bukkit.block.Block blockClicked = world.getWorld().getBlockAt(i, j, k);
|
||||
Player thePlayer = (Player) entityhuman.getBukkitEntity();
|
||||
|
||||
BlockIgniteEvent eventIgnite = new BlockIgniteEvent(blockClicked, BlockIgniteEvent.IgniteCause.FLINT_AND_STEEL, thePlayer);
|
||||
world.getServer().getPluginManager().callEvent(eventIgnite);
|
||||
|
||||
if (eventIgnite.isCancelled()) {
|
||||
if (org.bukkit.craftbukkit.event.CraftEventFactory.callBlockIgniteEvent(world, i, j, k, org.bukkit.event.block.BlockIgniteEvent.IgniteCause.FLINT_AND_STEEL, entityhuman).isCancelled()) {
|
||||
itemstack.damage(1, entityhuman);
|
||||
return false;
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ import net.minecraft.server.EntityItem;
|
||||
import net.minecraft.server.EntityLiving;
|
||||
import net.minecraft.server.EntityPlayer;
|
||||
import net.minecraft.server.EntityPotion;
|
||||
import net.minecraft.server.Explosion;
|
||||
import net.minecraft.server.InventoryCrafting;
|
||||
import net.minecraft.server.Item;
|
||||
import net.minecraft.server.ItemStack;
|
||||
@ -41,6 +42,7 @@ import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.AnimalTamer;
|
||||
import org.bukkit.entity.Arrow;
|
||||
import org.bukkit.entity.Creeper;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LightningStrike;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Pig;
|
||||
@ -51,6 +53,7 @@ import org.bukkit.entity.ThrownExpBottle;
|
||||
import org.bukkit.entity.ThrownPotion;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.block.*;
|
||||
import org.bukkit.event.block.BlockIgniteEvent.IgniteCause;
|
||||
import org.bukkit.event.entity.*;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
|
||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||
@ -551,4 +554,64 @@ public class CraftEventFactory {
|
||||
PlayerItemBreakEvent event = new PlayerItemBreakEvent((Player) human.getBukkitEntity(), item);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
}
|
||||
|
||||
public static BlockIgniteEvent callBlockIgniteEvent(World world, int x, int y, int z, int igniterX, int igniterY, int igniterZ) {
|
||||
org.bukkit.World bukkitWorld = world.getWorld();
|
||||
Block igniter = bukkitWorld.getBlockAt(igniterX, igniterY, igniterZ);
|
||||
IgniteCause cause;
|
||||
switch (igniter.getType()) {
|
||||
case LAVA:
|
||||
cause = IgniteCause.LAVA;
|
||||
break;
|
||||
case DISPENSER:
|
||||
cause = IgniteCause.FLINT_AND_STEEL;
|
||||
break;
|
||||
case FIRE: // Fire or any other unknown block counts as SPREAD.
|
||||
default:
|
||||
cause = IgniteCause.SPREAD;
|
||||
}
|
||||
|
||||
BlockIgniteEvent event = new BlockIgniteEvent(bukkitWorld.getBlockAt(x, y, z), cause, igniter);
|
||||
world.getServer().getPluginManager().callEvent(event);
|
||||
return event;
|
||||
}
|
||||
|
||||
public static BlockIgniteEvent callBlockIgniteEvent(World world, int x, int y, int z, Entity igniter) {
|
||||
org.bukkit.World bukkitWorld = world.getWorld();
|
||||
org.bukkit.entity.Entity bukkitIgniter = igniter.getBukkitEntity();
|
||||
IgniteCause cause;
|
||||
switch (bukkitIgniter.getType()) {
|
||||
case ENDER_CRYSTAL:
|
||||
cause = IgniteCause.ENDER_CRYSTAL;
|
||||
break;
|
||||
case LIGHTNING:
|
||||
cause = IgniteCause.LIGHTNING;
|
||||
break;
|
||||
case SMALL_FIREBALL:
|
||||
case FIREBALL:
|
||||
cause = IgniteCause.FIREBALL;
|
||||
break;
|
||||
default:
|
||||
cause = IgniteCause.FLINT_AND_STEEL;
|
||||
}
|
||||
|
||||
BlockIgniteEvent event = new BlockIgniteEvent(bukkitWorld.getBlockAt(x, y, z), cause, bukkitIgniter);
|
||||
world.getServer().getPluginManager().callEvent(event);
|
||||
return event;
|
||||
}
|
||||
|
||||
public static BlockIgniteEvent callBlockIgniteEvent(World world, int x, int y, int z, Explosion explosion) {
|
||||
org.bukkit.World bukkitWorld = world.getWorld();
|
||||
org.bukkit.entity.Entity igniter = explosion.source == null ? null : explosion.source.getBukkitEntity();
|
||||
|
||||
BlockIgniteEvent event = new BlockIgniteEvent(bukkitWorld.getBlockAt(x, y, z), IgniteCause.EXPLOSION, igniter);
|
||||
world.getServer().getPluginManager().callEvent(event);
|
||||
return event;
|
||||
}
|
||||
|
||||
public static BlockIgniteEvent callBlockIgniteEvent(World world, int x, int y, int z, IgniteCause cause, Entity igniter) {
|
||||
BlockIgniteEvent event = new BlockIgniteEvent(world.getWorld().getBlockAt(x, y, z), cause, igniter.getBukkitEntity());
|
||||
world.getServer().getPluginManager().callEvent(event);
|
||||
return event;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user