PlayerSelector .java

net.minecraft.command.PlayerSelector (class, 730 lines): members: matchEntitiesToChatComponent, matchesMultiplePlayers, keyValueListPattern, func_179650_a.

net.minecraft.commandclass730 linescommon25.3 KB

API Surface (20)

EntityPlayerMP matchOnePlayer(ICommandSender sender, String token)
<T extends Entity> T matchOneEntity(ICommandSender sender, String token, Class <? extends T > targetClass)
IChatComponent matchEntitiesToChatComponent(ICommandSender sender, String token)
<T extends Entity> List<T> matchEntities(ICommandSender sender, String token, Class <? extends T > targetClass)
boolean apply(Entity p_apply_1_)
boolean apply(Entity p_apply_1_)
boolean apply(Entity p_apply_1_)
boolean apply(Entity p_apply_1_)
boolean apply(Entity p_apply_1_)
boolean apply(Entity p_apply_1_)
boolean apply(Entity p_apply_1_)
boolean apply(Entity p_apply_1_)
boolean apply(Entity p_apply_1_)
boolean apply(Entity p_apply_1_)
boolean apply(Entity p_apply_1_)
int compare(Entity p_compare_1_, Entity p_compare_2_)
int func_179650_a(int p_179650_0_)
Map<String, Integer> func_96560_a(Map<String, String> p_96560_0_)
boolean matchesMultiplePlayers(String p_82377_0_)
boolean hasArguments(String p_82378_0_)

Fields & Constants (4)

tokenPattern
intListPattern
keyValueListPattern
WORLD_BINDING_ARGS

String literals (5)

"^@([pare])(?:\\[([\\w=,!-]*)\\])?$"
"commands.generic.entity.invalidType"
"team"
"_min"
"score_"

Full Source

