mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-22 17:27:38 +00:00
Few misc command fixes.
This commit is contained in:
parent
9099a17fe5
commit
1e7c074217
@ -80,10 +80,7 @@ class BukkitCommandInspector implements CommandInspector {
|
||||
InjectedValueStore store = MapBackedValueStore.create();
|
||||
store.injectValue(Key.of(Actor.class), context ->
|
||||
Optional.of(plugin.wrapCommandSender(sender)));
|
||||
CommandParameters parameters = NoInputCommandParameters.builder()
|
||||
.injectedValues(MemoizingValueAccess.wrap(store))
|
||||
.build();
|
||||
return mapping.get().getCondition().satisfied(parameters);
|
||||
return mapping.get().getCondition().satisfied(store);
|
||||
} else {
|
||||
logger.warn("BukkitCommandInspector doesn't know how about the command '" + command + "'");
|
||||
return false;
|
||||
|
@ -77,14 +77,11 @@ public class WorldEditListener implements Listener {
|
||||
InjectedValueStore store = MapBackedValueStore.create();
|
||||
store.injectValue(Key.of(Actor.class), context ->
|
||||
Optional.of(plugin.wrapCommandSender(event.getPlayer())));
|
||||
CommandParameters parameters = NoInputCommandParameters.builder()
|
||||
.injectedValues(MemoizingValueAccess.wrap(store))
|
||||
.build();
|
||||
CommandManager commandManager = plugin.getWorldEdit().getPlatformManager().getPlatformCommandManager().getCommandManager();
|
||||
event.getCommands().removeIf(name ->
|
||||
// remove if in the manager and not satisfied
|
||||
commandManager.getCommand(name)
|
||||
.filter(command -> !command.getCondition().satisfied(parameters))
|
||||
.filter(command -> !command.getCondition().satisfied(store))
|
||||
.isPresent()
|
||||
);
|
||||
}
|
||||
|
@ -219,15 +219,16 @@ public class GeneralCommands {
|
||||
aliases = {"/searchitem", "/l", "/search"},
|
||||
desc = "Search for an item"
|
||||
)
|
||||
@CommandPermissions("worldedit.searchitem")
|
||||
public void searchItem(Actor actor,
|
||||
@Arg(desc = "Search query", variable = true)
|
||||
List<String> query,
|
||||
@Switch(name = 'b', desc = "Only search for blocks")
|
||||
boolean blocksOnly,
|
||||
@Switch(name = 'i', desc = "Only search for items")
|
||||
boolean itemsOnly,
|
||||
@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);
|
||||
if (search.length() <= 2) {
|
||||
actor.printError("Enter a longer search string (len > 2).");
|
||||
|
@ -21,7 +21,6 @@ package com.sk89q.worldedit.command.util;
|
||||
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import org.enginehub.piston.Command;
|
||||
import org.enginehub.piston.CommandParameters;
|
||||
import org.enginehub.piston.inject.InjectedValueAccess;
|
||||
import org.enginehub.piston.inject.Key;
|
||||
|
||||
|
@ -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;
|
||||
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
|
@ -125,6 +125,7 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
@ -583,6 +584,10 @@ public final class PlatformCommandManager {
|
||||
original.getEnd() + 1
|
||||
);
|
||||
}).collect(Collectors.toList()));
|
||||
} catch (ConditionFailedException e) {
|
||||
if (e.getCondition() instanceof PermissionCondition) {
|
||||
event.setSuggestions(new ArrayList<>());
|
||||
}
|
||||
} catch (CommandException e) {
|
||||
event.getActor().printError(e.getMessage());
|
||||
}
|
||||
|
@ -31,17 +31,20 @@ import com.mojang.brigadier.suggestion.Suggestion;
|
||||
import com.mojang.brigadier.suggestion.Suggestions;
|
||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.command.util.PermissionCondition;
|
||||
import com.sk89q.worldedit.event.platform.CommandSuggestionEvent;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.internal.util.Substring;
|
||||
import net.minecraft.command.CommandSource;
|
||||
import net.minecraft.entity.Entity;
|
||||
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.Set;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static net.minecraft.command.Commands.argument;
|
||||
import static net.minecraft.command.Commands.literal;
|
||||
@ -58,8 +61,7 @@ public final class CommandWrapper {
|
||||
.then(argument("args", StringArgumentType.greedyString())
|
||||
.suggests(CommandWrapper::suggest)
|
||||
.executes(FAKE_COMMAND));
|
||||
if (command.getCondition().as(PermissionCondition.class)
|
||||
.filter(p -> p.getPermissions().size() > 0).isPresent()) {
|
||||
if (command.getCondition() != org.enginehub.piston.Command.Condition.TRUE) {
|
||||
base.requires(requirementsFor(command));
|
||||
}
|
||||
dispatcher.register(base);
|
||||
@ -67,8 +69,7 @@ public final class CommandWrapper {
|
||||
}
|
||||
|
||||
public static final Command<CommandSource> FAKE_COMMAND = ctx -> {
|
||||
EntityPlayerMP player = ctx.getSource().asPlayer();
|
||||
if (player.world.isRemote()) {
|
||||
if (ctx.getSource().getWorld().isRemote) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
@ -76,15 +77,12 @@ public final class CommandWrapper {
|
||||
|
||||
private static Predicate<CommandSource> requirementsFor(org.enginehub.piston.Command mapping) {
|
||||
return ctx -> {
|
||||
ForgePermissionsProvider permsProvider = ForgeWorldEdit.inst.getPermissionsProvider();
|
||||
return ctx.getEntity() instanceof EntityPlayerMP &&
|
||||
mapping.getCondition().as(PermissionCondition.class)
|
||||
.map(PermissionCondition::getPermissions)
|
||||
.map(Set::stream)
|
||||
.orElseGet(Stream::empty)
|
||||
.allMatch(perm -> permsProvider.hasPermission(
|
||||
(EntityPlayerMP) ctx.getEntity(), perm
|
||||
));
|
||||
final Entity entity = ctx.getEntity();
|
||||
if (!(entity instanceof EntityPlayerMP)) return true;
|
||||
final Actor actor = ForgeAdapter.adaptPlayer(((EntityPlayerMP) entity));
|
||||
InjectedValueStore store = MapBackedValueStore.create();
|
||||
store.injectValue(Key.of(Actor.class), context -> Optional.of(actor));
|
||||
return mapping.getCondition().satisfied(store);
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user