mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-11-19 10:25:00 +00:00
Port navigation commands
This commit is contained in:
parent
6d4982f23a
commit
f2283e8ad0
@ -19,23 +19,26 @@
|
|||||||
|
|
||||||
package com.sk89q.worldedit.command;
|
package com.sk89q.worldedit.command;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
|
||||||
import static com.sk89q.worldedit.command.util.Logging.LogMode.POSITION;
|
|
||||||
|
|
||||||
import com.sk89q.minecraft.util.commands.Command;
|
|
||||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
|
||||||
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
|
||||||
import com.sk89q.worldedit.LocalConfiguration;
|
import com.sk89q.worldedit.LocalConfiguration;
|
||||||
import com.sk89q.worldedit.WorldEdit;
|
import com.sk89q.worldedit.WorldEdit;
|
||||||
import com.sk89q.worldedit.WorldEditException;
|
import com.sk89q.worldedit.WorldEditException;
|
||||||
|
import com.sk89q.worldedit.command.util.CommandPermissions;
|
||||||
|
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
|
||||||
import com.sk89q.worldedit.command.util.Logging;
|
import com.sk89q.worldedit.command.util.Logging;
|
||||||
import com.sk89q.worldedit.entity.Player;
|
import com.sk89q.worldedit.entity.Player;
|
||||||
import com.sk89q.worldedit.util.Location;
|
import com.sk89q.worldedit.util.Location;
|
||||||
import com.sk89q.worldedit.util.command.parametric.Optional;
|
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;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
import static com.sk89q.worldedit.command.util.Logging.LogMode.POSITION;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Commands for moving the player around.
|
* Commands for moving the player around.
|
||||||
*/
|
*/
|
||||||
|
@CommandContainer(superTypes = CommandPermissionsConditionGenerator.Registration.class)
|
||||||
public class NavigationCommands {
|
public class NavigationCommands {
|
||||||
|
|
||||||
private final WorldEdit worldEdit;
|
private final WorldEdit worldEdit;
|
||||||
@ -51,80 +54,78 @@ public class NavigationCommands {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
aliases = { "unstuck", "!" },
|
name = "unstuck",
|
||||||
usage = "",
|
aliases = { "!" },
|
||||||
desc = "Escape from being stuck inside a block",
|
desc = "Escape from being stuck inside a block"
|
||||||
min = 0,
|
|
||||||
max = 0
|
|
||||||
)
|
)
|
||||||
@CommandPermissions("worldedit.navigation.unstuck")
|
@CommandPermissions("worldedit.navigation.unstuck")
|
||||||
public void unstuck(Player player) throws WorldEditException {
|
public void unstuck(Player player) throws WorldEditException {
|
||||||
player.print("There you go!");
|
|
||||||
player.findFreePosition();
|
player.findFreePosition();
|
||||||
|
player.print("There you go!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
aliases = { "ascend", "asc" },
|
name = "ascend",
|
||||||
usage = "[# of levels]",
|
aliases = { "asc" },
|
||||||
desc = "Go up a floor",
|
desc = "Go up a floor"
|
||||||
min = 0,
|
|
||||||
max = 1
|
|
||||||
)
|
)
|
||||||
@CommandPermissions("worldedit.navigation.ascend")
|
@CommandPermissions("worldedit.navigation.ascend")
|
||||||
public void ascend(Player player, @Optional("1") int levelsToAscend) throws WorldEditException {
|
public void ascend(Player player,
|
||||||
|
@Arg(desc = "# of levels to ascend", def = "1")
|
||||||
|
int levels) throws WorldEditException {
|
||||||
int ascentLevels = 0;
|
int ascentLevels = 0;
|
||||||
while (player.ascendLevel()) {
|
while (player.ascendLevel()) {
|
||||||
++ascentLevels;
|
++ascentLevels;
|
||||||
if (levelsToAscend == ascentLevels) {
|
if (levels == ascentLevels) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ascentLevels == 0) {
|
if (ascentLevels == 0) {
|
||||||
player.printError("No free spot above you found.");
|
player.printError("No free spot above you found.");
|
||||||
} else {
|
} else {
|
||||||
player.print((ascentLevels != 1) ? "Ascended " + Integer.toString(ascentLevels) + " levels." : "Ascended a level.");
|
player.print((ascentLevels != 1) ? "Ascended " + ascentLevels + " levels." : "Ascended a level.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
aliases = { "descend", "desc" },
|
name = "descend",
|
||||||
usage = "[# of floors]",
|
aliases = { "desc" },
|
||||||
desc = "Go down a floor",
|
desc = "Go down a floor"
|
||||||
min = 0,
|
|
||||||
max = 1
|
|
||||||
)
|
)
|
||||||
@CommandPermissions("worldedit.navigation.descend")
|
@CommandPermissions("worldedit.navigation.descend")
|
||||||
public void descend(Player player, @Optional("1") int levelsToDescend) throws WorldEditException {
|
public void descend(Player player,
|
||||||
|
@Arg(desc = "# of levels to descend", def = "1")
|
||||||
|
int levels) throws WorldEditException {
|
||||||
int descentLevels = 0;
|
int descentLevels = 0;
|
||||||
while (player.descendLevel()) {
|
while (player.descendLevel()) {
|
||||||
++descentLevels;
|
++descentLevels;
|
||||||
if (levelsToDescend == descentLevels) {
|
if (levels == descentLevels) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (descentLevels == 0) {
|
if (descentLevels == 0) {
|
||||||
player.printError("No free spot below you found.");
|
player.printError("No free spot below you found.");
|
||||||
} else {
|
} else {
|
||||||
player.print((descentLevels != 1) ? "Descended " + Integer.toString(descentLevels) + " levels." : "Descended a level.");
|
player.print((descentLevels != 1) ? "Descended " + descentLevels + " levels." : "Descended a level.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
aliases = { "ceil" },
|
name = "ceil",
|
||||||
usage = "[clearance]",
|
desc = "Go to the ceiling"
|
||||||
desc = "Go to the celing",
|
|
||||||
flags = "fg",
|
|
||||||
min = 0,
|
|
||||||
max = 1
|
|
||||||
)
|
)
|
||||||
@CommandPermissions("worldedit.navigation.ceiling")
|
@CommandPermissions("worldedit.navigation.ceiling")
|
||||||
@Logging(POSITION)
|
@Logging(POSITION)
|
||||||
public void ceiling(Player player, CommandContext args) throws WorldEditException {
|
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);
|
||||||
|
|
||||||
final int clearance = args.argsLength() > 0 ?
|
boolean alwaysGlass = getAlwaysGlass(forceFlight, forceGlass);
|
||||||
Math.max(0, args.getInteger(0)) : 0;
|
|
||||||
|
|
||||||
final boolean alwaysGlass = getAlwaysGlass(args);
|
|
||||||
if (player.ascendToCeiling(clearance, alwaysGlass)) {
|
if (player.ascendToCeiling(clearance, alwaysGlass)) {
|
||||||
player.print("Whoosh!");
|
player.print("Whoosh!");
|
||||||
} else {
|
} else {
|
||||||
@ -133,11 +134,8 @@ public class NavigationCommands {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
aliases = { "thru" },
|
name = "thru",
|
||||||
usage = "",
|
desc = "Pass through walls"
|
||||||
desc = "Passthrough walls",
|
|
||||||
min = 0,
|
|
||||||
max = 0
|
|
||||||
)
|
)
|
||||||
@CommandPermissions("worldedit.navigation.thru.command")
|
@CommandPermissions("worldedit.navigation.thru.command")
|
||||||
public void thru(Player player) throws WorldEditException {
|
public void thru(Player player) throws WorldEditException {
|
||||||
@ -149,11 +147,9 @@ public class NavigationCommands {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
aliases = { "jumpto", "j" },
|
name = "jumpto",
|
||||||
usage = "",
|
aliases = { "j" },
|
||||||
desc = "Teleport to a location",
|
desc = "Teleport to a location"
|
||||||
min = 0,
|
|
||||||
max = 0
|
|
||||||
)
|
)
|
||||||
@CommandPermissions("worldedit.navigation.jumpto.command")
|
@CommandPermissions("worldedit.navigation.jumpto.command")
|
||||||
public void jumpTo(Player player) throws WorldEditException {
|
public void jumpTo(Player player) throws WorldEditException {
|
||||||
@ -168,19 +164,19 @@ public class NavigationCommands {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
aliases = { "up" },
|
name = "up",
|
||||||
usage = "<block>",
|
desc = "Go upwards some distance"
|
||||||
desc = "Go upwards some distance",
|
|
||||||
flags = "fg",
|
|
||||||
min = 1,
|
|
||||||
max = 1
|
|
||||||
)
|
)
|
||||||
@CommandPermissions("worldedit.navigation.up")
|
@CommandPermissions("worldedit.navigation.up")
|
||||||
@Logging(POSITION)
|
@Logging(POSITION)
|
||||||
public void up(Player player, CommandContext args) throws WorldEditException {
|
public void up(Player player,
|
||||||
final int distance = args.getInteger(0);
|
@Arg(desc = "Distance to go upwards")
|
||||||
|
int distance,
|
||||||
final boolean alwaysGlass = getAlwaysGlass(args);
|
@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);
|
||||||
if (player.ascendUpwards(distance, alwaysGlass)) {
|
if (player.ascendUpwards(distance, alwaysGlass)) {
|
||||||
player.print("Whoosh!");
|
player.print("Whoosh!");
|
||||||
} else {
|
} else {
|
||||||
@ -191,15 +187,13 @@ public class NavigationCommands {
|
|||||||
/**
|
/**
|
||||||
* Helper function for /up and /ceil.
|
* Helper function for /up and /ceil.
|
||||||
*
|
*
|
||||||
* @param args The {@link CommandContext} to extract the flags from.
|
* @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
|
||||||
* @return true, if glass should always be put under the player
|
* @return true, if glass should always be put under the player
|
||||||
*/
|
*/
|
||||||
private boolean getAlwaysGlass(CommandContext args) {
|
private boolean getAlwaysGlass(boolean forceFlight, boolean forceGlass) {
|
||||||
final LocalConfiguration config = worldEdit.getConfiguration();
|
final LocalConfiguration config = worldEdit.getConfiguration();
|
||||||
|
|
||||||
final boolean forceFlight = args.hasFlag('f');
|
|
||||||
final boolean forceGlass = args.hasFlag('g');
|
|
||||||
|
|
||||||
return forceGlass || (config.navigationUseGlass && !forceFlight);
|
return forceGlass || (config.navigationUseGlass && !forceFlight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,8 @@ import com.sk89q.worldedit.command.GenerationCommands;
|
|||||||
import com.sk89q.worldedit.command.GenerationCommandsRegistration;
|
import com.sk89q.worldedit.command.GenerationCommandsRegistration;
|
||||||
import com.sk89q.worldedit.command.HistoryCommands;
|
import com.sk89q.worldedit.command.HistoryCommands;
|
||||||
import com.sk89q.worldedit.command.HistoryCommandsRegistration;
|
import com.sk89q.worldedit.command.HistoryCommandsRegistration;
|
||||||
|
import com.sk89q.worldedit.command.NavigationCommands;
|
||||||
|
import com.sk89q.worldedit.command.NavigationCommandsRegistration;
|
||||||
import com.sk89q.worldedit.command.SchematicCommands;
|
import com.sk89q.worldedit.command.SchematicCommands;
|
||||||
import com.sk89q.worldedit.command.SchematicCommandsRegistration;
|
import com.sk89q.worldedit.command.SchematicCommandsRegistration;
|
||||||
import com.sk89q.worldedit.command.argument.Arguments;
|
import com.sk89q.worldedit.command.argument.Arguments;
|
||||||
@ -284,14 +286,17 @@ public final class PlatformCommandMananger {
|
|||||||
HistoryCommandsRegistration.builder(),
|
HistoryCommandsRegistration.builder(),
|
||||||
new HistoryCommands(worldEdit)
|
new HistoryCommands(worldEdit)
|
||||||
);
|
);
|
||||||
|
register(
|
||||||
|
commandManager,
|
||||||
|
NavigationCommandsRegistration.builder(),
|
||||||
|
new NavigationCommands(worldEdit)
|
||||||
|
);
|
||||||
|
|
||||||
// Unported commands are below. Delete once they're added to the main manager above.
|
// Unported commands are below. Delete once they're added to the main manager above.
|
||||||
/*
|
/*
|
||||||
dispatcher = new CommandGraph()
|
dispatcher = new CommandGraph()
|
||||||
.builder(builder)
|
.builder(builder)
|
||||||
.commands()
|
.commands()
|
||||||
.registerMethods(new HistoryCommands(worldEdit))
|
|
||||||
.registerMethods(new NavigationCommands(worldEdit))
|
|
||||||
.registerMethods(new RegionCommands(worldEdit))
|
.registerMethods(new RegionCommands(worldEdit))
|
||||||
.registerMethods(new ScriptingCommands(worldEdit))
|
.registerMethods(new ScriptingCommands(worldEdit))
|
||||||
.registerMethods(new SelectionCommands(worldEdit))
|
.registerMethods(new SelectionCommands(worldEdit))
|
||||||
|
Loading…
Reference in New Issue
Block a user