Another selective merge

This commit is contained in:
matt
2019-03-28 15:02:37 -04:00
parent acc8eb0a99
commit 699783ba72
14 changed files with 260 additions and 626 deletions

View File

@ -36,8 +36,6 @@ import com.boydti.fawe.object.schematic.Schematic;
import com.boydti.fawe.util.ImgurUtility;
import com.boydti.fawe.util.MainUtil;
import com.boydti.fawe.util.MaskTraverser;
import com.boydti.fawe.util.gui.FormBuilder;
import com.boydti.fawe.wrappers.FakePlayer;
import com.sk89q.minecraft.util.commands.*;
import com.sk89q.worldedit.*;
import static com.google.common.base.Preconditions.checkNotNull;
@ -393,17 +391,7 @@ public class ClipboardCommands extends MethodCommands {
e.printStackTrace();
}
}
if (Fawe.imp().getPlatform().equalsIgnoreCase("nukkit")) {
FormBuilder form = Fawe.imp().getFormBuilder();
FawePlayer<Object> fp = FawePlayer.wrap(player);
if (form != null && fp != FakePlayer.getConsole().toFawePlayer()) {
form.setTitle("Download Clipboard");
form.addInput("url:", urlText, urlText);
form.display(fp);
return;
}
}
BBC.DOWNLOAD_LINK.send(player, urlText);
BBC.DOWNLOAD_LINK.send(player, urlText);
}
}
}

View File

