Solved Problem with my plugin

Discussion in 'Plugin Development' started by Koyote_059, May 20, 2018.

Thread Status:
Not open for further replies.
  1. Offline

    Koyote_059

    Hey, i'm new in bukkit developing. I'm trying to create a faction plugin. I create the command /f create but I have a problem: it doesn't work. Now i'll explain why.
    First of all, when I tryed to make the server start, the plugin wasn't loaded. Then i tryed to delete the "commands" part in the yml file the plugin was loaded, but the commands I created didn't work. So... any advice? Here are the codes that could be useful:

    File yml:
    Code:
    name: NewFactions
    author: Koyote_059
    version: 1.0
    description: plugin
    main: it.ss.factionplugin.koyote.NewFactions
    commands:
        f: 
            description: Fazioni
            usage: f 
    
    Main Class:
    Code:
    package it.ss.factionplugin.koyote;
    
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class NewFactions extends JavaPlugin {
        @Override
        public void onEnable(){
            loadConfig();
            registerCommands();
        }
       
        @Override
        public void onDisable() {
           
        }
       
       
        private void loadConfig() {
            getConfig().options().copyDefaults(true);
            saveConfig();
        }
       
        private void registerCommands() {
            getCommand("f").setExecutor(new cmds());
        }
       
    }
    
    Command class:
    Code:
    package it.ss.factionplugin.koyote;
    
    import java.awt.Color;
    
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    
     public class cmds implements CommandExecutor{
        private NewFactions plugin = new NewFactions();
       
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
           
               
                if(label.equalsIgnoreCase("f") && sender instanceof Player) {
                    Player player = (Player) sender;
                    if(args[0].equalsIgnoreCase("create")) {
                        if(args.length == 2) {
                            if(args[1].length()>3 && args[1].length() <11) {
                                plugin.getConfig().set("NameFaction_" + args[1] + ".Player_"+ player.getUniqueId() , "Factions:");
                                player.sendMessage(Color.GREEN + "Fazione "  + args[1] + " creata!");
                            } else {
                                sender.sendMessage(ChatColor.RED + "Il nome della fazione deve contenere dai 3 ai 10 caratteri");
                            }       
                        } else {
                            sender.sendMessage("Sintassi corretta: " + Color.GREEN + "/f create [nome]");
                        }
                    }
                    return true;
                }
            return false;
        }
    }
     
    Last edited by a moderator: May 20, 2018
  2. Offline

    Machine Maker

    The commands for the plugins will not work if the plugin did not load when you started the server. Is there a console error when you start up the server? Also, make sure the plugin.yml has the correct main class.
     
  3. Offline

    Koyote_059

    It Says that the yml file is invalid, I don't know why... It says something about the description in the first lines of error

    I solved the Yml problem, but the command doesn't start working

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 21, 2018
  4. Offline

    KarimAKL

    @Koyote_059 I don't know if this could be the problem but you are checking if arg 0 is "create" before checking if it is set.
     
  5. Offline

    Koyote_059

    Solved, thank you all.
     
  6. Offline

    KarimAKL

    @Koyote_059 Good to know, now please change the title prefix to solved. :)
     
Thread Status:
Not open for further replies.

Share This Page