Fixes #255 compass exceptipn

This commit is contained in:
Jesse Boyd 2019-11-23 05:15:48 +00:00
parent 97a4d2e103
commit 944c8c5521
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
8 changed files with 131 additions and 81 deletions

View File

@ -21,9 +21,6 @@ package com.sk89q.worldedit.bukkit;
import static com.google.common.base.Preconditions.checkNotNull;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.wrappers.PlayerWrapper;
import com.sk89q.worldedit.NotABlockException;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
@ -37,22 +34,12 @@ import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.biome.BiomeTypes;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.entity.EntityType;
import com.sk89q.worldedit.world.entity.EntityTypes;
import com.sk89q.worldedit.world.gamemode.GameMode;
import com.sk89q.worldedit.world.gamemode.GameModes;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.item.ItemTypes;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.Biome;
import org.bukkit.block.data.BlockData;

View File

@ -2,7 +2,7 @@ package com.boydti.fawe.object.brush;
import com.boydti.fawe.util.StringMan;
import com.boydti.fawe.wrappers.LocationMaskedPlayerWrapper;
import com.boydti.fawe.wrappers.PlayerWrapper;
import com.boydti.fawe.wrappers.AsyncPlayer;
import com.boydti.fawe.wrappers.SilentPlayerWrapper;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
@ -42,7 +42,7 @@ public class CommandBrush implements Brush {
position = position.add(face.getDirection().toBlockPoint());
}
player.setSelection(selector);
PlayerWrapper wePlayer = new SilentPlayerWrapper(new LocationMaskedPlayerWrapper(player, new Location(player.getExtent(), position.toVector3())));
AsyncPlayer wePlayer = new SilentPlayerWrapper(new LocationMaskedPlayerWrapper(player, new Location(player.getExtent(), position.toVector3())));
List<String> cmds = StringMan.split(replaced, ';');
for (String cmd : cmds) {
CommandEvent event = new CommandEvent(wePlayer, cmd);

View File

@ -17,16 +17,16 @@ import com.sk89q.worldedit.util.TargetBlock;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BlockTypes;
public class PlayerWrapper extends PlayerProxy {
public PlayerWrapper(Player parent) {
public class AsyncPlayer extends PlayerProxy {
public AsyncPlayer(Player parent) {
super(parent);
}
public static PlayerWrapper wrap(Player parent) {
if (parent instanceof PlayerWrapper) {
return (PlayerWrapper) parent;
public static AsyncPlayer wrap(Player parent) {
if (parent instanceof AsyncPlayer) {
return (AsyncPlayer) parent;
}
return new PlayerWrapper(parent);
return new AsyncPlayer(parent);
}
@Override
@ -162,23 +162,23 @@ public class PlayerWrapper extends PlayerProxy {
} catch (RuntimeException e) {
caught = e;
}
TaskManager.IMP.sync(new RunnableVal<Object>() {
@Override
public void run(Object value) {
setPosition(Vector3.at(x + 0.5, y, z + 0.5));
}
});
setPosition(Vector3.at(x + 0.5, y, z + 0.5));
if (caught != null) {
throw caught;
}
}
@Override
public void setPosition(Vector3 pos, float pitch, float yaw) {
Fawe.get().getQueueHandler().sync(() -> super.setPosition(pos, pitch, yaw));
}
@Override
public Location getBlockTrace(int range, boolean useLastBlock) {
return TaskManager.IMP.sync(new RunnableVal<Location>() {
@Override
public void run(Location value) {
TargetBlock tb = new TargetBlock(PlayerWrapper.this, range, 0.2D);
TargetBlock tb = new TargetBlock(AsyncPlayer.this, range, 0.2D);
this.value = useLastBlock ? tb.getAnyTargetBlock() : tb.getTargetBlock();
}
});
@ -189,7 +189,7 @@ public class PlayerWrapper extends PlayerProxy {
return TaskManager.IMP.sync(new RunnableVal<Location>() {
@Override
public void run(Location value) {
TargetBlock tb = new TargetBlock(PlayerWrapper.this, range, 0.2D);
TargetBlock tb = new TargetBlock(AsyncPlayer.this, range, 0.2D);
this.value = useLastBlock ? tb.getAnyTargetBlockFace() : tb.getTargetBlockFace();
}
});
@ -200,7 +200,7 @@ public class PlayerWrapper extends PlayerProxy {
return TaskManager.IMP.sync(new RunnableVal<Location>() {
@Override
public void run(Location value) {
TargetBlock tb = new TargetBlock(PlayerWrapper.this, range, 0.2D);
TargetBlock tb = new TargetBlock(AsyncPlayer.this, range, 0.2D);
this.value = tb.getSolidTargetBlock();
}
});
@ -215,7 +215,7 @@ public class PlayerWrapper extends PlayerProxy {
public boolean passThroughForwardWall(int range) {
return TaskManager.IMP.sync(() -> {
int searchDist = 0;
TargetBlock hitBlox = new TargetBlock(PlayerWrapper.this, range, 0.2);
TargetBlock hitBlox = new TargetBlock(AsyncPlayer.this, range, 0.2);
Extent world = getLocation().getExtent();
Location block;
boolean firstBlock = true;

View File

@ -1,10 +1,19 @@
package com.boydti.fawe.wrappers;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.object.RunnableVal;
import com.boydti.fawe.util.EditSessionBuilder;
import com.boydti.fawe.util.TaskManager;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.block.BlockTypes;
public class LocationMaskedPlayerWrapper extends PlayerWrapper {
public class LocationMaskedPlayerWrapper extends AsyncPlayer {
private final boolean allowTeleport;
private Location position;
@ -23,11 +32,101 @@ public class LocationMaskedPlayerWrapper extends PlayerWrapper {
return position;
}
private void update() {
this.position = super.getLocation();
}
@Override
public void setPosition(Vector3 pos, float pitch, float yaw) {
this.position = new Location(position.getExtent(), pos, pitch, yaw);
if (allowTeleport) {
super.setPosition(pos, pitch, yaw);
update();
}
}
@Override
public void findFreePosition(Location searchPos) {
if (allowTeleport) {
super.setPosition(searchPos);
update();
}
}
@Override
public void setOnGround(Location searchPos) {
if (allowTeleport) {
super.setPosition(searchPos);
update();
}
}
@Override
public void findFreePosition() {
if (allowTeleport) {
super.findFreePosition();
update();
}
}
@Override
public boolean ascendLevel() {
if (allowTeleport) {
super.ascendLevel();
update();
}
return true;
}
@Override
public boolean descendLevel() {
if (allowTeleport) {
super.descendLevel();
update();
}
return true;
}
@Override
public boolean ascendToCeiling(int clearance) {
if (allowTeleport) {
super.ascendToCeiling(clearance);
update();
}
return true;
}
@Override
public boolean ascendToCeiling(int clearance, boolean alwaysGlass) {
if (allowTeleport) {
super.ascendToCeiling(clearance, alwaysGlass);
update();
}
return true;
}
@Override
public boolean ascendUpwards(int distance) {
if (allowTeleport) {
super.ascendUpwards(distance);
update();
}
return true;
}
@Override
public boolean ascendUpwards(int distance, boolean alwaysGlass) {
if (allowTeleport) {
super.ascendUpwards(distance, alwaysGlass);
update();
}
return true;
}
@Override
public void floatAt(int x, int y, int z, boolean alwaysGlass) {
if (allowTeleport) {
super.floatAt(x, y, z, alwaysGlass);
update();
}
}
}

View File

@ -3,12 +3,10 @@ package com.boydti.fawe.wrappers;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.util.formatting.text.Component;
import java.awt.*;
/**
* Avoids printing any messages
*/
public class SilentPlayerWrapper extends PlayerWrapper {
public class SilentPlayerWrapper extends AsyncPlayer {
public SilentPlayerWrapper(Player parent) {
super(parent);
}

View File

@ -337,44 +337,6 @@ public final class PlatformCommandManager {
globalInjectedValues.injectValue(Key.of(InjectedValueAccess.class), Optional::of);
}
private Actor wrapActor(Actor actor, InjectedValueStore context) {
if (actor instanceof Player) {
final Set<String> failedPermissions = new LinkedHashSet<>();
Player player = (Player) actor;
Player unwrapped = PlayerProxy.unwrap(player);
actor = new LocationMaskedPlayerWrapper(unwrapped, unwrapped.getLocation(), true) {
@Override
public boolean hasPermission(String permission) {
if (!super.hasPermission(permission)) {
failedPermissions.add(permission);
return false;
}
return true;
}
@Override
public void checkPermission(String permission) throws AuthorizationException {
try {
super.checkPermission(permission);
} catch (AuthorizationException e) {
failedPermissions.add(permission);
throw e;
}
}
};
context.injectValue(Key.of(CommandPermissions.class), i -> Optional.of(new CommandPermissions() {
@Override
public Class<? extends Annotation> annotationType() {
return CommandPermissions.class;
}
@Override
public String[] value() {
return failedPermissions.toArray(new String[0]);
}
}));
}
return actor;
}
private <CI> void registerSubCommands(String name, List<String> aliases, String desc,
CommandManager commandManager,
Consumer<BiConsumer<CommandRegistration, CI>> handlerInstance) {
@ -815,9 +777,8 @@ public final class PlatformCommandManager {
getCommandManager(), actor, "//help");
}
private MemoizingValueAccess initializeInjectedValues(Arguments arguments, Actor tmp, Event event) {
private MemoizingValueAccess initializeInjectedValues(Arguments arguments, Actor actor, Event event) {
InjectedValueStore store = MapBackedValueStore.create();
Actor actor = wrapActor(tmp, store);
store.injectValue(Key.of(Actor.class), ValueProvider.constant(actor));
if (actor instanceof Player) {
store.injectValue(Key.of(Player.class), ValueProvider.constant((Player) actor));

View File

@ -21,6 +21,8 @@ package com.sk89q.worldedit.extension.platform;
import static com.google.common.base.Preconditions.checkNotNull;
import com.boydti.fawe.wrappers.AsyncPlayer;
import com.boydti.fawe.wrappers.LocationMaskedPlayerWrapper;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import com.boydti.fawe.object.brush.visualization.VirtualWorld;
import com.boydti.fawe.object.exception.FaweException;
@ -267,13 +269,19 @@ public class PlatformManager {
if (cuiActor == null) {
cuiActor = player;
}
return (T) new PlayerProxy(player, permActor, cuiActor, getWorldForEditing(player.getWorld()));
if (player == permActor && player == cuiActor) {
return (T) proxyFawe(player);
}
return (T) proxyFawe(new PlayerProxy(player, permActor, cuiActor, getWorldForEditing(player.getWorld())));
} else {
return base;
}
}
private <T extends Player> T proxyFawe(T player) {
return (T) new LocationMaskedPlayerWrapper(player, player.getLocation(), true);
}
/**
* Get the command manager.
*

View File

@ -21,7 +21,6 @@ package com.sk89q.worldedit.extension.platform;
import static com.google.common.base.Preconditions.checkNotNull;
import com.boydti.fawe.wrappers.PlayerWrapper;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.entity.BaseEntity;
@ -34,7 +33,6 @@ import com.sk89q.worldedit.session.SessionKey;
import com.sk89q.worldedit.util.HandSide;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockStateHolder;
@ -44,7 +42,6 @@ import com.sk89q.worldedit.world.gamemode.GameMode;
import javax.annotation.Nullable;
import java.util.UUID;
import java.util.function.Supplier;
public class PlayerProxy extends AbstractPlayerActor {