3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-24 15:20:11 +01:00
Paper/nms-patches/EntityPotion.patch

135 Zeilen
6.6 KiB
Diff

2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/EntityPotion.java
+++ b/net/minecraft/server/EntityPotion.java
2020-06-25 02:00:00 +02:00
@@ -4,6 +4,13 @@
import java.util.List;
import java.util.function.Predicate;
2019-04-23 04:00:00 +02:00
import javax.annotation.Nullable;
+// CraftBukkit start
+import java.util.HashMap;
2016-11-17 02:41:03 +01:00
+import java.util.Map;
+import org.bukkit.craftbukkit.entity.CraftLivingEntity;
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.entity.LivingEntity;
+// CraftBukkit end
2016-11-17 02:41:03 +01:00
2020-06-25 02:00:00 +02:00
public class EntityPotion extends EntityProjectileThrowable {
2020-06-25 02:00:00 +02:00
@@ -69,7 +76,7 @@
2016-11-17 02:41:03 +01:00
if (flag) {
2019-04-23 04:00:00 +02:00
this.splash();
2016-11-17 02:41:03 +01:00
- } else if (!list.isEmpty()) {
+ } else if (true || !list.isEmpty()) { // CraftBukkit - Call event even if no effects to apply
if (this.isLingering()) {
this.a(itemstack, potionregistry);
} else {
2020-06-25 02:00:00 +02:00
@@ -106,6 +113,7 @@
2019-04-23 04:00:00 +02:00
private void a(List<MobEffect> list, @Nullable Entity entity) {
2016-11-17 02:41:03 +01:00
AxisAlignedBB axisalignedbb = this.getBoundingBox().grow(4.0D, 2.0D, 4.0D);
2018-12-25 22:00:00 +01:00
List<EntityLiving> list1 = this.world.a(EntityLiving.class, axisalignedbb);
2016-11-17 02:41:03 +01:00
+ Map<LivingEntity, Double> affected = new HashMap<LivingEntity, Double>(); // CraftBukkit
2016-11-17 02:41:03 +01:00
if (!list1.isEmpty()) {
Iterator iterator = list1.iterator();
2020-06-25 02:00:00 +02:00
@@ -123,21 +131,46 @@
2016-11-17 02:41:03 +01:00
d1 = 1.0D;
}
2015-02-26 23:41:06 +01:00
2016-11-17 02:41:03 +01:00
- Iterator iterator1 = list.iterator();
+ // CraftBukkit start
2016-11-17 02:41:03 +01:00
+ affected.put((LivingEntity) entityliving.getBukkitEntity(), d1);
+ }
+ }
+ }
+ }
2020-06-25 02:00:00 +02:00
- while (iterator1.hasNext()) {
- MobEffect mobeffect = (MobEffect) iterator1.next();
- MobEffectList mobeffectlist = mobeffect.getMobEffect();
-
- if (mobeffectlist.isInstant()) {
- mobeffectlist.applyInstantEffect(this, this.getShooter(), entityliving, mobeffect.getAmplifier(), d1);
- } else {
- int i = (int) (d1 * (double) mobeffect.getDuration() + 0.5D);
-
- if (i > 20) {
- entityliving.addEffect(new MobEffect(mobeffectlist, i, mobeffect.getAmplifier(), mobeffect.isAmbient(), mobeffect.isShowParticles()));
- }
- }
2016-11-17 02:41:03 +01:00
+ org.bukkit.event.entity.PotionSplashEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callPotionSplashEvent(this, affected);
+ if (!event.isCancelled() && list != null && !list.isEmpty()) { // do not process effects if there are no effects to process
+ for (LivingEntity victim : event.getAffectedEntities()) {
+ if (!(victim instanceof CraftLivingEntity)) {
+ continue;
+ }
+
2016-11-17 02:41:03 +01:00
+ EntityLiving entityliving = ((CraftLivingEntity) victim).getHandle();
+ double d1 = event.getIntensity(victim);
+ // CraftBukkit end
+
2016-11-17 02:41:03 +01:00
+ Iterator iterator1 = list.iterator();
2015-02-26 23:41:06 +01:00
+
2016-11-17 02:41:03 +01:00
+ while (iterator1.hasNext()) {
+ MobEffect mobeffect = (MobEffect) iterator1.next();
+ MobEffectList mobeffectlist = mobeffect.getMobEffect();
+ // CraftBukkit start - Abide by PVP settings - for players only!
+ if (!this.world.pvpMode && this.getShooter() instanceof EntityPlayer && entityliving instanceof EntityPlayer && entityliving != this.getShooter()) {
+ int i = MobEffectList.getId(mobeffectlist);
+ // Block SLOWER_MOVEMENT, SLOWER_DIG, HARM, BLINDNESS, HUNGER, WEAKNESS and POISON potions
+ if (i == 2 || i == 4 || i == 7 || i == 15 || i == 17 || i == 18 || i == 19) {
+ continue;
+ }
+ }
+ // CraftBukkit end
2020-06-25 02:00:00 +02:00
+
2016-11-17 02:41:03 +01:00
+ if (mobeffectlist.isInstant()) {
+ mobeffectlist.applyInstantEffect(this, this.getShooter(), entityliving, mobeffect.getAmplifier(), d1);
+ } else {
+ int i = (int) (d1 * (double) mobeffect.getDuration() + 0.5D);
2016-03-20 03:42:12 +01:00
+
2016-11-17 02:41:03 +01:00
+ if (i > 20) {
+ entityliving.addEffect(new MobEffect(mobeffectlist, i, mobeffect.getAmplifier(), mobeffect.isAmbient(), mobeffect.isShowParticles()), org.bukkit.event.entity.EntityPotionEffectEvent.Cause.POTION_SPLASH); // CraftBukkit
2016-02-29 22:32:46 +01:00
}
}
}
2020-06-25 02:00:00 +02:00
@@ -173,7 +206,14 @@
2016-12-20 21:00:00 +01:00
entityareaeffectcloud.setColor(nbttagcompound.getInt("CustomPotionColor"));
}
2016-11-17 02:41:03 +01:00
- this.world.addEntity(entityareaeffectcloud);
+ // CraftBukkit start
+ org.bukkit.event.entity.LingeringPotionSplashEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callLingeringPotionSplashEvent(this, entityareaeffectcloud);
+ if (!(event.isCancelled() || entityareaeffectcloud.dead)) {
+ this.world.addEntity(entityareaeffectcloud);
+ } else {
+ entityareaeffectcloud.dead = true;
+ }
+ // CraftBukkit end
}
public boolean isLingering() {
2020-06-25 02:00:00 +02:00
@@ -184,11 +224,19 @@
IBlockData iblockdata = this.world.getType(blockposition);
2020-06-25 02:00:00 +02:00
if (iblockdata.a((Tag) TagsBlock.FIRE)) {
- this.world.a(blockposition, false);
+ // CraftBukkit start
2020-06-25 02:00:00 +02:00
+ if (!CraftEventFactory.callEntityChangeBlockEvent(this, blockposition, Blocks.AIR.getBlockData()).isCancelled()) {
+ this.world.a(blockposition, false);
+ }
+ // CraftBukkit end
2020-06-25 02:00:00 +02:00
} else if (BlockCampfire.g(iblockdata)) {
- this.world.a((EntityHuman) null, 1009, blockposition, 0);
2020-06-25 02:00:00 +02:00
- BlockCampfire.c((GeneratorAccess) this.world, blockposition, iblockdata);
- this.world.setTypeUpdate(blockposition, (IBlockData) iblockdata.set(BlockCampfire.b, false));
+ // CraftBukkit start
+ if (!CraftEventFactory.callEntityChangeBlockEvent(this, blockposition, iblockdata.set(BlockCampfire.b, false)).isCancelled()) { // PAIL rename LIT
+ this.world.a((EntityHuman) null, 1009, blockposition, 0);
2020-06-25 02:00:00 +02:00
+ BlockCampfire.c((GeneratorAccess) this.world, blockposition, iblockdata);
+ this.world.setTypeUpdate(blockposition, (IBlockData) iblockdata.set(BlockCampfire.b, false));
+ }
+ // CraftBukkit end
}
}