refactor: split MineConfig and Mines classes (291→182, 247→157 lines)

- Extract MineConfig.Builder → MineConfigBuilder (separate file)
- Split Mines into 3 services:
  * MineFileManager - file operations
  * MineRepository - CRUD operations
  * MaskScanService - mask scanning logic
- Fix imports: data.* → data.config.*

Progress: 2/7 files >200 lines fixed
This commit is contained in:
loki5512344 2026-04-24 10:31:43 +02:00
parent 14daef3a9f
commit 1e29889902
11 changed files with 467 additions and 301 deletions

View file

@ -2,7 +2,7 @@ package com.loki.lomines.command;
import com.loki.lomines.LoMinesPlugin; import com.loki.lomines.LoMinesPlugin;
import com.loki.lomines.core.Mines; import com.loki.lomines.core.Mines;
import com.loki.lomines.data.ConfigParseException; import com.loki.lomines.data.config.ConfigParseException;
import dev.lolib.commands.annotation.Arg; import dev.lolib.commands.annotation.Arg;
import dev.lolib.commands.annotation.Command; import dev.lolib.commands.annotation.Command;
import dev.lolib.commands.annotation.Subcommand; import dev.lolib.commands.annotation.Subcommand;

View file

@ -0,0 +1,50 @@
package com.loki.lomines.core;
import com.loki.lomines.data.config.ConfigParseException;
import com.loki.lomines.util.location.Cuboid;
import com.loki.lomines.util.selection.MaskScanner;
import org.bukkit.Location;
import org.bukkit.Material;
import java.io.IOException;
import java.util.List;
/**
* Service for scanning and saving mask positions.
*/
final class MaskScanService {
private final MineRepository repository;
private final MineFileManager fileManager;
MaskScanService(MineRepository repository, MineFileManager fileManager) {
this.repository = repository;
this.fileManager = fileManager;
}
int scanAndSave(String mineName) throws IOException, ConfigParseException {
Mine mine = repository.get(mineName);
Material marker = parseMarkerMaterial(mine.getConfig().getMaskMarkerMaterial());
List<Cuboid> regions = mine.getRegions();
List<Location> found = MaskScanner.scan(regions, marker);
fileManager.saveMaskPositions(
mineName,
mine.getConfig().getMaskMarkerMaterial(),
found
);
repository.reload(mineName);
return found.size();
}
private Material parseMarkerMaterial(String materialName) {
try {
return Material.valueOf(materialName.toUpperCase());
} catch (IllegalArgumentException e) {
return Material.PINK_CONCRETE;
}
}
}

View file

@ -3,7 +3,7 @@ package com.loki.lomines.core;
import com.loki.lomines.LoMinesPlugin; import com.loki.lomines.LoMinesPlugin;
import com.loki.lomines.block.BlockSetter; import com.loki.lomines.block.BlockSetter;
import com.loki.lomines.data.FillMode; import com.loki.lomines.data.FillMode;
import com.loki.lomines.data.MineConfig; import com.loki.lomines.data.config.MineConfig;
import com.loki.lomines.util.BlockKeys; import com.loki.lomines.util.BlockKeys;
import com.loki.lomines.handler.ActionBarHandler; import com.loki.lomines.handler.ActionBarHandler;
import com.loki.lomines.handler.MineBlockHandler; import com.loki.lomines.handler.MineBlockHandler;

View file

