Placeholders in config.yml

Discussion in 'Plugin Development' started by Kiriller256, May 9, 2024.

  1. Offline

    Kiriller256

    I want to make a placeholder “%prefix%”, and when I change the config and add this placeholder anywhere it will be replaced by the prefix value in the same config.
    Configuration:

    Prefix: “&7[#00c6ffGym&7]&r”
    Messages:

    ErrorPlsHelp: “Test %prefix%”.
     
  2. Offline

    timtower Administrator Administrator Moderator

  3. Offline

    Kiriller256

    .matcher() and then replace this don't work
    @timtower
     
  4. Offline

    timtower Administrator Administrator Moderator

    Show the code, how you use it.
    Show what it made instead, show errors if you have them.
     
  5. Offline

    Kiriller256

    Code:
    Code:
    private String format(String msg) {
    Matcher match2 = prefix.matcher(msg);
    while (match2.find()) {
    String prefix = msg.substring(match2.start(), match2.end());
    msg = msg.replace(prefix, GymPlugin.getInstance().getConfig().getString("prefix") + " ");
    }
    Matcher match = pattern.matcher(msg);
    while (match.find()) {
    String color = msg.substring(match.start(), match.end());
    msg = msg.replace(color, ChatColor.of(color) + "");
    }
    
    
    return ChatColor.translateAlternateColorCodes('&', msg);
    }
    Error:
    Code:
    [14:34:48 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'gym' in plugin GymPlugin v1.0-SNAPSHOT
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:47) ~[paper-api-1.20.1-R0.1-SNAPSHOT.jar:?]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:155) ~[paper-api-1.20.1-R0.1-SNAPSHOT.jar:?]
            at org.bukkit.craftbukkit.v1_20_R1.CraftServer.dispatchCommand(CraftServer.java:987) ~[paper-1.20.1.jar:git-Paper-196]
            at org.bukkit.craftbukkit.v1_20_R1.command.BukkitCommandWrapper.run(BukkitCommandWrapper.java:64) ~[paper-1.20.1.jar:git-Paper-196]
            at com.mojang.brigadier.CommandDispatcher.execute(CommandDispatcher.java:265) ~[paper-1.20.1.jar:?]
            at net.minecraft.commands.Commands.performCommand(Commands.java:324) ~[?:?]
            at net.minecraft.commands.Commands.performCommand(Commands.java:308) ~[?:?]
            at net.minecraft.server.network.ServerGamePacketListenerImpl.performChatCommand(ServerGamePacketListenerImpl.java:2354) ~[?:?]
            at net.minecraft.server.network.ServerGamePacketListenerImpl.lambda$handleChatCommand$21(ServerGamePacketListenerImpl.java:2314) ~[?:?]
            at net.minecraft.util.thread.BlockableEventLoop.lambda$submitAsync$0(BlockableEventLoop.java:59) ~[?:?]
            at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1768) ~[?:?]
            at net.minecraft.server.TickTask.run(TickTask.java:18) ~[paper-1.20.1.jar:git-Paper-196]
            at net.minecraft.util.thread.BlockableEventLoop.doRunTask(BlockableEventLoop.java:153) ~[?:?]
            at net.minecraft.util.thread.ReentrantBlockableEventLoop.doRunTask(ReentrantBlockableEventLoop.java:24) ~[?:?]
            at net.minecraft.server.MinecraftServer.doRunTask(MinecraftServer.java:1338) ~[paper-1.20.1.jar:git-Paper-196]
            at net.minecraft.server.MinecraftServer.d(MinecraftServer.java:197) ~[paper-1.20.1.jar:git-Paper-196]
            at net.minecraft.util.thread.BlockableEventLoop.pollTask(BlockableEventLoop.java:126) ~[?:?]
            at net.minecraft.server.MinecraftServer.pollTaskInternal(MinecraftServer.java:1315) ~[paper-1.20.1.jar:git-Paper-196]
            at net.minecraft.server.MinecraftServer.pollTask(MinecraftServer.java:1308) ~[paper-1.20.1.jar:git-Paper-196]
            at net.minecraft.util.thread.BlockableEventLoop.runAllTasks(BlockableEventLoop.java:114) ~[?:?]
            at net.minecraft.server.MinecraftServer.tickServer(MinecraftServer.java:1424) ~[paper-1.20.1.jar:git-Paper-196]
            at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1170) ~[paper-1.20.1.jar:git-Paper-196]
            at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:317) ~[paper-1.20.1.jar:git-Paper-196]
            at java.lang.Thread.run(Thread.java:1583) ~[?:?]
    Caused by: java.lang.IllegalArgumentException: Could not parse ChatColor m&7]&r
            at net.md_5.bungee.api.ChatColor.of(ChatColor.java:273) ~[bungeecord-chat-1.20-R0.1-deprecated+build.14.jar:?]
            at by.kiriller256.gymplugin.configs.ConfigManager.format(ConfigManager.java:24) ~[GymPlugin-1.0-SNAPSHOT.jar:?]
            at by.kiriller256.gymplugin.configs.ConfigManager.ErrorPlsHelp(ConfigManager.java:13) ~[GymPlugin-1.0-SNAPSHOT.jar:?]
            at by.kiriller256.gymplugin.GymCommands.onCommand(GymCommands.java:27) ~[GymPlugin-1.0-SNAPSHOT.jar:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45) ~[paper-api-1.20.1-R0.1-SNAPSHOT.jar:?]
            ... 23 more
     
    Last edited by a moderator: May 10, 2024
  6. Offline

    timtower Administrator Administrator Moderator

    @Kiriller256 It can't find the color, remove the part that handles the colors for now.
    See if that works.
     
  7. Offline

    Kiriller256

    it works, but before that the color class worked.
     
  8. Offline

    timtower Administrator Administrator Moderator

    Well, I have no idea why you need to use "ChatColor.of" anyways.
    Only translateAlternateColorCodes is needed
     
  9. Offline

    Kiriller256

    There is no support for hex colors in translateAlternateColorCodes
     
  10. Offline

    timtower Administrator Administrator Moderator

    Then don't use them?
     
  11. Offline

    KarimAKL

    @Kiriller256 There might be a problem with the regex; can you post your patterns and an example message to be processed?
     

Share This Page