package me.galaran.bukkitutils.__utils_project_name__.text;

import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BookMeta;
import org.bukkit.inventory.meta.ItemMeta;

import java.util.*;

public class McEncoding {

    private static final String WRONG =  "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ¸¨";
    private static final String RIGHT =  "АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыьэюяёЁ";

    private static final Map<Character, Character> encMap = new HashMap<Character, Character>();
    static {
        for (int i = 0; i < WRONG.length(); i++) {
            encMap.put(WRONG.charAt(i), RIGHT.charAt(i));
        }
    }

    public static String fix(String str) {
        if (str == null) return null;
        if (str.isEmpty()) return "";

        StringBuilder sb = new StringBuilder();

        for (char curChar : str.toCharArray()) {
            Character replace = encMap.get(curChar);
            sb.append(replace == null ? curChar : replace);
        }

        return sb.toString();
    }

    public static List<String> fixCollection(Collection<String> col) {
        if (col == null) return null;
        if (col.isEmpty()) return Collections.emptyList();

        List<String> result = new ArrayList<String>(col.size());
        for (String element : col) {
            result.add(fix(element));
        }
        return result;
    }

    public static ItemStack fixItem(ItemStack stack) {
        if (stack == null) return null;
        if (!stack.hasItemMeta()) {
            return stack;
        }

        ItemMeta meta = stack.getItemMeta();
        meta.setDisplayName(fix(meta.getDisplayName()));
        meta.setLore(fixCollection(meta.getLore()));
        
        if (meta instanceof BookMeta) {
            BookMeta book = (BookMeta) meta;
            book.setAuthor(fix(book.getAuthor()));
            book.setTitle(fix(book.getTitle()));
            book.setPages(fixCollection(book.getPages()));
        }

        stack.setItemMeta(meta);
        return stack;
    }
}

@@ -1178,67 +1178,8 @@
 ull;
-%0A        if (col.isEmpty()) return Collections.emptyList();
 %0A%0A  
@@ -1348,32 +1348,80 @@
  result;%0A    %7D%0A%0A
+    /**%0A     * @return passed ItemStack%0A     */%0A
     public stati
@@ -1477,37 +1477,49 @@
  (stack 
-=
+!
 = null
-) return null;
+ && stack.hasItemMeta()) %7B
 %0A       
@@ -1523,40 +1523,75 @@
     
-if (!
+    
 stack.
-hasItemMeta()) %7B%0A    
+setItemMeta(fixItemMeta(stack.getItemMeta()));%0A        %7D%0A
     
@@ -1616,59 +1616,153 @@
     
+%7D%0A%0A
     
-%7D%0A
+/**
 %0A     
-   ItemMeta meta = stack.getItemMeta();
+* @return passed ItemMeta%0A     */%0A    public static ItemMeta fixItemMeta(ItemMeta meta) %7B%0A        if (meta == null) return null;%0A
 %0A   
@@ -1868,24 +1868,16 @@
 re()));%0A
-        
 %0A       
@@ -2126,42 +2126,8 @@
    %7D
-%0A%0A        stack.setItemMeta(meta);
 %0A   
@@ -2130,31 +2130,30 @@
 %0A        return 
-stack
+meta
 ;%0A    %7D%0A%7D%0A

Add fixItemMeta (encoding)