Skip to content

Commit

Permalink
Add support for more minor versions
Browse files Browse the repository at this point in the history
  • Loading branch information
BoomEaro committed Aug 27, 2024
1 parent afb534c commit 7506a80
Show file tree
Hide file tree
Showing 14 changed files with 375 additions and 4 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

LangHelper - это простой API плагин, который позволяет получить любую переведенную строку клиента игры Minecraft.

Поддерживаются только самые последние релизные версии Minecraft:
Поддерживаются версии Minecraft:
1.12.2,
1.13.2,
1.14.4,
Expand All @@ -11,7 +11,14 @@ LangHelper - это простой API плагин, который позвол
1.17.1,
1.18.2,
1.19.4
1.20
1.20.1
1.20.2
1.20.3
1.20.4
1.20.5
1.20.6
1.21
1.21.1

Плагин поддерживает все языки которые поддерживает сам Minecraft.
Expand Down
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ dependencies {
implementation project(":nms:1_17_R1")
implementation project(":nms:1_18_R2")
implementation project(":nms:1_19_R3")
implementation project(":nms:1_20_R1")
implementation project(":nms:1_20_R2")
implementation project(":nms:1_20_R3")
implementation project(":nms:1_20_R4")
implementation project(":nms:1_21_R1")
}
Expand Down
4 changes: 4 additions & 0 deletions nms/1_20_R1/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dependencies {
compileOnly project(":common")
compileOnly "org.spigotmc:spigot:1.20-R0.1-SNAPSHOT"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package ru.boomearo.langhelper.versions;

import com.google.common.base.Preconditions;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemLingeringPotion;
import net.minecraft.world.item.ItemPotion;
import net.minecraft.world.item.ItemSplashPotion;
import net.minecraft.world.item.alchemy.PotionUtil;
import org.bukkit.Material;
import org.bukkit.block.Biome;
import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftItemStack;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.EntityType;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin;
import org.bukkit.potion.PotionEffectType;
import ru.boomearo.langhelper.managers.ConfigManager;

import java.util.Locale;
import java.util.logging.Level;

public class Translate1_20_R1 extends JsonTranslateManager {

public Translate1_20_R1(Plugin plugin, ConfigManager configManager) {
super("1.20", plugin, configManager);
}

@Override
public String getItemName(ItemStack item, LangType langType) {
Preconditions.checkArgument(item != null);
Preconditions.checkArgument(langType != null);

try {
net.minecraft.world.item.ItemStack itemStack = CraftItemStack.asNMSCopy(item);

String name;
Item i = itemStack.d();
if (i instanceof ItemSplashPotion) {
name = "item.minecraft." + PotionUtil.d(itemStack).b("splash_potion.effect.");
} else if (i instanceof ItemLingeringPotion) {
name = "item.minecraft." + PotionUtil.d(itemStack).b("lingering_potion.effect.");
} else if (i instanceof ItemPotion) {
name = "item.minecraft." + PotionUtil.d(itemStack).b("potion.effect.");
} else {
name = i.a();
}

if (item.getType() != Material.AIR) {
if (name.equals("block.minecraft.air")) {
return null;
}
}

return getTranslate(name, langType);
} catch (Exception e) {
this.plugin.getLogger().log(Level.SEVERE, "Failed to get item name for " + item, e);
return null;
}
}

@Override
public String getEntityName(EntityType entityType, LangType langType) {
Preconditions.checkArgument(entityType != null);
Preconditions.checkArgument(langType != null);

return getTranslate("entity.minecraft." + entityType.getKey().getKey(), langType);
}

@Override
public String getEnchantmentName(Enchantment enchant, LangType langType) {
Preconditions.checkArgument(enchant != null);
Preconditions.checkArgument(langType != null);

return getTranslate("enchantment.minecraft." + enchant.getKey().getKey(), langType);
}

@Override
public String getEnchantmentLevelName(int level, LangType langType) {
Preconditions.checkArgument(langType != null);

return getTranslate("enchantment.level." + level, langType);
}

@Override
public String getPotionEffectName(PotionEffectType potionEffectType, LangType langType) {
Preconditions.checkArgument(potionEffectType != null);
Preconditions.checkArgument(langType != null);

String effectName = switch (potionEffectType.getName().toLowerCase(Locale.ROOT)) {
case "fast_digging" -> "haste";
case "harm" -> "instant_damage";
case "heal" -> "instant_health";
case "jump" -> "jump_boost";
case "slow_digging" -> "mining_fatigue";
case "confusion" -> "nausea";
case "damage_resistance" -> "resistance";
case "slow" -> "slowness";
case "increase_damage" -> "strength";
default -> potionEffectType.getName().toLowerCase(Locale.ROOT);
};
String name = "effect.minecraft." + effectName;
return getTranslate(name, langType);
}

@Override
public String getBiomeName(Biome biome, LangType langType) {
Preconditions.checkArgument(biome != null);
Preconditions.checkArgument(langType != null);

return getTranslate("biome.minecraft." + biome.name().toLowerCase(Locale.ROOT), langType);
}
}
4 changes: 4 additions & 0 deletions nms/1_20_R2/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dependencies {
compileOnly project(":common")
compileOnly "org.spigotmc:spigot:1.20.2-R0.1-SNAPSHOT"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package ru.boomearo.langhelper.versions;

import com.google.common.base.Preconditions;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemLingeringPotion;
import net.minecraft.world.item.ItemPotion;
import net.minecraft.world.item.ItemSplashPotion;
import net.minecraft.world.item.alchemy.PotionUtil;
import org.bukkit.Material;
import org.bukkit.block.Biome;
import org.bukkit.craftbukkit.v1_20_R2.inventory.CraftItemStack;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.EntityType;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin;
import org.bukkit.potion.PotionEffectType;
import ru.boomearo.langhelper.managers.ConfigManager;

import java.util.Locale;
import java.util.logging.Level;

public class Translate1_20_R2 extends JsonTranslateManager {

public Translate1_20_R2(Plugin plugin, ConfigManager configManager) {
super("1.20.2", plugin, configManager);
}

@Override
public String getItemName(ItemStack item, LangType langType) {
Preconditions.checkArgument(item != null);
Preconditions.checkArgument(langType != null);

try {
net.minecraft.world.item.ItemStack itemStack = CraftItemStack.asNMSCopy(item);

String name;
Item i = itemStack.d();
if (i instanceof ItemSplashPotion) {
name = "item.minecraft." + PotionUtil.d(itemStack).b("splash_potion.effect.");
} else if (i instanceof ItemLingeringPotion) {
name = "item.minecraft." + PotionUtil.d(itemStack).b("lingering_potion.effect.");
} else if (i instanceof ItemPotion) {
name = "item.minecraft." + PotionUtil.d(itemStack).b("potion.effect.");
} else {
name = i.a();
}

if (item.getType() != Material.AIR) {
if (name.equals("block.minecraft.air")) {
return null;
}
}

return getTranslate(name, langType);
} catch (Exception e) {
this.plugin.getLogger().log(Level.SEVERE, "Failed to get item name for " + item, e);
return null;
}
}

@Override
public String getEntityName(EntityType entityType, LangType langType) {
Preconditions.checkArgument(entityType != null);
Preconditions.checkArgument(langType != null);

return getTranslate("entity.minecraft." + entityType.getKey().getKey(), langType);
}

@Override
public String getEnchantmentName(Enchantment enchant, LangType langType) {
Preconditions.checkArgument(enchant != null);
Preconditions.checkArgument(langType != null);

return getTranslate("enchantment.minecraft." + enchant.getKey().getKey(), langType);
}

@Override
public String getEnchantmentLevelName(int level, LangType langType) {
Preconditions.checkArgument(langType != null);

return getTranslate("enchantment.level." + level, langType);
}

@Override
public String getPotionEffectName(PotionEffectType potionEffectType, LangType langType) {
Preconditions.checkArgument(potionEffectType != null);
Preconditions.checkArgument(langType != null);

String effectName = switch (potionEffectType.getName().toLowerCase(Locale.ROOT)) {
case "fast_digging" -> "haste";
case "harm" -> "instant_damage";
case "heal" -> "instant_health";
case "jump" -> "jump_boost";
case "slow_digging" -> "mining_fatigue";
case "confusion" -> "nausea";
case "damage_resistance" -> "resistance";
case "slow" -> "slowness";
case "increase_damage" -> "strength";
default -> potionEffectType.getName().toLowerCase(Locale.ROOT);
};
String name = "effect.minecraft." + effectName;
return getTranslate(name, langType);
}

@Override
public String getBiomeName(Biome biome, LangType langType) {
Preconditions.checkArgument(biome != null);
Preconditions.checkArgument(langType != null);

return getTranslate("biome.minecraft." + biome.name().toLowerCase(Locale.ROOT), langType);
}
}
4 changes: 4 additions & 0 deletions nms/1_20_R3/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dependencies {
compileOnly project(":common")
compileOnly "org.spigotmc:spigot:1.20.3-R0.1-SNAPSHOT"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package ru.boomearo.langhelper.versions;

import com.google.common.base.Preconditions;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemLingeringPotion;
import net.minecraft.world.item.ItemPotion;
import net.minecraft.world.item.ItemSplashPotion;
import net.minecraft.world.item.alchemy.PotionUtil;
import org.bukkit.Material;
import org.bukkit.block.Biome;
import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftItemStack;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.EntityType;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin;
import org.bukkit.potion.PotionEffectType;
import ru.boomearo.langhelper.managers.ConfigManager;

import java.util.Locale;
import java.util.logging.Level;

public class Translate1_20_R3 extends JsonTranslateManager {

public Translate1_20_R3(Plugin plugin, ConfigManager configManager) {
super("1.20.3", plugin, configManager);
}

@Override
public String getItemName(ItemStack item, LangType langType) {
Preconditions.checkArgument(item != null);
Preconditions.checkArgument(langType != null);

try {
net.minecraft.world.item.ItemStack itemStack = CraftItemStack.asNMSCopy(item);

String name;
Item i = itemStack.d();
if (i instanceof ItemSplashPotion) {
name = "item.minecraft." + PotionUtil.d(itemStack).b("splash_potion.effect.");
} else if (i instanceof ItemLingeringPotion) {
name = "item.minecraft." + PotionUtil.d(itemStack).b("lingering_potion.effect.");
} else if (i instanceof ItemPotion) {
name = "item.minecraft." + PotionUtil.d(itemStack).b("potion.effect.");
} else {
name = i.a();
}

if (item.getType() != Material.AIR) {
if (name.equals("block.minecraft.air")) {
return null;
}
}

return getTranslate(name, langType);
} catch (Exception e) {
this.plugin.getLogger().log(Level.SEVERE, "Failed to get item name for " + item, e);
return null;
}
}

@Override
public String getEntityName(EntityType entityType, LangType langType) {
Preconditions.checkArgument(entityType != null);
Preconditions.checkArgument(langType != null);

return getTranslate("entity.minecraft." + entityType.getKey().getKey(), langType);
}

@Override
public String getEnchantmentName(Enchantment enchant, LangType langType) {
Preconditions.checkArgument(enchant != null);
Preconditions.checkArgument(langType != null);

return getTranslate("enchantment.minecraft." + enchant.getKey().getKey(), langType);
}

@Override
public String getEnchantmentLevelName(int level, LangType langType) {
Preconditions.checkArgument(langType != null);

return getTranslate("enchantment.level." + level, langType);
}

@Override
public String getPotionEffectName(PotionEffectType potionEffectType, LangType langType) {
Preconditions.checkArgument(potionEffectType != null);
Preconditions.checkArgument(langType != null);

String effectName = switch (potionEffectType.getName().toLowerCase(Locale.ROOT)) {
case "fast_digging" -> "haste";
case "harm" -> "instant_damage";
case "heal" -> "instant_health";
case "jump" -> "jump_boost";
case "slow_digging" -> "mining_fatigue";
case "confusion" -> "nausea";
case "damage_resistance" -> "resistance";
case "slow" -> "slowness";
case "increase_damage" -> "strength";
default -> potionEffectType.getName().toLowerCase(Locale.ROOT);
};
String name = "effect.minecraft." + effectName;
return getTranslate(name, langType);
}

@Override
public String getBiomeName(Biome biome, LangType langType) {
Preconditions.checkArgument(biome != null);
Preconditions.checkArgument(langType != null);

return getTranslate("biome.minecraft." + biome.name().toLowerCase(Locale.ROOT), langType);
}
}
2 changes: 1 addition & 1 deletion nms/1_20_R4/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
dependencies {
compileOnly project(":common")
compileOnly "org.spigotmc:spigot:1.20.6-R0.1-SNAPSHOT"
compileOnly "org.spigotmc:spigot:1.20.5-R0.1-SNAPSHOT"
}
Loading

0 comments on commit 7506a80

Please sign in to comment.