Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Stacker Support #812

Closed
wants to merge 12 commits into from
3 changes: 1 addition & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@ dependencies {
implementation("org.jetbrains:annotations:24.1.0")
implementation("com.j256.ormlite:ormlite-core:6.1")
implementation("com.j256.ormlite:ormlite-jdbc:6.1")
implementation("com.iridium:IridiumTeams:2.4.2")
implementation("com.iridium:IridiumTeams:2.4.3")

// Other dependencies that are not required or already available at runtime
compileOnly("org.projectlombok:lombok:1.18.32")
compileOnly("org.spigotmc:spigot-api:1.20.6-R0.1-SNAPSHOT")
compileOnly("com.github.MilkBowl:VaultAPI:1.7.1")
compileOnly("net.ess3:EssentialsXSpawn:2.16.1")
compileOnly("com.sk89q.worldedit:worldedit-bukkit:7.2.13-SNAPSHOT")

// Enable lombok annotation processing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.iridium.iridiumteams.IridiumTeams;
import com.iridium.iridiumteams.managers.MissionManager;
import com.iridium.iridiumteams.managers.ShopManager;
import com.iridium.iridiumteams.managers.SupportManager;
import lombok.Getter;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
Expand Down Expand Up @@ -62,6 +63,7 @@ public class IridiumSkyblock extends IridiumTeams<Island, User> {
private SchematicManager schematicManager;
private ShopManager<Island, User> shopManager;
private BiomeManager biomeManager;
private SupportManager<Island, User> supportManager;

private Economy economy;

Expand Down Expand Up @@ -99,6 +101,10 @@ public void onEnable() {
this.missionManager = new MissionManager<>(this);
this.shopManager = new ShopManager<>(this);
this.biomeManager = new BiomeManager();
this.supportManager = new SupportManager<>(this);

supportManager.registerSupport();

try {
databaseManager.init();
} catch (SQLException exception) {
Expand Down Expand Up @@ -140,6 +146,7 @@ public void registerListeners() {
Bukkit.getPluginManager().registerEvents(new PlayerTeleportListener(), this);
Bukkit.getPluginManager().registerEvents(new PlayerPortalListener(), this);
Bukkit.getPluginManager().registerEvents(new PlayerInteractListener(), this);
Bukkit.getPluginManager().registerEvents(new PlayerRespawnEventListener(), this);
Bukkit.getPluginManager().registerEvents(new EntityDamageListener(), this);
if(!XMaterial.supports(15)) Bukkit.getPluginManager().registerEvents(new PortalCreateListener(), this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public Configuration() {
public boolean clearEnderChestOnRegen = false;
public boolean allowPvPOnIslands = false;
public boolean islandCreateOnJoin = false;
public boolean spawnOnIsland = false;
public int distance = 151;
public int netherUnlockLevel = 10;
public int endUnlockLevel = 20;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,8 @@ public class PlayerInteractListener implements Listener {
@EventHandler(ignoreCancelled = true)
public void onClick(PlayerInteractEvent event) {
Player player = event.getPlayer();
User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
ItemStack itemInHand = player.getInventory().getItemInMainHand();

Optional<Island> island = IridiumSkyblock.getInstance().getTeamManager().getTeamViaLocation(event.getClickedBlock().getLocation());
if (!island.isPresent()) return;
if (!IridiumSkyblock.getInstance().getTeamManager().getTeamPermission(island.get(), user, PermissionType.BLOCK_BREAK)) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotBreakBlocks
.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)
));
return;
}

if (IridiumSkyblock.getInstance().getConfiguration().obsidianBucket
&& event.getAction().equals(Action.RIGHT_CLICK_BLOCK)
&& event.getClickedBlock().getType().equals(Material.OBSIDIAN)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.iridium.iridiumskyblock.listeners;

import com.iridium.iridiumskyblock.IridiumSkyblock;
import com.iridium.iridiumskyblock.utils.PlayerUtils;
import lombok.AllArgsConstructor;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerRespawnEvent;

@AllArgsConstructor
public class PlayerRespawnEventListener implements Listener {

@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerRespawnEvent(PlayerRespawnEvent event) {

if(!IridiumSkyblock.getInstance().getConfiguration().spawnOnIsland) { return; }
if(!event.isBedSpawn() && !event.isAnchorSpawn()) event.setRespawnLocation(PlayerUtils.getSpawn(event.getPlayer()));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.iridium.iridiumskyblock.managers;

import com.iridium.iridiumcore.dependencies.xseries.XBiome;
import com.iridium.iridiumcore.dependencies.commons.lang3.text.WordUtils;
import com.iridium.iridiumcore.utils.StringUtils;
import com.iridium.iridiumskyblock.IridiumSkyblock;
import com.iridium.iridiumskyblock.configs.Biomes;
Expand All @@ -9,7 +10,7 @@
import com.iridium.iridiumteams.database.IridiumUser;
import com.iridium.iridiumteams.database.TeamBank;
import net.milkbowl.vault.economy.Economy;
import org.apache.commons.lang.WordUtils;

import org.bukkit.entity.Player;

import java.util.Optional;
Expand Down Expand Up @@ -55,8 +56,8 @@ public void buy(Player player, Biomes.BiomeItem biomeItem) {
.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)
.replace("%player%", player.getName())
.replace("%biome%", WordUtils.capitalizeFully(biome.toString().toLowerCase().replace("_", " ")))
));
}
));
}
});
IridiumSkyblock.getInstance().getBiomes().successSound.play(player);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,16 @@
import com.iridium.iridiumteams.missions.Mission;
import com.iridium.iridiumteams.missions.MissionData;
import com.iridium.iridiumteams.missions.MissionType;
import org.bukkit.*;
import com.iridium.iridiumteams.support.SpawnerSupport;
import com.iridium.iridiumteams.support.StackerSupport;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.WorldCreator;
import org.bukkit.Chunk;
import org.bukkit.ChunkSnapshot;
import org.bukkit.OfflinePlayer;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.CreatureSpawner;
Expand All @@ -40,7 +49,6 @@
import org.jetbrains.annotations.Nullable;

