Solved sendMessage("") not working

Discussion in 'Plugin Development' started by dajako, Jul 14, 2015.

Thread Status:
Not open for further replies.
  1. I am trying to set appropriate names for players and send them a message to notify them. However the name is not being set and the message is not being sent.

    Here's my code:
    Code:
    public static void selectTeams() {
            for (Player p : main.inGame) {
                if (main.inTeam.contains(p)) {
                    if (main.teamA.isEmpty() && !main.joined.contains(p)
                            && main.cTeam.containsKey(p)) { // A
                        main.teamA.add(p);
                        main.teamA.add(main.cTeam.get(p));
                        main.joined.add(p);
                        main.joined.add(main.cTeam.get(p));
    
                        p.sendMessage(ChatColor.BLUE + "[RealmUHC] "
                                + ChatColor.GOLD + "You have joined Team A!");
                        p.setCustomName(ChatColor.BLUE + "[A] " + ChatColor.GRAY
                                + p.getName());
    
                        main.cTeam.get(p).sendMessage(
                                ChatColor.BLUE + "[RealmUHC] " + ChatColor.GOLD
                                        + "You have joined Team A!");
                        main.cTeam.get(p).setCustomName(
                                ChatColor.BLUE + "[A] " + ChatColor.GRAY
                                        + p.getName());
    
                        p.setCustomNameVisible(true);
                        main.cTeam.get(p).setCustomNameVisible(true);
                    }
    
                    else if (main.teamB.isEmpty() && !main.joined.contains(p)
                            && main.cTeam.containsKey(p)) { // B
                        main.teamB.add(p);
                        main.teamB.add(main.cTeam.get(p));
                        main.joined.add(p);
                        main.joined.add(main.cTeam.get(p));
    
                        p.sendMessage(ChatColor.BLUE + "[RealmUHC] "
                                + ChatColor.GOLD + "You have joined Team B!");
                        p.setCustomName(ChatColor.GREEN + "[B] " + ChatColor.GRAY
                                + p.getName());
    
                        main.cTeam.get(p).sendMessage(
                                ChatColor.BLUE + "[RealmUHC] " + ChatColor.GOLD
                                        + "You have joined Team B!");
                        main.cTeam.get(p).setCustomName(
                                ChatColor.BLUE + "[B] " + ChatColor.GRAY
                                        + p.getName());
    
                        p.setCustomNameVisible(true);
                        main.cTeam.get(p).setCustomNameVisible(true);
                    }
    
                    else if (main.teamC.isEmpty() && !main.joined.contains(p)
                            && main.cTeam.containsKey(p)) { // C
                        main.teamC.add(p);
                        main.teamC.add(main.cTeam.get(p));
                        main.joined.add(p);
                        main.joined.add(main.cTeam.get(p));
    
                        p.sendMessage(ChatColor.BLUE + "[RealmUHC] "
                                + ChatColor.GOLD + "You have joined Team C!");
                        p.setCustomName(ChatColor.GOLD + "[C] " + ChatColor.GRAY
                                + p.getName());
    
                        main.cTeam.get(p).sendMessage(
                                ChatColor.BLUE + "[RealmUHC] " + ChatColor.GOLD
                                        + "You have joined Team C!");
                        main.cTeam.get(p).setCustomName(
                                ChatColor.BLUE + "[C] " + ChatColor.GRAY
                                        + p.getName());
    
                        p.setCustomNameVisible(true);
                        main.cTeam.get(p).setCustomNameVisible(true);
                    }
    
                    else if (main.teamD.isEmpty() && !main.joined.contains(p)
                            && main.cTeam.containsKey(p)) { // D
                        main.teamD.add(p);
                        main.teamD.add(main.cTeam.get(p));
                        main.joined.add(p);
                        main.joined.add(main.cTeam.get(p));
    
                        p.sendMessage(ChatColor.BLUE + "[RealmUHC] "
                                + ChatColor.GOLD + "You have joined Team D!");
                        p.setCustomName(ChatColor.BLACK + "[D] " + ChatColor.GRAY
                                + p.getName());
    
                        main.cTeam.get(p).sendMessage(
                                ChatColor.BLUE + "[RealmUHC] " + ChatColor.GOLD
                                        + "You have joined Team D!");
                        main.cTeam.get(p).setCustomName(
                                ChatColor.BLUE + "[D] " + ChatColor.GRAY
                                        + p.getName());
    
                        p.setCustomNameVisible(true);
                        main.cTeam.get(p).setCustomNameVisible(true);
                    }
    
                    else if (main.teamE.isEmpty() && !main.joined.contains(p)
                            && main.cTeam.containsKey(p)) { // E
                        main.teamE.add(p);
                        main.teamE.add(main.cTeam.get(p));
                        main.joined.add(p);
                        main.joined.add(main.cTeam.get(p));
    
                        p.sendMessage(ChatColor.BLUE + "[RealmUHC] "
                                + ChatColor.GOLD + "You have joined Team E!");
                        p.setCustomName(ChatColor.RED + "[E] " + ChatColor.GRAY
                                + p.getName());
    
                        main.cTeam.get(p).sendMessage(
                                ChatColor.BLUE + "[RealmUHC] " + ChatColor.GOLD
                                        + "You have joined Team E!");
                        main.cTeam.get(p).setCustomName(
                                ChatColor.BLUE + "[E] " + ChatColor.GRAY
                                        + p.getName());
    
                        p.setCustomNameVisible(true);
                        main.cTeam.get(p).setCustomNameVisible(true);
                    }
                } else { // Not in team
                    p.sendMessage(ChatColor.BLUE + "[RealmUHC] " + ChatColor.GOLD
                            + "You are playing solo!");
                    p.setCustomName(ChatColor.WHITE + "[SOLO] " + ChatColor.GRAY
                            + p.getName());
                    p.setCustomNameVisible(true);
                }
            }
        }
    Thank you for any replies!
     
  2. How would you recommend going about doing that?
    @FisheyLP
     
  3. Offline

    mariosunny

    That would seem to indicate that the code is not being called at all. Check your conditions for validity, especially this one:

    Code:
    main.inTeam.contains(p)
    Also ensure selectTeams() is being called.

    Also you have a lot of redundant code. I suggest chopping off this portion of your code and putting it in its own separate function, with the team as a parameter:

    Code:
     main.teamE.add(p);
                        main.teamE.add(main.cTeam.get(p));
                        main.joined.add(p);
                        main.joined.add(main.cTeam.get(p));
                        p.sendMessage(ChatColor.BLUE + "[RealmUHC] "
                                + ChatColor.GOLD + "You have joined Team E!");
                        p.setCustomName(ChatColor.RED + "[E] " + ChatColor.GRAY
                                + p.getName());
                        main.cTeam.get(p).sendMessage(
                                ChatColor.BLUE + "[RealmUHC] " + ChatColor.GOLD
                                        + "You have joined Team E!");
                        main.cTeam.get(p).setCustomName(
                                ChatColor.BLUE + "[E] " + ChatColor.GRAY
                                        + p.getName());
                        p.setCustomNameVisible(true);
                        main.cTeam.get(p).setCustomNameVisible(true);
    Be wary of UVS (unicorn vomit syndrome), where the color palette of your player chat is so diverse that it ends up driving away players who cannot interpret the Leonid Afremov you have painted them.
     
    Last edited: Jul 14, 2015
  4. I've solved it now :)


    @mariosunny I was calling the method and the colours aren't too much of an issue as the only colours which really vary are 3 characters behind players' names.
     
Thread Status:
Not open for further replies.

Share This Page