@ -176,7 +176,7 @@ public class SchematicCommands extends MethodCommands {
@CommandPermissions({"worldedit.schematic.remap"})
public void remap(final Player player, final LocalSession session) throws WorldEditException {
ClipboardRemapper remapper;
if (Fawe.imp().getPlatform().equalsIgnoreCase("nukkit")) {
if (false) {
remapper = new ClipboardRemapper(ClipboardRemapper.RemapPlatform.PC, ClipboardRemapper.RemapPlatform.PE);
} else {
remapper = new ClipboardRemapper(ClipboardRemapper.RemapPlatform.PE, ClipboardRemapper.RemapPlatform.PC);

View File

@ -28,22 +28,17 @@ import com.boydti.fawe.config.Settings;
import com.boydti.fawe.object.DelegateConsumer;
import com.boydti.fawe.object.FaweLimit;
import com.boydti.fawe.object.FawePlayer;
import com.boydti.fawe.object.RunnableVal;
import com.boydti.fawe.object.RunnableVal3;
import com.boydti.fawe.util.MainUtil;
import com.boydti.fawe.util.MathMan;
import com.boydti.fawe.util.StringMan;
import com.boydti.fawe.util.chat.Message;
import com.boydti.fawe.util.chat.UsageMessage;
import com.boydti.fawe.util.gui.FormBuilder;
import com.boydti.fawe.util.image.ImageUtil;
import com.sk89q.minecraft.util.commands.*;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.world.block.BlockState;
import static com.sk89q.minecraft.util.commands.Logging.LogMode.PLACEMENT;
import com.google.common.base.Joiner;
import com.sk89q.minecraft.util.commands.Command;
import com.sk89q.minecraft.util.commands.CommandContext;
import com.sk89q.minecraft.util.commands.CommandException;
@ -201,33 +196,30 @@ public class UtilityCommands extends MethodCommands {
File maxImages = new File(webSrc, "images" + File.separator + "max");
final int sub = srcFolder.getAbsolutePath().length();
List<String> images = new ArrayList<>();
MainUtil.iterateFiles(srcFolder, new Consumer<File>() {
@Override
public void accept(File file) {
switch (file.getName().substring(file.getName().lastIndexOf('.')).toLowerCase()) {
case ".png":
case ".jpeg":
break;
default:
return;
}
try {
String name = file.getAbsolutePath().substring(sub);
if (name.startsWith(File.separator)) name = name.replaceFirst(java.util.regex.Pattern.quote(File.separator), "");
BufferedImage img = MainUtil.readImage(file);
BufferedImage minImg = ImageUtil.getScaledInstance(img, min, min, RenderingHints.VALUE_INTERPOLATION_BILINEAR, true);
BufferedImage maxImg = max == -1 ? img : ImageUtil.getScaledInstance(img, max, max, RenderingHints.VALUE_INTERPOLATION_BILINEAR, true);
player.sendMessage("Writing " + name);
File minFile = new File(minImages, name);
File maxFile = new File(maxImages, name);
minFile.getParentFile().mkdirs();
maxFile.getParentFile().mkdirs();
ImageIO.write(minImg, "png", minFile);
ImageIO.write(maxImg, "png", maxFile);
images.add(name);
} catch (IOException e) {
throw new RuntimeException(e);
}
MainUtil.iterateFiles(srcFolder, file -> {
switch (file.getName().substring(file.getName().lastIndexOf('.')).toLowerCase()) {
case ".png":
case ".jpeg":
break;
default:
return;
}
try {
String name = file.getAbsolutePath().substring(sub);
if (name.startsWith(File.separator)) name = name.replaceFirst(java.util.regex.Pattern.quote(File.separator), "");
BufferedImage img = MainUtil.readImage(file);
BufferedImage minImg = ImageUtil.getScaledInstance(img, min, min, RenderingHints.VALUE_INTERPOLATION_BILINEAR, true);
BufferedImage maxImg = max == -1 ? img : ImageUtil.getScaledInstance(img, max, max, RenderingHints.VALUE_INTERPOLATION_BILINEAR, true);
player.sendMessage("Writing " + name);
File minFile = new File(minImages, name);
File maxFile = new File(maxImages, name);
minFile.getParentFile().mkdirs();
maxFile.getParentFile().mkdirs();
ImageIO.write(minImg, "png", minFile);
ImageIO.write(maxImg, "png", maxFile);
images.add(name);
} catch (IOException e) {
throw new RuntimeException(e);
}
});
StringBuilder config = new StringBuilder();
@ -666,20 +658,12 @@ public class UtilityCommands extends MethodCommands {
final Expression expression = Expression.compile(input);
ExecutorService executor = Executors.newSingleThreadExecutor();
Future<Double> futureResult = executor.submit(new Callable<Double>() {
@Override
public Double call() throws Exception {
return expression.evaluate();
}
});
Future<Double> futureResult = executor.submit((Callable<Double>) expression::evaluate);
Double result = Double.NaN;
try {
result = futureResult.get(limit.MAX_EXPRESSION_MS, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
} catch (TimeoutException e) {
futureResult.cancel(true);
@ -780,26 +764,25 @@ public class UtilityCommands extends MethodCommands {
final int sortType = args.hasFlag('d') ? -1 : args.hasFlag('n') ? 1 : 0;
// cleanup file list
Collections.sort(fileList, new Comparator<File>() {
@Override
public int compare(File f1, File f2) {
boolean dir1 = f1.isDirectory();
boolean dir2 = f2.isDirectory();
if (dir1 != dir2) return dir1 ? -1 : 1;
int res;
if (sortType == 0) { // use name by default
int p = f1.getParent().compareTo(f2.getParent());
if (p == 0) { // same parent, compare names
res = f1.getName().compareTo(f2.getName());
} else { // different parent, sort by that
res = p;
}
} else {
res = Long.valueOf(f1.lastModified()).compareTo(f2.lastModified()); // use date if there is a flag
if (sortType == 1) res = -res; // flip date for newest first instead of oldest first
fileList.sort((f1, f2) -> {
boolean dir1 = f1.isDirectory();
boolean dir2 = f2.isDirectory();
if (dir1 != dir2)
return dir1 ? -1 : 1;
int res;
if (sortType == 0) { // use name by default
int p = f1.getParent().compareTo(f2.getParent());
if (p == 0) { // same parent, compare names
res = f1.getName().compareTo(f2.getName());
} else { // different parent, sort by that
res = p;
}
return res;
} else {
res = Long.compare(f1.lastModified(), f2.lastModified()); // use date if there is a flag
if (sortType == 1)
res = -res; // flip date for newest first instead of oldest first
}
return res;
});
int offset = (page - 1) * perPage;
@ -891,7 +874,7 @@ public class UtilityCommands extends MethodCommands {
UUID uuid = UUID.fromString(f.getName());
return false;
}
} catch (IllegalArgumentException exception) {}
} catch (IllegalArgumentException ignored) {}
return true;
};
@ -1031,269 +1014,6 @@ public class UtilityCommands extends MethodCommands {
help(args, we, actor, "/", null);
}
@Command(
aliases = {"/gui"},
desc = "Open the GUI"
)
@Logging(PLACEMENT)
public void gui(Actor actor, FawePlayer fp, LocalSession session, CommandContext args) throws WorldEditException, CommandException {
FormBuilder gui = Fawe.imp().getFormBuilder();
if (gui == null) throw new CommandException("Only supported on Pocket Edition");
Dispatcher callable = worldEdit.getPlatformManager().getCommandManager().getDispatcher();
CommandLocals locals = args.getLocals();
String prefix = Commands.getAlias(UtilityCommands.class, "/gui");
// TODO sort commands by most used
new HelpBuilder(callable, args, prefix, Integer.MAX_VALUE) {
@Override
public void displayFailure(String message) {
gui.setTitle("Error");
gui.addLabel(message);
}
@Override
public void displayUsage(CommandCallable callable, String commandString) {
gui.setTitle(commandString);
if (callable instanceof Dispatcher) {
Dispatcher dispathcer = (Dispatcher) callable;
dispathcer.getCommands();
gui.addLabel("Dispatcher not implemented for " + commandString);
} else {
Description cmdDesc = callable.getDescription();
List<Parameter> params = cmdDesc.getParameters();
String[] suggested = new String[params.size()];
if (cmdDesc.getUsage() != null) {
String[] usageArgs = cmdDesc.getUsage().split(" ", params.size());
for (int i = 0; i < usageArgs.length; i++) {
String arg = usageArgs[i];
String[] splitSug = arg.split("=");
if (splitSug.length == 2) {
suggested[i] = splitSug[1];
}
}
}
for (int i = 0 ; i < params.size(); i++) {
String[] def = params.get(i).getDefaultValue();
if (def != null && def.length != 0) {
suggested[i] = def[0];
}
}
String help = cmdDesc.getHelp();
if (help == null || help.isEmpty()) help = cmdDesc.getDescription();
gui.addLabel(BBC.color("&2" + help + "\n"));
List<String> flags = new ArrayList<>();
for (int i = 0; i < params.size(); i++) {
Parameter param = params.get(i);
String name = param.getName();
boolean optional = param.isValueFlag() || param.isOptional();
String[] def = param.getDefaultValue();
if (param.getFlag() != null) {
flags.add("-" + param.getFlag() + " ");
} else {
flags.add("");
}
if (param instanceof ParameterData) {
ParameterData pd = (ParameterData) param;
Type type = pd.getType();
String suggestion = suggested[i];
String color = optional ? "3" : "c";
StringBuilder label = new StringBuilder(BBC.color("&" + color + name + ": "));
// if (suggested[i] != null) label.append(" e.g. " + suggestion);
Range range = MainUtil.getOf(pd.getModifiers(), Range.class);
double min = 0;
double max = 100;
if (range != null) {
min = range.min();
max = range.max();
} else {
SuggestedRange suggestedRange = MainUtil.getOf(pd.getModifiers(), SuggestedRange.class);
if (suggestedRange != null) {
min = suggestedRange.min();
max = suggestedRange.max();
} else if (name.equalsIgnoreCase("radius") || name.equalsIgnoreCase("size")) {
max = WorldEdit.getInstance().getConfiguration().maxBrushRadius;
}
}
int step = 1;
Step stepSizeAnn = MainUtil.getOf(pd.getModifiers(), Step.class);
if (stepSizeAnn != null) {
double stepVal = stepSizeAnn.value();
step = Math.max(1, (int) stepVal);
}
/*
BaseBiome
Vector
Vector2D
*/
switch (type.getTypeName()) {
case "double":
case "java.lang.Double": {
double value = suggestion != null ? Double.parseDouble(suggestion) : min;
gui.addSlider("\n" + label.toString(), min, max, 1, value);
break;
}
case "int":
case "java.lang.Integer": {
int value = suggestion != null ? Integer.parseInt(suggestion) : (int) min;
gui.addSlider("\n" + label.toString(), min, max, 1, value);
break;
}
case "boolean":
case "java.lang.Boolean": {
boolean value = suggestion != null ? Boolean.parseBoolean(suggestion) : false;
gui.addToggle(label.toString(), value);
break;
}
case "com.sk89q.worldedit.patterns.Pattern": {
gui.addInput("\n" + label.toString(), "stone", "wood");
break;
}
case "com.sk89q.worldedit.blocks.BaseBlock": {
gui.addInput("\n" + label.toString(), "stone", "wood");
break;
}
case "com.sk89q.worldedit.function.mask.Mask": {
gui.addInput("\n" + label.toString(), "stone", "wood");
break;
}
default:
case "java.lang.String": {
// TODO
// clipboard
// schematic
// image
if (suggestion == null) suggestion = "";
gui.addInput("\n" + label.toString(), suggestion, suggestion);
break;
}
}
} else {
throw new UnsupportedOperationException("Unsupported callable: " + callable.getClass() + " | " + param.getClass());
}
}
gui.setResponder(new Consumer<Map<Integer, Object>>() {
@Override
public void accept(Map<Integer, Object> response) {
int index = 0;
StringBuilder command = new StringBuilder(commandString);
for (Map.Entry<Integer, Object> arg : response.entrySet()) {
String argValue = arg.getValue().toString();
String flag = flags.get(index);
if (!flag.isEmpty()) {
if (argValue.equalsIgnoreCase("false")) continue;
if (argValue.equalsIgnoreCase("true")) argValue = "";
}
command.append(" " + flag + argValue);
index++;
}
CommandEvent event = new CommandEvent(actor, command.toString());
CommandManager.getInstance().handleCommand(event);
}
});
}
}
@Override
public void displayCategories(Map<String, Map<CommandMapping, String>> categories) {
gui.setTitle(BBC.HELP_HEADER_CATEGORIES.s());
List<String> categoryList = new ArrayList<>();
for (Map.Entry<String, Map<CommandMapping, String>> categoryEntry : categories.entrySet()) {
String category = categoryEntry.getKey();
categoryList.add(category);
Map<CommandMapping, String> commandMap = categoryEntry.getValue();
int size = commandMap.size();
String plural = size == 1 ? "command" : "commands";
gui.addButton(BBC.HELP_ITEM_ALLOWED.f(category, "(" + size + " " + plural + ")"), null);
}
gui.setResponder(new Consumer<Map<Integer, Object>>() {
@Override
public void accept(Map<Integer, Object> response) {
if (response.isEmpty()) {
// ??
throw new IllegalArgumentException("No response for categories");
} else {
Map.Entry<Integer, Object> clicked = response.entrySet().iterator().next();
String category = categoryList.get(clicked.getKey());
String arguments = prefix + " " + category;
CommandEvent event = new CommandEvent(actor, arguments);
CommandManager.getInstance().handleCommand(event);
}
}
});
}
@Override
public void displayCommands(Map<CommandMapping, String> commandMap, String visited, int page, int pageTotal, int effectiveLength) {
gui.setTitle(BBC.HELP_HEADER_SUBCOMMANDS.s());
String baseCommand = prefix;
if (effectiveLength > 0) baseCommand += " " + args.getString(0, effectiveLength - 1);
CommandLocals locals = args.getLocals();
if (!visited.isEmpty()) {
visited = visited + " ";
}
List<String> commands = new ArrayList<>();
for (Map.Entry<CommandMapping, String> cmdEntry : commandMap.entrySet()) {
CommandMapping mapping = cmdEntry.getKey();
String subPrefix = cmdEntry.getValue();
StringBuilder helpCmd = new StringBuilder();
helpCmd.append(prefix);
helpCmd.append(" ");
helpCmd.append(subPrefix);
CommandCallable c = mapping.getCallable();
helpCmd.append(visited);
helpCmd.append(mapping.getPrimaryAlias());
String s2 = mapping.getDescription().getDescription();
if (c.testPermission(locals)) {
// gui.addLabel(s2);
gui.addButton(helpCmd.toString(), null);
commands.add(helpCmd.toString());
}
}
gui.setResponder(new Consumer<Map<Integer, Object>>() {
@Override
public void accept(Map<Integer, Object> response) {
if (response.isEmpty()) {
// ??
throw new IllegalArgumentException("No response for command list: " + prefix);
} else {
Map.Entry<Integer, Object> clicked = response.entrySet().iterator().next();
int index = clicked.getKey();
String cmd = commands.get(index);
CommandEvent event = new CommandEvent(actor, cmd);
CommandManager.getInstance().handleCommand(event);
}
}
});
}
}.run();
gui.display(fp);
}
public static void help(CommandContext args, WorldEdit we, Actor actor, String prefix, CommandCallable callable) {
final int perPage = actor instanceof Player ? 12 : 20; // More pages for console