Skip to content

Commit

Permalink
Add PlayerInteractEvent(...) when a player is trampling a crop (#1124)
Browse files Browse the repository at this point in the history
* Add CropTrampleEvent

* Change TABs to spaces to match the rest of the class

* Remove CropTrampleEvent, change to PlayerInteractEvent(...)
  • Loading branch information
MrPowerGamerBR authored and wu-vincent committed Oct 10, 2016
1 parent 1ea136c commit 2ea9e19
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions server/src/main/java/cn/nukkit/entity/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import cn.nukkit.block.BlockWater;
import cn.nukkit.entity.data.*;
import cn.nukkit.event.entity.*;
import cn.nukkit.event.player.PlayerInteractEvent;
import cn.nukkit.event.player.PlayerTeleportEvent;
import cn.nukkit.item.Item;
import cn.nukkit.level.Level;
Expand Down Expand Up @@ -1027,6 +1028,14 @@ public void fall(float fallDistance) {
Block down = this.level.getBlock(this.temporalVector.setComponents(getFloorX(), getFloorY() - 1, getFloorZ()));

if (down.getId() == Item.FARMLAND) {
if (this instanceof Player) {
Player p = (Player) this;
PlayerInteractEvent ev = new PlayerInteractEvent(p, p.getInventory().getItemInHand(), this.temporalVector.setComponents(down.x, down.y, down.z), PlayerInteractEvent.PHYSICAL);
this.server.getPluginManager().callEvent(ev);
if (ev.isCancelled()) {
return;
}
}
this.level.setBlock(this.temporalVector.setComponents(down.x, down.y, down.z), new BlockDirt(), true, true);
}
}
Expand Down

0 comments on commit 2ea9e19

Please sign in to comment.