mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-09 04:09:54 +01:00
BlockDamagedEvent
This commit is contained in:
parent
103d4ee887
commit
21e7f1c440
128
src/main/java/net/minecraft/server/ItemInWorldManager.java
Normal file
128
src/main/java/net/minecraft/server/ItemInWorldManager.java
Normal file
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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 {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user