forked from SteamWar/SteamWar
Improve Region.Area
This commit is contained in:
+2
-2
@@ -63,11 +63,11 @@ public class ColorCommand extends SWCommand {
|
||||
}
|
||||
region.getRegionData().set(Flag.COLOR, color);
|
||||
try {
|
||||
PasteBuilder pasteBuilder = new PasteBuilder(new PasteBuilder.FileProvider(region.getArea().getResetFile()))
|
||||
PasteBuilder pasteBuilder = new PasteBuilder(PasteBuilder.ClipboardProvider.EMPTY)
|
||||
.ignoreAir(true)
|
||||
.onlyColors(true)
|
||||
.color(color);
|
||||
region.getArea().reset(pasteBuilder, false);
|
||||
region.getArea().reset(p.getLocation(), pasteBuilder, false);
|
||||
RegionUtils.message(region, "REGION_REGION_COLORED");
|
||||
RegionUtils.message(region, "REGION_REGION_COLORED_FAILED");
|
||||
} catch (SecurityException e) {
|
||||
|
||||
+2
-34
@@ -29,9 +29,6 @@ import de.steamwar.bausystem.utils.PasteBuilder;
|
||||
import de.steamwar.command.SWCommand;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import de.steamwar.linkage.LinkedInstance;
|
||||
import de.steamwar.sql.Punishment;
|
||||
import de.steamwar.sql.SchematicNode;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@@ -52,9 +49,9 @@ public class ResetCommand extends SWCommand {
|
||||
Region region = regionCheck(p);
|
||||
if (region == null) return;
|
||||
try {
|
||||
PasteBuilder pasteBuilder = new PasteBuilder(new PasteBuilder.FileProvider(region.getArea().getResetFile()))
|
||||
PasteBuilder pasteBuilder = new PasteBuilder(PasteBuilder.ClipboardProvider.EMPTY)
|
||||
.color(region.getRegionData().get(Flag.COLOR).getWithDefault());
|
||||
region.getArea().reset(pasteBuilder, false);
|
||||
region.getArea().reset(p.getLocation(), pasteBuilder, false);
|
||||
region.getRegionData().clear();
|
||||
RegionUtils.message(region, "REGION_RESET_RESETED");
|
||||
} catch (SecurityException e) {
|
||||
@@ -63,35 +60,6 @@ public class ResetCommand extends SWCommand {
|
||||
}
|
||||
}
|
||||
|
||||
@Register(description = "REGION_RESET_HELP_SCHEMATIC")
|
||||
public void schematicResetCommand(@Validator Player p, SchematicNode node) {
|
||||
Region region = regionCheck(p);
|
||||
if (region == null) return;
|
||||
|
||||
if (!p.getUniqueId().equals(bauServer.getOwner())) {
|
||||
if (Punishment.isPunished(SteamwarUser.get(bauServer.getOwner()), Punishment.PunishmentType.NoSchemReceiving, punishment -> BauSystem.MESSAGE.send("REGION_TB_NO_SCHEMRECEIVING", p, punishment.getEndTime()))) {
|
||||
return;
|
||||
}
|
||||
if (Punishment.isPunished(SteamwarUser.get(p.getUniqueId()), Punishment.PunishmentType.NoSchemSharing, punishment -> BauSystem.MESSAGE.send("REGION_TB_NO_SCHEMSHARING", p, punishment.getEndTime()))) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (node.isDir()) {
|
||||
BauSystem.MESSAGE.send("ONLY_SCHEMS", p);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
PasteBuilder pasteBuilder = new PasteBuilder(new PasteBuilder.SchematicProvider(node))
|
||||
.color(region.getRegionData().get(Flag.COLOR).getWithDefault());
|
||||
region.getArea().reset(pasteBuilder, true);
|
||||
RegionUtils.message(region, "REGION_RESET_RESETED");
|
||||
} catch (SecurityException e) {
|
||||
BauSystem.MESSAGE.send("REGION_RESET_ERROR", p);
|
||||
Bukkit.getLogger().log(Level.WARNING, "Failed reset", e);
|
||||
}
|
||||
}
|
||||
|
||||
private Region regionCheck(Player player) {
|
||||
Region region = Region.getRegion(player.getLocation());
|
||||
if (region == RegionSystem.INSTANCE.getGlobalRegion()) {
|
||||
|
||||
+2
-8
@@ -108,13 +108,7 @@ public class TestblockCommand extends SWCommand {
|
||||
region.getRegionData().setTestblockSchematic(node);
|
||||
}
|
||||
|
||||
PasteBuilder.ClipboardProvider clipboardProvider;
|
||||
if (node == null) {
|
||||
clipboardProvider = new PasteBuilder.FileProvider(region.getTestblockArea().getResetFile());
|
||||
} else {
|
||||
clipboardProvider = new PasteBuilder.SchematicProvider(node);
|
||||
}
|
||||
|
||||
PasteBuilder.ClipboardProvider clipboardProvider = node == null ? PasteBuilder.ClipboardProvider.EMPTY : PasteBuilder.ClipboardProvider.schematic(node);
|
||||
try {
|
||||
PasteBuilder pasteBuilder = new PasteBuilder(clipboardProvider)
|
||||
.ignoreAir(ignoreAir)
|
||||
@@ -122,7 +116,7 @@ public class TestblockCommand extends SWCommand {
|
||||
.removeTNT(removeTNT)
|
||||
.removeWater(removeWater)
|
||||
.color(region.getRegionData().get(Flag.COLOR).getWithDefault());
|
||||
region.getTestblockArea().reset(pasteBuilder, regionExtensionType == RegionExtensionType.EXTENSION);
|
||||
region.getTestblockArea().reset(p.getLocation(), pasteBuilder, regionExtensionType == RegionExtensionType.EXTENSION);
|
||||
RegionUtils.message(region, "REGION_TB_DONE");
|
||||
} catch (SecurityException e) {
|
||||
BauSystem.MESSAGE.send("REGION_TB_ERROR", p);
|
||||
|
||||
+2
-10
@@ -50,16 +50,8 @@ public class ResetBauGuiItem extends BauGuiItem {
|
||||
|
||||
@Override
|
||||
public boolean click(ClickType click, Player p) {
|
||||
if (click == ClickType.LEFT) {
|
||||
p.closeInventory();
|
||||
resetCommand.genericResetCommand(p);
|
||||
} else {
|
||||
SchematicSelector selector = new SchematicSelector(p, SchematicSelector.selectSchematic(), node -> {
|
||||
p.closeInventory();
|
||||
resetCommand.schematicResetCommand(p, node);
|
||||
});
|
||||
selector.open();
|
||||
}
|
||||
p.closeInventory();
|
||||
resetCommand.genericResetCommand(p);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -33,12 +33,12 @@ public class StabFinalizer extends StabStep {
|
||||
@Override
|
||||
protected void start() {
|
||||
try {
|
||||
PasteBuilder.ClipboardProvider clipboardProvider = new PasteBuilder.ClipboardProviderImpl(data.clipboard);
|
||||
PasteBuilder.ClipboardProvider clipboardProvider = PasteBuilder.ClipboardProvider.clipboard(data.clipboard);
|
||||
PasteBuilder pasteBuilder = new PasteBuilder(clipboardProvider);
|
||||
if (data.region.getRegionData().has(Flag.COLOR).isReadable()) {
|
||||
pasteBuilder.color(data.region.getRegionData().get(Flag.COLOR).getWithDefault());
|
||||
}
|
||||
data.region.getTestblockArea().reset(pasteBuilder, true);
|
||||
data.region.getTestblockArea().reset(null, pasteBuilder, true);
|
||||
} catch (SecurityException e) {
|
||||
stop();
|
||||
throw e;
|
||||
|
||||
+2
-2
@@ -72,12 +72,12 @@ public class StabGenerator extends StabStep implements Listener {
|
||||
@Override
|
||||
protected void start() {
|
||||
try {
|
||||
PasteBuilder.ClipboardProvider clipboardProvider = new PasteBuilder.ClipboardProviderImpl(data.clipboard);
|
||||
PasteBuilder.ClipboardProvider clipboardProvider = PasteBuilder.ClipboardProvider.clipboard(data.clipboard);
|
||||
PasteBuilder pasteBuilder = new PasteBuilder(clipboardProvider);
|
||||
if (data.region.getRegionData().has(Flag.COLOR).isReadable()) {
|
||||
pasteBuilder.color(data.region.getRegionData().get(Flag.COLOR).getWithDefault());
|
||||
}
|
||||
data.region.getTestblockArea().reset(pasteBuilder, true);
|
||||
data.region.getTestblockArea().reset(null, pasteBuilder, true);
|
||||
} catch (SecurityException e) {
|
||||
stop();
|
||||
throw e;
|
||||
|
||||
@@ -29,7 +29,6 @@ import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.File;
|
||||
import java.util.UUID;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.stream.Stream;
|
||||
@@ -112,12 +111,7 @@ public interface Region extends RegionDataStore {
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getResetFile() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void place(PasteBuilder pasteBuilder, boolean extension) {
|
||||
public void place(Location location, PasteBuilder pasteBuilder, boolean extension) {
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -165,14 +159,11 @@ public interface Region extends RegionDataStore {
|
||||
return FlatteningWrapper.impl.copy(getMinPoint(extension), getMaxPoint(extension), getCopyPoint());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
File getResetFile();
|
||||
|
||||
default void reset(PasteBuilder pasteBuilder, boolean extension) {
|
||||
place(pasteBuilder, extension);
|
||||
default void reset(Location location, PasteBuilder pasteBuilder, boolean extension) {
|
||||
place(location, pasteBuilder, extension);
|
||||
}
|
||||
|
||||
void place(PasteBuilder pasteBuilder, boolean extension);
|
||||
void place(Location location, PasteBuilder pasteBuilder, boolean extension);
|
||||
|
||||
default void forEachChunk(BiConsumer<Integer, Integer> executor) {
|
||||
Point minPoint = getMinPoint(false);
|
||||
|
||||
@@ -42,7 +42,7 @@ import java.util.function.BiPredicate;
|
||||
@Getter
|
||||
public class PasteBuilder {
|
||||
|
||||
private final ClipboardProvider clipboardProvider;
|
||||
private ClipboardProvider clipboardProvider;
|
||||
private Point pastPoint;
|
||||
private boolean rotate;
|
||||
private boolean ignoreAir;
|
||||
@@ -53,21 +53,18 @@ public class PasteBuilder {
|
||||
private List<BiPredicate<BaseBlock, String>> predicates = new ArrayList<>();
|
||||
private List<BiConsumer<Clipboard, BlockVector3>> mappers = new ArrayList<>();
|
||||
|
||||
public PasteBuilder() {
|
||||
clipboardProvider = ClipboardProvider.EMPTY;
|
||||
}
|
||||
|
||||
public PasteBuilder(@NonNull ClipboardProvider clipboardProvider) {
|
||||
this.clipboardProvider = clipboardProvider;
|
||||
}
|
||||
|
||||
public PasteBuilder with(ClipboardProvider clipboardProvider) {
|
||||
return new PasteBuilder(clipboardProvider)
|
||||
.pastePoint(pastPoint)
|
||||
.rotate(rotate)
|
||||
.ignoreAir(ignoreAir)
|
||||
.reset(reset)
|
||||
.minPoint(minPoint)
|
||||
.maxPoint(maxPoint)
|
||||
.waterLevel(waterLevel)
|
||||
.predicates(predicates)
|
||||
.mappers(mappers);
|
||||
public PasteBuilder with(@NonNull ClipboardProvider clipboardProvider) {
|
||||
if (this.clipboardProvider != ClipboardProvider.EMPTY) return this;
|
||||
this.clipboardProvider = clipboardProvider;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PasteBuilder pastePoint(Point point) {
|
||||
@@ -212,6 +209,20 @@ public class PasteBuilder {
|
||||
}
|
||||
|
||||
public interface ClipboardProvider {
|
||||
ClipboardProvider EMPTY = new EmptyProvider();
|
||||
|
||||
static ClipboardProvider file(File file) {
|
||||
return new FileProvider(file);
|
||||
}
|
||||
|
||||
static ClipboardProvider schematic(SchematicNode schematic) {
|
||||
return new SchematicProvider(schematic);
|
||||
}
|
||||
|
||||
static ClipboardProvider clipboard(Clipboard clipboard) {
|
||||
return new ClipboardProviderImpl(clipboard);
|
||||
}
|
||||
|
||||
Clipboard getClipboard();
|
||||
|
||||
default <T extends ClipboardProvider> boolean is(Class<T> clazz) {
|
||||
@@ -223,12 +234,22 @@ public class PasteBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
private static class EmptyProvider implements ClipboardProvider {
|
||||
private EmptyProvider() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Clipboard getClipboard() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Getter
|
||||
public static class FileProvider implements ClipboardProvider {
|
||||
private final File file;
|
||||
private final Clipboard clipboard;
|
||||
|
||||
public FileProvider(File file) {
|
||||
private FileProvider(File file) {
|
||||
this.file = file;
|
||||
this.clipboard = FlatteningWrapper.impl.loadSchematic(file);
|
||||
}
|
||||
@@ -244,7 +265,7 @@ public class PasteBuilder {
|
||||
private final SchematicNode schematic;
|
||||
private final Clipboard clipboard;
|
||||
|
||||
public SchematicProvider(SchematicNode schematic) {
|
||||
private SchematicProvider(SchematicNode schematic) {
|
||||
this.schematic = schematic;
|
||||
try {
|
||||
this.clipboard = new SchematicData(schematic).load();
|
||||
@@ -263,7 +284,7 @@ public class PasteBuilder {
|
||||
public static class ClipboardProviderImpl implements ClipboardProvider {
|
||||
private final Clipboard clipboard;
|
||||
|
||||
public ClipboardProviderImpl(Clipboard clipboard) {
|
||||
private ClipboardProviderImpl(Clipboard clipboard) {
|
||||
this.clipboard = clipboard;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user