Method not being called

Discussion in 'Plugin Development' started by Hammergold, Sep 1, 2013.

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

    Hammergold

    I am making a minigame plugin but cant seem to get it to call other methods once the timer reaches 0 so the players aren't teleported. Here is the code. There are no errors in console. Here is countdown timer:

    Code:java
    1. public class GameLoop implements Runnable {
    2.  
    3. public void run() {
    4. if (Main.timeInSeconds < 120 && Main.timeInSeconds + 2 % 60 == 0) {
    5.  
    6. broadcastTimeUntilStart(true);
    7. }
    8. if (Main.timeInSeconds <= 127 && Main.timeInSeconds % 1 == 0
    9. && Main.timeInSeconds >= 122) {
    10.  
    11. broadcastTimeUntilStart(true);
    12. }
    13. if (Main.timeInSeconds >= 60 && Main.timeInSeconds % 60 == 0
    14. && Main.timeInSeconds < 121) {
    15.  
    16. broadcastTimeUntilStart(true);
    17.  
    18. }
    19. if (Main.timeInSeconds <= 30 && Main.timeInSeconds % 10 == 0
    20. && Main.timeInSeconds > 5) {
    21.  
    22. broadcastTimeUntilStart(true);
    23.  
    24. }
    25. if (Main.timeInSeconds <= 5 && Main.timeInSeconds > 0) {
    26. ;
    27.  
    28. broadcastTimeUntilStart(false);
    29.  
    30. }
    31. if (Main.timeInSeconds <= 0) {
    32. if (Main.canStart == true) {
    33. Bukkit.broadcastMessage("The Game Has Started!");
    34. Main.timeInSeconds = 722;
    35. Bukkit.broadcastMessage("You Now Have 10 Minutes Until The Game Ends");
    36. Main.gameStart = true;
    37. Main.loc.teleportPlayers(true);
    38.  
    39. } else {
    40. Bukkit.broadcastMessage("Not Enough Players! Timer Is Being Reset!");
    41. Main.timeInSeconds = 121;
    42. }
    43. }
    44. if (Main.timeInSeconds > 0) {
    45. Main.timeInSeconds--;
    46. }
    47. }
    48.  
    49. private void broadcastTimeUntilStart(boolean b) {
    50. if (Main.timeInSeconds % 1 == 0 && Main.timeInSeconds <= 127
    51. && Main.timeInSeconds >= 122) {
    52. Bukkit.broadcastMessage(Main.timeInSeconds - 120
    53. + " Seconds Until The Game Ends!");
    54. }
    55. if (Main.timeInSeconds % 60 == 0 && Main.timeInSeconds > 120) {
    56. Bukkit.broadcastMessage(Main.timeInSeconds - 120 / 60
    57. + " Minutes Until The Game Ends");
    58. } else if (Main.timeInSeconds % 60 == 0 && Main.timeInSeconds > 60) {
    59. Bukkit.broadcastMessage(Main.timeInSeconds / 60
    60. + " Minutes Until The Game Starts!");
    61. } else if (Main.timeInSeconds % 60 == 0 && Main.timeInSeconds == 60) {
    62. Bukkit.broadcastMessage(Main.timeInSeconds / 60
    63. + " Minute Until The Game Starts!");
    64. } else if (Main.timeInSeconds % 10 == 0 && Main.timeInSeconds <= 30
    65. && Main.timeInSeconds > 5) {
    66. Bukkit.broadcastMessage(Main.timeInSeconds
    67. + " Seconds Until The Game Starts!");
    68. } else if (Main.timeInSeconds <= 5 && Main.timeInSeconds > 1) {
    69. Bukkit.broadcastMessage(Main.timeInSeconds + " Seconds Remaining!");
    70. } else if (Main.timeInSeconds == 1) {
    71. Bukkit.broadcastMessage(Main.timeInSeconds + " Second Remaining!");
    72. }
    73.  
    74. }
    75.  
    76. }


    Here is the Main class:

    Code:java
    1. public class Main extends JavaPlugin implements Listener {
    2.  
    3. public static final Logger logger = Logger.getLogger("Minecraft");
    4. public static int gameLoop = 0;
    5. public static int timeInSeconds;
    6. public static boolean canStart;
    7. public static boolean gameStart;
    8. public static Player[] players;
    9. public static ItemStack book;
    10.  
    11. final static Locations loc = new Locations();
    12.  
    13. public void onEnable() {
    14. timeInSeconds = 120;
    15. canStart = false;
    16. gameStart = false;
    17. players = Bukkit.getOnlinePlayers();
    18. book = new ItemStack(Material.BOOK);
    19. getServer().getScheduler().scheduleSyncRepeatingTask(this,
    20. new GameLoop(), 20l, 20l);
    21. PluginDescriptionFile pdfFile = this.getDescription();
    22. PluginManager pm = this.getServer().getPluginManager();
    23. pm.registerEvents(this, this);
    24.  
    25. logger.info("[PerilousPyramids]" + " Version " + pdfFile.getVersion()
    26. + " Made By " + pdfFile.getAuthors() + " Has Been Enabled");
    27. getConfig().options().copyDefaults(true);
    28. saveConfig();
    29. setupConfig(getConfig());
    30.  
    31. }
    32.  
    33. public void onDisable() {
    34.  
    35. getServer().getScheduler().cancelTask(gameLoop);
    36. PluginDescriptionFile pdfFile = this.getDescription();
    37.  
    38. logger.info("[Perilous Pyramid]" + " Version " + pdfFile.getVersion()
    39. + " Made By " + pdfFile.getAuthors() + " Has Been Disabled");
    40.  
    41. }
    42.  
    43. public boolean onCommand(CommandSender sender, Command cmd,
    44. String commandlabel, String[] args) {
    45. if (commandlabel.equalsIgnoreCase("StartGame")) {
    46. if (sender.isOp()) {
    47. if (timeInSeconds <= 120){
    48. timeInSeconds = 5;
    49. }
    50. }
    51. }
    52.  
    53. return false;
    54. }
    55.  
    56. public static Locations getLocations(){
    57. return loc;
    58. }


    Here is the teleportPlayers Method in a seperate class:

    Code:java
    1. public class Locations extends Game{
    2.  
    3. FileConfiguration config;
    4.  
    5. public void teleportPlayers(boolean b) {
    6.  
    7. config = getConfig();
    8.  
    9. if (Main.gameStart == true) {
    10.  
    11. String s = config.getString("Maps");
    12. String[] u = s.split(",");
    13. Random random = new Random();
    14. int l = random.nextInt(u.length);
    15. int i = Integer.parseInt(u[l]);
    16.  
    17. if (i == 1) {
    18. // Locations in here
    19. }
    20. }
    21. }


    I have been trying to solve this with various different ways for about a month now so if someone could provide the answer that would be great!

    If you need any more information just ask me and i will provide it.

    Code:
    16:40:22 [INFO] 5 Seconds Remaining!
    16:40:23 [INFO] 4 Seconds Remaining!
    16:40:24 [INFO] 3 Seconds Remaining!
    16:40:25 [INFO] 2 Seconds Remaining!
    16:40:26 [INFO] 1 Second Remaining!
    16:40:27 [INFO] The Game Has Started!
    16:40:27 [INFO] You Now Have 10 Minutes Until The Game Ends
    16:40:27 [WARNING] [Perilous Pyramid] Task #2 for Perilous Pyramid v1.0 generated an exception
    java.lang.IllegalArgumentException: File cannot be null
        at org.apache.commons.lang.Validate.notNull(Validate.java:203)
        at org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(YamlConfiguration.java:170)
        at org.bukkit.plugin.java.JavaPlugin.reloadConfig(JavaPlugin.java:117)
        at org.bukkit.plugin.java.JavaPlugin.getConfig(JavaPlugin.java:111)
        at minigame.hammergold.files.Locations.teleportPlayers(Locations.java:27)
        at minigame.hammergold.files.GameLoop.run(GameLoop.java:41)
        at org.bukkit.craftbukkit.v1_6_R2.scheduler.CraftTask.run(CraftTask.java:53)
        at org.bukkit.craftbukkit.v1_6_R2.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:345)
        at net.minecraft.server.v1_6_R2.MinecraftServer.t(MinecraftServer.java:522)
        at net.minecraft.server.v1_6_R2.DedicatedServer.t(DedicatedServer.java:226)
        at net.minecraft.server.v1_6_R2.MinecraftServer.s(MinecraftServer.java:486)
        at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java:419)
        at net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:582)
    
    this is error i'm getting in console

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  2. Offline

    frymaster

    getConfig() is a Plugin method, you have to call it on a valid Plugin reference. Locations extends Game, which I'm guessing extends plugin somehow? That won't work, you can't just create a new Plugin object, because it won't be "plumbed in" to the server the way a proper plugin is. You have to pass a reference to your plugin into Locations when you instantiate it, then call getConfig() on this reference
     
  3. Offline

    Hammergold

    Locations extends Game, which in turn extends Main which extends JavaPlugin. Could you please post a bit of code for me on how I should do it, and would this solve the issue of the method not being called and used?
     
Thread Status:
Not open for further replies.

Share This Page