Radio Chat

Discussion in 'Plugin Development' started by killerzz1, Aug 31, 2014.

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

    killerzz1

    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
    1. package me.killerzz1.Main;
    2.  
    3. import java.util.ArrayList;
    4.  
    5. import mkremins.fanciful.FancyMessage;
    6.  
    7. import org.bukkit.ChatColor;
    8. import org.bukkit.Material;
    9.  
    10. import org.bukkit.command.Command;
    11. import org.bukkit.command.CommandSender;
    12. import org.bukkit.entity.Player;
    13. import org.bukkit.event.EventHandler;
    14. import org.bukkit.event.Listener;
    15. import org.bukkit.event.block.Action;
    16.  
    17. import org.bukkit.plugin.java.JavaPlugin;
    18. import org.bukkit.event.player.AsyncPlayerChatEvent;
    19. import org.bukkit.event.player.PlayerInteractEvent;
    20. import org.bukkit.event.player.PlayerJoinEvent;
    21. import org.bukkit.inventory.ItemStack;
    22. import org.bukkit.inventory.meta.ItemMeta;
    23.  
    24. public class Main extends JavaPlugin implements Listener {
    25.  
    26.  
    27. @Override
    28. public void onEnable() {
    29. getServer().getPluginManager().registerEvents(this, this);
    30. }
    31.  
    32. public ArrayList<Player> germanteam = new ArrayList<Player>();
    33. public ArrayList<Player> americanteam = new ArrayList<Player>();
    34. public ArrayList<Player> Japanteam = new ArrayList<Player>();
    35. public ArrayList<Player> RussianTeam = new ArrayList<Player>();
    36. public ArrayList<Player> radio = new ArrayList<Player>();
    37.  
    38.  
    39.  
    40.  
    41.  
    42. @EventHandler
    43. public void onChat(AsyncPlayerChatEvent e) {
    44. Player p = e.getPlayer();
    45. String msg = e.getMessage();
    46. for(Player player : germanteam) {
    47. if(!(radio.contains(p))) {
    48. return;
    49. } else {
    50. player.sendMessage("[German] " + p.getName() + ": " + msg);
    51.  
    52. }
    53. if(!(germanteam.contains(p))) {
    54. return;
    55. }
    56.  
    57.  
    58. for(Player americans : americanteam) {
    59. if(!(radio.contains(p))){
    60. return;
    61. } else {
    62. americans.sendMessage("[German] " + p.getName() + ": " + msg);
    63. }
    64. if(!(americanteam.contains(p))) {
    65. return;
    66. }
    67.  
    68.  
    69. for(Player japan : Japanteam) {
    70. if(!(radio.contains(p)) && (Japanteam.contains(p))) {
    71. return;
    72. } else {
    73. japan.sendMessage("");
    74. }
    75. if(!(Japanteam.contains(p))) {
    76. return;
    77. }
    78. }
    79.  
    80.  
    81. }
    82.  
    83.  
    84. }
    85.  
    86.  
    87. }
    88. //Adding Item To Inv!
    89. @EventHandler
    90. public void onPlayerJoin(PlayerJoinEvent e) {
    91. Player p = e.getPlayer();
    92.  
    93. ItemStack radio = new ItemStack(Material.BLAZE_ROD);
    94. ItemMeta r = radio.getItemMeta();
    95. r.setDisplayName(ChatColor.YELLOW + "*" + ChatColor.BLUE + ChatColor.UNDERLINE + "Radio Selector" + ChatColor.RESET + ChatColor.YELLOW + "*");
    96. radio.setItemMeta(r);
    97. p.getInventory().setItem(8, radio);
    98.  
    99. }
    100.  
    101.  
    102.  
    103. //InterAct Radio!
    104. @EventHandler
    105. public void onClick(PlayerInteractEvent e){
    106. Player p = e.getPlayer();
    107.  
    108. //Blaze Rod Interract
    109. if(e.getAction() == Action.LEFT_CLICK_AIR){
    110. if (p.getItemInHand().getType() == Material.BLAZE_ROD){
    111.  
    112. if (p.hasPermission("opfor.usa")) {
    113.  
    114. new FancyMessage("Click To Join: ")
    115. .color(ChatColor.GREEN)
    116. .then("Global Radio ")
    117. .style(new ChatColor[] {
    118. ChatColor.UNDERLINE })
    119. .color(ChatColor.GOLD)
    120. .tooltip("Click here to go into the Global Radio!")
    121. .command("/radioglo")
    122. .then("<|> ")
    123. .color(ChatColor.GREEN)
    124. .then("Team Radio")
    125. .style(new ChatColor[] {
    126. ChatColor.UNDERLINE })
    127. .color(ChatColor.GOLD)
    128. .tooltip("Click here to go to the team radio!")
    129. .command("/radiousa")//Command radiousa
    130. .send(e.getPlayer());
    131.  
    132. return;
    133.  
    134. } else if (p.hasPermission("opfor.rus")){
    135.  
    136. new FancyMessage("Click To Join: ")
    137. .color(ChatColor.GREEN)
    138. .then("Global Radio ")
    139. .style(new ChatColor[] {
    140. ChatColor.UNDERLINE })
    141. .color(ChatColor.GOLD)
    142. .tooltip("Click here to go into the Global Radio!")
    143. .command("/radioglo")
    144. .then("<|> ")
    145. .color(ChatColor.GREEN)
    146. .then("Team Radio")
    147. .style(new ChatColor[] {
    148. ChatColor.UNDERLINE })
    149. .color(ChatColor.GOLD)
    150. .tooltip("Click here to go to the team radio!")
    151. .command("/radiorus")//Command radiorus
    152. .send(e.getPlayer());
    153. return;
    154.  
    155. } else if (p.hasPermission("opfor.jap")){
    156.  
    157. new FancyMessage("Click To Join: ")
    158. .color(ChatColor.GREEN)
    159. .then("Global Radio ")
    160. .style(new ChatColor[] {
    161. ChatColor.UNDERLINE })
    162. .color(ChatColor.GOLD)
    163. .tooltip("Click here to go into the Global Radio!")
    164. .command("/radioglo")
    165. .then("<|> ")
    166. .color(ChatColor.GREEN)
    167. .then("Team Radio")
    168. .style(new ChatColor[] {
    169. ChatColor.UNDERLINE })
    170. .color(ChatColor.GOLD)
    171. .tooltip("Click here to go to the team radio!")
    172. .command("/radiojap")//Command radiojap
    173. .send(e.getPlayer());
    174. return;
    175. }
    176.  
    177. else if (p.hasPermission("opfor.ger")){
    178.  
    179. new FancyMessage("Click To Join: ")
    180. .color(ChatColor.GREEN)
    181. .then("Global Radio ")
    182. .style(new ChatColor[] {
    183. ChatColor.UNDERLINE })
    184. .color(ChatColor.GOLD)
    185. .tooltip("Click here to go into the Global Radio!")
    186. .command("/radioglo")
    187. .then("<|> ")
    188. .color(ChatColor.GREEN)
    189. .then("Team Radio")
    190. .style(new ChatColor[] {
    191. ChatColor.UNDERLINE })
    192. .color(ChatColor.GOLD)
    193. .tooltip("Click here to go to the team radio!")
    194. .command("/radioger")//Command radioger
    195. .send(e.getPlayer());
    196. return;
    197. }
    198.  
    199. }
    200.  
    201.  
    202.  
    203. }
    204.  
    205. }
    206. @EventHandler
    207. public void onclick1(PlayerInteractEvent e){
    208. Player p = e.getPlayer();
    209.  
    210. if(e.getAction() == Action.RIGHT_CLICK_AIR){
    211. if(p.getItemInHand().getType() == Material.BLAZE_ROD){
    212. if(e.getAction() == Action.RIGHT_CLICK_AIR){
    213. if (p.getItemInHand().getType() == Material.BLAZE_ROD){
    214.  
    215. if (p.hasPermission("opfor.usa")) {
    216.  
    217. new FancyMessage("Click To Join: ")
    218. .color(ChatColor.GREEN)
    219. .then("Global Radio ")
    220. .style(new ChatColor[] {
    221. ChatColor.UNDERLINE })
    222. .color(ChatColor.GOLD)
    223. .tooltip("Click here to go into the Global Radio!")
    224. .command("/radioglo")
    225. .then("<|> ")
    226. .color(ChatColor.GREEN)
    227. .then("Team Radio")
    228. .style(new ChatColor[] {
    229. ChatColor.UNDERLINE })
    230. .color(ChatColor.GOLD)
    231. .tooltip("Click here to go to the team radio!")
    232. .command("/radiousa")//Command radiousa
    233. .send(e.getPlayer());
    234.  
    235. return;
    236.  
    237. } else if (p.hasPermission("opfor.rus")){
    238.  
    239. new FancyMessage("Click To Join: ")
    240. .color(ChatColor.GREEN)
    241. .then("Global Radio ")
    242. .style(new ChatColor[] {
    243. ChatColor.UNDERLINE })
    244. .color(ChatColor.GOLD)
    245. .tooltip("Click here to go into the Global Radio!")
    246. .command("/radioglo")
    247. .then("<|> ")
    248. .color(ChatColor.GREEN)
    249. .then("Team Radio")
    250. .style(new ChatColor[] {
    251. ChatColor.UNDERLINE })
    252. .color(ChatColor.GOLD)
    253. .tooltip("Click here to go to the team radio!")
    254. .command("/radiorus")//Command radiorus
    255. .send(e.getPlayer());
    256. return;
    257.  
    258. } else if (p.hasPermission("opfor.jap")){
    259.  
    260. new FancyMessage("Click To Join: ")
    261. .color(ChatColor.GREEN)
    262. .then("Global Radio ")
    263. .style(new ChatColor[] {
    264. ChatColor.UNDERLINE })
    265. .color(ChatColor.GOLD)
    266. .tooltip("Click here to go into the Global Radio!")
    267. .command("/radioglo")
    268. .then("<|> ")
    269. .color(ChatColor.GREEN)
    270. .then("Team Radio")
    271. .style(new ChatColor[] {
    272. ChatColor.UNDERLINE })
    273. .color(ChatColor.GOLD)
    274. .tooltip("Click here to go to the team radio!")
    275. .command("/radiojap")//Command radiojap
    276. .send(e.getPlayer());
    277. return;
    278. }
    279.  
    280. else if (p.hasPermission("opfor.ger")){
    281.  
    282. new FancyMessage("Click To Join: ")
    283. .color(ChatColor.GREEN)
    284. .then("Global Radio ")
    285. .style(new ChatColor[] {
    286. ChatColor.UNDERLINE })
    287. .color(ChatColor.GOLD)
    288. .tooltip("Click here to go into the Global Radio!")
    289. .command("/radioglo")
    290. .then("<|> ")
    291. .color(ChatColor.GREEN)
    292. .then("Team Radio")
    293. .style(new ChatColor[] {
    294. ChatColor.UNDERLINE })
    295. .color(ChatColor.GOLD)
    296. .tooltip("Click here to go to the team radio!")
    297. .command("/radioger")//Command radioger
    298. .send(e.getPlayer());
    299. return;
    300. }
    301. }
    302. }
    303. }
    304.  
    305. }
    306.  
    307. }
    308.  
    309. public boolean onCommand(CommandSender sender, Command cmd, String commandLable, String[] args){
    310. Player player = (Player) sender;
    311. if (!(sender instanceof Player)){
    312. sender.sendMessage(" " + ChatColor.BLUE + ChatColor.UNDERLINE + "The Console can't do that!");
    313. return true;
    314. }
    315.  
    316. Player p = (Player) sender;
    317.  
    318. //German Radio!
    319.  
    320. if(p.hasPermission("opfor.ger")){
    321.  
    322. if(cmd.getName().equalsIgnoreCase("radioger")){
    323. p.sendMessage(" ");
    324. p.sendMessage(" ");
    325. p.sendMessage(" ");
    326. p.sendMessage(" ");
    327. p.sendMessage(" ");
    328. p.sendMessage(" ");
    329. p.sendMessage(" ");
    330. p.sendMessage(" ");
    331. p.sendMessage(" ");
    332. p.sendMessage(" ");
    333. p.sendMessage(" ");
    334. p.sendMessage(" ");
    335. p.sendMessage(" ");
    336. p.sendMessage(" ");
    337. p.sendMessage(" ");
    338. p.sendMessage(ChatColor.YELLOW + "*" + ChatColor.WHITE + "OF" + ChatColor.YELLOW + "*" + " " + ChatColor.GREEN +"You Joined The Team Radio!" );
    339.  
    340. germanteam.add(player);
    341.  
    342. }
    343. }else if(p.hasPermission("opfor.jap")){
    344. if(cmd.getName().equalsIgnoreCase("radiojap")){
    345. p.sendMessage(" ");
    346. p.sendMessage(" ");
    347. p.sendMessage(" ");
    348. p.sendMessage(" ");
    349. p.sendMessage(" ");
    350. p.sendMessage(" ");
    351. p.sendMessage(" ");
    352. p.sendMessage(" ");
    353. p.sendMessage(" ");
    354. p.sendMessage(" ");
    355. p.sendMessage(" ");
    356. p.sendMessage(" ");
    357. p.sendMessage(" ");
    358. p.sendMessage(" ");
    359. p.sendMessage(" ");
    360. p.sendMessage(" ");
    361. p.sendMessage(" ");
    362. p.sendMessage(" ");
    363. p.sendMessage(" ");
    364. p.sendMessage(ChatColor.YELLOW + "*" + ChatColor.WHITE + "OF" + ChatColor.YELLOW + "*" + " " + ChatColor.GREEN +"You Joined The Team Radio!" );
    365.  
    366. Japanteam.add(player);
    367. }
    368. }else if(p.hasPermission("opfor.rus")){
    369. if(cmd.getName().equalsIgnoreCase("radiorus")){
    370. p.sendMessage(" ");
    371. p.sendMessage(" ");
    372. p.sendMessage(" ");
    373. p.sendMessage(" ");
    374. p.sendMessage(" ");
    375. p.sendMessage(" ");
    376. p.sendMessage(" ");
    377. p.sendMessage(" ");
    378. p.sendMessage(" ");
    379. p.sendMessage(" ");
    380. p.sendMessage(" ");
    381. p.sendMessage(" ");
    382. p.sendMessage(" ");
    383. p.sendMessage(" ");
    384. p.sendMessage(" ");
    385. p.sendMessage(" ");
    386. p.sendMessage(" ");
    387. p.sendMessage(" ");
    388. p.sendMessage(" ");
    389. p.sendMessage(ChatColor.YELLOW + "*" + ChatColor.WHITE + "OF" + ChatColor.YELLOW + "*" + " " + ChatColor.GREEN +"You Joined The Team Radio!" );
    390.  
    391. RussianTeam.add(player);
    392. }
    393. }else if(p.hasPermission("opfor.usa")){
    394. if(cmd.getName().equalsIgnoreCase("radiousa")){
    395. p.sendMessage(" ");
    396. p.sendMessage(" ");
    397. p.sendMessage(" ");
    398. p.sendMessage(" ");
    399. p.sendMessage(" ");
    400. p.sendMessage(" ");
    401. p.sendMessage(" ");
    402. p.sendMessage(" ");
    403. p.sendMessage(" ");
    404. p.sendMessage(" ");
    405. p.sendMessage(" ");
    406. p.sendMessage(" ");
    407. p.sendMessage(" ");
    408. p.sendMessage(" ");
    409. p.sendMessage(" ");
    410. p.sendMessage(" ");
    411. p.sendMessage(" ");
    412. p.sendMessage(" ");
    413. p.sendMessage(" ");
    414. p.sendMessage(ChatColor.YELLOW + "*" + ChatColor.WHITE + "OF" + ChatColor.YELLOW + "*" + " " + ChatColor.GREEN +"You Joined The Team Radio!" );
    415.  
    416. americanteam.add(player);
    417. }
    418. }else if(cmd.getName().equalsIgnoreCase("radioglo")){
    419. if(p.hasPermission("opfor.usa")){
    420. americanteam.remove(player);
    421. }else if(p.hasPermission("opfor.rus")){
    422. RussianTeam.remove(player);
    423. }else if(p.hasPermission("opfor.ger")){
    424. germanteam.remove(player);
    425. }else if(p.hasPermission("opfor.jap")){
    426. Japanteam.remove(player);
    427.  
    428. }
    429. }
    430. return true;
    431. }
    432. }
     
  2. Offline

    mine-care

    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
     
  3. Offline

    hintss

    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.
     
  4. Offline

    fireblast709

    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.
     
Thread Status:
Not open for further replies.

Share This Page