3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-24 07:10:10 +01:00
Paper/nms-patches/EntityFishingHook.patch

118 Zeilen
6.2 KiB
Diff

2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/EntityFishingHook.java
+++ b/net/minecraft/server/EntityFishingHook.java
2018-07-15 02:00:00 +02:00
@@ -3,6 +3,11 @@
import java.util.Collections;
2016-02-29 22:32:46 +01:00
import java.util.Iterator;
import java.util.List;
+// CraftBukkit start
+import org.bukkit.entity.Player;
2018-07-15 02:00:00 +02:00
+import org.bukkit.entity.FishHook;
+import org.bukkit.event.player.PlayerFishEvent;
+// CraftBukkit end
2016-11-17 02:41:03 +01:00
public class EntityFishingHook extends Entity {
2018-07-15 02:00:00 +02:00
@@ -266,6 +271,7 @@
2016-11-17 02:41:03 +01:00
}
if (movingobjectposition != null && movingobjectposition.type != MovingObjectPosition.EnumMovingObjectType.MISS) {
2016-11-28 02:47:01 +01:00
+ org.bukkit.craftbukkit.event.CraftEventFactory.callProjectileHitEvent(this, movingobjectposition); // Craftbukkit - Call event
if (movingobjectposition.type == MovingObjectPosition.EnumMovingObjectType.ENTITY) {
this.hooked = movingobjectposition.entity;
2018-07-15 02:00:00 +02:00
this.o();
@@ -298,6 +304,10 @@
2016-11-17 02:41:03 +01:00
if (this.g <= 0) {
this.h = 0;
2018-07-15 02:00:00 +02:00
this.aw = 0;
2016-11-17 02:41:03 +01:00
+ // CraftBukkit start
2018-07-15 02:00:00 +02:00
+ PlayerFishEvent playerFishEvent = new PlayerFishEvent((Player) this.owner.getBukkitEntity(), null, (FishHook) this.getBukkitEntity(), PlayerFishEvent.State.FAILED_ATTEMPT);
2016-11-17 02:41:03 +01:00
+ this.world.getServer().getPluginManager().callEvent(playerFishEvent);
+ // CraftBukkit end
} else {
this.motY -= 0.2D * (double) this.random.nextFloat() * (double) this.random.nextFloat();
}
2018-07-15 02:00:00 +02:00
@@ -333,6 +343,13 @@
worldserver.a(Particles.x, d0, d1, d2, 0, (double) (-f4), 0.01D, (double) f3, 1.0D);
2016-11-17 02:41:03 +01:00
}
} else {
+ // CraftBukkit start
2018-07-15 02:00:00 +02:00
+ PlayerFishEvent playerFishEvent = new PlayerFishEvent((Player) this.owner.getBukkitEntity(), null, (FishHook) this.getBukkitEntity(), PlayerFishEvent.State.BITE);
2016-11-17 02:41:03 +01:00
+ this.world.getServer().getPluginManager().callEvent(playerFishEvent);
+ if (playerFishEvent.isCancelled()) {
+ return;
+ }
+ // CraftBukkit end
this.motY = (double) (-0.4F * MathHelper.a(this.random, 0.6F, 1.0F));
2018-07-15 02:00:00 +02:00
this.a(SoundEffects.ENTITY_FISHING_BOBBER_SPLASH, 0.25F, 1.0F + (this.random.nextFloat() - this.random.nextFloat()) * 0.4F);
2016-11-17 02:41:03 +01:00
double d3 = this.getBoundingBox().b + 0.5D;
2018-07-15 02:00:00 +02:00
@@ -389,6 +406,14 @@
int i = 0;
if (this.hooked != null) {
+ // CraftBukkit start
2018-07-15 02:00:00 +02:00
+ PlayerFishEvent playerFishEvent = new PlayerFishEvent((Player) this.owner.getBukkitEntity(), this.hooked.getBukkitEntity(), (FishHook) this.getBukkitEntity(), PlayerFishEvent.State.CAUGHT_ENTITY);
+ this.world.getServer().getPluginManager().callEvent(playerFishEvent);
+
+ if (playerFishEvent.isCancelled()) {
+ return 0;
+ }
+ // CraftBukkit end
2018-07-15 02:00:00 +02:00
this.f();
CriterionTriggers.D.a((EntityPlayer) this.owner, itemstack, this, Collections.emptyList());
this.world.broadcastEntityEffect(this, (byte) 31);
2018-07-15 02:00:00 +02:00
@@ -405,6 +430,15 @@
2016-02-29 22:32:46 +01:00
while (iterator.hasNext()) {
2018-07-15 02:00:00 +02:00
ItemStack itemstack1 = (ItemStack) iterator.next();
EntityItem entityitem = new EntityItem(this.world, this.locX, this.locY, this.locZ, itemstack1);
2016-02-29 22:32:46 +01:00
+ // CraftBukkit start
2018-07-15 02:00:00 +02:00
+ PlayerFishEvent playerFishEvent = new PlayerFishEvent((Player) this.owner.getBukkitEntity(), entityitem.getBukkitEntity(), (FishHook) this.getBukkitEntity(), PlayerFishEvent.State.CAUGHT_FISH);
2016-02-29 22:32:46 +01:00
+ playerFishEvent.setExpToDrop(this.random.nextInt(6) + 1);
+ this.world.getServer().getPluginManager().callEvent(playerFishEvent);
+
2016-02-29 22:32:46 +01:00
+ if (playerFishEvent.isCancelled()) {
+ return 0;
+ }
+ // CraftBukkit end
double d0 = this.owner.locX - this.locX;
double d1 = this.owner.locY - this.locY;
double d2 = this.owner.locZ - this.locZ;
2018-07-15 02:00:00 +02:00
@@ -415,7 +449,11 @@
2016-06-09 03:43:49 +02:00
entityitem.motY = d1 * 0.1D + (double) MathHelper.sqrt(d3) * 0.08D;
entityitem.motZ = d2 * 0.1D;
2016-02-29 22:32:46 +01:00
this.world.addEntity(entityitem);
- this.owner.world.addEntity(new EntityExperienceOrb(this.owner.world, this.owner.locX, this.owner.locY + 0.5D, this.owner.locZ + 0.5D, this.random.nextInt(6) + 1));
+ // CraftBukkit start - this.random.nextInt(6) + 1 -> playerFishEvent.getExpToDrop()
+ if (playerFishEvent.getExpToDrop() > 0) {
+ this.owner.world.addEntity(new EntityExperienceOrb(this.owner.world, this.owner.locX, this.owner.locY + 0.5D, this.owner.locZ + 0.5D, playerFishEvent.getExpToDrop()));
+ }
2016-11-17 02:41:03 +01:00
+ // CraftBukkit end
2018-08-26 04:00:00 +02:00
if (itemstack1.getItem().a(TagsItem.FISHES)) {
2018-07-15 02:00:00 +02:00
this.owner.a(StatisticList.FISH_CAUGHT, 1);
}
@@ -425,8 +463,25 @@
}
2016-02-29 22:32:46 +01:00
if (this.isInGround) {
+ // CraftBukkit start
2018-07-15 02:00:00 +02:00
+ PlayerFishEvent playerFishEvent = new PlayerFishEvent((Player) this.owner.getBukkitEntity(), null, (FishHook) this.getBukkitEntity(), PlayerFishEvent.State.IN_GROUND);
+ this.world.getServer().getPluginManager().callEvent(playerFishEvent);
+
+ if (playerFishEvent.isCancelled()) {
+ return 0;
+ }
+ // CraftBukkit end
2016-02-29 22:32:46 +01:00
i = 2;
}
+ // CraftBukkit start
+ if (i == 0) {
2018-07-15 02:00:00 +02:00
+ PlayerFishEvent playerFishEvent = new PlayerFishEvent((Player) this.owner.getBukkitEntity(), null, (FishHook) this.getBukkitEntity(), PlayerFishEvent.State.FAILED_ATTEMPT);
+ this.world.getServer().getPluginManager().callEvent(playerFishEvent);
+ if (playerFishEvent.isCancelled()) {
+ return 0;
+ }
+ }
+ // CraftBukkit end
2015-02-26 23:41:06 +01:00
this.die();
2016-11-17 02:41:03 +01:00
return i;