Work on CLI and I forget what else

This commit is contained in:
MattBDev
2019-07-29 10:57:28 -04:00
parent 8aaed49fa6
commit ca54f8c371
92 changed files with 1111 additions and 1107 deletions

View File

@ -198,7 +198,7 @@ public class DefaultMaskParser extends FaweParser<Mask> {
String suggestion = suggestions.get(i);
if (suggestion.indexOf(' ') != 0) {
String[] split = suggestion.split(" ");
suggestion = BBC.color("[" + StringMan.join(split, "][") + "]");
suggestion = "[" + StringMan.join(split, "][") + "]";
suggestions.set(i, suggestion);
}
}

View File

@ -161,7 +161,7 @@ public class DefaultPatternParser extends FaweParser<Pattern> {
String suggestion = suggestions.get(i);
if (suggestion.indexOf(' ') != 0) {
String[] split = suggestion.split(" ");
suggestion = BBC.color("[" + StringMan.join(split, "][") + "]");
suggestion = "[" + StringMan.join(split, "][") + "]";
suggestions.set(i, suggestion);
}
}

View File

@ -0,0 +1,51 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.extension.platform;
import com.sk89q.worldedit.internal.cui.CUIEvent;
import java.io.File;
public abstract class AbstractNonPlayerActor implements Actor {
@Override
public boolean canDestroyBedrock() {
return true;
}
@Override
public boolean isPlayer() {
return false;
}
@Override
public File openFileOpenDialog(String[] extensions) {
return null;
}
@Override
public File openFileSaveDialog(String[] extensions) {
return null;
}
@Override
public void dispatchCUIEvent(CUIEvent event) {
}
}

View File

