Solved A strange nullpointerexception

Discussion in 'Spigot Plugin Development' started by Stellrow, Aug 10, 2018.

  1. So im trying to simply give someone a item when they write a command
    Code (Text):
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if(sender instanceof Player) {
                Player player = (Player) sender;
                UUID uuid = player.getUniqueId();
                if(plugin.rpgtool.containsKey(uuid)) {
                    String mdp = plugin.getConfig().getString(".MesajDetinePickaxe");
                    String mdp2 = mdp.replaceAll("&", "§");
                    String mdp3 = mdp2.replaceAll("§§", "§");
                }else {
                    String mapp = plugin.getConfig().getString(".MesajAiPrimitPickaxe");
                    String mapp2 = mapp.replaceAll("&", "§");
                    String mapp3 = mapp2.replaceAll("§§", "§");
                    plugin.rpgtool.put(uuid, 1);
                    ItemStack rpgtool = new ItemStack(Material.WOOD_PICKAXE);
                    ItemMeta rpgtoolm = rpgtool.getItemMeta();
                    String np = plugin.getConfig().getString(".NumePickaxe");
                    String np2 = np.replaceAll("&", "§");
                    String np3 = np2.replaceAll("§§", "§");
                    String nume = player.getName();
                    String np4 = np3.replace("%nume", nume);
                    List<String> lore = new ArrayList<String>();
                    String lp1 = plugin.getConfig().getString(".LorePickaxe1");
                    String lp12 = lp1.replaceAll("&", "§");
                    String lp13 = lp12.replaceAll("§§", "§");
                    String lp2 = plugin.getConfig().getString(".LorePickaxe2");
                    String lp21 = lp2.replaceAll("&", "§");
                    String lp22 = lp21.replaceAll("§§", "§");  
                    String lp3 = plugin.getConfig().getString(".LorePickaxe3");
                    String lp31 = lp3.replaceAll("&", "§");
                    String lp32 = lp31.replaceAll("§§", "§");
                    String lp4 = plugin.getConfig().getString(".LorePickaxe4");
                    String lp41 = lp4.replaceAll("&", "§");
                    String lp42 = lp41.replaceAll("§§", "§");
    This is the code,i know its a bit messy but meh
    And this is the error
    Code (Text):
    [13:52:47] [Server thread/ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'rpgtool' in plugin RPGTools v0.1
        at org.bukkit.command.PluginCommand.execute( ~[spigot-1.12.2.jar:git-Spigot-642f6d2-6103339]
        at org.bukkit.command.SimpleCommandMap.dispatch( ~[spigot-1.12.2.jar:git-Spigot-642f6d2-6103339]
        at org.bukkit.craftbukkit.v1_12_R1.CraftServer.dispatchCommand( ~[spigot-1.12.2.jar:git-Spigot-642f6d2-6103339]
        at net.minecraft.server.v1_12_R1.PlayerConnection.handleCommand( [spigot-1.12.2.jar:git-Spigot-642f6d2-6103339]
        at net.minecraft.server.v1_12_R1.PlayerConnection.a( [spigot-1.12.2.jar:git-Spigot-642f6d2-6103339]
        at net.minecraft.server.v1_12_R1.PacketPlayInChat.a( [spigot-1.12.2.jar:git-Spigot-642f6d2-6103339]
        at net.minecraft.server.v1_12_R1.PacketPlayInChat.a( [spigot-1.12.2.jar:git-Spigot-642f6d2-6103339]
        at net.minecraft.server.v1_12_R1.PlayerConnectionUtils$ [spigot-1.12.2.jar:git-Spigot-642f6d2-6103339]
        at java.util.concurrent.Executors$ Source) [?:1.8.0_161]
        at Source) [?:1.8.0_161]
        at net.minecraft.server.v1_12_R1.SystemUtils.a(SourceFile:46) [spigot-1.12.2.jar:git-Spigot-642f6d2-6103339]
        at net.minecraft.server.v1_12_R1.MinecraftServer.D( [spigot-1.12.2.jar:git-Spigot-642f6d2-6103339]
        at net.minecraft.server.v1_12_R1.DedicatedServer.D( [spigot-1.12.2.jar:git-Spigot-642f6d2-6103339]
        at net.minecraft.server.v1_12_R1.MinecraftServer.C( [spigot-1.12.2.jar:git-Spigot-642f6d2-6103339]
        at [spigot-1.12.2.jar:git-Spigot-642f6d2-6103339]
        at Source) [?:1.8.0_161]
    Caused by: java.lang.NullPointerException
        at RPGTools.CommandClass.onCommand( ~[?:?]
        at org.bukkit.command.PluginCommand.execute( ~[spigot-1.12.2.jar:git-Spigot-642f6d2-6103339]
        ... 15 more
  2. What is line 31 in your code?
  3. Code (Text):
    String mapp2 = mapp.replaceAll("&", "§");
    A replace to use the & colorcodes
  4. Why?
    Code (Java):

      String mapp2 = mapp.replaceAll("&", "§");
      String mapp3 = mapp2.replaceAll("§§", "§");
    Code (Java):

        * Returns a message translated.
        * @param msg
        *            The message to be translated
        * @return A translated message

       public static String tr(String msg) {
           return ChatColor.translateAlternateColorCodes('&', msg);

    Code (Java):

    Either the plugin instance if null or there is no .MesajAiPrimitPickaxe path in your config.
  5. Yep that "i" was the problem
  6. If we are still at this topic before i start to create it do you know a good way to modify the lore every xAction..? without filling everything with my disgusting coding habits(spam every simple thing)
  7. Create a new thread for this case and do not forget to provide more details on what you wish to achieve. I'm not sure what you mean by saying modify a lore every "xAction".
  8. Its a simple breakevent if it breaks a block i will change the part of the lore containing the xp count, getting the value from a config
    But the part changing the lore is worrying me
  9. Manipulating lores:
    Code (Java):

    ItemMeta meta = ItemStack#getItemMeta;
    List<String> lore = meta#getLore;



  10. I opened a new thread as you said