Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] 1.13 #9

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
12 changes: 8 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ apply plugin: 'maven-publish'

group = 'com.meowj'
archivesBaseName = 'LangUtils'
version = '1.9'
version = '2.0'

final def BUKKIT_VERSION = '1.12-R0.1-SNAPSHOT'
final def BUKKIT_VERSION = '1.13-R0.1-SNAPSHOT'

sourceCompatibility = '1.7'
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
sourceCompatibility = '1.8'

compileJava {
options.compilerArgs += ["-Xlint:deprecation", "-Xlint:unchecked"]
options.encoding = 'UTF-8'
}

//noinspection GroovyAssignabilityCheck
processResources {
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.8-all.zip
8 changes: 3 additions & 5 deletions src/main/java/com/meowj/langutils/lang/LanguageHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ public static String getItemName(ItemStack item, String locale) {
// Potion & SpawnEgg & Player Skull
if (item.getType() == Material.POTION || item.getType() == Material.SPLASH_POTION || item.getType() == Material.LINGERING_POTION || item.getType() == Material.TIPPED_ARROW)
return EnumPotionEffect.getLocalizedName(item, locale);
else if (item.getType() == Material.MONSTER_EGG)
return EnumEntity.getSpawnEggName(item, locale);
else if (item.getType() == Material.SKULL_ITEM && item.getDurability() == 3) // is player's skull
else if (item.getType() == Material.PLAYER_HEAD || item.getType() == Material.PLAYER_WALL_HEAD) // is player's skull
return EnumItem.getPlayerSkullName(item, locale);

return translateToLocal(getItemUnlocalizedName(item), locale);
Expand All @@ -93,7 +91,7 @@ public static String getItemName(ItemStack item, Player player) {
* @return The unlocalized name. If the item doesn't have a unlocalized name, this method will return the Material of it.
*/
public static String getItemUnlocalizedName(ItemStack item) {
EnumItem enumItem = EnumItem.get(new ItemEntry(item));
EnumItem enumItem = EnumItem.get(item.getType());
return enumItem != null ? enumItem.getUnlocalizedName() : item.getType().toString();
}

Expand Down Expand Up @@ -228,7 +226,7 @@ public static String getEnchantmentLevelName(int level, String locale) {
*/
public static String getEnchantmentUnlocalizedName(Enchantment enchantment) {
EnumEnchantment enumEnch = EnumEnchantment.get(enchantment);
return (enumEnch != null ? enumEnch.getUnlocalizedName() : enchantment.getName());
return (enumEnch != null ? enumEnch.getUnlocalizedName() : enchantment.getKey().getKey());
}

/**
Expand Down
66 changes: 35 additions & 31 deletions src/main/java/com/meowj/langutils/lang/convert/EnumEnchantment.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,38 +25,42 @@
*/
public enum EnumEnchantment {

PROTECTION_ENVIRONMENTAL(Enchantment.PROTECTION_ENVIRONMENTAL, "enchantment.protect.all"),
PROTECTION_FIRE(Enchantment.PROTECTION_FIRE, "enchantment.protect.fire"),
PROTECTION_FALL(Enchantment.PROTECTION_FALL, "enchantment.protect.fall"),
PROTECTION_EXPLOSIONS(Enchantment.PROTECTION_EXPLOSIONS, "enchantment.protect.explosion"),
PROTECTION_PROJECTILE(Enchantment.PROTECTION_PROJECTILE, "enchantment.protect.projectile"),
OXYGEN(Enchantment.OXYGEN, "enchantment.oxygen"),
WATER_WORKER(Enchantment.WATER_WORKER, "enchantment.waterWorker"),
THORNS(Enchantment.THORNS, "enchantment.thorns"),
DEPTH_STRIDER(Enchantment.DEPTH_STRIDER, "enchantment.waterWalker"),
FROST_WALKER(Enchantment.FROST_WALKER, "enchantment.frostWalker"),
DAMAGE_ALL(Enchantment.DAMAGE_ALL, "enchantment.damage.all"),
DAMAGE_UNDEAD(Enchantment.DAMAGE_UNDEAD, "enchantment.damage.undead"),
DAMAGE_ARTHROPODS(Enchantment.DAMAGE_ARTHROPODS, "enchantment.damage.arthropods"),
KNOCKBACK(Enchantment.KNOCKBACK, "enchantment.knockback"),
FIRE_ASPECT(Enchantment.FIRE_ASPECT, "enchantment.fire"),
LOOT_BONUS_MOBS(Enchantment.LOOT_BONUS_MOBS, "enchantment.lootBonus"),
DIG_SPEED(Enchantment.DIG_SPEED, "enchantment.digging"),
SILK_TOUCH(Enchantment.SILK_TOUCH, "enchantment.untouching"),
DURABILITY(Enchantment.DURABILITY, "enchantment.durability"),
LOOT_BONUS_BLOCKS(Enchantment.LOOT_BONUS_BLOCKS, "enchantment.lootBonusDigger"),
ARROW_DAMAGE(Enchantment.ARROW_DAMAGE, "enchantment.arrowDamage"),
ARROW_KNOCKBACK(Enchantment.ARROW_KNOCKBACK, "enchantment.arrowKnockback"),
ARROW_FIRE(Enchantment.ARROW_FIRE, "enchantment.arrowFire"),
ARROW_INFINITE(Enchantment.ARROW_INFINITE, "enchantment.arrowInfinite"),
LUCK(Enchantment.LUCK, "enchantment.lootBonusFishing"),
LURE(Enchantment.LURE, "enchantment.fishingSpeed"),
MENDING(Enchantment.MENDING, "enchantment.mending"),
BINDING_CURSE(Enchantment.BINDING_CURSE, "enchantment.binding_curse"),
VANISHING_CURSE(Enchantment.VANISHING_CURSE, "enchantment.vanishing_curse"),
SWEEPING_EDGE(Enchantment.SWEEPING_EDGE, "enchantment.sweeping");
ARROW_DAMAGE(Enchantment.ARROW_DAMAGE, "enchantment.minecraft.power"),
ARROW_FIRE(Enchantment.ARROW_FIRE, "enchantment.minecraft.flame"),
ARROW_INFINITE(Enchantment.ARROW_INFINITE, "enchantment.minecraft.infinity"),
ARROW_KNOCKBACK(Enchantment.ARROW_KNOCKBACK, "enchantment.minecraft.knockback"),
BINDING_CURSE(Enchantment.BINDING_CURSE, "enchantment.minecraft.binding_curse"),
CHANNELING(Enchantment.CHANNELING, "enchantment.minecraft.channeling"),
DAMAGE_ALL(Enchantment.DAMAGE_ALL, "enchantment.minecraft.sharpness"),
DAMAGE_ARTHROPODS(Enchantment.DAMAGE_ARTHROPODS, "enchantment.minecraft.bane_of_arthropods"),
DAMAGE_UNDEAD(Enchantment.DAMAGE_UNDEAD, "enchantment.minecraft.smite"),
DEPTH_STRIDER(Enchantment.DEPTH_STRIDER, "enchantment.minecraft.depth_strider"),
DIG_SPEED(Enchantment.DIG_SPEED, "enchantment.minecraft.efficiency"),
DURABILITY(Enchantment.DURABILITY, "enchantment.minecraft.unbreaking"),
FIRE_ASPECT(Enchantment.FIRE_ASPECT, "enchantment.minecraft.fire_aspect"),
FROST_WALKER(Enchantment.FROST_WALKER, "enchantment.minecraft.frost_walker"),
IMPALING(Enchantment.IMPALING, "enchantment.minecraft.impaling"),
KNOCKBACK(Enchantment.KNOCKBACK, "enchantment.minecraft.knockback"),
LOOT_BONUS_BLOCKS(Enchantment.LOOT_BONUS_BLOCKS, "enchantment.minecraft.fortune"),
LOOT_BONUS_MOBS(Enchantment.LOOT_BONUS_MOBS, "enchantment.minecraft.looting"),
LOYALTY(Enchantment.LOYALTY, "enchantment.minecraft.loyalty"),
LUCK(Enchantment.LUCK, "enchantment.minecraft.luck_of_the_sea"),
LURE(Enchantment.LURE, "enchantment.minecraft.lure"),
MENDING(Enchantment.MENDING, "enchantment.minecraft.mending"),
OXYGEN(Enchantment.OXYGEN, "enchantment.minecraft.respiration"),
PROTECTION_ENVIRONMENTAL(Enchantment.PROTECTION_ENVIRONMENTAL, "enchantment.minecraft.protection"),
PROTECTION_EXPLOSIONS(Enchantment.PROTECTION_EXPLOSIONS, "enchantment.minecraft.blast_protection"),
PROTECTION_FALL(Enchantment.PROTECTION_FALL, "enchantment.minecraft.feather_falling"),
PROTECTION_FIRE(Enchantment.PROTECTION_FIRE, "enchantment.minecraft.fire_protection"),
PROTECTION_PROJECTILE(Enchantment.PROTECTION_PROJECTILE, "enchantment.minecraft.projectile_protection"),
RIPTIDE(Enchantment.RIPTIDE, "enchantment.minecraft.riptide"),
SILK_TOUCH(Enchantment.SILK_TOUCH, "enchantment.minecraft.sweeping"),
SWEEPING_EDGE(Enchantment.SWEEPING_EDGE, "enchantment.minecraft.sweeping"),
THORNS(Enchantment.THORNS, "enchantment.minecraft.thorns"),
VANISHING_CURSE(Enchantment.VANISHING_CURSE, "enchantment.minecraft.vanishing_curse"),
WATER_WORKER(Enchantment.WATER_WORKER, "enchantment.minecraft.aqua_affinity");

private static final Map<Enchantment, EnumEnchantment> lookup = new HashMap<Enchantment, EnumEnchantment>();
private static final Map<Enchantment, EnumEnchantment> lookup = new HashMap<>();

static {
for (EnumEnchantment enchantment : EnumSet.allOf(EnumEnchantment.class))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@

package com.meowj.langutils.lang.convert;

import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;

/**
* This file is part of LanguageUtils
* <p>
Expand All @@ -32,14 +28,7 @@ public enum EnumEnchantmentLevel {
LEVEL7(7, "enchantment.level.7"),
LEVEL8(8, "enchantment.level.8"),
LEVEL9(9, "enchantment.level.9"),
LEVEL10(10, "enchantment.level.10"),;

private static final Map<Integer, EnumEnchantmentLevel> lookup = new HashMap<Integer, EnumEnchantmentLevel>();

static {
for (EnumEnchantmentLevel level : EnumSet.allOf(EnumEnchantmentLevel.class))
lookup.put(level.getLevel(), level);
}
LEVEL10(10, "enchantment.level.10");

private int level;
private String unlocalizedName;
Expand All @@ -56,8 +45,31 @@ public enum EnumEnchantmentLevel {
* @param level Enchantment level.
* @return The index of a level.
*/
public static EnumEnchantmentLevel get(Integer level) {
return lookup.get(level);
public static EnumEnchantmentLevel get(int level) {
switch (level) {
case 1:
return LEVEL1;
case 2:
return LEVEL2;
case 3:
return LEVEL3;
case 4:
return LEVEL4;
case 5:
return LEVEL5;
case 6:
return LEVEL6;
case 7:
return LEVEL7;
case 8:
return LEVEL8;
case 9:
return LEVEL9;
case 10:
return LEVEL10;
default:
throw new IndexOutOfBoundsException();
}
}

/**
Expand Down
Loading