Filter out commands that the player doesn't have permissions for. Workaround for a Spigot issue.

This commit is contained in:
Matthew Miller 2018-12-05 16:32:20 +10:00 committed by IronApollo
parent e9fbde3ac8
commit b276907dcd
2 changed files with 18 additions and 1 deletions

View File

@ -21,10 +21,13 @@
package com.sk89q.worldedit.bukkit;
import com.sk89q.minecraft.util.commands.CommandLocals;
import com.sk89q.util.StringUtil;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.util.command.CommandMapping;
import com.sk89q.worldedit.world.World;
import org.bukkit.block.Block;
import org.bukkit.event.Event.Result;
@ -33,10 +36,14 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerCommandSendEvent;
import org.bukkit.event.player.PlayerGameModeChangeEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.EquipmentSlot;
import java.util.Set;
import java.util.stream.Collectors;
/**
* Handles all events thrown in relation to a Player
*/
@ -99,6 +106,17 @@ public class WorldEditListener implements Listener {
}
}
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPlayerCommand(PlayerCommandSendEvent event) {
CommandLocals locals = new CommandLocals();
locals.put(Actor.class, plugin.wrapCommandSender(event.getPlayer()));
Set<String> toRemove = plugin.getWorldEdit().getPlatformManager().getCommandManager().getDispatcher().getCommands().stream()
.filter(commandMapping -> !commandMapping.getCallable().testPermission(locals))
.map(CommandMapping::getPrimaryAlias)
.collect(Collectors.toSet());
event.getCommands().removeIf(toRemove::contains);
}
/**
* Called when a player interacts
*

View File

@ -183,7 +183,6 @@ public class FlagParser implements CommandExecutor<FlagData> {
return (T) data.get(flag);
}
@SuppressWarnings("unchecked")
public T get(FlagData data, T fallback) {
T value = get(data);
if (value == null) {