Feature/propagate diff and object cleanup (#1190)

* Feature/main/propagate diff annotations (#1187)

* 25% done

* More work

* More work

* 50%

* More work

* 75%

* 100% & cleanup

* Update adapters

* Squish squash, applesauce

commit 275ba9bd84
Author: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Date:   Sat Jul 17 01:10:20 2021 +0200

    Update dependency com.comphenix.protocol:ProtocolLib to v4.7.0 (#1173)

    Co-authored-by: Renovate Bot <bot@renovateapp.com>

commit 9fd8984804
Author: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Date:   Sat Jul 17 01:09:29 2021 +0200

    Update dependency org.checkerframework:checker-qual to v3.16.0 (#1184)

    Co-authored-by: Renovate Bot <bot@renovateapp.com>

commit 861fb45e5c
Author: dordsor21 <dordsor21@gmail.com>
Date:   Fri Jul 16 19:07:02 2021 +0100

    Fix #1075

commit 420c45a29a
Author: dordsor21 <dordsor21@gmail.com>
Date:   Fri Jul 16 18:48:21 2021 +0100

    Entity removal should be on the main thread as we're just passing through rather than doing chunk operations
     - Fixes #1164
     - Not working: butcher/remove history

commit 4d4db7dcd0
Author: SirYwell <hannesgreule@outlook.de>
Date:   Fri Jul 16 17:52:44 2021 +0200

    Make sure leaves category is loaded for heightmaps (fixes #1176)

commit c98f6e4f37
Author: dordsor21 <dordsor21@gmail.com>
Date:   Fri Jul 16 10:44:52 2021 +0100

    Do not allow generation commands to generate outside selection

commit 2485f5eccc
Author: dordsor21 <dordsor21@gmail.com>
Date:   Fri Jul 16 10:43:15 2021 +0100

    EditSession needs to override some Extent methods to ensure block changes are correctly set through the various extents
    Fixes #1152

commit d9418ec8ae
Author: dordsor21 <dordsor21@gmail.com>
Date:   Fri Jul 16 09:52:44 2021 +0100

    Undo part of 41073bb1a0
    Fixes #1178

* Update Upstream

fb1fb84 Fixed typo and grammar

* We don't support custom heights yet

* Casing inconsistency

* Address a few comments

* Address comments

* Don't refactor to AP classpath

* Document annotation style

* Refactoring & shade cleanup

* Address a few comments

* More work

* Resolve comments not being resolved yet

* Feature/main/propagate diff annotations (#1187) (#1194)

* Remove beta package, fix history packages, move classes out of object package

* Resolve comments not being resolved yet

* Remove beta package, fix history packages, move classes out of object package

Co-authored-by: NotMyFault <mc.cache@web.de>

* brushes should be under brush

* More refactoring
 - Filters/processors should be in the same place and are related to extents
 - Transforms are in `extent.transform` in upstream

* Move history classes under history

* Update adapters

Co-authored-by: dordsor21 <dordsor21@gmail.com>
This commit is contained in:
NotMyFault
2021-07-23 17:48:51 +02:00
committed by GitHub
parent ad102ab7a9
commit 50ab8ad5c7
799 changed files with 4916 additions and 10589 deletions

View File

@ -20,14 +20,14 @@
package com.sk89q.worldedit;
import com.fastasyncworldedit.core.Fawe;
import com.fastasyncworldedit.core.configuration.Caption;
import com.fastasyncworldedit.core.configuration.Settings;
import com.fastasyncworldedit.core.object.FaweInputStream;
import com.fastasyncworldedit.core.internal.io.FaweInputStream;
import com.fastasyncworldedit.core.object.FaweLimit;
import com.fastasyncworldedit.core.object.FaweOutputStream;
import com.fastasyncworldedit.core.object.changeset.DiskStorageHistory;
import com.fastasyncworldedit.core.object.clipboard.MultiClipboardHolder;
import com.fastasyncworldedit.core.object.collection.SparseBitSet;
import com.fastasyncworldedit.core.object.extent.ResettableExtent;
import com.fastasyncworldedit.core.internal.io.FaweOutputStream;
import com.fastasyncworldedit.core.history.DiskStorageHistory;
import com.fastasyncworldedit.core.extent.clipboard.MultiClipboardHolder;
import com.fastasyncworldedit.core.extent.ResettableExtent;
import com.fastasyncworldedit.core.util.BrushCache;
import com.fastasyncworldedit.core.util.EditSessionBuilder;
import com.fastasyncworldedit.core.util.MainUtil;
@ -76,6 +76,7 @@ import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.item.ItemTypes;
import com.sk89q.worldedit.world.snapshot.experimental.Snapshot;
import com.zaxxer.sparsebits.SparseBitSet;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import java.io.File;
@ -85,11 +86,9 @@ import java.io.IOException;
import java.time.ZoneId;
import java.util.Calendar;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Objects;
import java.util.TimeZone;
import java.util.UUID;
@ -122,6 +121,7 @@ public class LocalSession implements TextureHolder {
// Session related
private transient RegionSelector selector = new CuboidRegionSelector();
private transient boolean placeAtPos1 = false;
//FAWE start
private final transient List<Object> history = Collections.synchronizedList(new LinkedList<>() {
@Override
public Object get(int index) {
@ -139,12 +139,17 @@ public class LocalSession implements TextureHolder {
}
});
private transient volatile Integer historyNegativeIndex;
private transient final Lock historyWriteLock = new ReentrantLock(true);
private final transient Int2ObjectOpenHashMap<Tool> tools = new Int2ObjectOpenHashMap<>(0);
private transient Mask sourceMask;
private transient TextureUtil texture;
private transient ResettableExtent transform = null;
private transient World currentWorld;
//FAWE end
private transient ClipboardHolder clipboard;
private transient final Object clipboardLock = new Object();
private transient final Lock historyWriteLock = new ReentrantLock(true);
private transient boolean superPickaxe = false;
private transient BlockTool pickaxeMode = new SinglePickaxe();
private final transient Int2ObjectOpenHashMap<Tool> tools = new Int2ObjectOpenHashMap<>(0);
private transient int maxBlocksChanged = -1;
private transient int maxTimeoutTime;
private transient boolean useInventory;
@ -152,11 +157,7 @@ public class LocalSession implements TextureHolder {
private transient Snapshot snapshotExperimental;
private transient SideEffectSet sideEffectSet = SideEffectSet.defaults();
private transient Mask mask;
private transient Mask sourceMask;
private transient TextureUtil texture;
private transient ResettableExtent transform = null;
private transient ZoneId timezone = ZoneId.systemDefault();
private transient World currentWorld;
private transient UUID uuid;
private transient volatile long historySize = 0;
@ -174,7 +175,6 @@ public class LocalSession implements TextureHolder {
private boolean useServerCUI = false; // Save this to not annoy players.
private ItemType wandItem;
private ItemType navWandItem;
private Map<String, String> macros = new HashMap<>();
/**
* Construct the object.
@ -213,6 +213,7 @@ public class LocalSession implements TextureHolder {
}
}
//FAWE start
public boolean loadSessionHistoryFromDisk(UUID uuid, World world) {
if (world == null || uuid == null) {
return false;
@ -307,19 +308,7 @@ public class LocalSession implements TextureHolder {
file.delete();
}
}
public Map<String, String> getMacros() {
return Collections.unmodifiableMap(this.macros);
}
public void setMacro(String key, String value) {
this.macros.put(key, value);
setDirty();
}
public String getMacro(String key) {
return this.macros.get(key);
}
//FAWE end
/**
* Get whether this session is "dirty" and has changes that needs to
@ -338,6 +327,7 @@ public class LocalSession implements TextureHolder {
dirty.set(true);
}
//FAWE start
public int getHistoryIndex() {
return history.size() - 1 - (historyNegativeIndex == null ? 0 : historyNegativeIndex);
}
@ -360,6 +350,7 @@ public class LocalSession implements TextureHolder {
}
return false;
}
//FAWE end
/**
* Get whether this session is "dirty" and has changes that needs to
@ -395,9 +386,11 @@ public class LocalSession implements TextureHolder {
*/
public void clearHistory() {
history.clear();
//FAWE start
historyNegativeIndex = 0;
historySize = 0;
currentWorld = null;
//FAWE end
}
/**
@ -414,6 +407,7 @@ public class LocalSession implements TextureHolder {
return;
}
//FAWE start
Player player = editSession.getPlayer();
int limit = player == null ? Integer.MAX_VALUE : player.getLimit().MAX_HISTORY;
remember(editSession, true, limit);
@ -552,6 +546,7 @@ public class LocalSession implements TextureHolder {
historyWriteLock.unlock();
}
}
//FAWE end
/**
* Performs an undo.
@ -562,6 +557,7 @@ public class LocalSession implements TextureHolder {
*/
public EditSession undo(@Nullable BlockBag newBlockBag, Actor actor) {
checkNotNull(actor);
//FAWE start - use our logic
World world = ((Player) actor).getWorldForEditing();
loadSessionHistoryFromDisk(actor.getUniqueId(), world);
if (getHistoryNegativeIndex() < history.size()) {
@ -590,6 +586,7 @@ public class LocalSession implements TextureHolder {
}
return null;
}
//FAWE end
}
/**
@ -599,6 +596,7 @@ public class LocalSession implements TextureHolder {
* @param actor the actor
* @return whether anything was redone
*/
//FAWE start - use our logic
public EditSession redo(@Nullable BlockBag newBlockBag, Actor actor) {
checkNotNull(actor);
World world = ((Player) actor).getWorldForEditing();
@ -620,6 +618,7 @@ public class LocalSession implements TextureHolder {
return newEditSession;
}
}
//FAWE end
return null;
}
@ -775,14 +774,17 @@ public class LocalSession implements TextureHolder {
* @throws EmptyClipboardException thrown if no clipboard is set
*/
public ClipboardHolder getClipboard() throws EmptyClipboardException {
//FAWE start
synchronized (clipboardLock) {
if (clipboard == null) {
throw new EmptyClipboardException();
}
//FAWE end
return clipboard;
}
}
//FAWE start
@Nullable
public ClipboardHolder getExistingClipboard() {
synchronized (clipboardLock) {
@ -810,6 +812,7 @@ public class LocalSession implements TextureHolder {
}
setClipboard(multi);
}
//FAWE end
/**
* Sets the clipboard.
@ -819,6 +822,7 @@ public class LocalSession implements TextureHolder {
* @param clipboard the clipboard, or null if the clipboard is to be cleared
*/
public void setClipboard(@Nullable ClipboardHolder clipboard) {
//FAWE start
synchronized (clipboardLock) {
if (this.clipboard == clipboard) {
return;
@ -829,6 +833,7 @@ public class LocalSession implements TextureHolder {
this.clipboard.close();
}
}
//FAWE end
this.clipboard = clipboard;
}
}
@ -967,7 +972,9 @@ public class LocalSession implements TextureHolder {
@Nullable
public BlockBag getBlockBag(Player player) {
checkNotNull(player);
//FAWE start - inventory mode
if (!useInventory && player.getLimit().INVENTORY_MODE == 0) {
//FAWE end
return null;
}
return player.getInventoryBlockBag();
@ -1044,6 +1051,7 @@ public class LocalSession implements TextureHolder {
}
}
//FAWE start
@Nullable
public Tool getTool(Player player) {
loadDefaults(player, false);
@ -1087,7 +1095,9 @@ public class LocalSession implements TextureHolder {
}
}
}
//FAWE end
//FAWE start - see deprecation note
/**
* Get the brush tool assigned to the item. If there is no tool assigned
* or the tool is not assigned, the slot will be replaced with the
@ -1114,7 +1124,7 @@ public class LocalSession implements TextureHolder {
public BrushTool getBrushTool(BaseItem item, Player player, boolean create) throws InvalidToolBindException {
if (item.getType().hasBlockType()) {
throw new InvalidToolBindException(item.getType(), "Blocks can't be used");
throw new InvalidToolBindException(item.getType(), Caption.of("worldedit.error.blocks-cant-be-used"));
}
Tool tool = getTool(item, player);
if (!(tool instanceof BrushTool)) {
@ -1128,7 +1138,9 @@ public class LocalSession implements TextureHolder {
return (BrushTool) tool;
}
//FAWE end
//FAWE start - see note of getBrushTool
/**
* Set the tool.
*
@ -1138,7 +1150,7 @@ public class LocalSession implements TextureHolder {
*/
public void setTool(ItemType item, @Nullable Tool tool) throws InvalidToolBindException {
if (item.hasBlockType()) {
throw new InvalidToolBindException(item, "Blocks can't be used");
throw new InvalidToolBindException(item, Caption.of("worldedit.error.blocks-cant-be-used"));
}
if (tool instanceof SelectionWand) {
changeTool(this.wandItem, this.wandItem = item, tool);
@ -1175,7 +1187,7 @@ public class LocalSession implements TextureHolder {
public void setTool(BaseItem item, @Nullable Tool tool, Player player) throws InvalidToolBindException {
ItemType type = item.getType();
if (type.hasBlockType() && type.getBlockType().getMaterial().isAir()) {
throw new InvalidToolBindException(type, "Blocks can't be used");
throw new InvalidToolBindException(type, Caption.of("worldedit.error.blocks-cant-be-used"));
} else if (tool instanceof SelectionWand) {
changeTool(this.wandItem, this.wandItem = item.getType(), tool);
setDirty();
@ -1208,6 +1220,7 @@ public class LocalSession implements TextureHolder {
}
}
}
//FAWE end
/**
* Returns whether inventory usage is enabled for this session.
@ -1380,7 +1393,9 @@ public class LocalSession implements TextureHolder {
public void describeCUI(Actor actor) {
checkNotNull(actor);
//FAWE start
// TODO preload
//FAWE end
if (!hasCUISupport) {
return;
@ -1518,6 +1533,7 @@ public class LocalSession implements TextureHolder {
}
// Create an edit session
//FAWE start - we don't use the edit session builder yet
EditSession editSession;
EditSessionBuilder builder = new EditSessionBuilder(world);
if (actor.isPlayer() && actor instanceof Player) {
@ -1543,6 +1559,7 @@ public class LocalSession implements TextureHolder {
return editSession;
}
//FAWE end
private void prepareEditingExtents(EditSession editSession, Actor actor) {
editSession.setSideEffectApplier(sideEffectSet);
@ -1617,6 +1634,7 @@ public class LocalSession implements TextureHolder {
return mask;
}
//FAWE start
/**
* Get the mask.
*
@ -1625,6 +1643,7 @@ public class LocalSession implements TextureHolder {
public Mask getSourceMask() {
return sourceMask;
}
//FAWE end
/**
* Set a mask.
@ -1635,6 +1654,7 @@ public class LocalSession implements TextureHolder {
this.mask = mask;
}
//FAWE start
/**
* Set a mask.
*
@ -1662,6 +1682,7 @@ public class LocalSession implements TextureHolder {
}
return tmp;
}
//FAWE end
/**
* Get the preferred wand item for this user, or {@code null} to use the default