mirror of
https://github.com/songoda/FabledSkyBlock.git
synced 2025-01-10 17:58:03 +01:00
Queue level scans
This commit is contained in:
parent
e205e07910
commit
753f1a9c5e
@ -7,6 +7,7 @@ import me.goodandevil.skyblock.island.Island;
|
||||
import me.goodandevil.skyblock.island.IslandLevel;
|
||||
import me.goodandevil.skyblock.island.IslandManager;
|
||||
import me.goodandevil.skyblock.island.IslandWorld;
|
||||
import me.goodandevil.skyblock.message.MessageManager;
|
||||
import me.goodandevil.skyblock.stackable.Stackable;
|
||||
import me.goodandevil.skyblock.stackable.StackableManager;
|
||||
import me.goodandevil.skyblock.utils.version.Materials;
|
||||
@ -31,9 +32,11 @@ import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Queue;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
|
||||
@ -41,7 +44,8 @@ public class LevellingManager {
|
||||
|
||||
private final SkyBlock skyblock;
|
||||
|
||||
private Set<Island> activeIslandScans = new HashSet<>();
|
||||
private Island activelyScanningIsland = null;
|
||||
private Queue<QueuedIsland> islandsInQueue = new LinkedList<>();
|
||||
private List<LevellingMaterial> materialStorage = new ArrayList<>();
|
||||
|
||||
public LevellingManager(SkyBlock skyblock) {
|
||||
@ -53,17 +57,29 @@ public class LevellingManager {
|
||||
public void calculatePoints(Player player, Island island) {
|
||||
IslandManager islandManager = skyblock.getIslandManager();
|
||||
WorldManager worldManager = skyblock.getWorldManager();
|
||||
MessageManager messageManager = skyblock.getMessageManager();
|
||||
StackableManager stackableManager = skyblock.getStackableManager();
|
||||
|
||||
if (player != null && islandManager.getIslandPlayerAt(player) != island) {
|
||||
String message = ChatColor.translateAlternateColorCodes('&', this.skyblock.getFileManager()
|
||||
.getConfig(new File(this.skyblock.getDataFolder(), "language.yml"))
|
||||
.getFileConfiguration().getString("Command.Island.Level.Scanning.NotOnIsland.Message"));
|
||||
player.sendMessage(message);
|
||||
FileConfiguration languageConfig = this.skyblock.getFileManager().getConfig(new File(this.skyblock.getDataFolder(), "language.yml")).getFileConfiguration();
|
||||
|
||||
if (!this.isIslandLevelBeingScanned(island) && player != null && islandManager.getIslandPlayerAt(player) != island) {
|
||||
messageManager.sendMessage(player, languageConfig.getString("Command.Island.Level.Scanning.NotOnIsland.Message"));
|
||||
return;
|
||||
}
|
||||
|
||||
this.activeIslandScans.add(island);
|
||||
if (this.activelyScanningIsland != null) {
|
||||
this.islandsInQueue.add(new QueuedIsland(player, island));
|
||||
|
||||
String queuedMessage = languageConfig.getString("Command.Island.Level.Scanning.Queued.Message");
|
||||
islandManager.getPlayersAtIsland(island).forEach(x -> messageManager.sendMessage(x, queuedMessage));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
this.activelyScanningIsland = island;
|
||||
|
||||
String nowScanningMessage = languageConfig.getString("Command.Island.Level.Scanning.Started.Message");
|
||||
islandManager.getPlayersAtIsland(island).forEach(x -> messageManager.sendMessage(x, nowScanningMessage));
|
||||
|
||||
Chunk chunk = new Chunk(skyblock, island);
|
||||
chunk.prepareInitial();
|
||||
@ -100,8 +116,10 @@ public class LevellingManager {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!chunk.isReadyToScan()) return;
|
||||
if (!chunk.isReadyToScan())
|
||||
return;
|
||||
|
||||
try {
|
||||
if (chunk.isFinished()) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(skyblock, () -> finalizeMaterials(levellingData, spawnerLocations, epicSpawnerLocations, ultimateStackerSpawnerLocations, player, island), 1);
|
||||
cancel();
|
||||
@ -205,6 +223,9 @@ public class LevellingManager {
|
||||
}
|
||||
|
||||
chunk.prepareNextChunkSnapshots();
|
||||
} catch (Exception ex) {
|
||||
skyblock.getLogger().severe("An error occurred while scanning an island. This is a severe error.");
|
||||
}
|
||||
}
|
||||
}.runTaskTimerAsynchronously(skyblock, 0L, 1L);
|
||||
}
|
||||
@ -282,7 +303,15 @@ public class LevellingManager {
|
||||
}
|
||||
}
|
||||
|
||||
this.activeIslandScans.remove(island);
|
||||
MessageManager messageManager = skyblock.getMessageManager();
|
||||
FileConfiguration languageConfig = this.skyblock.getFileManager().getConfig(new File(this.skyblock.getDataFolder(), "language.yml")).getFileConfiguration();
|
||||
String nowScanningMessage = languageConfig.getString("Command.Island.Level.Scanning.Done.Message");
|
||||
skyblock.getIslandManager().getPlayersAtIsland(island).forEach(x -> messageManager.sendMessage(x, nowScanningMessage));
|
||||
|
||||
this.activelyScanningIsland = null;
|
||||
QueuedIsland nextInQueue = this.islandsInQueue.poll();
|
||||
if (nextInQueue != null)
|
||||
this.calculatePoints(nextInQueue.getPlayer(), nextInQueue.getIsland());
|
||||
}
|
||||
|
||||
public void registerMaterials() {
|
||||
@ -307,7 +336,7 @@ public class LevellingManager {
|
||||
}
|
||||
|
||||
public boolean isIslandLevelBeingScanned(Island island) {
|
||||
return this.activeIslandScans.contains(island);
|
||||
return this.islandsInQueue.stream().anyMatch(x -> x.getIsland() == island) || this.activelyScanningIsland == island;
|
||||
}
|
||||
|
||||
public void unregisterMaterials() {
|
||||
@ -385,4 +414,22 @@ public class LevellingManager {
|
||||
return Materials.getMaterials(this.material, this.data);
|
||||
}
|
||||
}
|
||||
|
||||
private class QueuedIsland {
|
||||
private final Player player;
|
||||
private final Island island;
|
||||
|
||||
public QueuedIsland(Player player, Island island) {
|
||||
this.player = player;
|
||||
this.island = island;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return this.player;
|
||||
}
|
||||
|
||||
public Island getIsland() {
|
||||
return this.island;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -84,6 +84,12 @@ Command:
|
||||
Message: '&bSkyBlock &8| &cError&8: &eYou cannot initiate an Island level scan without being on your Island.'
|
||||
BlockPlacing:
|
||||
Message: '&bSkyBlock &8 | &cError:&8: &eYou cannot place blocks during an Island level scan. Please wait for the scan to finish.'
|
||||
Started:
|
||||
Message: '&bSkyBlock &8| &aInfo&8: &eA level scan has started on this island.'
|
||||
Queued:
|
||||
Message: '&bSkyBlock &8| &aInfo&8: &eA level scan has been &aqueued&e for this island. The scan will start as soon as all other queued scans are complete.'
|
||||
Done:
|
||||
Message: '&bSkyBlock &8| &aInfo&8: &eThe scan has completed.'
|
||||
Cooldown:
|
||||
Word:
|
||||
Minute: minute(s)
|
||||
|
Loading…
Reference in New Issue
Block a user