Solved Command problems

Discussion in 'Plugin Development' started by vhbob, Dec 3, 2015.

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

    vhbob

    Hello, i am having issues with my command, whenever i use it, it does not work please help me D:
    Code:
    package com.vhbob.vc;
    
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class VCMain extends JavaPlugin implements Listener {
    
        public void onEnable() {
            getServer().getPluginManager().registerEvents(this, this);
        }
    
        @EventHandler
        public void onJoin(PlayerJoinEvent e) {
            Player p = e.getPlayer();
            if (!(getConfig().contains(p.getName() + "Bal"))) {
                getConfig().set(p.getName() + "Bal", 0);
            }
        }
    
        @Override
        public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
            if (sender instanceof Player) {
                Player p = (Player) sender;
                int bal = getConfig().getInt(p.getName() + "Bal");
                if (label.equalsIgnoreCase("balance")) {
                    p.sendMessage(ChatColor.GRAY + "You have " + ChatColor.GOLD + bal + ChatColor.GRAY + " VC");
                }
            } else {
                sender.sendMessage(ChatColor.RED + "You are not a player!");
            }
            return false;
        }
    
    }
    plugin.yml< Also, the aliases do not work D:
    Code:
    name: VCurrency
    main: com.vhbob.vc.VCMain
    author: Vhbob
    version: 1.0
    description: a custom currency plugin
    commands:
      balance:
        aliases: [money, bal, vc]
        description: Shows you you're VC balance
        
     
  2. Offline

    Scimiguy

    use cmd.getName() instead of label.
     
  3. Offline

    vhbob

    @Scimiguy okay, it still doesn't create a config, but that fixed the main issue
     
  4. Offline

    Scimiguy

    You never said anything about a config not generating.
    What config?
     
  5. Offline

    Zombie_Striker

    So you set values to the config without saving the config? The way you generate the config is by saving it.
     
Thread Status:
Not open for further replies.

Share This Page