Command Wont work

Discussion in 'Plugin Development' started by Joshua Neicho, Mar 14, 2011.

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

    Joshua Neicho

    Hi,
    if you could please look at my code since it is pissing me off
    Application.java

    Code:
    package com.JWNJWN.Application;
    
    import java.io.File;
    
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.player.PlayerEvent;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Application extends JavaPlugin {
    	static String maindirectory = "plugins/Application/";
    
    	public void onEnable() {
    		new File(maindirectory).mkdirs();
    
    		LoadSettings.loadMain();
    
    		PluginDescriptionFile pdfFile = getDescription();
    		System.out.println(pdfFile.getName() + " version "
    				+ pdfFile.getVersion() + " is enabled!");}
        public boolean onCommand(CommandSender sender, Command cmd,
                PlayerEvent event, String commandLabel, String[] args) {
            Player player = event.getPlayer();
            if (cmd.getName().compareToIgnoreCase("apply") == 0) {
    
                player.sendMessage(LoadSettings.ApplyOne);
                player.sendMessage(LoadSettings.ApplyTwo);
                player.sendMessage(LoadSettings.ApplyThree);
                player.sendMessage(LoadSettings.ApplyFour);
                player.sendMessage(LoadSettings.ApplyFive);
                player.sendMessage(LoadSettings.ApplySix);
            }
            return true;
    		}
    
    	public void onDisable() {
    	}
    
    }
    
    LoadSettings.java
    Code:
    package com.JWNJWN.Application;
    
    import org.bukkit.ChatColor;
    
    public class LoadSettings {
        static ChatColor Red;
        static String ApplyOne;
        static String ApplyTwo;
        static String ApplyThree;
        static String ApplyFour;
        static String ApplyFive;
        static String ApplySix;
        static String TeamOne;
    
        public static void loadMain() {
            String propertiesFile = Application.maindirectory
                    + "Application.properties";
            PluginProperties properties = new PluginProperties(propertiesFile);
            properties.load();
    
            Red = ChatColor.RED;
    
            ApplyOne = properties
                    .getString("Apply Line One", "Write Line One Here");
            ApplyTwo = properties
                    .getString("Apply Line Two", "Write Line Two Here");
            ApplyThree = properties.getString("Apply Line Three",
                    "Write Line Three Here");
            ApplyFour = properties.getString("Apply Line Four",
                    "Write Line Four Here");
            ApplyFive = properties.getString("Apply Line Five",
                    "Write Line Five Here");
            ApplySix = properties
                    .getString("Apply Line Six", "Write Line Six Here");
            properties.save("===Application & Teams Configuration===");
    
        }
    
    }
    
    PluginProperties.java
    Code:
    package com.JWNJWN.Application;
    
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.util.Properties;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    
    public class PluginProperties extends Properties {
        static final long serialVersionUID = 0L;
        static final Logger log = Logger.getLogger("minecraft");
        private String fileName;
    
        public PluginProperties(String file) {
            this.fileName = file;
        }
    
        public void load() {
            File file = new File(this.fileName);
            if (file.exists()) {
                try {
                    load(new FileInputStream(this.fileName));
                } catch (IOException ex) {
                    log.log(Level.SEVERE, "Unable to load " + this.fileName, ex);
                }
            }
        }
    
        public void save(String start) {
            try {
                store(new FileOutputStream(this.fileName), start);
            } catch (IOException ex) {
                log.log(Level.SEVERE, "Unable to save " + this.fileName, ex);
            }
        }
    
        public int getInteger(String key, int value) {
            if (containsKey(key)) {
                return Integer.parseInt(getProperty(key));
            }
    
            put(key, String.valueOf(value));
            return value;
        }
    
        public double getDouble(String key, double value) {
            if (containsKey(key)) {
                return Double.parseDouble(getProperty(key));
            }
    
            put(key, String.valueOf(value));
            return value;
        }
    
        public String getString(String key, String value) {
            if (containsKey(key)) {
                return getProperty(key);
            }
    
            put(key, value);
            return value;
        }
    
        public boolean getBoolean(String key, boolean value) {
            if (containsKey(key)) {
                String boolString = getProperty(key);
                return (boolString.length() > 0)
                        && (boolString.toLowerCase().charAt(0) == 't');
            }
            put(key, value ? "true" : "false");
            return value;
        }
    
    }
    plugin.yml
    Code:
    name: Application & Teams
    main: com.JWNJWN.Application.Application
    version: 0.1
    author: JWNJWN
    description: Application And Team Information for mcteamwars.tk
    commands:
        apply:
            description: Applications instructions
            usage: /<command>
    Thank You
     
  2. Offline

    Edward Hand

    1) Have you registered the command in your plugin.yml?
    2) 'wont work' isn't very specific. Are there error messages? What is it about that is wrong?
     
  3. Offline

    Crash

    Also, onCommand goes in your main class.
     
  4. Offline

    Joshua Neicho

    @Edward Hand no it just returns the command, ie. i type /apply and it return /apply

    @Crash k will try that now
     
  5. Offline

    Joshua Neicho

    still doesnt work just replies /apply
     
  6. Offline

    Edward Hand

    Let's see your new code and your plugin.yml
     
  7. Offline

    Joshua Neicho

    edited main post i have only changed the main class removed the player listener and added the plugin.yml so you dont scan through them all
     
  8. Offline

    Edward Hand

    Your onCommand function needs to have the follow arguments:

    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
    {
    
    }
    The player sending the command is sender.
    The command used is given by commandLabel
    Extra parameters given after the command are in args.
     
  9. Offline

    Joshua Neicho

    so this should work?
    Code:
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args, PlayerEvent event)
        {
            Player player = event.getPlayer();
            if (cmd.getName().compareToIgnoreCase("apply") == 0) {
    
                player.sendMessage(LoadSettings.ApplyOne);
                player.sendMessage(LoadSettings.ApplyTwo);
                player.sendMessage(LoadSettings.ApplyThree);
                player.sendMessage(LoadSettings.ApplyFour);
                player.sendMessage(LoadSettings.ApplyFive);
                player.sendMessage(LoadSettings.ApplySix);
            }
            return true;
            }
     
  10. Offline

    Edward Hand

    You can't just add an extra PlayerEvent parameter like that and expect it to work (so no).
     
Thread Status:
Not open for further replies.

Share This Page