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

72 Zeilen
3.5 KiB
Diff

2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/EntityPotion.java
+++ b/net/minecraft/server/EntityPotion.java
@@ -3,6 +3,13 @@
import java.util.Iterator;
import java.util.List;
+// CraftBukkit start
+import java.util.HashMap;
+
+import org.bukkit.craftbukkit.entity.CraftLivingEntity;
+import org.bukkit.entity.LivingEntity;
+// CraftBukkit end
+
public class EntityPotion extends EntityProjectile {
public ItemStack item;
2015-02-26 23:41:06 +01:00
@@ -57,13 +64,16 @@
if (!this.world.isClientSide) {
List list = Items.POTION.h(this.item);
- if (list != null && !list.isEmpty()) {
+ if (true || list != null && !list.isEmpty()) { // CraftBukkit - Call event even if no effects to apply
AxisAlignedBB axisalignedbb = this.getBoundingBox().grow(4.0D, 2.0D, 4.0D);
List list1 = this.world.a(EntityLiving.class, axisalignedbb);
- if (!list1.isEmpty()) {
2015-02-26 23:41:06 +01:00
+ if (true || !list1.isEmpty()) { // CraftBukkit - Run code even if there are no entities around
Iterator iterator = list1.iterator();
2015-02-26 23:41:06 +01:00
+ // CraftBukkit
+ HashMap<LivingEntity, Double> affected = new HashMap<LivingEntity, Double>();
2015-02-26 23:41:06 +01:00
+
while (iterator.hasNext()) {
EntityLiving entityliving = (EntityLiving) iterator.next();
2015-02-26 23:41:06 +01:00
double d0 = this.h(entityliving);
@@ -75,12 +85,35 @@
d1 = 1.0D;
}
2015-02-26 23:41:06 +01:00
+ // CraftBukkit start
+ affected.put((LivingEntity) entityliving.getBukkitEntity(), d1);
+ }
+ }
+
+ 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;
+ }
+
+ EntityLiving entityliving = ((CraftLivingEntity) victim).getHandle();
+ double d1 = event.getIntensity(victim);
+ // CraftBukkit end
2015-02-26 23:41:06 +01:00
+
Iterator iterator1 = list.iterator();
while (iterator1.hasNext()) {
MobEffect mobeffect = (MobEffect) iterator1.next();
int i = mobeffect.getEffectId();
2015-02-26 23:41:06 +01:00
+ // CraftBukkit start - Abide by PVP settings - for players only!
+ if (!this.world.pvpMode && this.getShooter() instanceof EntityPlayer && entityliving instanceof EntityPlayer && entityliving != this.getShooter()) {
+ // 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
2015-02-26 23:41:06 +01:00
+
if (MobEffectList.byId[i].isInstant()) {
MobEffectList.byId[i].applyInstantEffect(this, this.getShooter(), entityliving, mobeffect.getAmplifier(), d1);
2015-02-26 23:41:06 +01:00
} else {