SteamWar/BauSystem
Archiviert
13
0

Add '/rg restore' to restore broken blocks not self set ones #235

Manuell gemergt
YoyoNow hat 2 Commits von RestoreCommand nach master 2021-04-04 21:32:00 +02:00 zusammengeführt
4 geänderte Dateien mit 66 neuen und 25 gelöschten Zeilen

Datei anzeigen

@ -40,7 +40,7 @@ class Region_12 {
private Region_12() { private Region_12() {
} }
static EditSession paste(File file, int x, int y, int z, boolean rotate) { static EditSession paste(File file, int x, int y, int z, boolean rotate, boolean ignoreAir) {
World w = new BukkitWorld(Bukkit.getWorlds().get(0)); World w = new BukkitWorld(Bukkit.getWorlds().get(0));
Clipboard clipboard; Clipboard clipboard;
try { try {
@ -49,10 +49,10 @@ class Region_12 {
throw new SecurityException("Bausystem schematic not found", e); throw new SecurityException("Bausystem schematic not found", e);
} }
return paste(clipboard, x, y, z, rotate); return paste(clipboard, x, y, z, rotate, ignoreAir);
} }
static EditSession paste(Clipboard clipboard, int x, int y, int z, boolean rotate) { static EditSession paste(Clipboard clipboard, int x, int y, int z, boolean rotate, boolean ignoreAir) {
World w = new BukkitWorld(Bukkit.getWorlds().get(0)); World w = new BukkitWorld(Bukkit.getWorlds().get(0));
Vector dimensions = clipboard.getDimensions(); Vector dimensions = clipboard.getDimensions();
@ -69,7 +69,7 @@ class Region_12 {
EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(w, -1); EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(w, -1);
ClipboardHolder ch = new ClipboardHolder(clipboard, w.getWorldData()); ClipboardHolder ch = new ClipboardHolder(clipboard, w.getWorldData());
ch.setTransform(aT); ch.setTransform(aT);
Operations.completeBlindly(ch.createPaste(e, w.getWorldData()).to(v).build()); Operations.completeBlindly(ch.createPaste(e, w.getWorldData()).to(v).ignoreAirBlocks(ignoreAir).build());
return e; return e;
} }
} }

Datei anzeigen

@ -42,7 +42,7 @@ class Region_15 {
private Region_15() { private Region_15() {
} }
static EditSession paste(File file, int x, int y, int z, boolean rotate) { static EditSession paste(File file, int x, int y, int z, boolean rotate, boolean ignoreAir) {
Clipboard clipboard; Clipboard clipboard;
try (ClipboardReader reader = Objects.requireNonNull(ClipboardFormats.findByFile(file)).getReader(new FileInputStream(file))) { try (ClipboardReader reader = Objects.requireNonNull(ClipboardFormats.findByFile(file)).getReader(new FileInputStream(file))) {
clipboard = reader.read(); clipboard = reader.read();
@ -50,10 +50,10 @@ class Region_15 {
throw new SecurityException("Bausystem schematic not found", e); throw new SecurityException("Bausystem schematic not found", e);
} }
return paste(clipboard, x, y, z, rotate); return paste(clipboard, x, y, z, rotate, ignoreAir);
} }
static EditSession paste(Clipboard clipboard, int x, int y, int z, boolean rotate) { static EditSession paste(Clipboard clipboard, int x, int y, int z, boolean rotate, boolean ignoreAir) {
try (EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorlds().get(0)), -1)) { try (EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorlds().get(0)), -1)) {
ClipboardHolder ch = new ClipboardHolder(clipboard); ClipboardHolder ch = new ClipboardHolder(clipboard);
BlockVector3 dimensions = clipboard.getDimensions(); BlockVector3 dimensions = clipboard.getDimensions();
@ -66,7 +66,7 @@ class Region_15 {
v = v.subtract(dimensions.getX() / 2 - dimensions.getX() % 2, 0, dimensions.getZ() / 2 - dimensions.getZ() % 2).subtract(offset); v = v.subtract(dimensions.getX() / 2 - dimensions.getX() % 2, 0, dimensions.getZ() / 2 - dimensions.getZ() % 2).subtract(offset);
} }
Operations.completeBlindly(ch.createPaste(e).to(v).build()); Operations.completeBlindly(ch.createPaste(e).to(v).ignoreAirBlocks(ignoreAir).build());
return e; return e;
} }
} }

Datei anzeigen

@ -5,8 +5,13 @@ import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.world.Region; import de.steamwar.bausystem.world.Region;
import de.steamwar.bausystem.world.Welt; import de.steamwar.bausystem.world.Welt;
import de.steamwar.command.SWCommand; import de.steamwar.command.SWCommand;
import de.steamwar.sql.Schematic;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.io.IOException;
import java.util.logging.Level;
public class CommandRegion extends SWCommand { public class CommandRegion extends SWCommand {
public CommandRegion() { public CommandRegion() {
@ -50,6 +55,43 @@ public class CommandRegion extends SWCommand {
} }
} }
@Register("restore")
public void genericRestoreCommand(Player p) {
if (!permissionCheck(p)) return;
Region region = Region.getRegion(p.getLocation());
if(checkGlobalRegion(region, p)) return;
if (region == null) return;
try {
region.reset(null, true);
p.sendMessage(BauSystem.PREFIX + "§7Region zurückgesetzt");
} catch (IOException e) {
p.sendMessage(BauSystem.PREFIX + "§cFehler beim Zurücksetzen der Region");
Bukkit.getLogger().log(Level.WARNING, "Failed testblock", e);
}
}
@Register("restore")
public void schematicRestoreCommand(Player p, String s) {
if (!permissionCheck(p)) return;
Region region = Region.getRegion(p.getLocation());
if(checkGlobalRegion(region, p)) return;
if (region == null) return;
Schematic schem = Schematic.getSchemFromDB(s, p.getUniqueId());
if (schem == null) {
p.sendMessage(BauSystem.PREFIX + "§cSchematic nicht gefunden");
return;
}
try {
region.reset(schem, true);
p.sendMessage(BauSystem.PREFIX + "§7Region zurückgesetzt");
} catch (IOException e) {
p.sendMessage(BauSystem.PREFIX + "§cFehler beim Zurücksetzen der Region");
Bukkit.getLogger().log(Level.WARNING, "Failed reset", e);
}
}
static boolean checkGlobalRegion(Region region, Player p) { static boolean checkGlobalRegion(Region region, Player p) {
if(Region.GlobalRegion.isGlobalRegion(region)) { if(Region.GlobalRegion.isGlobalRegion(region)) {
p.sendMessage(BauSystem.PREFIX + "§cDu bist in keiner Region"); p.sendMessage(BauSystem.PREFIX + "§cDu bist in keiner Region");

Datei anzeigen

@ -174,14 +174,13 @@ public class Region {
return prototype.buildArea.inRegionExtension(this, l); return prototype.buildArea.inRegionExtension(this, l);
} }
public void reset() throws IOException { public void reset(Schematic schem) throws IOException, NoClipboardException {
initSessions(); reset(schem, false);
undosessions.push(prototype.reset(this, null));
} }
public void reset(Schematic schem) throws IOException, NoClipboardException { public void reset(Schematic schem, boolean ignoreAir) throws IOException, NoClipboardException {
initSessions(); initSessions();
undosessions.push(prototype.reset(this, schem)); undosessions.push(prototype.reset(this, schem, ignoreAir));
} }
public boolean hasTestblock() { public boolean hasTestblock() {
@ -368,14 +367,14 @@ public class Region {
inRange(l.getZ(), region.minZ + offsetZ - extensionNegativeZ, sizeZ + extensionNegativeZ + extensionPositiveZ); inRange(l.getZ(), region.minZ + offsetZ - extensionNegativeZ, sizeZ + extensionNegativeZ + extensionPositiveZ);
} }
public EditSession reset(Region region, Schematic schem) throws IOException, NoClipboardException { public EditSession reset(Region region, Schematic schem, boolean ignoreAir) throws IOException, NoClipboardException {
int x = region.minX + offsetX + sizeX / 2; int x = region.minX + offsetX + sizeX / 2;
int y = region.minY + offsetY; int y = region.minY + offsetY;
int z = region.minZ + offsetZ + sizeZ / 2; int z = region.minZ + offsetZ + sizeZ / 2;
if (schem == null) if (schem == null)
return paste(new File(schematic), x, y, z, rotate); return paste(new File(schematic), x, y, z, rotate, ignoreAir);
else else
return paste(schem.load(), x, y, z, rotate); return paste(schem.load(), x, y, z, rotate, ignoreAir);
} }
public boolean hasProtection() { public boolean hasProtection() {
@ -387,9 +386,9 @@ public class Region {
int y = region.minY + testblock.offsetY - 1; int y = region.minY + testblock.offsetY - 1;
int z = region.minZ + offsetZ + sizeZ / 2; int z = region.minZ + offsetZ + sizeZ / 2;
if (schem == null) if (schem == null)
return paste(new File(protectSchematic), x, y, z, rotate); return paste(new File(protectSchematic), x, y, z, rotate, false);
else else
return paste(schem.load(), x, y, z, rotate); return paste(schem.load(), x, y, z, rotate, false);
} }
public boolean hasTestblock() { public boolean hasTestblock() {
@ -397,21 +396,21 @@ public class Region {
} }
public EditSession resetTestblock(Region region, Schematic schem) throws IOException, NoClipboardException { public EditSession resetTestblock(Region region, Schematic schem) throws IOException, NoClipboardException {
return testblock.reset(region, schem); return testblock.reset(region, schem, false);
} }
private static boolean inRange(double l, int min, int size) { private static boolean inRange(double l, int min, int size) {
return min <= l && l < min + size; return min <= l && l < min + size;
} }
private static EditSession paste(File file, int x, int y, int z, boolean rotate) { //Type of protect private static EditSession paste(File file, int x, int y, int z, boolean rotate, boolean ignoreAir) { //Type of protect
return (EditSession) VersionedCallable.call(new VersionedCallable(() -> Region_12.paste(file, x, y, z, rotate), 8), 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), 15)); new VersionedCallable(() -> Region_15.paste(file, x, y, z, rotate, ignoreAir), 15));
} }
private static EditSession paste(Clipboard clipboard, int x, int y, int z, boolean rotate) { private static EditSession paste(Clipboard clipboard, int x, int y, int z, boolean rotate, boolean ignoreAir) {
return (EditSession) VersionedCallable.call(new VersionedCallable(() -> Region_12.paste(clipboard, x, y, z, rotate), 8), 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), 15)); new VersionedCallable(() -> Region_15.paste(clipboard, x, y, z, rotate, ignoreAir), 15));
} }
} }
} }