support for exploding spawners

This commit is contained in:
Brianna O'Keefe 2018-12-02 21:14:40 -05:00
parent 8d9a478c66
commit dbd8d01917
2 changed files with 32 additions and 1 deletions

View File

@ -5,7 +5,7 @@ variables:
name: "UltimateStacker" name: "UltimateStacker"
suffex: "Legacy" suffex: "Legacy"
path: "/builds/Songoda/$name" path: "/builds/Songoda/$name"
version: "1.0.9" version: "1.0.10"
build: build:
stage: build stage: build

View File

@ -1,11 +1,23 @@
package com.songoda.ultimatestacker.events; package com.songoda.ultimatestacker.events;
import com.songoda.ultimatestacker.UltimateStacker; 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.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.player.PlayerPickupItemEvent; import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import java.util.List;
public class EntityListeners implements Listener { public class EntityListeners implements Listener {
private final UltimateStacker instance; private final UltimateStacker instance;
@ -14,6 +26,25 @@ public class EntityListeners implements Listener {
this.instance = instance; 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<Block> 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 @EventHandler
public void onPickup(PlayerPickupItemEvent event) { public void onPickup(PlayerPickupItemEvent event) {
event.getItem().setItemStack(instance.getStackingTask().setMax(event.getItem().getItemStack(), 0, true)); event.getItem().setItemStack(instance.getStackingTask().setMax(event.getItem().getItemStack(), 0, true));