mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-01 02:46:41 +00:00
wip on 1.14
This commit is contained in:
@ -2,14 +2,36 @@ package com.boydti.fawe.util;
|
||||
|
||||
import com.boydti.fawe.Fawe;
|
||||
import com.boydti.fawe.FaweAPI;
|
||||
import com.boydti.fawe.config.BBC;
|
||||
import com.boydti.fawe.config.Settings;
|
||||
import com.boydti.fawe.jnbt.anvil.MCAQueue;
|
||||
import com.boydti.fawe.jnbt.anvil.MCAWorld;
|
||||
import com.boydti.fawe.logging.LoggingChangeSet;
|
||||
import com.boydti.fawe.logging.rollback.RollbackOptimizedHistory;
|
||||
import com.boydti.fawe.object.*;
|
||||
import com.boydti.fawe.object.brush.visualization.VirtualWorld;
|
||||
import com.boydti.fawe.object.changeset.BlockBagChangeSet;
|
||||
import com.boydti.fawe.object.changeset.CPUOptimizedChangeSet;
|
||||
import com.boydti.fawe.object.changeset.DiskStorageHistory;
|
||||
import com.boydti.fawe.object.changeset.FaweChangeSet;
|
||||
import com.boydti.fawe.object.changeset.MemoryOptimizedHistory;
|
||||
import com.boydti.fawe.object.exception.FaweException;
|
||||
import com.boydti.fawe.object.extent.FastWorldEditExtent;
|
||||
import com.boydti.fawe.object.extent.HeightBoundExtent;
|
||||
import com.boydti.fawe.object.extent.MultiRegionExtent;
|
||||
import com.boydti.fawe.object.extent.NullExtent;
|
||||
import com.boydti.fawe.object.extent.ProcessedWEExtent;
|
||||
import com.boydti.fawe.object.extent.SingleRegionExtent;
|
||||
import com.boydti.fawe.object.extent.SlowExtent;
|
||||
import com.boydti.fawe.object.extent.StripNBTExtent;
|
||||
import com.boydti.fawe.object.progress.ChatProgressTracker;
|
||||
import com.boydti.fawe.object.progress.DefaultProgressTracker;
|
||||
import com.boydti.fawe.wrappers.WorldWrapper;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.event.extent.EditSessionEvent;
|
||||
import com.sk89q.worldedit.extent.AbstractDelegateExtent;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.extent.inventory.BlockBag;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.util.eventbus.EventBus;
|
||||
@ -57,6 +79,12 @@ public class EditSessionBuilder {
|
||||
this.worldName = Fawe.imp().getWorldName(world);
|
||||
}
|
||||
|
||||
public EditSessionBuilder(World world, String worldName) {
|
||||
if (world == null && worldName == null) throw new NullPointerException("Both world and worldname cannot be null");
|
||||
this.world = world;
|
||||
this.worldName = worldName;
|
||||
}
|
||||
|
||||
public EditSessionBuilder(@Nonnull String worldName) {
|
||||
checkNotNull(worldName);
|
||||
this.worldName = worldName;
|
||||
@ -190,7 +218,274 @@ public class EditSessionBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
private boolean wrapped;
|
||||
|
||||
private AbstractDelegateExtent wrapExtent(final AbstractDelegateExtent extent, final EventBus eventBus, EditSessionEvent event, final EditSession.Stage stage) {
|
||||
event = event.clone(stage);
|
||||
event.setExtent(extent);
|
||||
eventBus.post(event);
|
||||
if (event.isCancelled()) {
|
||||
return new NullExtent(extent, FaweException.MANUAL);
|
||||
}
|
||||
final Extent toReturn = event.getExtent();
|
||||
if(toReturn instanceof com.sk89q.worldedit.extent.NullExtent) {
|
||||
return new NullExtent(toReturn, FaweException.MANUAL);
|
||||
}
|
||||
if (!(toReturn instanceof AbstractDelegateExtent)) {
|
||||
Fawe.debug("Extent " + toReturn + " must be AbstractDelegateExtent");
|
||||
return extent;
|
||||
}
|
||||
if (toReturn != extent) {
|
||||
String className = toReturn.getClass().getName().toLowerCase();
|
||||
for (String allowed : Settings.IMP.EXTENT.ALLOWED_PLUGINS) {
|
||||
if (className.contains(allowed.toLowerCase())) {
|
||||
this.wrapped = true;
|
||||
return (AbstractDelegateExtent) toReturn;
|
||||
}
|
||||
}
|
||||
if (Settings.IMP.EXTENT.DEBUG) {
|
||||
Fawe.debug("&cPotentially unsafe extent blocked: " + toReturn.getClass().getName());
|
||||
Fawe.debug("&8 - &7For area restrictions, it is recommended to use the FaweAPI");
|
||||
Fawe.debug("&8 - &7For block logging, it is recommended to use use BlocksHub");
|
||||
Fawe.debug("&8 - &7To allow this plugin add it to the FAWE `allowed-plugins` list");
|
||||
Fawe.debug("&8 - &7To hide this message set `debug` to false in the FAWE config.yml");
|
||||
if (toReturn.getClass().getName().contains("CoreProtect")) {
|
||||
Fawe.debug("Note on CoreProtect: ");
|
||||
Fawe.debug(" - If you disable CP's WE logger (CP config) and this still shows, please update CP");
|
||||
Fawe.debug(" - Use BlocksHub and set `debug` false in the FAWE config");
|
||||
}
|
||||
}
|
||||
}
|
||||
return extent;
|
||||
}
|
||||
|
||||
private FaweChangeSet changeTask;
|
||||
private AbstractDelegateExtent extent;
|
||||
private int maxY;
|
||||
private HistoryExtent history;
|
||||
private AbstractDelegateExtent bypassHistory;
|
||||
private AbstractDelegateExtent bypassAll;
|
||||
|
||||
public EditSessionBuilder compile() {
|
||||
if (extent != null) return this;
|
||||
|
||||
wrapped = false;
|
||||
//
|
||||
if (worldName == null) {
|
||||
if (world == null) {
|
||||
if (queue == null) {
|
||||
worldName = "";
|
||||
} else {
|
||||
worldName = queue.getWorldName();
|
||||
}
|
||||
} else {
|
||||
worldName = Fawe.imp().getWorldName(world);
|
||||
}
|
||||
}
|
||||
if (world == null && !this.worldName.isEmpty()) {
|
||||
world = FaweAPI.getWorld(this.worldName);
|
||||
}
|
||||
if (eventBus == null) {
|
||||
eventBus = WorldEdit.getInstance().getEventBus();
|
||||
}
|
||||
if (event == null) {
|
||||
event = new EditSessionEvent(world, player == null ? null : (player.getPlayer()), -1, null);
|
||||
}
|
||||
if (player == null && event.getActor() != null) {
|
||||
player = FawePlayer.wrap(event.getActor());
|
||||
}
|
||||
if (limit == null) {
|
||||
if (player == null) {
|
||||
limit = FaweLimit.MAX;
|
||||
} else {
|
||||
limit = player.getLimit();
|
||||
}
|
||||
}
|
||||
if (autoQueue == null) {
|
||||
autoQueue = true;
|
||||
}
|
||||
if (fastmode == null) {
|
||||
if (player == null) {
|
||||
fastmode = !Settings.IMP.HISTORY.ENABLE_FOR_CONSOLE;
|
||||
} else {
|
||||
fastmode = player.getSession().hasFastMode();
|
||||
}
|
||||
}
|
||||
if (checkMemory == null) {
|
||||
checkMemory = player != null && !this.fastmode;
|
||||
}
|
||||
if (checkMemory) {
|
||||
if (MemUtil.isMemoryLimitedSlow()) {
|
||||
if (Perm.hasPermission(player, "worldedit.fast")) {
|
||||
BBC.WORLDEDIT_OOM_ADMIN.send(player);
|
||||
}
|
||||
throw FaweException.LOW_MEMORY;
|
||||
}
|
||||
}
|
||||
// this.originalLimit = limit;
|
||||
this.blockBag = limit.INVENTORY_MODE != 0 ? blockBag : null;
|
||||
// this.limit = limit.copy();
|
||||
|
||||
if (queue == null) {
|
||||
boolean placeChunks = this.fastmode || this.limit.FAST_PLACEMENT;
|
||||
World unwrapped = WorldWrapper.unwrap(world);
|
||||
if (unwrapped instanceof FaweQueue) {
|
||||
queue = (FaweQueue) unwrapped;
|
||||
} else if (unwrapped instanceof MCAWorld) {
|
||||
queue = ((MCAWorld) unwrapped).getQueue();
|
||||
} else if (player != null && world.equals(player.getWorld())) {
|
||||
queue = player.getFaweQueue(placeChunks, autoQueue);
|
||||
} else {
|
||||
queue = SetQueue.IMP.getNewQueue(world, placeChunks, autoQueue);
|
||||
}
|
||||
}
|
||||
if (combineStages == null) {
|
||||
combineStages =
|
||||
// If it's enabled in the settings
|
||||
Settings.IMP.HISTORY.COMBINE_STAGES
|
||||
// If fast placement is disabled, it's slower to perform a copy on each chunk
|
||||
&& this.limit.FAST_PLACEMENT
|
||||
// If the specific queue doesn't support it
|
||||
&& queue.supports(FaweQueue.Capability.CHANGE_TASKS)
|
||||
// If the edit uses items from the inventory we can't use a delayed task
|
||||
&& this.blockBag == null;
|
||||
}
|
||||
if (!Settings.IMP.QUEUE.PROGRESS.DISPLAY.equalsIgnoreCase("false") && player != null) {
|
||||
switch (Settings.IMP.QUEUE.PROGRESS.DISPLAY.toLowerCase()) {
|
||||
case "chat":
|
||||
this.queue.setProgressTask(new ChatProgressTracker(player));
|
||||
break;
|
||||
case "title":
|
||||
case "true":
|
||||
default:
|
||||
this.queue.setProgressTask(new DefaultProgressTracker(player));
|
||||
}
|
||||
}
|
||||
this.bypassAll = wrapExtent(new FastWorldEditExtent(world, queue), eventBus, event, EditSession.Stage.BEFORE_CHANGE);
|
||||
this.bypassHistory = (this.extent = wrapExtent(bypassAll, eventBus, event, EditSession.Stage.BEFORE_REORDER));
|
||||
if (!this.fastmode || changeSet != null) {
|
||||
if (changeSet == null) {
|
||||
if (Settings.IMP.HISTORY.USE_DISK) {
|
||||
UUID uuid = player == null ? EditSession.CONSOLE : player.getUUID();
|
||||
if (Settings.IMP.HISTORY.USE_DATABASE) {
|
||||
changeSet = new RollbackOptimizedHistory(world, uuid);
|
||||
} else {
|
||||
changeSet = new DiskStorageHistory(world, uuid);
|
||||
}
|
||||
} else if (combineStages && Settings.IMP.HISTORY.COMPRESSION_LEVEL == 0 && !(queue instanceof MCAQueue)) {
|
||||
changeSet = new CPUOptimizedChangeSet(world);
|
||||
} else {
|
||||
changeSet = new MemoryOptimizedHistory(world);
|
||||
}
|
||||
}
|
||||
if (this.limit.SPEED_REDUCTION > 0) {
|
||||
this.bypassHistory = new SlowExtent(this.bypassHistory, this.limit.SPEED_REDUCTION);
|
||||
}
|
||||
if (changeSet instanceof NullChangeSet && Fawe.imp().getBlocksHubApi() != null && player != null) {
|
||||
changeSet = LoggingChangeSet.wrap(player, changeSet);
|
||||
}
|
||||
if (!(changeSet instanceof NullChangeSet)) {
|
||||
if (!(changeSet instanceof LoggingChangeSet) && player != null && Fawe.imp().getBlocksHubApi() != null) {
|
||||
changeSet = LoggingChangeSet.wrap(player, changeSet);
|
||||
}
|
||||
if (this.blockBag != null) {
|
||||
changeSet = new BlockBagChangeSet(changeSet, blockBag, limit.INVENTORY_MODE == 1);
|
||||
}
|
||||
if (combineStages) {
|
||||
changeTask = changeSet;
|
||||
changeSet.addChangeTask(queue);
|
||||
} else {
|
||||
this.extent = (history = new HistoryExtent(bypassHistory, changeSet, queue));
|
||||
// if (this.blockBag != null) {
|
||||
// this.extent = new BlockBagExtent(this.extent, blockBag, limit.INVENTORY_MODE == 1);
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
if (allowedRegions == null) {
|
||||
if (player != null && !player.hasPermission("fawe.bypass") && !player.hasPermission("fawe.bypass.regions") && !(queue instanceof VirtualWorld)) {
|
||||
allowedRegions = player.getCurrentRegions();
|
||||
}
|
||||
}
|
||||
this.maxY = world == null ? 255 : world.getMaxY();
|
||||
if (allowedRegions != null) {
|
||||
if (allowedRegions.length == 0) {
|
||||
this.extent = new NullExtent(this.extent, FaweException.NO_REGION);
|
||||
} else {
|
||||
this.extent = new ProcessedWEExtent(this.extent, this.limit);
|
||||
if (allowedRegions.length == 1) {
|
||||
this.extent = new SingleRegionExtent(this.extent, this.limit, allowedRegions[0]);
|
||||
} else {
|
||||
this.extent = new MultiRegionExtent(this.extent, this.limit, allowedRegions);
|
||||
}
|
||||
}
|
||||
} 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, eventBus, event, EditSession.Stage.BEFORE_HISTORY);
|
||||
return this;
|
||||
}
|
||||
|
||||
public EditSession build() {
|
||||
return new EditSession(worldName, world, queue, player, limit, changeSet, allowedRegions, autoQueue, fastmode, checkMemory, combineStages, blockBag, eventBus, event);
|
||||
return new EditSession(this);
|
||||
}
|
||||
|
||||
public Extent getExtent() {
|
||||
return extent;
|
||||
}
|
||||
|
||||
public World getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
public String getWorldName() {
|
||||
return worldName;
|
||||
}
|
||||
|
||||
public FaweQueue getQueue() {
|
||||
return queue;
|
||||
}
|
||||
|
||||
public boolean isWrapped() {
|
||||
return wrapped;
|
||||
}
|
||||
|
||||
public boolean hasFastMode() {
|
||||
return fastmode;
|
||||
}
|
||||
|
||||
public HistoryExtent getHistory() {
|
||||
return history;
|
||||
}
|
||||
|
||||
public AbstractDelegateExtent getBypassHistory() {
|
||||
return bypassHistory;
|
||||
}
|
||||
|
||||
public AbstractDelegateExtent getBypassAll() {
|
||||
return bypassAll;
|
||||
}
|
||||
|
||||
public FaweLimit getLimit() {
|
||||
return limit;
|
||||
}
|
||||
|
||||
public FawePlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public FaweChangeSet getChangeTask() {
|
||||
return changeTask;
|
||||
}
|
||||
|
||||
public BlockBag getBlockBag() {
|
||||
return blockBag;
|
||||
}
|
||||
|
||||
public int getMaxY() {
|
||||
return maxY;
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,14 @@
|
||||
package com.boydti.fawe.util;
|
||||
|
||||
import com.boydti.fawe.Fawe;
|
||||
import com.boydti.fawe.beta.SingleFilterBlock;
|
||||
import com.boydti.fawe.config.Settings;
|
||||
import com.boydti.fawe.object.pattern.PatternExtent;
|
||||
import com.boydti.fawe.util.image.ImageUtil;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.pattern.BlockPattern;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
@ -66,14 +65,15 @@ public class TextureUtil implements TextureHolder {
|
||||
|
||||
public static TextureUtil fromMask(Mask mask) throws FileNotFoundException {
|
||||
HashSet<BlockType> blocks = new HashSet<>();
|
||||
BlockPattern pattern = new BlockPattern(BlockTypes.AIR.getDefaultState());
|
||||
PatternExtent extent = new PatternExtent(pattern);
|
||||
|
||||
SingleFilterBlock extent = new SingleFilterBlock();
|
||||
new MaskTraverser(mask).reset(extent);
|
||||
|
||||
TextureUtil tu = Fawe.get().getTextureUtil();
|
||||
for (int typeId : tu.getValidBlockIds()) {
|
||||
BlockType block = BlockTypes.get(typeId);
|
||||
pattern.setBlock(block.getDefaultState());
|
||||
if (mask.test(BlockVector3.ZERO)) {
|
||||
extent.init(0, 0, 0, block.getDefaultState().toBaseBlock());
|
||||
if (mask.test(extent)) {
|
||||
blocks.add(block);
|
||||
}
|
||||
}
|
||||
@ -491,7 +491,7 @@ public class TextureUtil implements TextureHolder {
|
||||
BlockType block = getNearestBlock(color);
|
||||
TextureUtil.BiomeColor biome = getNearestBiome(color);
|
||||
int blockColor = getColor(block);
|
||||
blockAndBiomeIdOutput[0] = block.getInternalId();
|
||||
blockAndBiomeIdOutput[0] = block.getDefaultState().getOrdinalChar();
|
||||
blockAndBiomeIdOutput[1] = biome.id;
|
||||
if (colorDistance(biome.grassCombined, color) - biomePriority > colorDistance(blockColor,
|
||||
color)) {
|
||||
|
@ -24,7 +24,7 @@ public class WEManager {
|
||||
|
||||
public final ArrayDeque<FaweMaskManager> managers = new ArrayDeque<>();
|
||||
|
||||
public void cancelEditSafe(Extent parent, BBC reason) throws FaweException {
|
||||
public void cancelEditSafe(Extent parent, FaweException reason) throws FaweException {
|
||||
try {
|
||||
final Field field = AbstractDelegateExtent.class.getDeclaredField("extent");
|
||||
field.setAccessible(true);
|
||||
@ -35,10 +35,10 @@ public class WEManager {
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
throw new FaweException(reason);
|
||||
throw reason;
|
||||
}
|
||||
|
||||
public void cancelEdit(Extent parent, BBC reason) throws WorldEditException {
|
||||
public void cancelEdit(Extent parent, FaweException reason) throws WorldEditException {
|
||||
cancelEditSafe(parent, reason);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user