Prevent mobs from the Mob Bomb doing weird things like catching on 🔥 or 💣
This commit is contained in:
parent
9bd7cb18b2
commit
01f82a7043
@ -4,7 +4,9 @@ import java.text.DecimalFormat;
|
||||
import java.time.Month;
|
||||
import java.time.YearMonth;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.bukkit.Color;
|
||||
@ -20,6 +22,9 @@ import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Sheep;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.EntityCombustEvent;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
import org.bukkit.event.entity.ExplosionPrimeEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
@ -69,6 +74,7 @@ public class ItemMobBomb extends ItemGadget
|
||||
};
|
||||
|
||||
private final Map<Player, MobType> _typeMap;
|
||||
private final Set<LivingEntity> _exploding;
|
||||
|
||||
public ItemMobBomb(GadgetManager manager)
|
||||
{
|
||||
@ -86,6 +92,7 @@ public class ItemMobBomb extends ItemGadget
|
||||
setPPCYearMonth(YearMonth.of(2018, Month.JANUARY));
|
||||
|
||||
_typeMap = new HashMap<>();
|
||||
_exploding = new HashSet<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -150,6 +157,8 @@ public class ItemMobBomb extends ItemGadget
|
||||
entity.setCustomNameVisible(true);
|
||||
entity.setVelocity(location.getDirection());
|
||||
|
||||
_exploding.add(entity);
|
||||
|
||||
Manager.runSyncTimer(new BukkitRunnable()
|
||||
{
|
||||
|
||||
@ -177,6 +186,7 @@ public class ItemMobBomb extends ItemGadget
|
||||
{
|
||||
UtilParticle.PlayParticleToAll(ParticleType.CLOUD, entityLocation, 0.8F, 0.4F, 0.8F, 0, 30, ViewDist.NORMAL);
|
||||
cancel();
|
||||
_exploding.remove(entity);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -216,6 +226,24 @@ public class ItemMobBomb extends ItemGadget
|
||||
item.setVelocity(new Vector((Math.random() - 0.5) / 1.5, Math.random() / 2 + 0.3, (Math.random() - 0.5) / 1.5));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void entityExplode(ExplosionPrimeEvent event)
|
||||
{
|
||||
if (_exploding.contains(event.getEntity()))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void entityCombust(EntityCombustEvent event)
|
||||
{
|
||||
if (_exploding.contains(event.getEntity()))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
private enum MobType
|
||||
{
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user