package com.forgeessentials.commands.player;

import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraftforge.permissions.PermissionsManager.RegisteredPermValue;

import com.forgeessentials.api.APIRegistry;
import com.forgeessentials.api.UserIdent;
import com.forgeessentials.commands.util.FEcmdModuleCommands;
import com.forgeessentials.core.misc.Translator;
import com.forgeessentials.util.OutputHandler;
import com.forgeessentials.util.PlayerInfo;
import com.forgeessentials.util.ServerUtil;

public class CommandAFK extends FEcmdModuleCommands
{

    public static final String PERM = "fe.commands.afk";

    public static final String PERM_ANNOUNCE = PERM + ".announce";

    public static final String PERM_WARMUP = PERM + ".warmup";

    public static final String PERM_AUTOTIME = PERM + ".autotime";

    public static final String PERM_AUTOKICK = PERM + ".autokick";

    @Override
    public String getCommandName()
    {
        return "afk";
    }

    @Override
    public String getCommandUsage(ICommandSender sender)
    {
        return "/afk: Mark yourself as away.";
    }

    @Override
    public RegisteredPermValue getDefaultPermission()
    {
        return RegisteredPermValue.TRUE;
    }

    @Override
    public void registerExtraPermissions()
    {
        APIRegistry.perms.registerPermission(PERM_ANNOUNCE, RegisteredPermValue.TRUE);
        APIRegistry.perms.registerPermissionProperty(PERM_WARMUP, "10", "Time a player needs to wait before he can go afk with /afk");
        APIRegistry.perms.registerPermissionProperty(PERM_AUTOTIME, "480", "Auto afk time in seconds. Set to 0 to disable.");
        APIRegistry.perms.registerPermission(PERM_AUTOKICK, RegisteredPermValue.FALSE, "Automatically kick a player, when he is AFK");
    }

    @Override
    public boolean canConsoleUseCommand()
    {
        return false;
    }

    @Override
    public void processCommandPlayer(EntityPlayerMP sender, String[] args)
    {
        UserIdent ident = UserIdent.get(sender);
        int autoTime = ServerUtil.parseIntDefault(ident.getPermissionProperty(CommandAFK.PERM_AUTOTIME), 60 * 2);
        int warmup = ServerUtil.parseIntDefault(ident.getPermissionProperty(PERM_WARMUP), 0);
        PlayerInfo.get(sender).setActive(autoTime * 1000 - warmup * 1000);
        OutputHandler.chatConfirmation(sender, Translator.format("Stand still for %d seconds.", warmup));
    }

}

@@ -39,16 +39,82 @@
 layer;%0A%0A
+import com.forgeessentials.api.permissions.PermissionEvent.Group;%0A
 import n
@@ -2119,16 +2119,1132 @@
 ender);%0A
+%0A        // expected syntax: /afk timeout %3Cgroup%7Cplayer%3E %3Ctimeout%3E%0A        // to set custom afk timeout for yourself, replace %3Cplayer%3E with your own username%0A        if (args%5B0%5D.equalsIgnoreCase(%22timeout%22))%0A        %7B%0A            UserIdent applyTo = UserIdent.get(args%5B1%5D, true);%0A            if (applyTo != null)%0A            %7B%0A                APIRegistry.perms.setPlayerPermissionProperty(applyTo, PERM_AUTOTIME, args%5B2%5D);%0A            %7D%0A            else%0A            %7B%0A                APIRegistry.perms.setGroupPermissionProperty(args%5B1%5D, PERM_AUTOTIME, args%5B2%5D);%0A            %7D%0A        %7D%0A        // expected syntax: /afk timeout %3Cgroup%7Cplayer%3E %5Btrue%7Cfalse%7D%0A        else if (args%5B0%5D.equalsIgnoreCase(%22autokick%22))%0A        %7B%0A            UserIdent applyTo = UserIdent.get(args%5B1%5D, true);%0A            if (applyTo != null)%0A            %7B%0A                APIRegistry.perms.setPlayerPermissionProperty(applyTo, PERM_AUTOKICK, args%5B2%5D);%0A            %7D%0A            else%0A            %7B%0A                APIRegistry.perms.setGroupPermissionProperty(args%5B1%5D, PERM_AUTOKICK, args%5B2%5D);%0A            %7D%0A        %7D%0A        else%0A        %7B%0A    
         
@@ -3353,24 +3353,28 @@
 2);%0A        
+    
 int warmup =
@@ -3455,16 +3455,20 @@
         
+ 
+   
 PlayerIn
@@ -3522,24 +3522,28 @@
 up * 1000);%0A
+    
         Outp
@@ -3636,16 +3636,26 @@
 rmup));%0A
+        %7D%0A
     %7D%0A%0A%7D

Make setting AFK timeout easier - closes #1563