Commands doesn't work

Discussion in 'Spigot Plugin Development' started by Seager_, May 28, 2017.

  1. Hello i have a problem commands doesn't work if they aren't in main class i wanted to make ban plugin here i s my:

    Main class:
    Code (Text):
    package me.fallcraft.core;


    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.plugin.java.JavaPlugin;
    import me.fallcraft.core.protect.Ban;

    public class Main extends JavaPlugin {
       
        FileConfiguration config = getConfig();

        public void onEnable(){
        getLogger().info("Loading FallCraft Core");
        getLogger().info("Loading Files");
        getServer().getPluginManager().registerEvents(new Ban(), null);
        getLogger().info("Loading Config");
        saveConfig();
        getLogger().info("Done");
       

    }
       
        public void onDisable(){
            getLogger().info("Stopping FallCraft Core");
            getLogger().info("SavingConfig");
            saveConfig();
           
           

        }







    }
    Ban class:

    Code (Text):
    package me.fallcraft.core.protect;

    import java.net.InetSocketAddress;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;

    import me.fallcraft.core.Main;



    public class Ban extends Main implements Listener {
        FileConfiguration config = getConfig();
        public boolean onCommand(CommandSender sender, Command command, String alias, String[] args) {
           
            //Zkratky pro Barvy
            ChatColor red = ChatColor.RED;
            ChatColor gold = ChatColor.GOLD;  
            ChatColor white = ChatColor.WHITE;
           
            //KickedBanMessage
            String kicked = ChatColor.RED + "Přístup k tomuto serveru ti byl navždy odepřen!" + "                                    " + ChatColor.GREEN + "Jestli chceš unban jdi na www.fallcraft.smsmc.net";
           
            //prefix
            String prefix = red + "[" + gold + "BAN" + red + "]" + white; //prefix
           
            //Permise
            if(sender.hasPermission("fallcraft.ban")){
           
               
                //command /ban
                if(alias.equalsIgnoreCase("sban")){
               
                    //pokud hráč napíše jen /ban
                    if(args[0].length() == 0){
                    sender.sendMessage( prefix + white + " Musíte zadat jméno hráče /ban <hráč>" );
                    return true;
                    }
                    else{
                        String target = Bukkit.getPlayerExact(args[0]).getName();
                        config.set(target, true);
                        Player player = Bukkit.getPlayerExact(args[0]);
                        InetSocketAddress ip = player.getAddress();
                        config.set(target + "ip", ip);
                        player.kickPlayer(kicked);
                   
                    }
               
               
                }
         
    }
            else{
                sender.sendMessage( prefix + red + " Na toto nemáš oprávnění" );  
            return true;
            }
       
        return true;

        }
    }
     
    plugin.yml:
    Code (Text):
    name: FallCraftCore
    main: me.fallcraft.core.Main
    version: 1.0
    commands:
       sban:
          description: Da hracovi Ban.
          usage: /<command>
    And if i type /sban in chat it only writes /sban please help!!!
     
  2. change "return true;" to "return false;"