Merge branch 'worktree-agent-a00d0cd05056c134c'

This commit is contained in:
loki5512344 2026-06-08 14:34:27 +02:00
commit 8f094c2971
6 changed files with 24 additions and 9 deletions

View file

@ -130,7 +130,12 @@ public class GeneratorProfileManager {
String materialName = Config.GENERATION.getString(materialPath);
int chance = Config.GENERATION.getInt(chancePath, 1);
BlockData blockData = org.bukkit.Bukkit.createBlockData(materialName);
BlockData blockData;
try {
blockData = org.bukkit.Bukkit.createBlockData(materialName);
} catch (IllegalArgumentException e) {
continue; // skip invalid material names
}
generator.state.specialChances.put(blockData, (double) chance);
}

View file

@ -31,8 +31,9 @@ public class GeneratorState {
// Time state
public Instant start;
// Block history (sync list: all mutations occur on the main thread; avoids accidental CME if extended later)
public final List<Block> history = Collections.synchronizedList(new LinkedList<>());
// Block history — all access is main-thread-only (Bukkit scheduler runTimer), so no sync wrapper needed.
// Iteration is safe without external synchronization as all mutations happen on the same thread.
public final List<Block> history = new ArrayList<>();
public int lastPositionIndexPlayer = -1;
// Schematic state

View file

@ -45,16 +45,18 @@ public class Profile {
}
/**
* @return The value as a double.
* @return The value as a double. Returns 0.0 if the value is empty.
*/
public double asDouble() {
if (value.isEmpty()) return 0.0;
return Double.parseDouble(value);
}
/**
* @return The value as an int.
* @return The value as an int. Returns 0 if the value is empty.
*/
public int asInt() {
if (value.isEmpty()) return 0;
return Integer.parseInt(value);
}
}

View file

@ -9,6 +9,8 @@ import org.bukkit.block.data.BlockData;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
/**
* Handles selection of block types and materials for parkour generation.
*/
@ -29,7 +31,11 @@ public class BlockSelector {
public BlockData selectBlockData() {
Style style = Registry.getStyle(generator.profile.get("style").value());
if (style == null) {
generator.profile.set("style", Registry.getStyles().stream().findFirst().orElseThrow().getName());
List<Style> styles = Registry.getStyles();
if (styles.isEmpty()) {
return Material.STONE.createBlockData();
}
generator.profile.set("style", styles.stream().findFirst().orElseThrow().getName());
return selectBlockData();
}
for (int i = 0; i < MAX_STYLE_PICKS; i++) {

View file

@ -92,7 +92,8 @@ public class LifecycleTickManager {
if (currentBlocks < targetBlocks) {
int needed = targetBlocks - currentBlocks;
generator.generate(needed);
// Cap generation per tick to prevent runaway generation in multiplayer
generator.generate(Math.min(needed, 5));
}
}
}

View file

@ -82,8 +82,8 @@ public class PlayerInteractionHandler {
}
}
// Generate more blocks after scoring
generator.generate(1);
// Block generation is handled by LifecycleTickManager.maintainBlockLead()
// to avoid runaway generation in multiplayer (N players = N generates per tick otherwise).
}
/**