GeorgH93 / MarriageMaster

Marriage Plugin for Bukkit/Spigot
https://www.spigotmc.org/resources/marriage-master.19273/
GNU General Public License v3.0
113 stars 90 forks source link

Are placeholders available inside messages (en.yml etc.) ? #237

Open Qveshn opened 2 years ago

Qveshn commented 2 years ago

Help request

Problem Am I getting it right that ATM the plugin does not currently support placeholders inside messages (en.yml etc.)?

What I have tried I tried use placeholders and they do not converts to values. For example en.yml contains:

Language:
  ...
  Ingame:
    NoPermission: "&cYou (%player_ip%) don't have the permission to do that."

When I use unavailable command for player, then I see in chat: You (%%player_ip%%) don't have the permission to do that. But I expected to see ip instead %player_ip% like: You (192.168.0.10) don't have the permission to do that.

GeorgH93 commented 2 years ago

You are right, at the moment they are not supported. If I remember correctly, there actually already exists the code to resolve papi placeholders in messages, but I haven't added the option to enable it in the language file yet. I probably should finish that at some point :D

GeorgH93 commented 2 years ago

I quickly added the switch, but the PAPI code will probably need some safety checks. If you drop this version of the plugin lib into your plugins directory, you should be able to enable PAPI for every message. To use it, just create a new entry after the message with this template: <MessageKey>_PAPI: true For example:

Language:
  ...
  Ingame:
    NoPermission: "&cYou (%player_ip%) don't have the permission to do that."
    NoPermission_PAPI: true

If the used placeholder can contain a \ or " character, I would strongly recommend you to not use them with JSON formatted messages and to add another entry with this template: <MessageKey>_SendMethod: CHAT_CLASSIC like this:

Language:
  ...
  Ingame:
    NoPermission: "&cYou (%somePlaceholderContainingJsonSpecialChars%) don't have the permission to do that."
    NoPermission_SendMethod: CHAT_CLASSIC
    NoPermission_PAPI: true
Qveshn commented 2 years ago

Well... I tested it but it does not work.

Language:
  ...
  Ingame:
    NoPermission: "&cYou (%player_ip%) don't have the permission to do that."
    NoPermission_PAPI: true

And I see in chat: You (%%player_ip%%) don't have the permission to do that.

This is because of double '%%'. You often use plugin.getLanguage().getMessage("...") and this method escapes '%' to '%%'. PlaceholderAPI does not understand them. It finds first placeholder '%%' (with empty identifier) and skips it. Then it finds the second one '%%' and also skpis it :D

Moreover, you often use the construction like plugin.getLanguage().getMessage("...").replaceAll("\\{...tag...}", "%s"); Therefore you can not use plugin.getLanguage().getMessage("...",false).replaceAll("\\{...tag...}", "%s");, because it will be unsafe if somebody type in text something like "Hello %dady" :D

I found the way how to easy solve this problem. But I will need to make small changes to the plugin PCGF_PluginLib The concepts is that it will remember that Message was escaped to %%. And the method prepareMessage(...) will unescape it again at the end if it was escaped.

I have already made these changes to PCGF_PluginLib Now there is no double '%%' at the final stage.

Look please PR https://github.com/GeorgH93/PCGF_PluginLib/pull/25

I'm sorry for the english. This is not my native language.

GeorgH93 commented 2 years ago

Thanks for the fix. I have merged it.