Merge branch 'master' into feat/nested-fabric-api

This commit is contained in:
wizjany 2019-09-28 19:43:06 -04:00 committed by GitHub
commit 7f4166157e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 193 additions and 20 deletions

View File

@ -50,7 +50,7 @@ dependencies {
implementation("net.ltgt.apt-idea:net.ltgt.apt-idea.gradle.plugin:0.21") implementation("net.ltgt.apt-idea:net.ltgt.apt-idea.gradle.plugin:0.21")
implementation("org.jfrog.buildinfo:build-info-extractor-gradle:4.9.7") implementation("org.jfrog.buildinfo:build-info-extractor-gradle:4.9.7")
implementation("gradle.plugin.org.spongepowered:spongegradle:0.9.0") implementation("gradle.plugin.org.spongepowered:spongegradle:0.9.0")
implementation("net.minecraftforge.gradle:ForgeGradle:3.0.141") implementation("net.minecraftforge.gradle:ForgeGradle:3.0.143")
implementation("net.fabricmc:fabric-loom:$loomVersion") implementation("net.fabricmc:fabric-loom:$loomVersion")
implementation("net.fabricmc:sponge-mixin:$mixinVersion") implementation("net.fabricmc:sponge-mixin:$mixinVersion")
} }

View File

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.5.1-all.zip distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists

4
gradlew vendored
View File

