Fix WetRegion -> WetRegionData

Fix DynamicRegionSystem.get
Add Fallback.schem for PathArea
This commit is contained in:
2026-03-06 15:34:53 +01:00
parent 9f27292fa2
commit ed51106d4a
6 changed files with 107 additions and 28 deletions
@@ -21,13 +21,17 @@ package de.steamwar.bausystem.region;
import de.steamwar.bausystem.features.region.RegionCommand;
import de.steamwar.bausystem.region.dynamic.DynamicRegion;
import de.steamwar.bausystem.region.dynamic.DynamicRegionRepository;
import de.steamwar.bausystem.region.dynamic.Tile;
import de.steamwar.bausystem.region.dynamic.path.PathRegion;
import de.steamwar.bausystem.utils.PasteBuilder;
import de.steamwar.command.AbstractSWCommand;
import de.steamwar.command.PreviousArguments;
import de.steamwar.command.SWCommand;
import de.steamwar.command.TypeMapper;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.Collection;
import java.util.UUID;
@AbstractSWCommand.PartOf(RegionCommand.class)
@@ -38,16 +42,17 @@ public class DynamicRegionCommand extends SWCommand {
}
@Register({"dynamic", "place"})
public void placeRegion(Player player) {
public void placeRegion(Player player, @Mapper("regionType") String regionType) {
Region region = DynamicRegionSystem.INSTANCE.get(player.getLocation());
if (!region.getType().isGlobal()) return;
Tile tile = Tile.fromLocation(player.getLocation()).orElse(null);
if (tile == null) return;
// TODO: Replace!
PathRegion dynamicRegion = new PathRegion(UUID.randomUUID(), tile.getMinX(), tile.getMinZ());
Class<? extends DynamicRegion> regionClass = DynamicRegionSystem.identifierDataMap.get(regionType);
DynamicRegion dynamicRegion = DynamicRegionRepository.constructRegion(regionClass, UUID.randomUUID(), tile.getMinX(), tile.getMinZ());
dynamicRegion.getArea().reset(new PasteBuilder(new PasteBuilder.FileProvider(dynamicRegion.getArea().getResetFile())), false);
// TODO: This here still has some kind of error!aww
DynamicRegionSystem.INSTANCE.getNeighbours(dynamicRegion).forEach(r -> r.update(dynamicRegion));
}
@@ -57,4 +62,23 @@ public class DynamicRegionCommand extends SWCommand {
if (!region.getType().isDeletable()) return;
((DynamicRegion) region).delete();
}
@Mapper("regionType")
private TypeMapper<String> regionType() {
return new TypeMapper<>() {
@Override
public String map(CommandSender commandSender, String[] previousArguments, String s) {
if (DynamicRegionSystem.identifierDataMap.containsKey(s)) {
return s;
} else {
return null;
}
}
@Override
public Collection<String> tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) {
return DynamicRegionSystem.identifierDataMap.keySet();
}
};
}
}
@@ -118,7 +118,9 @@ public class DynamicRegionSystem implements RegionSystem {
.filter(rg -> rg.getArea().inRegion(x, z, false))
.findFirst()
.orElseGet(this::getGlobalRegion);
if (fastCache || regions.contains(region)) {
regionCache.put(tile.getId(), region);
}
return region;
}
@@ -144,21 +144,25 @@ public class DynamicRegionRepository {
continue;
}
Location minTileLocation = tile.getMinLocation();
constructRegion(regionClass, regionUUID, minTileLocation.getBlockX(), minTileLocation.getBlockZ());
}
}
public static DynamicRegion constructRegion(Class<? extends DynamicRegion> clazz, UUID uuid, int minX, int minZ) {
Constructor<? extends DynamicRegion> regionConstructor;
try {
regionConstructor = regionClass.getConstructor(UUID.class, int.class, int.class);
regionConstructor = clazz.getConstructor(UUID.class, int.class, int.class);
} catch (NoSuchMethodException e) {
RegionSystem.LOGGER.log(Level.SEVERE, "Failed to read region metadata file (region constructor not found)");
continue;
return null;
}
try {
regionConstructor.newInstance(regionUUID, minTileLocation.getBlockX(), minTileLocation.getBlockZ());
return regionConstructor.newInstance(uuid, minX, minZ);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException |
InvocationTargetException e) {
RegionSystem.LOGGER.log(Level.SEVERE, "Failed to read region metadata file (invalid data)");
}
return null;
}
}
@@ -19,6 +19,7 @@
package de.steamwar.bausystem.region.dynamic.path;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.region.DynamicRegionSystem;
import de.steamwar.bausystem.region.Point;
import de.steamwar.bausystem.region.Region;
@@ -42,6 +43,7 @@ import static de.steamwar.bausystem.region.RegionType.ConnectionType.*;
public class PathArea implements Region.Area {
private static final File PATH_DIR = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "sections/path");
private static final File FALLBACK_SCHEM = new File(PATH_DIR, "Fallback.schem");
private static final VariantSelector CENTER_NORMAL = VariantSelector.Get(new File(PATH_DIR, "center/normal"));
private static final VariantSelector SIDE_GLOBAL = VariantSelector.Get(new File(PATH_DIR, "side/global"));
@@ -151,10 +153,11 @@ public class PathArea implements Region.Area {
for (Side side : Side.values()) {
VariantSelector selector = SELECTOR_SIDE.Select(tile, side);
if (selector == null) continue;
resetFile = selector.select(regionIdentifier, side.ordinal() + side.rotate).orElse(null);
if (resetFile == null) continue;
if (selector != null) resetFile = selector.select(regionIdentifier, side.ordinal() + side.rotate).orElse(null);
if (selector == null || resetFile == null) {
if (!BauSystem.DEV_SERVER) continue;
resetFile = FALLBACK_SCHEM;
}
PasteUtils.paste(resetFile, minPoint.add(side.pasteOffsetX, 0, side.pasteOffsetZ), side.rotate);
}
@@ -162,11 +165,13 @@ public class PathArea implements Region.Area {
for (Corner corner : Corner.values()) {
Pair<VariantSelector, RotationCorrection> pair = SELECTOR_CORNER.Select(tile, corner);
VariantSelector selector = pair.getKey();
if (selector == null) continue;
RotationCorrection rotationCorrection = pair.getValue();
resetFile = selector.select(regionIdentifier, corner.side1.ordinal() * corner.side2.ordinal() + corner.side1.rotate * corner.side2.rotate).orElse(null);
if (resetFile == null) continue;
if (selector != null) resetFile = selector.select(regionIdentifier, corner.side1.ordinal() * corner.side2.ordinal() + corner.side1.rotate * corner.side2.rotate).orElse(null);
if (selector == null || resetFile == null) {
if (!BauSystem.DEV_SERVER) continue;
resetFile = FALLBACK_SCHEM;
rotationCorrection = RotationCorrection.Unchanged;
}
int rotate = corner.rotate;
switch (rotationCorrection) {
@@ -25,7 +25,6 @@ import de.steamwar.bausystem.region.RegionHistory;
import de.steamwar.bausystem.region.RegionType;
import de.steamwar.bausystem.region.dynamic.*;
import de.steamwar.bausystem.region.dynamic.special.SpecialArea;
import de.steamwar.bausystem.region.dynamic.special.SpecialRegionData;
import de.steamwar.sql.GameModeConfig;
import lombok.NonNull;
import org.bukkit.Material;
@@ -53,7 +52,7 @@ public class WetRegion extends DynamicRegion {
@Override
public void init() {
area = new SpecialArea(Tile.fromXZ(minX, minZ).orElseThrow(), this, WET);
regionData = new SpecialRegionData(this);
regionData = new WetRegionData(this);
}
@Override
@@ -0,0 +1,45 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2026 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.region.dynamic.special.wet;
import de.steamwar.bausystem.region.RegionFlagPolicy;
import de.steamwar.bausystem.region.dynamic.DynamicRegion;
import de.steamwar.bausystem.region.dynamic.special.SpecialRegionData;
import de.steamwar.bausystem.region.flags.Flag;
import de.steamwar.bausystem.region.flags.ProtectMode;
import lombok.NonNull;
public class WetRegionData extends SpecialRegionData {
public WetRegionData(DynamicRegion region) {
super(region);
}
@Override
protected void initialize() {
flagMap.put(Flag.PROTECT, ProtectMode.INACTIVE);
}
@Override
public @NonNull <T extends Enum<T> & Flag.Value<T>> RegionFlagPolicy has(@NonNull Flag<T> flag) {
if (flag.oneOf(Flag.PROTECT)) return RegionFlagPolicy.NOT_APPLICABLE;
return super.has(flag);
}
}