Translate navigation

This commit is contained in:
Jesse Boyd 2016-06-29 20:44:04 +10:00
parent af6c80901a
commit 51a8b41399
5 changed files with 252 additions and 1 deletions

View File

@ -27,6 +27,7 @@ import com.sk89q.worldedit.blocks.BlockData;
import com.sk89q.worldedit.command.BrushCommands; import com.sk89q.worldedit.command.BrushCommands;
import com.sk89q.worldedit.command.ClipboardCommands; import com.sk89q.worldedit.command.ClipboardCommands;
import com.sk89q.worldedit.command.HistoryCommands; import com.sk89q.worldedit.command.HistoryCommands;
import com.sk89q.worldedit.command.NavigationCommands;
import com.sk89q.worldedit.command.RegionCommands; import com.sk89q.worldedit.command.RegionCommands;
import com.sk89q.worldedit.command.SchematicCommands; import com.sk89q.worldedit.command.SchematicCommands;
import com.sk89q.worldedit.command.ScriptingCommands; import com.sk89q.worldedit.command.ScriptingCommands;
@ -275,6 +276,7 @@ public class Fawe {
SelectionCommand.inject(); // Translations + set optimizations SelectionCommand.inject(); // Translations + set optimizations
RegionCommands.inject(); // Translations RegionCommands.inject(); // Translations
HistoryCommands.inject(); // Translations HistoryCommands.inject(); // Translations
NavigationCommands.inject(); // Translations + thru fix
// Schematic // Schematic
SchematicReader.inject(); SchematicReader.inject();
SchematicWriter.inject(); SchematicWriter.inject();

View File

@ -134,6 +134,37 @@ public enum BBC {
INDEXING_HISTORY("Indexing %s history objects on disk, please wait.", "History"), INDEXING_HISTORY("Indexing %s history objects on disk, please wait.", "History"),
INDEXING_COMPLETE("Indexing complete. Took: %s seconds!", "History"), INDEXING_COMPLETE("Indexing complete. Took: %s seconds!", "History"),
ASCEND_FAIL("No free spot above you found.", "Navigation"),
ASCENDED_PLURAL("Ascended %s0 levels.", "Navigation"),
ASCENDED_SINGULAR("Ascended a level.", "Navigation"),
UNSTUCK("There you go!", "Navigation"),
DESCEND_FAIL("No free spot below you found.", "Navigation"),
DESCEND_PLURAL("Descended %s0 levels.", "Navigation"),
DESCEND_SINGULAR("Descended a level.", "Navigation"),
WHOOSH("Whoosh!", "Navigation"),
POOF("Poof!", "Navigation"),
THRU_FAIL("No free spot ahead of you found.", "Navigation"),
JUMPTO_FAIL("No block in sight!", "Navigation"),
UP_FAIL("You would hit something above you.", "Navigation"),

View File

@ -203,7 +203,7 @@ public class LocalSession {
} }
public void remember(final EditSession editSession, final boolean append, final boolean sendMessage, int limitMb) { public void remember(final EditSession editSession, final boolean append, final boolean sendMessage, int limitMb) {
if (editSession == null || editSession.getChangeSet() == null || limitMb == 0) { if (editSession == null || editSession.getChangeSet() == null || limitMb == 0 || ((historySize >> 20) > limitMb && !append)) {
return; return;
} }
// It should have already been flushed, but just in case! // It should have already been flushed, but just in case!

View File

@ -474,6 +474,7 @@ public class ClipboardCommands {
session.setClipboard(null); session.setClipboard(null);
BBC.CLIPBOARD_CLEARED.send(player); BBC.CLIPBOARD_CLEARED.send(player);
} }
public static Class<?> inject() { public static Class<?> inject() {
return ClipboardCommands.class; return ClipboardCommands.class;
} }

View File

@ -0,0 +1,217 @@
/*
* 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.command;
import com.boydti.fawe.config.BBC;
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;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.WorldVector;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.util.command.parametric.Optional;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.sk89q.minecraft.util.commands.Logging.LogMode.POSITION;
/**
* Commands for moving the player around.
*/
public class NavigationCommands {
@SuppressWarnings("unused")
private final WorldEdit worldEdit;
/**
* Create a new instance.
*
* @param worldEdit reference to WorldEdit
*/
public NavigationCommands(WorldEdit worldEdit) {
checkNotNull(worldEdit);
this.worldEdit = worldEdit;
}
@Command(
aliases = { "unstuck", "!" },
usage = "",
desc = "Escape from being stuck inside a block",
min = 0,
max = 0
)
@CommandPermissions("worldedit.navigation.unstuck")
public void unstuck(Player player) throws WorldEditException {
player.findFreePosition();
BBC.UNSTUCK.send(player);
}
@Command(
aliases = { "ascend", "asc" },
usage = "[# of levels]",
desc = "Go up a floor",
min = 0,
max = 1
)
@CommandPermissions("worldedit.navigation.ascend")
public void ascend(Player player, @Optional("1") int levelsToAscend) throws WorldEditException {
int ascentLevels = 1;
while (player.ascendLevel() && levelsToAscend != ascentLevels) {
++ascentLevels;
}
if (ascentLevels == 0) {
BBC.ASCEND_FAIL.send(player);
} else {
if (ascentLevels == 1) {
BBC.ASCENDED_SINGULAR.send(player);
} else {
BBC.ASCENDED_PLURAL.send(player, ascentLevels);
}
}
}
@Command(
aliases = { "descend", "desc" },
usage = "[# of floors]",
desc = "Go down a floor",
min = 0,
max = 1
)
@CommandPermissions("worldedit.navigation.descend")
public void descend(Player player, @Optional("1") int levelsToDescend) throws WorldEditException {
int descentLevels = 1;
while (player.descendLevel() && levelsToDescend != descentLevels) {
++descentLevels;
}
if (descentLevels == 0) {
BBC.DESCEND_FAIL.send(player);
} else {
if (descentLevels == 1) {
BBC.DESCEND_SINGULAR.send(player);
} else {
BBC.DESCEND_PLURAL.send(player, descentLevels);
}
}
}
@Command(
aliases = { "ceil" },
usage = "[clearance]",
desc = "Go to the celing",
flags = "fg",
min = 0,
max = 1
)
@CommandPermissions("worldedit.navigation.ceiling")
@Logging(POSITION)
public void ceiling(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
final int clearance = args.argsLength() > 0 ?
Math.max(0, args.getInteger(0)) : 0;
final boolean alwaysGlass = getAlwaysGlass(args);
if (player.ascendToCeiling(clearance, alwaysGlass)) {
BBC.WHOOSH.send(player);
} else {
BBC.ASCEND_FAIL.send(player);
}
}
@Command(
aliases = { "thru" },
usage = "",
desc = "Passthrough walls",
min = 0,
max = 0
)
@CommandPermissions("worldedit.navigation.thru.command")
public void thru(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
if (player.passThroughForwardWall(6)) {
BBC.WHOOSH.send(player);
} else {
BBC.THRU_FAIL.send(player);
player.printError("No free spot ahead of you found.");
}
}
@Command(
aliases = { "jumpto", "j" },
usage = "",
desc = "Teleport to a location",
min = 0,
max = 0
)
@CommandPermissions("worldedit.navigation.jumpto.command")
public void jumpTo(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
WorldVector pos = player.getSolidBlockTrace(300);
if (pos != null) {
player.findFreePosition(pos);
BBC.POOF.send(player);
} else {
BBC.JUMPTO_FAIL.send(player);
}
}
@Command(
aliases = { "up" },
usage = "<block>",
desc = "Go upwards some distance",
flags = "fg",
min = 1,
max = 1
)
@CommandPermissions("worldedit.navigation.up")
@Logging(POSITION)
public void up(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException {
final int distance = args.getInteger(0);
final boolean alwaysGlass = getAlwaysGlass(args);
if (player.ascendUpwards(distance, alwaysGlass)) {
BBC.WHOOSH.send(player);
} else {
BBC.UP_FAIL.send(player);
}
}
/**
* Helper function for /up and /ceil.
*
* @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) {
final LocalConfiguration config = worldEdit.getConfiguration();
final boolean forceFlight = args.hasFlag('f');
final boolean forceGlass = args.hasFlag('g');
return forceGlass || (config.navigationUseGlass && !forceFlight);
}
public static Class<?> inject() {
return NavigationCommands.class;
}
}