Skip to content
Permalink
Browse files

Fixed commands, and set the loaded schematic as the world override in…

… CLI
  • Loading branch information...
me4502 committed Jul 15, 2019
1 parent 527dd7e commit 39699c8db3c3b734571899ec656d9d919aa8bfad
@@ -302,6 +302,7 @@ public static void main(String[] args) {
file.getName()
);
worldEdit.platform.addWorld(world);
WorldEdit.getInstance().getSessionManager().get(worldEdit.commandSender).setWorldOverride(world);
} else {
throw new IllegalArgumentException("Unknown file provided!");
}
@@ -900,34 +900,6 @@ public Calendar detectDate(String input) {
}
}

/**
* Construct a new edit session.
*
* @param player the player
* @return an edit session
*/
public EditSession createEditSession(Player player) {
checkNotNull(player);

BlockBag blockBag = getBlockBag(player);

// Create an edit session
EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(
hasWorldOverride() ? getWorldOverride() : player.isPlayer() ? player.getWorld() : null,
getBlockChangeLimit(), blockBag, player
);
Request.request().setEditSession(editSession);

editSession.setFastMode(fastMode);
editSession.setReorderMode(reorderMode);
editSession.setMask(mask);
if (editSession.getSurvivalExtent() != null) {
editSession.getSurvivalExtent().setStripNbt(!player.hasPermission("worldedit.setnbt"));
}

return editSession;
}

