0
0
mirror of https://hub.spigotmc.org/stash/scm/spigot/craftbukkit.git synced 2025-04-16 01:25:35 +00:00
Files
2025-03-26 03:05:00 +11:00

83 lines
4.7 KiB
Diff

--- a/net/minecraft/world/entity/projectile/ThrownSplashPotion.java
+++ b/net/minecraft/world/entity/projectile/ThrownSplashPotion.java
@@ -17,6 +17,16 @@
import net.minecraft.world.level.World;
import net.minecraft.world.phys.AxisAlignedBB;
+// CraftBukkit start
+import java.util.HashMap;
+import java.util.Map;
+import net.minecraft.server.level.EntityPlayer;
+import net.minecraft.world.effect.MobEffects;
+import net.minecraft.world.phys.MovingObjectPosition;
+import org.bukkit.craftbukkit.entity.CraftLivingEntity;
+import org.bukkit.entity.LivingEntity;
+// CraftBukkit end
+
public class ThrownSplashPotion extends EntityPotion {
public ThrownSplashPotion(EntityTypes<? extends ThrownSplashPotion> entitytypes, World world) {
@@ -37,12 +47,13 @@
}
@Override
- public void onHitAsPotion(WorldServer worldserver, ItemStack itemstack, @Nullable Entity entity) {
+ public void onHitAsPotion(WorldServer worldserver, ItemStack itemstack, @Nullable Entity entity, MovingObjectPosition position) { // CraftBukkit - Pass MovingObjectPosition
PotionContents potioncontents = (PotionContents) itemstack.getOrDefault(DataComponents.POTION_CONTENTS, PotionContents.EMPTY);
float f = (Float) itemstack.getOrDefault(DataComponents.POTION_DURATION_SCALE, 1.0F);
Iterable<MobEffect> iterable = potioncontents.getAllEffects();
AxisAlignedBB axisalignedbb = this.getBoundingBox().inflate(4.0D, 2.0D, 4.0D);
List<EntityLiving> list = this.level().<EntityLiving>getEntitiesOfClass(EntityLiving.class, axisalignedbb);
+ Map<LivingEntity, Double> affected = new HashMap<LivingEntity, Double>(); // CraftBukkit
if (!list.isEmpty()) {
Entity entity1 = this.getEffectSource();
@@ -60,8 +71,38 @@
d1 = 1.0D - Math.sqrt(d0) / 4.0D;
}
+ // CraftBukkit start
+ affected.put((LivingEntity) entityliving.getBukkitEntity(), d1);
+ }
+ }
+ }
+ }
+
+ {
+ {
+ org.bukkit.event.entity.PotionSplashEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callPotionSplashEvent(this, position, affected);
+ if (!event.isCancelled() && list != null && !list.isEmpty()) { // do not process effects if there are no effects to process
+ Entity entity1 = this.getEffectSource();
+ for (LivingEntity victim : event.getAffectedEntities()) {
+ if (!(victim instanceof CraftLivingEntity)) {
+ continue;
+ }
+
+ EntityLiving entityliving = ((CraftLivingEntity) victim).getHandle();
+ double d1 = event.getIntensity(victim);
+ // CraftBukkit end
+
for (MobEffect mobeffect : iterable) {
Holder<MobEffectList> holder = mobeffect.getEffect();
+ // CraftBukkit start - Abide by PVP settings - for players only!
+ if (!this.level().pvpMode && this.getOwner() instanceof EntityPlayer && entityliving instanceof EntityPlayer && entityliving != this.getOwner()) {
+ MobEffectList mobeffectlist = (MobEffectList) holder.value();
+ if (mobeffectlist == MobEffects.SLOWNESS || mobeffectlist == MobEffects.MINING_FATIGUE || mobeffectlist == MobEffects.INSTANT_DAMAGE || mobeffectlist == MobEffects.BLINDNESS
+ || mobeffectlist == MobEffects.HUNGER || mobeffectlist == MobEffects.WEAKNESS || mobeffectlist == MobEffects.POISON) {
+ continue;
+ }
+ }
+ // CraftBukkit end
if (((MobEffectList) holder.value()).isInstantenous()) {
((MobEffectList) holder.value()).applyInstantenousEffect(worldserver, this, this.getOwner(), entityliving, mobeffect.getAmplifier(), d1);
@@ -72,7 +113,7 @@
MobEffect mobeffect1 = new MobEffect(holder, i, mobeffect.getAmplifier(), mobeffect.isAmbient(), mobeffect.isVisible());
if (!mobeffect1.endsWithin(20)) {
- entityliving.addEffect(mobeffect1, entity1);
+ entityliving.addEffect(mobeffect1, entity1, org.bukkit.event.entity.EntityPotionEffectEvent.Cause.POTION_SPLASH); // CraftBukkit
}
}
}