BossBarAPI Help! Selecting all players?

Discussion in 'Spigot Plugin Development' started by SmashDev, Jul 13, 2015.

  1. Click here
    That will bring you to the page of the API I am using!
    Ok lets get to the question bit!
    How would I select all players heres the code:
    Code (Text):
    package com.smash.bar;

    import org.bukkit.command.Command;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.inventivetalent.bossbar.BossBarAPI;

    public class Main extends JavaPlugin {
        public void onEnavle(){
            getLogger().info("SmashBar enabled!");
        }
        public boolean onCommand(Command sender, Command cmd, String label, String[] args){
           
            if(cmd.getName().equalsIgnoreCase("BossMessage")){
                StringBuilder builder = new StringBuilder();
                for(int i = 0; i < args.length; i++) {
                builder.append(args[i] + " ");
                }

                String msg = builder.toString();

                BossBarAPI.setMessage(player, message);
            }
           
            return false;
        }
       
    }
     
    Please help!
     
  2. Have you tried loop?
    Code (Text):
    for(Player pl : Bukkit.getServer().getOnlinePlayers()) {

    BossBarAPI.setMessage(pl, "Hello! I am a message!");

    }
     
  3. Ill try that now!
     
  4. I edited the code/post, so hoping you will understand it easier.
     
  5. I tried it heres my new code:
    Code (Text):
    package com.smash.bar;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.inventivetalent.bossbar.BossBarAPI;

    public class Main extends JavaPlugin {
        public void onEnavle(){
            getLogger().info("SmashBar enabled!");
        }
        public boolean onCommand(Command sender, Command cmd, String label, String[] args){
           
            if(cmd.getName().equalsIgnoreCase("BossMessage")){
                StringBuilder builder = new StringBuilder();
                for(int i = 0; i < args.length; i++) {
                builder.append(args[i] + " ");
                }

                String msg = builder.toString();

                // you may now do the
                for(Player pl : Bukkit.getServer().getOnlinePlayers()) {
                    BossBarAPI.setMessage(pl, ChatColor.translateAlternateColorCodes('&', msg));
                }
            }
           
            return false;
        }
       
    }
     
    And I get this error:
    Code (Text):
    [11:12:07 ERROR]: Could not load 'plugins/SmashBar1.3.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: java.lang.Error: Unresolved compilation problems:
        The import org.inventivetalent cannot be resolved
        BossBarAPI cannot be resolved

        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:135) ~[Spigot187.jar:git-Spigot-c3c767f-33d5de3]
        at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:329) ~[Spigot187.jar:git-Spigot-c3c767f-33d5de3]
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:251) [Spigot187.jar:git-Spigot-c3c767f-33d5de3]
        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.loadPlugins(CraftServer.java:291) [Spigot187.jar:git-Spigot-c3c767f-33d5de3]
        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.reload(CraftServer.java:744) [Spigot187.jar:git-Spigot-c3c767f-33d5de3]
        at org.bukkit.Bukkit.reload(Bukkit.java:534) [Spigot187.jar:git-Spigot-c3c767f-33d5de3]
        at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:25) [Spigot187.jar:git-Spigot-c3c767f-33d5de3]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) [Spigot187.jar:git-Spigot-c3c767f-33d5de3]
        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchCommand(CraftServer.java:646) [Spigot187.jar:git-Spigot-c3c767f-33d5de3]
        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchServerCommand(CraftServer.java:632) [Spigot187.jar:git-Spigot-c3c767f-33d5de3]
        at net.minecraft.server.v1_8_R1.DedicatedServer.aM(DedicatedServer.java:353) [Spigot187.jar:git-Spigot-c3c767f-33d5de3]
        at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:317) [Spigot187.jar:git-Spigot-c3c767f-33d5de3]
        at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:634) [Spigot187.jar:git-Spigot-c3c767f-33d5de3]
        at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:537) [Spigot187.jar:git-Spigot-c3c767f-33d5de3]
        at java.lang.Thread.run(Thread.java:745) [?:1.8.0_45]
    Caused by: java.lang.Error: Unresolved compilation problems:
        The import org.inventivetalent cannot be resolved
        BossBarAPI cannot be resolved

        at com.smash.bar.Main.<init>(Main.java:8) ~[?:?]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_45]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[?:1.8.0_45]
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:1.8.0_45]
        at java.lang.reflect.Constructor.newInstance(Constructor.java:422) ~[?:1.8.0_45]
        at java.lang.Class.newInstance(Class.java:442) ~[?:1.8.0_45]
        at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:76) ~[Spigot187.jar:git-Spigot-c3c767f-33d5de3]
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:131) ~[Spigot187.jar:git-Spigot-c3c767f-33d5de3]
        ... 14 more
     
  6. Code (Text):
    The import org.inventivetalent cannot be resolved
    Have you imported the BossBarAPI?
     
  7. Ill re import it
     
  8. Yep its imported!
     
  9. Have you loaded BossBarAPI as Library? (Same as craftbukkit.jar, just with the plugin)
    Do you have the plugin on the server?
     
  10. There's problem with the the import.
    Line 8
     
  11. Do you have [Depend] or [SoftDepend] in your plugin.yml?
     
  12. No. Do i need it
     
  13. If it is a bukkit plugin that you are using, yes. If you are using a API that is not loaded as plugin, no.
     
  14. ANother error message!
    Code (Text):
    [11:48:39 ERROR]: Could not load 'plugins/SmashBar1.4.jar' in folder 'plugins'
    org.bukkit.plugin.UnknownDependencyException: BossBarAPI_v1.0.6
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:219) [Spigot187.jar:git-Spigot-c3c767f-33d5de3]
        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.loadPlugins(CraftServer.java:291) [Spigot187.jar:git-Spigot-c3c767f-33d5de3]
        at net.minecraft.server.v1_8_R1.DedicatedServer.init(DedicatedServer.java:152) [Spigot187.jar:git-Spigot-c3c767f-33d5de3]
        at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:505) [Spigot187.jar:git-Spigot-c3c767f-33d5de3]
        at java.lang.Thread.run(Thread.java:745) [?:1.8.0_45]
     
    New code:
    Code (Text):
    package com.smash.bar;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.inventivetalent.bossbar.BossBarAPI;

    public class Main extends JavaPlugin {
        public void onEnavle(){
            getLogger().info("SmashBar enabled!");
        }
        public boolean onCommand(Command sender, Command cmd, String label, String[] args){
           
            if(cmd.getName().equalsIgnoreCase("BossMessage")){
                StringBuilder builder = new StringBuilder();
                for(int i = 0; i < args.length; i++) {
                builder.append(args[i] + " ");
                }

                String msg = builder.toString();

                // you may now do the
                for(Player pl : Bukkit.getServer().getOnlinePlayers()) {
                    BossBarAPI.setMessage(pl, ChatColor.translateAlternateColorCodes('&', msg));
                }
            }
           
            return false;
        }
       
    }
     
    Plugin.yml file:
    Code (Text):
    main: com.smash.bar.Main
    name: SmashBar
    version: 1.4
    depend: [BossBarAPI_v1.0.6]
    author: Smashlols
    prefix: SmashBar
    commands:
      BossMessage:
        description: Change the boss bar message!
        aliases: [bm, bossbar, bb]
     
  15. Try "depend: [BossBarAPI]"?
     
  16. done that! And now there is this:
    Code (Text):
    [13:01:24 ERROR]: Could not load 'plugins/SmashBar1.4.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: java.lang.Error: Unresolved compilation problems:
        The import org.inventivetalent cannot be resolved
        BossBarAPI cannot be resolved

        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:135) ~[Spigot187.jar:git-Spigot-c3c767f-33d5de3]
        at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:329) ~[Spigot187.jar:git-Spigot-c3c767f-33d5de3]
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:251) [Spigot187.jar:git-Spigot-c3c767f-33d5de3]
        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.loadPlugins(CraftServer.java:291) [Spigot187.jar:git-Spigot-c3c767f-33d5de3]
        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.reload(CraftServer.java:744) [Spigot187.jar:git-Spigot-c3c767f-33d5de3]
        at org.bukkit.Bukkit.reload(Bukkit.java:534) [Spigot187.jar:git-Spigot-c3c767f-33d5de3]
        at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:25) [Spigot187.jar:git-Spigot-c3c767f-33d5de3]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) [Spigot187.jar:git-Spigot-c3c767f-33d5de3]
        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchCommand(CraftServer.java:646) [Spigot187.jar:git-Spigot-c3c767f-33d5de3]
        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchServerCommand(CraftServer.java:632) [Spigot187.jar:git-Spigot-c3c767f-33d5de3]
        at net.minecraft.server.v1_8_R1.DedicatedServer.aM(DedicatedServer.java:353) [Spigot187.jar:git-Spigot-c3c767f-33d5de3]
        at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:317) [Spigot187.jar:git-Spigot-c3c767f-33d5de3]
        at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:634) [Spigot187.jar:git-Spigot-c3c767f-33d5de3]
        at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:537) [Spigot187.jar:git-Spigot-c3c767f-33d5de3]
        at java.lang.Thread.run(Thread.java:745) [?:1.8.0_45]
    Caused by: java.lang.Error: Unresolved compilation problems:
        The import org.inventivetalent cannot be resolved
        BossBarAPI cannot be resolved

        at com.smash.bar.Main.<init>(Main.java:8) ~[?:?]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_45]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[?:1.8.0_45]
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:1.8.0_45]
        at java.lang.reflect.Constructor.newInstance(Constructor.java:422) ~[?:1.8.0_45]
        at java.lang.Class.newInstance(Class.java:442) ~[?:1.8.0_45]
        at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:76) ~[Spigot187.jar:git-Spigot-c3c767f-33d5de3]
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:131) ~[Spigot187.jar:git-Spigot-c3c767f-33d5de3]
        ... 14 more
     
     
  17. Does your coding Programm work fine?