/**
* Construct a new edit session.
*
@@ -936,11 +908,26 @@ public EditSession createEditSession(Player player) {
*/
public EditSession createEditSession(Actor actor) {
checkNotNull(actor);
checkNotNull(getWorldOverride());

World world = null;
if (hasWorldOverride()) {
world = getWorldOverride();
} else if (actor.isPlayer() && actor instanceof Player) {
world = ((Player) actor).getWorld();
}

// Create an edit session
EditSession editSession = WorldEdit.getInstance().getEditSessionFactory()
.getEditSession(getWorldOverride(), getBlockChangeLimit());
EditSession editSession;
if (actor.isPlayer() && actor instanceof Player) {
BlockBag blockBag = getBlockBag((Player) actor);
editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(
world,
getBlockChangeLimit(), blockBag, actor
);
} else {
editSession = WorldEdit.getInstance().getEditSessionFactory()
.getEditSession(world, getBlockChangeLimit());
}
Request.request().setEditSession(editSession);

editSession.setFastMode(fastMode);
@@ -0,0 +1,27 @@
/*
* 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;

/**
* Raised when a world is missing but is required.
*/
public class MissingWorldException extends WorldEditException {

}
@@ -33,6 +33,7 @@
import com.sk89q.worldedit.command.util.Logging;
import com.sk89q.worldedit.command.util.WorldEditAsyncCommandBuilder;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.platform.permission.ActorSelectorLimits;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.function.block.BlockDistributionCounter;
@@ -104,23 +105,26 @@ public SelectionCommands(WorldEdit we) {
)
@Logging(POSITION)
@CommandPermissions("worldedit.selection.pos")
public void pos1(Player player, LocalSession session,
public void pos1(Actor actor, World world, LocalSession session,
@Arg(desc = "Coordinates to set position 1 to", def = "")
BlockVector3 coordinates) throws WorldEditException {
Location pos;
if (coordinates != null) {
pos = new Location(player.getWorld(), coordinates.toVector3());
pos = new Location(world, coordinates.toVector3());
} else if (actor.isPlayer() && actor instanceof Player) {
pos = ((Player) actor).getBlockIn();
} else {
pos = player.getBlockIn();
actor.printError("You must provide coordinates as console.");
return;
}

if (!session.getRegionSelector(player.getWorld()).selectPrimary(pos.toVector().toBlockPoint(), ActorSelectorLimits.forActor(player))) {
player.printError("Position already set.");
if (!session.getRegionSelector(world).selectPrimary(pos.toVector().toBlockPoint(), ActorSelectorLimits.forActor(actor))) {
actor.printError("Position already set.");
return;
}

session.getRegionSelector(player.getWorld())
.explainPrimarySelection(player, session, pos.toVector().toBlockPoint());
session.getRegionSelector(world)
.explainPrimarySelection(actor, session, pos.toVector().toBlockPoint());
}

@Command(
@@ -129,23 +133,26 @@ public void pos1(Player player, LocalSession session,
)
@Logging(POSITION)
@CommandPermissions("worldedit.selection.pos")
public void pos2(Player player, LocalSession session,
public void pos2(Actor actor, World world, LocalSession session,
@Arg(desc = "Coordinates to set position 2 to", def = "")
BlockVector3 coordinates) throws WorldEditException {
Location pos;
if (coordinates != null) {
pos = new Location(player.getWorld(), coordinates.toVector3());
pos = new Location(world, coordinates.toVector3());
} else if (actor.isPlayer() && actor instanceof Player) {
pos = ((Player) actor).getBlockIn();
} else {
pos = player.getBlockIn();
actor.printError("You must provide coordinates as console.");
return;
}

if (!session.getRegionSelector(player.getWorld()).selectSecondary(pos.toVector().toBlockPoint(), ActorSelectorLimits.forActor(player))) {
player.printError("Position already set.");
if (!session.getRegionSelector(world).selectSecondary(pos.toVector().toBlockPoint(), ActorSelectorLimits.forActor(actor))) {
actor.printError("Position already set.");
return;
}

session.getRegionSelector(player.getWorld())
.explainSecondarySelection(player, session, pos.toVector().toBlockPoint());
session.getRegionSelector(world)
.explainSecondarySelection(actor, session, pos.toVector().toBlockPoint());
}

@Command(
@@ -28,6 +28,7 @@
import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.MissingWorldException;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.command.ApplyBrushCommands;
import com.sk89q.worldedit.command.BiomeCommands;
@@ -225,63 +226,54 @@ private void registerAlwaysInjectedValues() {
context -> {
LocalSession localSession = context.injectedValue(Key.of(LocalSession.class))
.orElseThrow(() -> new IllegalStateException("No LocalSession"));
Optional<Player> playerValue = context.injectedValue(Key.of(Player.class));
if (playerValue.isPresent()) {
return playerValue.map(player -> {
try {
return localSession.getSelection(player.getWorld());
} catch (IncompleteRegionException e) {
exceptionConverter.convert(e);
throw new AssertionError("Should have thrown a new exception.");
}
});
} else {
return context.injectedValue(Key.of(Actor.class))
.map(actor -> {
try {
if (!localSession.hasWorldOverride()) {
throw new IncompleteRegionException();
}
return localSession.getSelection(localSession.getWorldOverride());
} catch (IncompleteRegionException e) {
exceptionConverter.convert(e);
throw new AssertionError("Should have thrown a new exception.");
return context.injectedValue(Key.of(Actor.class))
.map(actor -> {
try {
World world;
if (localSession.hasWorldOverride()) {
world = localSession.getWorldOverride();
} else if (actor.isPlayer() && actor instanceof Player) {
world = ((Player) actor).getWorld();
} else {
throw new MissingWorldException();
}
});
}
return localSession.getSelection(world);
} catch (MissingWorldException | IncompleteRegionException e) {
exceptionConverter.convert(e);
throw new AssertionError("Should have thrown a new exception.");
}
});
});
globalInjectedValues.injectValue(Key.of(EditSession.class),
context -> {
LocalSession localSession = context.injectedValue(Key.of(LocalSession.class))
.orElseThrow(() -> new IllegalStateException("No LocalSession"));
Optional<Player> playerValue = context.injectedValue(Key.of(Player.class));
if (playerValue.isPresent()) {
return playerValue.map(player -> {
EditSession editSession = localSession.createEditSession(player);
editSession.enableStandardMode();
return editSession;
});
} else {
return context.injectedValue(Key.of(Actor.class))
.map(actor -> {
EditSession editSession = localSession.createEditSession(actor);
editSession.enableStandardMode();
return editSession;
});
}
return context.injectedValue(Key.of(Actor.class))
.map(player -> {
EditSession editSession = localSession.createEditSession(player);
editSession.enableStandardMode();
return editSession;
});
});
globalInjectedValues.injectValue(Key.of(World.class),
context -> {
LocalSession localSession = context.injectedValue(Key.of(LocalSession.class))
.orElseThrow(() -> new IllegalStateException("No LocalSession"));
Optional<Player> playerValue = context.injectedValue(Key.of(Player.class));
if (playerValue.isPresent()) {
return playerValue
.map(player -> localSession.hasWorldOverride() ? localSession.getWorldOverride() : player.getWorld());
} else {
return context.injectedValue(Key.of(Actor.class))
.map(actor -> localSession.getWorldOverride());
}
return context.injectedValue(Key.of(Actor.class))
.map(actor -> {
try {
if (localSession.hasWorldOverride()) {
return localSession.getWorldOverride();
} else if (actor.isPlayer() && actor instanceof Player) {
return ((Player) actor).getWorld();
} else {
throw new MissingWorldException();
}
} catch (MissingWorldException e) {
exceptionConverter.convert(e);
throw new AssertionError("Should have thrown a new exception.");
}
});
});
}

@@ -27,6 +27,7 @@
import com.sk89q.worldedit.MaxBrushRadiusException;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.MaxRadiusException;
import com.sk89q.worldedit.MissingWorldException;
import com.sk89q.worldedit.UnknownDirectionException;
import com.sk89q.worldedit.UnknownItemException;
import com.sk89q.worldedit.WorldEdit;
@@ -81,6 +82,11 @@ public void convert(IncompleteRegionException e) throws CommandException {
throw newCommandException("Make a region selection first.", e);
}

@ExceptionMatch
public void convert(MissingWorldException e) throws CommandException {
throw newCommandException("You need to provide a world (Try //world)", e);
}

@ExceptionMatch
public void convert(UnknownItemException e) throws CommandException {
throw newCommandException("Block name '" + e.getID() + "' was not recognized.", e);

0 comments on commit 39699c8

Please sign in to comment.
You can’t perform that action at this time.