Few misc command fixes.

Dieser Commit ist enthalten in:
wizjany 2019-06-01 07:41:19 -04:00
Ursprung 9099a17fe5
Commit 1e7c074217
7 geänderte Dateien mit 44 neuen und 28 gelöschten Zeilen

Datei anzeigen

@ -80,10 +80,7 @@ class BukkitCommandInspector implements CommandInspector {
InjectedValueStore store = MapBackedValueStore.create(); InjectedValueStore store = MapBackedValueStore.create();
store.injectValue(Key.of(Actor.class), context -> store.injectValue(Key.of(Actor.class), context ->
Optional.of(plugin.wrapCommandSender(sender))); Optional.of(plugin.wrapCommandSender(sender)));
CommandParameters parameters = NoInputCommandParameters.builder() return mapping.get().getCondition().satisfied(store);
.injectedValues(MemoizingValueAccess.wrap(store))
.build();
return mapping.get().getCondition().satisfied(parameters);
} else { } else {
logger.warn("BukkitCommandInspector doesn't know how about the command '" + command + "'"); logger.warn("BukkitCommandInspector doesn't know how about the command '" + command + "'");
return false; return false;

Datei anzeigen

@ -77,14 +77,11 @@ public class WorldEditListener implements Listener {
InjectedValueStore store = MapBackedValueStore.create(); InjectedValueStore store = MapBackedValueStore.create();
store.injectValue(Key.of(Actor.class), context -> store.injectValue(Key.of(Actor.class), context ->
Optional.of(plugin.wrapCommandSender(event.getPlayer()))); Optional.of(plugin.wrapCommandSender(event.getPlayer())));
CommandParameters parameters = NoInputCommandParameters.builder()
.injectedValues(MemoizingValueAccess.wrap(store))
.build();
CommandManager commandManager = plugin.getWorldEdit().getPlatformManager().getPlatformCommandManager().getCommandManager(); CommandManager commandManager = plugin.getWorldEdit().getPlatformManager().getPlatformCommandManager().getCommandManager();
event.getCommands().removeIf(name -> event.getCommands().removeIf(name ->
// remove if in the manager and not satisfied // remove if in the manager and not satisfied
commandManager.getCommand(name) commandManager.getCommand(name)
.filter(command -> !command.getCondition().satisfied(parameters)) .filter(command -> !command.getCondition().satisfied(store))
.isPresent() .isPresent()
); );
} }

Datei anzeigen

