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

BlockDamagedEvent

Dieser Commit ist enthalten in:
Taylor Kelly 2011-01-10 09:36:19 +08:00 committet von Dinner Bone
Ursprung 103d4ee887
Commit 21e7f1c440
2 geänderte Dateien mit 198 neuen und 33 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,128 @@
package net.minecraft.server;
public class ItemInWorldManager {
private World b;
public EntityPlayer a;
private float c;
private float d;
private int e;
private float f;
private int g;
private int h;
private int i;
public ItemInWorldManager(World world) {
d = 0.0F;
e = 0;
f = 0.0F;
b = world;
}
public void a(int j, int k, int l) {
int i1 = b.a(j, k, l);
if (i1 > 0 && d == 0.0F) {
Block.m[i1].b(b, j, k, l, a);
}
if (i1 > 0 && Block.m[i1].a(a) >= 1.0F) {
c(j, k, l);
}
}
public void a() {
d = 0.0F;
e = 0;
}
public void a(int j, int k, int l, int i1) {
if (e > 0) {
e--;
return;
}
if (j == g && k == h && l == i) {
int j1 = b.a(j, k, l);
if (j1 == 0) {
return;
}
Block block = Block.m[j1];
d += block.a(a);
f++;
if (d >= 1.0F) {
c(j, k, l);
d = 0.0F;
c = 0.0F;
f = 0.0F;
e = 5;
}
} else {
d = 0.0F;
c = 0.0F;
f = 0.0F;
g = j;
h = k;
i = l;
}
}
public boolean b(int j, int k, int l) {
Block block = Block.m[b.a(j, k, l)];
int i1 = b.b(j, k, l);
boolean flag = b.d(j, k, l, 0);
if (block != null && flag) {
block.a(b, j, k, l, i1);
}
return flag;
}
public boolean c(int j, int k, int l) {
int i1 = b.a(j, k, l);
int j1 = b.b(j, k, l);
boolean flag = b(j, k, l);
ItemStack itemstack = a.M();
if (itemstack != null) {
itemstack.a(i1, j, k, l);
if (itemstack.a == 0) {
itemstack.a(a);
a.N();
}
}
if (flag && a.b(Block.m[i1])) {
Block.m[i1].g(b, j, k, l, j1);
}
return flag;
}
public boolean a(EntityPlayer entityplayer, World world, ItemStack itemstack) {
int j = itemstack.a;
ItemStack itemstack1 = itemstack.a(world, entityplayer);
if (itemstack1 != itemstack || itemstack1 != null && itemstack1.a != j) {
entityplayer.an.a[entityplayer.an.c] = itemstack1;
if (itemstack1.a == 0) {
entityplayer.an.a[entityplayer.an.c] = null;
}
return true;
} else {
return false;
}
}
public boolean a(EntityPlayer entityplayer, World world, ItemStack itemstack, int j, int k, int l, int i1) {
int j1 = world.a(j, k, l);
if (j1 > 0 && Block.m[j1].a(world, j, k, l, entityplayer)) {
return true;
}
if (itemstack == null) {
return false;
} else {
return itemstack.a(entityplayer, world, j, k, l, i1);
}
}
}

Datei anzeigen

