Command not registering? No errors

Discussion in 'Plugin Development' started by Treeline1, Jan 19, 2015.

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

    Treeline1

    ATM I am trying to make a currency system blah blah blah. They buy kits by doing /buy(kit).
    For some reason when I do /buyscout for example it doesnt work! Can anyone tell me why? I've tried debugging but nothing comes up for some reason. Thanks
    Code:
    package me.liam.main;
    
    
    
    import java.util.ArrayList;
    
    import me.liam.commands.ArcherCommand;
    import me.liam.commands.ChestCommand;
    import me.liam.commands.FishermanCommand;
    import me.liam.commands.HopperCommand;
    import me.liam.commands.JuggernautCommand;
    import me.liam.commands.KitCommand;
    import me.liam.commands.MarioCommand;
    import me.liam.commands.Menu;
    import me.liam.commands.PilotCommand;
    import me.liam.commands.RageCommand;
    import me.liam.commands.ScoutCommand;
    import me.liam.commands.SniperCommand;
    import me.liam.commands.SoupCommand;
    import me.liam.commands.SpawnCommand;
    import me.liam.commands.SquashCommand;
    import me.liam.commands.SquidCommand;
    import me.liam.event.BlockListener;
    import me.liam.event.DamageListener;
    import me.liam.event.InventoryListener;
    import me.liam.event.KillstreakEvent;
    import me.liam.event.PlayerListener;
    import net.milkbowl.vault.economy.Economy;
    import net.milkbowl.vault.economy.EconomyResponse;
    import net.milkbowl.vault.permission.Permission;
    
    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.permissions.PermissionAttachmentInfo;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.RegisteredServiceProvider;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Kitpvp extends JavaPlugin implements CommandExecutor {
    
    
        public static Economy econ = null;
        public static Kitpvp inst;
        public static Permission permission = null;
        private Menu menu;
    
        private boolean setupPermissions() {
            RegisteredServiceProvider<Permission> rsp = getServer().getServicesManager().getRegistration(Permission.class);
            permission = rsp.getProvider();
            return permission != null;
        }
    
       
    
        private PlayerListener Events = new PlayerListener(this);
        public ArrayList<String> KitCommand = new ArrayList<String>();
        public ArrayList<String> SniperCommand = new ArrayList<String>();
        public ArrayList<String> HopperCommand = new ArrayList<String>();
        public ArrayList<String> RageCommand = new ArrayList<String>();
        public ArrayList<String> FishermanCommand = new ArrayList<String>();
        public ArrayList<String> PilotCommand = new ArrayList<String>();
        public ArrayList<String> MarioCommand = new ArrayList<String>();
        public ArrayList<String> ScoutCommand = new ArrayList<String>();
        public ArrayList<String> ArcherCommand = new ArrayList<String>();
        public ArrayList<String> SquashCommand = new ArrayList<String>();
        public ArrayList<String> SoupCommand = new ArrayList<String>();
        public ArrayList<String> ChestCommand = new ArrayList<String>();
        public ArrayList<String> SquidCommand = new ArrayList<String>();
        public ArrayList<String> BatmanCommand = new ArrayList<String>();
        public ArrayList<String> JuggernautCommand = new ArrayList<String>();
        public ArrayList<String> kitused = new ArrayList<String>();
    
    
        @Override
        public void onEnable() {
            PluginManager pm = getServer().getPluginManager();
            inst = this;
            menu = new Menu(this);
            if (!setupEconomy() ) {
                getLogger().severe(String.format("[%s] - Disabled due to no Vault dependency found!", getDescription().getName()));
                getServer().getPluginManager().disablePlugin(this);
                return;
            }
    
            Bukkit.getServer().getPluginManager().registerEvents(menu, this);
            pm.registerEvents(new DamageListener(), this);
            pm.registerEvents(new BlockListener(), this);
            pm.registerEvents(new InventoryListener(), this);
            pm.registerEvents(new PlayerListener(this), this);
            pm.registerEvents(new HopperCommand(this), this);
            pm.registerEvents(new JuggernautCommand(this), this);
            pm.registerEvents(new RageCommand(this), this);
            pm.registerEvents(new MarioCommand(this), this);
            pm.registerEvents(new PilotCommand(this), this);
            pm.registerEvents(new SquidCommand(this), this);
            pm.registerEvents(new FishermanCommand(this), this);
            pm.registerEvents(new SniperCommand(this), this);
            pm.registerEvents(new KillstreakEvent(this), this);
            pm.registerEvents(new Menu(this), this);
            pm.registerEvents(new SquashCommand(this), this);
            getCommand("archer").setExecutor(new ArcherCommand(this));
            getCommand("mario").setExecutor(new MarioCommand(this));
            getCommand("squash").setExecutor(new SquashCommand(this));
            getCommand("hopper").setExecutor(new HopperCommand(this));
            getCommand("pilot").setExecutor(new PilotCommand(this));
            getCommand("rage").setExecutor(new RageCommand(this));
            getCommand("pvp").setExecutor(new KitCommand(this));
            getCommand("scout").setExecutor(new ScoutCommand(this));
            getCommand("sniper").setExecutor(new SniperCommand(this));
            getCommand("squid").setExecutor(new SquidCommand(this));
            getCommand("fisherman").setExecutor(new FishermanCommand(this));
            getCommand("buyfisherman").setExecutor(new FishermanCommand(this));
            getCommand("buyscout").setExecutor(new FishermanCommand(this));
            getCommand("buypilot").setExecutor(new FishermanCommand(this));
            getCommand("juggernaut").setExecutor(new JuggernautCommand(this));
            getCommand("chest").setExecutor(new ChestCommand(this));
            getCommand("soup").setExecutor(new SoupCommand());
            getCommand("spawn").setExecutor(new SpawnCommand());
    
    
    
    
    
            System.out.println("KitPVP Enabled!");
        }
    
    
    
        public void onDisabled(){
            System.out.println("KitPVP Disabled!");
        }
        public void events() {
            PluginManager pm = getServer().getPluginManager();
            pm.registerEvents(this.Events, this);
        }
    
    
        private boolean setupEconomy() {
            if (getServer().getPluginManager().getPlugin("Vault") == null) {
                return false;
            }
            RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
            if (rsp == null) {
                return false;
            }
            econ = rsp.getProvider();
            return econ != null;
        }
    
    
    
        public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
            Player player = null;
            if (sender instanceof Player){
                player = (Player) sender;
            }
    
            if (command.getName().equalsIgnoreCase("buyfisherman")){
                if (player != null){
                    EconomyResponse r = econ.withdrawPlayer(player.getName(), 10);
                    if (r.transactionSuccess()) {
                         permission.playerAddTransient(player,"fisherman.set");
                            player.sendMessage(ChatColor.RED + "You bought the Fisherman kit!");
                    }
                   
                }
            }else
                if (command.getName().equalsIgnoreCase("buyscout")){
                    if (player != null){
                        EconomyResponse r = econ.withdrawPlayer(player.getName(), 10);
                        if (r.transactionSuccess()) {
                             permission.playerAddTransient(player,"scout.set");
                                player.sendMessage(ChatColor.RED + "You bought the Scout kit!");
                        }
                    }
                }else
                    if (command.getName().equalsIgnoreCase("buypilot")){
                        EconomyResponse r = econ.withdrawPlayer(player.getName(), 10);
                        if (r.transactionSuccess()) {
                             permission.playerAddTransient(player,"pilot.set");
                                player.sendMessage(ChatColor.RED + "You bought the Pilot kit!");
                        }
                    }
    
            return true;
        }
    
    }
    
     
  2. Offline

    q8minecraft

    Did you add the commands in the plugin.yml file ?
     
  3. Offline

    Treeline1

    ya

    DERP! I had the wrong class typed in xD Stupid me. but nowwww its giveing me an error :p
    Code:
            getCommand("buyfisherman").setExecutor(new Kitpvp());
            getCommand("buyscout").setExecutor(new Kitpvp());
            getCommand("buypilot").setExecutor(new Kitpvp());
    Thats my code that it gives the error from, and this is the error
    http://imgur.com/2aLuxnj
    Im assuming it cant register its own command in its class or some crap... Any thoughts?

    EDIT by Timtower: merged posts
     
    Last edited by a moderator: Jan 20, 2015
  4. try with
    Code:java
    1.  
    2. getCommand("buyfishman").setExuctor(new Kitpvp(this));
    3.  

    Also you can use args instead of creating a command for every kit .
    If you wanna register the events on easier way :
    Code:java
    1.  
    2. public static void registerEvents(org.bukkit.plugin.Plugin plugin, Listener... listeners) {
    3. for (Listener listener : listeners) {
    4. Bukkit.getServer().getPluginManager().registerEvents(listener, plugin);
    5. } }
    6. //On enable
    7. public void onEnable() {
    8. registerEvents(this, eventClass(This);
    9. }
    10.  
     
    Last edited: Jan 20, 2015
  5. Offline

    Treeline1

    Naa tried that. The error with that is:
    The constructor Kitpvp(Kitpvp) is undefined
    @MaTaMoR_
     
  6. So create the constructor..
     
  7. Offline

    Treeline1

    that breaks the plugin completely :p
    Code:
    package me.liam.main;
    
    
    
    import java.util.ArrayList;
    
    import me.liam.commands.ArcherCommand;
    import me.liam.commands.ChestCommand;
    import me.liam.commands.FishermanCommand;
    import me.liam.commands.HopperCommand;
    import me.liam.commands.JuggernautCommand;
    import me.liam.commands.KitCommand;
    import me.liam.commands.MarioCommand;
    import me.liam.commands.Menu;
    import me.liam.commands.PilotCommand;
    import me.liam.commands.RageCommand;
    import me.liam.commands.ScoutCommand;
    import me.liam.commands.SniperCommand;
    import me.liam.commands.SoupCommand;
    import me.liam.commands.SpawnCommand;
    import me.liam.commands.SquashCommand;
    import me.liam.commands.SquidCommand;
    import me.liam.event.BlockListener;
    import me.liam.event.DamageListener;
    import me.liam.event.InventoryListener;
    import me.liam.event.KillstreakEvent;
    import me.liam.event.PlayerListener;
    import net.milkbowl.vault.economy.Economy;
    import net.milkbowl.vault.economy.EconomyResponse;
    import net.milkbowl.vault.permission.Permission;
    
    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.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.PlayerDeathEvent;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.RegisteredServiceProvider;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Kitpvp extends JavaPlugin implements CommandExecutor, Listener{
    
    
        public static Economy econ = null;
        public static Kitpvp inst;
        public static Permission permission = null;
        private Menu menu;
    
        private Kitpvp plugin;
    
        public Kitpvp(Kitpvp instance)
        {
            this.plugin = instance;
        }
    
    
        private boolean setupPermissions() {
            RegisteredServiceProvider<Permission> rsp = getServer().getServicesManager().getRegistration(Permission.class);
            permission = rsp.getProvider();
            return permission != null;
        }
    
    
    
        private PlayerListener Events = new PlayerListener(this);
        public ArrayList<String> KitCommand = new ArrayList<String>();
        public ArrayList<String> SniperCommand = new ArrayList<String>();
        public ArrayList<String> HopperCommand = new ArrayList<String>();
        public ArrayList<String> RageCommand = new ArrayList<String>();
        public ArrayList<String> FishermanCommand = new ArrayList<String>();
        public ArrayList<String> PilotCommand = new ArrayList<String>();
        public ArrayList<String> MarioCommand = new ArrayList<String>();
        public ArrayList<String> ScoutCommand = new ArrayList<String>();
        public ArrayList<String> ArcherCommand = new ArrayList<String>();
        public ArrayList<String> SquashCommand = new ArrayList<String>();
        public ArrayList<String> SoupCommand = new ArrayList<String>();
        public ArrayList<String> ChestCommand = new ArrayList<String>();
        public ArrayList<String> SquidCommand = new ArrayList<String>();
        public ArrayList<String> BatmanCommand = new ArrayList<String>();
        public ArrayList<String> JuggernautCommand = new ArrayList<String>();
        public ArrayList<String> kitused = new ArrayList<String>();
    
        @Override
        public void onEnable() {
            PluginManager pm = getServer().getPluginManager();
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
            inst = this;
            menu = new Menu(this);
            if (!setupEconomy() ) {
                getLogger().severe(String.format("[%s] - Disabled due to no Vault dependency found!", getDescription().getName()));
                getServer().getPluginManager().disablePlugin(this);
                return;
            }
    
            Bukkit.getServer().getPluginManager().registerEvents(menu, this);
            pm.registerEvents(new DamageListener(), this);
            pm.registerEvents(new BlockListener(), this);
            pm.registerEvents(new InventoryListener(), this);
            pm.registerEvents(new PlayerListener(this), this);
            pm.registerEvents(new HopperCommand(this), this);
            pm.registerEvents(new JuggernautCommand(this), this);
            pm.registerEvents(new RageCommand(this), this);
            pm.registerEvents(new MarioCommand(this), this);
            pm.registerEvents(new PilotCommand(this), this);
            pm.registerEvents(new SquidCommand(this), this);
            pm.registerEvents(new FishermanCommand(this), this);
            pm.registerEvents(new SniperCommand(this), this);
            pm.registerEvents(new KillstreakEvent(this), this);
            pm.registerEvents(new Menu(this), this);
            pm.registerEvents(new SquashCommand(this), this);
            getCommand("archer").setExecutor(new ArcherCommand(this));
            getCommand("mario").setExecutor(new MarioCommand(this));
            getCommand("squash").setExecutor(new SquashCommand(this));
            getCommand("hopper").setExecutor(new HopperCommand(this));
            getCommand("pilot").setExecutor(new PilotCommand(this));
            getCommand("rage").setExecutor(new RageCommand(this));
            getCommand("pvp").setExecutor(new KitCommand(this));
            getCommand("scout").setExecutor(new ScoutCommand(this));
            getCommand("sniper").setExecutor(new SniperCommand(this));
            getCommand("squid").setExecutor(new SquidCommand(this));
            getCommand("fisherman").setExecutor(new FishermanCommand(this));
            getCommand("buyfishman").setExecutor(new Kitpvp(this));
            getCommand("buyscout").setExecutor(new Kitpvp(this));
            getCommand("buypilot").setExecutor(new Kitpvp(this));
            getCommand("juggernaut").setExecutor(new JuggernautCommand(this));
            getCommand("chest").setExecutor(new ChestCommand(this));
            getCommand("soup").setExecutor(new SoupCommand());
            getCommand("spawn").setExecutor(new SpawnCommand());
    
    
    
    
    
            System.out.println("KitPVP Enabled!");
        }
    
    
    
        public void onDisabled(){
            System.out.println("KitPVP Disabled!");
        }
        public void events() {
            PluginManager pm = getServer().getPluginManager();
            pm.registerEvents(this.Events, this);
        }
    
    
        private boolean setupEconomy() {
            if (getServer().getPluginManager().getPlugin("Vault") == null) {
                return false;
            }
            RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
            if (rsp == null) {
                return false;
            }
            econ = rsp.getProvider();
            return econ != null;
        }
    
    
    
        public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
            Player player = null;
            if (sender instanceof Player){
                player = (Player) sender;
            }
    
            if (command.getName().equalsIgnoreCase("buyfisherman")){
                if (player != null){
                    EconomyResponse r = econ.withdrawPlayer(player.getName(), 10);
                    if (r.transactionSuccess()) {
                        permission.playerAddTransient(player,"fisherman.set");
                        player.sendMessage(ChatColor.RED + "You bought the Fisherman kit!");
                    }
    
                }
            }else
                if (command.getName().equalsIgnoreCase("buyscout")){
                    if (player != null){
                        EconomyResponse r = econ.withdrawPlayer(player.getName(), 10);
                        if (r.transactionSuccess()) {
                            permission.playerAddTransient(player,"scout.set");
                            player.sendMessage(ChatColor.RED + "You bought the Scout kit!");
                        }
                    }
                }else
                    if (command.getName().equalsIgnoreCase("buypilot")){
                        EconomyResponse r = econ.withdrawPlayer(player.getName(), 10);
                        if (r.transactionSuccess()) {
                            permission.playerAddTransient(player,"pilot.set");
                            player.sendMessage(ChatColor.RED + "You bought the Pilot kit!");
                        }
                    }
    
            return true;
        }
    
    
        @EventHandler
        public void onPlayerDeath(PlayerDeathEvent event){
            if(event.getEntity() instanceof Player) {
                Player p = (Player) event.getEntity().getPlayer();
                if(event.getEntity().getKiller() instanceof Player) {
                    econ.depositPlayer(p.getKiller(), 80);
                }
    
            }
        }
    }
    
    
    
    http://imgur.com/UZHabd7
     
  8. If you gonna use a command in main class you don't have to set command executor and implements CommandExecutor ... If it does not work is cause of you, use [.syntax=java] [./syntax] instead of [.code] [./code]
     
  9. Offline

    Lolmewn

    Instead of doing new Kitpvp(this), just use this. There's no need to make new Kitpvp instances.
    EDIT: Quick-tip: JavaPlugin is a CommandExecutor and is the default class to execute your plugins commands. E.g. if you haven't specified where they should be executed, it'll always call onCommand in your main class.
     
  10. Offline

    Treeline1

    @Lolmewn
    @MaTaMoR_
    Ok so.... I took your guys advice, got rid of CommandExcecutor and did the "this". I am still getting an error though
    Code:
    package me.liam.main;
    
    
    
    import java.util.ArrayList;
    
    import me.liam.commands.ArcherCommand;
    import me.liam.commands.ChestCommand;
    import me.liam.commands.FishermanCommand;
    import me.liam.commands.HopperCommand;
    import me.liam.commands.JuggernautCommand;
    import me.liam.commands.KitCommand;
    import me.liam.commands.MarioCommand;
    import me.liam.commands.Menu;
    import me.liam.commands.PilotCommand;
    import me.liam.commands.RageCommand;
    import me.liam.commands.ScoutCommand;
    import me.liam.commands.SniperCommand;
    import me.liam.commands.SoupCommand;
    import me.liam.commands.SpawnCommand;
    import me.liam.commands.SquashCommand;
    import me.liam.commands.SquidCommand;
    import me.liam.event.BlockListener;
    import me.liam.event.DamageListener;
    import me.liam.event.InventoryListener;
    import me.liam.event.KillstreakEvent;
    import me.liam.event.PlayerListener;
    import net.milkbowl.vault.economy.Economy;
    import net.milkbowl.vault.economy.EconomyResponse;
    import net.milkbowl.vault.permission.Permission;
    
    import org.bukkit.Bukkit;
    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.entity.PlayerDeathEvent;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.RegisteredServiceProvider;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Kitpvp extends JavaPlugin implements Listener{
    
    
        public static Economy econ = null;
        public static Kitpvp inst;
        public static Permission permission = null;
        private Menu menu;
    
        private boolean setupPermissions() {
            RegisteredServiceProvider<Permission> rsp = getServer().getServicesManager().getRegistration(Permission.class);
            permission = rsp.getProvider();
            return permission != null;
        }
    
    
    
        private PlayerListener Events = new PlayerListener(this);
        public ArrayList<String> KitCommand = new ArrayList<String>();
        public ArrayList<String> SniperCommand = new ArrayList<String>();
        public ArrayList<String> HopperCommand = new ArrayList<String>();
        public ArrayList<String> RageCommand = new ArrayList<String>();
        public ArrayList<String> FishermanCommand = new ArrayList<String>();
        public ArrayList<String> PilotCommand = new ArrayList<String>();
        public ArrayList<String> MarioCommand = new ArrayList<String>();
        public ArrayList<String> ScoutCommand = new ArrayList<String>();
        public ArrayList<String> ArcherCommand = new ArrayList<String>();
        public ArrayList<String> SquashCommand = new ArrayList<String>();
        public ArrayList<String> SoupCommand = new ArrayList<String>();
        public ArrayList<String> ChestCommand = new ArrayList<String>();
        public ArrayList<String> SquidCommand = new ArrayList<String>();
        public ArrayList<String> BatmanCommand = new ArrayList<String>();
        public ArrayList<String> JuggernautCommand = new ArrayList<String>();
        public ArrayList<String> kitused = new ArrayList<String>();
    
        @Override
        public void onEnable() {
            PluginManager pm = getServer().getPluginManager();
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
            inst = this;
            menu = new Menu(this);
            if (!setupEconomy() ) {
                getLogger().severe(String.format("[%s] - Disabled due to no Vault dependency found!", getDescription().getName()));
                getServer().getPluginManager().disablePlugin(this);
                return;
            }
    
            Bukkit.getServer().getPluginManager().registerEvents(menu, this);
            pm.registerEvents(new DamageListener(), this);
            pm.registerEvents(new BlockListener(), this);
            pm.registerEvents(new InventoryListener(), this);
            pm.registerEvents(new PlayerListener(this), this);
            pm.registerEvents(new HopperCommand(this), this);
            pm.registerEvents(new JuggernautCommand(this), this);
            pm.registerEvents(new RageCommand(this), this);
            pm.registerEvents(new MarioCommand(this), this);
            pm.registerEvents(new PilotCommand(this), this);
            pm.registerEvents(new SquidCommand(this), this);
            pm.registerEvents(new FishermanCommand(this), this);
            pm.registerEvents(new SniperCommand(this), this);
            pm.registerEvents(new KillstreakEvent(this), this);
            pm.registerEvents(new Menu(this), this);
            pm.registerEvents(new SquashCommand(this), this);
            getCommand("archer").setExecutor(new ArcherCommand(this));
            getCommand("mario").setExecutor(new MarioCommand(this));
            getCommand("squash").setExecutor(new SquashCommand(this));
            getCommand("hopper").setExecutor(new HopperCommand(this));
            getCommand("pilot").setExecutor(new PilotCommand(this));
            getCommand("rage").setExecutor(new RageCommand(this));
            getCommand("pvp").setExecutor(new KitCommand(this));
            getCommand("scout").setExecutor(new ScoutCommand(this));
            getCommand("sniper").setExecutor(new SniperCommand(this));
            getCommand("squid").setExecutor(new SquidCommand(this));
            getCommand("fisherman").setExecutor(new FishermanCommand(this));
            getCommand("buyfishman").setExecutor(this);
            getCommand("buyscout").setExecutor(this);
            getCommand("buypilot").setExecutor(this);
            getCommand("juggernaut").setExecutor(new JuggernautCommand(this));
            getCommand("chest").setExecutor(new ChestCommand(this));
            getCommand("soup").setExecutor(new SoupCommand());
            getCommand("spawn").setExecutor(new SpawnCommand());
    
    
    
    
    
            System.out.println("KitPVP Enabled!");
        }
    
    
    
        public void onDisabled(){
            System.out.println("KitPVP Disabled!");
        }
        public void events() {
            PluginManager pm = getServer().getPluginManager();
            pm.registerEvents(this.Events, this);
        }
    
    
        private boolean setupEconomy() {
            if (getServer().getPluginManager().getPlugin("Vault") == null) {
                return false;
            }
            RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
            if (rsp == null) {
                return false;
            }
            econ = rsp.getProvider();
            return econ != null;
        }
    
    
    
        public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
            Player player = null;
            if (sender instanceof Player){
                player = (Player) sender;
            }
    
            if (command.getName().equalsIgnoreCase("buyfisherman")){
                if (player != null){
                    EconomyResponse r = econ.withdrawPlayer(player.getName(), 10);
                    if (r.transactionSuccess()) {
                        permission.playerAddTransient(player,"fisherman.set");
                        player.sendMessage(ChatColor.RED + "You bought the Fisherman kit!");
                    }
    
                }
            }else
                if (command.getName().equalsIgnoreCase("buyscout")){
                    if (player != null){
                        EconomyResponse r = econ.withdrawPlayer(player.getName(), 10);
                        if (r.transactionSuccess()) {
                            permission.playerAddTransient(player,"scout.set");
                            player.sendMessage(ChatColor.RED + "You bought the Scout kit!");
                        }
                    }
                }else
                    if (command.getName().equalsIgnoreCase("buypilot")){
                        EconomyResponse r = econ.withdrawPlayer(player.getName(), 10);
                        if (r.transactionSuccess()) {
                            permission.playerAddTransient(player,"pilot.set");
                            player.sendMessage(ChatColor.RED + "You bought the Pilot kit!");
                        }
                    }
    
            return true;
        }
    
    
        @EventHandler
        public void onPlayerDeath(PlayerDeathEvent event){
            if(event.getEntity() instanceof Player) {
                Player p = (Player) event.getEntity().getPlayer();
                if(event.getEntity().getKiller() instanceof Player) {
                    econ.depositPlayer(p.getKiller(), 80);
                }
    
            }
        }
    }
    
    
    
    http://imgur.com/JaYz747
    http://imgur.com/rrvVv0T
     
    Last edited: Jan 20, 2015
  11. Offline

    1Rogue

    You're trying to set the executor for a command that your plugin has not defined ("buyfishman"). You also have public static fields which are null. You need to initialize those and make them not public.
     
  12. Offline

    Treeline1

    @1Rogue
    Ahh so fishman was just a spelling mistake... Stupid me xD
    So no error anymore on start up. But when i do /buyfisherman etc i get this still: http://imgur.com/4MqDQsK
    And where are the public static fields which are null??
    *edit* I assume its
    Code:
    public static Economy econ = null;
    but how do I fix it
     
  13. Offline

    1Rogue

    Code:java
    1. public static Economy econ = null;
    2. public static Permission permission = null;


    The new error is a result of these fields as well.
     
  14. Offline

    Treeline1

    Ok, so do I need to change them to private or something?
     
  15. In the error, when you do /buyfisherman, at the bottom it says that the error is occurring on line 164 in your Kitpvp.java class. And when you do /buyscout, the error is occurring on line 174 in your Kitpvp.java. Try and look where those lines are and see if you can fix the error. You should also try and read the error, and see where the error is occurring, instead of posting every time you get one. :)
     
  16. Offline

    Skionz

    You need to initialize them.
     
  17. Offline

    Treeline1

    Those are these lines:
    permission.playerAddTransient(player,"scout.set");
    permission.playerAddTransient(player,"fisherman.set");
     
  18. Offline

    1Rogue

    Right. They try to dereference the null variable "permission". The dot '.' is a dereference operator, if you use it on a null variable, a NullPointerException (NPE) is thrown (you can't get the value of nothing).

    Make your field private or private static, and initialize (set a value to) it in your onEnable.
     
  19. @Treeline1 Hm... Those commands are giving you a NullPointerException, so that doesn't clear up much... Pretty sure you add a permission to a player like this:
    Code:
    Permissible perm;
    
    // Adding permission:
    PermissionAttachment permInfo = perm.addAttachment(plugin, "your.permission.here", boolean);
    
    // Removing permission:
    perm.removeAttachment(permInfo);
     
  20. Offline

    Treeline1

    That isnt what I need though for vault :p
     
  21. @Treeline1 Try using it anyway, see what happens. Besides, why are you using vault to add permissions to players anyway? I know that you can, but I think it'd be a lot more basic if you used Essentials or GroupManager. ;)
     
  22. Offline

    Treeline1

    im using vault so when they do /buy it keeps them stored even when server restarts.
    And no, it doesnt work
     
  23. @Treeline1 Hm. Thought I had it. (You know that you aren't doing /buy by the way? There's no space in between the arguments. To make it so its /buy [args] you would have to do:
    Code:
    if(cmd.getName().equalsIgnoreCase("buy")) {
    if(args.length == 0) {
    player.sendMessage(ChatColor.RED + "/buy <rank>");
    } else if (args[0].equalsIgnoreCase("scout")) {
    // Do stuff here.
    }
    }
    ) :)
     
  24. Offline

    Treeline1

    I know what im doing xD I tried args first and it was fucking up so I just did /buy my way xD
     
  25. Offline

    1Rogue

    He's using vault, it has nothing to do with the Permissible interface (and would be better than directly accessing a permissions plugin's api).

    You would retrieve the Permission object the same way the economy object is obtained.

    RegisteredServiceProvider<T> is a generic wrapper that allows plugins to register a service provider (a class they define themselves), indexed by class (the generic operand, which is why you see return values of things such as RegisteredServiceProvider<Economy>). You simply retrieve the class you want and set it to a variable.

    On another note, Vault's tutorials should be taken as a point of reference, not a literal example.
     
  26. Offline

    Treeline1

    Thank you xD But to my problem atm, how do I fix it? o.o

    @1Rogue

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 13, 2016
  27. Offline

    Treeline1

    No one? xD It just isnt letting me buy it :/
     
Thread Status:
Not open for further replies.

Share This Page