@ -0,0 +1,100 @@
package com.loki.lomines.core;
import com.loki.lomines.data.config.ConfigLoader;
import com.loki.lomines.data.config.ConfigParseException;
import com.loki.lomines.data.config.MineConfig;
import com.loki.lomines.util.location.LocationParser;
import org.bukkit.Location;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* Handles file operations for mine configurations.
*/
final class MineFileManager {
private final Path minesFolder;
MineFileManager(Path minesFolder) {
this.minesFolder = minesFolder;
}
void ensureFolderExists() throws IOException {
if (!Files.exists(minesFolder)) {
Files.createDirectories(minesFolder);
}
}
void createDefaultConfig(String name, Location corner1, Location corner2) throws IOException {
Path configFile = minesFolder.resolve(name + ".yml");
YamlConfiguration yaml = new YamlConfiguration();
if (corner1 != null && corner2 != null) {
yaml.set("selection.1", LocationParser.format(corner1));
yaml.set("selection.2", LocationParser.format(corner2));
} else {
yaml.set("selection.1", "world;0;64;0;0;0");
yaml.set("selection.2", "world;10;74;10;0;0");
}
yaml.set("contents.stone", 100.0);
yaml.set("reset.ticks", 6000);
yaml.set("reset.percent", 10.0);
yaml.set("reset-on-percent", false);
yaml.set("actionbar.enabled", true);
yaml.set("actionbar.message", "&aMine: %mine% | Blocks: %blocks%/%total% (%percent%%)");
yaml.set("actionbar.range", 50.0);
yaml.set("timer-format", "mm:ss");
yaml.set("teleport-on-reset", false);
yaml.set("broadcast-reset", "");
yaml.set("reset-commands", new ArrayList<String>());
yaml.set("random-rewards", new ArrayList<Map<String, Object>>());
yaml.set("fill-mode", "cuboid");
yaml.set("mask.marker", "pink_concrete");
yaml.set("mask.positions", new ArrayList<String>());
yaml.save(configFile.toFile());
}
MineConfig loadConfig(String name) throws IOException, ConfigParseException {
Path configFile = minesFolder.resolve(name + ".yml");
if (!Files.exists(configFile)) {
throw new IOException("Mine config not found: " + configFile);
}
ConfigLoader loader = new ConfigLoader();
return loader.load(configFile);
}
void deleteConfig(String name) throws IOException {
Path configFile = minesFolder.resolve(name + ".yml");
if (Files.exists(configFile)) {
Files.delete(configFile);
}
}
void saveMaskPositions(String name, String markerMaterial, List<Location> positions) throws IOException {
Path configFile = minesFolder.resolve(name + ".yml");
YamlConfiguration yaml = YamlConfiguration.loadConfiguration(configFile.toFile());
yaml.set("fill-mode", "mask");
yaml.set("mask.marker", markerMaterial);
List<String> lines = new ArrayList<>();
for (Location loc : positions) {
lines.add(LocationParser.format(loc));
}
yaml.set("mask.positions", lines);
yaml.save(configFile.toFile());
}
Path getMinesFolder() {
return minesFolder;
}
}

View file

@ -0,0 +1,87 @@
package com.loki.lomines.core;
import com.loki.lomines.LoMinesPlugin;
import com.loki.lomines.data.config.ConfigParseException;
import com.loki.lomines.data.config.MineConfig;
import org.bukkit.Location;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
/**
* Repository for managing mine instances.
*/
final class MineRepository {
private final Map<String, Mine> mines = new ConcurrentHashMap<>();
private final LoMinesPlugin plugin;
private final MineFileManager fileManager;
MineRepository(LoMinesPlugin plugin, MineFileManager fileManager) {
this.plugin = plugin;
this.fileManager = fileManager;
}
void add(String name, Mine mine) {
mines.put(name.toLowerCase(), mine);
}
Mine remove(String name) {
return mines.remove(name.toLowerCase());
}
Mine get(String name) {
Mine mine = mines.get(name.toLowerCase());
if (mine == null) {
throw new IllegalArgumentException("Mine not found: " + name);
}
return mine;
}
Optional<Mine> find(String name) {
return Optional.ofNullable(mines.get(name.toLowerCase()));
}
Collection<Mine> getAll() {
return Collections.unmodifiableCollection(mines.values());
}
Optional<Mine> findByLocation(Location location) {
return mines.values().stream()
.filter(mine -> mine.contains(location))
.findFirst();
}
boolean exists(String name) {
return mines.containsKey(name.toLowerCase());
}
void clear() {
for (Mine mine : new ArrayList<>(mines.values())) {
mine.stop();
}
mines.clear();
}
Mine createAndStart(String name, MineConfig config) {
Mine mine = new Mine(name, config, plugin);
add(name, mine);
mine.start();
return mine;
}
void stopAndRemove(String name) {
Mine mine = remove(name);
if (mine != null) {
mine.stop();
}
}
void reload(String name) throws IOException, ConfigParseException {
stopAndRemove(name);
MineConfig config = fileManager.loadConfig(name);
Mine mine = createAndStart(name, config);
plugin.loLogger().info("Reloaded mine: " + name);
}
}

View file

