bossbarmessage plugin with BarAPI

Discussion in 'Plugin Development' started by Randomguy, Feb 3, 2015.

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

    Randomguy

    hi, I'm making a plugin called bossbarmessage and I'm having some problems... quite a lot... kinda new to this so sorry if I'm asking A LOT of questions...
    here are the problems:
    1. the bossbar doesn't come up,
    2. when i do /bossbar enable or any other commands from the plugin the bossbar menu comes up
    3. I'm not sure how to disable and enable the bossbar...
    4. I'm not sure if what i did is right...
    5. i don't know how to change the bossbar by doing a command...

    plz help... i know I'm asking a lot but I'm not sure what to do... :( I'm stumped...


    code:
    Code:
    package com.Zach.BossBarMessage;
    
    import me.confuser.barapi.BarAPI;
    
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class BossBarMessage extends JavaPlugin {
    
        @Override
        public void onEnable() {
            getLogger().info("BossBarMessage Enabled Successfully");
        }   
       
        @Override
        public void onDisable() {
            getLogger().info("BossBarMessage Sucessfully Disabled!");
        }
           
       
        public boolean onCommand(CommandSender sender, Command cmd, String Label, String[] args) {
           
            if (cmd.getName().equalsIgnoreCase("bossbar help") && sender instanceof Player); {
         
            Player player = (Player) sender;
            player.sendMessage(ChatColor.YELLOW + "" + ChatColor.BOLD + "BossBarMessage Help:");
            player.sendMessage(ChatColor.YELLOW + "/BossBar = displays the BossBarMessage Help");
            player.sendMessage(ChatColor.YELLOW + "/BossBar help = displays the BossBarMessage Help");
            player.sendMessage(ChatColor.YELLOW + "/BossBar disable = Disables the display of the BossBarMessage for you");
            player.sendMessage(ChatColor.YELLOW + "/BossBar enable = Enables the display of the BossBarMessage for you");
            player.sendMessage(ChatColor.YELLOW + "Note: The default is set to the bossbar is enabled for everyone");
           
               
            }else if (cmd.getName().equalsIgnoreCase("bossbar disable") && sender instanceof Player) {
                if (BarAPI.hasBar((Player) sender)); {
                BarAPI.removeBar((Player) sender); }
                sender.sendMessage(ChatColor.DARK_PURPLE + "Disabled the bossbar!");
                while (BarAPI.hasBar((Player) sender) == false);
                sender.sendMessage(ChatColor.DARK_PURPLE + "You already have the bossbar off!");
           
       
            }else if (cmd.getName().equalsIgnoreCase("bossbar enable") && sender instanceof Player) {
               
                if (BarAPI.hasBar((Player) sender));
                sender.sendMessage(ChatColor.DARK_PURPLE + "You already have the bar on!");
                while (BarAPI.hasBar((Player) sender) == false); {
                BarAPI.setMessage((Player) sender, Label, 75f);
                }
               
            }
            return false;
        }
    }
    btw i know i have an error on the first time i do }else.

    plugin.yml:

    Code:
    name: BossBarMessage
    main: com.Zach.BossBarMessage.BossBarMessage
    version: 1.0
    dependency: [BarAPI]
    commands:
        bossbar:
            description: Bossbar help
        bossbar help:
            description: Bossbar help
        bossbar disable:
            description: Disables the bossbar
        bossbar enable:
            description: Enables the bossbar
       
    plz help...

    the plugin does have BarAPI and CraftBukkit as build paths... and the plugin is supposed to show the bossbar... with a custom message players can disable, enable, change the message (for only themselves) and see a bossier

    <Edited by bwfcwalshy: Merged posts, please use the edit button rather than double posting.>
     
    Last edited by a moderator: Feb 4, 2015
  2. @Randomguy You should probably go look up a tutorial, I know that usually you shouldn't do this, but maybe by looking at it you can get what's happening and can use it in your code
     
  3. Offline

    Randomguy

    i have, I've found 1 so far with bcbroz, i didn't understand it... anyways if you watched his last video, he doesn't use that channel anymore so he doesn't answer comments, and i did comment on it

    but thanks!

    i also have another thread i need help with:

    http://bukkit.org/threads/help-plz-with-2-plugins-im-making.339907/#post-3009343

    <Edited by bwfcwalshy: Merged posts, please use the edit button rather than double posting.>
     
    Last edited by a moderator: Feb 3, 2015
  4. Offline

    CraftCreeper6

    @Randomguy
    Your onCommand is wrong.
    You need to use args (Arguments) instead of using one String.
     
  5. Offline

    Randomguy

    0k...

    and btw can i see code? I'm better when someone shows me how to do it than tells me

    btw i have an error on the }else

    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String Label, String[] args) {
           
            if (cmd.getName().equalsIgnoreCase("bossbar help") && sender instanceof Player); {
         
            Player player = (Player) sender;
            player.sendMessage(ChatColor.YELLOW + "" + ChatColor.BOLD + "BossBarMessage Help:");
            player.sendMessage(ChatColor.YELLOW + "/BossBar = displays the BossBarMessage Help");
            player.sendMessage(ChatColor.YELLOW + "/BossBar help = displays the BossBarMessage Help");
            player.sendMessage(ChatColor.YELLOW + "/BossBar disable = Disables the display of the BossBarMessage for you");
            player.sendMessage(ChatColor.YELLOW + "/BossBar enable = Enables the display of the BossBarMessage for you");
            player.sendMessage(ChatColor.YELLOW + "Note: The default is set to the bossbar is enabled for everyone");
           
               
            }else if (cmd.getName().equalsIgnoreCase("bossbar disable") && sender instanceof Player) {
               
                if (BarAPI.hasBar((Player) sender)); {
                BarAPI.removeBar((Player) sender); }
                sender.sendMessage(ChatColor.DARK_PURPLE + "Disabled the bossbar!");
                while (BarAPI.hasBar((Player) sender) == false);
                sender.sendMessage(ChatColor.DARK_PURPLE + "You already have the bossbar off!");
            
    <Edited by bwfcwalshy: Merged posts, please use the edit button rather than triple posting.>

    so wait, should i do this?:

    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String Label, String[] args) {
       
        if (cmd.getName().equalsIgnoreCase("bossbar") && sender instanceof Player); {
       
        if (args.length == 1)
        if (args[1] = ("help") != null)
    
     
    Last edited by a moderator: Feb 3, 2015
  6.  
  7. Offline

    SuperOriginal

    @bwfcwalshy I thought you were making a frowny face for a second

    @Randomguy if you legitimately can't figure out your own syntax errors you should probably review Java a bit.
     
  8. Offline

    Randomguy

    I've tried it out... i am reviewing it now... it works on the bottom but not the top... i have to }else ifs and only 1 works...

    btw does anyone know the difference between doing
    if (cmd.getname...) over and over or doing
    }else if (cmd.getname...)
     
    Last edited by a moderator: Feb 4, 2015
  9. Offline

    MordorKing78

    @Randomguy There is no difference but I recommend using }else if
     
  10. Offline

    Randomguy

    is there a reason why you prefer it? anyways i tried }else if and one of them doesn't work... else gets underlined... so i'll just use if
     
  11. Offline

    1Rogue

    There certainly is, if you use an else-if then your program won't evaluate anything additional once it's found the correct match. Though if people really wanted to be fast then a switch statement would be a better use-case, or mapping commands to handlers.
     
  12. Offline

    Randomguy

    ok, thanks

    and one more question, can you do two worded commands as so:
    Code:
    if (cmd.getName.equalsIgnoreCase("Bossier disable");
    or do you have to do:
    Code:
    if (args.length == 1);
    actually 2 more things... when i do this:
    Code:
            
            else if (cmd.getName().equalsIgnoreCase("bossbar disable") && sender instanceof Player) {
              
                if (BarAPI.hasBar((Player) sender)); {
                BarAPI.removeBar((Player) sender); }
                sender.sendMessage(ChatColor.DARK_PURPLE + "Disabled the bossbar!");
                while (BarAPI.hasBar((Player) sender) == false);
                sender.sendMessage(ChatColor.DARK_PURPLE + "You already have the bossbar off!"); }
          
          
      
            else if (cmd.getName().equalsIgnoreCase("bossbar enable") && sender instanceof Player) {
              
                if (BarAPI.hasBar((Player) sender));
                sender.sendMessage(ChatColor.DARK_PURPLE + "You already have the bar on!");
                while (BarAPI.hasBar((Player) sender) == false); {
                sender.sendMessage(ChatColor.YELLOW + "Type what you want the bossbar to say! What you type will not be heard in chat!");
                BarAPI.setMessage((Player) sender, in.nextLine);
                }
                
    when i use else 2 times, i get an error on one of the else, saying: error on token else, delete this token

    and also, would that work:
    Code:
    BarAPI.setMessage((Player) sender, in.nextLine);
    i keep getting an error on in, but I'm not sure if that'll work... the error says in cannot be resolved to a variable

    <Edited by bwfcwalshy: Merged posts, please use the edit button rather than double posting.>
     
    Last edited by a moderator: Feb 4, 2015
  13. Offline

    1Rogue

    Anything after the first space are all arguments passed in the String array in onCommand.

    You aren't closing your if statements.

    What is "in"? A BufferedReader?
     
  14. Offline

    MordorKing78

    @1Rogue Yeah, OK. Thats right.
     
  15. Offline

    Randomguy

    i watched some java tutorials on youtube and in the console (or the terminal or whatever its called) you could do something like:
    Code:
    String Name;
    String Name = in.nextLine
    i was thinking that might work for bukkit... it is still java so... but i get an error on in
     
  16. Offline

    Randomguy

    also I'm almost certain this will work, but i'm not sure, will it? and plz respond to the other comment...

    Code:
    if (args.length == 1);
                if (args[1] == "enable");
     
  17. Offline

    Randomguy

    would this work?

    Code:
    if (args.length == 0-10) { //would this line work? if args 0-10, because i want the bossbarmessage to only 
    //be able to be 10 characters.
                if (args[0] == "enable") { 
               
                if (BarAPI.hasBar((Player) sender)) {
                sender.sendMessage(ChatColor.DARK_PURPLE + "You already have the bar on!");
                }
                else
                {
                player.sendMessage("Invalid Arguments!!");
                }
                }
                else
                {
                player.sendMessage("Invalid Arguments!!");
                }
                }
                else
                {
                player.sendMessage("Invalid Arguments!!");
           
                while (BarAPI.hasBar((Player) sender) == false); {
                BarAPI.setMessage((Player) player, args[1-10] ); }
    i have 3 else's for the 3 if statements...
     
    Last edited by a moderator: Feb 22, 2015
Thread Status:
Not open for further replies.

Share This Page