Array List with PlayerJoinEvent

Discussion in 'Plugin Development' started by TheGamesHawk2001, Nov 9, 2014.

Thread Status:
Not open for further replies.
  1. Hello everyone. I have a problem, my sound won't play to the player when they join. Even when I join and type /joinsound on and leave and rejoin, I don't get a sound played to me.
     
  2. turn the sounds on
    Are you sure that the code is something like
    player.getWorld().playSound(Sound.LEVEL_UP, 10,10);
    or as LEVEL_UP that sound you want??
     
  3. Offline

    ShadowDisruptor

    Source code? (Please use code and /code in []'s)
     

  4. Code:java
    1.  
    2.  
    3.  
    4. import java.util.ArrayList;
    5. import java.util.List;
    6.  
    7. import org.bukkit.ChatColor;
    8. import org.bukkit.Sound;
    9. import org.bukkit.command.Command;
    10. import org.bukkit.command.CommandExecutor;
    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.player.PlayerJoinEvent;
    16. import org.bukkit.plugin.java.JavaPlugin;
    17.  
    18. public class Main extends JavaPlugin implements CommandExecutor, Listener{
    19.  
    20. static List<Player> joinsound = new ArrayList<Player>(); //if player is in it the sound work else not
    21.  
    22. public void onEnable(){
    23. getCommand("joinsound").setExecutor(this);
    24. getServer().getPluginManager().registerEvents(this, this);
    25. }
    26.  
    27. public void onDisable(){
    28.  
    29. }
    30. @EventHandler
    31. public void onJoinEvent(PlayerJoinEvent e){
    32. Player p = e.getPlayer();
    33. if(joinsound.contains(p)){ // check if player is in arraylist
    34. p.playSound(p.getLocation(), Sound.EXPLODE, 10, 1);
    35. }
    36. }
    37. public boolean onCommand(CommandSender sender, Command cmd, String cl, String[] args) {
    38.  
    39. if(sender instanceof Player){
    40. Player player = (Player) sender;
    41. if(cmd.getName().equalsIgnoreCase("joinsound")) {
    42. if(args.length == 0){
    43. player.sendMessage(ChatColor.GRAY + "" + ChatColor.STRIKETHROUGH + " ------------------------------------");
    44. player.sendMessage(" ");
    45. player.sendMessage(ChatColor.GOLD + " Usage: /minesound on|off");
    46. player.sendMessage(ChatColor.GRAY + " By" + ChatColor.GOLD + " TheGamesHawk2001");
    47. player.sendMessage(" ");
    48. player.sendMessage(ChatColor.GRAY + "" + ChatColor.STRIKETHROUGH + " ------------------------------------");
    49. return true;
    50. }else if(args.length == 1){
    51. if(args[0].equalsIgnoreCase("on")){
    52. joinsound.add(player); //adding player to arraylist
    53. player.sendMessage(ChatColor.RED + "JoinSound is now turned on. You will hear a sound when you join.");
    54. }else if(args[0].equalsIgnoreCase("off")){
    55. joinsound.remove(player); //removing player from arraylist
    56. player.sendMessage(ChatColor.RED + "JoinSound is now turned off.");
    57.  
    58. }
    59.  
    60.  
    61. }
    62. }
    63. }
    64. return true;
    65.  
    66. }
    67. }
     
  5. Offline

    ShadowDisruptor

    TheGamesHawk2001 first of all, if you want to play the sound to everyone around that area, change 'p.playSound()' to 'p.getWorld().playSound()' if that dosen't fix it, tag me again
     
  6. I want it to send it to the person who is added to the array list.
     
Thread Status:
Not open for further replies.

Share This Page