refactor(core): update all classes for new config system + add tab completion
BREAKING CHANGE: Core classes updated to use new section-based config Updated classes: - Mine.java - uses RegionConfig, BlockConfig, new FillMode - Mines.java - uses new ConfigLoader.ConfigLoadException - MineFileManager.java - creates configs with new system - MineRepository.java - uses new ConfigLoader - MaskScanService.java - uses BlockKey for markers - BukkitBlockSetter.java - uses Map<BlockKey, Double> Handlers updated: - ActionBarHandler.java - uses UIConfig with MiniMessage - MineBlockHandler.java - uses ResetConfig - MineRewardHandler.java - uses RewardConfig - MineResetHandler.java - uses new config sections Commands updated: - MaskCommands.java - updated exception handling Added: - LoMinesTabCompleter.java - Bukkit tab completion for all commands - RegistrationManager.registerTabCompleter() - registers tab completer Removed: - Old ConfigLoaderTest.java (uses deprecated config system) All classes now use: - Type-safe BlockKey instead of String - Section-based config (region, blocks, reset, rewards, ui, teleport) - Duration-based intervals instead of ticks - MiniMessage formatting for action bar
This commit is contained in:
parent
f1060f34d4
commit
8b8b9fee18
16 changed files with 564 additions and 878 deletions
|
|
@ -2,14 +2,16 @@ package dev.loki.lomines.handler;
|
|||
|
||||
import dev.loki.lomines.LoMinesPlugin;
|
||||
import dev.loki.lomines.core.Mine;
|
||||
import dev.loki.lomines.data.config.FillMode;
|
||||
import dev.loki.lomines.data.config.block.FillMode;
|
||||
import dev.loki.lomines.util.location.Cuboid;
|
||||
import dev.loki.lomines.util.location.LocationParser;
|
||||
import dev.lolib.scheduler.Scheduler;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
|
@ -25,6 +27,8 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||
* <li>Wait for all regions to complete</li>
|
||||
* <li>Execute post-reset actions in main thread</li>
|
||||
* </ol>
|
||||
*
|
||||
* <p>Updated for new configuration system (v2).</p>
|
||||
*/
|
||||
public final class MineResetHandler {
|
||||
|
||||
|
|
@ -71,12 +75,20 @@ public final class MineResetHandler {
|
|||
return;
|
||||
}
|
||||
|
||||
if (mine.getConfig().getFillMode() == FillMode.MASK) {
|
||||
mine.getBlockSetter().fillAtLocations(mine.getConfig().getMaskPositions(), placed ->
|
||||
// Handle MASK fill mode
|
||||
if (mine.getConfig().blocks().fillMode() == FillMode.MASK) {
|
||||
List<Location> maskPositions = getMaskPositions();
|
||||
if (maskPositions.isEmpty()) {
|
||||
plugin.loLogger().warn("No mask positions found for mine " + mine.getName());
|
||||
running.set(false);
|
||||
return;
|
||||
}
|
||||
mine.getBlockSetter().fillAtLocations(maskPositions, placed ->
|
||||
Scheduler.get(plugin).run(() -> onResetComplete(placed, silent)));
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle CUBOID fill mode
|
||||
for (Cuboid region : regions) {
|
||||
mine.getBlockSetter().fill(region, blocksSet -> {
|
||||
totalBlocks.addAndGet(blocksSet);
|
||||
|
|
@ -90,6 +102,29 @@ public final class MineResetHandler {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets mask positions from config.
|
||||
*/
|
||||
private List<Location> getMaskPositions() {
|
||||
List<Location> positions = new ArrayList<>();
|
||||
var mask = mine.getConfig().blocks().mask();
|
||||
if (mask == null) {
|
||||
return positions;
|
||||
}
|
||||
|
||||
for (String posStr : mask.positions().keySet()) {
|
||||
try {
|
||||
Location loc = LocationParser.parse(posStr);
|
||||
if (loc != null) {
|
||||
positions.add(loc);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
plugin.loLogger().warn("Invalid mask position in mine " + mine.getName() + ": " + posStr);
|
||||
}
|
||||
}
|
||||
return positions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when all regions have been filled.
|
||||
* Executes post-reset actions in the main thread.
|
||||
|
|
@ -104,7 +139,7 @@ public final class MineResetHandler {
|
|||
broadcastReset();
|
||||
}
|
||||
|
||||
if (mine.getConfig().isTeleportOnReset()) {
|
||||
if (mine.getConfig().teleport().enabled()) {
|
||||
teleportPlayers();
|
||||
}
|
||||
|
||||
|
|
@ -115,7 +150,7 @@ public final class MineResetHandler {
|
|||
* Executes commands configured for reset.
|
||||
*/
|
||||
private void executeResetCommands() {
|
||||
List<String> commands = mine.getConfig().getResetCommands();
|
||||
List<String> commands = mine.getConfig().reset().commands();
|
||||
for (String command : commands) {
|
||||
String parsed = command.replace("%mine%", mine.getName());
|
||||
plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), parsed);
|
||||
|
|
@ -126,7 +161,7 @@ public final class MineResetHandler {
|
|||
* Broadcasts reset message to players.
|
||||
*/
|
||||
private void broadcastReset() {
|
||||
String message = mine.getConfig().getBroadcastReset();
|
||||
String message = mine.getConfig().reset().broadcastMessage();
|
||||
if (message != null && !message.isEmpty()) {
|
||||
String formatted = message.replace("%mine%", mine.getName());
|
||||
Component component = MiniMessage.miniMessage().deserialize(formatted);
|
||||
|
|
@ -138,8 +173,12 @@ public final class MineResetHandler {
|
|||
* Teleports players standing inside the mine to the configured location.
|
||||
*/
|
||||
private void teleportPlayers() {
|
||||
Location dest = mine.getConfig().getTeleportLocation();
|
||||
if (dest == null || dest.getWorld() == null) {
|
||||
var destOpt = mine.getConfig().teleport().getLocation();
|
||||
if (destOpt.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
Location dest = destOpt.get();
|
||||
if (dest.getWorld() == null) {
|
||||
return;
|
||||
}
|
||||
for (Player p : dest.getWorld().getPlayers()) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue