SteamWar/BauSystem2.0
Archiviert
12
0

Add /rgc and /rgp and /region copy and /region paste
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
yoyosource 2024-04-07 16:39:00 +02:00
Ursprung 9b70f2b365
Commit e7438029b0
6 geänderte Dateien mit 144 neuen und 9 gelöschten Zeilen

Datei anzeigen

@ -106,6 +106,7 @@ public class FlatteningWrapper15 implements FlatteningWrapper {
private static final WorldEditPlugin WORLDEDIT_PLUGIN = Objects.requireNonNull((WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit")); private static final WorldEditPlugin WORLDEDIT_PLUGIN = Objects.requireNonNull((WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit"));
private static final World BUKKITWORLD = new BukkitWorld(Bukkit.getWorlds().get(0)); private static final World BUKKITWORLD = new BukkitWorld(Bukkit.getWorlds().get(0));
@Override @Override
public void setSelection(Player p, Point minPoint, Point maxPoint) { public void setSelection(Player p, Point minPoint, Point maxPoint) {
WORLDEDIT_PLUGIN.getSession(p).setRegionSelector(BUKKITWORLD, new CuboidRegionSelector(BUKKITWORLD, toBlockVector3(minPoint), toBlockVector3(maxPoint))); WORLDEDIT_PLUGIN.getSession(p).setRegionSelector(BUKKITWORLD, new CuboidRegionSelector(BUKKITWORLD, toBlockVector3(minPoint), toBlockVector3(maxPoint)));
@ -190,7 +191,7 @@ public class FlatteningWrapper15 implements FlatteningWrapper {
} }
@Override @Override
public boolean backup(Point minPoint, Point maxPoint, File file) { public Clipboard copy(Point minPoint, Point maxPoint, Point copyPoint) {
BukkitWorld bukkitWorld = new BukkitWorld(Bukkit.getWorlds().get(0)); BukkitWorld bukkitWorld = new BukkitWorld(Bukkit.getWorlds().get(0));
CuboidRegion region = new CuboidRegion(bukkitWorld, toBlockVector3(minPoint), toBlockVector3(maxPoint)); CuboidRegion region = new CuboidRegion(bukkitWorld, toBlockVector3(minPoint), toBlockVector3(maxPoint));
BlockArrayClipboard clipboard = new BlockArrayClipboard(region); BlockArrayClipboard clipboard = new BlockArrayClipboard(region);
@ -203,12 +204,21 @@ public class FlatteningWrapper15 implements FlatteningWrapper {
copy.setCopyingBiomes(false); copy.setCopyingBiomes(false);
Operations.complete(copy); Operations.complete(copy);
clipboard.setOrigin(toBlockVector3(copyPoint));
return clipboard;
} catch (WorldEditException e) {
Bukkit.getLogger().log(Level.SEVERE, e.getMessage(), e);
return null;
}
}
try (ClipboardWriter writer = BuiltInClipboardFormat.SPONGE_SCHEMATIC.getWriter(new FileOutputStream(file))) { @Override
writer.write(clipboard); public boolean backup(Point minPoint, Point maxPoint, File file) {
} Clipboard clipboard = copy(minPoint, maxPoint, minPoint);
try (ClipboardWriter writer = BuiltInClipboardFormat.SPONGE_SCHEMATIC.getWriter(new FileOutputStream(file))) {
writer.write(clipboard);
return true; return true;
} catch (WorldEditException | IOException e) { } catch (IOException e) {
Bukkit.getLogger().log(Level.SEVERE, e.getMessage(), e); Bukkit.getLogger().log(Level.SEVERE, e.getMessage(), e);
return false; return false;
} }

Datei anzeigen

@ -811,6 +811,8 @@ REGION_REGION_HELP_COPYPOINT=§8/§eregion copypoint §8- §7Teleport to the reg
REGION_REGION_HELP_TESTBLOCKPOINT=§8/§eregion testblockpoint §8- §7Teleport to the regions dummy point REGION_REGION_HELP_TESTBLOCKPOINT=§8/§eregion testblockpoint §8- §7Teleport to the regions dummy point
REGION_REGION_HELP_CHANGESKIN_INFO=§8/§eregion changeskin §8- §7Returns the region skin REGION_REGION_HELP_CHANGESKIN_INFO=§8/§eregion changeskin §8- §7Returns the region skin
REGION_REGION_HELP_CHANGESKIN=§8/§eregion changeskin §8[§7Skin§8] §8- §8Sets the region skin REGION_REGION_HELP_CHANGESKIN=§8/§eregion changeskin §8[§7Skin§8] §8- §8Sets the region skin
REGION_REGION_HELP_COPY=§8/§eregion copy [-e] [-s] §8- §8Copy the build area optional with extensions or selection at the copypoint
REGION_REGION_HELP_PASTE=§8/§eregion paste [-a] [-s] §8[§7Skin§8] §8- §8Pastes at the copypoint optional without air and selecting the pasted region
REGION_REGION_NOTHING_UNDO=§cNothing left to undo REGION_REGION_NOTHING_UNDO=§cNothing left to undo
REGION_REGION_UNDID=§7Last action undone REGION_REGION_UNDID=§7Last action undone
REGION_REGION_NOTHING_REDO=§cNothing left to redo REGION_REGION_NOTHING_REDO=§cNothing left to redo
@ -824,6 +826,9 @@ REGION_REGION_TP_COPY=§7Teleported to the copy point
REGION_REGION_TP_TEST_BLOCK=§7Teleported to the tesblock REGION_REGION_TP_TEST_BLOCK=§7Teleported to the tesblock
REGION_REGION_TP_UNKNOWN=§cUndefined teleport point REGION_REGION_TP_UNKNOWN=§cUndefined teleport point
REGION_REGION_NO_REGION=§cYou are not inside any region REGION_REGION_NO_REGION=§cYou are not inside any region
REGION_REGION_NO_BUILD=§cThis region has no build area
REGION_REGION_COPY_DONE=§eBuild region or selection copied
REGION_REGION_PASTE_DONE=§eBuild region or selection pasted
REGION_REGION_CHANGESKIN_INFO=§7Region skin is §e{0} REGION_REGION_CHANGESKIN_INFO=§7Region skin is §e{0}
REGION_REGION_CHANGESKIN_INFO_CREATOR=§7Skin created by §e{0} REGION_REGION_CHANGESKIN_INFO_CREATOR=§7Skin created by §e{0}
REGION_REGION_CHANGESKIN_UNKNOWN=§cRegion skin is invalid REGION_REGION_CHANGESKIN_UNKNOWN=§cRegion skin is invalid

Datei anzeigen

@ -774,6 +774,8 @@ REGION_REGION_HELP_COPYPOINT=§8/§eregion copypoint §8- §7Teleportiere dich z
REGION_REGION_HELP_TESTBLOCKPOINT=§8/§eregion testblockpoint §8- §7Teleportiere dich zum Regions Testblockpunkt REGION_REGION_HELP_TESTBLOCKPOINT=§8/§eregion testblockpoint §8- §7Teleportiere dich zum Regions Testblockpunkt
REGION_REGION_HELP_CHANGESKIN_INFO=§8/§eregion changeskin §8- §7Gebe den Regions Skin aus REGION_REGION_HELP_CHANGESKIN_INFO=§8/§eregion changeskin §8- §7Gebe den Regions Skin aus
REGION_REGION_HELP_CHANGESKIN=§8/§eregion changeskin §8[§7Skin§8] §8- §8Setzte den Regions Skin REGION_REGION_HELP_CHANGESKIN=§8/§eregion changeskin §8[§7Skin§8] §8- §8Setzte den Regions Skin
REGION_REGION_HELP_COPY=§8/§eregion copy [-e] [-s] §8- §8Kopieren des Baubereichs optional mit Erweiterungen oder Auswahl am Kopierpunkt
REGION_REGION_HELP_PASTE=§8/§eregion paste [-a] [-s] §8[§7Skin§8] §8- §8Einfügen am Kopierpunkt optional ohne Luft und Auswahl des eingefügten Bereichs
REGION_REGION_NOTHING_UNDO=§cNichts zum rückgängig machen REGION_REGION_NOTHING_UNDO=§cNichts zum rückgängig machen
REGION_REGION_UNDID=§7Letzte Aktion rückgangig gemacht REGION_REGION_UNDID=§7Letzte Aktion rückgangig gemacht
REGION_REGION_NOTHING_REDO=§cNichts zum wiederhohlen REGION_REGION_NOTHING_REDO=§cNichts zum wiederhohlen
@ -787,6 +789,9 @@ REGION_REGION_TP_COPY=§7Zum Kopierpunkt teleportiert
REGION_REGION_TP_TEST_BLOCK=§7Zum Testblock teleportiert REGION_REGION_TP_TEST_BLOCK=§7Zum Testblock teleportiert
REGION_REGION_TP_UNKNOWN=§cNicht definierter Teleportierpunkt REGION_REGION_TP_UNKNOWN=§cNicht definierter Teleportierpunkt
REGION_REGION_NO_REGION=§cDu bist in keiner Region REGION_REGION_NO_REGION=§cDu bist in keiner Region
REGION_REGION_NO_BUILD=§cDiese Region hat kein Baugebiet
REGION_REGION_COPY_DONE=§eBauregion oder Selektion kopiert
REGION_REGION_PASTE_DONE=§eBauregion oder Selektion eingefügt
REGION_REGION_CHANGESKIN_INFO=§7Regions Skin ist §e{0} REGION_REGION_CHANGESKIN_INFO=§7Regions Skin ist §e{0}
REGION_REGION_CHANGESKIN_INFO_CREATOR=§7Skin erstellt von §e{0} REGION_REGION_CHANGESKIN_INFO_CREATOR=§7Skin erstellt von §e{0}
REGION_REGION_CHANGESKIN_UNKNOWN=§cRegions Skin ist nicht valide REGION_REGION_CHANGESKIN_UNKNOWN=§cRegions Skin ist nicht valide

Datei anzeigen

@ -19,31 +19,40 @@
package de.steamwar.bausystem.features.region; package de.steamwar.bausystem.features.region;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.bukkit.BukkitWorld;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.function.operation.Operations;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.session.ClipboardHolder;
import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.features.util.SelectCommand; import de.steamwar.bausystem.features.util.SelectCommand;
import de.steamwar.bausystem.region.Prototype; import de.steamwar.bausystem.region.Point;
import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.Region;
import de.steamwar.bausystem.region.RegionUtils; import de.steamwar.bausystem.region.RegionUtils;
import de.steamwar.bausystem.region.flags.Flag; import de.steamwar.bausystem.region.flags.Flag;
import de.steamwar.bausystem.region.flags.flagvalues.ColorMode; import de.steamwar.bausystem.region.flags.flagvalues.ColorMode;
import de.steamwar.bausystem.region.utils.RegionExtensionType; import de.steamwar.bausystem.region.utils.RegionExtensionType;
import de.steamwar.bausystem.region.utils.RegionType; import de.steamwar.bausystem.region.utils.RegionType;
import de.steamwar.bausystem.shared.Pair;
import de.steamwar.bausystem.utils.FlatteningWrapper;
import de.steamwar.bausystem.utils.PasteBuilder; import de.steamwar.bausystem.utils.PasteBuilder;
import de.steamwar.bausystem.utils.WorldEditUtils;
import de.steamwar.command.PreviousArguments; import de.steamwar.command.PreviousArguments;
import de.steamwar.command.SWCommand; import de.steamwar.command.SWCommand;
import de.steamwar.command.TypeMapper; import de.steamwar.command.TypeMapper;
import de.steamwar.command.TypeValidator;
import de.steamwar.linkage.Linked; import de.steamwar.linkage.Linked;
import de.steamwar.linkage.LinkedInstance; import de.steamwar.linkage.LinkedInstance;
import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SchematicNode;
import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.ClickEvent;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.player.PlayerTeleportEvent;
import java.io.IOException;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
@ -197,6 +206,106 @@ public class RegionCommand extends SWCommand {
} }
} }
@Register(value = "copy", description = "REGION_REGION_HELP_COPY")
public void copyCommand(@Validator Player p, @OptionalValue("") @StaticValue(value = {"", "-e", "-s"}, allowISE = true) int option) {
Region region = Region.getRegion(p.getLocation());
if (checkGlobalRegion(region, p)) {
return;
}
if (!region.hasType(RegionType.BUILD)) {
BauSystem.MESSAGE.send("REGION_REGION_NO_BUILD", p);
return;
}
if (region.getCopyPoint() == null) {
BauSystem.MESSAGE.send("REGION_REGION_TP_UNKNOWN", p);
return;
}
Point minPoint = region.getMinPoint(RegionType.BUILD, RegionExtensionType.NORMAL);
Point maxPoint = region.getMaxPoint(RegionType.BUILD, RegionExtensionType.NORMAL);
switch (option) {
case 0:
break;
case 1:
minPoint = region.getMinPoint(RegionType.BUILD, RegionExtensionType.EXTENSION);
maxPoint = region.getMaxPoint(RegionType.BUILD, RegionExtensionType.EXTENSION);
break;
case 2:
Pair<Location, Location> selection = WorldEditUtils.getSelection(p);
minPoint = Point.fromLocation(selection.getKey());
maxPoint = Point.fromLocation(selection.getValue());
break;
default:
break;
}
Clipboard clipboard = FlatteningWrapper.impl.copy(minPoint, maxPoint, region.getCopyPoint());
WorldEdit.getInstance()
.getSessionManager()
.get(BukkitAdapter.adapt(p))
.setClipboard(new ClipboardHolder(clipboard));
BauSystem.MESSAGE.send("REGION_REGION_COPY_DONE", p);
}
@Register(value = "paste", description = "REGION_REGION_HELP_PASTE")
public void pasteCommand(@Validator Player p, @OptionalValue("") @StaticValue(value = {"", "-a", "-s", "-as", "-sa"}, allowISE = true) int options) {
Region region = Region.getRegion(p.getLocation());
if (checkGlobalRegion(region, p)) {
return;
}
if (!region.hasType(RegionType.BUILD)) {
BauSystem.MESSAGE.send("REGION_REGION_NO_BUILD", p);
return;
}
if (region.getCopyPoint() == null) {
BauSystem.MESSAGE.send("REGION_REGION_TP_UNKNOWN", p);
return;
}
ClipboardHolder clipboardHolder = WorldEdit.getInstance()
.getSessionManager()
.get(BukkitAdapter.adapt(p))
.getClipboard();
boolean selectPasted = false;
boolean ignoreAir = false;
switch (options) {
case 0:
break;
case 1:
ignoreAir = true;
break;
case 2:
selectPasted = true;
break;
case 3:
case 4:
selectPasted = true;
ignoreAir = true;
break;
default:
break;
}
try (EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorlds().get(0)), -1)) {
Operations.completeBlindly(clipboardHolder.createPaste(e).ignoreAirBlocks(ignoreAir).to(toBlockVector3(region.getCopyPoint())).build());
WorldEditUtils.addToPlayer(p, e);
if (selectPasted) {
Clipboard clipboard = clipboardHolder.getClipboards().get(0);
BlockVector3 minPointSelection = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin()).add(toBlockVector3(region.getCopyPoint()));
BlockVector3 maxPointSelection = clipboard.getRegion().getMaximumPoint().subtract(clipboard.getOrigin()).add(toBlockVector3(region.getCopyPoint()));
FlatteningWrapper.impl.setSelection(p, Point.fromBlockVector3(minPointSelection), Point.fromBlockVector3(maxPointSelection));
}
BauSystem.MESSAGE.send("REGION_REGION_PASTE_DONE", p);
}
}
private BlockVector3 toBlockVector3(Point point) {
return BlockVector3.at(point.getX(), point.getY(), point.getZ());
}
@Mapper(value = "skinTypeMapper", local = true) @Mapper(value = "skinTypeMapper", local = true)
private TypeMapper<String> skinTypeMapper() { private TypeMapper<String> skinTypeMapper() {
return new TypeMapper<String>() { return new TypeMapper<String>() {

Datei anzeigen

@ -19,6 +19,7 @@
package de.steamwar.bausystem.region; package de.steamwar.bausystem.region;
import com.sk89q.worldedit.math.BlockVector3;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.Getter; import lombok.Getter;
@ -41,6 +42,10 @@ public class Point {
return new Point(location.getBlockX(), location.getBlockY(), location.getBlockZ()); return new Point(location.getBlockX(), location.getBlockY(), location.getBlockZ());
} }
public static Point fromBlockVector3(final BlockVector3 blockVector3) {
return new Point(blockVector3.getBlockX(), blockVector3.getBlockY(), blockVector3.getBlockZ());
}
public Point add(int x, int y, int z) { public Point add(int x, int y, int z) {
return new Point(this.x + x, this.y + y, this.z + z); return new Point(this.x + x, this.y + y, this.z + z);
} }

Datei anzeigen

@ -46,6 +46,7 @@ public interface FlatteningWrapper {
Clipboard loadSchematic(File file); Clipboard loadSchematic(File file);
EditSession paste(PasteBuilder pasteBuilder); EditSession paste(PasteBuilder pasteBuilder);
Clipboard copy(Point minPoint, Point maxPoint, Point copyPoint);
boolean backup(Point minPoint, Point maxPoint, File file); boolean backup(Point minPoint, Point maxPoint, File file);
boolean inWater(World world, Vector tntPosition); boolean inWater(World world, Vector tntPosition);