forked from SteamWar/SteamWar
Fix WetRegion -> WetRegionData
Fix DynamicRegionSystem.get Add Fallback.schem for PathArea
This commit is contained in:
+28
-4
@@ -21,13 +21,17 @@ package de.steamwar.bausystem.region;
|
|||||||
|
|
||||||
import de.steamwar.bausystem.features.region.RegionCommand;
|
import de.steamwar.bausystem.features.region.RegionCommand;
|
||||||
import de.steamwar.bausystem.region.dynamic.DynamicRegion;
|
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.Tile;
|
||||||
import de.steamwar.bausystem.region.dynamic.path.PathRegion;
|
|
||||||
import de.steamwar.bausystem.utils.PasteBuilder;
|
import de.steamwar.bausystem.utils.PasteBuilder;
|
||||||
import de.steamwar.command.AbstractSWCommand;
|
import de.steamwar.command.AbstractSWCommand;
|
||||||
|
import de.steamwar.command.PreviousArguments;
|
||||||
import de.steamwar.command.SWCommand;
|
import de.steamwar.command.SWCommand;
|
||||||
|
import de.steamwar.command.TypeMapper;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@AbstractSWCommand.PartOf(RegionCommand.class)
|
@AbstractSWCommand.PartOf(RegionCommand.class)
|
||||||
@@ -38,16 +42,17 @@ public class DynamicRegionCommand extends SWCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Register({"dynamic", "place"})
|
@Register({"dynamic", "place"})
|
||||||
public void placeRegion(Player player) {
|
public void placeRegion(Player player, @Mapper("regionType") String regionType) {
|
||||||
Region region = DynamicRegionSystem.INSTANCE.get(player.getLocation());
|
Region region = DynamicRegionSystem.INSTANCE.get(player.getLocation());
|
||||||
if (!region.getType().isGlobal()) return;
|
if (!region.getType().isGlobal()) return;
|
||||||
Tile tile = Tile.fromLocation(player.getLocation()).orElse(null);
|
Tile tile = Tile.fromLocation(player.getLocation()).orElse(null);
|
||||||
if (tile == null) return;
|
if (tile == null) return;
|
||||||
|
|
||||||
// TODO: Replace!
|
Class<? extends DynamicRegion> regionClass = DynamicRegionSystem.identifierDataMap.get(regionType);
|
||||||
PathRegion dynamicRegion = new PathRegion(UUID.randomUUID(), tile.getMinX(), tile.getMinZ());
|
DynamicRegion dynamicRegion = DynamicRegionRepository.constructRegion(regionClass, UUID.randomUUID(), tile.getMinX(), tile.getMinZ());
|
||||||
|
|
||||||
dynamicRegion.getArea().reset(new PasteBuilder(new PasteBuilder.FileProvider(dynamicRegion.getArea().getResetFile())), false);
|
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));
|
DynamicRegionSystem.INSTANCE.getNeighbours(dynamicRegion).forEach(r -> r.update(dynamicRegion));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,4 +62,23 @@ public class DynamicRegionCommand extends SWCommand {
|
|||||||
if (!region.getType().isDeletable()) return;
|
if (!region.getType().isDeletable()) return;
|
||||||
((DynamicRegion) region).delete();
|
((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();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-1
@@ -118,7 +118,9 @@ public class DynamicRegionSystem implements RegionSystem {
|
|||||||
.filter(rg -> rg.getArea().inRegion(x, z, false))
|
.filter(rg -> rg.getArea().inRegion(x, z, false))
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.orElseGet(this::getGlobalRegion);
|
.orElseGet(this::getGlobalRegion);
|
||||||
regionCache.put(tile.getId(), region);
|
if (fastCache || regions.contains(region)) {
|
||||||
|
regionCache.put(tile.getId(), region);
|
||||||
|
}
|
||||||
return region;
|
return region;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+17
-13
@@ -144,21 +144,25 @@ public class DynamicRegionRepository {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Location minTileLocation = tile.getMinLocation();
|
Location minTileLocation = tile.getMinLocation();
|
||||||
|
constructRegion(regionClass, regionUUID, minTileLocation.getBlockX(), minTileLocation.getBlockZ());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Constructor<? extends DynamicRegion> regionConstructor;
|
public static DynamicRegion constructRegion(Class<? extends DynamicRegion> clazz, UUID uuid, int minX, int minZ) {
|
||||||
try {
|
Constructor<? extends DynamicRegion> regionConstructor;
|
||||||
regionConstructor = regionClass.getConstructor(UUID.class, int.class, int.class);
|
try {
|
||||||
} catch (NoSuchMethodException e) {
|
regionConstructor = clazz.getConstructor(UUID.class, int.class, int.class);
|
||||||
RegionSystem.LOGGER.log(Level.SEVERE, "Failed to read region metadata file (region constructor not found)");
|
} catch (NoSuchMethodException e) {
|
||||||
continue;
|
RegionSystem.LOGGER.log(Level.SEVERE, "Failed to read region metadata file (region constructor not found)");
|
||||||
}
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
regionConstructor.newInstance(regionUUID, minTileLocation.getBlockX(), minTileLocation.getBlockZ());
|
return regionConstructor.newInstance(uuid, minX, minZ);
|
||||||
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException |
|
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException |
|
||||||
InvocationTargetException e) {
|
InvocationTargetException e) {
|
||||||
RegionSystem.LOGGER.log(Level.SEVERE, "Failed to read region metadata file (invalid data)");
|
RegionSystem.LOGGER.log(Level.SEVERE, "Failed to read region metadata file (invalid data)");
|
||||||
}
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+13
-8
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.region.dynamic.path;
|
package de.steamwar.bausystem.region.dynamic.path;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.bausystem.region.DynamicRegionSystem;
|
import de.steamwar.bausystem.region.DynamicRegionSystem;
|
||||||
import de.steamwar.bausystem.region.Point;
|
import de.steamwar.bausystem.region.Point;
|
||||||
import de.steamwar.bausystem.region.Region;
|
import de.steamwar.bausystem.region.Region;
|
||||||
@@ -42,6 +43,7 @@ import static de.steamwar.bausystem.region.RegionType.ConnectionType.*;
|
|||||||
public class PathArea implements Region.Area {
|
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 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 CENTER_NORMAL = VariantSelector.Get(new File(PATH_DIR, "center/normal"));
|
||||||
private static final VariantSelector SIDE_GLOBAL = VariantSelector.Get(new File(PATH_DIR, "side/global"));
|
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()) {
|
for (Side side : Side.values()) {
|
||||||
VariantSelector selector = SELECTOR_SIDE.Select(tile, side);
|
VariantSelector selector = SELECTOR_SIDE.Select(tile, side);
|
||||||
if (selector == null) continue;
|
if (selector != null) resetFile = selector.select(regionIdentifier, side.ordinal() + side.rotate).orElse(null);
|
||||||
|
if (selector == null || resetFile == null) {
|
||||||
resetFile = selector.select(regionIdentifier, side.ordinal() + side.rotate).orElse(null);
|
if (!BauSystem.DEV_SERVER) continue;
|
||||||
if (resetFile == null) continue;
|
resetFile = FALLBACK_SCHEM;
|
||||||
|
}
|
||||||
|
|
||||||
PasteUtils.paste(resetFile, minPoint.add(side.pasteOffsetX, 0, side.pasteOffsetZ), side.rotate);
|
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()) {
|
for (Corner corner : Corner.values()) {
|
||||||
Pair<VariantSelector, RotationCorrection> pair = SELECTOR_CORNER.Select(tile, corner);
|
Pair<VariantSelector, RotationCorrection> pair = SELECTOR_CORNER.Select(tile, corner);
|
||||||
VariantSelector selector = pair.getKey();
|
VariantSelector selector = pair.getKey();
|
||||||
if (selector == null) continue;
|
|
||||||
RotationCorrection rotationCorrection = pair.getValue();
|
RotationCorrection rotationCorrection = pair.getValue();
|
||||||
|
if (selector != null) resetFile = selector.select(regionIdentifier, corner.side1.ordinal() * corner.side2.ordinal() + corner.side1.rotate * corner.side2.rotate).orElse(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 (resetFile == null) continue;
|
if (!BauSystem.DEV_SERVER) continue;
|
||||||
|
resetFile = FALLBACK_SCHEM;
|
||||||
|
rotationCorrection = RotationCorrection.Unchanged;
|
||||||
|
}
|
||||||
|
|
||||||
int rotate = corner.rotate;
|
int rotate = corner.rotate;
|
||||||
switch (rotationCorrection) {
|
switch (rotationCorrection) {
|
||||||
|
|||||||
+1
-2
@@ -25,7 +25,6 @@ import de.steamwar.bausystem.region.RegionHistory;
|
|||||||
import de.steamwar.bausystem.region.RegionType;
|
import de.steamwar.bausystem.region.RegionType;
|
||||||
import de.steamwar.bausystem.region.dynamic.*;
|
import de.steamwar.bausystem.region.dynamic.*;
|
||||||
import de.steamwar.bausystem.region.dynamic.special.SpecialArea;
|
import de.steamwar.bausystem.region.dynamic.special.SpecialArea;
|
||||||
import de.steamwar.bausystem.region.dynamic.special.SpecialRegionData;
|
|
||||||
import de.steamwar.sql.GameModeConfig;
|
import de.steamwar.sql.GameModeConfig;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@@ -53,7 +52,7 @@ public class WetRegion extends DynamicRegion {
|
|||||||
@Override
|
@Override
|
||||||
public void init() {
|
public void init() {
|
||||||
area = new SpecialArea(Tile.fromXZ(minX, minZ).orElseThrow(), this, WET);
|
area = new SpecialArea(Tile.fromXZ(minX, minZ).orElseThrow(), this, WET);
|
||||||
regionData = new SpecialRegionData(this);
|
regionData = new WetRegionData(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+45
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user