mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-05 04:26:42 +00:00
Feature/unsafe over reflections (#1082)
* Use Unsafe to replace Lock * Start cleaning up everything that has to do with CleanableThreadLocal * Make cancellation work Co-authored-by: NotMyFault <mc.cache@web.de>
This commit is contained in:
@ -23,7 +23,6 @@ import com.boydti.fawe.config.Caption;
|
||||
import com.boydti.fawe.object.brush.BrushSettings;
|
||||
import com.boydti.fawe.object.brush.TargetMode;
|
||||
import com.boydti.fawe.object.brush.scroll.Scroll;
|
||||
import com.boydti.fawe.object.brush.visualization.VisualMode;
|
||||
import com.boydti.fawe.util.MathMan;
|
||||
import com.boydti.fawe.util.StringMan;
|
||||
import com.google.common.collect.Iterables;
|
||||
@ -231,31 +230,6 @@ public class ToolUtilCommands {
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
name = "visualize",
|
||||
aliases = {"visual", "vis", "/visualize", "/visual", "/vis"},
|
||||
desc = "Toggle between different visualization modes",
|
||||
descFooter = "Toggle between different visualization modes\n"
|
||||
+ "0 = No visualization\n"
|
||||
+ "1 = Single block at target position\n"
|
||||
+ "2 = Glass showing what blocks will be changed"
|
||||
)
|
||||
@CommandPermissions("worldedit.brush.visualize")
|
||||
public void visual(Player player, LocalSession session,
|
||||
@Arg(name = "mode", desc = "int", def = "0")
|
||||
@Range(from = 0, to = 2)
|
||||
int mode) throws WorldEditException {
|
||||
BrushTool tool = session.getBrushTool(player, false);
|
||||
if (tool == null) {
|
||||
player.print(Caption.of("fawe.worldedit.brush.brush.none"));
|
||||
return;
|
||||
}
|
||||
VisualMode[] modes = VisualMode.values();
|
||||
VisualMode newMode = modes[MathMan.wrap(mode, 0, modes.length - 1)];
|
||||
tool.setVisualMode(player, newMode);
|
||||
player.print(Caption.of("fawe.worldedit.brush.brush.visual.mode.set", newMode));
|
||||
}
|
||||
|
||||
@Command(
|
||||
name = "target",
|
||||
aliases = {"tar", "/target", "/tar"},
|
||||
|
@ -19,10 +19,8 @@
|
||||
|
||||
package com.sk89q.worldedit.command.tool;
|
||||
|
||||
import com.boydti.fawe.Fawe;
|
||||
import com.boydti.fawe.beta.implementation.IChunkExtent;
|
||||
import com.boydti.fawe.beta.implementation.processors.NullProcessor;
|
||||
import com.boydti.fawe.beta.implementation.processors.PersistentChunkSendProcessor;
|
||||
import com.boydti.fawe.config.Caption;
|
||||
import com.boydti.fawe.object.brush.BrushSettings;
|
||||
import com.boydti.fawe.object.brush.MovableTool;
|
||||
@ -30,8 +28,6 @@ import com.boydti.fawe.object.brush.ResettableTool;
|
||||
import com.boydti.fawe.object.brush.TargetMode;
|
||||
import com.boydti.fawe.object.brush.scroll.Scroll;
|
||||
import com.boydti.fawe.object.brush.scroll.ScrollTool;
|
||||
import com.boydti.fawe.object.brush.visualization.VisualExtent;
|
||||
import com.boydti.fawe.object.brush.visualization.VisualMode;
|
||||
import com.boydti.fawe.object.extent.ResettableExtent;
|
||||
import com.boydti.fawe.object.mask.MaskedTargetBlock;
|
||||
import com.boydti.fawe.object.pattern.PatternTraverser;
|
||||
@ -93,7 +89,6 @@ public class BrushTool
|
||||
protected static int MAX_RANGE = 500;
|
||||
protected static int DEFAULT_RANGE = 240; // 500 is laggy as the default
|
||||
protected int range = -1;
|
||||
private VisualMode visualMode = VisualMode.NONE;
|
||||
private TargetMode targetMode = TargetMode.TARGET_BLOCK_RANGE;
|
||||
private Mask traceMask = null;
|
||||
private int targetOffset;
|
||||
@ -102,8 +97,6 @@ public class BrushTool
|
||||
private transient BrushSettings secondary = new BrushSettings();
|
||||
private transient BrushSettings context = primary;
|
||||
|
||||
private transient PersistentChunkSendProcessor visualExtent;
|
||||
|
||||
private transient BaseItem holder;
|
||||
|
||||
/**
|
||||
@ -517,26 +510,6 @@ public class BrushTool
|
||||
update();
|
||||
}
|
||||
|
||||
public void setVisualMode(Player player, VisualMode visualMode) {
|
||||
if (visualMode == null) {
|
||||
visualMode = VisualMode.NONE;
|
||||
}
|
||||
if (this.visualMode != visualMode) {
|
||||
if (this.visualMode != VisualMode.NONE) {
|
||||
clear(player);
|
||||
}
|
||||
this.visualMode = visualMode;
|
||||
if (visualMode != VisualMode.NONE) {
|
||||
try {
|
||||
queueVisualization(player);
|
||||
} catch (Throwable e) {
|
||||
WorldEdit.getInstance().getPlatformManager().handleThrowable(e, player);
|
||||
}
|
||||
}
|
||||
}
|
||||
update();
|
||||
}
|
||||
|
||||
public TargetMode getTargetMode() {
|
||||
return targetMode;
|
||||
}
|
||||
@ -545,114 +518,19 @@ public class BrushTool
|
||||
return targetOffset;
|
||||
}
|
||||
|
||||
public VisualMode getVisualMode() {
|
||||
return visualMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean increment(Player player, int amount) {
|
||||
BrushSettings current = getContext();
|
||||
Scroll tmp = current.getScrollAction();
|
||||
if (tmp != null) {
|
||||
tmp.setTool(this);
|
||||
if (tmp.increment(player, amount)) {
|
||||
if (visualMode != VisualMode.NONE) {
|
||||
try {
|
||||
queueVisualization(player);
|
||||
} catch (Throwable e) {
|
||||
WorldEdit.getInstance().getPlatformManager().handleThrowable(e, player);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (visualMode != VisualMode.NONE) {
|
||||
clear(player);
|
||||
return tmp.increment(player, amount);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void queueVisualization(Player player) {
|
||||
Fawe.get().getVisualQueue().queue(player);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public synchronized void visualize(BrushTool.BrushAction action, Player player)
|
||||
throws WorldEditException {
|
||||
VisualMode mode = getVisualMode();
|
||||
if (mode == VisualMode.NONE) {
|
||||
return;
|
||||
}
|
||||
BrushSettings current = getContext();
|
||||
Brush brush = current.getBrush();
|
||||
if (brush == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
EditSessionBuilder builder =
|
||||
new EditSessionBuilder(player.getWorld()).command(current.toString()).player(player)
|
||||
.allowedRegionsEverywhere().autoQueue(false).blockBag(null).changeSetNull()
|
||||
.fastmode(true).combineStages(true);
|
||||
EditSession editSession = builder.build();
|
||||
|
||||
World world = editSession.getWorld();
|
||||
Supplier<Collection<Player>> players = () -> Collections.singleton(player);
|
||||
|
||||
PersistentChunkSendProcessor newVisualExtent =
|
||||
new PersistentChunkSendProcessor(world, this.visualExtent, players);
|
||||
ExtentTraverser<IChunkExtent> traverser =
|
||||
new ExtentTraverser<>(editSession).find(IChunkExtent.class);
|
||||
if (traverser == null) {
|
||||
throw new IllegalStateException("No queue found");
|
||||
}
|
||||
|
||||
IChunkExtent chunkExtent = traverser.get();
|
||||
if (this.visualExtent != null) {
|
||||
this.visualExtent.init(chunkExtent);
|
||||
}
|
||||
newVisualExtent.init(chunkExtent);
|
||||
|
||||
editSession.addProcessor(newVisualExtent);
|
||||
editSession.addProcessor(NullProcessor.getInstance());
|
||||
|
||||
BlockVector3 position = getPosition(editSession, player);
|
||||
if (position != null) {
|
||||
switch (mode) {
|
||||
case POINT:
|
||||
editSession.setBlock(position, VisualExtent.VISUALIZE_BLOCK_DEFAULT);
|
||||
break;
|
||||
case OUTLINE: {
|
||||
new PatternTraverser(current).reset(editSession);
|
||||
brush.build(editSession, position, current.getMaterial(), current.getSize());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw new IllegalStateException("Unexpected value: " + mode);
|
||||
}
|
||||
}
|
||||
editSession.flushQueue();
|
||||
|
||||
if (visualExtent != null) {
|
||||
// clear old data
|
||||
visualExtent.flush();
|
||||
}
|
||||
visualExtent = newVisualExtent;
|
||||
newVisualExtent.flush();
|
||||
}
|
||||
|
||||
public void clear(Player player) {
|
||||
Fawe.get().getVisualQueue().dequeue(player);
|
||||
if (visualExtent != null) {
|
||||
visualExtent.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean move(Player player) {
|
||||
if (visualMode != VisualMode.NONE) {
|
||||
queueVisualization(player);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user