Help | Can someone explain me what I did wrong here?

Discussion in 'Spigot Plugin Development' started by eyalfx, May 19, 2016.

  1. package com.Eyal.code;
    import java.util.logging.Logger;

    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.PluginDescriptionFile;

    public class msgplugin extends JavaPlugin{
    public final Logger logger = Logger.getLogger("Minecraft");
    public static msg_test plugin;

    public void onDisable(){
    PluginDescriptionFile pdfFile = this.getDescription(); + " has been disabled!");
    public void onEnable(){
    PluginDescriptionFile pdfFile = this.getDescription(); + " version " + pdfFile.getVersion() + " has been enabled!");
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    Player target = getServer().getPlayer(args[0]);
    Player p = (Player)sender;
    if (cmd.getName().equalsIgnoreCase("msg")) {

    if(args.length < 2)
    sender.sendMessage(ChatColor.RED + "Not enough args!");


    String message = " ";

    for(int i = 0; i < args.length; i++)
    message += " " + args;

    target.sendMessage(ChatColor.GOLD + "[" + p.getDisplayName() + ChatColor.GOLD + " -> " + ChatColor.GRAY + "me" + ChatColor.GOLD + "]" + ChatColor.GRAY + message);
    sender.sendMessage(ChatColor.GOLD + "[" + ChatColor.GRAY + "me" + ChatColor.GOLD + " -> " + Bukkit.targetPlayer.getDisplayName() + ChatColor.GOLD + "]" + ChatColor.GRAY + message);



    this is the code, there are some errors and I can't fix them can someone help?
    #1 eyalfx, May 19, 2016
    Last edited: May 19, 2016
  2. Put it in code tags, hard to read.

    Also what ARE the errors?
    We're not magicians. Well, we are, but..
    • Like Like x 1
  3. This looks like the BC bro's work.. what error are you getting
    • Like Like x 1
  4. If you can't code Java, learn Java. Don't go on YouTube and learn Bukkit, use it to learn Java if you're going to be that lazy.
    • Agree Agree x 1
    • Winner Winner x 1
  5. I can code java but I can't understand what I did wrong
  6. I wrote this up to help you better understand with your onCommand class. Also don't worry about the loggers in your onEnable and onDisable methods. Those are old school :cool: :p

    Code (Text):
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
            // Here I check if the command example was typed and check if the sender of the command is a player
            // && is short for AND
            // eqalsIgnoreCase means it COULD be typed ExAMple and it wouldn't matter
            if(cmd.getName().equalsIgnoreCase("example") && sender instanceof Player) {
                // Always cast after checking if it's a player first else it does nothing. so basically the line above
                Player player = (Player) sender;
                // If X player has permission to perform the command
                if(player.hasPermission("random.permission")) {
                    player.sendMessage(ChatColor.YELLOW + "Example message");
                    return true; // return true because the player had permission and all we wanted to do was send the msg
                } else {
                    // else, they don't have permission or another exception occured during them typing the message
                    // meaning they could be the console instead of the player like we checked above.
                    player.sendMessage(ChatColor.RED + "No permission!");
            return false;
    • Friendly Friendly x 2
  7. No, you can't. You put a capital in the package, so you're definitely inexperienced. Being able to rip off YouTube videos does not mean you can code.

    This is your error anyways^ Remove the second bracket.
    #7 MineOrity, May 19, 2016
    Last edited: May 19, 2016
    • Like Like x 1
    • Agree Agree x 1
    • Put your code in code tags to make it easier to read.
    • Telling us you have an error isn't helpful at all. Where is it coming from? Is there a stack trace?
    • Name your packages in all lowercase and make them unique to your project, as stated by Java conventions.
    • Your class name shouldn't be lowercase, but instead, in ThisStyle.
    • Don't use Minecraft's logger, use the one provided with Bukkit with getLogger()
    • Name your variables in camelCase form, NOT like_this.
    • No need to send a message when the plugin is enabled/disabled, Bukkit does this for you.
    • What if the target isn't online? It will throw a NullPointerException if so.
    • What if the player doesn't provide any arguments? An ArrayIndexOutOfBoundsException will be thrown in this case.
    • Don't blindly cast the sender to a player. What if the sender isn't a player? What if the console executes the command? It will throw a ClassCastException if so.
    • What do you expect to happen? It's not a method so why are you making it one? It's a variable, not a method.
    • Learn Java.
    • Don't watch TheBCBroz.
    • Agree Agree x 4
    • Winner Winner x 4
    • Like Like x 2
  8. You won my medal since *cries* I always name my class thisStyle without noticing
    same as my variables, fields, methods

    Edit: ahh for the OP, try to learn Java ;)