@ -125,8 +125,8 @@ if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi fi
# For Cygwin, switch paths to Windows format before running java # For Cygwin or MSYS, switch paths to Windows format before running java
if $cygwin ; then if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"` APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"` JAVACMD=`cygpath --unix "$JAVACMD"`

View File

@ -521,6 +521,14 @@ public class LocalSession {
return selector.getPrimaryPosition(); return selector.getPrimaryPosition();
} }
public void setPlaceAtPos1(boolean placeAtPos1) {
this.placeAtPos1 = placeAtPos1;
}
public boolean isPlaceAtPos1() {
return placeAtPos1;
}
/** /**
* Toggle placement position. * Toggle placement position.
* *

View File

@ -82,6 +82,15 @@ public class BrushCommands {
this.worldEdit = worldEdit; this.worldEdit = worldEdit;
} }
@Command(
name = "none",
aliases = "unbind",
desc = "Unbind a bound brush from your current item"
)
void none(Player player, LocalSession session) throws WorldEditException {
ToolCommands.setToolNone(player, session, "Brush");
}
@Command( @Command(
name = "sphere", name = "sphere",
aliases = { "s" }, aliases = { "s" },

View File

@ -19,6 +19,7 @@
package com.sk89q.worldedit.command; package com.sk89q.worldedit.command;
import com.google.common.collect.Collections2;
import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEdit;
@ -29,6 +30,7 @@ import com.sk89q.worldedit.command.tool.BlockReplacer;
import com.sk89q.worldedit.command.tool.DistanceWand; import com.sk89q.worldedit.command.tool.DistanceWand;
import com.sk89q.worldedit.command.tool.FloatingTreeRemover; import com.sk89q.worldedit.command.tool.FloatingTreeRemover;
import com.sk89q.worldedit.command.tool.FloodFillTool; import com.sk89q.worldedit.command.tool.FloodFillTool;
import com.sk89q.worldedit.command.tool.InvalidToolBindException;
import com.sk89q.worldedit.command.tool.LongRangeBuildTool; import com.sk89q.worldedit.command.tool.LongRangeBuildTool;
import com.sk89q.worldedit.command.tool.NavigationWand; import com.sk89q.worldedit.command.tool.NavigationWand;
import com.sk89q.worldedit.command.tool.QueryTool; import com.sk89q.worldedit.command.tool.QueryTool;
@ -38,16 +40,94 @@ import com.sk89q.worldedit.command.util.CommandPermissions;
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator; import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.internal.command.CommandRegistrationHandler;
import com.sk89q.worldedit.internal.command.CommandUtil;
import com.sk89q.worldedit.util.HandSide; import com.sk89q.worldedit.util.HandSide;
import com.sk89q.worldedit.util.TreeGenerator; import com.sk89q.worldedit.util.TreeGenerator;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.item.ItemType; import com.sk89q.worldedit.world.item.ItemType;
import org.enginehub.piston.CommandManager;
import org.enginehub.piston.CommandManagerService;
import org.enginehub.piston.CommandMetadata;
import org.enginehub.piston.CommandParameters;
import org.enginehub.piston.annotation.Command; import org.enginehub.piston.annotation.Command;
import org.enginehub.piston.annotation.CommandContainer; import org.enginehub.piston.annotation.CommandContainer;
import org.enginehub.piston.annotation.param.Arg; import org.enginehub.piston.annotation.param.Arg;
import org.enginehub.piston.part.SubCommandPart;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
@CommandContainer(superTypes = CommandPermissionsConditionGenerator.Registration.class) @CommandContainer(superTypes = CommandPermissionsConditionGenerator.Registration.class)
public class ToolCommands { public class ToolCommands {
public static void register(CommandRegistrationHandler registration,
CommandManager commandManager,
CommandManagerService commandManagerService,
WorldEdit worldEdit) {
// Collect the tool commands
CommandManager collect = commandManagerService.newCommandManager();
registration.register(
collect,
ToolCommandsRegistration.builder(),
new ToolCommands(worldEdit)
);
// Register deprecated global commands
Set<org.enginehub.piston.Command> commands = collect.getAllCommands()
.collect(Collectors.toSet());
for (org.enginehub.piston.Command command : commands) {
if (command.getAliases().contains("unbind")) {
// Don't register new /tool unbind alias
command = command.toBuilder().aliases(
Collections2.filter(command.getAliases(), alias -> !"unbind".equals(alias))
).build();
}
commandManager.register(CommandUtil.deprecate(
command, "Using global tool names is deprecated " +
"and will be removed in WorldEdit 8", ToolCommands::asNonGlobal
));
}
// Remove aliases with / in them, since it doesn't make sense for sub-commands.
Set<org.enginehub.piston.Command> nonGlobalCommands = commands.stream()
.map(command ->
command.toBuilder().aliases(
Collections2.filter(command.getAliases(), alias -> !alias.startsWith("/"))
).build()
)
.collect(Collectors.toSet());
commandManager.register("tool", command -> {
command.addPart(SubCommandPart.builder(
TranslatableComponent.of("tool"),
TextComponent.of("The tool to bind")
)
.withCommands(nonGlobalCommands)
.required()
.build());
command.description(TextComponent.of("Binds a tool to the item in your hand"));
});
}
private static String asNonGlobal(org.enginehub.piston.Command oldCommand,
CommandParameters oldParameters) {
String name = Optional.ofNullable(oldParameters.getMetadata())
.map(CommandMetadata::getCalledName)
.filter(n -> !n.startsWith("/"))
.orElseGet(oldCommand::getName);
return "/tool " + name;
}
static void setToolNone(Player player, LocalSession session, String type)
throws InvalidToolBindException {
session.setTool(player.getItemInHand(HandSide.MAIN_HAND).getType(), null);
player.print(type + " unbound from your current item.");
}
private final WorldEdit we; private final WorldEdit we;
public ToolCommands(WorldEdit we) { public ToolCommands(WorldEdit we) {
@ -56,17 +136,16 @@ public class ToolCommands {
@Command( @Command(
name = "none", name = "none",
aliases = "unbind",
desc = "Unbind a bound tool from your current item" desc = "Unbind a bound tool from your current item"
) )
public void none(Player player, LocalSession session) throws WorldEditException { public void none(Player player, LocalSession session) throws WorldEditException {
setToolNone(player, session, "Tool");
session.setTool(player.getItemInHand(HandSide.MAIN_HAND).getType(), null);
player.print("Tool unbound from your current item.");
} }
@Command( @Command(
name = "/selwand", name = "selwand",
aliases = "selwand", aliases = "/selwand",
desc = "Selection wand tool" desc = "Selection wand tool"
) )
@CommandPermissions("worldedit.setwand") @CommandPermissions("worldedit.setwand")
@ -78,8 +157,8 @@ public class ToolCommands {
} }
@Command( @Command(
name = "/navwand", name = "navwand",
aliases = "navwand", aliases = "/navwand",
desc = "Navigation wand tool" desc = "Navigation wand tool"
) )
@CommandPermissions("worldedit.setwand") @CommandPermissions("worldedit.setwand")

View File

@ -19,8 +19,6 @@
package com.sk89q.worldedit.extension.platform; package com.sk89q.worldedit.extension.platform;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.reflect.TypeToken; import com.google.common.reflect.TypeToken;
@ -64,7 +62,6 @@ import com.sk89q.worldedit.command.SnapshotUtilCommandsRegistration;
import com.sk89q.worldedit.command.SuperPickaxeCommands; import com.sk89q.worldedit.command.SuperPickaxeCommands;
import com.sk89q.worldedit.command.SuperPickaxeCommandsRegistration; import com.sk89q.worldedit.command.SuperPickaxeCommandsRegistration;
import com.sk89q.worldedit.command.ToolCommands; import com.sk89q.worldedit.command.ToolCommands;
import com.sk89q.worldedit.command.ToolCommandsRegistration;
import com.sk89q.worldedit.command.ToolUtilCommands; import com.sk89q.worldedit.command.ToolUtilCommands;
import com.sk89q.worldedit.command.ToolUtilCommandsRegistration; import com.sk89q.worldedit.command.ToolUtilCommandsRegistration;
import com.sk89q.worldedit.command.UtilityCommands; import com.sk89q.worldedit.command.UtilityCommands;
@ -141,6 +138,8 @@ import java.util.regex.Pattern;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import static com.google.common.base.Preconditions.checkNotNull;
/** /**
* Handles the registration and invocation of commands. * Handles the registration and invocation of commands.
* *
@ -399,11 +398,7 @@ public final class PlatformCommandManager {
SnapshotUtilCommandsRegistration.builder(), SnapshotUtilCommandsRegistration.builder(),
new SnapshotUtilCommands(worldEdit) new SnapshotUtilCommands(worldEdit)
); );
this.registration.register( ToolCommands.register(registration, commandManager, commandManagerService, worldEdit);
commandManager,
ToolCommandsRegistration.builder(),
new ToolCommands(worldEdit)
);
this.registration.register( this.registration.register(
commandManager, commandManager,
ToolUtilCommandsRegistration.builder(), ToolUtilCommandsRegistration.builder(),

View File

@ -21,11 +21,17 @@ package com.sk89q.worldedit.internal.command;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.platform.PlatformCommandManager; import com.sk89q.worldedit.extension.platform.PlatformCommandManager;
import com.sk89q.worldedit.internal.util.Substring; import com.sk89q.worldedit.internal.util.Substring;
import com.sk89q.worldedit.util.formatting.text.Component; import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.TextComponent; import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.util.formatting.text.event.ClickEvent;
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
import com.sk89q.worldedit.util.formatting.text.format.TextDecoration;
import org.enginehub.piston.Command; import org.enginehub.piston.Command;
import org.enginehub.piston.CommandParameters;
import org.enginehub.piston.NoInputCommandParameters;
import org.enginehub.piston.exception.CommandException; import org.enginehub.piston.exception.CommandException;
import org.enginehub.piston.inject.InjectedValueAccess; import org.enginehub.piston.inject.InjectedValueAccess;
import org.enginehub.piston.inject.Key; import org.enginehub.piston.inject.Key;
@ -43,6 +49,63 @@ import static java.util.stream.Collectors.toList;
public class CommandUtil { public class CommandUtil {
private static Component makeDeprecatedFooter(Component newCommand) {
return TextComponent.builder("This command is deprecated. Use ", TextColor.GOLD)
.decoration(TextDecoration.ITALIC, true)
.append(newCommand)
.append(" instead.")
.build();
}
public interface NewCommandGenerator {
String newCommand(Command oldCommand, CommandParameters oldParameters);
}
public static Command deprecate(Command command, String reason,
NewCommandGenerator newCommandGenerator) {
Component deprecatedWarning = makeDeprecatedFooter(
newCommandSuggestion(newCommandGenerator,
NoInputCommandParameters.builder().build(),
command)
);
return command.toBuilder()
.action(parameters ->
deprecatedCommandWarning(parameters, command, reason, newCommandGenerator))
.footer(command.getFooter()
.map(existingFooter -> existingFooter
.append(TextComponent.newline()).append(deprecatedWarning))
.orElse(deprecatedWarning))
.build();
}
private static int deprecatedCommandWarning(
CommandParameters parameters,
Command command,
String reason,
NewCommandGenerator generator
) throws Exception {
parameters.injectedValue(Key.of(Actor.class))
.ifPresent(actor -> {
Component suggestion = newCommandSuggestion(generator, parameters, command);
actor.print(TextComponent.of(reason + ". Please use ", TextColor.GOLD)
.append(suggestion)
.append(TextComponent.of(" instead."))
);
});
return command.getAction().run(parameters);
}
private static Component newCommandSuggestion(NewCommandGenerator generator,
CommandParameters parameters,
Command command) {
String suggestedCommand = generator.newCommand(command, parameters);
return TextComponent.of(suggestedCommand)
.decoration(TextDecoration.UNDERLINED, true)
.clickEvent(ClickEvent.suggestCommand(suggestedCommand));
}
public static Map<String, Command> getSubCommands(Command currentCommand) { public static Map<String, Command> getSubCommands(Command currentCommand) {
return currentCommand.getParts().stream() return currentCommand.getParts().stream()
.filter(p -> p instanceof SubCommandPart) .filter(p -> p instanceof SubCommandPart)

View File

@ -34,6 +34,7 @@ import com.sk89q.worldedit.command.tool.SelectionWand;
import com.sk89q.worldedit.command.tool.Tool; import com.sk89q.worldedit.command.tool.Tool;
import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.event.platform.ConfigurationLoadEvent; import com.sk89q.worldedit.event.platform.ConfigurationLoadEvent;
import com.sk89q.worldedit.extension.platform.Locatable;
import com.sk89q.worldedit.session.request.Request; import com.sk89q.worldedit.session.request.Request;
import com.sk89q.worldedit.session.storage.JsonFileSessionStore; import com.sk89q.worldedit.session.storage.JsonFileSessionStore;
import com.sk89q.worldedit.session.storage.SessionStore; import com.sk89q.worldedit.session.storage.SessionStore;
@ -199,6 +200,11 @@ public class SessionManager {
&& (owner.hasPermission("worldedit.inventory.unrestricted") && (owner.hasPermission("worldedit.inventory.unrestricted")
|| (config.useInventoryCreativeOverride && (!(owner instanceof Player) || ((Player) owner).getGameMode() == GameModes.CREATIVE))))); || (config.useInventoryCreativeOverride && (!(owner instanceof Player) || ((Player) owner).getGameMode() == GameModes.CREATIVE)))));
// Force non-locatable actors to use placeAtPos1
if (!(owner instanceof Locatable)) {
session.setPlaceAtPos1(true);
}
return session; return session;
} }

View File

@ -88,7 +88,15 @@ public class JsonFileSessionStore implements SessionStore {
try (Closer closer = Closer.create()) { try (Closer closer = Closer.create()) {
FileReader fr = closer.register(new FileReader(file)); FileReader fr = closer.register(new FileReader(file));
BufferedReader br = closer.register(new BufferedReader(fr)); BufferedReader br = closer.register(new BufferedReader(fr));
return gson.fromJson(br, LocalSession.class); LocalSession session = gson.fromJson(br, LocalSession.class);
if (session == null) {
log.warn("Loaded a null session from {}, creating new session", file);
if (!file.delete()) {
log.warn("Failed to delete corrupted session {}", file);
}
session = new LocalSession();
}
return session;
} catch (JsonParseException e) { } catch (JsonParseException e) {
throw new IOException(e); throw new IOException(e);
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
@ -98,6 +106,7 @@ public class JsonFileSessionStore implements SessionStore {
@Override @Override
public void save(UUID id, LocalSession session) throws IOException { public void save(UUID id, LocalSession session) throws IOException {
checkNotNull(session);
File finalFile = getPath(id); File finalFile = getPath(id);
File tempFile = new File(finalFile.getParentFile(), finalFile.getName() + ".tmp"); File tempFile = new File(finalFile.getParentFile(), finalFile.getName() + ".tmp");
@ -115,6 +124,10 @@ public class JsonFileSessionStore implements SessionStore {
} }
} }
if (tempFile.length() == 0) {
throw new IllegalStateException("Gson wrote zero bytes");
}
if (!tempFile.renameTo(finalFile)) { if (!tempFile.renameTo(finalFile)) {
log.warn("Failed to rename temporary session file to " + finalFile.getPath()); log.warn("Failed to rename temporary session file to " + finalFile.getPath());
} }