@ -19,7 +19,10 @@
package com.sk89q.worldedit.extension.platform;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.NotABlockException;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extent.Extent;
@ -33,6 +36,7 @@ import com.sk89q.worldedit.util.HandSide;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.util.TargetBlock;
import com.sk89q.worldedit.util.auth.AuthorizationException;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
@ -44,13 +48,13 @@ import com.sk89q.worldedit.world.gamemode.GameModes;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.item.ItemTypes;
import com.sk89q.worldedit.world.registry.BlockMaterial;
import java.io.File;
import javax.annotation.Nullable;
/**
* An abstract implementation of both a {@link Actor} and a {@link Player} that is intended for
* implementations of WorldEdit to use to wrap players that make use of WorldEdit.
* An abstract implementation of both a {@link Actor} and a {@link Player}
* that is intended for implementations of WorldEdit to use to wrap
* players that make use of WorldEdit.
*/
public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
@ -151,12 +155,12 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
@Override
public void findFreePosition() {
findFreePosition(getBlockIn());
findFreePosition(getBlockLocation());
}
@Override
public boolean ascendLevel() {
final Location pos = getBlockIn();
final Location pos = getBlockLocation();
final int x = pos.getBlockX();
int y = Math.max(0, pos.getBlockY());
final int z = pos.getBlockZ();
@ -214,7 +218,7 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
@Override
public boolean descendLevel() {
final Location pos = getBlockIn();
final Location pos = getBlockLocation();
final int x = pos.getBlockX();
int y = Math.max(0, pos.getBlockY());
final int z = pos.getBlockZ();
@ -277,7 +281,7 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
@Override
public boolean ascendToCeiling(int clearance, boolean alwaysGlass) {
Location pos = getBlockIn();
Location pos = getBlockLocation();
int x = pos.getBlockX();
int initialY = Math.max(0, pos.getBlockY());
int y = Math.max(0, pos.getBlockY() + 2);
@ -294,6 +298,13 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
if (world.getBlock(BlockVector3.at(x, y, z)).getBlockType().getMaterial()
.isMovementBlocker()) {
int platformY = Math.max(initialY, y - 3 - clearance);
if (platformY < initialY) { // if ==, they already have the given clearance, if <, clearance is too large
printError("Not enough space above you!");
return false;
} else if (platformY == initialY) {
printError("You're already at the ceiling.");
return false;
}
floatAt(x, platformY + 1, z, alwaysGlass);
return true;
}
@ -311,7 +322,7 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
@Override
public boolean ascendUpwards(int distance, boolean alwaysGlass) {
final Location pos = getBlockIn();
final Location pos = getBlockLocation();
final int x = pos.getBlockX();
final int initialY = Math.max(0, pos.getBlockY());
int y = Math.max(0, pos.getBlockY() + 1);
@ -338,27 +349,41 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
@Override
public void floatAt(int x, int y, int z, boolean alwaysGlass) {
try {
if (alwaysGlass || !isAllowedToFly()) {
BlockVector3 spot = BlockVector3.at(x, y - 1, z);
if (!getLocation().getExtent().getBlock(spot).getBlockType().getMaterial()
.isMovementBlocker()) {
getLocation().getExtent().setBlock(spot, BlockTypes.GLASS.getDefaultState());
final World world = getWorld();
if (!world.getBlock(spot).getBlockType().getMaterial().isMovementBlocker()) {
try (EditSession session = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, 1, this)) {
session.setBlock(spot, BlockTypes.GLASS.getDefaultState());
} catch (MaxChangedBlocksException ignored) {
}
} catch (WorldEditException e) {
e.printStackTrace();
}
} else {
setFlying(true);
}
setPosition(Vector3.at(x + 0.5, y, z + 0.5));
}
@Override
public Location getBlockIn() {
return getLocation().setPosition(getLocation().toVector().floor());
/**
* Check whether the player is allowed to fly.
*
* @return true if allowed flight
*/
protected boolean isAllowedToFly() {
return false;
}
/**
* Set whether the player is currently flying.
*
* @param flying true to fly
*/
protected void setFlying(boolean flying) {
}
@Override
public Location getBlockOn() {
return getLocation()
.setPosition(getLocation().setY(getLocation().getY() - 1).toVector().floor());
return getLocation().setPosition(getLocation().setY(getLocation().getY() - 1).toVector().floor());
}
@Override
@ -407,15 +432,16 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
@Override
public Direction getCardinalDirection(int yawOffset) {
if (getLocation().getPitch() > 67.5) {
final Location location = getLocation();
if (location.getPitch() > 67.5) {
return Direction.DOWN;
}
if (getLocation().getPitch() < -67.5) {
if (location.getPitch() < -67.5) {
return Direction.UP;
}
// From hey0's code
double rot = (getLocation().getYaw() + yawOffset) % 360; //let's use real yaw now
double rot = (location.getYaw() + yawOffset) % 360; //let's use real yaw now
if (rot < 0) {
rot += 360.0;
}
@ -432,56 +458,66 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
}
}
private boolean canPassThroughBlock(Location curBlock) {
BlockVector3 blockPos = curBlock.toVector().toBlockPoint();
BlockState block = curBlock.getExtent().getBlock(blockPos);
return !block.getBlockType().getMaterial().isMovementBlocker();
}
/**
* Get the player's view yaw.
*
* @return yaw
* Advances the block target block until the current block is a wall
* @return true if a wall is found
*/
@Override
public boolean passThroughForwardWall(int range) {
int searchDist = 0;
TargetBlock hitBlox = new TargetBlock(this, range, 0.2);
Extent world = getLocation().getExtent();
Location block;
boolean firstBlock = true;
int freeToFind = 2;
boolean inFree = false;
while ((block = hitBlox.getNextBlock()) != null) {
boolean free = !world.getBlock(block.toVector().toBlockPoint()).getBlockType()
.getMaterial().isMovementBlocker();
if (firstBlock) {
firstBlock = false;
if (!free) {
--freeToFind;
continue;
}
}
++searchDist;
if (searchDist > 20) {
return false;
}
if (inFree != free) {
if (free) {
--freeToFind;
}
}
if (freeToFind == 0) {
setOnGround(block);
private boolean advanceToWall(TargetBlock hitBlox) {
Location curBlock;
while ((curBlock = hitBlox.getCurrentBlock()) != null) {
if (!canPassThroughBlock(curBlock)) {
return true;
}
inFree = free;
hitBlox.getNextBlock();
}
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;
}
if (!advanceToFree(hitBlox)) {
return false;
}
Location foundBlock = hitBlox.getCurrentBlock();
if (foundBlock != null) {
setOnGround(foundBlock);
return true;
}
return false;
}
@Override
public void setPosition(Vector3 pos) {

View File

@ -0,0 +1,69 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.extension.platform;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.util.Location;
public interface Locatable {
/**
* Get the location of this actor.
*
* @return the location of the actor
*/
Location getLocation();
/**
* Get the location of this actor in block coordinates.
*
* @return the block location of the actor
*/
default Location getBlockLocation() {
Location location = getLocation();
return location.setPosition(location.toVector().floor());
}
/**
* Sets the location of this actor.
*
* @param location the new location of the actor
* @return if the teleport succeeded
*/
boolean setLocation(Location location);
/**
* Sets the position of this actor.
*
* @param pos where to move them
*/
default void setPosition(Vector3 pos) {
setLocation(new Location(getExtent(), pos));
}
/**
* Get the extent that this actor is in.
*
* @return the extent
*/
Extent getExtent();
}

View File

@ -411,11 +411,6 @@ public final class PlatformCommandManager {
GenerationCommandsRegistration.builder(),
new GenerationCommands(worldEdit)
);
this.registration.register(
new CFICommand(commandManager),
CFICommandsRegistration.builder(),
new CFICommands(worldEdit)
);
this.registration.register(
commandManager,
HistoryCommandsRegistration.builder(),