Why isnt this working?

Discussion in 'Spigot Plugin Help' started by DocDrewskii, May 27, 2018.

  1. Im trying to figure out why this code is not working for me, I tried everything, but When I export it, then try the command, it doesnt work
    Code (Text):
          if (cmd.getName().equalsIgnoreCase("Sl")) {
              if (sender.hasPermission("StaffList.Reload")) {
                  if (args.length == 0) {
                      sender.sendMessage(ChatColor.GREEN + "/SL reload");
                      return true;
                  }

                  if (args[0].equalsIgnoreCase("Reload")) {
                      sender.sendMessage(ChatColor.GREEN + "StaffList reloaded");
                      Bukkit.getScheduler().cancelTasks(StaffList.getInstance());
                      StaffList.getInstance().reloadConfig();
                      StaffList.getInstance().saveConfig();
                      return true;
                  }
                  return false;
              }
             
        }
     
  2. Did you add the command to plugin.yml, does the player executing the command S1 have the permission 'StaffList.Reload'?
     
    • Useful Useful x 1
  3. Wow, Im really dumb, I forgot to add it to the plugin.yml... Thanks, Probrobly never would have figured that out cause its the most simpliest thing
     
  4. It still isnt working, I was going to go public with the sourcecode, so here is the full code
    Code (Text):
    package com.LilDevs.spigot;

    import java.util.ArrayList;
    import java.util.Iterator;
    import java.util.List;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;

    import net.md_5.bungee.api.chat.ClickEvent;
    import net.md_5.bungee.api.chat.ComponentBuilder;
    import net.md_5.bungee.api.chat.HoverEvent;
    import net.md_5.bungee.api.chat.TextComponent;

    public class StaffList
    extends JavaPlugin
    implements CommandExecutor
    {
    public void onEnable()
    {
      saveDefaultConfig();
    }

    public boolean onCommand(CommandSender sender, Command cmd, String msg, String[] args)
    {
      if ((sender instanceof Player))
      {
        Player p = (Player)sender;
        if ((!cmd.getName().equalsIgnoreCase("elist")) && (!cmd.getName().equalsIgnoreCase("list")) && (!cmd.getName().equalsIgnoreCase("estaff")) && (!cmd.getName().equalsIgnoreCase("who")) && (!cmd.getName().equalsIgnoreCase("ewho"))) {
          cmd.getName().equalsIgnoreCase("staff");
        }
        List<Player> staffs = new ArrayList<Player>();
        for (Player pls : Bukkit.getOnlinePlayers()) {
          if (pls.hasPermission("staff.allow")) {
            staffs.add(pls);
          }
        if (staffs.isEmpty())
        {
          for (String header1 : getConfig().getStringList("list.format-header"))
          {
            header1 = header1.replace("&", "�");
            p.sendMessage(header1);
          }
          for (String footer1 : getConfig().getStringList("list.format-footer"))
          {
            footer1 = footer1.replace("{online}", Integer.toString(Bukkit.getOnlinePlayers().size()));
            footer1 = footer1.replace("&", "�");
            p.sendMessage(footer1);
          }
          return false;
        }
        for (String header2 : getConfig().getStringList("list.format-header"))
        {
          header2 = header2.replace("&", "�");
          p.sendMessage(header2);
        }
        for (int i = 0; i != staffs.size(); i++)
        {
          Player t = (Player)staffs.get(i);
          TextComponent tp = new TextComponent(
            ChatColor.translateAlternateColorCodes('&', getConfig().getString("list.staff-format"))
            .replace("{player}", ((Player)t).getName()));
          for (String hover1 : getConfig().getStringList("hover.hover-commands"))
          {
            hover1 = hover1.replace("&", "�");
            hover1 = hover1.replace("{player}", ((Player)t).getName());
            tp.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, hover1));
          }
          for (String hover2 : getConfig().getStringList("hover.hover-messages"))
          {
            hover2 = hover2.replace("&", "�");
            tp.setHoverEvent(
              new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(hover2).create()));
          }
          p.spigot().sendMessage(tp);
        }
        for (Object t = getConfig().getStringList("list.format-footer").iterator(); ((Iterator<?>)t).hasNext();)
        {
          String footer1 = (String)((Iterator<?>)t).next();
          footer1 = footer1.replace("{online}", Integer.toString(Bukkit.getOnlinePlayers().size()));
          footer1 = footer1.replace("&", "�");
          p.sendMessage(footer1);
        }    if (cmd.getName().equalsIgnoreCase("StaffList")) {
            if (sender.hasPermission("StaffList.reload")) {
                if (args.length == 0) {
                    sender.sendMessage(ChatColor.GREEN + "/StaffList Reload");
                    return true;
                }

                if (args[0].equalsIgnoreCase("Reload")) {
                    sender.sendMessage(ChatColor.GREEN + "StaffList reloaded");
                    saveDefaultConfig();
                    reloadConfig();
                    return true;
            }
        }
        return false;
      }
      return false;
    }
    return false;
    }
    return false;
    }
    }
    Here is my config.yml
    Code (Text):
    list:
      format-header:
        - '&8▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬'
        - '&8» &7&o(Hover and click the user to join the server!)'
      format-footer:
        - ''
        - '&8&l» &7There''s currently &b{online} &7player''s online!'
        - '&8▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬'
      staff-format: '&8&l» &b{player} &3is logged onto &bFactions&3.'
     
    hover:
      hover-messages:
        - '&7Click to connect to &bFactions&7.'
      hover-commands:
        - ''
    Here is my plugin.yml:
    Code (Text):
    name: StaffList
    main: com.LilDevs.spigot.StaffList
    version: 1.1
    author: LilDevs
    commands:
      elist:
        description: See staff members that are currently online.
      list:
        description: See staff members that are currently online.
      estaff:
        description: See staff members that are currently online.
      staff:
        description: See staff members that are currently online.
      ewho:
        description: See staff members that are currently online.
      who:
        description: See staff members that are currently online.
      StaffList Reload:
        description: Reload the config.yml
      StaffList:
        description: USAGE: /StaffList Reload
    I honestly do not know what I did wrong, but maybe you would find out what I did wrong, Cause now /staff doesnt work anymore.
     
  5. DavidDevelops

    Supporter

    You gotta register the command correctly, (You forgot onenable too..) You should go read some tutorials but eitherways
     
  6. I have onEnable, and What do you mean registering the command, In the plugin.yml or the class?
     
  7. DavidDevelops

    Supporter

    Plugin YML:
    Code (Text):
    commands:
      command1:
        aliases: [ali1,ali2,ali2]
        description: Whatever you want
        usage: </command> // Leave  this like </command> and it will get command1
    For registering it how do you not know how?...
    getCommand("command1").setExecutor(new CommandClassName);
    also in my first comment i meant you forgot to register it in onenable oops <3