Hello there guys i am making a bukkit plugin that is when the player joins the server they get an item and when they click that item they will then be able to select team radio or global radio but when the player joins the team radio i need the chat message to only be sent to the people that are in that team radio and no one else so here is my code and it is not stopping the msg from all users seeing it how would i fix this here is my code Code:java package me.killerzz1.Main; import java.util.ArrayList; import mkremins.fanciful.FancyMessage; import org.bukkit.ChatColor;import org.bukkit.Material; import org.bukkit.command.Command;import org.bukkit.command.CommandSender;import org.bukkit.entity.Player;import org.bukkit.event.EventHandler;import org.bukkit.event.Listener;import org.bukkit.event.block.Action; import org.bukkit.plugin.java.JavaPlugin;import org.bukkit.event.player.AsyncPlayerChatEvent;import org.bukkit.event.player.PlayerInteractEvent;import org.bukkit.event.player.PlayerJoinEvent;import org.bukkit.inventory.ItemStack;import org.bukkit.inventory.meta.ItemMeta; public class Main extends JavaPlugin implements Listener { @Overridepublic void onEnable() { getServer().getPluginManager().registerEvents(this, this);} public ArrayList<Player> germanteam = new ArrayList<Player>();public ArrayList<Player> americanteam = new ArrayList<Player>();public ArrayList<Player> Japanteam = new ArrayList<Player>();public ArrayList<Player> RussianTeam = new ArrayList<Player>();public ArrayList<Player> radio = new ArrayList<Player>(); @EventHandler public void onChat(AsyncPlayerChatEvent e) { Player p = e.getPlayer(); String msg = e.getMessage(); for(Player player : germanteam) { if(!(radio.contains(p))) { return; } else { player.sendMessage("[German] " + p.getName() + ": " + msg); } if(!(germanteam.contains(p))) { return; } for(Player americans : americanteam) { if(!(radio.contains(p))){ return; } else { americans.sendMessage("[German] " + p.getName() + ": " + msg); } if(!(americanteam.contains(p))) { return; } for(Player japan : Japanteam) { if(!(radio.contains(p)) && (Japanteam.contains(p))) { return; } else { japan.sendMessage(""); } if(!(Japanteam.contains(p))) { return; } } } } } //Adding Item To Inv! @EventHandler public void onPlayerJoin(PlayerJoinEvent e) { Player p = e.getPlayer(); ItemStack radio = new ItemStack(Material.BLAZE_ROD); ItemMeta r = radio.getItemMeta(); r.setDisplayName(ChatColor.YELLOW + "*" + ChatColor.BLUE + ChatColor.UNDERLINE + "Radio Selector" + ChatColor.RESET + ChatColor.YELLOW + "*"); radio.setItemMeta(r); p.getInventory().setItem(8, radio); } //InterAct Radio! @EventHandler public void onClick(PlayerInteractEvent e){ Player p = e.getPlayer(); //Blaze Rod Interract if(e.getAction() == Action.LEFT_CLICK_AIR){ if (p.getItemInHand().getType() == Material.BLAZE_ROD){ if (p.hasPermission("opfor.usa")) { new FancyMessage("Click To Join: ") .color(ChatColor.GREEN) .then("Global Radio ") .style(new ChatColor[] { ChatColor.UNDERLINE }) .color(ChatColor.GOLD) .tooltip("Click here to go into the Global Radio!") .command("/radioglo") .then("<|> ") .color(ChatColor.GREEN) .then("Team Radio") .style(new ChatColor[] { ChatColor.UNDERLINE }) .color(ChatColor.GOLD) .tooltip("Click here to go to the team radio!") .command("/radiousa")//Command radiousa .send(e.getPlayer()); return; } else if (p.hasPermission("opfor.rus")){ new FancyMessage("Click To Join: ") .color(ChatColor.GREEN) .then("Global Radio ") .style(new ChatColor[] { ChatColor.UNDERLINE }) .color(ChatColor.GOLD) .tooltip("Click here to go into the Global Radio!") .command("/radioglo") .then("<|> ") .color(ChatColor.GREEN) .then("Team Radio") .style(new ChatColor[] { ChatColor.UNDERLINE }) .color(ChatColor.GOLD) .tooltip("Click here to go to the team radio!") .command("/radiorus")//Command radiorus .send(e.getPlayer()); return; } else if (p.hasPermission("opfor.jap")){ new FancyMessage("Click To Join: ") .color(ChatColor.GREEN) .then("Global Radio ") .style(new ChatColor[] { ChatColor.UNDERLINE }) .color(ChatColor.GOLD) .tooltip("Click here to go into the Global Radio!") .command("/radioglo") .then("<|> ") .color(ChatColor.GREEN) .then("Team Radio") .style(new ChatColor[] { ChatColor.UNDERLINE }) .color(ChatColor.GOLD) .tooltip("Click here to go to the team radio!") .command("/radiojap")//Command radiojap .send(e.getPlayer()); return; } else if (p.hasPermission("opfor.ger")){ new FancyMessage("Click To Join: ") .color(ChatColor.GREEN) .then("Global Radio ") .style(new ChatColor[] { ChatColor.UNDERLINE }) .color(ChatColor.GOLD) .tooltip("Click here to go into the Global Radio!") .command("/radioglo") .then("<|> ") .color(ChatColor.GREEN) .then("Team Radio") .style(new ChatColor[] { ChatColor.UNDERLINE }) .color(ChatColor.GOLD) .tooltip("Click here to go to the team radio!") .command("/radioger")//Command radioger .send(e.getPlayer()); return; } } } } @EventHandler public void onclick1(PlayerInteractEvent e){ Player p = e.getPlayer(); if(e.getAction() == Action.RIGHT_CLICK_AIR){ if(p.getItemInHand().getType() == Material.BLAZE_ROD){ if(e.getAction() == Action.RIGHT_CLICK_AIR){ if (p.getItemInHand().getType() == Material.BLAZE_ROD){ if (p.hasPermission("opfor.usa")) { new FancyMessage("Click To Join: ") .color(ChatColor.GREEN) .then("Global Radio ") .style(new ChatColor[] { ChatColor.UNDERLINE }) .color(ChatColor.GOLD) .tooltip("Click here to go into the Global Radio!") .command("/radioglo") .then("<|> ") .color(ChatColor.GREEN) .then("Team Radio") .style(new ChatColor[] { ChatColor.UNDERLINE }) .color(ChatColor.GOLD) .tooltip("Click here to go to the team radio!") .command("/radiousa")//Command radiousa .send(e.getPlayer()); return; } else if (p.hasPermission("opfor.rus")){ new FancyMessage("Click To Join: ") .color(ChatColor.GREEN) .then("Global Radio ") .style(new ChatColor[] { ChatColor.UNDERLINE }) .color(ChatColor.GOLD) .tooltip("Click here to go into the Global Radio!") .command("/radioglo") .then("<|> ") .color(ChatColor.GREEN) .then("Team Radio") .style(new ChatColor[] { ChatColor.UNDERLINE }) .color(ChatColor.GOLD) .tooltip("Click here to go to the team radio!") .command("/radiorus")//Command radiorus .send(e.getPlayer()); return; } else if (p.hasPermission("opfor.jap")){ new FancyMessage("Click To Join: ") .color(ChatColor.GREEN) .then("Global Radio ") .style(new ChatColor[] { ChatColor.UNDERLINE }) .color(ChatColor.GOLD) .tooltip("Click here to go into the Global Radio!") .command("/radioglo") .then("<|> ") .color(ChatColor.GREEN) .then("Team Radio") .style(new ChatColor[] { ChatColor.UNDERLINE }) .color(ChatColor.GOLD) .tooltip("Click here to go to the team radio!") .command("/radiojap")//Command radiojap .send(e.getPlayer()); return; } else if (p.hasPermission("opfor.ger")){ new FancyMessage("Click To Join: ") .color(ChatColor.GREEN) .then("Global Radio ") .style(new ChatColor[] { ChatColor.UNDERLINE }) .color(ChatColor.GOLD) .tooltip("Click here to go into the Global Radio!") .command("/radioglo") .then("<|> ") .color(ChatColor.GREEN) .then("Team Radio") .style(new ChatColor[] { ChatColor.UNDERLINE }) .color(ChatColor.GOLD) .tooltip("Click here to go to the team radio!") .command("/radioger")//Command radioger .send(e.getPlayer()); return; } } } } } } public boolean onCommand(CommandSender sender, Command cmd, String commandLable, String[] args){ Player player = (Player) sender; if (!(sender instanceof Player)){ sender.sendMessage(" " + ChatColor.BLUE + ChatColor.UNDERLINE + "The Console can't do that!"); return true; } Player p = (Player) sender; //German Radio! if(p.hasPermission("opfor.ger")){ if(cmd.getName().equalsIgnoreCase("radioger")){ p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(ChatColor.YELLOW + "*" + ChatColor.WHITE + "OF" + ChatColor.YELLOW + "*" + " " + ChatColor.GREEN +"You Joined The Team Radio!" ); germanteam.add(player); } }else if(p.hasPermission("opfor.jap")){ if(cmd.getName().equalsIgnoreCase("radiojap")){ p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(ChatColor.YELLOW + "*" + ChatColor.WHITE + "OF" + ChatColor.YELLOW + "*" + " " + ChatColor.GREEN +"You Joined The Team Radio!" ); Japanteam.add(player); } }else if(p.hasPermission("opfor.rus")){ if(cmd.getName().equalsIgnoreCase("radiorus")){ p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(ChatColor.YELLOW + "*" + ChatColor.WHITE + "OF" + ChatColor.YELLOW + "*" + " " + ChatColor.GREEN +"You Joined The Team Radio!" ); RussianTeam.add(player); } }else if(p.hasPermission("opfor.usa")){ if(cmd.getName().equalsIgnoreCase("radiousa")){ p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(" "); p.sendMessage(ChatColor.YELLOW + "*" + ChatColor.WHITE + "OF" + ChatColor.YELLOW + "*" + " " + ChatColor.GREEN +"You Joined The Team Radio!" ); americanteam.add(player); } }else if(cmd.getName().equalsIgnoreCase("radioglo")){ if(p.hasPermission("opfor.usa")){ americanteam.remove(player); }else if(p.hasPermission("opfor.rus")){ RussianTeam.remove(player); }else if(p.hasPermission("opfor.ger")){ germanteam.remove(player); }else if(p.hasPermission("opfor.jap")){ Japanteam.remove(player); } } return true;}}
Please read my signature on casting, you could use a method for fancy message, and for player.sendmessage(" ") or a for loop there, because you have ~200 lines of the same code over and over and over... I can't see what's the problem because code function of bukkit is buggy for iOS so.. Sorry, can you please wrap up your code and repost it? EDIT:http://www.tutorialspoint.com/java/java_methods.htm
You never said what's wrong with the code you posted. Anyway, I'd just look at the recipients list in asyncplayerchatevent and remove everyone not on their team.
killerzz1 the return; in the for loops of the chat event will stop the chat from functioning properly. Also, you create memory leaks in your code by adding the Player to an ArrayList without ever removing them.