Permalink
Browse files

Filter out commands that the player doesn't have permissions for. Wor…

…karound for a Spigot issue.
  • Loading branch information...
me4502 committed Dec 5, 2018
1 parent b192466 commit be0d21e2a93073881573d9a2ebcb3e49516827d8
@@ -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.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 void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
}
}
@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
*
@@ -183,7 +183,6 @@ public T get(FlagData data) {
return (T) data.get(flag);
}
@SuppressWarnings("unchecked")
public T get(FlagData data, T fallback) {
T value = get(data);
if (value == null) {

0 comments on commit be0d21e

Please sign in to comment.