3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-18 04:20:08 +01:00

Further fixes to fire events

Moved lava ignition event into the correct position.
Spam should be reduced significantly.
Dieser Commit ist enthalten in:
Andrew Ardill 2011-01-19 05:44:01 +08:00 committet von Warren
Ursprung abc4b35bcd
Commit eace2d0f8a
3 geänderte Dateien mit 57 neuen und 32 gelöschten Zeilen

Datei anzeigen

@ -1,13 +1,13 @@
package net.minecraft.server; package net.minecraft.server;
// CraftBukkit start
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.block.BlockIgniteEvent; import org.bukkit.event.block.BlockIgniteEvent;
import org.bukkit.event.block.BlockIgniteEvent.IgniteCause; import org.bukkit.event.block.BlockIgniteEvent.IgniteCause;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.craftbukkit.CraftWorld;
import java.util.Random; import java.util.Random;
// CraftBukkit end
public class BlockFire extends Block { public class BlockFire extends Block {
@ -86,20 +86,22 @@ public class BlockFire extends Block {
} }
int i2 = h(world, i1, k1, j1); int i2 = h(world, i1, k1, j1);
//CraftBukkit start: Call to stop spead of fire. // CraftBukkit start: Call to stop spread of fire.
Server server = ((WorldServer)world).getServer(); Server server = ((WorldServer)world).getServer();
CraftWorld cworld = ((WorldServer)world).getWorld(); CraftWorld cworld = ((WorldServer)world).getWorld();
org.bukkit.block.Block theBlock = (cworld.getBlockAt(i1, j1, k1)); org.bukkit.block.Block theBlock = (cworld.getBlockAt(i1, j1, k1));
IgniteCause igniteCause = BlockIgniteEvent.IgniteCause.SPREAD;
Player thePlayer = null;
if (theBlock.getTypeId() != Block.ar.bi){ if (theBlock.getTypeId() != Block.ar.bi){
BlockIgniteEvent event = new BlockIgniteEvent(theBlock, BlockIgniteEvent.IgniteCause.SPREAD, null); BlockIgniteEvent event = new BlockIgniteEvent(theBlock, igniteCause, thePlayer);
server.getPluginManager().callEvent(event); server.getPluginManager().callEvent(event);
if (event.isCancelled()) { if (event.isCancelled()) {
return; return;
} }
} }
//CraftBukkit end // CraftBukkit end
if (i2 > 0 && random.nextInt(l1) <= i2) { if (i2 > 0 && random.nextInt(l1) <= i2) {
world.e(i1, k1, j1, bi); world.e(i1, k1, j1, bi);
} }
@ -121,15 +123,17 @@ public class BlockFire extends Block {
CraftWorld cworld = ((WorldServer)world).getWorld(); CraftWorld cworld = ((WorldServer)world).getWorld();
org.bukkit.block.Block theBlock = (cworld.getBlockAt(i, j, k)); org.bukkit.block.Block theBlock = (cworld.getBlockAt(i, j, k));
IgniteCause igniteCause = BlockIgniteEvent.IgniteCause.SLOW_SPREAD;
Player thePlayer = null;
if (theBlock.getTypeId() != Block.ar.bi){ if (theBlock.getTypeId() != Block.ar.bi){
BlockIgniteEvent event = new BlockIgniteEvent(theBlock, BlockIgniteEvent.IgniteCause.SLOW_SPREAD, null); BlockIgniteEvent event = new BlockIgniteEvent(theBlock, igniteCause, thePlayer);
server.getPluginManager().callEvent(event); server.getPluginManager().callEvent(event);
if (event.isCancelled()) { if (event.isCancelled()) {
return; return;
} }
} }
//CraftBukkit end // CraftBukkit end
world.e(i, j, k, bi); world.e(i, j, k, bi);
} else { } else {
world.e(i, j, k, 0); world.e(i, j, k, 0);

Datei anzeigen

@ -1,9 +1,13 @@
package net.minecraft.server; package net.minecraft.server;
// CraftBukkit start
import org.bukkit.Server;
import org.bukkit.entity.Player;
import org.bukkit.event.block.BlockIgniteEvent; import org.bukkit.event.block.BlockIgniteEvent;
import org.bukkit.craftbukkit.CraftServer; import org.bukkit.event.block.BlockIgniteEvent.IgniteCause;
import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.craftbukkit.CraftWorld;
import java.util.Random; import java.util.Random;
// CraftBukkit end
public class BlockStationary extends BlockFluids { public class BlockStationary extends BlockFluids {
@ -36,17 +40,6 @@ public class BlockStationary extends BlockFluids {
if (bt == Material.g) { if (bt == Material.g) {
int j1 = random.nextInt(3); int j1 = random.nextInt(3);
// Craftbukkit start: prevent lava putting something on fire.
CraftServer server = ((WorldServer)world).getServer();
CraftWorld cworld = ((WorldServer)world).getWorld();
org.bukkit.block.Block bblock = (cworld.getBlockAt(k, l, i1));
BlockIgniteEvent event = new BlockIgniteEvent((org.bukkit.block.Block) bblock, BlockIgniteEvent.IgniteCause.LAVA, null);
server.getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
}
// Craftbukkit end
for (int k1 = 0; k1 < j1; k1++) { for (int k1 = 0; k1 < j1; k1++) {
k += random.nextInt(3) - 1; k += random.nextInt(3) - 1;
l++; l++;
@ -54,7 +47,25 @@ public class BlockStationary extends BlockFluids {
int l1 = world.a(k, l, i1); int l1 = world.a(k, l, i1);
if (l1 == 0) { if (l1 == 0) {
// this checks if an adjacent block is flammable before lighting this block.
// perhaps we can reduce spam by checking this earlier.
if (j(world, k - 1, l, i1) || j(world, k + 1, l, i1) || j(world, k, l, i1 - 1) || j(world, k, l, i1 + 1) || j(world, k, l - 1, i1) || j(world, k, l + 1, i1)) { if (j(world, k - 1, l, i1) || j(world, k + 1, l, i1) || j(world, k, l, i1 - 1) || j(world, k, l, i1 + 1) || j(world, k, l - 1, i1) || j(world, k, l + 1, i1)) {
// CraftBukkit start: prevent lava putting something on fire.
Server server = ((WorldServer)world).getServer();
CraftWorld cworld = ((WorldServer)world).getWorld();
org.bukkit.block.Block theBlock = cworld.getBlockAt(k, l, i1);
IgniteCause igniteCause = BlockIgniteEvent.IgniteCause.LAVA;
Player thePlayer = null;
if (theBlock.getTypeId() != Block.ar.bi){
BlockIgniteEvent event = new BlockIgniteEvent(theBlock, igniteCause, thePlayer);
server.getPluginManager().callEvent(event);
if (event.isCancelled()) {
continue;
}
}
// CraftBukkit end
world.e(k, l, i1, Block.ar.bi); world.e(k, l, i1, Block.ar.bi);
return; return;
} }

Datei anzeigen

@ -3,12 +3,16 @@ package net.minecraft.server;
import java.util.Random; import java.util.Random;
// CraftBukkit start // CraftBukkit start
import org.bukkit.Server;
import org.bukkit.block.BlockFace;
import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.block.CraftBlock; import org.bukkit.craftbukkit.block.CraftBlock;
import org.bukkit.craftbukkit.inventory.CraftItemStack; import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.craftbukkit.entity.CraftPlayer; import org.bukkit.entity.Player;
import org.bukkit.event.Event.Type; import org.bukkit.event.Event.Type;
import org.bukkit.event.player.PlayerItemEvent; import org.bukkit.event.player.PlayerItemEvent;
import org.bukkit.event.block.BlockIgniteEvent; import org.bukkit.event.block.BlockIgniteEvent;
import org.bukkit.event.block.BlockIgniteEvent.IgniteCause;
// CraftBukkit end // CraftBukkit end
public class ItemFlintAndSteel extends Item { public class ItemFlintAndSteel extends Item {
@ -20,9 +24,6 @@ public class ItemFlintAndSteel extends Item {
} }
public boolean a(ItemStack itemstack, EntityPlayer entityplayer, World world, int i, int j, int k, int l) { public boolean a(ItemStack itemstack, EntityPlayer entityplayer, World world, int i, int j, int k, int l) {
// CraftBukkit - get the clicked block
CraftBlock blockClicked = (CraftBlock) ((WorldServer) world).getWorld().getBlockAt(i, j, k);
if (l == 0) { if (l == 0) {
j--; j--;
} }
@ -45,17 +46,26 @@ public class ItemFlintAndSteel extends Item {
if (i1 == 0) { if (i1 == 0) {
// CraftBukkit start - Flint and steel // CraftBukkit start - Flint and steel
CraftItemStack itemInHand = new CraftItemStack(itemstack); Server server = ((WorldServer)world).getServer();
CraftPlayer thePlayer = new CraftPlayer(((WorldServer) world).getServer(), (EntityPlayerMP) entityplayer); CraftWorld cworld = ((WorldServer)world).getWorld();
PlayerItemEvent pie = new PlayerItemEvent(Type.PLAYER_ITEM, thePlayer, itemInHand, blockClicked, CraftBlock.notchToBlockFace(l));
((WorldServer) world).getServer().getPluginManager().callEvent(pie);
org.bukkit.block.Block pblock = (((WorldServer) world).getWorld().getBlockAt(i, j, k)); Type eventType = Type.PLAYER_ITEM;
BlockIgniteEvent bie = new BlockIgniteEvent((org.bukkit.block.Block) pblock, BlockIgniteEvent.IgniteCause.FLINT_AND_STEEL, thePlayer); Player thePlayer = (Player) entityplayer.getBukkitEntity();
((WorldServer) world).getServer().getPluginManager().callEvent(bie); CraftItemStack itemInHand = new CraftItemStack(itemstack);
org.bukkit.block.Block blockClicked = cworld.getBlockAt(i, j, k);
BlockFace blockFace = CraftBlock.notchToBlockFace(l);
PlayerItemEvent pie = new PlayerItemEvent(eventType, thePlayer, itemInHand, blockClicked, blockFace);
server.getPluginManager().callEvent(pie);
boolean preventLighter = pie.isCancelled(); boolean preventLighter = pie.isCancelled();
boolean preventFire = bie.isCancelled(); boolean preventFire = false;
if (blockClicked.getTypeId() != Block.ar.bi){
IgniteCause igniteCause = BlockIgniteEvent.IgniteCause.FLINT_AND_STEEL;
BlockIgniteEvent bie = new BlockIgniteEvent(blockClicked, igniteCause, thePlayer);
server.getPluginManager().callEvent(bie);
preventFire = bie.isCancelled();
}
if (preventLighter || preventFire) { if (preventLighter || preventFire) {
return false; return false;