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;
|
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
import com.boydti.fawe.FaweAPI;
|
|
|
|
import com.boydti.fawe.config.BBC;
|
|
|
|
import com.boydti.fawe.util.MathMan;
|
2014-04-03 02:08:50 +00:00
|
|
|
import com.sk89q.minecraft.util.commands.Command;
|
|
|
|
import com.sk89q.minecraft.util.commands.CommandContext;
|
|
|
|
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
|
|
|
import com.sk89q.minecraft.util.commands.Logging;
|
2014-07-03 10:33:16 +00:00
|
|
|
import com.sk89q.worldedit.LocalConfiguration;
|
|
|
|
import com.sk89q.worldedit.LocalSession;
|
|
|
|
import com.sk89q.worldedit.WorldEdit;
|
|
|
|
import com.sk89q.worldedit.WorldEditException;
|
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;
|
2014-07-03 10:33:16 +00:00
|
|
|
import com.sk89q.worldedit.util.command.parametric.Optional;
|
2018-08-12 14:03:07 +00:00
|
|
|
import com.sk89q.worldedit.world.World;
|
|
|
|
|
|
|
|
|
|
|
|
import static com.google.common.base.Preconditions.checkNotNull;
|
|
|
|
import static com.sk89q.minecraft.util.commands.Logging.LogMode.POSITION;
|
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
|
|
|
*/
|
2018-08-12 14:03:07 +00:00
|
|
|
@Command(aliases = {}, desc = "Commands for moving the player around: [More Info](https://goo.gl/uQTUiT)")
|
2014-04-03 02:08:50 +00:00
|
|
|
public class NavigationCommands {
|
2014-06-28 08:01:49 +00:00
|
|
|
|
2014-04-03 02:08:50 +00:00
|
|
|
@SuppressWarnings("unused")
|
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(
|
2018-08-12 14:03:07 +00:00
|
|
|
aliases = {"unstuck", "!"},
|
|
|
|
usage = "",
|
|
|
|
desc = "Escape from being stuck inside a block",
|
|
|
|
min = 0,
|
|
|
|
max = 0
|
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 {
|
2014-04-03 02:08:50 +00:00
|
|
|
player.findFreePosition();
|
2018-08-12 14:03:07 +00:00
|
|
|
BBC.UNSTUCK.send(player);
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2018-08-12 14:03:07 +00:00
|
|
|
aliases = {"ascend", "asc"},
|
|
|
|
usage = "[# of levels]",
|
|
|
|
desc = "Go up a floor",
|
|
|
|
min = 0,
|
|
|
|
max = 1
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.navigation.ascend")
|
2014-07-03 10:33:16 +00:00
|
|
|
public void ascend(Player player, @Optional("1") int levelsToAscend) 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;
|
2018-07-09 09:38:22 +00:00
|
|
|
if (levelsToAscend == ascentLevels) {
|
|
|
|
break;
|
|
|
|
}
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
if (ascentLevels == 0) {
|
2018-08-12 14:03:07 +00:00
|
|
|
BBC.ASCEND_FAIL.send(player);
|
2014-04-03 02:08:50 +00:00
|
|
|
} else {
|
2018-08-12 14:03:07 +00:00
|
|
|
if (ascentLevels == 1) {
|
|
|
|
BBC.ASCENDED_SINGULAR.send(player);
|
|
|
|
} else {
|
|
|
|
BBC.ASCENDED_PLURAL.send(player, ascentLevels);
|
|
|
|
}
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2018-08-12 14:03:07 +00:00
|
|
|
aliases = {"descend", "desc"},
|
|
|
|
usage = "[# of floors]",
|
|
|
|
desc = "Go down a floor",
|
|
|
|
min = 0,
|
|
|
|
max = 1
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.navigation.descend")
|
2014-07-03 10:33:16 +00:00
|
|
|
public void descend(Player player, @Optional("1") int levelsToDescend) 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;
|
2018-07-09 09:38:22 +00:00
|
|
|
if (levelsToDescend == descentLevels) {
|
|
|
|
break;
|
|
|
|
}
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
if (descentLevels == 0) {
|
2018-08-12 14:03:07 +00:00
|
|
|
BBC.DESCEND_FAIL.send(player);
|
2014-04-03 02:08:50 +00:00
|
|
|
} else {
|
2018-08-12 14:03:07 +00:00
|
|
|
if (descentLevels == 1) {
|
|
|
|
BBC.DESCEND_SINGULAR.send(player);
|
|
|
|
} else {
|
|
|
|
BBC.DESCEND_PLURAL.send(player, descentLevels);
|
|
|
|
}
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2018-08-12 14:03:07 +00:00
|
|
|
aliases = {"ceil"},
|
|
|
|
usage = "[clearance]",
|
|
|
|
desc = "Go to the celing",
|
|
|
|
flags = "fg",
|
|
|
|
min = 0,
|
|
|
|
max = 1
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.navigation.ceiling")
|
|
|
|
@Logging(POSITION)
|
2018-08-12 14:03:07 +00:00
|
|
|
public void ceiling(Player player, LocalSession session, CommandContext args) throws WorldEditException {
|
2014-04-03 02:08:50 +00:00
|
|
|
|
|
|
|
final int clearance = args.argsLength() > 0 ?
|
2018-08-12 14:03:07 +00:00
|
|
|
Math.max(0, args.getInteger(0)) : 0;
|
2014-04-03 02:08:50 +00:00
|
|
|
|
|
|
|
final boolean alwaysGlass = getAlwaysGlass(args);
|
|
|
|
if (player.ascendToCeiling(clearance, alwaysGlass)) {
|
2018-08-12 14:03:07 +00:00
|
|
|
BBC.WHOOSH.send(player);
|
2014-04-03 02:08:50 +00:00
|
|
|
} else {
|
2018-08-12 14:03:07 +00:00
|
|
|
BBC.ASCEND_FAIL.send(player);
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2018-08-12 14:03:07 +00:00
|
|
|
aliases = {"thru"},
|
|
|
|
usage = "",
|
|
|
|
desc = "Passthrough walls",
|
|
|
|
min = 0,
|
|
|
|
max = 0
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.navigation.thru.command")
|
2018-08-12 14:03:07 +00:00
|
|
|
public void thru(Player player, LocalSession session, CommandContext args) throws WorldEditException {
|
2014-04-03 02:08:50 +00:00
|
|
|
if (player.passThroughForwardWall(6)) {
|
2018-08-12 14:03:07 +00:00
|
|
|
BBC.WHOOSH.send(player);
|
2014-04-03 02:08:50 +00:00
|
|
|
} else {
|
2018-08-12 14:03:07 +00:00
|
|
|
BBC.THRU_FAIL.send(player);
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2018-08-12 14:03:07 +00:00
|
|
|
aliases = {"jumpto", "j"},
|
|
|
|
usage = "[world,x,y,z]",
|
|
|
|
desc = "Teleport to a location",
|
|
|
|
min = 0,
|
|
|
|
max = 1
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.navigation.jumpto.command")
|
2018-08-12 14:03:07 +00:00
|
|
|
public void jumpTo(Player player, LocalSession session, CommandContext args) throws WorldEditException {
|
|
|
|
Location pos;
|
|
|
|
if (args.argsLength() == 1) {
|
|
|
|
String arg = args.getString(0);
|
|
|
|
String[] split = arg.split(",");
|
|
|
|
World world = FaweAPI.getWorld(split[0]);
|
|
|
|
if (world != null && split.length == 4 && MathMan.isInteger(split[1]) && MathMan.isInteger(split[2]) && MathMan.isInteger(split[3])) {
|
|
|
|
pos = new Location(world, Integer.parseInt(split[1]), Integer.parseInt(split[2]), Integer.parseInt(split[3]));
|
|
|
|
} else {
|
|
|
|
BBC.SELECTOR_INVALID_COORDINATES.send(player, args.getString(0));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
pos = player.getSolidBlockTrace(300);
|
|
|
|
}
|
2014-04-03 02:08:50 +00:00
|
|
|
if (pos != null) {
|
|
|
|
player.findFreePosition(pos);
|
2018-08-12 14:03:07 +00:00
|
|
|
BBC.POOF.send(player);
|
2014-04-03 02:08:50 +00:00
|
|
|
} else {
|
2018-08-12 14:03:07 +00:00
|
|
|
BBC.NO_BLOCK.send(player);
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2018-08-12 14:03:07 +00:00
|
|
|
aliases = {"up"},
|
|
|
|
usage = "<number>",
|
|
|
|
desc = "Go upwards some distance",
|
|
|
|
flags = "fg",
|
|
|
|
min = 1,
|
|
|
|
max = 1
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.navigation.up")
|
|
|
|
@Logging(POSITION)
|
2018-08-12 14:03:07 +00:00
|
|
|
public void up(Player player, LocalSession session, CommandContext args) throws WorldEditException {
|
2014-04-03 02:08:50 +00:00
|
|
|
final int distance = args.getInteger(0);
|
|
|
|
|
|
|
|
final boolean alwaysGlass = getAlwaysGlass(args);
|
|
|
|
if (player.ascendUpwards(distance, alwaysGlass)) {
|
2018-08-12 14:03:07 +00:00
|
|
|
BBC.WHOOSH.send(player);
|
2014-04-03 02:08:50 +00:00
|
|
|
} else {
|
2018-08-12 14:03:07 +00:00
|
|
|
BBC.UP_FAIL.send(player);
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper function for /up and /ceil.
|
2018-08-12 14:03:07 +00:00
|
|
|
*
|
2014-04-03 02:08:50 +00:00
|
|
|
* @param args The {@link CommandContext} to extract the flags from.
|
|
|
|
* @return true, if glass should always be put under the player
|
|
|
|
*/
|
|
|
|
private boolean getAlwaysGlass(CommandContext args) {
|
2014-06-28 08:01:49 +00:00
|
|
|
final LocalConfiguration config = worldEdit.getConfiguration();
|
2014-04-03 02:08:50 +00:00
|
|
|
|
|
|
|
final boolean forceFlight = args.hasFlag('f');
|
|
|
|
final boolean forceGlass = args.hasFlag('g');
|
|
|
|
|
|
|
|
return forceGlass || (config.navigationUseGlass && !forceFlight);
|
|
|
|
}
|
2018-08-12 14:03:07 +00:00
|
|
|
|
|
|
|
public static Class<?> inject() {
|
|
|
|
return NavigationCommands.class;
|
|
|
|
}
|
|
|
|
}
|