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
109 lines
3.5 KiB
Java
109 lines
3.5 KiB
Java
package dev.loki.lomines.block;
|
|
|
|
import dev.loki.lomines.LoMinesPlugin;
|
|
import dev.loki.lomines.data.config.block.BlockKey;
|
|
import dev.loki.lomines.util.location.Cuboid;
|
|
import dev.lolib.scheduler.Scheduler;
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.Location;
|
|
import org.bukkit.Material;
|
|
import org.bukkit.World;
|
|
import org.bukkit.block.data.BlockData;
|
|
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.function.IntConsumer;
|
|
|
|
/**
|
|
* BlockSetter implementation for vanilla Minecraft blocks.
|
|
* Uses Bukkit API to set blocks with optimal performance settings.
|
|
* Updated for BlockKey type-safe configuration.
|
|
*/
|
|
public final class BukkitBlockSetter extends BlockSetter {
|
|
|
|
private final Map<BlockKey, Double> weights;
|
|
private final LoMinesPlugin plugin;
|
|
|
|
public BukkitBlockSetter(Map<BlockKey, Double> weights, LoMinesPlugin plugin) {
|
|
this.weights = weights;
|
|
this.plugin = plugin;
|
|
}
|
|
|
|
@Override
|
|
public void fill(Cuboid region, IntConsumer callback) {
|
|
Scheduler.get(plugin).runAsync(() -> {
|
|
int count = fillSync(region);
|
|
|
|
Scheduler.get(plugin).run(() -> {
|
|
callback.accept(count);
|
|
});
|
|
});
|
|
}
|
|
|
|
@Override
|
|
public void fillAtLocations(List<Location> locations, IntConsumer callback) {
|
|
if (locations == null || locations.isEmpty()) {
|
|
Scheduler.get(plugin).run(() -> callback.accept(0));
|
|
return;
|
|
}
|
|
Scheduler.get(plugin).runAsync(() -> {
|
|
int count = fillAtLocationsSync(locations);
|
|
Scheduler.get(plugin).run(() -> callback.accept(count));
|
|
});
|
|
}
|
|
|
|
private int fillSync(Cuboid region) {
|
|
int count = 0;
|
|
World world = region.getWorld();
|
|
|
|
for (int x = region.getMinX(); x <= region.getMaxX(); x++) {
|
|
for (int y = region.getMinY(); y <= region.getMaxY(); y++) {
|
|
for (int z = region.getMinZ(); z <= region.getMaxZ(); z++) {
|
|
BlockData data = sampleBlockData();
|
|
world.getBlockAt(x, y, z).setBlockData(data, false);
|
|
count++;
|
|
}
|
|
}
|
|
}
|
|
|
|
return count;
|
|
}
|
|
|
|
private int fillAtLocationsSync(List<Location> locations) {
|
|
int count = 0;
|
|
for (Location loc : locations) {
|
|
if (loc.getWorld() == null) {
|
|
continue;
|
|
}
|
|
BlockData data = sampleBlockData();
|
|
loc.getBlock().setBlockData(data, false);
|
|
count++;
|
|
}
|
|
return count;
|
|
}
|
|
|
|
private BlockData sampleBlockData() {
|
|
// Simple weighted random selection
|
|
double random = Math.random();
|
|
|
|
double currentWeight = 0;
|
|
for (Map.Entry<BlockKey, Double> entry : weights.entrySet()) {
|
|
currentWeight += entry.getValue();
|
|
if (random <= currentWeight) {
|
|
// BlockKey is already validated to be a block
|
|
if (entry.getKey() instanceof BlockKey.Vanilla vanilla) {
|
|
return Bukkit.createBlockData(vanilla.material());
|
|
}
|
|
// Fallback for non-vanilla keys in vanilla setter (shouldn't happen)
|
|
return Bukkit.createBlockData(Material.STONE);
|
|
}
|
|
}
|
|
|
|
// Fallback to first entry
|
|
BlockKey firstKey = weights.keySet().iterator().next();
|
|
if (firstKey instanceof BlockKey.Vanilla vanilla) {
|
|
return Bukkit.createBlockData(vanilla.material());
|
|
}
|
|
return Bukkit.createBlockData(Material.STONE);
|
|
}
|
|
}
|