languages - Nutty101/NPC-Police GitHub Wiki
The language files for most of my plugins look rather complex but in essence, they are not that hard to manage. They offer the ability to change the entire interface without modifying any code.
By default, the plugin will utilize the en_def language file. This file is overwritten every time the plugin starts up. This is to ensure that the plugin always has the correct language to function in the event of an update. When you want to make changes to the languages that can persist over multiple updates, just create a new file and populate only the lines that you want to change. I will revert to the en_def file for all other lines.
For the sake of this tutorial, let's make a new English language file with changes that we want on our server. The first thing you want to do is open the config.yml file inside the plugin's folder {plugins/NPC_Police/config.yml}.
language: en_def
Change the language setting to en_us, and upon reloading the plugin will look in {plugins/NPC_Police/Languages} for a file named en_us-npcpolice.yml.
language: en_us
For this example, let's change some of the lines that are the most asked about lines. The notices that players are given upon actions.
npc_messages:
warning_message: "[{\"text\":\"[\",\"color\":\"red\"},{\"text\":\"<npc.name>\",\"color\":\"green\"},{\"text\":\"] \",\"color\":\"blue\"},{\"text\":\"hit me again \",\"color\":\"green\"},{\"text\":\"<player.name>\",\"color\":\"yellow\"},{\"text\":\" and I will call for the guards!\",\"color\":\"green\"}]"
broadcast_attack_noguards: "[{\"text\":\"[\",\"color\":\"red\"},{\"text\":\"<npc.name>\",\"color\":\"green\"},{\"text\":\"] \",\"color\":\"blue\"},{\"text\":\"Someone help me! \",\"color\":\"green\"},{\"text\":\"<player.name>\",\"color\":\"yellow\"},{\"text\":\" is attacking me!\",\"color\":\"green\"}]"
The above lines are what happens when a player is attacking an NPC. The warning is the initial attack, and the second is what happens when no guards are in the configured distance of the attacked NPC. Below is what the string looks like unformatted.
warning_message: [<npc.name>] hit me again <player.name> and I will call for the guards!
broadcast_attack_noguards: [<npc.name>] Someone help me! <player.name> is attacking me!
In the new language file {plugins/NPC_Police/Languages/en_us-npcpolice.yml} let's paste the lines below (the formatted messages with the JSON encoding).
npc_messages:
warning_message: "[{\"text\":\"[\",\"color\":\"red\"},{\"text\":\"<npc.name>\",\"color\":\"green\"},{\"text\":\"] \",\"color\":\"blue\"},{\"text\":\"This is your only warning \",\"color\":\"green\"},{\"text\":\"<player.name>\",\"color\":\"yellow\"},{\"text\":\". Hit me again and you will be wanted by the police!\",\"color\":\"green\"}]"
broadcast_attack_noguards: "[{\"text\":\"[\",\"color\":\"red\"},{\"text\":\"<npc.name>\",\"color\":\"green\"},{\"text\":\"] \",\"color\":\"blue\"},{\"text\":\"Everyone, \",\"color\":\"green\"},{\"text\":\"<player.name>\",\"color\":\"yellow\"},{\"text\":\" is attacking me. Save me!\",\"color\":\"green\"}]"
Would now look like the following to users:
warning_message: [<npc.name>] This is your only warning <player.name>. Hit me again you will be wanted by the police!
broadcast_attack_noguards: [<npc.name>] Everyone, <player.name> is attacking me. Save me!
06.17.19 - At this time, the plugin does not support language changes with the /np reload command. That will change very soon :)