Solved %player% in config

Discussion in 'Plugin Development' started by user_91277742, Jan 24, 2019.

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

    user_91277742

    Hello there! , So.. is very simple, i just want to know, how can i define the variable %player% to put that inside the config.
     
  2. Offline

    timtower Administrator Administrator Moderator

    @Ahrigumi String#replace("%player%", player.getName())
     
    KarimAKL likes this.
  3. Offline

    user_91277742

    @timtower so i use it, but i have an NPE and im not really sure about the problem
    Code:
                         if (args[0].equalsIgnoreCase("start")) {
                            String clase = args[1];
                            String mensaje = main.mensajesConfig.getString("teleported-class");
                            String newMessage = mensaje.replaceAll("%class%", clase);
                            if (main.oldLoc.containsKey(player.getUniqueId())) {
                                for (Player enClase : Bukkit.getOnlinePlayers()) {
                                    if (main.oldLoc.containsKey(enClase.getUniqueId())) {
                                        enClase.sendRawMessage(newMessage);
                                        Bukkit.getScheduler().scheduleSyncDelayedTask(main, new BukkitRunnable() {
                                            @Override
                                            public void run() {
                                                main.entrarClase(enClase, clase);
                                                enClase.sendTitle(ChatColor.GREEN + clase, ChatColor.GOLD + "Professor: "
                                                        + ChatColor.DARK_RED + player.getDisplayName());
                                                return;
                                            }
                                        }, 80L);
                                        return true;
                                    }
                                }
                            }
    
                        }
    
    The npe appear on String newMessage = mensaje.replaceAll("%class%", clase);

    and the config is
    Code:
    teleported-class: "You will be telerported to the %class%"
    
     
  4. Offline

    timtower Administrator Administrator Moderator

    @Ahrigumi On what line is the npe? I personally think the third line.
    And you have a typo in your config :p
     
  5. Offline

    user_91277742

    @timtower i will show you the error
    Code:
    
    [21:10:56 INFO]: Ahrigumi issued server command: /class start test
    [21:10:56 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'class' in plugin ShiloClassRPG v1.0
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spigot-1.12.2.jar:git-Spigot-2cf50f0-8166d17]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[spigot-1.12.2.jar:git-Spigot-2cf50f0-8166d17]
            at org.bukkit.craftbukkit.v1_12_R1.CraftServer.dispatchCommand(CraftServer.java:648) ~[spigot-1.12.2.jar:git-Spigot-2cf50f0-8166d17]
            at net.minecraft.server.v1_12_R1.PlayerConnection.handleCommand(PlayerConnection.java:1397) [spigot-1.12.2.jar:git-Spigot-2cf50f0-8166d17]
            at net.minecraft.server.v1_12_R1.PlayerConnection.a(PlayerConnection.java:1232) [spigot-1.12.2.jar:git-Spigot-2cf50f0-8166d17]
            at net.minecraft.server.v1_12_R1.PacketPlayInChat.a(PacketPlayInChat.java:45) [spigot-1.12.2.jar:git-Spigot-2cf50f0-8166d17]
            at net.minecraft.server.v1_12_R1.PacketPlayInChat.a(PacketPlayInChat.java:1) [spigot-1.12.2.jar:git-Spigot-2cf50f0-8166d17]
            at net.minecraft.server.v1_12_R1.PlayerConnectionUtils$1.run(SourceFile:13) [spigot-1.12.2.jar:git-Spigot-2cf50f0-8166d17]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_181]
            at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_181]
            at net.minecraft.server.v1_12_R1.SystemUtils.a(SourceFile:46) [spigot-1.12.2.jar:git-Spigot-2cf50f0-8166d17]
            at net.minecraft.server.v1_12_R1.MinecraftServer.D(MinecraftServer.java:748) [spigot-1.12.2.jar:git-Spigot-2cf50f0-8166d17]
            at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:406) [spigot-1.12.2.jar:git-Spigot-2cf50f0-8166d17]
            at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:679) [spigot-1.12.2.jar:git-Spigot-2cf50f0-8166d17]
            at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:577) [spigot-1.12.2.jar:git-Spigot-2cf50f0-8166d17]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_181]
    Caused by: java.lang.NullPointerException
            at java.util.regex.Matcher.appendReplacement(Unknown Source) ~[?:1.8.0_181]
            at java.util.regex.Matcher.replaceAll(Unknown Source) ~[?:1.8.0_181]
            at java.lang.String.replaceAll(Unknown Source) ~[?:1.8.0_181]
            at io.github.shilodabing.Clase.Comandos.onCommand(Comandos.java:322) ~[?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spigot-1.12.2.jar:git-Spigot-2cf50f0-8166d17]
            ... 15 more
    
    and yes, corrected the typo :$
     
  6. Offline

    KarimAKL

    @Ahrigumi I don't know if it makes any difference but maybe try '.replace()' instead of '.replaceAll()'.
     
  7. Offline

    user_91277742

    @KarimAKL I tried with it, but i have the same npe
     
  8. Offline

    timtower Administrator Administrator Moderator

  9. Offline

    user_91277742

    @timtower im sorry, but how works "Pattern.Quote("%player%")" ??
     
  10. Offline

    timtower Administrator Administrator Moderator

    @Ahrigumi Use it as replacement for the string that you have now.
     
  11. Offline

    user_91277742

    @timtower , ok im sorry again, the problem was "replaceAll()" , i used it, but the correct was just replace() . Im so stupid hahahah , thanks to all :D , is fixed
     
Thread Status:
Not open for further replies.

Share This Page