Archiviert
13
0

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.logging.Logger;
import org.bukkit.BlockDamageLevel;
import org.bukkit.BlockFace;
import org.bukkit.Location;
@ -10,12 +11,12 @@ import org.bukkit.craftbukkit.CraftItemStack;
import org.bukkit.craftbukkit.CraftPlayer;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.event.Event.Type;
import org.bukkit.event.block.BlockDamagedEvent;
import org.bukkit.event.block.BlockRightClickedEvent;
import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.event.player.PlayerItemEvent;
import org.bukkit.event.player.PlayerMoveEvent;
public class NetServerHandler extends NetHandler
implements ICommandListener {
@ -30,7 +31,6 @@ implements ICommandListener {
private double i;
private boolean j;
private Map<Integer, Short> k;
// CraftBukkit - next 2 lines
private final CraftServer server;
private final CraftPlayer player;
@ -272,16 +272,50 @@ implements ICommandListener {
if (l1 > i2) {
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 (i2 > 16 || flag) {
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) {
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) {
if (i2 > 16 || flag) {
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) {
double d6 = e.p - ((double) l + 0.5D);
double d7 = e.q - ((double) i1 + 0.5D);
@ -292,9 +326,10 @@ implements ICommandListener {
e.a.b(new Packet53BlockChange(l, i1, j1, d.e));
}
}
// Craftbukkit stop
d.e.B = false;
}
// Craftbukkit start - store the last block right clicked and what type it was
CraftBlock lastRightClicked;
int lastMaterial;
@ -464,7 +499,9 @@ implements ICommandListener {
PlayerChatEvent event = new PlayerChatEvent(Type.PLAYER_CHAT, player, s);
server.getPluginManager().callEvent(event);
s = String.format(event.getFormat(), event.getPlayer().getDisplayName(), event.getMessage());
if (event.isCancelled()) return;
if (event.isCancelled()) {
return;
}
// CraftBukkit stop
a.info(s);
@ -476,7 +513,9 @@ implements ICommandListener {
// CraftBukkit start
PlayerChatEvent event = new PlayerChatEvent(Type.PLAYER_COMMAND, player, s);
server.getPluginManager().callEvent(event);
if (event.isCancelled()) return;
if (event.isCancelled()) {
return;
}
s = event.getMessage();
CraftPlayer player = (CraftPlayer) event.getPlayer();
EntityPlayerMP e = player.getHandle();
@ -634,6 +673,4 @@ implements ICommandListener {
}
}
}
}