Help Team Chat

Discussion in 'Plugin Development' started by nyanneko0113, Aug 18, 2020.

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

    nyanneko0113

    not error, not work TeamChat

    Code:

    Code:
    public class ChatEditEvent implements Listener {
    
        ScoreboardAPI sc = new ScoreboardAPI();
        TeamCommand team = new TeamCommand();
    
        @EventHandler
        public void onPlayerChat(AsyncPlayerChatEvent e){
            @SuppressWarnings("deprecation")
            OfflinePlayer player = Bukkit.getOfflinePlayer(e.getPlayer().getName());
            for (Player p : Bukkit.getOnlinePlayers()) {
               if (sc.board.getTeam("Red").getPlayers() == player) {
                   e.setCancelled(false);
                   p.getPlayer().sendMessage("your red");
               }
               else if (sc.board.getTeam("Blue").getPlayers() == player) {
                   e.setCancelled(false);
                   p.getPlayer().sendMessage("your blue");
               }
               else if (sc.board.getTeam("Yellow").getPlayers() == player) {
                   e.setCancelled(false);
                   p.getPlayer().sendMessage("your yellow");
               }
               else if (sc.board.getTeam("Green").getPlayers() == player) {
                   e.setCancelled(false);
                   p.getPlayer().sendMessage("your green");
               }
               e.setCancelled(true);
            }
        }
    }
    TeamCommand:
    Code:
    public class TeamCommand implements CommandExecutor {
    
        ScoreboardAPI sc = new ScoreboardAPI();
    
        public List<Player> red = new ArrayList<Player>();
        public List<Player> blue = new ArrayList<Player>();
        public List<Player> yellow = new ArrayList<Player>();
        public List<Player> green = new ArrayList<Player>();
     
  2. Offline

    timtower Moderator Moderator

    @nyanneko0113 A list of players will never equal to a single one.
     
  3. Offline

    nyanneko0113

    Are you saying this?

    if (sc.board.getTeam("Red").getPlayers() == player) {
     
  4. Offline

    timtower Moderator Moderator

    @nyanneko0113 That line will never work.
    You need to check if the list contains the player.
     
  5. Offline

    nyanneko0113

    Not work... Not Error..


    Code:
    public class ChatEditEvent implements Listener {
    
        ScoreboardAPI sc = new ScoreboardAPI();
        TeamCommand team = new TeamCommand();
    
        @EventHandler
        public void onPlayerChat(AsyncPlayerChatEvent e){
            @SuppressWarnings("deprecation")
            Player player = Bukkit.getPlayer(e.getPlayer().getName());
            for (Player p : Bukkit.getOnlinePlayers()) {
               if (team.red == player) {
                   p.getPlayer().sendMessage(e.getMessage());
               }
               else if (team.blue == player) {
                   p.getPlayer().sendMessage(e.getMessage());
               }
               else if (team.yellow == player) {
                   p.getPlayer().sendMessage(e.getMessage());
               }
               else if (team.green == player) {
                   p.getPlayer().sendMessage(e.getMessage());
               }
               e.setCancelled(true);
            }
        }
    }
     
  6. Offline

    timtower Moderator Moderator

  7. Offline

    nyanneko0113

    What is wrong?

    Code:
    public class ChatEditEvent implements Listener {
    
        ScoreboardAPI sc = new ScoreboardAPI();
        TeamCommand team = new TeamCommand();
    
        @EventHandler
        public void onPlayerChat(AsyncPlayerChatEvent e){
            @SuppressWarnings("deprecation")
            Player player = Bukkit.getPlayer(e.getPlayer().getName());
            for (Player p : Bukkit.getOnlinePlayers()) {
               if (team.red.contains(player)) {
                   p.getPlayer().sendMessage(e.getMessage());
               }
               else if (team.blue.contains(player)) {
                   p.getPlayer().sendMessage(e.getMessage());
               }
               else if (team.yellow.contains(player)) {
                   p.getPlayer().sendMessage(e.getMessage());
               }
               else if (team.green.contains(player)) {
                   p.getPlayer().sendMessage(e.getMessage());
               }
               e.setCancelled(true);
            }
        }
    }
     
Thread Status:
Not open for further replies.

Share This Page