import java.io.File;
import java.io.IOException;
import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.CompletableFuture;
Expand Down Expand Up @@ -463,33 +471,77 @@ public synchronized TeamEnhancement getTeamEnhancement(Island island, String enh
public CompletableFuture<Void> recalculateTeam(Island island) {
Map<XMaterial, Integer> teamBlocks = new HashMap<>();
Map<EntityType, Integer> teamSpawners = new HashMap<>();

HashSet<StackerSupport> stackerSupportList = IridiumSkyblock.getInstance().getSupportManager().getStackerSupport();
HashSet<SpawnerSupport> spawnerSupportList = IridiumSkyblock.getInstance().getSupportManager().getSpawnerSupport();

HashMap<String, List<Block>> stackedBlocksList = new HashMap<>();
for(StackerSupport stackerSupport : stackerSupportList)
stackedBlocksList.put(stackerSupport.supportProvider(), new ArrayList<>());

Map<String, List<CreatureSpawner>> stackedSpawnersList = new HashMap<>();
for(SpawnerSupport spawnerSupport : spawnerSupportList)
stackedSpawnersList.put(spawnerSupport.supportProvider(), new ArrayList<>());


List<Material> ignoreAirBlocks = Arrays.asList(Material.AIR, Material.CAVE_AIR, Material.VOID_AIR);

return CompletableFuture.runAsync(() -> {
List<Chunk> chunks = getIslandChunks(island).join();

for (Chunk chunk : chunks) {
ChunkSnapshot chunkSnapshot = chunk.getChunkSnapshot(true, false, false);
World currentWorld = Bukkit.getWorld(chunkSnapshot.getWorldName());

int minY = currentWorld.getMinHeight();

for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
final int maxy = chunkSnapshot.getHighestBlockYAt(x, z);
for (int y = 0; y <= maxy; y++) {
final int maxY = chunkSnapshot.getHighestBlockYAt(x, z);
for (int y = minY; y <= maxY; y++) {
if (island.isInIsland(x + (chunkSnapshot.getX() * 16), z + (chunkSnapshot.getZ() * 16))) {
XMaterial material = XMaterial.matchXMaterial(chunkSnapshot.getBlockType(x, y, z));

Material blockType = chunkSnapshot.getBlockType(x, y, z);
if(ignoreAirBlocks.contains(blockType)) continue;

XMaterial material = XMaterial.matchXMaterial(blockType);
teamBlocks.put(material, teamBlocks.getOrDefault(material, 0) + 1);
}
}
}
}

getSpawners(chunk, island).join().forEach(creatureSpawner ->
teamSpawners.put(creatureSpawner.getSpawnedType(), teamSpawners.getOrDefault(creatureSpawner.getSpawnedType(), 0) + 1)
teamSpawners.put(creatureSpawner.getSpawnedType(), teamSpawners.getOrDefault(creatureSpawner.getSpawnedType(), 0) + 1)
);

for(StackerSupport stackerSupport : stackerSupportList) {
stackedBlocksList.get(stackerSupport.supportProvider()).addAll(stackerSupport.getBlocksStacked(chunk));
}

for(SpawnerSupport spawnerSupport : spawnerSupportList) {
stackedSpawnersList.get(spawnerSupport.supportProvider()).addAll(spawnerSupport.getSpawnersStacked(chunk));
}

}
}).thenRun(() -> Bukkit.getScheduler().runTask(IridiumSkyblock.getInstance(), () -> {
List<TeamBlock> blocks = IridiumSkyblock.getInstance().getDatabaseManager().getTeamBlockTableManager().getEntries(island);
List<TeamSpawners> spawners = IridiumSkyblock.getInstance().getDatabaseManager().getTeamSpawnerTableManager().getEntries(island);
for (TeamBlock teamBlock : blocks) {
teamBlock.setAmount(teamBlocks.getOrDefault(teamBlock.getXMaterial(), 0));

for(TeamBlock teamBlock : blocks.stream().filter(teamBlock -> teamBlocks.containsKey(teamBlock.getXMaterial())).collect(Collectors.toList())) {
int stackedBlocks = 0;
for(StackerSupport stackerSupport : stackerSupportList) {
stackedBlocks += stackerSupport.getExtraBlocks(island, teamBlock.getXMaterial(), stackedBlocksList.get(stackerSupport.supportProvider()));
}
teamBlock.setAmount(teamBlocks.getOrDefault(teamBlock.getXMaterial(), 0) + stackedBlocks);
}
for (TeamSpawners teamSpawner : spawners) {
teamSpawner.setAmount(teamSpawners.getOrDefault(teamSpawner.getEntityType(), 0));

for(TeamSpawners teamSpawner : spawners.stream().filter(teamSpawner -> teamSpawners.containsKey(teamSpawner.getEntityType())).collect(Collectors.toList())) {
int stackedSpawners = 0;
for(SpawnerSupport spawnerSupport : spawnerSupportList) {
stackedSpawners += spawnerSupport.getExtraSpawners(island, teamSpawner.getEntityType(), stackedSpawnersList.get(spawnerSupport.supportProvider()));
}
teamSpawner.setAmount(teamSpawners.getOrDefault(teamSpawner.getEntityType(), 0) + stackedSpawners);
}
}));
}
Expand Down Expand Up @@ -642,6 +694,11 @@ public void deleteTeamReward(TeamReward teamReward) {
return null;
}

@Override
public boolean isInTeam(Island island, Location location){
return island.isInIsland(location);
}

public boolean isInSkyblockWorld(World world) {
if(world == null) return false;
return world.getName().equals(getWorldName(World.Environment.NORMAL)) || world.getName().equals(getWorldName(World.Environment.NETHER)) || world.getName().equals(getWorldName(World.Environment.THE_END));
Expand Down
40 changes: 27 additions & 13 deletions src/main/java/com/iridium/iridiumskyblock/utils/PlayerUtils.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,40 @@
package com.iridium.iridiumskyblock.utils;

import com.earth2me.essentials.Essentials;
import com.earth2me.essentials.spawn.EssentialsSpawn;
import com.iridium.iridiumskyblock.IridiumSkyblock;
import com.iridium.iridiumskyblock.database.Island;
import com.iridium.iridiumteams.support.SpawnSupport;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;

import java.util.Optional;

public class PlayerUtils {

public static void teleportSpawn(Player player) {
World spawnWorld = Bukkit.getWorld(IridiumSkyblock.getInstance().getConfiguration().spawnWorldName);
if (spawnWorld == null) {
spawnWorld = Bukkit.getWorlds().get(0);
player.teleport(getSpawn(player));
}

public static Location getSpawn(Player player) {

if(IridiumSkyblock.getInstance().getConfiguration().spawnOnIsland) {
Optional<Island> island = IridiumSkyblock.getInstance().getTeamManager().getTeamViaNameOrPlayer(player.getName());
if(island.isPresent()) {
return island.get().getHome();
}
}

EssentialsSpawn essentialsSpawn = (EssentialsSpawn) Bukkit.getPluginManager().getPlugin("EssentialsSpawn");
Essentials essentials = (Essentials) Bukkit.getPluginManager().getPlugin("Essentials");
if (essentialsSpawn != null && essentials != null) {
player.teleport(essentialsSpawn.getSpawn(essentials.getUser(player).getGroup()));
} else {
player.teleport(spawnWorld.getSpawnLocation());
for(SpawnSupport spawnSupport : IridiumSkyblock.getInstance().getSupportManager().getSpawnSupport()) {
return spawnSupport.getSpawn(player);
}

World spawnWorld = Bukkit.getWorld(IridiumSkyblock.getInstance().getConfiguration().spawnWorldName);
if (spawnWorld != null) {
return spawnWorld.getSpawnLocation();
}
}

}
return Bukkit.getWorlds().get(0).getSpawnLocation();
}
}
1 change: 1 addition & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ softdepend:
- "EssentialsSpawn"
- "RoseStacker"
- "WorldEdit"
- "ObsidianStacker"
loadbefore:
- "Multiverse-Core"
commands:
Expand Down
Loading