@ -2,6 +2,7 @@ package net.minecraft.server;
import java.util.*; import java.util.*;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.bukkit.BlockDamageLevel;
import org.bukkit.BlockFace; import org.bukkit.BlockFace;
import org.bukkit.Location; import org.bukkit.Location;
@ -10,14 +11,14 @@ import org.bukkit.craftbukkit.CraftItemStack;
import org.bukkit.craftbukkit.CraftPlayer; import org.bukkit.craftbukkit.CraftPlayer;
import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.event.Event.Type; import org.bukkit.event.Event.Type;
import org.bukkit.event.block.BlockDamagedEvent;
import org.bukkit.event.block.BlockRightClickedEvent; import org.bukkit.event.block.BlockRightClickedEvent;
import org.bukkit.event.player.PlayerChatEvent; import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.event.player.PlayerItemEvent; import org.bukkit.event.player.PlayerItemEvent;
import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerMoveEvent;
public class NetServerHandler extends NetHandler public class NetServerHandler extends NetHandler
implements ICommandListener { implements ICommandListener {
public static Logger a = Logger.getLogger("Minecraft"); public static Logger a = Logger.getLogger("Minecraft");
public NetworkManager b; public NetworkManager b;
@ -30,7 +31,6 @@ implements ICommandListener {
private double i; private double i;
private boolean j; private boolean j;
private Map<Integer, Short> k; private Map<Integer, Short> k;
// CraftBukkit - next 2 lines // CraftBukkit - next 2 lines
private final CraftServer server; private final CraftServer server;
private final CraftPlayer player; private final CraftPlayer player;
@ -272,15 +272,49 @@ implements ICommandListener {
if (l1 > i2) { if (l1 > i2) {
i2 = l1; i2 = l1;
} }
// Craftbukkit start
CraftBlock block = (CraftBlock) player.getWorld().getBlockAt(l, i1, j1);
int blockID = block.getTypeID();
float damage = Block.m[blockID].a(player.getHandle()); //Get amount of damage going to block
if (packet14blockdig.e == 0) { if (packet14blockdig.e == 0) {
if (i2 > 16 || flag) { if (i2 > 16 || flag) {
e.c.a(l, i1, j1); if(blockID > 0) {
BlockDamagedEvent event;
// 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)
if(damage >= 1.0F) {
event = new BlockDamagedEvent(Type.BLOCK_DAMAGED, block, BlockDamageLevel.BROKEN, player);
} else {
event = new BlockDamagedEvent(Type.BLOCK_DAMAGED, block, BlockDamageLevel.STARTED, player);
}
server.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
e.c.a(l, i1, j1);
}
}
} }
} else if (packet14blockdig.e == 2) { } else if (packet14blockdig.e == 2) {
e.c.a(); BlockDamagedEvent event = new BlockDamagedEvent(Type.BLOCK_DAMAGED, block, BlockDamageLevel.STOPPED, player);
server.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
e.c.a();
}
} else if (packet14blockdig.e == 1) { } else if (packet14blockdig.e == 1) {
if (i2 > 16 || flag) { if (i2 > 16 || flag) {
e.c.a(l, i1, j1, k1); BlockDamagedEvent event;
// 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.
if (e.c.d + damage >= 1.0F) {
event = new BlockDamagedEvent(Type.BLOCK_DAMAGED, block, BlockDamageLevel.BROKEN, player);
} else {
event = new BlockDamagedEvent(Type.BLOCK_DAMAGED, block, BlockDamageLevel.DIGGING, player);
}
server.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
e.c.a(l, i1, j1, k1);
}
} }
} else if (packet14blockdig.e == 3) { } else if (packet14blockdig.e == 3) {
double d6 = e.p - ((double) l + 0.5D); double d6 = e.p - ((double) l + 0.5D);
@ -292,9 +326,10 @@ implements ICommandListener {
e.a.b(new Packet53BlockChange(l, i1, j1, d.e)); e.a.b(new Packet53BlockChange(l, i1, j1, d.e));
} }
} }
// Craftbukkit stop
d.e.B = false; d.e.B = false;
} }
// Craftbukkit start - store the last block right clicked and what type it was // Craftbukkit start - store the last block right clicked and what type it was
CraftBlock lastRightClicked; CraftBlock lastRightClicked;
int lastMaterial; int lastMaterial;
@ -302,7 +337,7 @@ implements ICommandListener {
public void a(Packet15Place packet15place) { public void a(Packet15Place packet15place) {
ItemStack itemstack = e.an.e(); ItemStack itemstack = e.an.e();
// Craftbukkit we don't check spawn protection here anymore // Craftbukkit we don't check spawn protection here anymore
/* boolean flag = */d.e.B = d.f.g(e.aw); /* boolean flag = */ d.e.B = d.f.g(e.aw);
CraftBlock blockClicked = null; CraftBlock blockClicked = null;
BlockFace blockFace = null; BlockFace blockFace = null;
@ -346,13 +381,13 @@ implements ICommandListener {
// Craftbukkit We still call this event even in spawn protection. // Craftbukkit We still call this event even in spawn protection.
// Don't call this event if using Buckets / signs // Don't call this event if using Buckets / signs
switch (craftItem.getType()) { switch (craftItem.getType()) {
case Sign: case Sign:
case Bucket: case Bucket:
case WaterBucket: case WaterBucket:
case LavaBucket: case LavaBucket:
break; break;
default: default:
server.getPluginManager().callEvent(pie); server.getPluginManager().callEvent(pie);
} }
if (!pie.isCancelled()) { if (!pie.isCancelled()) {
@ -464,7 +499,9 @@ implements ICommandListener {
PlayerChatEvent event = new PlayerChatEvent(Type.PLAYER_CHAT, player, s); PlayerChatEvent event = new PlayerChatEvent(Type.PLAYER_CHAT, player, s);
server.getPluginManager().callEvent(event); server.getPluginManager().callEvent(event);
s = String.format(event.getFormat(), event.getPlayer().getDisplayName(), event.getMessage()); s = String.format(event.getFormat(), event.getPlayer().getDisplayName(), event.getMessage());
if (event.isCancelled()) return; if (event.isCancelled()) {
return;
}
// CraftBukkit stop // CraftBukkit stop
a.info(s); a.info(s);
@ -476,9 +513,11 @@ implements ICommandListener {
// CraftBukkit start // CraftBukkit start
PlayerChatEvent event = new PlayerChatEvent(Type.PLAYER_COMMAND, player, s); PlayerChatEvent event = new PlayerChatEvent(Type.PLAYER_COMMAND, player, s);
server.getPluginManager().callEvent(event); server.getPluginManager().callEvent(event);
if (event.isCancelled()) return; if (event.isCancelled()) {
return;
}
s = event.getMessage(); s = event.getMessage();
CraftPlayer player = (CraftPlayer)event.getPlayer(); CraftPlayer player = (CraftPlayer) event.getPlayer();
EntityPlayerMP e = player.getHandle(); EntityPlayerMP e = player.getHandle();
// CraftBukkit stop // CraftBukkit stop
@ -634,6 +673,4 @@ implements ICommandListener {
} }
} }
} }
} }