Skip to content
This repository has been archived by the owner on Feb 8, 2022. It is now read-only.

apachezy/LangUtils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

60 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Language Utils

English Chinese

A Bukkit/Spigot API to get the localized names of vanilla items, entitys, enchantments, biomes, potions, etc.

This project comes from MascusJeoraly:LanguageUtils.

Now, it has been completely refactored, improved performance, can support more vanilla object name translations, is compatible with the previous LangUtils, and a copy can support all Minecraft versions above 1.13 at the same time.

Tip: If you want to use it on a server of 1.12.2 and below, please go to the original project: MascusJeoraly:LanguageUtils

Features:

  • Get localized name of Items and Materials.
  • Get localized name of Biomes.
  • Get localized name of Entitys.
  • Get localized name of Enchantments.
  • Get localized name of Potions, Potion Effects, and Tipped Arrows.
  • Get Tropical Fish Type(Pattern) names and Predefined Tropical Fish names.
  • Get localized name of Dye Colors.
  • Get localized name of Villagers’ Level and Professions.
  • Get localized name of Banner Patterns and Colored Shields.
  • Get the description of the Music-Disk and the new Banner-Pattern in 1.14 and above.

Supported Minecraft version

  • 1.13, 1.14, 1.15, 1.16, 1.17

Install

Please go to Releases to download the latest version, put it in your server 'plugins' directory, and restart your server. Please delete all old LangUtils plugins before this.

Configuration

This is an example:

# Please do not remove this.
Extra-TAG: tag_r72EhIAL

# When a name in the language requested does not exist, the name will be
# retrieved in this language. The default fall back language is English.
FallbackLanguage: en_us

# If you want to enable the loading of a language, add it to the following list
# LoadLanguage: [ja_jp, ko_kr, ru_ru, zh_cn, zh_tw]
# Or
LoadLanguage:
    - ja_jp
    - ko_kr
    - ru_ru
    - zh_cn
    - zh_tw
# If you want to load all the languages, add "all" to the list:
# - all

Use LangUtils in your plugin

  1. Declaring repositories and dependencies to your build tools
  • Build with Gradle
    Add a repository and a dependency to your build.gradle:
    repositories {
        maven {
            url 'https://jitpack.io'
        }
    }
    
    dependencies {
        // Please check the latest version
        provided group: 'com.github.apachezy', name: 'LangUtils', version: '3.2.1'
    }
  • Build with Maven
    Add a repository and a dependency to your pom.xml:
    <repositories>
        <repository>
            <id>jitpack.io</id>
            <url>https://jitpack.io</url>
        </repository>
    </repositories>
    
    <dependencies>
        <!-- LangUtils -->
        <dependency>
            <groupId>com.github.apachezy</groupId>
            <artifactId>LangUtils</artifactId>
            <!--Please check the latest version -->  
            <version>3.2.1</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
  1. Add plugin dependencies to your plugin.yml
  • If your plugin must depend on LangUtils to run:
    Add this line to your plugin.yml: depend: [..., LangUtils]
    Where ... are other plugins.
  • If your plugin does not depend on LangUtils, it can also run:
    Add this line to your plugin.yml: softdepend: [..., LangUtils]
    Where ... are other plugins.
  1. Use LangUtils
  • The best usage is to create a hook for LangUtils:
    The hook may be static class, or be singleton, or be a parameterized instance, as you like.
    The following is an example of a hook using a static class:
    package com.exampleplugin.hooks;
    
    import com.meowj.langutils.lang.LanguageHelper;
    import org.bukkit.entity.Entity;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.Plugin;
    
    public class LangUtilsHook {
    
        private static boolean hooked;
    
        public static void init() {
            Plugin plugin = Bukkit.getPluginManager().getPlugin("LangUtils");
            hooked = plugin != null && plugin.isEnabled();
        }
    
        public static String getItemName(ItemStack itemStack, String locale) {
            if (hooked) {
                return LanguageHelper.getItemName(itemStack, locale);
            }
            return itemStack.getType().name();
        }
    
        public static String getEntityName(Entity entity, String locale) {
            if (hooked) {
                return LanguageHelper.getEntityName(entity, locale);
            }
            return entity.getName();
        }
    
        // Add another method...
    }
  • Then initialize the hook when your plugin starts:
    package com.exampleplugin;
    
    import com.exampleplugin.hooks;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class MyPlugin extends JavaPlugin {
    
        @Override
        public void onEnable() {
            // Initialize LangUtilsHook
            LangUtilsHook.init();
        }
    
    }
  • Call the hook where needed:
    ItemStack item = new ItemStack(Material.STONE);
    // Call LangUtilsHook to get the name of the item.
    String name = LangUtilsHook.getItemName(item, "zh_cn");

Contribute to this Project

If you find any problems or want to improve the efficiency, please send me PR or issues.