mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-01-05 07:57:59 +01:00
Use enchantment key names for 1.13+
Enchantment#getName is deprecated and gives the wrong names for enchantments starting in 1.21
This commit is contained in:
parent
64531aa862
commit
b392f03ad1
@ -334,6 +334,17 @@ public final class Enchantments {
|
|||||||
private Enchantments() {
|
private Enchantments() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getRealName(final Enchantment enchantment) {
|
||||||
|
if (enchantment == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isFlat) { // 1.13+ only
|
||||||
|
return enchantment.getKey().getKey();
|
||||||
|
}
|
||||||
|
return enchantment.getName().toLowerCase(Locale.ENGLISH);
|
||||||
|
}
|
||||||
|
|
||||||
public static Enchantment getByName(final String name) {
|
public static Enchantment getByName(final String name) {
|
||||||
if (name == null || name.isEmpty()) {
|
if (name == null || name.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -576,7 +576,7 @@ public class MetaItemStack {
|
|||||||
if (enchantment == null) {
|
if (enchantment == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (hasMetaPermission(sender, "enchantments." + enchantment.getName().toLowerCase(Locale.ENGLISH), false, false, ess)) {
|
if (hasMetaPermission(sender, "enchantments." + Enchantments.getRealName(enchantment), false, false, ess)) {
|
||||||
int level = -1;
|
int level = -1;
|
||||||
if (split.length > 1) {
|
if (split.length > 1) {
|
||||||
try {
|
try {
|
||||||
@ -619,7 +619,7 @@ public class MetaItemStack {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (final Exception ex) {
|
} catch (final Exception ex) {
|
||||||
throw new Exception("Enchantment " + enchantment.getName() + ": " + ex.getMessage(), ex);
|
throw new Exception("Enchantment " + Enchantments.getRealName(enchantment) + ": " + ex.getMessage(), ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -629,7 +629,7 @@ public class MetaItemStack {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
final String enchantmentName = enchantment.getName().toLowerCase(Locale.ENGLISH);
|
final String enchantmentName = Enchantments.getRealName(enchantment);
|
||||||
|
|
||||||
if (!hasMetaPermission(user, "enchantments." + enchantmentName, true, false)) {
|
if (!hasMetaPermission(user, "enchantments." + enchantmentName, true, false)) {
|
||||||
throw new TranslatableException("enchantmentPerm", enchantmentName);
|
throw new TranslatableException("enchantmentPerm", enchantmentName);
|
||||||
|
@ -14,7 +14,6 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
@ -35,7 +34,7 @@ public class Commandenchant extends EssentialsCommand {
|
|||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
final Set<String> usableEnchants = new TreeSet<>();
|
final Set<String> usableEnchants = new TreeSet<>();
|
||||||
for (final Map.Entry<String, Enchantment> entry : Enchantments.entrySet()) {
|
for (final Map.Entry<String, Enchantment> entry : Enchantments.entrySet()) {
|
||||||
final String name = entry.getValue().getName().toLowerCase(Locale.ENGLISH);
|
final String name = Enchantments.getRealName(entry.getValue());
|
||||||
if (usableEnchants.contains(name) || (user.isAuthorized("essentials.enchantments." + name) && entry.getValue().canEnchantItem(stack))) {
|
if (usableEnchants.contains(name) || (user.isAuthorized("essentials.enchantments." + name) && entry.getValue().canEnchantItem(stack))) {
|
||||||
usableEnchants.add(entry.getKey());
|
usableEnchants.add(entry.getKey());
|
||||||
}
|
}
|
||||||
@ -57,7 +56,7 @@ public class Commandenchant extends EssentialsCommand {
|
|||||||
metaStack.addEnchantment(user.getSource(), ess.getSettings().allowUnsafeEnchantments() && user.isAuthorized("essentials.enchantments.allowunsafe"), enchantment, level);
|
metaStack.addEnchantment(user.getSource(), ess.getSettings().allowUnsafeEnchantments() && user.isAuthorized("essentials.enchantments.allowunsafe"), enchantment, level);
|
||||||
stack.setItemMeta(metaStack.getItemStack().getItemMeta());
|
stack.setItemMeta(metaStack.getItemStack().getItemMeta());
|
||||||
user.getBase().updateInventory();
|
user.getBase().updateInventory();
|
||||||
final String enchantName = enchantment.getName().toLowerCase(Locale.ENGLISH).replace('_', ' ');
|
final String enchantName = Enchantments.getRealName(enchantment).replace('_', ' ');
|
||||||
if (level == 0) {
|
if (level == 0) {
|
||||||
user.sendTl("enchantmentRemoved", enchantName);
|
user.sendTl("enchantmentRemoved", enchantName);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.earth2me.essentials.items;
|
package com.earth2me.essentials.items;
|
||||||
|
|
||||||
|
import com.earth2me.essentials.Enchantments;
|
||||||
import com.earth2me.essentials.IConf;
|
import com.earth2me.essentials.IConf;
|
||||||
import com.earth2me.essentials.User;
|
import com.earth2me.essentials.User;
|
||||||
import com.earth2me.essentials.craftbukkit.Inventories;
|
import com.earth2me.essentials.craftbukkit.Inventories;
|
||||||
@ -218,7 +219,7 @@ public abstract class AbstractItemDb implements IConf, net.ess3.api.IItemDb {
|
|||||||
|
|
||||||
if (meta.hasEnchants()) {
|
if (meta.hasEnchants()) {
|
||||||
for (final Enchantment e : meta.getEnchants().keySet()) {
|
for (final Enchantment e : meta.getEnchants().keySet()) {
|
||||||
sb.append(e.getName().toLowerCase()).append(":").append(meta.getEnchantLevel(e)).append(" ");
|
sb.append(Enchantments.getRealName(e)).append(":").append(meta.getEnchantLevel(e)).append(" ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -263,7 +264,7 @@ public abstract class AbstractItemDb implements IConf, net.ess3.api.IItemDb {
|
|||||||
case ENCHANTED_BOOK:
|
case ENCHANTED_BOOK:
|
||||||
final EnchantmentStorageMeta enchantmentStorageMeta = (EnchantmentStorageMeta) is.getItemMeta();
|
final EnchantmentStorageMeta enchantmentStorageMeta = (EnchantmentStorageMeta) is.getItemMeta();
|
||||||
for (final Enchantment e : enchantmentStorageMeta.getStoredEnchants().keySet()) {
|
for (final Enchantment e : enchantmentStorageMeta.getStoredEnchants().keySet()) {
|
||||||
sb.append(e.getName().toLowerCase()).append(":").append(enchantmentStorageMeta.getStoredEnchantLevel(e)).append(" ");
|
sb.append(Enchantments.getRealName(e)).append(":").append(enchantmentStorageMeta.getStoredEnchantLevel(e)).append(" ");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -106,7 +106,7 @@ public class SignEnchant extends EssentialsSign {
|
|||||||
throw new SignException(ex, "errorWithMessage", ex.getMessage());
|
throw new SignException(ex, "errorWithMessage", ex.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
final String enchantmentName = enchantment.getName().toLowerCase(Locale.ENGLISH);
|
final String enchantmentName = Enchantments.getRealName(enchantment);
|
||||||
if (level == 0) {
|
if (level == 0) {
|
||||||
player.sendTl("enchantmentRemoved", enchantmentName.replace('_', ' '));
|
player.sendTl("enchantmentRemoved", enchantmentName.replace('_', ' '));
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user