Merge remote-tracking branch 'upstream/master' into merge

This commit is contained in:
Jesse Boyd
2019-11-19 21:23:47 +00:00
272 changed files with 16041 additions and 6107 deletions

View File

@ -19,45 +19,12 @@
package com.sk89q.worldedit.extension.platform;
import com.boydti.fawe.object.exception.FaweException;
import com.boydti.fawe.object.task.SimpleAsyncNotifyQueue;
import com.boydti.fawe.util.TaskManager;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.internal.cui.CUIEvent;
import java.io.File;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
public abstract class AbstractNonPlayerActor implements Actor {
private final ConcurrentHashMap<String, Object> meta = new ConcurrentHashMap<>();
@Override
public Map<String, Object> getRawMeta() {
return meta;
}
// Queue for async tasks
private AtomicInteger runningCount = new AtomicInteger();
private SimpleAsyncNotifyQueue asyncNotifyQueue = new SimpleAsyncNotifyQueue(
(thread, throwable) -> {
while (throwable.getCause() != null) {
throwable = throwable.getCause();
}
if (throwable instanceof WorldEditException) {
printError(throwable.getLocalizedMessage());
} else {
FaweException fe = FaweException.get(throwable);
if (fe != null) {
printError(fe.getMessage());
} else {
throwable.printStackTrace();
}
}
});
@Override
public boolean canDestroyBedrock() {
return true;
@ -81,35 +48,4 @@ public abstract class AbstractNonPlayerActor implements Actor {
@Override
public void dispatchCUIEvent(CUIEvent event) {
}
/**
* Run a task either async, or on the current thread
*
* @param ifFree
* @param checkFree Whether to first check if a task is running
* @param async
* @return false if the task was ran or queued
*/
@Override
public boolean runAction(Runnable ifFree, boolean checkFree, boolean async) {
if (checkFree) {
if (runningCount.get() != 0) {
return false;
}
}
Runnable wrapped = () -> {
try {
runningCount.addAndGet(1);
ifFree.run();
} finally {
runningCount.decrementAndGet();
}
};
if (async) {
asyncNotifyQueue.queue(wrapped);
} else {
TaskManager.IMP.taskNow(wrapped, false);
}
return true;
}
}

View File

@ -19,13 +19,14 @@
package com.sk89q.worldedit.extension.platform;
import com.sk89q.worldedit.EditSession;
import com.boydti.fawe.config.BBC;
import com.boydti.fawe.object.exception.FaweException;
import com.boydti.fawe.object.task.SimpleAsyncNotifyQueue;
import com.boydti.fawe.regions.FaweMaskManager;
import com.boydti.fawe.util.TaskManager;
import com.boydti.fawe.util.WEManager;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException;
@ -45,6 +46,8 @@ import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.RegionOperationException;
import com.sk89q.worldedit.regions.RegionSelector;
import com.sk89q.worldedit.regions.selector.ConvexPolyhedralRegionSelector;
import javax.annotation.Nullable;
import com.sk89q.worldedit.regions.selector.CuboidRegionSelector;
import com.sk89q.worldedit.regions.selector.CylinderRegionSelector;
import com.sk89q.worldedit.regions.selector.Polygonal2DRegionSelector;
@ -70,7 +73,6 @@ import java.text.NumberFormat;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
import javax.annotation.Nullable;
import org.enginehub.piston.inject.InjectedValueAccess;
import org.jetbrains.annotations.NotNull;
@ -249,7 +251,7 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
if (!lastState) {
lastState = BlockTypeUtil.centralBottomLimit(state) != 1;
continue;
}
}
if (freeStart == -1) {
freeStart = level + BlockTypeUtil.centralTopLimit(state);
} else {
@ -257,13 +259,13 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
double space = level + bottomLimit - freeStart;
if (space >= height) {
setPosition(Vector3.at(x + 0.5, freeStart, z + 0.5));
return true;
}
return true;
}
// Not enough room, reset the free position
if (bottomLimit != 1) {
freeStart = -1;
}
}
}
}
} else {
freeStart = -1;
lastState = true;
@ -414,7 +416,7 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
session.setBlock(spot, BlockTypes.GLASS.getDefaultState());
} catch (MaxChangedBlocksException ignored) {
}
}
}
} else {
setFlying(true);
}
@ -477,6 +479,23 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
return getBlockTrace(range, false);
}
/**
* Advances the block target block until the current block is a free
* @return true if a free spot is found
*/
private boolean advanceToFree(TargetBlock hitBlox) {
Location curBlock;
while ((curBlock = hitBlox.getCurrentBlock()) != null) {
if (canPassThroughBlock(curBlock)) {
return true;
}
hitBlox.getNextBlock();
}
return false;
}
@Override
public Location getSolidBlockTrace(int range) {
TargetBlock tb = new TargetBlock(this, range, 0.2);
@ -541,33 +560,17 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
return false;
}
/**
* Advances the block target block until the current block is a free
* @return true if a free spot is found
*/
private boolean advanceToFree(TargetBlock hitBlox) {
Location curBlock;
while ((curBlock = hitBlox.getCurrentBlock()) != null) {
if (canPassThroughBlock(curBlock)) {
return true;
}
hitBlox.getNextBlock();
}
return false;
}
@Override
public boolean passThroughForwardWall(int range) {
TargetBlock hitBlox = new TargetBlock(this, range, 0.2);
if (!advanceToWall(hitBlox)) {
return false;
}
return false;
}
if (!advanceToFree(hitBlox)) {
return false;
return false;
}
Location foundBlock = hitBlox.getCurrentBlock();
@ -576,7 +579,6 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
return true;
}
return false;
}

