Paper/nms-patches/EntityFishingHook.patch
2020-06-25 10:00:00 +10:00

110 Zeilen
5.7 KiB
Diff

--- a/net/minecraft/server/EntityFishingHook.java
+++ b/net/minecraft/server/EntityFishingHook.java
@@ -6,6 +6,11 @@
import java.util.List;
import java.util.Random;
import javax.annotation.Nullable;
+// CraftBukkit start
+import org.bukkit.entity.Player;
+import org.bukkit.entity.FishHook;
+import org.bukkit.event.player.PlayerFishEvent;
+// CraftBukkit end
public class EntityFishingHook extends IProjectile {
@@ -253,6 +258,10 @@
this.ao = 0;
this.ap = 0;
this.getDataWatcher().set(EntityFishingHook.f, false);
+ // CraftBukkit start
+ PlayerFishEvent playerFishEvent = new PlayerFishEvent((Player) this.getOwner().getBukkitEntity(), null, (FishHook) this.getBukkitEntity(), PlayerFishEvent.State.FAILED_ATTEMPT);
+ this.world.getServer().getPluginManager().callEvent(playerFishEvent);
+ // CraftBukkit end
}
} else {
float f;
@@ -286,6 +295,13 @@
worldserver.a(Particles.FISHING, d0, d1, d2, 0, (double) (-f4), 0.01D, (double) f3, 1.0D);
}
} else {
+ // CraftBukkit start
+ PlayerFishEvent playerFishEvent = new PlayerFishEvent((Player) this.getOwner().getBukkitEntity(), null, (FishHook) this.getBukkitEntity(), PlayerFishEvent.State.BITE);
+ this.world.getServer().getPluginManager().callEvent(playerFishEvent);
+ if (playerFishEvent.isCancelled()) {
+ return;
+ }
+ // CraftBukkit end
this.playSound(SoundEffects.ENTITY_FISHING_BOBBER_SPLASH, 0.25F, 1.0F + (this.random.nextFloat() - this.random.nextFloat()) * 0.4F);
double d3 = this.locY() + 0.5D;
@@ -390,6 +406,14 @@
int i = 0;
if (this.hooked != null) {
+ // CraftBukkit start
+ PlayerFishEvent playerFishEvent = new PlayerFishEvent((Player) entityhuman.getBukkitEntity(), this.hooked.getBukkitEntity(), (FishHook) this.getBukkitEntity(), PlayerFishEvent.State.CAUGHT_ENTITY);
+ this.world.getServer().getPluginManager().callEvent(playerFishEvent);
+
+ if (playerFishEvent.isCancelled()) {
+ return 0;
+ }
+ // CraftBukkit end
this.reel();
CriterionTriggers.D.a((EntityPlayer) entityhuman, itemstack, this, (Collection) Collections.emptyList());
this.world.broadcastEntityEffect(this, (byte) 31);
@@ -405,6 +429,15 @@
while (iterator.hasNext()) {
ItemStack itemstack1 = (ItemStack) iterator.next();
EntityItem entityitem = new EntityItem(this.world, this.locX(), this.locY(), this.locZ(), itemstack1);
+ // CraftBukkit start
+ PlayerFishEvent playerFishEvent = new PlayerFishEvent((Player) entityhuman.getBukkitEntity(), entityitem.getBukkitEntity(), (FishHook) this.getBukkitEntity(), PlayerFishEvent.State.CAUGHT_FISH);
+ playerFishEvent.setExpToDrop(this.random.nextInt(6) + 1);
+ this.world.getServer().getPluginManager().callEvent(playerFishEvent);
+
+ if (playerFishEvent.isCancelled()) {
+ return 0;
+ }
+ // CraftBukkit end
double d0 = entityhuman.locX() - this.locX();
double d1 = entityhuman.locY() - this.locY();
double d2 = entityhuman.locZ() - this.locZ();
@@ -412,7 +445,11 @@
entityitem.setMot(d0 * 0.1D, d1 * 0.1D + Math.sqrt(Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2)) * 0.08D, d2 * 0.1D);
this.world.addEntity(entityitem);
- entityhuman.world.addEntity(new EntityExperienceOrb(entityhuman.world, entityhuman.locX(), entityhuman.locY() + 0.5D, entityhuman.locZ() + 0.5D, this.random.nextInt(6) + 1));
+ // CraftBukkit start - this.random.nextInt(6) + 1 -> playerFishEvent.getExpToDrop()
+ if (playerFishEvent.getExpToDrop() > 0) {
+ entityhuman.world.addEntity(new EntityExperienceOrb(entityhuman.world, entityhuman.locX(), entityhuman.locY() + 0.5D, entityhuman.locZ() + 0.5D, playerFishEvent.getExpToDrop()));
+ }
+ // CraftBukkit end
if (itemstack1.getItem().a((Tag) TagsItem.FISHES)) {
entityhuman.a(StatisticList.FISH_CAUGHT, 1);
}
@@ -422,8 +459,25 @@
}
if (this.onGround) {
+ // CraftBukkit start
+ PlayerFishEvent playerFishEvent = new PlayerFishEvent((Player) entityhuman.getBukkitEntity(), null, (FishHook) this.getBukkitEntity(), PlayerFishEvent.State.IN_GROUND);
+ this.world.getServer().getPluginManager().callEvent(playerFishEvent);
+
+ if (playerFishEvent.isCancelled()) {
+ return 0;
+ }
+ // CraftBukkit end
i = 2;
}
+ // CraftBukkit start
+ if (i == 0) {
+ PlayerFishEvent playerFishEvent = new PlayerFishEvent((Player) entityhuman.getBukkitEntity(), null, (FishHook) this.getBukkitEntity(), PlayerFishEvent.State.REEL_IN);
+ this.world.getServer().getPluginManager().callEvent(playerFishEvent);
+ if (playerFishEvent.isCancelled()) {
+ return 0;
+ }
+ }
+ // CraftBukkit end
this.die();
return i;