Solved Method not running on event

Discussion in 'Plugin Development' started by FuZioN720, Jun 28, 2013.

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

    FuZioN720

    Hello, i'm trying to have it so when someone joins a countdown will start but it's not working can someone tell me why. I'm not getting any errors.

    Listener Class:
    Code:java
    1.  
    2. package plugins.xxfuzion360xx.survivor;
    3.  
    4. import org.bukkit.Bukkit;
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.Sound;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.event.EventHandler;
    9. import org.bukkit.event.Listener;
    10. import org.bukkit.event.player.PlayerJoinEvent;
    11. import org.bukkit.plugin.Plugin;
    12.  
    13. public class PlayerListener implements Listener {
    14.  
    15. private static String prefix = ChatColor.BLACK + "" + ChatColor.GOLD + "Survivor" + ChatColor.BLACK + "]" + ChatColor.RESET;
    16. static int Count = 900;
    17. int playerCount = Bukkit.getServer().getOnlinePlayers().length;
    18. public static Survivor plugin;
    19.  
    20. public PlayerListener(Survivor instance) {
    21. plugin = instance;
    22. }
    23.  
    24. @EventHandler
    25. public void onPlayerJoin(PlayerJoinEvent event) {
    26. if (playerCount > 0){
    27. CountDown();
    28. }
    29. }
    30.  
    31. public void CountDown(){
    32. Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask((Plugin) this, new Runnable(){
    33. @Override
    34. public void run(){
    35. final int minutes = Count / 60;
    36. if (Count % 60 == 0 && Count > 60){
    37. Bukkit.broadcastMessage(prefix + ChatColor.GREEN + "THE GAME STARTS IN " + ChatColor.GOLD + ChatColor.BOLD + minutes + " MINUTES!");
    38. for (Player onlineplayer : Bukkit.getServer().getOnlinePlayers()) {
    39. onlineplayer.playSound(onlineplayer.getLocation(), Sound.ITEM_BREAK, 1, 1);
    40. }
    41. }
    42. else if (Count == 60){
    43. Bukkit.broadcastMessage(prefix + ChatColor.GREEN + "THE GAME STARTS IN " + ChatColor.GOLD + ChatColor.BOLD + minutes + " MINUTE!");
    44. for (Player onlineplayer : Bukkit.getServer().getOnlinePlayers()) {
    45. onlineplayer.playSound(onlineplayer.getLocation(), Sound.ITEM_BREAK, 1, 1);
    46. }
    47. }
    48. else if (Count == 30){
    49. Bukkit.broadcastMessage(prefix + ChatColor.GREEN + "THE GAME STARTS IN " + ChatColor.GOLD + ChatColor.BOLD + Count + " SECONDS!");
    50. for (Player onlineplayer : Bukkit.getServer().getOnlinePlayers()) {
    51. onlineplayer.playSound(onlineplayer.getLocation(), Sound.ITEM_BREAK, 1, 1);
    52. }
    53. }
    54. else if (Count == 15){
    55. Bukkit.broadcastMessage(prefix + ChatColor.GREEN + "THE GAME STARTS IN " + ChatColor.GOLD + ChatColor.BOLD + Count + " SECONDS!");
    56. for (Player onlineplayer : Bukkit.getServer().getOnlinePlayers()) {
    57. onlineplayer.playSound(onlineplayer.getLocation(), Sound.ITEM_BREAK, 1, 1);
    58. }
    59. }
    60. else if (Count < 11 && Count > 0){
    61. Bukkit.broadcastMessage(prefix + ChatColor.GREEN + "THE GAME STARTS IN " + ChatColor.GOLD + ChatColor.BOLD + Count + " SECONDS!");
    62. for (Player onlineplayer : Bukkit.getServer().getOnlinePlayers()) {
    63. onlineplayer.playSound(onlineplayer.getLocation(), Sound.ITEM_BREAK, 1, 1);
    64. }
    65. }
    66. else if (Count == 0){
    67.  
    68. }
    69. Count--;
    70. }
    71. },0L, 20L);
    72. }
    73. }
    74.  
     
  2. Offline

    StrangeOne101

    Code:
    @Override
        public void onEnable(){
            this.getLogger().info("It works, Jim!");
            this.getServer().getPluginManager().registerEvents(this, this);
        }
     
  3. Offline

    FuZioN720

    StrangeOne101 I did register the event in the main class:
    Code:
        @Override
        public void onEnable()
          {
            MotdManager.setGameState(IN_LOBBY);
           
            PluginManager pm = getServer().getPluginManager();
            pm.registerEvents(this.serverListener, this);
            pm.registerEvents(this.playerListener, this);
          }
     
Thread Status:
Not open for further replies.

Share This Page