Added advanced explosion handling from EpicSpawners

This commit is contained in:
Brianna 2019-06-07 13:48:17 -04:00
parent dad0d3e04b
commit 828fdb429f
4 changed files with 88 additions and 43 deletions

View File

@ -3,9 +3,9 @@ package com.songoda.ultimatestacker;
import com.songoda.ultimatestacker.command.CommandManager;
import com.songoda.ultimatestacker.entity.EntityStack;
import com.songoda.ultimatestacker.entity.EntityStackManager;
import com.songoda.ultimatestacker.listeners.*;
import com.songoda.ultimatestacker.hologram.Hologram;
import com.songoda.ultimatestacker.hologram.HologramHolographicDisplays;
import com.songoda.ultimatestacker.listeners.*;
import com.songoda.ultimatestacker.spawner.SpawnerStack;
import com.songoda.ultimatestacker.spawner.SpawnerStackManager;
import com.songoda.ultimatestacker.storage.Storage;
@ -13,13 +13,19 @@ import com.songoda.ultimatestacker.storage.StorageRow;
import com.songoda.ultimatestacker.storage.types.StorageMysql;
import com.songoda.ultimatestacker.storage.types.StorageYaml;
import com.songoda.ultimatestacker.tasks.StackingTask;
import com.songoda.ultimatestacker.utils.*;
import com.songoda.ultimatestacker.utils.ConfigWrapper;
import com.songoda.ultimatestacker.utils.Methods;
import com.songoda.ultimatestacker.utils.Metrics;
import com.songoda.ultimatestacker.utils.ServerVersion;
import com.songoda.ultimatestacker.utils.settings.Setting;
import com.songoda.ultimatestacker.utils.settings.SettingsManager;
import org.apache.commons.lang.ArrayUtils;
import com.songoda.ultimatestacker.utils.updateModules.LocaleModule;
import com.songoda.update.Plugin;
import com.songoda.update.SongodaUpdate;
import org.bukkit.*;
import org.apache.commons.lang.ArrayUtils;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.EntityType;
import org.bukkit.plugin.PluginManager;
@ -161,18 +167,18 @@ public class UltimateStacker extends JavaPlugin {
}, 10);
PluginManager pluginManager = Bukkit.getPluginManager();
if (isServerVersionAtLeast(ServerVersion.V1_10))
Bukkit.getPluginManager().registerEvents(new BreedListeners(this), this);
Bukkit.getPluginManager().registerEvents(new BlockListeners(this), this);
Bukkit.getPluginManager().registerEvents(new DeathListeners(this), this);
Bukkit.getPluginManager().registerEvents(new ShearListeners(this), this);
Bukkit.getPluginManager().registerEvents(new InteractListeners(this), this);
Bukkit.getPluginManager().registerEvents(new EntityListeners(this), this);
Bukkit.getPluginManager().registerEvents(new ItemListeners(this), this);
Bukkit.getPluginManager().registerEvents(new TameListeners(this), this);
Bukkit.getPluginManager().registerEvents(new SheepDyeListeners(this), this);
pluginManager.registerEvents(new BreedListeners(this), this);
pluginManager.registerEvents(new BlockListeners(this), this);
pluginManager.registerEvents(new DeathListeners(this), this);
pluginManager.registerEvents(new ShearListeners(this), this);
pluginManager.registerEvents(new InteractListeners(this), this);
pluginManager.registerEvents(new EntityListeners(this), this);
pluginManager.registerEvents(new ItemListeners(this), this);
pluginManager.registerEvents(new TameListeners(this), this);
pluginManager.registerEvents(new SheepDyeListeners(this), this);
// Register Hologram Plugin
if (getConfig().getBoolean("Spawners.Holograms Enabled")) {
if (Setting.SPAWNER_HOLOGRAMS.getBoolean()) {
if (pluginManager.isPluginEnabled("HolographicDisplays"))
hologram = new HologramHolographicDisplays(this);
}
@ -212,8 +218,7 @@ public class UltimateStacker extends JavaPlugin {
}
public boolean spawnersEnabled() {
if (this.getServer().getPluginManager().isPluginEnabled("EpicSpawners")) return false;
return this.getConfig().getBoolean("Main.Stack Spawners");
return !this.getServer().getPluginManager().isPluginEnabled("EpicSpawners") && Setting.SPAWNERS_ENABLED.getBoolean();
}
public Hologram getHologram() { return hologram; }

View File

@ -6,6 +6,7 @@ import com.songoda.ultimatestacker.entity.EntityStackManager;
import com.songoda.ultimatestacker.spawner.SpawnerStack;
import com.songoda.ultimatestacker.utils.Methods;
import com.songoda.ultimatestacker.utils.ServerVersion;
import com.songoda.ultimatestacker.utils.settings.Setting;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
@ -16,10 +17,10 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class EntityListeners implements Listener {
@ -30,31 +31,6 @@ 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;
if (event.getEntity() instanceof Creeper) {
Methods.onDeath((LivingEntity)event.getEntity(), new ArrayList<>(), 0);
}
List<Block> destroyed = event.blockList();
for (Block block : destroyed) {
if (block.getType() != (instance.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.SPAWNER : Material.valueOf("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);
if (instance.getHologram() == null) return;
instance.getHologram().remove(stack);
}
}
@EventHandler
public void onEgg(ItemSpawnEvent event) {
if (event.getEntity().getItemStack().getType() != Material.EGG) return;
@ -79,4 +55,56 @@ public class EntityListeners implements Listener {
event.getEntity().setItemStack(item);
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlow(EntityExplodeEvent event) {
List<Block> destroyed = event.blockList();
Iterator<Block> it = destroyed.iterator();
List<Block> toCancel = new ArrayList<>();
while (it.hasNext()) {
Block block = it.next();
if (block.getType() != (instance.isServerVersionAtLeast(ServerVersion.V1_13) ? Material.SPAWNER : Material.valueOf("MOB_SPAWNER")))
continue;
Location spawnLocation = block.getLocation();
SpawnerStack spawner = instance.getSpawnerStackManager().getSpawner(block);
if (Setting.SPAWNERS_DONT_EXPLODE.getBoolean())
toCancel.add(block);
else {
String chance = "";
if (event.getEntity() instanceof Creeper)
chance = Setting.EXPLOSION_DROP_CHANCE_TNT.getString();
else if (event.getEntity() instanceof TNTPrimed)
chance = Setting.EXPLOSION_DROP_CHANCE_CREEPER.getString();
int ch = Integer.parseInt(chance.replace("%", ""));
double rand = Math.random() * 100;
if (rand - ch < 0 || ch == 100) {
CreatureSpawner cs = (CreatureSpawner) block.getState();
EntityType blockType = cs.getSpawnedType();
ItemStack item = Methods.getSpawnerItem(blockType, spawner.getAmount());
spawnLocation.getWorld().dropItemNaturally(spawnLocation.clone().add(.5, 0, .5), item);
instance.getSpawnerStackManager().removeSpawner(spawnLocation);
if (instance.getHologram() != null)
instance.getHologram().remove(spawner);
}
}
Location nloc = spawnLocation.clone();
nloc.add(.5, -.4, .5);
List<Entity> near = (List<Entity>) nloc.getWorld().getNearbyEntities(nloc, 8, 8, 8);
for (Entity ee : near) {
if (ee.getLocation().getX() == nloc.getX() && ee.getLocation().getY() == nloc.getY() && ee.getLocation().getZ() == nloc.getZ()) {
ee.remove();
}
}
}
for (Block block : toCancel) {
event.blockList().remove(block);
}
}
}

View File

@ -103,6 +103,18 @@ public enum Setting {
MAX_STACK_SPAWNERS("Spawners.Max Stack Size", 5,
"What should the max a spawner can stack to be?"),
SNEAK_FOR_STACK("Spawners.Sneak To Receive A Stacked Spawner", true,
"Toggle ability to receive a stacked spawner when breaking a spawner while sneaking."),
SPAWNERS_DONT_EXPLODE("Spawners.Prevent Spawners From Exploding", false,
"Should spawners break when blown up?"),
EXPLOSION_DROP_CHANCE_TNT("Spawners.Chance On TNT Explosion", "100%",
"Chance of a TNT explosion dropping a spawner."),
EXPLOSION_DROP_CHANCE_CREEPER("Spawners.Chance On Creeper Explosion", "100%",
"Chance of a creeper explosion dropping a spawner."),
NAME_FORMAT_SPAWNER("Spawners.Name Format", "&f{TYPE} Spawner &6{AMT}x",
"The text displayed above a stacked spawner where {TYPE} refers to",
"The entities type and {AMT} is the amount currently stacked."),

View File

@ -1,7 +1,7 @@
name: UltimateStacker
description: UltimateStacker
version: maven-version-number
softdepend: [Arconix, HolographicDisplays, WorldGuard, EpicSpawners]
softdepend: [HolographicDisplays, WorldGuard, EpicSpawners]
main: com.songoda.ultimatestacker.UltimateStacker
author: songoda
api-version: 1.13