UltimateStacker spawner stacking in island levelling

This commit is contained in:
Esophose 2019-06-05 03:50:07 -06:00
parent 965170b23f
commit 3ea184fe69
4 changed files with 115 additions and 3 deletions

View File

@ -36,6 +36,9 @@ dependencies {
// EpicAnchors
implementation (group: 'com.songoda', name: 'epicanchors', version: '1.2.5')
// UltimateStacker
implementation (group: 'com.songoda', name: 'ultimatestacker', version: '1.3.1')
// WildStacker
implementation (group: 'com.bgsoftware', name: 'wildstacker-api', version: 'b15')

View File

@ -85,10 +85,12 @@ public class LevellingManager {
int worldMaxHeight = height;
boolean isEpicSpawnersEnabled = Bukkit.getPluginManager().isPluginEnabled("EpicSpawners");
boolean isUltimateStackerEnabled = Bukkit.getPluginManager().isPluginEnabled("UltimateStacker");
Map<LevellingData, Long> levellingData = new HashMap<>();
Set<Location> spawnerLocations = new HashSet<>(); // These have to be checked synchronously :(
Set<Location> epicSpawnerLocations = new HashSet<>();
Set<Location> ultimateStackerSpawnerLocations = new HashSet<>();
List<Material> blacklistedMaterials = new ArrayList<>();
blacklistedMaterials.add(Materials.AIR.getPostMaterial());
@ -103,7 +105,7 @@ public class LevellingManager {
if (!chunk.isReadyToScan()) return;
if (chunk.isFinished()) {
Bukkit.getScheduler().scheduleSyncDelayedTask(skyblock, () -> finalizeMaterials(levellingData, spawnerLocations, epicSpawnerLocations, player, island), 1);
Bukkit.getScheduler().scheduleSyncDelayedTask(skyblock, () -> finalizeMaterials(levellingData, spawnerLocations, epicSpawnerLocations, ultimateStackerSpawnerLocations, player, island), 1);
cancel();
return;
}
@ -166,6 +168,11 @@ public class LevellingManager {
epicSpawnerLocations.add(location);
continue;
}
} else if (isUltimateStackerEnabled) {
com.songoda.ultimatestacker.spawner.SpawnerStack spawnerStack = com.songoda.ultimatestacker.UltimateStacker.getInstance().getSpawnerStackManager().getSpawner(location);
if (spawnerStack != null)
ultimateStackerSpawnerLocations.add(location);
continue;
}
if (chunkSnapshotList.hasWildStackerData()) {
@ -225,7 +232,7 @@ public class LevellingManager {
}.runTaskTimerAsynchronously(skyblock, 0L, 1L);
}
private void finalizeMaterials(Map<LevellingData, Long> levellingData, Set<Location> spawnerLocations, Set<Location> epicSpawnerLocations, Player player, Island island) {
private void finalizeMaterials(Map<LevellingData, Long> levellingData, Set<Location> spawnerLocations, Set<Location> epicSpawnerLocations, Set<Location> ultimateStackerSpawnerLocations, Player player, Island island) {
for (Location location : spawnerLocations) {
if (!(location.getBlock().getState() instanceof CreatureSpawner))
continue;
@ -256,6 +263,20 @@ public class LevellingManager {
}
}
for (Location location : ultimateStackerSpawnerLocations) {
com.songoda.ultimatestacker.spawner.SpawnerStack spawnerStack = com.songoda.ultimatestacker.UltimateStacker.getInstance().getSpawnerStackManager().getSpawner(location);
if (spawnerStack == null)
continue;
int amount = spawnerStack.getAmount();
EntityType spawnerType = ((CreatureSpawner) location.getBlock().getState()).getSpawnedType();
LevellingData data = new LevellingData(Materials.SPAWNER.parseMaterial(), (byte) 0, spawnerType);
Long totalAmountInteger = levellingData.get(data);
long totalAmount = totalAmountInteger == null ? amount : totalAmountInteger + amount;
levellingData.put(data, totalAmount);
}
Map<String, Long> materials = new HashMap<>();
for (LevellingData data : levellingData.keySet()) {
long amount = levellingData.get(data);

View File

@ -0,0 +1,88 @@
package me.goodandevil.skyblock.listeners;
import com.songoda.ultimatestacker.events.SpawnerBreakEvent;
import com.songoda.ultimatestacker.events.SpawnerPlaceEvent;
import me.goodandevil.skyblock.SkyBlock;
import me.goodandevil.skyblock.config.FileManager;
import me.goodandevil.skyblock.island.Island;
import me.goodandevil.skyblock.island.IslandLevel;
import me.goodandevil.skyblock.island.IslandManager;
import me.goodandevil.skyblock.utils.version.Materials;
import me.goodandevil.skyblock.world.WorldManager;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.event.EventHandler;
import java.io.File;
public class UltimateStacker {
private final SkyBlock skyblock;
public UltimateStacker(SkyBlock skyblock) {
this.skyblock = skyblock;
}
@EventHandler
public void onSpawnerPlace(SpawnerPlaceEvent event) {
Bukkit.getScheduler().scheduleSyncDelayedTask(SkyBlock.getInstance(), () -> {
IslandManager islandManager = skyblock.getIslandManager();
WorldManager worldManager = skyblock.getWorldManager();
Location location = event.getBlock().getLocation();
if (!worldManager.isIslandWorld(location.getWorld())) return;
Island island = islandManager.getIslandAtLocation(location);
FileManager.Config config = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml"));
FileConfiguration configLoad = config.getFileConfiguration();
if (configLoad.getBoolean("Island.Block.Level.Enable")) {
Materials materials = Materials.getSpawner(event.getSpawnerType());
if (materials != null) {
IslandLevel level = island.getLevel();
long materialAmount = 0;
if (level.hasMaterial(materials.name())) {
materialAmount = level.getMaterialAmount(materials.name());
}
level.setMaterialAmount(materials.name(), materialAmount + event.getAmount());
}
}
});
}
@EventHandler
public void onSpawnerBreak(SpawnerBreakEvent event) {
IslandManager islandManager = skyblock.getIslandManager();
WorldManager worldManager = skyblock.getWorldManager();
Location location = event.getBlock().getLocation();
if (!worldManager.isIslandWorld(location.getWorld())) return;
Island island = islandManager.getIslandAtLocation(location);
FileManager.Config config = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml"));
FileConfiguration configLoad = config.getFileConfiguration();
if (configLoad.getBoolean("Island.Block.Level.Enable")) {
Materials materials = Materials.getSpawner(event.getSpawnerType());
if (materials != null) {
IslandLevel level = island.getLevel();
if (level.hasMaterial(materials.name())) {
long materialAmount = level.getMaterialAmount(materials.name());
if (materialAmount - event.getAmount() <= 0) {
level.removeMaterial(materials.name());
} else {
level.setMaterialAmount(materials.name(), materialAmount - event.getAmount());
}
}
}
}
}
}

View File

@ -4,7 +4,7 @@ version: @version@
api-version: 1.13
description: A unique SkyBlock plugin
author: Songoda
softdepend: [PlaceholderAPI, MVdWPlaceholderAPI, Vault, LeaderHeads, EpicSpawners, WildStacker, WorldEdit]
softdepend: [PlaceholderAPI, MVdWPlaceholderAPI, Vault, LeaderHeads, EpicSpawners, WildStacker, UltimateStacker, WorldEdit]
loadbefore: [Multiverse-Core]
commands:
island: