Add nbt stripping
This commit is contained in:
parent
3ed2e57f3a
commit
f2412bca13
@ -160,6 +160,10 @@ public class Settings extends Config {
|
||||
"Should large edits require confirmation (>16384 chunks)",
|
||||
})
|
||||
public boolean CONFIRM_LARGE = true;
|
||||
@Comment({
|
||||
"List of blocks to strip nbt from",
|
||||
})
|
||||
public List<String> STRIP_NBT = new ArrayList<>();
|
||||
}
|
||||
|
||||
public static class HISTORY {
|
||||
@ -476,6 +480,14 @@ public class Settings extends Config {
|
||||
limit.SPEED_REDUCTION = Math.min(limit.SPEED_REDUCTION, newLimit.SPEED_REDUCTION);
|
||||
limit.FAST_PLACEMENT |= newLimit.FAST_PLACEMENT;
|
||||
limit.CONFIRM_LARGE &= newLimit.CONFIRM_LARGE;
|
||||
if (limit.STRIP_NBT == null) limit.STRIP_NBT = newLimit.STRIP_NBT.isEmpty() ? Collections.emptySet() : new HashSet<>(newLimit.STRIP_NBT);
|
||||
else if (limit.STRIP_NBT.isEmpty() || newLimit.STRIP_NBT.isEmpty()) {
|
||||
limit.STRIP_NBT = Collections.emptySet();
|
||||
} else {
|
||||
limit.STRIP_NBT = new HashSet<>(limit.STRIP_NBT);
|
||||
limit.STRIP_NBT.retainAll(newLimit.STRIP_NBT);
|
||||
if (limit.STRIP_NBT.isEmpty()) limit.STRIP_NBT = Collections.emptySet();
|
||||
}
|
||||
}
|
||||
}
|
||||
return limit;
|
||||
|
@ -1,5 +1,10 @@
|
||||
package com.boydti.fawe.object;
|
||||
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Created by Jesse on 4/5/2016.
|
||||
*/
|
||||
@ -17,7 +22,7 @@ public class FaweLimit {
|
||||
public int SPEED_REDUCTION = Integer.MAX_VALUE;
|
||||
public boolean FAST_PLACEMENT = false;
|
||||
public boolean CONFIRM_LARGE = true;
|
||||
// public boolean[] STRIP_NBT = null;
|
||||
public Set<String> STRIP_NBT = null;
|
||||
|
||||
public static FaweLimit MAX;
|
||||
|
||||
@ -66,7 +71,7 @@ public class FaweLimit {
|
||||
MAX.MAX_EXPRESSION_MS = 50;
|
||||
MAX.FAST_PLACEMENT = true;
|
||||
MAX.CONFIRM_LARGE = true;
|
||||
// MAX.STRIP_NBT = null;
|
||||
MAX.STRIP_NBT = null;
|
||||
}
|
||||
|
||||
public boolean MAX_CHANGES() {
|
||||
@ -103,7 +108,8 @@ public class FaweLimit {
|
||||
MAX_HISTORY == Integer.MAX_VALUE &&
|
||||
INVENTORY_MODE == 0 &&
|
||||
SPEED_REDUCTION == 0 &&
|
||||
FAST_PLACEMENT == true;
|
||||
FAST_PLACEMENT == true &&
|
||||
(STRIP_NBT == null || STRIP_NBT.isEmpty());
|
||||
}
|
||||
|
||||
public void set(FaweLimit limit) {
|
||||
@ -119,6 +125,7 @@ public class FaweLimit {
|
||||
SPEED_REDUCTION = limit.SPEED_REDUCTION;
|
||||
FAST_PLACEMENT = limit.FAST_PLACEMENT;
|
||||
CONFIRM_LARGE = limit.CONFIRM_LARGE;
|
||||
STRIP_NBT = limit.STRIP_NBT;
|
||||
}
|
||||
|
||||
public FaweLimit copy() {
|
||||
@ -135,6 +142,7 @@ public class FaweLimit {
|
||||
limit.MAX_HISTORY = MAX_HISTORY;
|
||||
limit.FAST_PLACEMENT = FAST_PLACEMENT;
|
||||
limit.CONFIRM_LARGE = CONFIRM_LARGE;
|
||||
limit.STRIP_NBT = STRIP_NBT;
|
||||
return limit;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,49 @@
|
||||
package com.boydti.fawe.object.extent;
|
||||
|
||||
import com.boydti.fawe.util.ReflectionUtils;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.jnbt.Tag;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.extent.AbstractDelegateExtent;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class StripNBTExtent extends AbstractDelegateExtent {
|
||||
private final String[] strip;
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
*
|
||||
* @param extent the extent
|
||||
*/
|
||||
public StripNBTExtent(Extent extent, Set<String> strip) {
|
||||
super(extent);
|
||||
this.
|
||||
strip = strip.toArray(new String[strip.size()]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBlock(Vector location, BaseBlock block) throws WorldEditException {
|
||||
return super.setBlock(location, stripNBT(block));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBlock(int x, int y, int z, BaseBlock block) throws WorldEditException {
|
||||
return super.setBlock(x, y, z, stripNBT(block));
|
||||
}
|
||||
|
||||
public BaseBlock stripNBT(BaseBlock block) {
|
||||
if (!block.hasNbtData()) return block;
|
||||
CompoundTag nbt = block.getNbtData();
|
||||
Map<String, Tag> value = nbt.getValue();
|
||||
for (String key : strip) {
|
||||
value.remove(key);
|
||||
}
|
||||
return block;
|
||||
}
|
||||
}
|
@ -56,6 +56,7 @@ import com.sk89q.worldedit.extent.ChangeSetExtent;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.extent.MaskingExtent;
|
||||
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import com.sk89q.worldedit.extent.inventory.BlockBag;
|
||||
import com.sk89q.worldedit.extent.inventory.BlockBagExtent;
|
||||
import com.sk89q.worldedit.extent.world.SurvivalModeExtent;
|
||||
@ -317,6 +318,9 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
|
||||
} else {
|
||||
this.extent = new HeightBoundExtent(this.extent, this.limit, 0, maxY);
|
||||
}
|
||||
if (this.limit.STRIP_NBT != null && !this.limit.STRIP_NBT.isEmpty()) {
|
||||
this.extent = new StripNBTExtent(this.extent, this.limit.STRIP_NBT);
|
||||
}
|
||||
this.extent = wrapExtent(this.extent, bus, event, Stage.BEFORE_HISTORY);
|
||||
setExtent(this.extent);
|
||||
}
|
||||
|
@ -62,6 +62,21 @@ public class HistoryCommands extends MethodCommands {
|
||||
super(worldEdit);
|
||||
}
|
||||
|
||||
|
||||
@Command(
|
||||
aliases = {"/frb", "frb", "fawerollback", "/fawerollback", "/rollback"},
|
||||
usage = "<user=Empire92> <radius=5> <time=3d4h>",
|
||||
desc = "Undo a specific edit. " +
|
||||
" - The time uses s, m, h, d, y.\n" +
|
||||
" - Import from disk: /frb #import",
|
||||
min = 1,
|
||||
max = 3
|
||||
)
|
||||
@CommandPermissions("worldedit.history.rollback")
|
||||
public void faweRollback(final Player player, LocalSession session, final String user, @Optional("0") @Range(min = 0) int radius, @Optional("0") String time) throws WorldEditException {
|
||||
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/frb", "frb", "fawerollback", "/fawerollback", "/rollback"},
|
||||
usage = "<user=Empire92> <radius=5> <time=3d4h>",
|
||||
@ -199,8 +214,42 @@ public class HistoryCommands extends MethodCommands {
|
||||
);
|
||||
}
|
||||
|
||||
private void rollBack(DiskStorageHistory file) {
|
||||
|
||||
@Command(
|
||||
aliases = {"/fawerestore", "/frestore"},
|
||||
usage = "<user=Empire92|*> <radius=5> <time=3d4h>",
|
||||
desc = "Redo a specific edit. " +
|
||||
" - The time uses s, m, h, d, y.\n" +
|
||||
" - Import from disk: /frb #import",
|
||||
min = 1,
|
||||
max = 3
|
||||
)
|
||||
@CommandPermissions("worldedit.history.rollback")
|
||||
private void restore(DiskStorageHistory file) {
|
||||
int times = Math.max(1, context.getInteger(0, 1));
|
||||
if (times > 50) {
|
||||
FawePlayer.wrap(player).checkConfirmation(getArguments(context), times, 50);
|
||||
}
|
||||
for (int i = 0; i < times; ++i) {
|
||||
EditSession undone;
|
||||
if (context.argsLength() < 2) {
|
||||
undone = session.undo(session.getBlockBag(player), player);
|
||||
} else {
|
||||
player.checkPermission("worldedit.history.undo.other");
|
||||
LocalSession sess = worldEdit.getSession(context.getString(1));
|
||||
if (sess == null) {
|
||||
BBC.COMMAND_HISTORY_OTHER_ERROR.send(player, context.getString(1));
|
||||
break;
|
||||
}
|
||||
undone = sess.undo(session.getBlockBag(player), player);
|
||||
}
|
||||
if (undone != null) {
|
||||
BBC.COMMAND_UNDO_SUCCESS.send(player);
|
||||
worldEdit.flushBlockBag(player, undone);
|
||||
} else {
|
||||
BBC.COMMAND_UNDO_ERROR.send(player);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
|
@ -3,12 +3,14 @@ package com.sk89q.worldedit.extent;
|
||||
import com.boydti.fawe.FaweCache;
|
||||
import com.boydti.fawe.jnbt.anvil.generator.*;
|
||||
import com.boydti.fawe.object.PseudoRandom;
|
||||
import com.boydti.fawe.object.clipboard.WorldCopyClipboard;
|
||||
import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.blocks.BlockID;
|
||||
import com.sk89q.worldedit.blocks.BlockType;
|
||||
import com.sk89q.worldedit.entity.BaseEntity;
|
||||
import com.sk89q.worldedit.entity.Entity;
|
||||
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.operation.Operation;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
|
Loading…
Reference in New Issue
Block a user