@ -219,15 +219,16 @@ public class GeneralCommands {
aliases = {"/searchitem", "/l", "/search"}, aliases = {"/searchitem", "/l", "/search"},
desc = "Search for an item" desc = "Search for an item"
) )
@CommandPermissions("worldedit.searchitem")
public void searchItem(Actor actor, public void searchItem(Actor actor,
@Arg(desc = "Search query", variable = true)
List<String> query,
@Switch(name = 'b', desc = "Only search for blocks") @Switch(name = 'b', desc = "Only search for blocks")
boolean blocksOnly, boolean blocksOnly,
@Switch(name = 'i', desc = "Only search for items") @Switch(name = 'i', desc = "Only search for items")
boolean itemsOnly, boolean itemsOnly,
@ArgFlag(name = 'p', desc = "Page of results to return", def = "1") @ArgFlag(name = 'p', desc = "Page of results to return", def = "1")
int page) { int page,
@Arg(desc = "Search query", variable = true)
List<String> query) {
String search = String.join(" ", query); String search = String.join(" ", query);
if (search.length() <= 2) { if (search.length() <= 2) {
actor.printError("Enter a longer search string (len > 2)."); actor.printError("Enter a longer search string (len > 2).");

Datei anzeigen

@ -21,7 +21,6 @@ package com.sk89q.worldedit.command.util;
import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Actor;
import org.enginehub.piston.Command; import org.enginehub.piston.Command;
import org.enginehub.piston.CommandParameters;
import org.enginehub.piston.inject.InjectedValueAccess; import org.enginehub.piston.inject.InjectedValueAccess;
import org.enginehub.piston.inject.Key; import org.enginehub.piston.inject.Key;

Datei anzeigen

@ -1,3 +1,22 @@
/*
* 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.util; package com.sk89q.worldedit.command.util;
import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEdit;

Datei anzeigen

@ -125,6 +125,7 @@ import org.slf4j.LoggerFactory;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.function.Consumer; import java.util.function.Consumer;
@ -583,6 +584,10 @@ public final class PlatformCommandManager {
original.getEnd() + 1 original.getEnd() + 1
); );
}).collect(Collectors.toList())); }).collect(Collectors.toList()));
} catch (ConditionFailedException e) {
if (e.getCondition() instanceof PermissionCondition) {
event.setSuggestions(new ArrayList<>());
}
} catch (CommandException e) { } catch (CommandException e) {
event.getActor().printError(e.getMessage()); event.getActor().printError(e.getMessage());
} }

Datei anzeigen

@ -31,17 +31,20 @@ import com.mojang.brigadier.suggestion.Suggestion;
import com.mojang.brigadier.suggestion.Suggestions; import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder; import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.command.util.PermissionCondition;
import com.sk89q.worldedit.event.platform.CommandSuggestionEvent; import com.sk89q.worldedit.event.platform.CommandSuggestionEvent;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.internal.util.Substring; import com.sk89q.worldedit.internal.util.Substring;
import net.minecraft.command.CommandSource; import net.minecraft.command.CommandSource;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.EntityPlayerMP;
import org.enginehub.piston.inject.InjectedValueStore;
import org.enginehub.piston.inject.Key;
import org.enginehub.piston.inject.MapBackedValueStore;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Optional;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.function.Predicate; import java.util.function.Predicate;
import java.util.stream.Stream;
import static net.minecraft.command.Commands.argument; import static net.minecraft.command.Commands.argument;
import static net.minecraft.command.Commands.literal; import static net.minecraft.command.Commands.literal;
@ -58,8 +61,7 @@ public final class CommandWrapper {
.then(argument("args", StringArgumentType.greedyString()) .then(argument("args", StringArgumentType.greedyString())
.suggests(CommandWrapper::suggest) .suggests(CommandWrapper::suggest)
.executes(FAKE_COMMAND)); .executes(FAKE_COMMAND));
if (command.getCondition().as(PermissionCondition.class) if (command.getCondition() != org.enginehub.piston.Command.Condition.TRUE) {
.filter(p -> p.getPermissions().size() > 0).isPresent()) {
base.requires(requirementsFor(command)); base.requires(requirementsFor(command));
} }
dispatcher.register(base); dispatcher.register(base);
@ -67,8 +69,7 @@ public final class CommandWrapper {
} }
public static final Command<CommandSource> FAKE_COMMAND = ctx -> { public static final Command<CommandSource> FAKE_COMMAND = ctx -> {
EntityPlayerMP player = ctx.getSource().asPlayer(); if (ctx.getSource().getWorld().isRemote) {
if (player.world.isRemote()) {
return 0; return 0;
} }
return 1; return 1;
@ -76,15 +77,12 @@ public final class CommandWrapper {
private static Predicate<CommandSource> requirementsFor(org.enginehub.piston.Command mapping) { private static Predicate<CommandSource> requirementsFor(org.enginehub.piston.Command mapping) {
return ctx -> { return ctx -> {
ForgePermissionsProvider permsProvider = ForgeWorldEdit.inst.getPermissionsProvider(); final Entity entity = ctx.getEntity();
return ctx.getEntity() instanceof EntityPlayerMP && if (!(entity instanceof EntityPlayerMP)) return true;
mapping.getCondition().as(PermissionCondition.class) final Actor actor = ForgeAdapter.adaptPlayer(((EntityPlayerMP) entity));
.map(PermissionCondition::getPermissions) InjectedValueStore store = MapBackedValueStore.create();
.map(Set::stream) store.injectValue(Key.of(Actor.class), context -> Optional.of(actor));
.orElseGet(Stream::empty) return mapping.getCondition().satisfied(store);
.allMatch(perm -> permsProvider.hasPermission(
(EntityPlayerMP) ctx.getEntity(), perm
));
}; };
} }