2014-04-03 02:08:50 +00:00
|
|
|
/*
|
2014-04-04 22:03:18 +00:00
|
|
|
* WorldEdit, a Minecraft world manipulation toolkit
|
|
|
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
|
|
|
* Copyright (C) WorldEdit team and contributors
|
2014-04-03 02:08:50 +00:00
|
|
|
*
|
2014-04-04 22:03:18 +00:00
|
|
|
* 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
|
2014-04-03 02:08:50 +00:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
2014-04-04 22:03:18 +00:00
|
|
|
* 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.
|
2014-04-03 02:08:50 +00:00
|
|
|
*
|
2014-04-04 22:03:18 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
2014-04-03 02:08:50 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2014-04-04 22:03:18 +00:00
|
|
|
*/
|
2014-04-03 02:08:50 +00:00
|
|
|
|
|
|
|
package com.sk89q.worldedit.command;
|
2019-07-06 00:46:48 +00:00
|
|
|
import static com.sk89q.worldedit.command.util.Logging.LogMode.POSITION;
|
2019-04-02 22:21:02 +00:00
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
import com.boydti.fawe.config.BBC;
|
2014-07-03 10:33:16 +00:00
|
|
|
import com.sk89q.worldedit.LocalConfiguration;
|
|
|
|
import com.sk89q.worldedit.WorldEdit;
|
|
|
|
import com.sk89q.worldedit.WorldEditException;
|
2019-07-06 00:46:48 +00:00
|
|
|
import com.sk89q.worldedit.command.util.CommandPermissions;
|
|
|
|
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
|
|
|
|
import com.sk89q.worldedit.command.util.Logging;
|
2014-06-28 08:01:49 +00:00
|
|
|
import com.sk89q.worldedit.entity.Player;
|
2018-06-16 05:29:48 +00:00
|
|
|
import com.sk89q.worldedit.util.Location;
|
2019-10-13 11:47:26 +00:00
|
|
|
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
|
|
|
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
|
2019-07-06 00:46:48 +00:00
|
|
|
import org.enginehub.piston.annotation.Command;
|
|
|
|
import org.enginehub.piston.annotation.CommandContainer;
|
|
|
|
import org.enginehub.piston.annotation.param.Arg;
|
|
|
|
import org.enginehub.piston.annotation.param.Switch;
|
2018-08-12 14:03:07 +00:00
|
|
|
|
2019-04-23 23:14:21 +00:00
|
|
|
import static com.google.common.base.Preconditions.checkNotNull;
|
2014-06-28 08:01:49 +00:00
|
|
|
|
2014-04-03 02:08:50 +00:00
|
|
|
/**
|
2014-06-28 08:01:49 +00:00
|
|
|
* Commands for moving the player around.
|
2014-04-03 02:08:50 +00:00
|
|
|
*/
|
2019-07-06 00:46:48 +00:00
|
|
|
@CommandContainer(superTypes = CommandPermissionsConditionGenerator.Registration.class)
|
2014-04-03 02:08:50 +00:00
|
|
|
public class NavigationCommands {
|
2014-06-28 08:01:49 +00:00
|
|
|
|
|
|
|
private final WorldEdit worldEdit;
|
2014-04-03 02:08:50 +00:00
|
|
|
|
2014-06-28 08:01:49 +00:00
|
|
|
/**
|
|
|
|
* Create a new instance.
|
|
|
|
*
|
|
|
|
* @param worldEdit reference to WorldEdit
|
|
|
|
*/
|
|
|
|
public NavigationCommands(WorldEdit worldEdit) {
|
|
|
|
checkNotNull(worldEdit);
|
|
|
|
this.worldEdit = worldEdit;
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-07-06 00:46:48 +00:00
|
|
|
name = "unstuck",
|
|
|
|
aliases = { "!" },
|
|
|
|
desc = "Escape from being stuck inside a block"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.navigation.unstuck")
|
2014-06-28 08:01:49 +00:00
|
|
|
public void unstuck(Player player) throws WorldEditException {
|
2019-06-11 20:07:43 +00:00
|
|
|
player.findFreePosition();
|
2019-10-13 11:47:26 +00:00
|
|
|
player.printInfo(TranslatableComponent.of("worldedit.unstuck.moved"));
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-07-06 00:46:48 +00:00
|
|
|
name = "ascend",
|
|
|
|
aliases = { "asc" },
|
|
|
|
desc = "Go up a floor"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.navigation.ascend")
|
2019-07-06 00:46:48 +00:00
|
|
|
public void ascend(Player player,
|
|
|
|
@Arg(desc = "# of levels to ascend", def = "1")
|
|
|
|
int levels) throws WorldEditException {
|
2018-07-09 09:38:22 +00:00
|
|
|
int ascentLevels = 0;
|
|
|
|
while (player.ascendLevel()) {
|
2014-04-03 02:08:50 +00:00
|
|
|
++ascentLevels;
|
2019-07-06 00:46:48 +00:00
|
|
|
if (levels == ascentLevels) {
|
2018-07-09 09:38:22 +00:00
|
|
|
break;
|
|
|
|
}
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
if (ascentLevels == 0) {
|
2019-10-13 11:47:26 +00:00
|
|
|
player.printError(TranslatableComponent.of("worldedit.ascend.obstructed"));
|
2014-04-03 02:08:50 +00:00
|
|
|
} else {
|
2019-10-27 05:29:40 +00:00
|
|
|
player.printInfo(TranslatableComponent.of("worldedit.ascend.moved", TextComponent.of(ascentLevels)));
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-07-06 00:46:48 +00:00
|
|
|
name = "descend",
|
|
|
|
aliases = { "desc" },
|
|
|
|
desc = "Go down a floor"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.navigation.descend")
|
2019-07-06 00:46:48 +00:00
|
|
|
public void descend(Player player,
|
|
|
|
@Arg(desc = "# of levels to descend", def = "1")
|
|
|
|
int levels) throws WorldEditException {
|
2018-07-09 09:38:22 +00:00
|
|
|
int descentLevels = 0;
|
|
|
|
while (player.descendLevel()) {
|
2014-04-03 02:08:50 +00:00
|
|
|
++descentLevels;
|
2019-07-06 00:46:48 +00:00
|
|
|
if (levels == descentLevels) {
|
2018-07-09 09:38:22 +00:00
|
|
|
break;
|
|
|
|
}
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
if (descentLevels == 0) {
|
2019-10-13 11:47:26 +00:00
|
|
|
player.printError(TranslatableComponent.of("worldedit.descend.obstructed"));
|
2014-04-03 02:08:50 +00:00
|
|
|
} else {
|
2019-10-27 05:29:40 +00:00
|
|
|
player.printInfo(TranslatableComponent.of("worldedit.descend.moved", TextComponent.of(descentLevels)));
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-07-06 00:46:48 +00:00
|
|
|
name = "ceil",
|
|
|
|
desc = "Go to the ceiling"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.navigation.ceiling")
|
|
|
|
@Logging(POSITION)
|
2019-07-06 00:46:48 +00:00
|
|
|
public void ceiling(Player player,
|
|
|
|
@Arg(desc = "# of blocks to leave above you", def = "0")
|
|
|
|
int clearance,
|
|
|
|
@Switch(name = 'f', desc = "Force using flight to keep you still")
|
|
|
|
boolean forceFlight,
|
|
|
|
@Switch(name = 'g', desc = "Force using glass to keep you still")
|
|
|
|
boolean forceGlass) throws WorldEditException {
|
|
|
|
clearance = Math.max(0, clearance);
|
|
|
|
|
|
|
|
boolean alwaysGlass = getAlwaysGlass(forceFlight, forceGlass);
|
2014-04-03 02:08:50 +00:00
|
|
|
if (player.ascendToCeiling(clearance, alwaysGlass)) {
|
2019-10-13 11:47:26 +00:00
|
|
|
player.printInfo(TranslatableComponent.of("worldedit.ceil.moved"));
|
2014-04-03 02:08:50 +00:00
|
|
|
} else {
|
2019-10-13 11:47:26 +00:00
|
|
|
player.printError(TranslatableComponent.of("worldedit.ceil.obstructed"));
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-07-06 00:46:48 +00:00
|
|
|
name = "thru",
|
|
|
|
desc = "Pass through walls"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.navigation.thru.command")
|
2019-03-16 23:04:24 +00:00
|
|
|
public void thru(Player player) throws WorldEditException {
|
2014-04-03 02:08:50 +00:00
|
|
|
if (player.passThroughForwardWall(6)) {
|
2019-10-13 11:47:26 +00:00
|
|
|
player.printInfo(TranslatableComponent.of("worldedit.thru.moved"));
|
2014-04-03 02:08:50 +00:00
|
|
|
} else {
|
2019-10-13 11:47:26 +00:00
|
|
|
player.printError(TranslatableComponent.of("worldedit.thru.obstructed"));
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-07-06 00:46:48 +00:00
|
|
|
name = "jumpto",
|
|
|
|
aliases = { "j" },
|
|
|
|
desc = "Teleport to a location"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.navigation.jumpto.command")
|
2019-07-25 18:44:10 +00:00
|
|
|
public void jumpTo(Player player,
|
|
|
|
@Arg(desc = "Location to jump to", def = "")
|
|
|
|
Location pos,
|
2019-07-26 23:23:24 +00:00
|
|
|
@Switch(name = 'f', desc = "force teleport")
|
2019-07-25 18:44:10 +00:00
|
|
|
boolean force) throws WorldEditException {
|
|
|
|
|
2019-07-17 16:31:13 +00:00
|
|
|
if (pos == null) {
|
|
|
|
pos = player.getSolidBlockTrace(300);
|
|
|
|
}
|
2014-04-03 02:08:50 +00:00
|
|
|
if (pos != null) {
|
|
|
|
player.findFreePosition(pos);
|
2019-10-13 11:47:26 +00:00
|
|
|
player.printInfo(TranslatableComponent.of("worldedit.jumpto.moved"));
|
2014-04-03 02:08:50 +00:00
|
|
|
} else {
|
2019-10-13 11:47:26 +00:00
|
|
|
player.printError(TranslatableComponent.of("worldedit.jumpto.none"));
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-07-06 00:46:48 +00:00
|
|
|
name = "up",
|
|
|
|
desc = "Go upwards some distance"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.navigation.up")
|
|
|
|
@Logging(POSITION)
|
2019-07-06 00:46:48 +00:00
|
|
|
public void up(Player player,
|
|
|
|
@Arg(desc = "Distance to go upwards")
|
|
|
|
int distance,
|
|
|
|
@Switch(name = 'f', desc = "Force using flight to keep you still")
|
|
|
|
boolean forceFlight,
|
|
|
|
@Switch(name = 'g', desc = "Force using glass to keep you still")
|
|
|
|
boolean forceGlass) throws WorldEditException {
|
|
|
|
boolean alwaysGlass = getAlwaysGlass(forceFlight, forceGlass);
|
2014-04-03 02:08:50 +00:00
|
|
|
if (player.ascendUpwards(distance, alwaysGlass)) {
|
2019-10-13 11:47:26 +00:00
|
|
|
player.printInfo(TranslatableComponent.of("worldedit.up.moved"));
|
2014-04-03 02:08:50 +00:00
|
|
|
} else {
|
2019-10-13 11:47:26 +00:00
|
|
|
player.printError(TranslatableComponent.of("worldedit.up.obstructed"));
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper function for /up and /ceil.
|
2018-08-12 14:03:07 +00:00
|
|
|
*
|
2019-07-06 00:46:48 +00:00
|
|
|
* @param forceFlight if flight should be used, rather than the default config option
|
|
|
|
* @param forceGlass if glass should always be placed, rather than the default config option
|
2014-04-03 02:08:50 +00:00
|
|
|
* @return true, if glass should always be put under the player
|
|
|
|
*/
|
2019-07-06 00:46:48 +00:00
|
|
|
private boolean getAlwaysGlass(boolean forceFlight, boolean forceGlass) {
|
2014-06-28 08:01:49 +00:00
|
|
|
final LocalConfiguration config = worldEdit.getConfiguration();
|
2014-04-03 02:08:50 +00:00
|
|
|
|
|
|
|
return forceGlass || (config.navigationUseGlass && !forceFlight);
|
|
|
|
}
|
2019-04-02 22:21:02 +00:00
|
|
|
}
|