PlayerSelector.java730 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.command;
2
3
import com.google.common.base.Predicate;
4
import com.google.common.base.Predicates;
5
import com.google.common.collect.ComparisonChain;
6
import com.google.common.collect.Lists;
7
import com.google.common.collect.Maps;
8
import com.google.common.collect.Sets;
9
import java.util.Collections;
10
import java.util.Comparator;
11
import java.util.List;
12
import java.util.Map;
13
import java.util.Set;
14
import java.util.Map.Entry;
15
import java.util.regex.Matcher;
16
import java.util.regex.Pattern;
17
import net.minecraft.entity.Entity;
18
import net.minecraft.entity.EntityList;
19
import net.minecraft.entity.EntityLivingBase;
20
import net.minecraft.entity.player.EntityPlayer;
21
import net.minecraft.entity.player.EntityPlayerMP;
22
import net.minecraft.scoreboard.Score;
23
import net.minecraft.scoreboard.ScoreObjective;
24
import net.minecraft.scoreboard.Scoreboard;
25
import net.minecraft.scoreboard.Team;
26
import net.minecraft.server.MinecraftServer;
27
import net.minecraft.util.AxisAlignedBB;
28
import net.minecraft.util.BlockPos;
29
import net.minecraft.util.ChatComponentTranslation;
30
import net.minecraft.util.EntitySelectors;
31
import net.minecraft.util.EnumChatFormatting;
32
import net.minecraft.util.IChatComponent;
33
import net.minecraft.util.MathHelper;
34
import net.minecraft.world.World;
35
import net.minecraft.world.WorldSettings;
36
37
public class PlayerSelector
38
{
39
    /**
40
     * This matches the at-tokens introduced for command blocks, including their arguments, if any.
41
     */
42
    private static final Pattern tokenPattern = Pattern.compile("^@([pare])(?:\\[([\\w=,!-]*)\\])?$");
43
44
    /**
45
     * This matches things like "-1,,4", and is used for getting x,y,z,range from the token's argument list.
46
     */
47
    private static final Pattern intListPattern = Pattern.compile("\\G([-!]?[\\w-]*)(?:$|,)");
48
49
    /**
50
     * This matches things like "rm=4,c=2" and is used for handling named token arguments.
51
     */
52
    private static final Pattern keyValueListPattern = Pattern.compile("\\G(\\w+)=([-!]?[\\w-]*)(?:$|,)");
53
    private static final Set<String> WORLD_BINDING_ARGS = Sets.newHashSet(new String[] {"x", "y", "z", "dx", "dy", "dz", "rm", "r"});
54
55
    /**
56
     * Returns the one player that matches the given at-token.  Returns null if more than one player matches.
57
     */
58
    public static EntityPlayerMP matchOnePlayer(ICommandSender sender, String token)
59
    {
60
        return (EntityPlayerMP)matchOneEntity(sender, token, EntityPlayerMP.class);
61
    }
62
63
    public static <T extends Entity> T matchOneEntity(ICommandSender sender, String token, Class <? extends T > targetClass)
64
    {
65
        List<T> list = matchEntities(sender, token, targetClass);
66
        return (T)(list.size() == 1 ? (Entity)list.get(0) : null);
67
    }
68
69
    public static IChatComponent matchEntitiesToChatComponent(ICommandSender sender, String token)
70
    {
71
        List<Entity> list = matchEntities(sender, token, Entity.class);
72
73
        if (list.isEmpty())
74
        {
75
            return null;
76
        }
77
        else
78
        {
79
            List<IChatComponent> list1 = Lists.<IChatComponent>newArrayList();
80
81
            for (Entity entity : list)
82
            {
83
                list1.add(entity.getDisplayName());
84
            }
85
86
            return CommandBase.join(list1);
87
        }
88
    }
89
90
    public static <T extends Entity> List<T> matchEntities(ICommandSender sender, String token, Class <? extends T > targetClass)
91
    {
92
        Matcher matcher = tokenPattern.matcher(token);
93
94
        if (matcher.matches() && sender.canCommandSenderUseCommand(1, "@"))
95
        {
96
            Map<String, String> map = getArgumentMap(matcher.group(2));
97
98
            if (!isEntityTypeValid(sender, map))
99
            {
100
                return Collections.<T>emptyList();
101
            }
102
            else
103
            {
104
                String s = matcher.group(1);
105
                BlockPos blockpos = func_179664_b(map, sender.getPosition());
106
                List<World> list = getWorlds(sender, map);
107
                List<T> list1 = Lists.<T>newArrayList();
108
109
                for (World world : list)
110
                {
111
                    if (world != null)
112
                    {
113
                        List<Predicate<Entity>> list2 = Lists.<Predicate<Entity>>newArrayList();
114
                        list2.addAll(func_179663_a(map, s));
115
                        list2.addAll(getXpLevelPredicates(map));
116
                        list2.addAll(getGamemodePredicates(map));
117
                        list2.addAll(getTeamPredicates(map));
118
                        list2.addAll(getScorePredicates(map));
119
                        list2.addAll(getNamePredicates(map));
120
                        list2.addAll(func_180698_a(map, blockpos));
121
                        list2.addAll(getRotationsPredicates(map));
122
                        list1.addAll(filterResults(map, targetClass, list2, s, world, blockpos));
123
                    }
124
                }
125
126
                return func_179658_a(list1, map, sender, targetClass, s, blockpos);
127
            }
128
        }
129
        else
130
        {
131
            return Collections.<T>emptyList();
132
        }
133
    }
134
135
    private static List<World> getWorlds(ICommandSender sender, Map<String, String> argumentMap)
136
    {
137
        List<World> list = Lists.<World>newArrayList();
138
139
        if (func_179665_h(argumentMap))
140
        {
141
            list.add(sender.getEntityWorld());
142
        }
143
        else
144
        {
145
            Collections.addAll(list, MinecraftServer.getServer().worldServers);
146
        }
147
148
        return list;
149
    }
150
151
    private static <T extends Entity> boolean isEntityTypeValid(ICommandSender commandSender, Map<String, String> params)
152
    {
153
        String s = func_179651_b(params, "type");
154
        s = s != null && s.startsWith("!") ? s.substring(1) : s;
155
156
        if (s != null && !EntityList.isStringValidEntityName(s))
157
        {
158
            ChatComponentTranslation chatcomponenttranslation = new ChatComponentTranslation("commands.generic.entity.invalidType", new Object[] {s});
159
            chatcomponenttranslation.getChatStyle().setColor(EnumChatFormatting.RED);
160
            commandSender.addChatMessage(chatcomponenttranslation);
161
            return false;
162
        }
163
        else
164
        {
165
            return true;
166
        }
167
    }
168
169
    private static List<Predicate<Entity>> func_179663_a(Map<String, String> p_179663_0_, String p_179663_1_)
170
    {
171
        List<Predicate<Entity>> list = Lists.<Predicate<Entity>>newArrayList();
172
        String s = func_179651_b(p_179663_0_, "type");
173
        final boolean flag = s != null && s.startsWith("!");
174
175
        if (flag)
176
        {
177
            s = s.substring(1);
178
        }
179
180
        boolean flag1 = !p_179663_1_.equals("e");
181
        boolean flag2 = p_179663_1_.equals("r") && s != null;
182
183
        if ((s == null || !p_179663_1_.equals("e")) && !flag2)
184
        {
185
            if (flag1)
186
            {
187
                list.add(new Predicate<Entity>()
188
                {
189
                    public boolean apply(Entity p_apply_1_)
190
                    {
191
                        return p_apply_1_ instanceof EntityPlayer;
192
                    }
193
                });
194
            }
195
        }
196
        else
197
        {
198
            final String s_f = s;
199
            list.add(new Predicate<Entity>()
200
            {
201
                public boolean apply(Entity p_apply_1_)
202
                {
203
                    return EntityList.isStringEntityName(p_apply_1_, s_f) != flag;
204
                }
205
            });
206
        }
207
208
        return list;
209
    }
210
211
    private static List<Predicate<Entity>> getXpLevelPredicates(Map<String, String> p_179648_0_)
212
    {
213
        List<Predicate<Entity>> list = Lists.<Predicate<Entity>>newArrayList();
214
        final int i = parseIntWithDefault(p_179648_0_, "lm", -1);
215
        final int j = parseIntWithDefault(p_179648_0_, "l", -1);
216
217
        if (i > -1 || j > -1)
218
        {
219
            list.add(new Predicate<Entity>()
220
            {
221
                public boolean apply(Entity p_apply_1_)
222
                {
223
                    if (!(p_apply_1_ instanceof EntityPlayerMP))
224
                    {
225
                        return false;
226
                    }
227
                    else
228
                    {
229
                        EntityPlayerMP entityplayermp = (EntityPlayerMP)p_apply_1_;
230
                        return (i <= -1 || entityplayermp.experienceLevel >= i) && (j <= -1 || entityplayermp.experienceLevel <= j);
231
                    }
232
                }
233
            });
234
        }
235
236
        return list;
237
    }
238
239
    private static List<Predicate<Entity>> getGamemodePredicates(Map<String, String> p_179649_0_)
240
    {
241
        List<Predicate<Entity>> list = Lists.<Predicate<Entity>>newArrayList();
242
        final int i = parseIntWithDefault(p_179649_0_, "m", WorldSettings.GameType.NOT_SET.getID());
243
244
        if (i != WorldSettings.GameType.NOT_SET.getID())
245
        {
246
            list.add(new Predicate<Entity>()
247
            {
248
                public boolean apply(Entity p_apply_1_)
249
                {
250
                    if (!(p_apply_1_ instanceof EntityPlayerMP))
251
                    {
252
                        return false;
253
                    }
254
                    else
255
                    {
256
                        EntityPlayerMP entityplayermp = (EntityPlayerMP)p_apply_1_;
257
                        return entityplayermp.theItemInWorldManager.getGameType().getID() == i;
258
                    }
259
                }
260
            });
261
        }
262
263
        return list;
264
    }
265
266
    private static List<Predicate<Entity>> getTeamPredicates(Map<String, String> p_179659_0_)
267
    {
268
        List<Predicate<Entity>> list = Lists.<Predicate<Entity>>newArrayList();
269
        String s = func_179651_b(p_179659_0_, "team");
270
        final boolean flag = s != null && s.startsWith("!");
271
272
        if (flag)
273
        {
274
            s = s.substring(1);
275
        }
276
277
        if (s != null)
278
        {
279
            final String s_f = s;
280
            list.add(new Predicate<Entity>()
281
            {
282
                public boolean apply(Entity p_apply_1_)
283
                {
284
                    if (!(p_apply_1_ instanceof EntityLivingBase))
285
                    {
286
                        return false;
287
                    }
288
                    else
289
                    {
290
                        EntityLivingBase entitylivingbase = (EntityLivingBase)p_apply_1_;
291
                        Team team = entitylivingbase.getTeam();
292
                        String s1 = team == null ? "" : team.getRegisteredName();
293
                        return s1.equals(s_f) != flag;
294
                    }
295
                }
296
            });
297
        }
298
299
        return list;
300
    }
301
302
    private static List<Predicate<Entity>> getScorePredicates(Map<String, String> p_179657_0_)
303
    {
304
        List<Predicate<Entity>> list = Lists.<Predicate<Entity>>newArrayList();
305
        final Map<String, Integer> map = func_96560_a(p_179657_0_);
306
307
        if (map != null && map.size() > 0)
308
        {
309
            list.add(new Predicate<Entity>()
310
            {
311
                public boolean apply(Entity p_apply_1_)
312
                {
313
                    Scoreboard scoreboard = MinecraftServer.getServer().worldServerForDimension(0).getScoreboard();
314
315
                    for (Entry<String, Integer> entry : map.entrySet())
316
                    {
317
                        String s = (String)entry.getKey();
318
                        boolean flag = false;
319
320
                        if (s.endsWith("_min") && s.length() > 4)
321
                        {
322
                            flag = true;
323
                            s = s.substring(0, s.length() - 4);
324
                        }
325
326
                        ScoreObjective scoreobjective = scoreboard.getObjective(s);
327
328
                        if (scoreobjective == null)
329
                        {
330
                            return false;
331
                        }
332
333
                        String s1 = p_apply_1_ instanceof EntityPlayerMP ? p_apply_1_.getName() : p_apply_1_.getUniqueID().toString();
334
335
                        if (!scoreboard.entityHasObjective(s1, scoreobjective))
336
                        {
337
                            return false;
338
                        }
339
340
                        Score score = scoreboard.getValueFromObjective(s1, scoreobjective);
341
                        int i = score.getScorePoints();
342
343
                        if (i < ((Integer)entry.getValue()).intValue() && flag)
344
                        {
345
                            return false;
346
                        }
347
348
                        if (i > ((Integer)entry.getValue()).intValue() && !flag)
349
                        {
350
                            return false;
351
                        }
352
                    }
353
354
                    return true;
355
                }
356
            });
357
        }
358
359
        return list;
360
    }
361
362
    private static List<Predicate<Entity>> getNamePredicates(Map<String, String> p_179647_0_)
363
    {
364
        List<Predicate<Entity>> list = Lists.<Predicate<Entity>>newArrayList();
365
        String s = func_179651_b(p_179647_0_, "name");
366
        final boolean flag = s != null && s.startsWith("!");
367
368
        if (flag)
369
        {
370
            s = s.substring(1);
371
        }
372
373
        if (s != null)
374
        {
375
            final String s_f = s;
376
            list.add(new Predicate<Entity>()
377
            {
378
                public boolean apply(Entity p_apply_1_)
379
                {
380
                    return p_apply_1_.getName().equals(s_f) != flag;
381
                }
382
            });
383
        }
384
385
        return list;
386
    }
387
388
    private static List<Predicate<Entity>> func_180698_a(Map<String, String> p_180698_0_, final BlockPos p_180698_1_)
389
    {
390
        List<Predicate<Entity>> list = Lists.<Predicate<Entity>>newArrayList();
391
        final int i = parseIntWithDefault(p_180698_0_, "rm", -1);
392
        final int j = parseIntWithDefault(p_180698_0_, "r", -1);
393
394
        if (p_180698_1_ != null && (i >= 0 || j >= 0))
395
        {
396
            final int k = i * i;
397
            final int l = j * j;
398
            list.add(new Predicate<Entity>()
399
            {
400
                public boolean apply(Entity p_apply_1_)
401
                {
402
                    int i1 = (int)p_apply_1_.getDistanceSqToCenter(p_180698_1_);
403
                    return (i < 0 || i1 >= k) && (j < 0 || i1 <= l);
404
                }
405
            });
406
        }
407
408
        return list;
409
    }
410
411
    private static List<Predicate<Entity>> getRotationsPredicates(Map<String, String> p_179662_0_)
412
    {
413
        List<Predicate<Entity>> list = Lists.<Predicate<Entity>>newArrayList();
414
415
        if (p_179662_0_.containsKey("rym") || p_179662_0_.containsKey("ry"))
416
        {
417
            final int i = func_179650_a(parseIntWithDefault(p_179662_0_, "rym", 0));
418
            final int j = func_179650_a(parseIntWithDefault(p_179662_0_, "ry", 359));
419
            list.add(new Predicate<Entity>()
420
            {
421
                public boolean apply(Entity p_apply_1_)
422
                {
423
                    int i1 = PlayerSelector.func_179650_a((int)Math.floor((double)p_apply_1_.rotationYaw));
424
                    return i > j ? i1 >= i || i1 <= j : i1 >= i && i1 <= j;
425
                }
426
            });
427
        }
428
429
        if (p_179662_0_.containsKey("rxm") || p_179662_0_.containsKey("rx"))
430
        {
431
            final int k = func_179650_a(parseIntWithDefault(p_179662_0_, "rxm", 0));
432
            final int l = func_179650_a(parseIntWithDefault(p_179662_0_, "rx", 359));
433
            list.add(new Predicate<Entity>()
434
            {
435
                public boolean apply(Entity p_apply_1_)
436
                {
437
                    int i1 = PlayerSelector.func_179650_a((int)Math.floor((double)p_apply_1_.rotationPitch));
438
                    return k > l ? i1 >= k || i1 <= l : i1 >= k && i1 <= l;
439
                }
440
            });
441
        }
442
443
        return list;
444
    }
445
446
    private static <T extends Entity> List<T> filterResults(Map<String, String> params, Class <? extends T > entityClass, List<Predicate<Entity>> inputList, String type, World worldIn, BlockPos position)
447
    {
448
        List<T> list = Lists.<T>newArrayList();
449
        String s = func_179651_b(params, "type");
450
        s = s != null && s.startsWith("!") ? s.substring(1) : s;
451
        boolean flag = !type.equals("e");
452
        boolean flag1 = type.equals("r") && s != null;
453
        int i = parseIntWithDefault(params, "dx", 0);
454
        int j = parseIntWithDefault(params, "dy", 0);
455
        int k = parseIntWithDefault(params, "dz", 0);
456
        int l = parseIntWithDefault(params, "r", -1);
457
        Predicate<Entity> predicate = Predicates.and(inputList);
458
        Predicate<Entity> predicate1 = Predicates.<Entity> and (EntitySelectors.selectAnything, predicate);
459
460
        if (position != null)
461
        {
462
            int i1 = worldIn.playerEntities.size();
463
            int j1 = worldIn.loadedEntityList.size();
464
            boolean flag2 = i1 < j1 / 16;
465
466
            if (!params.containsKey("dx") && !params.containsKey("dy") && !params.containsKey("dz"))
467
            {
468
                if (l >= 0)
469
                {
470
                    AxisAlignedBB axisalignedbb1 = new AxisAlignedBB((double)(position.getX() - l), (double)(position.getY() - l), (double)(position.getZ() - l), (double)(position.getX() + l + 1), (double)(position.getY() + l + 1), (double)(position.getZ() + l + 1));
471
472
                    if (flag && flag2 && !flag1)
473
                    {
474
                        list.addAll(worldIn.<T>getPlayers(entityClass, predicate1));
475
                    }
476
                    else
477
                    {
478
                        list.addAll(worldIn.<T>getEntitiesWithinAABB(entityClass, axisalignedbb1, predicate1));
479
                    }
480
                }
481
                else if (type.equals("a"))
482
                {
483
                    list.addAll(worldIn.<T>getPlayers(entityClass, predicate));
484
                }
485
                else if (!type.equals("p") && (!type.equals("r") || flag1))
486
                {
487
                    list.addAll(worldIn.<T>getEntities(entityClass, predicate1));
488
                }
489
                else
490
                {
491
                    list.addAll(worldIn.<T>getPlayers(entityClass, predicate1));
492
                }
493
            }
494
            else
495
            {
496
                final AxisAlignedBB axisalignedbb = func_179661_a(position, i, j, k);
497
498
                if (flag && flag2 && !flag1)
499
                {
500
                    Predicate<Entity> predicate2 = new Predicate<Entity>()
501
                    {
502
                        public boolean apply(Entity p_apply_1_)
503
                        {
504
                            return p_apply_1_.posX >= axisalignedbb.minX && p_apply_1_.posY >= axisalignedbb.minY && p_apply_1_.posZ >= axisalignedbb.minZ ? p_apply_1_.posX < axisalignedbb.maxX && p_apply_1_.posY < axisalignedbb.maxY && p_apply_1_.posZ < axisalignedbb.maxZ : false;
505
                        }
506
                    };
507
                    list.addAll(worldIn.<T>getPlayers(entityClass, Predicates.<T> and (predicate1, predicate2)));
508
                }
509
                else
510
                {
511
                    list.addAll(worldIn.<T>getEntitiesWithinAABB(entityClass, axisalignedbb, predicate1));
512
                }
513
            }
514
        }
515
        else if (type.equals("a"))
516
        {
517
            list.addAll(worldIn.<T>getPlayers(entityClass, predicate));
518
        }
519
        else if (!type.equals("p") && (!type.equals("r") || flag1))
520
        {
521
            list.addAll(worldIn.<T>getEntities(entityClass, predicate1));
522
        }
523
        else
524
        {
525
            list.addAll(worldIn.<T>getPlayers(entityClass, predicate1));
526
        }
527
528
        return list;
529
    }
530
531
    private static <T extends Entity> List<T> func_179658_a(List<T> p_179658_0_, Map<String, String> p_179658_1_, ICommandSender p_179658_2_, Class <? extends T > p_179658_3_, String p_179658_4_, final BlockPos p_179658_5_)
532
    {
533
        int i = parseIntWithDefault(p_179658_1_, "c", !p_179658_4_.equals("a") && !p_179658_4_.equals("e") ? 1 : 0);
534
535
        if (!p_179658_4_.equals("p") && !p_179658_4_.equals("a") && !p_179658_4_.equals("e"))
536
        {
537
            if (p_179658_4_.equals("r"))
538
            {
539
                Collections.shuffle((List<?>)p_179658_0_);
540
            }
541
        }
542
        else if (p_179658_5_ != null)
543
        {
544
            Collections.sort((List<T>)p_179658_0_, new Comparator<Entity>()
545
            {
546
                public int compare(Entity p_compare_1_, Entity p_compare_2_)
547
                {
548
                    return ComparisonChain.start().compare(p_compare_1_.getDistanceSq(p_179658_5_), p_compare_2_.getDistanceSq(p_179658_5_)).result();
549
                }
550
            });
551
        }
552
553
        Entity entity = p_179658_2_.getCommandSenderEntity();
554
555
        if (entity != null && p_179658_3_.isAssignableFrom(entity.getClass()) && i == 1 && ((List)p_179658_0_).contains(entity) && !"r".equals(p_179658_4_))
556
        {
557
            p_179658_0_ = Lists.newArrayList((T)entity);
558
        }
559
560
        if (i != 0)
561
        {
562
            if (i < 0)
563
            {
564
                Collections.reverse((List<?>)p_179658_0_);
565
            }
566
567
            p_179658_0_ = ((List)p_179658_0_).subList(0, Math.min(Math.abs(i), ((List)p_179658_0_).size()));
568
        }
569
570
        return (List)p_179658_0_;
571
    }
572
573
    private static AxisAlignedBB func_179661_a(BlockPos p_179661_0_, int p_179661_1_, int p_179661_2_, int p_179661_3_)
574
    {
575
        boolean flag = p_179661_1_ < 0;
576
        boolean flag1 = p_179661_2_ < 0;
577
        boolean flag2 = p_179661_3_ < 0;
578
        int i = p_179661_0_.getX() + (flag ? p_179661_1_ : 0);
579
        int j = p_179661_0_.getY() + (flag1 ? p_179661_2_ : 0);
580
        int k = p_179661_0_.getZ() + (flag2 ? p_179661_3_ : 0);
581
        int l = p_179661_0_.getX() + (flag ? 0 : p_179661_1_) + 1;
582
        int i1 = p_179661_0_.getY() + (flag1 ? 0 : p_179661_2_) + 1;
583
        int j1 = p_179661_0_.getZ() + (flag2 ? 0 : p_179661_3_) + 1;
584
        return new AxisAlignedBB((double)i, (double)j, (double)k, (double)l, (double)i1, (double)j1);
585
    }
586
587
    public static int func_179650_a(int p_179650_0_)
588
    {
589
        p_179650_0_ = p_179650_0_ % 360;
590
591
        if (p_179650_0_ >= 160)
592
        {
593
            p_179650_0_ -= 360;
594
        }
595
596
        if (p_179650_0_ < 0)
597
        {
598
            p_179650_0_ += 360;
599
        }
600
601
        return p_179650_0_;
602
    }
603
604
    private static BlockPos func_179664_b(Map<String, String> p_179664_0_, BlockPos p_179664_1_)
605
    {
606
        return new BlockPos(parseIntWithDefault(p_179664_0_, "x", p_179664_1_.getX()), parseIntWithDefault(p_179664_0_, "y", p_179664_1_.getY()), parseIntWithDefault(p_179664_0_, "z", p_179664_1_.getZ()));
607
    }
608
609
    private static boolean func_179665_h(Map<String, String> p_179665_0_)
610
    {
611
        for (String s : WORLD_BINDING_ARGS)
612
        {
613
            if (p_179665_0_.containsKey(s))
614
            {
615
                return true;
616
            }
617
        }
618
619
        return false;
620
    }
621
622
    private static int parseIntWithDefault(Map<String, String> p_179653_0_, String p_179653_1_, int p_179653_2_)
623
    {
624
        return p_179653_0_.containsKey(p_179653_1_) ? MathHelper.parseIntWithDefault((String)p_179653_0_.get(p_179653_1_), p_179653_2_) : p_179653_2_;
625
    }
626
627
    private static String func_179651_b(Map<String, String> p_179651_0_, String p_179651_1_)
628
    {
629
        return (String)p_179651_0_.get(p_179651_1_);
630
    }
631
632
    public static Map<String, Integer> func_96560_a(Map<String, String> p_96560_0_)
633
    {
634
        Map<String, Integer> map = Maps.<String, Integer>newHashMap();
635
636
        for (String s : p_96560_0_.keySet())
637
        {
638
            if (s.startsWith("score_") && s.length() > "score_".length())
639
            {
640
                map.put(s.substring("score_".length()), Integer.valueOf(MathHelper.parseIntWithDefault((String)p_96560_0_.get(s), 1)));
641
            }
642
        }
643
644
        return map;
645
    }
646
647
    /**
648
     * Returns whether the given pattern can match more than one player.
649
     */
650
    public static boolean matchesMultiplePlayers(String p_82377_0_)
651
    {
652
        Matcher matcher = tokenPattern.matcher(p_82377_0_);
653
654
        if (!matcher.matches())
655
        {
656
            return false;
657
        }
658
        else
659
        {
660
            Map<String, String> map = getArgumentMap(matcher.group(2));
661
            String s = matcher.group(1);
662
            int i = !"a".equals(s) && !"e".equals(s) ? 1 : 0;
663
            return parseIntWithDefault(map, "c", i) != 1;
664
        }
665
    }
666
667
    /**
668
     * Returns whether the given token has any arguments set.
669
     */
670
    public static boolean hasArguments(String p_82378_0_)
671
    {
672
        return tokenPattern.matcher(p_82378_0_).matches();
673
    }
674
675
    private static Map<String, String> getArgumentMap(String argumentString)
676
    {
677
        Map<String, String> map = Maps.<String, String>newHashMap();
678
679
        if (argumentString == null)
680
        {
681
            return map;
682
        }
683
        else
684
        {
685
            int i = 0;
686
            int j = -1;
687
688
            for (Matcher matcher = intListPattern.matcher(argumentString); matcher.find(); j = matcher.end())
689
            {
690
                String s = null;
691
692
                switch (i++)
693
                {
694
                    case 0:
695
                        s = "x";
696
                        break;
697
698
                    case 1:
699
                        s = "y";
700
                        break;
701
702
                    case 2:
703
                        s = "z";
704
                        break;
705
706
                    case 3:
707
                        s = "r";
708
                }
709
710
                if (s != null && matcher.group(1).length() > 0)
711
                {
712
                    map.put(s, matcher.group(1));
713
                }
714
            }
715
716
            if (j < argumentString.length())
717
            {
718
                Matcher matcher1 = keyValueListPattern.matcher(j == -1 ? argumentString : argumentString.substring(j));
719
720
                while (matcher1.find())
721
                {
722
                    map.put(matcher1.group(1), matcher1.group(2));
723
                }
724
            }
725
726
            return map;
727
        }
728
    }
729
}
730

Deobfuscated MCP 1.8.9 source of PlayerSelector from Marcelektro/MavenMCP-1.8.9 (net/minecraft/command/PlayerSelector.java), stored verbatim.