View File

@ -19,6 +19,11 @@
package com.sk89q.worldedit.extension.platform;
import com.sk89q.worldedit.internal.block.BlockStateIdAccess;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.registry.BlockRegistry;
/**
* A collection of capabilities that a {@link Platform} may support.
*/
@ -73,7 +78,22 @@ public enum Capability {
/**
* The capability of a platform to perform modifications to a world.
*/
WORLD_EDITING;
WORLD_EDITING {
@Override
void initialize(PlatformManager platformManager, Platform platform) {
BlockRegistry blockRegistry = platform.getRegistries().getBlockRegistry();
for (BlockType type : BlockType.REGISTRY) {
for (BlockState state : type.getAllStates()) {
BlockStateIdAccess.register(state, blockRegistry.getInternalBlockStateId(state));
}
}
}
@Override
void unload(PlatformManager platformManager, Platform platform) {
BlockStateIdAccess.clear();
}
};
void initialize(PlatformManager platformManager, Platform platform) {

View File

@ -321,45 +321,45 @@ public class PlatformManager {
if (!(actor instanceof Player)) {
return;
}
Player player = (Player) actor;
LocalSession session = worldEdit.getSessionManager().get(actor);
Player player = (Player) actor;
LocalSession session = worldEdit.getSessionManager().get(actor);
Request.reset();
Request.request().setSession(session);
Request.request().setWorld(player.getWorld());
Request.reset();
Request.request().setSession(session);
Request.request().setWorld(player.getWorld());
try {
try {
Vector3 vector = location.toVector();
VirtualWorld virtual = session.getVirtualWorld();
if (virtual != null) {
virtual.handleBlockInteract(player, vector.toBlockPoint(), event);
if (event.isCancelled()) return;
}
}
if (event.getType() == Interaction.HIT) {
// superpickaxe is special because its primary interaction is a left click, not a right click
// in addition, it is implicitly bound to all pickaxe items, not just a single tool item
if (session.hasSuperPickAxe() && player.isHoldingPickAxe()) {
final BlockTool superPickaxe = session.getSuperPickaxe();
if (superPickaxe != null && superPickaxe.canUse(player)) {
final BlockTool superPickaxe = session.getSuperPickaxe();
if (superPickaxe != null && superPickaxe.canUse(player)) {
player.runAction(() -> reset(superPickaxe)
.actPrimary(queryCapability(Capability.WORLD_EDITING),
getConfiguration(), player, session, location), false, true);
event.setCancelled(true);
return;
return;
}
}
}
Tool tool = session.getTool(player);
if (tool instanceof DoubleActionBlockTool && tool.canUse(player)) {
player.runAction(() -> reset(((DoubleActionBlockTool) tool))
.actSecondary(queryCapability(Capability.WORLD_EDITING),
getConfiguration(), player, session, location), false, true);
event.setCancelled(true);
}
event.setCancelled(true);
}
} else if (event.getType() == Interaction.OPEN) {
} else if (event.getType() == Interaction.OPEN) {
Tool tool = session.getTool(player);
if (tool instanceof BlockTool && tool.canUse(player)) {
if (player.checkAction()) {
@ -367,20 +367,20 @@ public class PlatformManager {
BlockTool blockTool = (BlockTool) tool;
if (!(tool instanceof BrushTool)) {
blockTool = reset(blockTool);
}
}
blockTool.actPrimary(queryCapability(Capability.WORLD_EDITING),
getConfiguration(), player, session, location);
}, false, true);
event.setCancelled(true);
}
}
}
}
}
} catch (Throwable e) {
handleThrowable(e, actor);
} finally {
Request.reset();
} finally {
Request.reset();
}
}
}
public void handleThrowable(Throwable e, Actor actor) {
FaweException faweException = FaweException.get(e);
@ -409,53 +409,29 @@ public class PlatformManager {
try {
switch (event.getInputType()) {
case PRIMARY: {
if (getConfiguration().navigationWandMaxDistance > 0 && player.getItemInHand(HandSide.MAIN_HAND).getType().getId().equals(getConfiguration().navigationWand)) {
if (!player.hasPermission("worldedit.navigation.jumpto.tool")) {
return;
}
Location pos = player.getSolidBlockTrace(getConfiguration().navigationWandMaxDistance);
if (pos != null) {
player.findFreePosition(pos);
} else {
player.printError(BBC.NO_BLOCK.s());
}
event.setCancelled(true);
return;
}
Tool tool = session.getTool(player);
if (tool instanceof DoubleActionTraceTool && tool.canUse(player)) {
player.runAsyncIfFree(() -> reset((DoubleActionTraceTool) tool).actSecondary(queryCapability(Capability.WORLD_EDITING),
getConfiguration(), player, session));
event.setCancelled(true);
return;
}
event.setCancelled(true);
}
return;
}
break;
}
case SECONDARY: {
if (getConfiguration().navigationWandMaxDistance > 0 && player.getItemInHand(HandSide.MAIN_HAND).getType().getId().equals(getConfiguration().navigationWand)) {
if (!player.hasPermission("worldedit.navigation.thru.tool")) {
return;
}
if (!player.passThroughForwardWall(40)) {
player.printError(BBC.NAVIGATION_WAND_ERROR.s());
}
event.setCancelled(true);
return;
}
Tool tool = session.getTool(player);
if (tool instanceof TraceTool && tool.canUse(player)) {
//todo this needs to be fixed so the event is canceled after actPrimary is used and returns true
player.runAction(() -> reset((TraceTool) tool).actPrimary(queryCapability(Capability.WORLD_EDITING),
getConfiguration(), player, session), false, true);
event.setCancelled(true);
return;
}
event.setCancelled(true);
}
return;
}
break;
}

View File

@ -221,4 +221,9 @@ public class PlayerProxy extends AbstractPlayerActor {
public Player getBasePlayer() {
return basePlayer;
}
@Override
public void floatAt(int x, int y, int z, boolean alwaysGlass) {
basePlayer.floatAt(x, y, z, alwaysGlass);
}
}