PlayerSelector (nms)

Discussion in 'Plugin Development' started by FisheyLP, Jul 29, 2016.

Thread Status:
Not open for further replies.
  1. Offline

    FisheyLP

    I need to implement everything from the PlayerSelector class to commands (of other plugins) and chat messages. Examples: @a, @r, @p, @e.

    You sure ask why I don't just filter out these from the message/command and make my own selectors?
    Because it needs to contain all tags aswell. Example: @a[m=2,rm=10,score_name=x].

    I looked a bit in the source code and found the PlayerSelector class at first.
    Then the VanillaCommandWrapper.

    At the moment I have this to test it:

    Code:
    ICommandListener icl = Utils.getListener(sender);
    
                List<Entity> entities = (List<Entity>) PlayerSelector
                        .getPlayers(icl, "@a", Entity.class);
                sender.sendMessage(entities.size() + "");
    It should show 1, since I'm the only player on the server. But the list is empty.
    Entity is from the nms import.

    I already tried different arguments (instead of "@a"):
    "hi @a", "say hi @a", and "/say hi @a"
    But none of these work.

    icl isn't null (Utils.getListener() is copied from VanillaCommandWrapper) either.
     
  2. Offline

    mine-care

    I see in the class CommandSpreadPlayers an example use of PlayerSelector in case that helps:
    Code:
      String s = astring[(i++)];
    /*  50: 47 */       if (PlayerSelector.isPattern(s))
    /*  51:    */       {
    /*  52: 48 */         List list = PlayerSelector.getPlayers(icommandlistener, s, Entity.class);
    /*  53: 50 */         if (list.size() == 0) {
    /*  54: 51 */           throw new ExceptionEntityNotFound();
    /*  55:    */         }
    /*  56: 54 */         arraylist.addAll(list);
    /*  57:    */       }
    /*  58:    */       else
    /*  59:    */       {
    /*  60: 56 */         EntityPlayer entityplayer = MinecraftServer.getServer().getPlayerList().getPlayer(s);
    /*  61: 58 */         if (entityplayer == null) {
    /*  62: 59 */           throw new ExceptionPlayerNotFound();
    /*  63:    */         }
    /*  64: 62 */         arraylist.add(entityplayer);
    /*  65:    */       }
    /*  66:    */     }
    But in any way, looking at the source code of getPlayers, you may figure in what cases it returns an empty List (Sending this because the weird snowman unicodes are replaced with human readable strings.)

    Other than that i dont think i can provide much help :( just providing those for reference...
     
  3. Offline

    FisheyLP

    @mine-care
    Thanks for trying to help..

    I just found out that the String s is the whole message split by " " to get every arguments.
    But then I get an empty list again.

    I used this code:
    Code:
    ICommandListener icl = Utils.getListener(p);
                p.sendMessage("icl == null: "+(icl == null));
    
                for (String arg : msg.split(" ")) {
                    p.sendMessage("arg: "+arg);
                    p.sendMessage("isPattern: "+PlayerSelector.isPattern(arg));
                    Object entities = PlayerSelector.getPlayers(icl, arg, EntityPlayer.class);
                    p.sendMessage("list: "+entities);
                    p.sendMessage("");
                }
    (icl is an EntityPlayer, msg is "hi @a")

    And got this result:
    [​IMG]


    instead of getPlayers() and @a, I also tried getEntity(), getPlayerNames and getPlayer().
    getPlayer() and getPlayerNames() returns null.

    Then I tried CommandAbstract.a:
    Code:
    Object result2 = CommandAbstract.a(MinecraftServer.getServer(), icl,
                                arg, EntityPlayer.class);
    It throws this exception:
    Code:
    net.minecraft.server.v1_10_R1.ExceptionEntityNotFound: commands.generic.entity.invalidUuid
      at net.minecraft.server.v1_10_R1.CommandAbstract.a(SourceFile:220)
    Meaning that it found no entity at all. :(
    Such a dissapointment. Because all vanilla commands don't do it different and it works with them.

    My only guess is that it has something to do with the ICommandListener
     
    Last edited: Jul 30, 2016
Thread Status:
Not open for further replies.

Share This Page