package com.skcraft.plume.module;

import com.google.common.collect.Sets;
import com.skcraft.plume.common.util.config.Config;
import com.skcraft.plume.common.util.config.InjectConfig;
import com.skcraft.plume.common.util.module.Module;
import com.skcraft.plume.util.Messages;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import net.minecraft.server.MinecraftServer;
import net.minecraftforge.event.CommandEvent;
import ninja.leaping.configurate.objectmapping.Setting;

import java.util.Set;

import static com.skcraft.plume.common.util.SharedLocale.tr;

@Module(name = "command-filter", desc = "Configurable blocking on commands")
public class CommandFilter {

    @InjectConfig("command_filter")
    private Config<CommandConfig> config;

    @SubscribeEvent
    public void onCommand(CommandEvent event) {
        if (config.get().blocked.contains(event.command.getCommandName().toLowerCase())) {
            event.sender.addChatMessage(Messages.error(tr("commandFilter.blocked")));
            event.setCanceled(true);
            return;
        }

        if (config.get().consoleOnly.contains(event.command.getCommandName().toLowerCase())) {
            if (!(event.sender instanceof MinecraftServer)) {
                event.sender.addChatMessage(Messages.error(tr("commandFilter.consoleOnly")));
                event.setCanceled(true);
                return;
            }
        }
    }

    private static class CommandConfig {
        @Setting(comment = "List of commands (in lowercase) that cannot be used")
        public Set<String> blocked = Sets.newHashSet("example_command");

        @Setting(comment = "List of commands (in lowercase) that can only be used from console")
        public Set<String> consoleOnly = Sets.newHashSet("op", "deop");
    }

}

@@ -82,195 +82,591 @@
 com.
-skcraft.plume.common.util.config.Config;%0Aimport com.skcraft.plume.common.util.config.InjectConfig;%0Aimport com.skcraft.plume.common.util.module.Module;%0Aimport com.skcraft.plume.util.Messag
+google.inject.Inject;%0Aimport com.skcraft.plume.common.service.auth.Authorizer;%0Aimport com.skcraft.plume.common.service.auth.Context;%0Aimport com.skcraft.plume.common.util.Environment;%0Aimport com.skcraft.plume.common.util.config.Config;%0Aimport com.skcraft.plume.common.util.config.InjectConfig;%0Aimport com.skcraft.plume.common.util.module.Module;%0Aimport com.skcraft.plume.common.util.service.InjectService;%0Aimport com.skcraft.plume.common.util.service.Service;%0Aimport com.skcraft.plume.util.Contexts;%0Aimport com.skcraft.plume.util.Messages;%0Aimport com.skcraft.plume.util.profile.Profil
 es;%0A
@@ -717,24 +717,73 @@
 cribeEvent;%0A
+import net.minecraft.entity.player.EntityPlayer;%0A
 import net.m
@@ -1145,20 +1145,16 @@
 filter%22)
-%0A   
  private
@@ -1183,16 +1183,120 @@
  config;
+%0A    @InjectService private Service%3CAuthorizer%3E authorizer;%0A    @Inject private Environment environment;
 %0A%0A    @S
@@ -1369,42 +1369,29 @@
     
-if (config.get().blocked.contains(
+String testCommand = 
 even
@@ -1422,32 +1422,88 @@
 ().toLowerCase()
+;%0A%0A        if (config.get().blocked.contains(testCommand
 )) %7B%0A           
@@ -1695,52 +1695,19 @@
 ins(
-event.command.getCommandName().toLowerCase()
+testCommand
 )) %7B
@@ -1947,24 +1947,957 @@
  %7D%0A        %7D
+%0A%0A        if (config.get().restricted.contains(testCommand)) %7B%0A            if (event.sender instanceof EntityPlayer) %7B%0A                Context.Builder builder = new Context.Builder();%0A                environment.update(builder);%0A                String perm = %22plume.commandfilter.restricted.%22 + testCommand;%0A                Contexts.update(builder, (EntityPlayer) event.sender);%0A%0A                if (!authorizer.provide().getSubject(Profiles.fromCommandSender(event.sender)).hasPermission(perm, builder.build())) %7B%0A                    event.sender.addChatMessage(Messages.error(tr(%22commandFilter.noPermission%22)));%0A                    event.setCanceled(true);%0A                    return;%0A                %7D%0A            %7D else if (!(event.sender instanceof MinecraftServer)) %7B%0A                event.sender.addChatMessage(Messages.error(tr(%22commandFilter.noPermission%22)));%0A                event.setCanceled(true);%0A            %7D%0A        %7D
 %0A    %7D%0A%0A    
@@ -3257,16 +3257,214 @@
 %22deop%22);
+%0A%0A        @Setting(comment = %22List of commands (in lowercase) that require the plume.commandfilter.restricted permission%22)%0A        public Set%3CString%3E restricted = Sets.newHashSet(%22example_command%22);
 %0A    %7D%0A%0A

Add support for permission-gated command filtering.