Skip to content

Commit 8586ca0

Browse files
committed
🐛 Fix hologram NPE crash, enchant command, add LUNGE enchantment
- HologramLoader/Module: null check when NMS class unavailable (prevents plugin crash) - CommandEnchant: fallback for deprecated translationKey() - ZEnchantments: add LUNGE (1.21.11), null-safe register, use valueOf() for 1.21 enchants
1 parent 38f1caa commit 8586ca0

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

src/main/java/fr/maxlego08/essentials/commands/commands/utils/admins/CommandEnchant.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,12 @@ protected CommandResultType perform(EssentialsPlugin plugin) {
5252
}
5353

5454
enchant(itemStack, enchantment, level);
55-
String translatedEnchantments = "<lang:" + enchantment.translationKey() + ">";
55+
String translatedEnchantments;
56+
try {
57+
translatedEnchantments = "<lang:" + enchantment.translationKey() + ">";
58+
} catch (Exception e) {
59+
translatedEnchantments = "<lang:enchantment.minecraft." + enchantment.getKey().getKey() + ">";
60+
}
5661

5762
if (level == 0) {
5863
message(sender, player, Message.COMMAND_ENCHANT_REMOVE_SELF, Message.COMMAND_ENCHANT_REMOVE_PLAYER, "%enchant%", translatedEnchantments);

src/main/java/fr/maxlego08/essentials/enchantments/ZEnchantments.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,17 @@ public void register() {
6060
this.register(Enchantment.SOUL_SPEED, "soulspeed", "soilspeed", "sandspeed");
6161
this.register(Enchantment.SWIFT_SNEAK, "swiftsneak");
6262

63-
// 1.21
64-
try {
65-
this.register(Enchantment.getByName("BREACH"), "breach");
66-
this.register(Enchantment.getByName("DENSITY"), "density");
67-
this.register(Enchantment.getByName("WIND_BURST"), "windburst", "wind", "burst");
68-
} catch (Exception ignored) {
69-
}
63+
// 1.21+
64+
this.register(valueOf("BREACH"), "breach");
65+
this.register(valueOf("DENSITY"), "density");
66+
this.register(valueOf("WIND_BURST"), "windburst", "wind", "burst");
67+
68+
// 1.21.11+
69+
this.register(valueOf("LUNGE"), "lunge");
7070
}
7171

7272
private void register(Enchantment enchantment, String... strings) {
73+
if (enchantment == null) return;
7374
this.essentialsEnchantments.add(new ZEssentialsEnchantment(enchantment, Arrays.asList(strings)));
7475
}
7576

src/main/java/fr/maxlego08/essentials/module/modules/hologram/HologramLoader.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ public Hologram load(YamlConfiguration configuration, String path, Object... obj
5353
HologramManager hologramManager = this.plugin.getHologramManager();
5454
Hologram hologram = hologramManager.createHologram(hologramType, hologramConfiguration, (String) objects[0], name, location);
5555

56+
if (hologram == null) {
57+
this.plugin.getLogger().warning("Failed to create hologram '" + name + "', NMS class not available for this server version.");
58+
return null;
59+
}
60+
5661
loadConfiguration(configuration, hologramConfiguration);
5762

5863
switch (hologramType) {

src/main/java/fr/maxlego08/essentials/module/modules/hologram/HologramModule.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ public void loadHologram(File file) {
242242

243243
try {
244244
Hologram hologram = loader.load(configuration, "", file.getName().replace(".yml", ""));
245+
if (hologram == null) return;
245246
if (hologram.canLoad()) {
246247
hologram.create();
247248
hologram.createForAllPlayers();

0 commit comments

Comments
 (0)