1.8.8 How can I get placeholder from my config.yml?

Discussion in 'Spigot Plugin Development' started by MXT, Nov 15, 2021.

  1. MXT

    MXT

    Hey,

    How can I get placeholder from my config.yml (e.g. Hello %player_name% in config.yml) I want this to display like "Hello RandomPlayer" In Minecraft Chat, I know how to display the chat but How can I get the placeholder value from config.yml

    Config -
    suicide:
    enabled: true
    broadcast-message-enabled: true
    broadcast-msg: "&c%player% &aHas killed themselves"
    player-message: "&aYou have killed yourself!"

    How it shows: %player% Has killed themselves
    How I want: MXT Has killed themeselves

    Sorry if this is wrong place or my English is bad
     

    Attached Files:

  2. You are taking it from the config and then sending it,when sending just do replaceAll("%player_name%",player.getName()) to the message
     
    • Like Like x 1
  3. MXT

    MXT

    Where do I want to do "replaceAll("player_name",player.getName())" I am new to this

    My code - https://pastebin.com/ZPB5wvt4
     
  4. On all string where you want your placeholder, for example Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', CustomConfig.get().getString("suicide.broadcast-msg"))); will become Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', CustomConfig.get().getString("suicide.broadcast-msg"))).replaceAll("%player_name%", player.getName());
     
  5. MXT

    MXT

    at replaceAll I get error, "Cannot resolve method ' replaceAll(java.lang.String, java.lang.String)' "
     
  6. Sorry I misplaced it, use this Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', CustomConfig.get().getString("suicide.broadcast-msg").replaceAll("%player_name%", player.getName())));
     
    • Useful Useful x 1
  7. MXT

    MXT

    Thank you so much!!, It worked
     
  8. MXT

    MXT

    And other QUSTION:

    Code -
    player.sendMessage(ChatColor.translateAlternateColorCodes('&', CustomConfig.get().getString("game-mode-set-self").replaceAll("%player_name%", player.getName())));

    I want %gamemode% and %player_name% at same time what should I do?
     
  9. Add another replace method onto the end of your other one
     
    • Useful Useful x 1
  10. MXT

    MXT

    Oh thanks :D
     
  11. MXT

    MXT

    [22:46:06 INFO]: MXT_QT issued server command: /gmc
    [22:46:06 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'gmc' in plugin mxt v1.0
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:47) ~[patched.jar:git-PaperSpigot-"4c7641d"]
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:146) ~[patched.jar:git-PaperSpigot-"4c7641d"]
    at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:666) ~[patched.jar:git-PaperSpigot-"4c7641d"]
    at net.minecraft.server.v1_8_R3.PlayerConnection.handleCommand(PlayerConnection.java:1189) [patched.jar:git-PaperSpigot-"4c7641d"]
    at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:1001) [patched.jar:git-PaperSpigot-"4c7641d"]
    at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java:45) [patched.jar:git-PaperSpigot-"4c7641d"]
    at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java:1) [patched.jar:git-PaperSpigot-"4c7641d"]
    at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [patched.jar:git-PaperSpigot-"4c7641d"]
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_311]
    at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_311]
    at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [patched.jar:git-PaperSpigot-"4c7641d"]
    at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:774) [patched.jar:git-PaperSpigot-"4c7641d"]
    at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:378) [patched.jar:git-PaperSpigot-"4c7641d"]
    at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:713) [patched.jar:git-PaperSpigot-"4c7641d"]
    at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:616) [patched.jar:git-PaperSpigot-"4c7641d"]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_311]
    Caused by: java.lang.NullPointerException
    at me.mxt.bw1058mxtaddon.commands.CreativeCommand.onCommand(CreativeCommand.java:33) ~[?:?]
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45) ~[patched.jar:git-PaperSpigot-"4c7641d"]
    ... 15 more
    error Please help!
     
  12. MXT

    MXT

    Please send a code example it's not working for me :(
     
  13. MXT

    MXT

    Nvm I fixed it :D