More compile fixes

This commit is contained in:
MattBDev
2019-08-22 13:14:27 -04:00
parent 6998c2d230
commit 135c12b650
32 changed files with 217 additions and 269 deletions

View File

@ -26,8 +26,6 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class CommandContext {
@ -256,8 +254,11 @@ public class CommandContext {
}
public String getString(int start, int end) {
return IntStream.range(start + 1, end + 1).mapToObj(i -> " " + parsedArgs.get(i))
.collect(Collectors.joining("", parsedArgs.get(start), ""));
StringBuilder buffer = new StringBuilder(parsedArgs.get(start));
for (int i = start + 1; i < end + 1; ++i) {
buffer.append(" ").append(parsedArgs.get(i));
}
return buffer.toString();
}
public int getInteger(int index) throws NumberFormatException {

View File

@ -72,6 +72,7 @@ import com.sk89q.worldedit.regions.selector.RegionSelectorType;
import com.sk89q.worldedit.session.ClipboardHolder;
import com.sk89q.worldedit.util.Countable;
import com.sk89q.worldedit.util.HandSide;
import com.sk89q.worldedit.util.Identifiable;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
@ -395,7 +396,7 @@ public class LocalSession implements TextureHolder {
return null;
}
public synchronized void remember(Player player, World world, ChangeSet changeSet, FaweLimit limit) {
public synchronized void remember(Identifiable player, World world, ChangeSet changeSet, FaweLimit limit) {
if (Settings.IMP.HISTORY.USE_DISK) {
LocalSession.MAX_HISTORY_SIZE = Integer.MAX_VALUE;
}
@ -438,7 +439,7 @@ public class LocalSession implements TextureHolder {
}
}
public synchronized void remember(final EditSession editSession, final boolean append, int limitMb) {
public synchronized void remember(EditSession editSession, boolean append, int limitMb) {
if (Settings.IMP.HISTORY.USE_DISK) {
LocalSession.MAX_HISTORY_SIZE = Integer.MAX_VALUE;
}

View File

@ -81,7 +81,6 @@ import java.util.Map;
import javax.annotation.Nullable;
import javax.script.ScriptException;
import org.mozilla.javascript.NativeJavaObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -109,7 +108,8 @@ public final class WorldEdit {
private final PlatformManager platformManager = new PlatformManager(this);
private final EditSessionFactory editSessionFactory = new EditSessionFactory.EditSessionFactoryImpl(eventBus);
private final SessionManager sessions = new SessionManager(this);
private final ListeningExecutorService executorService = MoreExecutors.listeningDecorator(EvenMoreExecutors.newBoundedCachedThreadPool(0, 1, 20));;
private final ListeningExecutorService executorService = MoreExecutors.listeningDecorator(
EvenMoreExecutors.newBoundedCachedThreadPool(0, 1, 20, "WorldEdit Task Executor - %s"));
private final Supervisor supervisor = new SimpleSupervisor();
private final BlockFactory blockFactory = new BlockFactory(this);
@ -635,14 +635,14 @@ public final class WorldEdit {
* @param args arguments for the script
* @throws WorldEditException
*/
public Object runScript(Player player, File f, String[] args) throws WorldEditException {
public void runScript(Player player, File f, String[] args) throws WorldEditException {
String filename = f.getPath();
int index = filename.lastIndexOf('.');
String ext = filename.substring(index + 1);
if (!ext.equalsIgnoreCase("js")) {
player.printError("Only .js scripts are currently supported");
return null;
return;
}
String script;
@ -655,7 +655,7 @@ public final class WorldEdit {
if (file == null) {
player.printError("Script does not exist: " + filename);
return null;
return;
}
} else {
file = new FileInputStream(f);
@ -668,7 +668,7 @@ public final class WorldEdit {
script = new String(data, 0, data.length, StandardCharsets.UTF_8);
} catch (IOException e) {
player.printError("Script read error: " + e.getMessage());
return null;
return;
}
LocalSession session = getSessionManager().get(player);
@ -681,8 +681,8 @@ public final class WorldEdit {
engine = new RhinoCraftScriptEngine();
} catch (NoClassDefFoundError ignored) {
player.printError("Failed to find an installed script engine.");
player.printError("Please see https://worldedit.readthedocs.io/en/latest/usage/other/craftscripts/");
return null;
player.printError("Please see https://worldedit.enginehub.org/en/latest/usage/other/craftscripts/");
return;
}
engine.setTimeLimit(getConfiguration().scriptTimeout);
@ -693,11 +693,7 @@ public final class WorldEdit {
vars.put("player", player);
try {
Object result = engine.evaluate(script, filename, vars);
if (result instanceof NativeJavaObject) {
result = ((NativeJavaObject) result).unwrap();
}
return result;
engine.evaluate(script, filename, vars);
} catch (ScriptException e) {
player.printError("Failed to execute:");
player.printRaw(e.getMessage());
@ -714,7 +710,6 @@ public final class WorldEdit {
session.remember(editSession);
}
}
return null;
}
/**

View File

@ -19,14 +19,12 @@
package com.sk89q.worldedit.internal.command;
import static com.google.common.base.Preconditions.checkState;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.sk89q.worldedit.extension.platform.PlatformCommandManager;
import com.sk89q.worldedit.internal.util.Substring;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import static java.util.stream.Collectors.toList;
import org.enginehub.piston.Command;
import org.enginehub.piston.exception.CommandException;
import org.enginehub.piston.inject.InjectedValueAccess;
@ -40,6 +38,9 @@ import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;
import static com.google.common.base.Preconditions.checkState;
import static java.util.stream.Collectors.toList;
public class CommandUtil {
public static Map<String, Command> getSubCommands(Command currentCommand) {
@ -64,20 +65,37 @@ public class CommandUtil {
* Fix {@code suggestions} to replace the last space-separated word in {@code arguments}.
*/
public static List<String> fixSuggestions(String arguments, List<Substring> suggestions) {
Substring lastArg = Iterables.getLast(CommandArgParser.spaceSplit(arguments));
Substring lastArg = Iterables.getLast(
CommandArgParser.spaceSplit(arguments)
);
return suggestions.stream()
.map(suggestion -> CommandUtil.suggestLast(lastArg, suggestion))
// Re-map suggestions to only operate on the last non-quoted word
.map(suggestion -> onlyOnLastQuotedWord(lastArg, suggestion))
.map(suggestion -> suggestLast(lastArg, suggestion))
.filter(Optional::isPresent)
.map(Optional::get)
.collect(toList());
}
private static Substring onlyOnLastQuotedWord(Substring lastArg, Substring suggestion) {
if (suggestion.getSubstring().startsWith(lastArg.getSubstring())) {
// This is already fine.
return suggestion;
}
String substr = suggestion.getSubstring();
int sp = substr.lastIndexOf(' ');
if (sp < 0) {
return suggestion;
}
return Substring.wrap(substr.substring(sp + 1), suggestion.getStart() + sp + 1, suggestion.getEnd());
}
/**
* Given the last word of a command, mutate the suggestion to replace the last word, if
* possible.
*/
private static Optional<String> suggestLast(Substring last, Substring suggestion) {
if (suggestion.getStart() == last.getEnd()) {
if (suggestion.getStart() == last.getEnd() && !last.getSubstring().equals("\"")) {
// this suggestion is for the next argument.
if (last.getSubstring().isEmpty()) {
return Optional.of(suggestion.getSubstring());

View File

@ -32,6 +32,7 @@ import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.RegionSelector;
import com.sk89q.worldedit.regions.selector.CuboidRegionSelector;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockTypes;
@ -114,11 +115,12 @@ public class ServerCUIHandler {
}
// Borrowed this math from FAWE
double rotX = player.getLocation().getYaw();
double rotY = player.getLocation().getPitch();
final Location location = player.getLocation();
double rotX = location.getYaw();
double rotY = location.getPitch();
double xz = Math.cos(Math.toRadians(rotY));
int x = (int) (player.getLocation().getX() - (-xz * Math.sin(Math.toRadians(rotX))) * 12);
int z = (int) (player.getLocation().getZ() - (xz * Math.cos(Math.toRadians(rotX))) * 12);
int x = (int) (location.getX() - (-xz * Math.sin(Math.toRadians(rotX))) * 12);
int z = (int) (location.getZ() - (xz * Math.cos(Math.toRadians(rotX))) * 12);
int y = Math.max(0, Math.min(Math.min(255, posY + 32), posY + 3));
Map<String, Tag> structureTag = new HashMap<>();

View File

@ -71,7 +71,7 @@ public class SessionManager {
private static final Logger log = LoggerFactory.getLogger(SessionManager.class);
private static boolean warnedInvalidTool;
private final Timer timer = new Timer();
private final Timer timer = new Timer("WorldEdit Session Manager");
private final WorldEdit worldEdit;
private final Map<UUID, SessionHolder> sessions = new HashMap<>();
private SessionStore store = new VoidStore();

View File

@ -19,8 +19,10 @@
package com.sk89q.worldedit.util.concurrency;
import java.util.concurrent.ArrayBlockingQueue;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
@ -39,15 +41,33 @@ public final class EvenMoreExecutors {
*
* @param minThreads the minimum number of threads to have at a given time
* @param maxThreads the maximum number of threads to have at a given time
* @param queueSize the size of the queue before new submissions are rejected
* @param queueSize the size of the queue before new submissions are rejected
* @return the newly created thread pool
*/
public static ExecutorService newBoundedCachedThreadPool(int minThreads, int maxThreads, int queueSize) {
return newBoundedCachedThreadPool(minThreads, maxThreads, queueSize, null);
}
/**
* Creates a thread pool that creates new threads as needed up to
* a maximum number of threads, but will reuse previously constructed
* threads when they are available.
*
* @param minThreads the minimum number of threads to have at a given time
* @param maxThreads the maximum number of threads to have at a given time
* @param queueSize the size of the queue before new submissions are rejected
* @param threadFormat thread name formatter
* @return the newly created thread pool
*/
public static ExecutorService newBoundedCachedThreadPool(int minThreads, int maxThreads, int queueSize, String threadFormat) {
ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
minThreads, maxThreads,
60L, TimeUnit.SECONDS,
new ArrayBlockingQueue<>(queueSize));
new LinkedBlockingDeque<>(queueSize));
threadPoolExecutor.allowCoreThreadTimeOut(true);
if (threadFormat != null) {
threadPoolExecutor.setThreadFactory(new ThreadFactoryBuilder().setNameFormat(threadFormat).build());
}
return threadPoolExecutor;
}

View File

@ -19,8 +19,9 @@
package com.sk89q.worldedit.util.paste;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.sk89q.worldedit.util.net.HttpRequest;
import org.json.simple.JSONValue;
import java.io.IOException;
import java.net.URL;
@ -33,6 +34,8 @@ public class EngineHubPaste implements Paster {
private static final Pattern URL_PATTERN = Pattern.compile("https?://.+$");
private static final Gson GSON = new Gson();
@Override
public Callable<URL> paste(String content) {
return new PasteTask(content);
@ -59,10 +62,10 @@ public class EngineHubPaste implements Paster {
.returnContent()
.asString("UTF-8").trim();
Object object = JSONValue.parse(result);
if (object instanceof Map) {
@SuppressWarnings("unchecked")
String urlString = String.valueOf(((Map<Object, Object>) object).get("url"));
Map<Object, Object> object = GSON.fromJson(result, new TypeToken<Map<Object, Object>>() {
}.getType());
if (object != null) {
String urlString = String.valueOf(object.get("url"));
Matcher m = URL_PATTERN.matcher(urlString);
if (m.matches()) {

View File

@ -72,7 +72,6 @@ public interface World extends Extent, Keyed, IChunkCache<IChunkGet> {
*
* @return the maximum Y
*/
@Override
int getMaxY();
/**

View File

@ -66,13 +66,13 @@ public class SnapshotRepository {
}
/**
* Get a list of snapshots in a directory. The newest snapshot is near the top of the array.
* Get a list of snapshots in a directory. The newest snapshot is
* near the top of the array.
*
* @param newestFirst true to get the newest first
* @return a list of snapshots
*/
public List<Snapshot> getSnapshots(boolean newestFirst, String worldName)
throws MissingWorldException {
public List<Snapshot> getSnapshots(boolean newestFirst, String worldName) throws MissingWorldException {
FilenameFilter filter = (dir, name) -> {
File f = new File(dir, name);
return isValidSnapshot(f);
@ -116,8 +116,7 @@ public class SnapshotRepository {
* @return a snapshot or null
*/
@Nullable
public Snapshot getSnapshotAfter(ZonedDateTime date, String world)
throws MissingWorldException {
public Snapshot getSnapshotAfter(ZonedDateTime date, String world) throws MissingWorldException {
List<Snapshot> snapshots = getSnapshots(true, world);
Snapshot last = null;
@ -139,8 +138,7 @@ public class SnapshotRepository {
* @return a snapshot or null
*/
@Nullable
public Snapshot getSnapshotBefore(ZonedDateTime date, String world)
throws MissingWorldException {
public Snapshot getSnapshotBefore(ZonedDateTime date, String world) throws MissingWorldException {
List<Snapshot> snapshots = getSnapshots(false, world);
Snapshot last = null;
@ -206,8 +204,7 @@ public class SnapshotRepository {
* @return whether it is a valid snapshot
*/
protected boolean isValidSnapshot(File file) {
if (!file.getName()
.matches("^[A-Za-z0-9_\\- \\./\\\\'\\$@~!%\\^\\*\\(\\)\\[\\]\\+\\{\\},\\?]+$")) {
if (!file.getName().matches("^[A-Za-z0-9_\\- \\./\\\\'\\$@~!%\\^\\*\\(\\)\\[\\]\\+\\{\\},\\?]+$")) {
return false;
}