mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-24 03:25:15 +01:00
Send a BlockRedstoneEvent if powered redstone is destroyed
When a powered redstone block is destroyed, a BlockRedstoneEvent should be sent to notify plugins that particular block is returning to current 0 before the BlockDamageEvent is sent. This allows plugins dealing with redstone to not have to listen for redstone destruction, but just listen to changes in current.
This commit is contained in:
parent
4b6c633659
commit
71f97ffc5b
@ -17,6 +17,7 @@ import org.bukkit.craftbukkit.CraftWorld;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.Event.Type;
|
import org.bukkit.event.Event.Type;
|
||||||
import org.bukkit.event.block.BlockDamageEvent;
|
import org.bukkit.event.block.BlockDamageEvent;
|
||||||
|
import org.bukkit.event.block.BlockRedstoneEvent;
|
||||||
import org.bukkit.event.block.BlockRightClickEvent;
|
import org.bukkit.event.block.BlockRightClickEvent;
|
||||||
import org.bukkit.event.player.PlayerAnimationEvent;
|
import org.bukkit.event.player.PlayerAnimationEvent;
|
||||||
import org.bukkit.event.player.PlayerChatEvent;
|
import org.bukkit.event.player.PlayerChatEvent;
|
||||||
@ -319,7 +320,7 @@ public class NetServerHandler extends NetHandler implements ICommandListener {
|
|||||||
CraftBlock block = (CraftBlock) player.getWorld().getBlockAt(i, j, k);
|
CraftBlock block = (CraftBlock) player.getWorld().getBlockAt(i, j, k);
|
||||||
int blockId = block.getTypeId();
|
int blockId = block.getTypeId();
|
||||||
float damage = 0;
|
float damage = 0;
|
||||||
if(Block.byId[blockId] != null) {
|
if (Block.byId[blockId] != null) {
|
||||||
damage = Block.byId[blockId].a(player.getHandle()); //Get amount of damage going to block
|
damage = Block.byId[blockId].a(player.getHandle()); //Get amount of damage going to block
|
||||||
}
|
}
|
||||||
// CraftBukkit end
|
// CraftBukkit end
|
||||||
@ -327,11 +328,17 @@ public class NetServerHandler extends NetHandler implements ICommandListener {
|
|||||||
if (packet14blockdig.e == 0) {
|
if (packet14blockdig.e == 0) {
|
||||||
// CraftBukkit start
|
// CraftBukkit start
|
||||||
if (j1 > this.d.spawnProtection || flag) {
|
if (j1 > this.d.spawnProtection || flag) {
|
||||||
if(blockId > 0) {
|
if (blockId > 0) {
|
||||||
BlockDamageEvent event;
|
BlockDamageEvent event;
|
||||||
// If the amount of damage that the player is going to do to the block
|
// If the amount of damage that the player is going to do to the block
|
||||||
// is >= 1, then the block is going to break (eg, flowers, torches)
|
// is >= 1, then the block is going to break (eg, flowers, torches)
|
||||||
if (damage >= 1.0F) {
|
if (damage >= 1.0F) {
|
||||||
|
// if we are destroying either a redstone wire with a current greater than 0 or
|
||||||
|
// a redstone torch that is on, then we should notify plugins that this block has
|
||||||
|
// returned to a current value of 0 (since it will once the redstone is destroyed)
|
||||||
|
if ((blockId == Block.REDSTONE_WIRE.id && block.getData() > 0) || blockId == Block.REDSTONE_TORCH_ON.id) {
|
||||||
|
server.getPluginManager().callEvent( new BlockRedstoneEvent(block, (blockId == Block.REDSTONE_WIRE.id ? block.getData() : 15), 0));
|
||||||
|
}
|
||||||
event = new BlockDamageEvent(Type.BLOCK_DAMAGED, block, BlockDamageLevel.BROKEN, player);
|
event = new BlockDamageEvent(Type.BLOCK_DAMAGED, block, BlockDamageLevel.BROKEN, player);
|
||||||
} else {
|
} else {
|
||||||
event = new BlockDamageEvent(Type.BLOCK_DAMAGED, block, BlockDamageLevel.STARTED, player);
|
event = new BlockDamageEvent(Type.BLOCK_DAMAGED, block, BlockDamageLevel.STARTED, player);
|
||||||
@ -360,6 +367,12 @@ public class NetServerHandler extends NetHandler implements ICommandListener {
|
|||||||
// If the amount of damage going to the block plus the current amount
|
// If the amount of damage going to the block plus the current amount
|
||||||
// of damage is greater than 1, the block is going to break.
|
// of damage is greater than 1, the block is going to break.
|
||||||
if (e.c.d + damage >= 1.0F) {
|
if (e.c.d + damage >= 1.0F) {
|
||||||
|
// if we are destroying either a redstone wire with a current greater than 0 or
|
||||||
|
// a redstone torch that is on, then we should notify plugins that this block has
|
||||||
|
// returned to a current value of 0 (since it will once the redstone is destroyed)
|
||||||
|
if ((blockId == Block.REDSTONE_WIRE.id && block.getData() > 0) || blockId == Block.REDSTONE_TORCH_ON.id) {
|
||||||
|
server.getPluginManager().callEvent( new BlockRedstoneEvent(block, (blockId == Block.REDSTONE_WIRE.id ? block.getData() : 15), 0));
|
||||||
|
}
|
||||||
event = new BlockDamageEvent(Type.BLOCK_DAMAGED, block, BlockDamageLevel.BROKEN, player);
|
event = new BlockDamageEvent(Type.BLOCK_DAMAGED, block, BlockDamageLevel.BROKEN, player);
|
||||||
} else {
|
} else {
|
||||||
event = new BlockDamageEvent(Type.BLOCK_DAMAGED, block, BlockDamageLevel.DIGGING, player);
|
event = new BlockDamageEvent(Type.BLOCK_DAMAGED, block, BlockDamageLevel.DIGGING, player);
|
||||||
|
Loading…
Reference in New Issue
Block a user