Command Not Working 1.14.4

Discussion in 'Plugin Development' started by ExitCore, Jan 14, 2020.

  1. Offline

    ExitCore

    Not Sure how to fix this. The replace line has an error "Caused by: java.lang.NullPointerException".
    Code:
    public class flyCommand implements CommandExecutor {
    
        @SuppressWarnings("unused")
        private plugin plugin;
        @SuppressWarnings("unused")
        public String name = "fly";
       
        public flyCommand(plugin plugin) {
            this.plugin = plugin;
            plugin.getCommand("fly").setExecutor(this);
        }
       
        @Override
        public boolean onCommand(CommandSender s, Command cmd, String label, String[] args) {
         
            Player p = (Player) s;
           
            uChat chat = new uChat(label, label);
           
            if(!(s instanceof Player)) {
                s.sendMessage(chat.color(plugin.getConfig().getString("error00000").replace("<player>", p.getName())));
                return true;
            } else if(p.hasPermission("fly.use")) {
                p.sendMessage(
                    chat.color(
                        plugin.getConfig().
                        getString("fly"). 
                        replace(  // ERROR ? ? ? ? ?
                            "<player>",
                            p.getName()
                        )
                    )
                );
                return true;
            } else {
                s.sendMessage(chat.color(
                    plugin.getConfig().getString("error00001").replace("<player>", p.getName())
                ));
                return true;
            }
        }
    }
    
     
  2. Offline

    Pr0totype2

    Either your config is null or there's no "fly" String / key inside it.
     
  3. Offline

    Strahan

    Also you realize it's not very logical to check if sender is an instanceof Player after you've already cast it thus? That's putting the cart in front of the horse heh.
     

Share This Page