SteamWar/BauSystem2.0
Archiviert
12
0

Add undoability to Panzern
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2021-10-08 09:59:50 +02:00
Ursprung 5d2b14bd14
Commit 614f697900
3 geänderte Dateien mit 36 neuen und 6 gelöschten Zeilen

Datei anzeigen

@ -19,6 +19,7 @@
package de.steamwar.bausystem.features.slaves;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
@ -33,6 +34,14 @@ import org.bukkit.entity.Player;
@UtilityClass
public class WorldEditUtils {
public EditSession getEditSession(World world) {
return WorldEdit.getInstance().getEditSessionFactory().getEditSession(BukkitAdapter.adapt(world), Integer.MAX_VALUE);
}
public void addToPlayer(Player player, EditSession editSession) {
WorldEdit.getInstance().getSessionManager().get(BukkitAdapter.adapt(player)).remember(editSession);
}
public Pair<Location, Location> getSelection(Player player) {
RegionSelector regionSelector = WorldEdit.getInstance()
.getSessionManager()

Datei anzeigen

@ -19,6 +19,14 @@
package de.steamwar.bausystem.features.slaves.panzern;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.history.change.BlockChange;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockTypes;
import de.steamwar.bausystem.features.slaves.WorldEditUtils;
import lombok.Getter;
import lombok.SneakyThrows;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
@ -38,7 +46,7 @@ public class Panzern {
private static final BlockFace[] BLOCK_FACES = new BlockFace[]{BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST, BlockFace.UP, BlockFace.DOWN};
private Set<Location> current = new LinkedHashSet<>(); // Potenzielle geschwindigkeit durch `LinkedHashSet<>();` möchte aber lieber ein HashSet nehmen, weil dieses besser für mein Anwendungsfall ist
private Set<Location> current = new LinkedHashSet<>();
private Set<Vector> emptyBlocks = new HashSet<>();
private World world;
@ -47,6 +55,14 @@ public class Panzern {
private Material blockMaterial;
private Material slabMaterial;
private BaseBlock blockType;
private BaseBlock slabType;
private static final BaseBlock jukeboxType = BlockTypes.JUKEBOX.getDefaultState().toBaseBlock();
private static final BaseBlock airType = BlockTypes.AIR.getDefaultState().toBaseBlock();
@Getter
private EditSession editSession;
public Panzern(Location pos1, Location pos2, Location possibleSource, Material blockMaterial, Material slabMaterial) {
this.world = pos1.getWorld();
this.pos1 = new Location(world, Math.min(pos1.getBlockX(), pos2.getBlockX()), Math.min(pos1.getBlockY(), pos2.getBlockY()), Math.min(pos1.getBlockZ(), pos2.getBlockZ()));
@ -59,12 +75,18 @@ public class Panzern {
}
this.blockMaterial = blockMaterial;
this.slabMaterial = slabMaterial;
blockType = BlockTypes.get("minecraft:" + blockMaterial.name().toLowerCase()).getDefaultState().toBaseBlock();
slabType = BlockTypes.get("minecraft:" + slabMaterial.name().toLowerCase()).getDefaultState().toBaseBlock();
editSession = WorldEditUtils.getEditSession(world);
}
public boolean hasNext() {
return !current.isEmpty();
}
@SneakyThrows
public void next() {
Location toCheck = current.iterator().next();
current.remove(toCheck);
@ -96,13 +118,16 @@ public class Panzern {
return;
case SLAB:
currentBlock.setType(slabMaterial);
editSession.getChangeSet().add(new BlockChange(BukkitAdapter.asBlockVector(currentBlock.getLocation()), airType, slabType));
break;
case BLOCK:
case DEFAULT:
currentBlock.setType(blockMaterial);
editSession.getChangeSet().add(new BlockChange(BukkitAdapter.asBlockVector(currentBlock.getLocation()), airType, blockType));
break;
case UNMOVABLE:
currentBlock.setType(Material.JUKEBOX);
editSession.getChangeSet().add(new BlockChange(BukkitAdapter.asBlockVector(currentBlock.getLocation()), airType, jukeboxType));
break;
default:
emptyBlocks.add(currentBlock.getLocation().toVector());

Datei anzeigen

@ -30,11 +30,6 @@ import de.steamwar.command.SWCommand;
import de.steamwar.command.TypeMapper;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.data.Bisected;
import org.bukkit.block.data.Directional;
import org.bukkit.block.data.MultipleFacing;
import org.bukkit.block.data.type.Slab;
import org.bukkit.block.data.type.Stairs;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
@ -89,6 +84,7 @@ public class PanzernCommand extends SWCommand {
while (true) {
if (!panzern.hasNext()) {
BauSystem.MESSAGE.send("PANZERN_DONE", player);
WorldEditUtils.addToPlayer(player, panzern.getEditSession());
cancel();
return;
}