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