    001    package net.minecraft.command;
    002
    003    import java.util.Collections;
    004    import java.util.HashMap;
    005    import java.util.List;
    006    import java.util.Map;
    007    import java.util.regex.Matcher;
    008    import java.util.regex.Pattern;
    009    import net.minecraft.entity.player.EntityPlayerMP;
    010    import net.minecraft.server.MinecraftServer;
    011    import net.minecraft.util.ChunkCoordinates;
    012    import net.minecraft.util.MathHelper;
    013    import net.minecraft.world.EnumGameType;
    014
    015    public class PlayerSelector
    016    {
    017        private static final Pattern field_82389_a = Pattern.compile("^@([parf])(?:\\[([\\w=,-]*)\\])?$");
    018        private static final Pattern field_82387_b = Pattern.compile("\\G(-?\\w*)(?:$|,)");
    019        private static final Pattern field_82388_c = Pattern.compile("\\G(\\w{1,2})=(-?\\w+)(?:$|,)");
    020
    021        public static EntityPlayerMP func_82386_a(ICommandSender par0ICommandSender, String par1Str)
    022        {
    023            EntityPlayerMP[] var2 = func_82380_c(par0ICommandSender, par1Str);
    024            return var2 != null && var2.length == 1 ? var2[0] : null;
    025        }
    026
    027        public static String func_82385_b(ICommandSender par0ICommandSender, String par1Str)
    028        {
    029            EntityPlayerMP[] var2 = func_82380_c(par0ICommandSender, par1Str);
    030
    031            if (var2 != null && var2.length != 0)
    032            {
    033                String[] var3 = new String[var2.length];
    034
    035                for (int var4 = 0; var4 < var3.length; ++var4)
    036                {
    037                    var3[var4] = var2[var4].getEntityName();
    038                }
    039
    040                return CommandBase.joinNiceString(var3);
    041            }
    042            else
    043            {
    044                return null;
    045            }
    046        }
    047
    048        public static EntityPlayerMP[] func_82380_c(ICommandSender par0ICommandSender, String par1Str)
    049        {
    050            Matcher var2 = field_82389_a.matcher(par1Str);
    051
    052            if (var2.matches())
    053            {
    054                Map var3 = func_82381_h(var2.group(2));
    055                String var4 = var2.group(1);
    056                int var5 = func_82384_c(var4);
    057                int var6 = func_82379_d(var4);
    058                int var7 = func_82375_f(var4);
    059                int var8 = func_82376_e(var4);
    060                int var9 = func_82382_g(var4);
    061                int var10 = EnumGameType.NOT_SET.getID();
    062                ChunkCoordinates var11 = par0ICommandSender.getPlayerCoordinates();
    063
    064                if (var3.containsKey("rm"))
    065                {
    066                    var5 = MathHelper.parseIntWithDefault((String)var3.get("rm"), var5);
    067                }
    068
    069                if (var3.containsKey("r"))
    070                {
    071                    var6 = MathHelper.parseIntWithDefault((String)var3.get("r"), var6);
    072                }
    073
    074                if (var3.containsKey("lm"))
    075                {
    076                    var7 = MathHelper.parseIntWithDefault((String)var3.get("lm"), var7);
    077                }
    078
    079                if (var3.containsKey("l"))
    080                {
    081                    var8 = MathHelper.parseIntWithDefault((String)var3.get("l"), var8);
    082                }
    083
    084                if (var3.containsKey("x"))
    085                {
    086                    var11.posX = MathHelper.parseIntWithDefault((String)var3.get("x"), var11.posX);
    087                }
    088
    089                if (var3.containsKey("y"))
    090                {
    091                    var11.posY = MathHelper.parseIntWithDefault((String)var3.get("y"), var11.posY);
    092                }
    093
    094                if (var3.containsKey("z"))
    095                {
    096                    var11.posZ = MathHelper.parseIntWithDefault((String)var3.get("z"), var11.posZ);
    097                }
    098
    099                if (var3.containsKey("m"))
    100                {
    101                    var10 = MathHelper.parseIntWithDefault((String)var3.get("m"), var10);
    102                }
    103
    104                if (var3.containsKey("c"))
    105                {
    106                    var9 = MathHelper.parseIntWithDefault((String)var3.get("c"), var9);
    107                }
    108
    109                List var12;
    110
    111                if (!var4.equals("p") && !var4.equals("a"))
    112                {
    113                    if (!var4.equals("r"))
    114                    {
    115                        return null;
    116                    }
    117                    else
    118                    {
    119                        var12 = MinecraftServer.getServer().getConfigurationManager().findPlayers(var11, var5, var6, 0, var10, var7, var8);
    120                        Collections.shuffle(var12);
    121                        var12 = var12.subList(0, Math.min(var9, var12.size()));
    122                        return var12 != null && !var12.isEmpty() ? (EntityPlayerMP[])var12.toArray(new EntityPlayerMP[0]) : new EntityPlayerMP[0];
    123                    }
    124                }
    125                else
    126                {
    127                    var12 = MinecraftServer.getServer().getConfigurationManager().findPlayers(var11, var5, var6, var9, var10, var7, var8);
    128                    return var12 != null && !var12.isEmpty() ? (EntityPlayerMP[])var12.toArray(new EntityPlayerMP[0]) : new EntityPlayerMP[0];
    129                }
    130            }
    131            else
    132            {
    133                return null;
    134            }
    135        }
    136
    137        public static boolean func_82377_a(String par0Str)
    138        {
    139            Matcher var1 = field_82389_a.matcher(par0Str);
    140
    141            if (var1.matches())
    142            {
    143                Map var2 = func_82381_h(var1.group(2));
    144                String var3 = var1.group(1);
    145                int var4 = func_82382_g(var3);
    146
    147                if (var2.containsKey("c"))
    148                {
    149                    var4 = MathHelper.parseIntWithDefault((String)var2.get("c"), var4);
    150                }
    151
    152                return var4 != 1;
    153            }
    154            else
    155            {
    156                return false;
    157            }
    158        }
    159
    160        public static boolean func_82383_a(String par0Str, String par1Str)
    161        {
    162            Matcher var2 = field_82389_a.matcher(par0Str);
    163
    164            if (!var2.matches())
    165            {
    166                return false;
    167            }
    168            else
    169            {
    170                String var3 = var2.group(1);
    171                return par1Str == null || par1Str.equals(var3);
    172            }
    173        }
    174
    175        public static boolean func_82378_b(String par0Str)
    176        {
    177            return func_82383_a(par0Str, (String)null);
    178        }
    179
    180        private static final int func_82384_c(String par0Str)
    181        {
    182            return 0;
    183        }
    184
    185        private static final int func_82379_d(String par0Str)
    186        {
    187            return 0;
    188        }
    189
    190        private static final int func_82376_e(String par0Str)
    191        {
    192            return Integer.MAX_VALUE;
    193        }
    194
    195        private static final int func_82375_f(String par0Str)
    196        {
    197            return 0;
    198        }
    199
    200        private static final int func_82382_g(String par0Str)
    201        {
    202            return par0Str.equals("a") ? 0 : 1;
    203        }
    204
    205        private static Map func_82381_h(String par0Str)
    206        {
    207            HashMap var1 = new HashMap();
    208
    209            if (par0Str == null)
    210            {
    211                return var1;
    212            }
    213            else
    214            {
    215                Matcher var2 = field_82387_b.matcher(par0Str);
    216                int var3 = 0;
    217                int var4;
    218
    219                for (var4 = -1; var2.find(); var4 = var2.end())
    220                {
    221                    String var5 = null;
    222
    223                    switch (var3++)
    224                    {
    225                        case 0:
    226                            var5 = "x";
    227                            break;
    228                        case 1:
    229                            var5 = "y";
    230                            break;
    231                        case 2:
    232                            var5 = "z";
    233                            break;
    234                        case 3:
    235                            var5 = "r";
    236                    }
    237
    238                    if (var5 != null && var2.group(1).length() > 0)
    239                    {
    240                        var1.put(var5, var2.group(1));
    241                    }
    242                }
    243
    244                if (var4 < par0Str.length())
    245                {
    246                    var2 = field_82388_c.matcher(var4 == -1 ? par0Str : par0Str.substring(var4));
    247
    248                    while (var2.find())
    249                    {
    250                        var1.put(var2.group(1), var2.group(2));
    251                    }
    252                }
    253
    254                return var1;
    255            }
    256        }
    257    }