From 872dad554044aae57b786d5c14523cee5778ebc7 Mon Sep 17 00:00:00 2001 From: Zeerix Date: Fri, 20 Jan 2012 09:56:02 +0100 Subject: [PATCH] [Bleeding] Implemented PotionSplashEvent. Closes BUKKIT-307 --- .../net/minecraft/server/EntityPotion.java | 28 +++++++++++++++++++ .../craftbukkit/event/CraftEventFactory.java | 15 ++++++++++ 2 files changed, 43 insertions(+) diff --git a/src/main/java/net/minecraft/server/EntityPotion.java b/src/main/java/net/minecraft/server/EntityPotion.java index 884b052cc9..3641e52ff7 100644 --- a/src/main/java/net/minecraft/server/EntityPotion.java +++ b/src/main/java/net/minecraft/server/EntityPotion.java @@ -3,6 +3,16 @@ package net.minecraft.server; import java.util.Iterator; import java.util.List; +// CraftBukkit start +import java.util.Collection; +import java.util.HashMap; + +import org.bukkit.craftbukkit.entity.CraftLivingEntity; +import org.bukkit.craftbukkit.event.CraftEventFactory; +import org.bukkit.entity.LivingEntity; +import org.bukkit.event.entity.PotionSplashEvent; +// CraftBukkit end + public class EntityPotion extends EntityProjectile { private int d; @@ -48,6 +58,9 @@ public class EntityPotion extends EntityProjectile { if (list1 != null && !list1.isEmpty()) { Iterator iterator = list1.iterator(); + // CraftBukkit + HashMap affected = new HashMap(); + while (iterator.hasNext()) { Entity entity = (Entity) iterator.next(); double d0 = this.i(entity); @@ -59,6 +72,21 @@ public class EntityPotion extends EntityProjectile { d1 = 1.0D; } + // CraftBukkit start + affected.put((LivingEntity) entity.getBukkitEntity(), d1); + } + } + + PotionSplashEvent event = CraftEventFactory.callPotionSplashEvent(this, affected); + if (!event.isCancelled()) { + for (LivingEntity victim : event.getAffectedEntities()) { + if (!(victim instanceof CraftLivingEntity)) { + continue; + } + EntityLiving entity = ((CraftLivingEntity) victim).getHandle(); + double d1 = event.getIntensity(victim); + // CraftBukkit end + Iterator iterator1 = list.iterator(); while (iterator1.hasNext()) { diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java index d37ce1ad84..db45fb60cc 100644 --- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java @@ -2,6 +2,7 @@ package org.bukkit.craftbukkit.event; import java.net.InetAddress; import java.util.List; +import java.util.Map; import net.minecraft.server.ChunkCoordinates; import net.minecraft.server.Entity; @@ -24,6 +25,7 @@ import net.minecraft.server.EntityMushroomCow; import net.minecraft.server.EntityPig; import net.minecraft.server.EntityPigZombie; import net.minecraft.server.EntityPlayer; +import net.minecraft.server.EntityPotion; import net.minecraft.server.EntitySheep; import net.minecraft.server.EntitySilverfish; import net.minecraft.server.EntitySkeleton; @@ -56,6 +58,7 @@ import org.bukkit.entity.Arrow; import org.bukkit.entity.CreatureType; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; +import org.bukkit.entity.ThrownPotion; import org.bukkit.event.Event.Type; import org.bukkit.event.block.*; import org.bukkit.event.entity.*; @@ -65,6 +68,7 @@ import org.bukkit.event.player.*; import org.bukkit.event.server.ServerListPingEvent; public class CraftEventFactory { + // helper methods private static boolean canBuild(CraftWorld world, Player player, int x, int z) { WorldServer worldServer = world.getHandle(); int spawnSize = Bukkit.getServer().getSpawnRadius(); @@ -321,6 +325,17 @@ public class CraftEventFactory { return event; } + /** + * PotionSplashEvent + */ + public static PotionSplashEvent callPotionSplashEvent(EntityPotion potion, Map affectedEntities) { + ThrownPotion thrownPotion = (ThrownPotion) potion.getBukkitEntity(); + + PotionSplashEvent event = new PotionSplashEvent(thrownPotion, affectedEntities); + Bukkit.getPluginManager().callEvent(event); + return event; + } + /** * BlockFadeEvent */