Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
Ursprung
5d2b14bd14
Commit
614f697900
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.features.slaves;
|
package de.steamwar.bausystem.features.slaves;
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.EditSession;
|
||||||
import com.sk89q.worldedit.IncompleteRegionException;
|
import com.sk89q.worldedit.IncompleteRegionException;
|
||||||
import com.sk89q.worldedit.WorldEdit;
|
import com.sk89q.worldedit.WorldEdit;
|
||||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||||
@ -33,6 +34,14 @@ import org.bukkit.entity.Player;
|
|||||||
@UtilityClass
|
@UtilityClass
|
||||||
public class WorldEditUtils {
|
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) {
|
public Pair<Location, Location> getSelection(Player player) {
|
||||||
RegionSelector regionSelector = WorldEdit.getInstance()
|
RegionSelector regionSelector = WorldEdit.getInstance()
|
||||||
.getSessionManager()
|
.getSessionManager()
|
||||||
|
@ -19,6 +19,14 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.features.slaves.panzern;
|
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.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.World;
|
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 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 Set<Vector> emptyBlocks = new HashSet<>();
|
||||||
|
|
||||||
private World world;
|
private World world;
|
||||||
@ -47,6 +55,14 @@ public class Panzern {
|
|||||||
private Material blockMaterial;
|
private Material blockMaterial;
|
||||||
private Material slabMaterial;
|
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) {
|
public Panzern(Location pos1, Location pos2, Location possibleSource, Material blockMaterial, Material slabMaterial) {
|
||||||
this.world = pos1.getWorld();
|
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()));
|
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.blockMaterial = blockMaterial;
|
||||||
this.slabMaterial = slabMaterial;
|
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() {
|
public boolean hasNext() {
|
||||||
return !current.isEmpty();
|
return !current.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
public void next() {
|
public void next() {
|
||||||
Location toCheck = current.iterator().next();
|
Location toCheck = current.iterator().next();
|
||||||
current.remove(toCheck);
|
current.remove(toCheck);
|
||||||
@ -96,13 +118,16 @@ public class Panzern {
|
|||||||
return;
|
return;
|
||||||
case SLAB:
|
case SLAB:
|
||||||
currentBlock.setType(slabMaterial);
|
currentBlock.setType(slabMaterial);
|
||||||
|
editSession.getChangeSet().add(new BlockChange(BukkitAdapter.asBlockVector(currentBlock.getLocation()), airType, slabType));
|
||||||
break;
|
break;
|
||||||
case BLOCK:
|
case BLOCK:
|
||||||
case DEFAULT:
|
case DEFAULT:
|
||||||
currentBlock.setType(blockMaterial);
|
currentBlock.setType(blockMaterial);
|
||||||
|
editSession.getChangeSet().add(new BlockChange(BukkitAdapter.asBlockVector(currentBlock.getLocation()), airType, blockType));
|
||||||
break;
|
break;
|
||||||
case UNMOVABLE:
|
case UNMOVABLE:
|
||||||
currentBlock.setType(Material.JUKEBOX);
|
currentBlock.setType(Material.JUKEBOX);
|
||||||
|
editSession.getChangeSet().add(new BlockChange(BukkitAdapter.asBlockVector(currentBlock.getLocation()), airType, jukeboxType));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
emptyBlocks.add(currentBlock.getLocation().toVector());
|
emptyBlocks.add(currentBlock.getLocation().toVector());
|
||||||
|
@ -30,11 +30,6 @@ import de.steamwar.command.SWCommand;
|
|||||||
import de.steamwar.command.TypeMapper;
|
import de.steamwar.command.TypeMapper;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
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.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
@ -89,6 +84,7 @@ public class PanzernCommand extends SWCommand {
|
|||||||
while (true) {
|
while (true) {
|
||||||
if (!panzern.hasNext()) {
|
if (!panzern.hasNext()) {
|
||||||
BauSystem.MESSAGE.send("PANZERN_DONE", player);
|
BauSystem.MESSAGE.send("PANZERN_DONE", player);
|
||||||
|
WorldEditUtils.addToPlayer(player, panzern.getEditSession());
|
||||||
cancel();
|
cancel();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren