forked from SteamWar/SteamWar
Improve items for GameModeConfig
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
|
||||
plugins {
|
||||
steamwar.kotlin
|
||||
kotlin("plugin.lombok")
|
||||
}
|
||||
|
||||
kotlin {
|
||||
@@ -40,4 +41,8 @@ dependencies {
|
||||
compileOnlyApi(libs.exposedDao)
|
||||
compileOnlyApi(libs.exposedJdbc)
|
||||
compileOnlyApi(libs.exposedTime)
|
||||
testImplementation(kotlin("test"))
|
||||
}
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
@@ -688,13 +688,6 @@ public final class GameModeConfig<M, W> {
|
||||
*/
|
||||
public final int MaxBlocks;
|
||||
|
||||
/**
|
||||
* Maximal amount of items per dispenser
|
||||
*
|
||||
* @implSpec {@code 128} by default
|
||||
*/
|
||||
public final int MaxDispenserItems;
|
||||
|
||||
/**
|
||||
* Maximal blast resistance for the blocks
|
||||
*
|
||||
@@ -715,6 +708,42 @@ public final class GameModeConfig<M, W> {
|
||||
*/
|
||||
public final Map<Set<M>, Integer> Limited;
|
||||
|
||||
/**
|
||||
* Item amount limits per inventory (container) type.<br/>
|
||||
* Key: inventory material (e.g. DISPENSER, CHEST, ...). Value: item material -> maximal
|
||||
* amount of that item allowed to be stored in a single inventory of that type.<br/>
|
||||
* An item is only allowed to be placed in an inventory at all if it appears here for that
|
||||
* inventory's material and item. Every material returned by
|
||||
* {@link SQLWrapper#getInventoryMaterials()} is always present as a key - with an empty value
|
||||
* map if not explicitly configured - so every real container is always scanned by the schematic
|
||||
* checker for forbidden contents, it just allows no items by default.<br/>
|
||||
* Configured via the {@code ItemsInInventory} list, entries consisting of {@code Inventories}
|
||||
* (list of inventory materials or group names - {@code storage} for
|
||||
* {@link SQLWrapper#getStorageMaterials()}, {@code all} for every material from
|
||||
* {@link SQLWrapper#getInventoryMaterials()}), {@code Items} (list of item materials, each
|
||||
* checked independently against {@code Amount} - not summed) and {@code Amount}.
|
||||
*
|
||||
* @implSpec No item is allowed in any inventory unless configured here
|
||||
*/
|
||||
public final Map<M, Map<M, Integer>> ItemsInInventory;
|
||||
|
||||
/**
|
||||
* Resolves one {@code Inventories} entry to the concrete inventory materials it denotes:
|
||||
* {@code storage} for {@link SQLWrapper#getStorageMaterials()}, {@code all} for
|
||||
* {@link SQLWrapper#getInventoryMaterials()}, or the material itself otherwise.
|
||||
*/
|
||||
private Set<M> expandInventoryGroup(YMLWrapper<M, ?> loader, String name) {
|
||||
switch (name.toUpperCase()) {
|
||||
case "STORAGE":
|
||||
return (Set<M>) SQLWrapper.impl.getStorageMaterials();
|
||||
case "ALL":
|
||||
return (Set<M>) SQLWrapper.impl.getInventoryMaterials();
|
||||
default:
|
||||
M material = loader.materialMapper.apply(name.toUpperCase());
|
||||
return material != null ? Collections.singleton(material) : Collections.emptySet();
|
||||
}
|
||||
}
|
||||
|
||||
private SchematicConfig(YMLWrapper<M, ?> loader) {
|
||||
loaded = loader.canLoad();
|
||||
Size = new SizeConfig(loader.with("Size"));
|
||||
@@ -731,7 +760,6 @@ public final class GameModeConfig<M, W> {
|
||||
IgnorePublicOnly = loader.getBoolean("IgnorePublicOnly", false);
|
||||
UnlimitedPrepare = loader.getBoolean("UnlimitedPrepare", false);
|
||||
MaxBlocks = loader.getInt("MaxBlocks", 0);
|
||||
MaxDispenserItems = loader.getInt("MaxDispenserItems", 128);
|
||||
MaxBlastResistance = loader.getDouble("MaxBlastResistance", Double.MAX_VALUE);
|
||||
MaxDesignBlastResistance = loader.getDouble("MaxDesignBlastResistance", MaxBlastResistance);
|
||||
|
||||
@@ -753,6 +781,30 @@ public final class GameModeConfig<M, W> {
|
||||
});
|
||||
this.Limited = Collections.unmodifiableMap(Limited);
|
||||
|
||||
Map<M, Map<M, Integer>> itemsInInventory = new HashMap<>();
|
||||
for (Map<?, ?> entry : loader.getMapList("ItemsInInventory")) {
|
||||
int amount = (Integer) entry.get("Amount");
|
||||
List<String> inventories = (List<String>) entry.get("Inventories");
|
||||
List<String> items = (List<String>) entry.get("Items");
|
||||
for (String inventoryName : inventories) {
|
||||
for (M inventoryMaterial : expandInventoryGroup(loader, inventoryName)) {
|
||||
if (inventoryMaterial == null) continue;
|
||||
Map<M, Integer> itemCaps = itemsInInventory.computeIfAbsent(inventoryMaterial, m -> new HashMap<>());
|
||||
for (String itemName : items) {
|
||||
M itemMaterial = loader.materialMapper.apply(itemName.toUpperCase());
|
||||
if (itemMaterial == null) continue;
|
||||
itemCaps.put(itemMaterial, amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (M allMaterial : (Set<M>) SQLWrapper.impl.getInventoryMaterials()) {
|
||||
if (allMaterial == null) continue;
|
||||
itemsInInventory.computeIfAbsent(allMaterial, m -> new HashMap<>());
|
||||
}
|
||||
this.ItemsInInventory = Collections.unmodifiableMap(itemsInInventory.entrySet().stream()
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, e -> Collections.unmodifiableMap(e.getValue()))));
|
||||
|
||||
this.ReplacementsWithoutBlockUpdates = loader.getMap("ReplacementsWithoutBlockUpdates", loader.materialMapper, loader.materialMapper);
|
||||
this.ReplacementsWithBlockUpdates = loader.getMap("ReplacementsWithBlockUpdates", loader.materialMapper, loader.materialMapper);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import de.steamwar.ImplementationProvider;
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public interface SQLWrapper<M> {
|
||||
SQLWrapper<?> impl = ImplementationProvider.getImpl("de.steamwar.sql.SQLWrapperImpl");
|
||||
@@ -36,5 +37,21 @@ public interface SQLWrapper<M> {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Storage-type inventory materials (chests, barrels, shulker boxes of any color) - the
|
||||
* {@code storage} group usable in {@code GameModeConfig}'s {@code ItemsInInventory}.
|
||||
*/
|
||||
default Set<M> getStorageMaterials() {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
/**
|
||||
* Every inventory material - the {@code all} group usable in {@code GameModeConfig}'s
|
||||
* {@code ItemsInInventory}. Expected to be a superset of {@link #getStorageMaterials()}.
|
||||
*/
|
||||
default Set<M> getInventoryMaterials() {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
void additionalExceptionMetadata(StringBuilder builder);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user