Solved Im Back :D

Discussion in 'Plugin Development' started by Tyler Christensen, Aug 18, 2014.

Thread Status:
Not open for further replies.
  1. Hello you guys! Im back with another Noobish question... In my config, i have a string for an integer like so:

    Tugs: 10

    Where 10 is (supposed to be) the int.
    So in my coding, i have something like so:

    public void t(){// this is called onEnable();
    String r = String getConfig().get("Tugs");
    int tugss = Integer.parseInt(r);
    int tugs = (int) tugss;


    And at the top i have:
    Public static int tugs;


    There are many ways of doing this, but im looking for a proper way of getting a string from the config, and setting it as an Integer to use for a countdown and such. I appriciate all the help in advance!
     
  2. Offline

    JBoss925

    tugs is a global variable so replace "int tugs = (int) tugss;" with "tugs = tuggs;" That will set the global variable.
     
    Tyler Christensen likes this.
  3. Offline

    SpaceManiac

    As an added bonus, configurations offer getInt() so you don't have to parse strings manually.
     
  4. Offline

    Gerov

    Tyler Christensen And just a little tip, instead of having to parseInt, just do:

    Code:java
    1. getConfig().getInt("Tugs");



    :)
     
  5. Thanks @SpaceManoac and Gerov ! exactly the answer i was looking for! ty

    Time for another special phase!

    My Main Class:

    Code:java
    1. import java.util.ArrayList;
    2. import java.util.logging.Logger;
    3.  
    4. import net.pk.mcwar.listeners.Player.AsyncPlayerPreLogin;
    5. import net.pk.mcwar.listeners.Player.PlayerEvents;
    6. import net.pk.mcwar.listeners.Player.PlayerJoin;
    7. import net.pk.mcwar.listeners.Player.PlayerQuit;
    8. import net.pk.mcwar.listeners.entity.EntityDamageByEntity;
    9. import net.pk.mcwar.runnables.StartCountdown;
    10.  
    11. import org.bukkit.Bukkit;
    12. import org.bukkit.entity.Player;
    13. import org.bukkit.event.Listener;
    14. import org.bukkit.plugin.PluginManager;
    15. import org.bukkit.plugin.java.JavaPlugin;
    16.  
    17. public class Main extends JavaPlugin implements Listener{
    18. public static ArrayList<Player> kickEvent = new ArrayList<Player>();
    19. public final Logger logger = Logger.getLogger("Minecraft");
    20. public static String lobbyspawn = new String();
    21. public static String knightspawn = new String();
    22. public static String orcspawn= new String();
    23. public static int tugs;
    24. public static int gt;
    25. public static int tur;
    26.  
    27.  
    28. public void onDisable() {
    29. }
    30.  
    31. public void onEnable() {
    32. GameState.setState(GameState.IN_LOBBY);
    33. new StartCountdown().runTaskTimer(this, 0, 20);
    34. registerListeners();
    35. config();
    36. commands();
    37. configlist();
    38. Bukkit.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
    39. }
    40.  
    41. public void commands(){
    42. this.getCommand("team").setExecutor(new Commands(this));
    43. this.getCommand("leave").setExecutor(new Commands(this));
    44. this.getCommand("team").setExecutor(new Commands(this));
    45. }
    46.  
    47. public void registerListeners() {
    48. PluginManager pm = getServer().getPluginManager();
    49. pm.registerEvents(this, this);
    50. pm.registerEvents(new PlayerJoin(this), this);
    51. pm.registerEvents(new PlayerQuit(this), this);
    52. pm.registerEvents(new PlayerEvents(this), this);
    53. pm.registerEvents(new AsyncPlayerPreLogin(this), this);
    54. pm.registerEvents(new EntityDamageByEntity(this), this);
    55. }
    56.  
    57. public void config(){
    58. getConfig().options().copyDefaults(true);
    59. saveConfig();
    60. }
    61.  
    62. public void configlist(){
    63. String lobbyspawna = (String)getConfig().get("Lobby Spawn");
    64. lobbyspawn = (String) lobbyspawna;
    65.  
    66. String knightspawna = (String)getConfig().get("Knight Spawn");
    67. knightspawn = (String) knightspawna;
    68.  
    69. String orcspawna = (String)getConfig().get("Orc Spawn");
    70. orcspawn = (String) orcspawna;
    71.  
    72. int tugsa = (int) getConfig().getInt("TUGS");
    73. tugs = tugsa;
    74.  
    75. int gta = (int) getConfig().getInt("GT");
    76. gt = gta;
    77.  
    78. int tura = (int) getConfig().get("TUR");
    79. tur = tura;
    80. }
    81. }



    And this is what i have in my startCountdown class:

    Code:java
    1.  
    2. public class StartCountdown extends BukkitRunnable {
    3. public static int timeUntilStart = Main.tugs;
    4.  
    5.  
    6. public void run() {
    7. Bukkit.broadcastMessage("1");
    8. if (!(timeUntilStart <= 0)) {
    9. Bukkit.broadcastMessage("2");
    10. if (GameState.isState(GameState.IN_LOBBY)) {
    11. Bukkit.broadcastMessage("3");
    12. if (Game.canStart() == true) {
    13. Bukkit.broadcastMessage("4");
    14. timeUntilStart--;
    15. if (timeUntilStart == 0) {
    16. Bukkit.broadcastMessage("5");
    17. ChatUtilities.broadcast("Game Started!");
    18. Game.start();
    19. }
    20. if ((timeUntilStart % 10 == 0 || timeUntilStart < 5)
    21. && timeUntilStart != 0) {
    22. ChatUtilities.broadcast(timeUntilStart
    23. + " seconds until the game starts!");
    24. }
    25. }
    26. }
    27. }
    28. }
    29. }
    30.  


    Dont worry about the bukkit.broadcast message thing, just debugging. It IS running the class, BUT (this is a very big butt ;) ) It doesnt goe bast the broadcast "1" message and for some reason it isnt setting the int in the runnable. And i am not getting any errors. I pasted the code to let everyone see instread of making them guess :p And im triple checking and making the canstart to true and such so that isnt the problem. Thanks for all the help in the future :D

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

    br456

    Tyler Christensen
    You are only setting the tugs variable after you start your timer. You need to call you config(); method before you start the timer
     
  7. br456
    Im calling in on the onEnable, is that wrong?
     
  8. Offline

    JBoss925

    In your onEnable, you're calling config() after you start the runnable. Put the config(); method above the line where you start the runnable.
     
    Tyler Christensen likes this.
  9. Offline

    br456

    Tyler Christensen
    Everything is fine where it is, but inside of onEnable(); You are starting the task timer, and then you are calling your config method. The tugs variable is not set until you call the config method. You must call the config method before you run task timer
     
  10. TY Imma try tht xD

    JBoss925

    Being a retard sucks ass xD Thanks for your help! You da man! i seem to have forgot the fact that even though everything is refrenced together, it still wont run properly because of the way things run systematicly. Thanks! Your awesome!

    And br456
    I Appriciate your help as well :3

    Both you guys made my day! #DoneWithConfig!

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

    JBoss925

    :D
     
    Tyler Christensen likes this.
Thread Status:
Not open for further replies.

Share This Page