Solved Bukkit.getPlayer(UUID id) returning null. Bukkits problem?

Discussion in 'Plugin Development' started by artish1, Jul 30, 2014.

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

    artish1

    welp, i've singled out every other problem, and i have seen that indeed... Bukkit.getPlayer(uuid) == null.

    My code:
    Code:
    public void setInventory(){
            if(Bukkit.getPlayer(player) == null){
                Bukkit.broadcastMessage("Player is null, UUID: " + player);
                return;
            }
            //a bunch of set inventories.
    the (UUID) player object itself:
    Code:
    private UUID player;
        private String name;
        private ClassType type;
       
        public ArenaPlayer(Player player) {
            this.player = player.getUniqueId();
            this.name = player.getName();
            type = ClassType.SCOUT;
        }
    http://i.imgur.com/8A3OG5s.png


    The set inventory works only once, and that is when players are getting spawned into their respective areas (teams). After that, when they die, they still respawn in their respective teams it's just they do not get their inventories back?
    Code:
    @EventHandler    (priority = EventPriority.HIGHEST)
        public void onRespawn(PlayerRespawnEvent e){
            if(!ArenaManager.isInArena(e.getPlayer()))
                return;
           
            Player player = e.getPlayer();
            Arena arena = ArenaManager.getArena(player);
           
            if(arena.getState() == GameState.INGAME){
                if(arena.isRed(player)){
                    e.setRespawnLocation(arena.getRedSpawn());
                    arena.getArenaPlayer(player).setInventory();
                    arena.getArenaPlayer(player).setPassivePotionEffect();
                    player.sendMessage("SET INV for you!");
                    return;
                }
               
                if(arena.isBlue(player)){
                    e.setRespawnLocation(arena.getBlueSpawn());
                    arena.getArenaPlayer(player).setInventory();
                    arena.getArenaPlayer(player).setPassivePotionEffect();
                    player.sendMessage("SET INV FOR YOU");
                }
                return;
               
            }
           
           
        }
    the getArenaPlayer() method:

    Code:
    public ArenaPlayer getArenaPlayer(Player player){
            for(ArenaPlayer aplayer: redPlayers){
                if(player.getUniqueId().equals( aplayer.getUUID())){
                    player.sendMessage("You were in the red list!");
                    return aplayer;
                }
            }
           
            for(ArenaPlayer aplayer: bluePlayers){
                if(player.getUniqueId().equals( aplayer.getUUID())){
                    player.sendMessage("You were in the blue list");
                    return aplayer;
                }
            }
           
            for(ArenaPlayer aPlayer: lobbyPlayers){
                if(player.getUniqueId().equals( aPlayer.getUUID())){
                    player.sendMessage("You were in the lobby list.");
                    return aPlayer;
                }
            }
            player.sendMessage("You do not seem to be in the ArenaPlayer's list.");
           
            return null;
           
        }
     
  2. Offline

    Shevchik

    Bukkit.getPlayer return null for that player at respawn event. That's just how it works.
    Also you already have a player object at respawn event which you can use.
     
    artish1 likes this.
  3. Offline

    artish1

    Shevchik
    Ah yes! Thank you. I have changed my methods that way they take in the player object from the respawnevent. Instead of getting the player with Bukkit.getPlayer(), since you said it yourself, that's just how it works it seems, that it will return null on PlayerRespawnEvents...

    This has solved my problem, thank you :)
     
  4. Offline

    xize

    artish1

    hmm I'm wondering, are you trying to get a player who never has played before like in a fresh world?, or is your server in offline settings?

    from what I see here https://github.com/Bukkit/CraftBukk.../org/bukkit/craftbukkit/CraftServer.java#L537 line 537 it returns null if it does not know about a player with that uuid, the uuid of the player it self may returns null or is (may) changed into md-5 when one of the services of minecraft are down and the player has not played before.

    also I'm not sure how craftbukkit gets the uuid atleast I know they do store it inside the GameProfile and I thought they also store that inside the players data of the world but maybe that was on todo though.

    however from line 73 https://github.com/Bukkit/CraftBukk.../minecraft/server/ThreadPlayerLookupUUID.java I'm not sure if this allows players to join even when the UUID server is down if this is the case thats kinda worrying me.

    edit
    nvm :p
     
    artish1 likes this.
  5. Offline

    artish1

    xize
    Liked your post for the effort :) (A lot of research has been done, you must be rewarded!)
     
  6. Offline

    Shevchik

    getPlayer returns player object if he is in the nms player list.
    And there is no nms player object in nms player list with that uuid on respawn event.
     
Thread Status:
Not open for further replies.

Share This Page