Title Plugin

Discussion in 'Spigot Plugin Development' started by ZevoGaems, Apr 14, 2017.

  1. I am working on a title plugin and I have most of the code complete but I just need help fixing a few errors. Here is my code. I will highlight the errors that eclipse found.
    Code (Text):
    package pw.LoopTurn.announce;

    import org.bukkit.Bukkit;
    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;

    import com.connorlinfoot.titleapi.TitleAPI;

    public class main extends JavaPlugin {
        public void onEnable() {
            getLogger().info("Announcements are now active");
        }
        public void onDisbale() {
            getLogger().info("Announcements are now inactive");
        }
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if(cmd.getName().equalsIgnoreCase("announce"))
                if(sender instanceof Player)
                    if(args.length < 0)
                        sender.sendMessage(ChatColor.RED + "Announcements, " + ChatColor.DARK_GRAY + "Usage: /announce (message)");
            return true;
       
        } else if (args.length = 0)
            StringBuilder message = new StringBuilder();

            for (int i = 1; i < args.length; i++) {
                message.append(args[i] + " ");
            }

            Player all = (Player) Bukkit.getServer().getOnlinePlayers();
            TitleAPI.sendSubtitle(all, 20, 100, 20, message);
            return true;
        }
    }

     
    This area of the code has the errors
    Code (Text):
    } else if (args.length = 0)
            StringBuilder message = new StringBuilder();

            for (int i = 1; i < args.length; i++) {
                message.append(args[i] + " ");
     
    #1 ZevoGaems, Apr 14, 2017
    Last edited: Apr 14, 2017
  2. Well... I'm just going to put on my magical error-finding glasses, just a minute.
     
    • Funny Funny x 1
  3. There you go I gave a little segment where all the errors where. Can you please help me though
     
  4. Code (Text):
            StringBuilder message = new StringBuilder();

            for (int i = 1; i < args.length; i++) {
                message.append(args[i] + " ");
            }

            Player all = (Player) Bukkit.getServer().getOnlinePlayers();
            TitleAPI.sendSubtitle(all, 20, 100, 20, message);
            return true;
    Any reason for using a string builder? Why not String message = args[0]; and as a result remove the string builder, and the for loop

    This is all wrong, you can't send a message to a person called bobbyjimmysteve, use a foreach loop.
    Code (Text):
            String message = args[0];

            for (Player p : Bukkit.getOnlinePlayers()) {
                TitleAPI.sendSubtitle(p, 20, 100, 20, message);
            }
     
  5. I still get 3 errors here
    Code (Text):
        } else if (args.length = 0)
        String message = args[0];
     
  6. change it to args.length = 1
    *Noticed my mistake ^^ you get the point though*
    It does help if you learn at least a slight bit of java before using an api made with java

    Edit: Just realised your else statement isn't even part of your if statement, this should help Link
     
    #6 v_M_v, Apr 14, 2017
    Last edited: Apr 14, 2017
  7. It should be args.length == not args.length =

    A single = is for assigning a value
    Double == is for comparison


    Sent from my iPhone using Tapatalk
     
  8. Don't go around telling others to learn Java if you can't give proper advise yourself tyvm.
     
    • Funny Funny x 1