What am I doing wrong???

Discussion in 'Spigot Help' started by DrSpyros, Jun 28, 2021.

  1. I made a plugin but my commands do not work D: plz help (spigot)

    Code (Text):

    package com.drspyros.drfplugin.commands;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.attribute.Attribute;
    import org.bukkit.block.BrewingStand;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.HumanEntity;
    import org.bukkit.entity.Player;
    import java.util.Locale;

    public class DrFPluginCommands implements CommandExecutor {

        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if (!(sender instanceof Player)) {
                sender.sendMessage("Only players can use this command");
                return true;
            }

            if (cmd.getName().equalsIgnoreCase("yes")) {
                player.sendMessage(ChatColor.RED + "Y e s");
                return true;
            }

            if (cmd.getName().equalsIgnoreCase("DrPluginHelp")) {
                player.sendMessage("§e-----Commands-----");
                player.sendMessage("§eHelp page: /DrPluginHelp or /DrHelp");
                player.sendMessage("&eSummon a mob: /summon (mob) (amount)");
                player.sendMessage("§eFeed yourself (Get you hunger to full): /feed");
                player.sendMessage("§eHeal yourself (set your health to max): /heal)");
                player.sendMessage("§eSuicide: /suicide");
                player.sendMessage("§eGift someone the item you are holding: /gift (player) ");
                return true;
            }

            if (cmd.getName().equalsIgnoreCase("suicide")) {
                player.damage(1000);
                return true;
            }

            if (cmd.getName().equalsIgnoreCase("gift")) {
                Bukkit.getPlayerExact(args[0]);
                HumanEntity target = null;
                target.getInventory().addItem(player.getInventory().getItemInMainHand());
            }
           
            return true;
        }
    }
    [CODE]
     
  2. Did you register you commands in your main class and in your plugin.yml?

    Providing just your command class doesn't give us much information to go on.
     
  3. Here is my plugin.yml:

    Code (Text):

    name: DrPlugin
    version: 1.0
    author: DrSpyros
    main: com.drspyros.drfplugin.DrFPlugin
    api-version: 1.14
    commands:
        yes:
          description: yes
          usage: /<command>
          aliases: no
        help:
          description: It tells you all the commands
          usage: /<command>
          aliases: DrHelp
        suicide:
          description: suicide
          usage: /<command>
        gift:
          description: you gift someone an item
          usage: hold the item you want to gift and type /gift [name]
    [CODE]
     
  4. Did you register the commands in your main class?
     
  5. I always forget that tiny detail ;-;
    thank you very much for that!
    Hope you have a good day
     
    • Friendly Friendly x 1