From dbd8d01917ceac9dd706a7233d09bcd5a000f549 Mon Sep 17 00:00:00 2001 From: Brianna O'Keefe Date: Sun, 2 Dec 2018 21:14:40 -0500 Subject: [PATCH] support for exploding spawners --- .gitlab-ci.yml | 2 +- .../events/EntityListeners.java | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 18b8218..6ef30a1 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -5,7 +5,7 @@ variables: name: "UltimateStacker" suffex: "Legacy" path: "/builds/Songoda/$name" - version: "1.0.9" + version: "1.0.10" build: stage: build diff --git a/src/main/java/com/songoda/ultimatestacker/events/EntityListeners.java b/src/main/java/com/songoda/ultimatestacker/events/EntityListeners.java index d1614f7..3f3255c 100644 --- a/src/main/java/com/songoda/ultimatestacker/events/EntityListeners.java +++ b/src/main/java/com/songoda/ultimatestacker/events/EntityListeners.java @@ -1,11 +1,23 @@ package com.songoda.ultimatestacker.events; import com.songoda.ultimatestacker.UltimateStacker; +import com.songoda.ultimatestacker.spawner.SpawnerStack; +import com.songoda.ultimatestacker.utils.Methods; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.CreatureSpawner; +import org.bukkit.entity.Creeper; +import org.bukkit.entity.TNTPrimed; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.player.PlayerPickupItemEvent; import org.bukkit.inventory.ItemStack; +import java.util.List; + public class EntityListeners implements Listener { private final UltimateStacker instance; @@ -14,6 +26,25 @@ public class EntityListeners implements Listener { this.instance = instance; } + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onBlow(EntityExplodeEvent event) { + if (!(event.getEntity() instanceof Creeper) && !(event.getEntity() instanceof TNTPrimed)) return; + + List destroyed = event.blockList(); + for (Block block : destroyed) { + + if (block.getType() != Material.MOB_SPAWNER) continue; + Location spawnerLocation = block.getLocation(); + + SpawnerStack stack = instance.getSpawnerStackManager().getSpawner(spawnerLocation); + + ItemStack item = Methods.getSpawnerItem(((CreatureSpawner) block.getState()).getSpawnedType(), stack.getAmount()); + spawnerLocation.getWorld().dropItemNaturally(spawnerLocation.clone().add(.5, 0, .5), item); + + instance.getHologramHandler().despawn(spawnerLocation.getBlock()); + } + } + @EventHandler public void onPickup(PlayerPickupItemEvent event) { event.getItem().setItemStack(instance.getStackingTask().setMax(event.getItem().getItemStack(), 0, true));