Add TestblockScoreboardElement

Add WireframeCommand
Implement MWGPlotRegion
This commit is contained in:
2026-03-21 17:42:14 +01:00
parent b157473b99
commit 3961938b8e
5 changed files with 249 additions and 23 deletions
@@ -0,0 +1,78 @@
/*
* 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.features.region;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.region.Point;
import de.steamwar.bausystem.region.Region;
import de.steamwar.bausystem.region.RegionUtils;
import de.steamwar.bausystem.region.flags.Flag;
import de.steamwar.bausystem.region.flags.TestblockMode;
import de.steamwar.bausystem.utils.PasteBuilder;
import de.steamwar.command.SWCommand;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.util.logging.Level;
public class WireframeCommand extends SWCommand {
public WireframeCommand() {
super("wireframe");
}
@Register
public void wireframeCommand(@Validator Player p) {
Region region = regionCheck(p);
if (region == null) return;
PasteBuilder.ClipboardProvider clipboardProvider = new PasteBuilder.FileProvider(region.getBuildArea().getResetFile());
try {
PasteBuilder pasteBuilder = new PasteBuilder(clipboardProvider)
.ignoreAir(true)
.color(region.getRegionData().get(Flag.COLOR).getWithDefault());
region.getBuildArea().reset(pasteBuilder, false);
RegionUtils.message(region, "REGION_TB_DONE");
} catch (SecurityException e) {
BauSystem.MESSAGE.send("REGION_TB_ERROR", p);
Bukkit.getLogger().log(Level.WARNING, "Failed testblock", e);
}
}
private Region regionCheck(Player player) {
Region region = Region.getRegion(player.getLocation());
if (region.getRegionData().has(Flag.TESTBLOCK).isWritable() && region.getRegionData().get(Flag.TESTBLOCK).isWithDefault(TestblockMode.NO_VALUE)) {
Point minPoint = region.getArea().getMinPoint(false);
Point maxPoint = region.getArea().getMaxPoint(false);
// TODO: Check if empty!
int half = minPoint.getZ() + (maxPoint.getZ() - minPoint.getZ()) / 2;
if (player.getLocation().getBlockZ() <= half) {
region.getRegionData().set(Flag.TESTBLOCK, TestblockMode.SOUTH);
} else {
region.getRegionData().set(Flag.TESTBLOCK, TestblockMode.NORTH);
}
}
if (region.getTestblockArea().isEmpty()) {
BauSystem.MESSAGE.send("REGION_TB_NO_REGION", player);
return null;
}
return region;
}
}
@@ -20,6 +20,7 @@
package de.steamwar.bausystem.region;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.region.WireframeCommand;
import de.steamwar.bausystem.region.dynamic.*;
import de.steamwar.bausystem.region.dynamic.global.GlobalRegion;
import de.steamwar.bausystem.shared.Pair;
@@ -88,6 +89,7 @@ public class DynamicRegionSystem implements RegionSystem {
DynamicRegionRepository.loadRegions();
new DynamicRegionCommand();
new WireframeCommand();
}
@Override
@@ -19,28 +19,122 @@
package de.steamwar.bausystem.region.dynamic.modes;
import com.sk89q.worldedit.EditSession;
import de.steamwar.bausystem.region.Point;
import de.steamwar.bausystem.region.Region;
import de.steamwar.bausystem.region.dynamic.VariantSelector;
import de.steamwar.bausystem.shared.Pair;
import de.steamwar.bausystem.utils.PasteBuilder;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.NonNull;
import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.util.UUID;
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class AreaBlock implements Region.Area {
private final UUID regionIdentifier;
public enum CopyLocation {
/**
* If the CopyLocation is located in between the two Area.
*/
CENTER,
/**
* If the CopyLocation is located on the side of the Area.
*/
SIDE
}
/**
* Returns North and then South Region in the Pair.
*/
public static Pair<AreaBlock, AreaBlock> create(Region region, int yOffset, Point size, Point minExtension, Point maxExtension, CopyLocation copyLocation, int distance) {
Point regionMinPoint = region.getArea().getMinPoint(false);
Point regionMaxPoint = region.getArea().getMaxPoint(false);
int regionSizeX = regionMaxPoint.getX() - regionMinPoint.getX() + 1;
int regionSizeZ = regionMaxPoint.getZ() - regionMinPoint.getZ() + 1;
int tempSizeZ = switch (copyLocation) {
case CENTER -> size.getZ() * 2 + distance;
case SIDE -> size.getZ() + distance;
};
// Calculate Offset Region to North
int minOffsetX = regionSizeX / 2 - size.getX() / 2;
int minOffsetZ = regionSizeZ / 2 - tempSizeZ / 2;
// Calculate North Points
Point northMinPoint = regionMinPoint.add(minOffsetX, yOffset, minOffsetZ);
Point northMaxPoint = northMinPoint.add(size).subtract(1, 1, 1);
Point northMinPointExtension = northMinPoint.subtract(minExtension);
Point northMaxPointExtension = northMaxPoint.add(maxExtension);
Point northCopyPoint = switch (copyLocation) {
case CENTER -> northMinPoint.add(size.getX() / 2, 0, size.getZ());
case SIDE -> northMinPoint.add(-1, 0, size.getZ() / 2);
};
// System.out.println(northMinPoint + " " + northMaxPoint + " @ " + northCopyPoint);
// fill(northCopyPoint.add(0, -1, 0), northCopyPoint.add(0, -1, 0), Material.GOLD_BLOCK);
// fill(northMinPointExtension, northMaxPointExtension, Material.RED_STAINED_GLASS);
// fill(northMinPoint, northMaxPoint, Material.RED_WOOL);
// Calculate Offset North to South
minOffsetZ += distance;
if (copyLocation == CopyLocation.CENTER) minOffsetZ += size.getZ();
// Calculate South Points
Point southMinPoint = regionMinPoint.add(minOffsetX, yOffset, minOffsetZ);
Point southMaxPoint = southMinPoint.add(size).subtract(1, 1, 1);
Point southMinPointExtension = southMinPoint.subtract(minExtension);
Point southMaxPointExtension = southMaxPoint.add(maxExtension);
Point southCopyPoint = switch (copyLocation) {
case CENTER -> southMinPoint.add(size.getX() / 2, 0, -1);
case SIDE -> southMinPoint.add(-1, 0, size.getZ() / 2);
};
// System.out.println(southMinPoint + " " + southMaxPoint + " @ " + southCopyPoint);
// fill(southCopyPoint.add(0, -1, 0), southCopyPoint.add(0, -1, 0), Material.GOLD_BLOCK);
// fill(southMinPointExtension, southMaxPointExtension, Material.GREEN_STAINED_GLASS);
// fill(southMinPoint, southMaxPoint, Material.GREEN_WOOL);
AreaBlock northArea = new AreaBlock(region, northMinPoint, northMinPointExtension, northMaxPoint, northMaxPointExtension, northCopyPoint);
AreaBlock southArea = new AreaBlock(region, southMinPoint, southMinPointExtension, southMaxPoint, southMaxPointExtension, southCopyPoint);
return new Pair<>(northArea, southArea);
}
public static AreaBlock create(Region region, int yOffset, Point minExtension, Point maxExtension) {
return null; // TODO: Is this needed?
}
/*
private static final World WORLD = Bukkit.getWorlds().get(0);
private static void fill(Point minPoint, Point maxPoint, Material material) {
BlockData blockData = material.createBlockData();
for (int x = minPoint.getX(); x <= maxPoint.getX(); x++) {
for (int z = minPoint.getZ(); z <= maxPoint.getZ(); z++) {
for (int y = minPoint.getY(); y <= maxPoint.getY(); y++) {
WORLD.setBlockData(x, y, z, blockData);
}
}
}
}
*/
private final Region region;
private final Point minPoint;
private final Point minPointExtension;
private final Point maxPoint;
private final Point maxPointExtension;
private final Point copyPoint;
private VariantSelector selector = null;
public AreaBlock(@NonNull Region region, @NonNull Point minPoint, @NonNull Point maxPoint, @NonNull Point copyPoint) {
this.regionIdentifier = region.getID();
private AreaBlock(Region region, Point minPoint, Point minPointExtension, Point maxPoint, Point maxPointExtension, Point copyPoint) {
this.region = region;
this.minPoint = minPoint;
this.minPointExtension = minPointExtension;
this.maxPoint = maxPoint;
this.maxPointExtension = maxPointExtension;
this.copyPoint = copyPoint;
}
@@ -51,12 +145,12 @@ public class AreaBlock implements Region.Area {
@Override
public @NonNull Point getMinPoint(boolean extension) {
return minPoint;
return extension ? minPointExtension : minPoint;
}
@Override
public @NonNull Point getMaxPoint(boolean extension) {
return maxPoint;
return extension ? maxPointExtension : maxPoint;
}
@Override
@@ -67,11 +161,14 @@ public class AreaBlock implements Region.Area {
@Override
public @Nullable File getResetFile() {
if (selector == null) return null;
return selector.select(regionIdentifier, 0).orElse(null);
return selector.select(region.getID(), 0).orElse(null);
}
@Override
public void place(PasteBuilder pasteBuilder, boolean extension) {
// TODO: Implement placing!
EditSession editSession = pasteBuilder.pastePoint(copyPoint)
.run();
region.getHistory()
.remember(editSession);
}
}
@@ -19,15 +19,14 @@
package de.steamwar.bausystem.region.dynamic.modes.miniwargear;
import de.steamwar.bausystem.region.RegionBackups;
import de.steamwar.bausystem.region.RegionData;
import de.steamwar.bausystem.region.RegionHistory;
import de.steamwar.bausystem.region.RegionType;
import de.steamwar.bausystem.region.*;
import de.steamwar.bausystem.region.dynamic.*;
import de.steamwar.bausystem.region.dynamic.modes.AreaBlock;
import de.steamwar.bausystem.region.dynamic.modes.AreaTile;
import de.steamwar.bausystem.region.dynamic.modes.PlotRegionBackups;
import de.steamwar.bausystem.region.dynamic.modes.PlotRegionData;
import de.steamwar.bausystem.region.flags.Flag;
import de.steamwar.bausystem.shared.Pair;
import de.steamwar.sql.GameModeConfig;
import lombok.NonNull;
import org.bukkit.Bukkit;
@@ -45,7 +44,7 @@ import java.util.UUID;
)
public class MWGPlotRegion extends DynamicRegion {
protected static final int TILE_X = 4;
protected static final int TILE_X = 3;
protected static final int TILE_Z = 6;
private static final File DIRECTORY = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "sections/miniwargear/plot");
@@ -54,8 +53,8 @@ public class MWGPlotRegion extends DynamicRegion {
private static final VariantSelector WIREFRAME = VariantSelector.Get(new File(DIRECTORY, "wireframe"));
private final AreaTile area;
private final Area northArea;
private final Area southArea;
private final AreaBlock northArea;
private final AreaBlock southArea;
private final RegionHistory history;
private final RegionBackups backups;
@@ -65,10 +64,11 @@ public class MWGPlotRegion extends DynamicRegion {
backups = new PlotRegionBackups(this, PlotRegionData::new);
Tile tile = Tile.fromXZ(minX, minZ).orElseThrow();
area = new AreaTile(tile, TILE_X, TILE_Z, this, REGION);
// northArea = new AreaBlock();
// southArea = new AreaBlock();
northArea = Area.EMPTY; // TODO: Replace!
southArea = Area.EMPTY; // TODO: Replace!
Pair<AreaBlock, AreaBlock> pair = AreaBlock.create(this, 36, new Point(37, 26, 22), new Point(7, 0, 7), new Point(7, 7, 7), AreaBlock.CopyLocation.CENTER, 50);
northArea = pair.getKey();
southArea = pair.getValue();
regionData = new PlotRegionData(this);
finishInit();
}
@@ -87,8 +87,8 @@ public class MWGPlotRegion extends DynamicRegion {
public @NonNull Area getBuildArea() {
return switch (regionData.get(Flag.TESTBLOCK).getWithDefault()) {
case NO_VALUE -> Area.EMPTY;
case NORTH -> northArea;//.withSelector(WIREFRAME);
case SOUTH -> southArea;//.withSelector(WIREFRAME);
case NORTH -> southArea.withSelector(WIREFRAME);
case SOUTH -> northArea.withSelector(WIREFRAME);
};
}
@@ -96,8 +96,8 @@ public class MWGPlotRegion extends DynamicRegion {
public @NonNull Area getTestblockArea() {
return switch (regionData.get(Flag.TESTBLOCK).getWithDefault()) {
case NO_VALUE -> Area.EMPTY;
case NORTH -> southArea;//.withSelector(TESTBLOCK);
case SOUTH -> northArea;//.withSelector(TESTBLOCK);
case NORTH -> northArea.withSelector(TESTBLOCK);
case SOUTH -> southArea.withSelector(TESTBLOCK);
};
}