SteamWar/BauSystem
Archiviert
13
0

Merge pull request 'Add /tb extension or /tb normal to reset extension area as well' (#245) from TestblockReset into master

Reviewed-on: #245
Reviewed-by: Chaoscaot <chaoscaot444@gmail.com>
Dieser Commit ist enthalten in:
YoyoNow 2021-04-10 18:40:25 +02:00
Commit b3892b18f9
10 geänderte Dateien mit 232 neuen und 46 gelöschten Zeilen

Datei anzeigen

@ -19,12 +19,12 @@
package de.steamwar.bausystem.commands;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.bukkit.BukkitWorld;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.regions.selector.CuboidRegionSelector;
import com.sk89q.worldedit.world.World;
import de.steamwar.bausystem.world.regions.Point;
import de.steamwar.bausystem.world.regions.RegionUtils_12;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
@ -34,11 +34,7 @@ class CommandSelect_12 {
static final World BUKKITWORLD = new BukkitWorld(Bukkit.getWorlds().get(0));
static void setSelection(Player p, Point minPoint, Point maxPoint) {
WORLDEDIT_PLUGIN.getSession(p).setRegionSelector(BUKKITWORLD, new CuboidRegionSelector(BUKKITWORLD, toVector(minPoint), toVector(maxPoint)));
}
private static Vector toVector(Point point) {
return Vector.toBlockPoint(point.getX(), point.getY(), point.getZ());
WORLDEDIT_PLUGIN.getSession(p).setRegionSelector(BUKKITWORLD, new CuboidRegionSelector(BUKKITWORLD, RegionUtils_12.toVector(minPoint), RegionUtils_12.toVector(maxPoint)));
}
}

Datei anzeigen

@ -0,0 +1,32 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2020 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.world.regions;
import com.sk89q.worldedit.Vector;
import lombok.experimental.UtilityClass;
@UtilityClass
public class RegionUtils_12 {
public Vector toVector(Point point) {
return Vector.toBlockPoint(point.getX(), point.getY(), point.getZ());
}
}

Datei anzeigen

@ -20,13 +20,17 @@
package de.steamwar.bausystem.world.regions;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.BlockID;
import com.sk89q.worldedit.bukkit.BukkitWorld;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
import com.sk89q.worldedit.function.operation.Operations;
import com.sk89q.worldedit.math.transform.AffineTransform;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.session.ClipboardHolder;
import com.sk89q.worldedit.world.World;
import org.bukkit.Bukkit;
@ -40,7 +44,7 @@ class Region_12 {
private Region_12() {
}
static EditSession paste(File file, int x, int y, int z, boolean rotate, boolean ignoreAir) {
static EditSession paste(File file, int x, int y, int z, PasteOptions pasteOptions) throws MaxChangedBlocksException {
World w = new BukkitWorld(Bukkit.getWorlds().get(0));
Clipboard clipboard;
try {
@ -49,17 +53,17 @@ class Region_12 {
throw new SecurityException("Bausystem schematic not found", e);
}
return paste(clipboard, x, y, z, rotate, ignoreAir);
return paste(clipboard, x, y, z, pasteOptions);
}
static EditSession paste(Clipboard clipboard, int x, int y, int z, boolean rotate, boolean ignoreAir) {
static EditSession paste(Clipboard clipboard, int x, int y, int z, PasteOptions pasteOptions) throws MaxChangedBlocksException {
World w = new BukkitWorld(Bukkit.getWorlds().get(0));
Vector dimensions = clipboard.getDimensions();
Vector v = new Vector(x, y, z);
Vector offset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin());
AffineTransform aT = new AffineTransform();
if (rotate) {
if (pasteOptions.isRotate()) {
aT = aT.rotateY(180);
v = v.add(dimensions.getX() / 2 + dimensions.getX() % 2, 0, dimensions.getZ() / 2 + dimensions.getZ() % 2).subtract(offset.multiply(-1, 1, -1)).subtract(1, 0, 1);
} else {
@ -69,7 +73,11 @@ class Region_12 {
EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(w, -1);
ClipboardHolder ch = new ClipboardHolder(clipboard, w.getWorldData());
ch.setTransform(aT);
Operations.completeBlindly(ch.createPaste(e, w.getWorldData()).to(v).ignoreAirBlocks(ignoreAir).build());
if (pasteOptions.isReset()) {
e.setBlocks(new CuboidRegion(RegionUtils_12.toVector(pasteOptions.getMinPoint()), RegionUtils_12.toVector(pasteOptions.getMaxPoint())), new BaseBlock(BlockID.AIR));
}
Operations.completeBlindly(ch.createPaste(e, w.getWorldData()).to(v).ignoreAirBlocks(pasteOptions.isIgnoreAir()).build());
return e;
}
}

Datei anzeigen

@ -21,10 +21,10 @@ package de.steamwar.bausystem.commands;
import com.sk89q.worldedit.bukkit.BukkitWorld;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.selector.CuboidRegionSelector;
import com.sk89q.worldedit.world.World;
import de.steamwar.bausystem.world.regions.Point;
import de.steamwar.bausystem.world.regions.RegionUtils_15;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
@ -34,11 +34,7 @@ class CommandSelect_15 {
static final World BUKKITWORLD = new BukkitWorld(Bukkit.getWorlds().get(0));
static void setSelection(Player p, Point minPoint, Point maxPoint) {
WORLDEDIT_PLUGIN.getSession(p).setRegionSelector(BUKKITWORLD, new CuboidRegionSelector(BUKKITWORLD, toBlockVector3(minPoint), toBlockVector3(maxPoint)));
}
private static BlockVector3 toBlockVector3(Point point) {
return BlockVector3.at(point.getX(), point.getY(), point.getZ());
WORLDEDIT_PLUGIN.getSession(p).setRegionSelector(BUKKITWORLD, new CuboidRegionSelector(BUKKITWORLD, RegionUtils_15.toBlockVector3(minPoint), RegionUtils_15.toBlockVector3(maxPoint)));
}
}

Datei anzeigen

@ -0,0 +1,32 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2020 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.world.regions;
import com.sk89q.worldedit.math.BlockVector3;
import lombok.experimental.UtilityClass;
@UtilityClass
public class RegionUtils_15 {
public BlockVector3 toBlockVector3(Point point) {
return BlockVector3.at(point.getX(), point.getY(), point.getZ());
}
}

Datei anzeigen

@ -29,25 +29,25 @@ import com.sk89q.worldedit.extent.clipboard.io.ClipboardReader;
import com.sk89q.worldedit.function.operation.Operations;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.transform.AffineTransform;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.session.ClipboardHolder;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes;
import de.steamwar.bausystem.world.Color;
import org.bukkit.Bukkit;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Objects;
import de.steamwar.bausystem.world.Color;
import org.bukkit.Bukkit;
class Region_15 {
private Region_15() {
}
static EditSession paste(File file, int x, int y, int z, boolean rotate, boolean ignoreAir, Color color) {
static EditSession paste(File file, int x, int y, int z, PasteOptions pasteOptions) {
Clipboard clipboard;
try (ClipboardReader reader = Objects.requireNonNull(ClipboardFormats.findByFile(file)).getReader(new FileInputStream(file))) {
clipboard = reader.read();
@ -55,25 +55,28 @@ class Region_15 {
throw new SecurityException("Bausystem schematic not found", e);
}
return paste(clipboard, x, y, z, rotate, ignoreAir, color);
return paste(clipboard, x, y, z, pasteOptions);
}
static EditSession paste(Clipboard clipboard, int x, int y, int z, boolean rotate, boolean ignoreAir, Color color) {
static EditSession paste(Clipboard clipboard, int x, int y, int z, PasteOptions pasteOptions) {
try (EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorlds().get(0)), -1)) {
changeColor(clipboard, color);
changeColor(clipboard, pasteOptions.getColor());
ClipboardHolder ch = new ClipboardHolder(clipboard);
BlockVector3 dimensions = clipboard.getDimensions();
BlockVector3 v = BlockVector3.at(x, y, z);
BlockVector3 offset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin());
if (rotate) {
if (pasteOptions.isRotate()) {
ch.setTransform(new AffineTransform().rotateY(180));
v = v.add(dimensions.getX() / 2, 0, dimensions.getZ() / 2).subtract(offset.multiply(-1, 1, -1)).subtract(1, 0, 1);
} else {
v = v.subtract(dimensions.getX() / 2, 0, dimensions.getZ() / 2).subtract(offset);
}
Operations.completeBlindly(ch.createPaste(e).to(v).ignoreAirBlocks(ignoreAir).build());
if (pasteOptions.isReset()) {
e.setBlocks(new CuboidRegion(RegionUtils_15.toBlockVector3(pasteOptions.getMinPoint()), RegionUtils_15.toBlockVector3(pasteOptions.getMaxPoint())), BlockTypes.AIR.getDefaultState().toBaseBlock());
}
Operations.completeBlindly(ch.createPaste(e).to(v).ignoreAirBlocks(pasteOptions.isIgnoreAir()).build());
return e;
} catch (WorldEditException e) {
throw new SecurityException(e.getMessage(), e);

Datei anzeigen

@ -0,0 +1,94 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2020 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.world.regions;
import de.steamwar.bausystem.world.Color;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class PasteOptions {
/**
* Used in 1.12 and 1.15
*/
private boolean rotate = false;
/**
* Used in 1.12 and 1.15
*/
private boolean ignoreAir = false;
/**
* Used in 1.15
*/
private Color color = Color.YELLOW;
/**
* Used in 1.15
*/
private boolean reset = false;
/**
* Used in 1.15
*/
private Point minPoint = null;
/**
* Used in 1.15
*/
private Point maxPoint = null;
public PasteOptions(boolean rotate) {
this.rotate = rotate;
}
public PasteOptions(boolean rotate, Color color) {
this.rotate = rotate;
this.color = color;
}
public PasteOptions(boolean rotate, boolean ignoreAir) {
this.rotate = rotate;
this.ignoreAir = ignoreAir;
}
public PasteOptions(boolean rotate, boolean ignoreAir, boolean reset) {
this.rotate = rotate;
this.ignoreAir = ignoreAir;
this.reset = reset;
}
public PasteOptions(boolean rotate, Color color, boolean reset) {
this.rotate = rotate;
this.color = color;
this.reset = reset;
}
public PasteOptions(boolean rotate, boolean ignoreAir, Color color) {
this.rotate = rotate;
this.ignoreAir = ignoreAir;
this.color = color;
}
}

Datei anzeigen

@ -23,6 +23,7 @@ import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.world.regions.Region;
import de.steamwar.bausystem.world.Welt;
import de.steamwar.bausystem.world.regions.RegionExtensionType;
import de.steamwar.command.SWCommand;
import de.steamwar.sql.Schematic;
import org.bukkit.Bukkit;
@ -45,11 +46,16 @@ public class CommandTestblock extends SWCommand {
@Register
public void genericTestblockCommand(Player p) {
genericTestblockCommand(p, RegionExtensionType.NORMAL);
}
@Register
public void genericTestblockCommand(Player p, RegionExtensionType regionExtensionType) {
if (!permissionCheck(p)) return;
Region region = regionCheck(p);
if (region == null) return;
try {
region.resetTestblock(null);
region.resetTestblock(null, regionExtensionType == RegionExtensionType.EXTENSION);
p.sendMessage(BauSystem.PREFIX + "§7Testblock zurückgesetzt");
} catch (IOException e) {
p.sendMessage(BauSystem.PREFIX + "§cFehler beim Zurücksetzen des Testblocks");
@ -57,8 +63,19 @@ public class CommandTestblock extends SWCommand {
}
}
@Register
public void schematicTestblockCommand(Player p, String s) {
schematicTestblockCommand(p, s, RegionExtensionType.NORMAL);
}
@Register
public void schematicTestblockCommand(Player p, RegionExtensionType regionExtensionType, String s) {
schematicTestblockCommand(p, s, regionExtensionType);
}
@Register
public void schematicTestblockCommand(Player p, String s, RegionExtensionType regionExtensionType) {
if (!permissionCheck(p)) return;
Region region = regionCheck(p);
if (region == null) return;
@ -68,7 +85,7 @@ public class CommandTestblock extends SWCommand {
return;
}
try {
region.resetTestblock(schem);
region.resetTestblock(schem, regionExtensionType == RegionExtensionType.EXTENSION);
p.sendMessage(BauSystem.PREFIX + "§7Testblock zurückgesetzt");
} catch (IOException e) {
p.sendMessage(BauSystem.PREFIX + "§cFehler beim Zurücksetzen des Testblocks");

Datei anzeigen

@ -145,16 +145,24 @@ public class Prototype {
}
public EditSession reset(Region region, Schematic schem, boolean ignoreAir, Color color) throws IOException, NoClipboardException {
return reset(region, schem, ignoreAir, color, false);
}
public EditSession reset(Region region, Schematic schem, boolean ignoreAir, Color color, boolean reset) throws IOException, NoClipboardException {
PasteOptions pasteOptions;
if (reset) {
pasteOptions = new PasteOptions(rotate ^ (schem != null && (schem.getSchemType().fightType() || schem.getSchemType().check())), ignoreAir, color, true, getMinPoint(region, RegionExtensionType.EXTENSION), getMaxPoint(region, RegionExtensionType.EXTENSION));
} else {
pasteOptions = new PasteOptions(rotate ^ (schem != null && (schem.getSchemType().fightType() || schem.getSchemType().check())), ignoreAir, color);
}
int x = region.minPoint.getX() + offsetX + sizeX / 2;
int y = region.minPoint.getY() + offsetY;
int z = region.minPoint.getZ() + offsetZ + sizeZ / 2;
if (schem == null) {
return paste(new File(schematic), x, y, z, rotate, ignoreAir, color);
return paste(new File(schematic), x, y, z, pasteOptions);
} else {
if (schem.getSchemType().fightType() || schem.getSchemType().check()) {
return paste(schem.load(), x, y, z, !rotate, ignoreAir, color);
}
return paste(schem.load(), x, y, z, rotate, ignoreAir, color);
return paste(schem.load(), x, y, z, pasteOptions);
}
}
@ -167,9 +175,9 @@ public class Prototype {
int y = region.minPoint.getY() + testblock.offsetY - 1;
int z = region.minPoint.getZ() + offsetZ + sizeZ / 2;
if (schem == null) {
return paste(new File(protectSchematic), x, y, z, rotate, false, Color.YELLOW);
return paste(new File(protectSchematic), x, y, z, new PasteOptions(rotate, false, Color.YELLOW));
} else {
return paste(schem.load(), x, y, z, rotate, false, Color.YELLOW);
return paste(schem.load(), x, y, z, new PasteOptions(rotate, false, Color.YELLOW));
}
}
@ -177,21 +185,21 @@ public class Prototype {
return testblock != null;
}
public EditSession resetTestblock(Region region, Schematic schem, Color color) throws IOException, NoClipboardException {
return testblock.reset(region, schem, false, color);
public EditSession resetTestblock(Region region, Schematic schem, Color color, boolean reset) throws IOException, NoClipboardException {
return testblock.reset(region, schem, false, color, reset);
}
private static boolean inRange(double l, int min, int size) {
return min <= l && l < min + size;
}
private static EditSession paste(File file, int x, int y, int z, boolean rotate, boolean ignoreAir, Color color) { //Type of protect
return (EditSession) VersionedCallable.call(new VersionedCallable(() -> Region_12.paste(file, x, y, z, rotate, ignoreAir), 8),
new VersionedCallable(() -> Region_15.paste(file, x, y, z, rotate, ignoreAir, color), 15));
private static EditSession paste(File file, int x, int y, int z, PasteOptions pasteOptions) { //Type of protect
return (EditSession) VersionedCallable.call(new VersionedCallable(() -> Region_12.paste(file, x, y, z, pasteOptions), 8),
new VersionedCallable(() -> Region_15.paste(file, x, y, z, pasteOptions), 15));
}
private static EditSession paste(Clipboard clipboard, int x, int y, int z, boolean rotate, boolean ignoreAir, Color color) {
return (EditSession) VersionedCallable.call(new VersionedCallable(() -> Region_12.paste(clipboard, x, y, z, rotate, ignoreAir), 8),
new VersionedCallable(() -> Region_15.paste(clipboard, x, y, z, rotate, ignoreAir, color), 15));
private static EditSession paste(Clipboard clipboard, int x, int y, int z, PasteOptions pasteOptions) {
return (EditSession) VersionedCallable.call(new VersionedCallable(() -> Region_12.paste(clipboard, x, y, z, pasteOptions), 8),
new VersionedCallable(() -> Region_15.paste(clipboard, x, y, z, pasteOptions), 15));
}
}

Datei anzeigen

@ -296,9 +296,9 @@ public class Region {
return prototype.hasTestblock();
}
public void resetTestblock(Schematic schem) throws IOException, NoClipboardException {
public void resetTestblock(Schematic schem, boolean reset) throws IOException, NoClipboardException {
initSessions();
undosessions.push(prototype.resetTestblock(this, schem, color));
undosessions.push(prototype.resetTestblock(this, schem, color, reset));
}
public boolean hasProtection() {