Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0805b48763 | ||
|
|
d737322aaa | ||
|
|
4ddc150e1c | ||
|
|
0da119d89d | ||
|
|
fc0a07d1c5 |
@@ -8,42 +8,15 @@ import org.bukkit.persistence.PersistentDataType;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Queue;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utilities / API methods for blocks.
|
* Utilities / API methods for blocks.
|
||||||
*/
|
*/
|
||||||
public final class BlockUtils {
|
public final class BlockUtils {
|
||||||
/**
|
|
||||||
* Max blocks to mine (yes, this is to prevent a stack overflow).
|
|
||||||
*/
|
|
||||||
private static final int MAX_BLOCKS = 2500;
|
|
||||||
|
|
||||||
private static Set<Block> getNearbyBlocks(@NotNull final Block start,
|
|
||||||
@NotNull final List<Material> allowedMaterials,
|
|
||||||
@NotNull final Set<Block> blocks,
|
|
||||||
final int limit) {
|
|
||||||
for (BlockFace face : BlockFace.values()) {
|
|
||||||
Block block = start.getRelative(face);
|
|
||||||
if (blocks.contains(block)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (allowedMaterials.contains(block.getType())) {
|
|
||||||
blocks.add(block);
|
|
||||||
|
|
||||||
if (blocks.size() > limit || blocks.size() > MAX_BLOCKS) {
|
|
||||||
return blocks;
|
|
||||||
}
|
|
||||||
|
|
||||||
blocks.addAll(getNearbyBlocks(block, allowedMaterials, blocks, limit));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return blocks;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a set of all blocks in contact with each other of a specific type.
|
* Get a set of all blocks in contact with each other of a specific type.
|
||||||
*
|
*
|
||||||
@@ -56,7 +29,32 @@ public final class BlockUtils {
|
|||||||
public static Set<Block> getVein(@NotNull final Block start,
|
public static Set<Block> getVein(@NotNull final Block start,
|
||||||
@NotNull final List<Material> allowedMaterials,
|
@NotNull final List<Material> allowedMaterials,
|
||||||
final int limit) {
|
final int limit) {
|
||||||
return getNearbyBlocks(start, allowedMaterials, new HashSet<>(), limit);
|
Set<Block> blocks = new HashSet<>();
|
||||||
|
Queue<Block> toProcess = new LinkedList<>();
|
||||||
|
|
||||||
|
if (allowedMaterials.contains(start.getType())) {
|
||||||
|
toProcess.add(start);
|
||||||
|
}
|
||||||
|
|
||||||
|
while (!toProcess.isEmpty() && blocks.size() < limit) {
|
||||||
|
Block currentBlock = toProcess.poll();
|
||||||
|
|
||||||
|
if (blocks.contains(currentBlock)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
blocks.add(currentBlock);
|
||||||
|
|
||||||
|
for (BlockFace face : BlockFace.values()) {
|
||||||
|
Block adjacentBlock = currentBlock.getRelative(face);
|
||||||
|
|
||||||
|
if (!blocks.contains(adjacentBlock) && allowedMaterials.contains(adjacentBlock.getType())) {
|
||||||
|
toProcess.add(adjacentBlock);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return blocks;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ open class EcoConfig(
|
|||||||
private val values = ConcurrentHashMap<String, Any?>()
|
private val values = ConcurrentHashMap<String, Any?>()
|
||||||
|
|
||||||
@Transient
|
@Transient
|
||||||
var injections = mutableListOf<InjectablePlaceholder>()
|
var injections = ConcurrentHashMap<String, InjectablePlaceholder>()
|
||||||
|
|
||||||
fun init(values: Map<String, Any?>) {
|
fun init(values: Map<String, Any?>) {
|
||||||
this.values.clear()
|
this.values.clear()
|
||||||
@@ -104,12 +104,12 @@ open class EcoConfig(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun getSubsectionOrNull(path: String): Config? {
|
override fun getSubsectionOrNull(path: String): Config? {
|
||||||
return (get(path) as? Config)?.apply { this.addInjectablePlaceholder(injections) }
|
return (get(path) as? Config)?.apply { this.addInjectablePlaceholder(injections.values) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getSubsectionsOrNull(path: String): List<Config>? {
|
override fun getSubsectionsOrNull(path: String): List<Config>? {
|
||||||
return getList<Config>(path)
|
return getList<Config>(path)
|
||||||
?.map { it.apply { this.addInjectablePlaceholder(injections) } }
|
?.map { it.apply { this.addInjectablePlaceholder(injections.values) } }
|
||||||
?.toList()
|
?.toList()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,12 +180,13 @@ open class EcoConfig(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun addInjectablePlaceholder(placeholders: Iterable<InjectablePlaceholder>) {
|
override fun addInjectablePlaceholder(placeholders: Iterable<InjectablePlaceholder>) {
|
||||||
injections.removeIf { placeholders.any { placeholder -> it.identifier == placeholder.identifier } }
|
for (placeholder in placeholders) {
|
||||||
injections.addAll(placeholders)
|
injections[placeholder.identifier] = placeholder
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getPlaceholderInjections(): List<InjectablePlaceholder> {
|
override fun getPlaceholderInjections(): List<InjectablePlaceholder> {
|
||||||
return injections.toList()
|
return injections.values.toList()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun clearInjectedPlaceholders() {
|
override fun clearInjectedPlaceholders() {
|
||||||
|
|||||||
@@ -2,14 +2,15 @@ package com.willfp.eco.internal.config
|
|||||||
|
|
||||||
import com.willfp.eco.core.config.ConfigType
|
import com.willfp.eco.core.config.ConfigType
|
||||||
import com.willfp.eco.core.placeholder.InjectablePlaceholder
|
import com.willfp.eco.core.placeholder.InjectablePlaceholder
|
||||||
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
|
|
||||||
class EcoConfigSection(
|
class EcoConfigSection(
|
||||||
type: ConfigType,
|
type: ConfigType,
|
||||||
values: Map<String, Any?> = emptyMap(),
|
values: Map<String, Any?> = emptyMap(),
|
||||||
injections: Collection<InjectablePlaceholder> = emptyList()
|
injections: MutableMap<String, InjectablePlaceholder> = mutableMapOf()
|
||||||
) : EcoConfig(type) {
|
) : EcoConfig(type) {
|
||||||
init {
|
init {
|
||||||
this.init(values)
|
this.init(values)
|
||||||
this.injections = injections.toMutableList()
|
this.injections = ConcurrentHashMap(injections)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
version = 6.55.1
|
version = 6.55.2
|
||||||
plugin-name = eco
|
plugin-name = eco
|
||||||
kotlin.code.style = official
|
kotlin.code.style = official
|
||||||
Reference in New Issue
Block a user