BarAPI help

Discussion in 'Plugin Development' started by ThatGuyWhoDied13, Dec 7, 2013.

Thread Status:
Not open for further replies.
  1. Hey guys I'm still not getting why this doesn't work, it's in a repeating scheduler for every 20L but it doesn't change.
    Code:java
    1. if(bardisplay == 1){
    2. BarAPI.removeBar(Player onlineplayer);
    3. BarAPI.setMessage(Player onlineplayer, "Message 1");
    4. bardisplay --;
    5. }else{
    6. if(bardisplay == 0){
    7. BarAPI.removeBar(Player onlineplayer);
    8. BarAPI.setMessage(Player onlineplayer, "Message 2");
    9. bardisplay ++;
    10. }

    (bardisplay is an int)
    When I join the server it displays "Message 1" but stays like that.

    Any help? Thanks
     
  2. Offline

    Wolfey

    Code:java
    1.  
    2. if(bardisplay == 1) {
    3. BarAPI.removeBar(Player onlineplayer);
    4. BarAPI.setMessage(Player onlineplayer, "Message 1");
    5. bardisplay--;
    6. }
    7. if(bardisplay == 0) {
    8. BarAPI.removeBar(Player onlineplayer);
    9. BarAPI.setMessage(Player onlineplayer, "Message 2");
    10. bardisplay++;
    11. }
    12.  


    Try that.
     
  3. Offline

    The_Doctor_123

    Wolfey
    You didn't really modify any functionality in the code, and the proper way to write it would be
    Code:java
    1. if(bardisplay == 1) {
    2. BarAPI.removeBar(Player onlineplayer);
    3. BarAPI.setMessage(Player onlineplayer, "Message 1");
    4. bardisplay--;
    5. }
    6. else if(bardisplay == 0) {
    7. BarAPI.removeBar(Player onlineplayer);
    8. BarAPI.setMessage(Player onlineplayer, "Message 2");
    9. bardisplay++;
    10. }


    KevyPorter
    Umm.. is that really your code? It should have a compile error.
     
    Garris0n likes this.
  4. Offline

    Wolfey

    I got confused at his code, why is he putting Player onlineplayer in removeBar()? Makes no sense whatsoever.
     
  5. Offline

    The_Doctor_123

    Wolfey
     
  6. Wolfey Because otherwise it stays as the same bar

    The_Doctor_123 No compile errors but else if made it work
    Code:java
    1. Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
    2. public void run() {
    3. if(bardisplay == 5){
    4. BarAPI.removeBar(player);
    5. BarAPI.setMessage(player, "" + ChatColor.WHITE + ChatColor.BOLD + "WELCOME TO " + ChatColor.DARK_PURPLE + ChatColor.BOLD + "KEVYANDAZZA'S" + ChatColor.WHITE + ChatColor.BOLD + " SERVER!");
    6. bardisplay --;
    7. }else if(bardisplay == 4){
    8. BarAPI.removeBar(player);
    9. BarAPI.setMessage(player, "" + ChatColor.WHITE + ChatColor.BOLD + "WELCOME TO " + ChatColor.GOLD + ChatColor.BOLD + "KEVYANDAZZA'S" + ChatColor.WHITE + ChatColor.BOLD + " SERVER!");
    10. bardisplay --;
    11. }else if(bardisplay == 3){
    12. BarAPI.removeBar(player);
    13. BarAPI.setMessage(player, "" + ChatColor.WHITE + ChatColor.BOLD + "WELCOME TO " + ChatColor.RED + ChatColor.BOLD + "KEVYANDAZZA'S" + ChatColor.WHITE + ChatColor.BOLD + " SERVER!");
    14. bardisplay --;
    15. }else if(bardisplay == 2){
    16. BarAPI.removeBar(player);
    17. BarAPI.setMessage(player, "" + ChatColor.WHITE + ChatColor.BOLD + "WELCOME TO " + ChatColor.AQUA + ChatColor.BOLD + "KEVYANDAZZA'S" + ChatColor.WHITE + ChatColor.BOLD + " SERVER!");
    18. bardisplay --;
    19. }else if(bardisplay == 1){
    20. BarAPI.removeBar(player);
    21. BarAPI.setMessage(player, "" + ChatColor.WHITE + ChatColor.BOLD + "WELCOME TO " + ChatColor.GREEN + ChatColor.BOLD + "KEVYANDAZZA'S" + ChatColor.WHITE + ChatColor.BOLD + " SERVER!");
    22. bardisplay = 5;
    23. }
    24. }
    25. }, 0L, 20L);
     
  7. Offline

    Blah1

    Use a switch statement. It will make your code more organized
     
  8. Offline

    The_Doctor_123

    Blah1
    That's all preference. Yes, they can be used there, but if statements can just as easily be used as well.
     
Thread Status:
Not open for further replies.

Share This Page