mirror of
https://github.com/PikaMug/Quests.git
synced 2025-03-09 13:19:36 +01:00
Fix translate-items not working on older MC versions, fixes #575
This commit is contained in:
parent
ab265cab74
commit
6bb5f81e68
@ -26,6 +26,7 @@ import org.bukkit.entity.Player;
|
||||
|
||||
public class LocaleQuery {
|
||||
private static Class<?> craftMagicNumbers = null;
|
||||
private static Class<?> itemClazz = null;
|
||||
private final Quests plugin;
|
||||
private static boolean oldVersion = false;
|
||||
|
||||
@ -41,12 +42,12 @@ public class LocaleQuery {
|
||||
public void sendMessage(Player player, String message, Material material) {
|
||||
if (plugin.translateItems) {
|
||||
String key = queryByType(material);
|
||||
if (key != null) {
|
||||
if (oldVersion) {
|
||||
if (key.startsWith("tile.") || key.startsWith("item.")) {
|
||||
key = key + ".name";
|
||||
}
|
||||
}
|
||||
if (key != null) {
|
||||
String msg = message.replace("<item>", "\",{\"translate\":\"" + key + "\"},\"");
|
||||
player.chat("/tellraw " + player.getName() + " [\"" + msg + "\"]");
|
||||
return;
|
||||
@ -59,6 +60,7 @@ public class LocaleQuery {
|
||||
public void sendMessage(Player player, String message, Material material, Enchantment enchantment) {
|
||||
if (plugin.translateItems) {
|
||||
String key = queryByType(material);
|
||||
if (key != null) {
|
||||
if (oldVersion) {
|
||||
if (key.startsWith("tile.") || key.startsWith("item.")) {
|
||||
key = key + ".name";
|
||||
@ -71,13 +73,14 @@ public class LocaleQuery {
|
||||
} else {
|
||||
key2 = "enchantment.minecraft." + enchantment.toString().toLowerCase();
|
||||
}
|
||||
if (key != null && !key.equals("")) {
|
||||
if (!key2.equals("")) {
|
||||
String msg = message.replace("<item>", "\",{\"translate\":\"" + key + "\"},\"")
|
||||
.replace("<enchantment>", "\",{\"translate\":\"" + key2 + "\"},\"");
|
||||
player.chat("/tellraw " + player.getName() + " [\"" + msg + "\"]");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
player.sendMessage(message.replace("<item>", Quester.prettyItemString(material.name()))
|
||||
.replace("<enchantment>", Quester.prettyEnchantmentString(enchantment)));
|
||||
}
|
||||
@ -112,8 +115,7 @@ public class LocaleQuery {
|
||||
if (item == null) {
|
||||
throw new IllegalArgumentException("An item with that material could not be found! (Perhaps you have specified a block?)");
|
||||
}
|
||||
|
||||
String name = (String) MethodUtils.invokeExactMethod(item, "getName");
|
||||
String name = (String) itemClazz.getMethod("getName").invoke(item);
|
||||
return name;
|
||||
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
@ -125,6 +127,7 @@ public class LocaleQuery {
|
||||
String version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
|
||||
try {
|
||||
craftMagicNumbers = Class.forName("org.bukkit.craftbukkit.{v}.util.CraftMagicNumbers".replace("{v}", version));
|
||||
itemClazz = Class.forName("net.minecraft.server.{v}.Item".replace("{v}", version));
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user