refactor: migrate package from com.loki to dev.loki
- Change base package from com.loki to dev.loki across all Java files - Update plugin.yml main class path - Fix ConfigParseException imports in test files - Update build.gradle.kts relocate patterns - Add missing imports in ConfigLoaderTest.java - Update TODO.md with current status BREAKING CHANGE: Package namespace changed from com.loki to dev.loki
This commit is contained in:
parent
41924ea97f
commit
f4e9458544
87 changed files with 2185 additions and 1767 deletions
37
src/main/java/dev/loki/lomines/block/BlockSetter.java
Normal file
37
src/main/java/dev/loki/lomines/block/BlockSetter.java
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
package dev.loki.lomines.block;
|
||||
|
||||
import dev.loki.lomines.util.location.Cuboid;
|
||||
import org.bukkit.Location;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.IntConsumer;
|
||||
|
||||
/**
|
||||
* Abstract base class for block setting strategies.
|
||||
* Provides a template for filling mine regions with blocks.
|
||||
*
|
||||
* <p>Implementations:</p>
|
||||
* <ul>
|
||||
* <li>BukkitBlockSetter - For vanilla Minecraft blocks</li>
|
||||
* <li>OraxenBlockSetter - For Oraxen custom blocks</li>
|
||||
* <li>ItemsAdderBlockSetter - For ItemsAdder custom blocks</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p>This is a placeholder that will be fully implemented in task 2.7.</p>
|
||||
*/
|
||||
public abstract class BlockSetter {
|
||||
|
||||
/**
|
||||
* Fills a cuboid region with blocks asynchronously.
|
||||
* The callback is invoked in the main thread after completion.
|
||||
*
|
||||
* @param region The region to fill
|
||||
* @param callback Called with the number of blocks set when complete
|
||||
*/
|
||||
public abstract void fill(Cuboid region, IntConsumer callback);
|
||||
|
||||
/**
|
||||
* Places random weighted blocks only at the given locations (mask mode).
|
||||
*/
|
||||
public abstract void fillAtLocations(List<Location> locations, IntConsumer callback);
|
||||
}
|
||||
104
src/main/java/dev/loki/lomines/block/BukkitBlockSetter.java
Normal file
104
src/main/java/dev/loki/lomines/block/BukkitBlockSetter.java
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
package dev.loki.lomines.block;
|
||||
|
||||
import dev.loki.lomines.LoMinesPlugin;
|
||||
import dev.loki.lomines.util.ValidationUtils;
|
||||
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.
|
||||
*/
|
||||
public final class BukkitBlockSetter extends BlockSetter {
|
||||
|
||||
private final Map<String, Double> weights;
|
||||
private final LoMinesPlugin plugin;
|
||||
|
||||
public BukkitBlockSetter(Map<String, 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 totalWeight = weights.values().stream().mapToDouble(Double::doubleValue).sum();
|
||||
double random = Math.random() * totalWeight;
|
||||
|
||||
double currentWeight = 0;
|
||||
for (Map.Entry<String, Double> entry : weights.entrySet()) {
|
||||
currentWeight += entry.getValue();
|
||||
if (random <= currentWeight) {
|
||||
// Convert string key to BlockData
|
||||
Material material = ValidationUtils.parseMaterialOrDefault(entry.getKey(), Material.STONE);
|
||||
return Bukkit.createBlockData(material);
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback to first entry
|
||||
String firstKey = weights.keySet().iterator().next();
|
||||
Material material = ValidationUtils.parseMaterialOrDefault(firstKey, Material.STONE);
|
||||
return Bukkit.createBlockData(material);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,100 @@
|
|||
package com.loki.lomines.block;
|
||||
|
||||
import dev.lolib.scheduler.Scheduler;
|
||||
import com.loki.lomines.LoMinesPlugin;
|
||||
import com.loki.lomines.util.Cuboid;
|
||||
import dev.lone.itemsadder.api.CustomBlock;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.IntConsumer;
|
||||
|
||||
/**
|
||||
* BlockSetter implementation for ItemsAdder custom blocks.
|
||||
* Uses ItemsAdder API to place custom blocks in mine regions.
|
||||
*/
|
||||
public final class ItemsAdderBlockSetter extends BlockSetter {
|
||||
|
||||
private final Map<String, Double> itemsAdderIds;
|
||||
private final LoMinesPlugin plugin;
|
||||
|
||||
public ItemsAdderBlockSetter(Map<String, Double> itemsAdderIds, LoMinesPlugin plugin) {
|
||||
this.itemsAdderIds = itemsAdderIds;
|
||||
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++) {
|
||||
String itemsAdderId = sampleItemsAdderId();
|
||||
Block block = world.getBlockAt(x, y, z);
|
||||
CustomBlock.place(itemsAdderId, block.getLocation());
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
private int fillAtLocationsSync(List<Location> locations) {
|
||||
int count = 0;
|
||||
for (Location loc : locations) {
|
||||
if (loc.getWorld() == null) {
|
||||
continue;
|
||||
}
|
||||
String itemsAdderId = sampleItemsAdderId();
|
||||
Block block = loc.getBlock();
|
||||
CustomBlock.place(itemsAdderId, block.getLocation());
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
private String sampleItemsAdderId() {
|
||||
// Simple weighted random selection
|
||||
double totalWeight = itemsAdderIds.values().stream().mapToDouble(Double::doubleValue).sum();
|
||||
double random = Math.random() * totalWeight;
|
||||
|
||||
double currentWeight = 0;
|
||||
for (Map.Entry<String, Double> entry : itemsAdderIds.entrySet()) {
|
||||
currentWeight += entry.getValue();
|
||||
if (random <= currentWeight) {
|
||||
return entry.getKey();
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback to first entry
|
||||
return itemsAdderIds.keySet().iterator().next();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,100 @@
|
|||
package com.loki.lomines.block;
|
||||
|
||||
import dev.lolib.scheduler.Scheduler;
|
||||
import com.loki.lomines.LoMinesPlugin;
|
||||
import com.loki.lomines.util.Cuboid;
|
||||
import io.th0rgal.oraxen.api.OraxenBlocks;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.IntConsumer;
|
||||
|
||||
/**
|
||||
* BlockSetter implementation for Oraxen custom blocks.
|
||||
* Uses Oraxen API to place custom blocks in mine regions.
|
||||
*/
|
||||
public final class OraxenBlockSetter extends BlockSetter {
|
||||
|
||||
private final Map<String, Double> oraxenIds;
|
||||
private final LoMinesPlugin plugin;
|
||||
|
||||
public OraxenBlockSetter(Map<String, Double> oraxenIds, LoMinesPlugin plugin) {
|
||||
this.oraxenIds = oraxenIds;
|
||||
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++) {
|
||||
String oraxenId = sampleOraxenId();
|
||||
Block block = world.getBlockAt(x, y, z);
|
||||
OraxenBlocks.place(oraxenId, block.getLocation());
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
private int fillAtLocationsSync(List<Location> locations) {
|
||||
int count = 0;
|
||||
for (Location loc : locations) {
|
||||
if (loc.getWorld() == null) {
|
||||
continue;
|
||||
}
|
||||
String oraxenId = sampleOraxenId();
|
||||
Block block = loc.getBlock();
|
||||
OraxenBlocks.place(oraxenId, block.getLocation());
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
private String sampleOraxenId() {
|
||||
// Simple weighted random selection
|
||||
double totalWeight = oraxenIds.values().stream().mapToDouble(Double::doubleValue).sum();
|
||||
double random = Math.random() * totalWeight;
|
||||
|
||||
double currentWeight = 0;
|
||||
for (Map.Entry<String, Double> entry : oraxenIds.entrySet()) {
|
||||
currentWeight += entry.getValue();
|
||||
if (random <= currentWeight) {
|
||||
return entry.getKey();
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback to first entry
|
||||
return oraxenIds.keySet().iterator().next();
|
||||
}
|
||||
}
|
||||
12
src/main/java/dev/loki/lomines/block/package-info.java
Normal file
12
src/main/java/dev/loki/lomines/block/package-info.java
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
/**
|
||||
* Block system for mine filling operations.
|
||||
* <p>
|
||||
* This package contains the abstraction for setting blocks in mines:
|
||||
* <ul>
|
||||
* <li>{@code BlockSetter} - Abstract base class for block placement</li>
|
||||
* <li>{@code BukkitBlockSetter} - Implementation for vanilla Bukkit blocks</li>
|
||||
* <li>{@code OraxenBlockSetter} - Implementation for Oraxen custom blocks</li>
|
||||
* <li>{@code ItemsAdderBlockSetter} - Implementation for ItemsAdder custom blocks</li>
|
||||
* </ul>
|
||||
*/
|
||||
package dev.loki.lomines.block;
|
||||
Loading…
Add table
Add a link
Reference in a new issue