Sending message to player not working?

Discussion in 'Plugin Development' started by Ragnarok_, Apr 11, 2017.

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

    Ragnarok_

    Hey, it's me again. I know I asked 2 questions in like the past hour but I can't continue with my development without it, because I've come across this error before. So, if you read my first post, I'm creating a duels plugin, and when the player leaves, the game, it sends the opponent/bystander in the act to spawn and a message. But, I can't seem to send them a message, it worked but I modified and I don't know what I did. If you could help me, that'd be real nice! Thanks in advance!

    Code:
    I removed the name in the message because I thought that would cause an error since the player is offline.
    Code:
    @EventHandler
        public void onLeave(PlayerQuitEvent e) {
    
            e.setQuitMessage("");
    
            Player p = (Player) e.getPlayer();
    
            for (Entry<UUID, UUID> logger : inMatch.entrySet()) {
                Bukkit.broadcastMessage("Value: " + logger.getValue());
                Bukkit.broadcastMessage("Key: " + logger.getKey());
                if (logger.getKey().equals(p.getUniqueId())) {
    
                    Bukkit.broadcastMessage(ChatColor.RED + "KEY");
    
                    UUID bystandah = (UUID) logger.getValue();
                    Player bystander = (Player) Bukkit.getPlayer(bystandah);
                  
                    Player guy = (Player) bystander.getPlayer();
                  
                    guy.sendMessage(ChatColor.LIGHT_PURPLE + "[!]" + ChatColor.GRAY
                            + " You're opponent left the game " + ChatColor.LIGHT_PURPLE + "[!]");
    
                }
    
                else if (logger.getValue().equals(p.getUniqueId())) {
    
                    Bukkit.broadcastMessage(ChatColor.RED + "VALUE");
                  
                    Player bystander = (Player) Bukkit.getPlayer(logger.getKey());
                  
                    Player guy = (Player) bystander.getPlayer();
    
                    guy.sendMessage(ChatColor.LIGHT_PURPLE + "[!]" + ChatColor.GRAY
                            + " You're opponent left the game " + ChatColor.LIGHT_PURPLE + "[!]");
    OH, ALSO!!!
    Do you know why.. it's making like.. duplicates of the players at spawn. Here's a picture.
    https://gyazo.com/aee648bf4dc2ed5ca7a70c8117506fe2
     
  2. Offline

    Zombie_Striker

    @Ragnarok_
    What exactly does not work? Is it no longer finding the player? Is the player in the hashmap?

    Also, you do not need to cast the player to a aplyer. Bukkit.getPlayer returns a player.
     
  3. Offline

    Ragnarok_

    I'm not getting an error in console, but It just doesn't send the player a message. Also, I know I don't need to cast it to an aplyer, I was just messing with other stuff to see if the message would work.
     
  4. Offline

    Zombie_Striker

    @Ragnarok_
    Are you sure the player is in the map?

    I see you tried printing the UUIDs. The thing is, that is most likely not read-able. Try converting the UUID to a Player and printing out the player's name. If you do not clear the players on quit/ unsure if the player is null, Use OfflinePlayer
     
  5. Offline

    Ragnarok_

    Okay, I'm going to try what you said. But yes, I print the UUID's and they are both different and I checked them and they are correct with namemc.com. And yea, I was going to remove them, but it wasn't working so I tried to fix 1 bug at a time.
     
  6. Offline

    Zombie_Striker

    Do you know what bit of code is causing this? If so, can you post it?
     
  7. Offline

    Ragnarok_

    No, I don't. I remember my friend logging on with a hacked client, it created a duplicate of him tho. Maybe it affected the server? It didn't do that until he came.

    Um, It's working now. I don't know if it's because I used that offlinePlayer method you suggested, but it's working for some reason, even tho I added just Player guy = (Player) bystander.getPlayer(). I'm not so sure this is all fixed now, so I'm going to not mark this as solved just yet. Thanks for you're effort on helping me. I'll let you know if this is somehow tied to that duplicate players bug.
     
    Last edited: Apr 11, 2017
  8. Offline

    Zombie_Striker

    What do you mean by 'hacked client'? Do you mean that you had the server in offline mode and he joined with a fake name? If so, does this still happen if you turn the server back online?

    Are there duplicated files in the world/playerdata file? Does bukkit see the duplicate player as a valid player (do they appear on the tablist, or can events be triggered using that fake player)?
     
  9. Offline

    Ragnarok_

    He bought some premuim client, and I guess it can manipulate players or something. It pops up in the tablist, but it was gone ever since I hopefully, fixed the problem. I didn't check the playerfiles but yes events can we triggered by them. And no, the server wasn't in offline mode.
     
Thread Status:
Not open for further replies.

Share This Page