set {_index} to convert string uncolored {_message} to lowercase
replace all "-" and ":" and "'" and """" and "." and " " and "[" and "]" and "," and "!" and "?" and "*" and "^" and "%%" and "##" and "@" and "(" and ")" and "_" and "+" and "=" and "`" and "~" and "$" and "|" and "{" and "}" and "<" and ">" with "" in {_index}
#detect if the message hasn't been added to YAML file, if so, auto add it!
#one little issue about this, it results into double value check for current language, but I think optimizing that would be simply pointless (much less clean code)
yaml value "%{_index}%" from "lang%loop-value-2%" is not set:
set yaml value "%{_index}%" from "lang%loop-value-2%" to "%{_message}%"
#save the message to memory + CSV file that gets auto-loaded into memory on server startup (maybe I'll save this to mysql instead for future)
set {langmsg::%{_lang}%::%{_message}%} to {_message}
#if yaml value is present, but it is not loaded into memory, load it!
else:
set {langmsg::%{_lang}%::%{_message}%} to yaml value "%{_index}%" from "lang%{_lang}%"
#since INDEX generation in my yaml files may not be always unique if the messages are extremely similar, but only with differing color codes, this unused code checks for index duplication
#set {_msgc} to yaml value "%{_index}%" from "langEN"
#{_msgc} is not {_message}:
#send "LANGUAGE: %{_msgc}%&2 does not equal to &r%{_message}%&2 | this might be a bug of different colorcodes." to ops and console
#log "LANGUAGE: %{_msgc}% does not equal to %{_message}% | this might be a bug of different colorcodes." to "language-errors.log"
function getSlotFromLanguage(lang: text) :: number:
switch {_lang}:
case "EN":
return 0
case "LT":
return 1
case "RU":
return 2
case "DA":
return 3
case "PT":
return 4
case "CN_Simplified":
return 5
command /languages [<text>]:
description: Set your language
usage: /languages
trigger:
wait a tick
open chest with 1 row named "&6- &a&lSelect language &6-" to player
set {_inventory} to player's current inventory
#diamond block is displayed if the banner variable isn't set
set slot 0 of {_inventory} to {banners::english} ? diamond block named "&aEnglish" with lore "&e&lCLICK TO SELECT" with no nbt
set slot 1 of {_inventory} to {banners::lithuania} ? diamond block named "&aLietuvių" with lore "&e&lCLICK TO SELECT" with no nbt
set slot 2 of {_inventory} to {banners::russia} ? diamond block named "&aРусский" with lore "&e&lCLICK TO SELECT" with no nbt
set slot 3 of {_inventory} to {banners::denmark} ? diamond block named "&aDansk" with lore "&e&lCLICK TO SELECT" with no nbt
set slot 4 of {_inventory} to {banners::portugal} ? diamond block named "&aPortuguês" with lore "&e&lCLICK TO SELECT" with no nbt
set slot 5 of {_inventory} to {banners::china} ? diamond block named "&aChinese (Simplified)" with lore "&e&lCLICK TO SELECT" with no nbt
set {_slot} to getSlotFromLanguage(epic variable "%uuid of player%::language")
set {_item} to {_inventory}.getItem({_slot})
set lore of {_item} to "&a&lSELECTED"
set slot {_enchantslot} of {_inventory} to {_item}
set {_sp} to "Automatically detects your language based on your location."
if {forcedenglish::%uuid of player%} is not set:
set slot 8 of {_inventory} to glowing redstone dust named "&eAutomatic Language Detection &2[&a&lON&2]" with lore "&7%{_sp}%", "&7This is enabled by default.", "&a", "&a&lCLICK TO TOGGLE"
else:
set slot 8 of {_inventory} to redstone dust named "&eAutomatic Language Detection &2[&c&lOFF&2]" with lore "&7%{_sp}%", "&7This is enabled by default.", "&a", "&a&lCLICK TO TOGGLE"
on inventory click:
inventory name of player's current inventory = "&6- &a&lSelect language &6-"
clicked inventory is not player's inventory
set {_l} to epic variable "%uuid of player%::language"
switch clicked slot:
case 0:
set {_lang} to "EN"
case 1:
set {_lang} to "LT"
case 2:
set {_lang} to "RU"
case 3:
set {_lang} to "DA"
case 4:
set {_lang} to "PT"
case 8:
{forcedenglish::%uuid of player%} is not set:
set {forcedenglish::%uuid of player%} to true
send "&cAutomatic language detection has been disabled."
else:
delete {forcedenglish::%uuid of player%}
send "&aAutomatic language detection has been enabled back."
{_l} is not {_lang}:
set epic variable "%uuid of player%::language" to {_lang}
send "&eYou have selected &a%{_lang}% &elanguage!"