@ -1,20 +1,15 @@
package com.loki.lomines.core; package com.loki.lomines.core;
import com.loki.lomines.LoMinesPlugin; import com.loki.lomines.LoMinesPlugin;
import com.loki.lomines.data.ConfigLoader; import com.loki.lomines.data.config.ConfigParseException;
import com.loki.lomines.data.ConfigParseException; import com.loki.lomines.data.config.MineConfig;
import com.loki.lomines.data.MineConfig;
import com.loki.lomines.util.LocationParser;
import com.loki.lomines.util.MaskScanner;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.*; import java.util.Collection;
import java.util.concurrent.ConcurrentHashMap; import java.util.Optional;
import java.util.stream.Stream; import java.util.stream.Stream;
/** /**
@ -23,13 +18,17 @@ import java.util.stream.Stream;
*/ */
public final class Mines { public final class Mines {
private final Map<String, Mine> mines = new ConcurrentHashMap<>();
private final LoMinesPlugin plugin; private final LoMinesPlugin plugin;
private final Path minesFolder; private final MineFileManager fileManager;
private final MineRepository repository;
private final MaskScanService maskScanService;
public Mines(LoMinesPlugin plugin) { public Mines(LoMinesPlugin plugin) {
this.plugin = plugin; this.plugin = plugin;
this.minesFolder = plugin.getDataFolder().toPath().resolve("mines"); Path minesFolder = plugin.getDataFolder().toPath().resolve("mines");
this.fileManager = new MineFileManager(minesFolder);
this.repository = new MineRepository(plugin, fileManager);
this.maskScanService = new MaskScanService(repository, fileManager);
} }
/** /**
@ -37,36 +36,31 @@ public final class Mines {
* Clears and replaces any previously loaded mines (used for full reload). * Clears and replaces any previously loaded mines (used for full reload).
*/ */
public void loadAll() throws IOException { public void loadAll() throws IOException {
for (Mine m : new ArrayList<>(mines.values())) { repository.clear();
m.stop();
}
mines.clear();
Path minesFolder = fileManager.getMinesFolder();
if (!Files.exists(minesFolder)) { if (!Files.exists(minesFolder)) {
return; return;
} }
ConfigLoader loader = new ConfigLoader();
try (Stream<Path> paths = Files.list(minesFolder)) { try (Stream<Path> paths = Files.list(minesFolder)) {
paths.filter(path -> path.toString().endsWith(".yml")) paths.filter(path -> path.toString().endsWith(".yml"))
.forEach(configFile -> { .forEach(configFile -> loadMineFromFile(configFile));
}
}
private void loadMineFromFile(Path configFile) {
try { try {
String fileName = configFile.getFileName().toString(); String fileName = configFile.getFileName().toString();
String mineName = fileName.substring(0, fileName.length() - 4); String mineName = fileName.substring(0, fileName.length() - 4);
MineConfig config = loader.load(configFile); MineConfig config = fileManager.loadConfig(mineName);
Mine mine = new Mine(mineName, config, plugin); repository.createAndStart(mineName, config);
mines.put(mineName.toLowerCase(), mine);
mine.start();
plugin.loLogger().info("Loaded mine: " + mineName); plugin.loLogger().info("Loaded mine: " + mineName);
} catch (IOException | ConfigParseException e) { } catch (IOException | ConfigParseException e) {
plugin.loLogger().error("Failed to load mine from " + configFile.getFileName() + ": " + e.getMessage()); plugin.loLogger().error("Failed to load mine from " + configFile.getFileName() + ": " + e.getMessage());
} }
});
}
} }
/** /**
@ -80,63 +74,24 @@ public final class Mines {
* Creates a new mine; optional corners define {@code selection.1} and {@code selection.2} (same world required). * Creates a new mine; optional corners define {@code selection.1} and {@code selection.2} (same world required).
*/ */
public void create(String name, Location corner1, Location corner2) throws IOException { public void create(String name, Location corner1, Location corner2) throws IOException {
String key = name.toLowerCase(); if (repository.exists(name)) {
if (mines.containsKey(key)) {
throw new IllegalArgumentException("Mine already exists: " + name); throw new IllegalArgumentException("Mine already exists: " + name);
} }
if (corner1 != null && corner2 != null && !corner1.getWorld().equals(corner2.getWorld())) { if (corner1 != null && corner2 != null && !corner1.getWorld().equals(corner2.getWorld())) {
throw new IllegalArgumentException("Selection corners must be in the same world"); throw new IllegalArgumentException("Selection corners must be in the same world");
} }
// Ensure mines folder exists fileManager.ensureFolderExists();
if (!Files.exists(minesFolder)) { fileManager.createDefaultConfig(name, corner1, corner2);
Files.createDirectories(minesFolder);
}
// Create empty YAML configuration file
Path configFile = minesFolder.resolve(name + ".yml");
YamlConfiguration yaml = new YamlConfiguration();
// Set default empty configuration
if (corner1 != null && corner2 != null) {
yaml.set("selection.1", LocationParser.format(corner1));
yaml.set("selection.2", LocationParser.format(corner2));
} else {
yaml.set("selection.1", "world;0;64;0;0;0");
yaml.set("selection.2", "world;10;74;10;0;0");
}
yaml.set("contents.stone", 100.0);
yaml.set("reset.ticks", 6000);
yaml.set("reset.percent", 10.0);
yaml.set("reset-on-percent", false);
yaml.set("actionbar.enabled", true);
yaml.set("actionbar.message", "&aMine: %mine% | Blocks: %blocks%/%total% (%percent%%)");
yaml.set("actionbar.range", 50.0);
yaml.set("timer-format", "mm:ss");
yaml.set("teleport-on-reset", false);
yaml.set("broadcast-reset", "");
yaml.set("reset-commands", new ArrayList<String>());
yaml.set("random-rewards", new ArrayList<Map<String, Object>>());
yaml.set("fill-mode", "cuboid");
yaml.set("mask.marker", "pink_concrete");
yaml.set("mask.positions", new ArrayList<String>());
yaml.save(configFile.toFile());
// Load the mine configuration
ConfigLoader loader = new ConfigLoader();
MineConfig config; MineConfig config;
try { try {
config = loader.load(configFile); config = fileManager.loadConfig(name);
} catch (ConfigParseException e) { } catch (ConfigParseException e) {
throw new IOException("Failed to parse created mine configuration: " + e.getMessage(), e); throw new IOException("Failed to parse created mine configuration: " + e.getMessage(), e);
} }
// Create and register the mine repository.createAndStart(name, config);
Mine mine = new Mine(name, config, plugin);
mines.put(key, mine);
mine.start();
plugin.loLogger().info("Created mine: " + name); plugin.loLogger().info("Created mine: " + name);
} }
@ -144,21 +99,14 @@ public final class Mines {
* Deletes a mine by name. * Deletes a mine by name.
*/ */
public void delete(String name) throws IOException { public void delete(String name) throws IOException {
String key = name.toLowerCase(); Mine mine = repository.remove(name);
Mine mine = mines.remove(key);
if (mine == null) { if (mine == null) {
throw new IllegalArgumentException("Mine not found: " + name); throw new IllegalArgumentException("Mine not found: " + name);
} }
// Stop the mine
mine.stop(); mine.stop();
fileManager.deleteConfig(name);
// Delete configuration file
Path configFile = minesFolder.resolve(name + ".yml");
if (Files.exists(configFile)) {
Files.delete(configFile);
}
} }
/** /**
@ -166,34 +114,28 @@ public final class Mines {
* @throws IllegalArgumentException if mine not found * @throws IllegalArgumentException if mine not found
*/ */
public Mine get(String name) { public Mine get(String name) {
Mine mine = mines.get(name.toLowerCase()); return repository.get(name);
if (mine == null) {
throw new IllegalArgumentException("Mine not found: " + name);
}
return mine;
} }
/** /**
* Finds a mine by name, returning Optional. * Finds a mine by name, returning Optional.
*/ */
public Optional<Mine> find(String name) { public Optional<Mine> find(String name) {
return Optional.ofNullable(mines.get(name.toLowerCase())); return repository.find(name);
} }
/** /**
* Returns all mines. * Returns all mines.
*/ */
public Collection<Mine> getAll() { public Collection<Mine> getAll() {
return Collections.unmodifiableCollection(mines.values()); return repository.getAll();
} }
/** /**
* Finds a mine that contains the given location. * Finds a mine that contains the given location.
*/ */
public Optional<Mine> findByLocation(Location location) { public Optional<Mine> findByLocation(Location location) {
return mines.values().stream() return repository.findByLocation(location);
.filter(mine -> mine.contains(location))
.findFirst();
} }
/** /**
@ -201,47 +143,15 @@ public final class Mines {
* Must run on the main thread (world access). * Must run on the main thread (world access).
*/ */
public int scanAndSaveMask(String mineName) throws IOException, ConfigParseException { public int scanAndSaveMask(String mineName) throws IOException, ConfigParseException {
Mine mine = get(mineName); int count = maskScanService.scanAndSave(mineName);
Material marker; plugin.loLogger().info("Mask scan for '" + mineName + "': " + count + " marker block(s)");
try { return count;
marker = Material.valueOf(mine.getConfig().getMaskMarkerMaterial().toUpperCase());
} catch (IllegalArgumentException e) {
marker = Material.PINK_CONCRETE;
}
List<Location> found = MaskScanner.scan(mine.getRegions(), marker);
Path configFile = minesFolder.resolve(mineName + ".yml");
YamlConfiguration yaml = YamlConfiguration.loadConfiguration(configFile.toFile());
yaml.set("fill-mode", "mask");
yaml.set("mask.marker", mine.getConfig().getMaskMarkerMaterial());
List<String> lines = new ArrayList<>();
for (Location loc : found) {
lines.add(LocationParser.format(loc));
}
yaml.set("mask.positions", lines);
yaml.save(configFile.toFile());
plugin.loLogger().info("Mask scan for '" + mineName + "': " + found.size() + " marker block(s)");
reloadMine(mineName);
return found.size();
} }
/** /**
* Reloads one mine from disk (stop, replace instance, start tasks). * Reloads one mine from disk (stop, replace instance, start tasks).
*/ */
public void reloadMine(String name) throws IOException, ConfigParseException { public void reloadMine(String name) throws IOException, ConfigParseException {
String key = name.toLowerCase(); repository.reload(name);
Mine old = mines.remove(key);
if (old != null) {
old.stop();
}
Path configFile = minesFolder.resolve(name + ".yml");
if (!Files.exists(configFile)) {
throw new IOException("Mine config not found: " + configFile);
}
ConfigLoader loader = new ConfigLoader();
MineConfig config = loader.load(configFile);
Mine mine = new Mine(name, config, plugin);
mines.put(key, mine);
mine.start();
plugin.loLogger().info("Reloaded mine: " + name);
} }
} }

View file

@ -2,8 +2,6 @@ package com.loki.lomines.data.config;
import org.bukkit.Location; import org.bukkit.Location;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
@ -50,28 +48,33 @@ public final class MineConfig {
// Timer // Timer
private final String timerFormat; private final String timerFormat;
private MineConfig(Builder builder) { MineConfig(List<Location> selections, Map<String, Double> blocks, FillMode fillMode,
this.selections = List.copyOf(builder.selections); String maskMarkerMaterial, List<Location> maskPositions, List<Reward> rewards,
this.blocks = Map.copyOf(builder.blocks); int resetTicks, double resetPercent, boolean resetOnPercentEnabled,
this.fillMode = builder.fillMode; List<String> resetCommands, String broadcastReset, boolean teleportOnReset,
this.maskMarkerMaterial = builder.maskMarkerMaterial; Location teleportLocation, boolean actionBarEnabled, String actionBarMessage,
this.maskPositions = List.copyOf(builder.maskPositions); double actionBarRange, String timerFormat) {
this.rewards = List.copyOf(builder.rewards); this.selections = List.copyOf(selections);
this.resetTicks = builder.resetTicks; this.blocks = Map.copyOf(blocks);
this.resetPercent = builder.resetPercent; this.fillMode = fillMode;
this.resetOnPercentEnabled = builder.resetOnPercentEnabled; this.maskMarkerMaterial = maskMarkerMaterial;
this.resetCommands = List.copyOf(builder.resetCommands); this.maskPositions = List.copyOf(maskPositions);
this.broadcastReset = builder.broadcastReset; this.rewards = List.copyOf(rewards);
this.teleportOnReset = builder.teleportOnReset; this.resetTicks = resetTicks;
this.teleportLocation = builder.teleportLocation; this.resetPercent = resetPercent;
this.actionBarEnabled = builder.actionBarEnabled; this.resetOnPercentEnabled = resetOnPercentEnabled;
this.actionBarMessage = builder.actionBarMessage; this.resetCommands = List.copyOf(resetCommands);
this.actionBarRange = builder.actionBarRange; this.broadcastReset = broadcastReset;
this.timerFormat = builder.timerFormat; this.teleportOnReset = teleportOnReset;
this.teleportLocation = teleportLocation;
this.actionBarEnabled = actionBarEnabled;
this.actionBarMessage = actionBarMessage;
this.actionBarRange = actionBarRange;
this.timerFormat = timerFormat;
} }
public static Builder builder() { public static MineConfigBuilder builder() {
return new Builder(); return new MineConfigBuilder();
} }
// Getters // Getters
@ -176,116 +179,4 @@ public final class MineConfig {
resetOnPercentEnabled, resetCommands, broadcastReset, teleportOnReset, resetOnPercentEnabled, resetCommands, broadcastReset, teleportOnReset,
teleportLocation, actionBarEnabled, actionBarMessage, actionBarRange, timerFormat); teleportLocation, actionBarEnabled, actionBarMessage, actionBarRange, timerFormat);
} }
public static final class Builder {
private List<Location> selections = new ArrayList<>();
private Map<String, Double> blocks = new HashMap<>();
private FillMode fillMode = FillMode.CUBOID;
private String maskMarkerMaterial = "pink_concrete";
private List<Location> maskPositions = new ArrayList<>();
private List<Reward> rewards = new ArrayList<>();
private int resetTicks = 6000;
private double resetPercent = 10.0;
private boolean resetOnPercentEnabled = false;
private List<String> resetCommands = new ArrayList<>();
private String broadcastReset = "";
private boolean teleportOnReset = false;
private Location teleportLocation = null;
private boolean actionBarEnabled = true;
private String actionBarMessage = "";
private double actionBarRange = 50.0;
private String timerFormat = "mm:ss";
private Builder() {
}
public Builder selections(List<Location> selections) {
this.selections = new ArrayList<>(selections);
return this;
}
public Builder blocks(Map<String, Double> blocks) {
this.blocks = new HashMap<>(blocks);
return this;
}
public Builder fillMode(FillMode fillMode) {
this.fillMode = fillMode != null ? fillMode : FillMode.CUBOID;
return this;
}
public Builder maskMarkerMaterial(String maskMarkerMaterial) {
this.maskMarkerMaterial = maskMarkerMaterial != null ? maskMarkerMaterial : "pink_concrete";
return this;
}
public Builder maskPositions(List<Location> maskPositions) {
this.maskPositions = maskPositions != null ? new ArrayList<>(maskPositions) : new ArrayList<>();
return this;
}
public Builder rewards(List<Reward> rewards) {
this.rewards = new ArrayList<>(rewards);
return this;
}
public Builder resetTicks(int resetTicks) {
this.resetTicks = resetTicks;
return this;
}
public Builder resetPercent(double resetPercent) {
this.resetPercent = resetPercent;
return this;
}
public Builder resetOnPercentEnabled(boolean resetOnPercentEnabled) {
this.resetOnPercentEnabled = resetOnPercentEnabled;
return this;
}
public Builder resetCommands(List<String> resetCommands) {
this.resetCommands = new ArrayList<>(resetCommands);
return this;
}
public Builder broadcastReset(String broadcastReset) {
this.broadcastReset = broadcastReset;
return this;
}
public Builder teleportOnReset(boolean teleportOnReset) {
this.teleportOnReset = teleportOnReset;
return this;
}
public Builder teleportLocation(Location teleportLocation) {
this.teleportLocation = teleportLocation;
return this;
}
public Builder actionBarEnabled(boolean actionBarEnabled) {
this.actionBarEnabled = actionBarEnabled;
return this;
}
public Builder actionBarMessage(String actionBarMessage) {
this.actionBarMessage = actionBarMessage;
return this;
}
public Builder actionBarRange(double actionBarRange) {
this.actionBarRange = actionBarRange;
return this;
}
public Builder timerFormat(String timerFormat) {
this.timerFormat = timerFormat;
return this;
}
public MineConfig build() {
return new MineConfig(this);
}
}
} }

