1.14.4 New to coding, need some help.

Discussion in 'Spigot Plugin Development' started by KingUmbreon56, Mar 20, 2020.

  1. So I'm taking an udemy course on coding plugins, and they have the following code which I copied:
    Code (Java):
    package com.alex.plugin;

    import com.mojang.brigadier.Command;

    import net.md_5.bungee.api.ChatColor;
    import net.minecraft.server.v1_14_R1.EntityTNTPrimed;

    import javax.swing.text.html.parser.Entity;

    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.plugin.java.JavaPlugin;

    public class Main extends JavaPlugin{
       
        @Override
        public void onEnable() {
            System.out.println("Plugin enabled!");
        }
       
        @Override
        public void onDisable() {
            System.out.println("Plugin disabled!");
           
        }
       
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
           
            if (cmd.getName().equals("heal")) {
                if (sender instanceof Player) {
                    Player player = (Player) sender;
                    player.sendMessage(ChatColor.DARK_AQUA  + "Hello, " + ChatColor.DARK_GREEN + player.getName() + ChatColor.GREEN + "!");
                    player.setHealth(20.0);
                } else {
                    System.out.println("You cannot use this command through console!");
                }
               
               
            }
            return false;
       
        }
    }
           
    Problem is, the line "if (cmd.getName().equals("heal")) {" gives me an error message. Is this because im coding 1.14.4 spigot and the guy is using 1.11.2 (he said it would work with any future versions)?

    Can anyone help? I'm extremely new to both java and spigot, I've mainly just used Python in the past.

    Regards, Alex
     
  2. Strahan

    Benefactor

    There shouldn't be any issue with that; what is the error message?
     
  3. The method getName() is undefined for the type Command. It gives me the option to 'add cast' which resolves the error but when I load up the plugin, my command does nothing when run. It's registered in /help, but it does nothing.

    EDIT: Not sure if this is related, but on line 24, where it says 'Command cmd', Command has a minor error saying its a raw type.
     
  4. you imported the wrong command
    looking for org.bukkit command, not mojang's
     
  5. Thank you! This fixed it!
     
  6. looking at your other imports, you imported the wrong entity, you should import the bukkit chatcolor, and i question the need to import a nms entitytntprimed

    /e i saw that ninja delete
     
  7. While were on the subject you'r most likely to learn more from the tutorials out on youtube(there are alot) with practical use and everything
     
  8. Its looks like the source codes.