View file

@ -0,0 +1,128 @@
package com.loki.lomines.data.config;
import org.bukkit.Location;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Builder for creating immutable MineConfig instances.
*/
public final class MineConfigBuilder {
private List<Location> selections = new ArrayList<>();
private Map<String, Double> blocks = new HashMap<>();
private FillMode fillMode = FillMode.CUBOID;
private String maskMarkerMaterial = "pink_concrete";
private List<Location> maskPositions = new ArrayList<>();
private List<Reward> rewards = new ArrayList<>();
private int resetTicks = 6000;
private double resetPercent = 10.0;
private boolean resetOnPercentEnabled = false;
private List<String> resetCommands = new ArrayList<>();
private String broadcastReset = "";
private boolean teleportOnReset = false;
private Location teleportLocation = null;
private boolean actionBarEnabled = true;
private String actionBarMessage = "";
private double actionBarRange = 50.0;
private String timerFormat = "mm:ss";
MineConfigBuilder() {
}
public MineConfigBuilder selections(List<Location> selections) {
this.selections = new ArrayList<>(selections);
return this;
}
public MineConfigBuilder blocks(Map<String, Double> blocks) {
this.blocks = new HashMap<>(blocks);
return this;
}
public MineConfigBuilder fillMode(FillMode fillMode) {
this.fillMode = fillMode != null ? fillMode : FillMode.CUBOID;
return this;
}
public MineConfigBuilder maskMarkerMaterial(String maskMarkerMaterial) {
this.maskMarkerMaterial = maskMarkerMaterial != null ? maskMarkerMaterial : "pink_concrete";
return this;
}
public MineConfigBuilder maskPositions(List<Location> maskPositions) {
this.maskPositions = maskPositions != null ? new ArrayList<>(maskPositions) : new ArrayList<>();
return this;
}
public MineConfigBuilder rewards(List<Reward> rewards) {
this.rewards = new ArrayList<>(rewards);
return this;
}
public MineConfigBuilder resetTicks(int resetTicks) {
this.resetTicks = resetTicks;
return this;
}
public MineConfigBuilder resetPercent(double resetPercent) {
this.resetPercent = resetPercent;
return this;
}
public MineConfigBuilder resetOnPercentEnabled(boolean resetOnPercentEnabled) {
this.resetOnPercentEnabled = resetOnPercentEnabled;
return this;
}
public MineConfigBuilder resetCommands(List<String> resetCommands) {
this.resetCommands = new ArrayList<>(resetCommands);
return this;
}
public MineConfigBuilder broadcastReset(String broadcastReset) {
this.broadcastReset = broadcastReset;
return this;
}
public MineConfigBuilder teleportOnReset(boolean teleportOnReset) {
this.teleportOnReset = teleportOnReset;
return this;
}
public MineConfigBuilder teleportLocation(Location teleportLocation) {
this.teleportLocation = teleportLocation;
return this;
}
public MineConfigBuilder actionBarEnabled(boolean actionBarEnabled) {
this.actionBarEnabled = actionBarEnabled;
return this;
}
public MineConfigBuilder actionBarMessage(String actionBarMessage) {
this.actionBarMessage = actionBarMessage;
return this;
}
public MineConfigBuilder actionBarRange(double actionBarRange) {
this.actionBarRange = actionBarRange;
return this;
}
public MineConfigBuilder timerFormat(String timerFormat) {
this.timerFormat = timerFormat;
return this;
}
public MineConfig build() {
return new MineConfig(
selections, blocks, fillMode, maskMarkerMaterial, maskPositions,
rewards, resetTicks, resetPercent, resetOnPercentEnabled,
resetCommands, broadcastReset, teleportOnReset, teleportLocation,
actionBarEnabled, actionBarMessage, actionBarRange, timerFormat
);
}
}

View file

@ -2,7 +2,7 @@ package com.loki.lomines.handler;
import com.loki.lomines.LoMinesPlugin; import com.loki.lomines.LoMinesPlugin;
import com.loki.lomines.core.Mine; import com.loki.lomines.core.Mine;
import com.loki.lomines.data.MineConfig; import com.loki.lomines.data.config.MineConfig;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;

View file

@ -1,7 +1,7 @@
package com.loki.lomines.handler; package com.loki.lomines.handler;
import com.loki.lomines.LoMinesPlugin; import com.loki.lomines.LoMinesPlugin;
import com.loki.lomines.data.MineConfig; import com.loki.lomines.data.config.MineConfig;
import com.loki.lomines.data.Reward; import com.loki.lomines.data.Reward;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;

View file

@ -1,6 +1,6 @@
package com.loki.lomines.util.location; package com.loki.lomines.util.location;
import com.loki.lomines.data.ConfigParseException; import com.loki.lomines.data.config.ConfigParseException;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;