Skip to content

Commit

Permalink
Fixed depreciation warnings for /ench and removed unnecessary code fr…
Browse files Browse the repository at this point in the history
…om Enchantments.java
  • Loading branch information
Calcilore committed Apr 21, 2024
1 parent ad70da8 commit b2e6000
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
7 changes: 3 additions & 4 deletions src/main/java/net/serble/estools/Commands/Ench.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.serble.estools.Enchantments;
import net.serble.estools.Main;
import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.enchantments.Enchantment;
Expand Down Expand Up @@ -56,8 +57,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
Enchantment ench;
try {
if (Main.majorVersion > 12) {
// TODO: Fix for versions that use Registry
ench = Enchantment.getByKey(NamespacedKey.minecraft(args[0].toLowerCase()));
ench = Registry.ENCHANTMENT.get(NamespacedKey.minecraft(args[0].toLowerCase()));
} else {
ench = Enchantments.getByName(args[0].toLowerCase());
}
Expand All @@ -84,8 +84,7 @@ public List<String> tabComplete(CommandSender sender, String[] args, String lArg
switch (args.length) {
case 1:
if (Main.majorVersion > 12) {
// TODO: Fix for versions that use Registry
for (Enchantment e : Enchantment.values()) {
for (Enchantment e : Registry.ENCHANTMENT) {
tab.add(e.getKey().getKey());
}
} else {
Expand Down
8 changes: 2 additions & 6 deletions src/main/java/net/serble/estools/Enchantments.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import java.util.Map;
import java.util.Set;

// This class exists because the registry doesn't exist pre 1.13, so all the enchantments names have to be hardcoded.
// only enchantments before 1.13 need to be here because this class isn't used past 1.13
public class Enchantments {
private static final Map<String, Enchantment> ENCHANTMENTS = new HashMap<>();

Expand Down Expand Up @@ -60,11 +62,5 @@ private static void AddEnchants() {
ENCHANTMENTS.put("bindingcurse", Enchantment.BINDING_CURSE);
ENCHANTMENTS.put("vanishingcurse", Enchantment.VANISHING_CURSE);
ENCHANTMENTS.put("sweepingedge", Enchantment.SWEEPING_EDGE);

if (Main.majorVersion <= 15) return;
ENCHANTMENTS.put("soulspeed", Enchantment.SOUL_SPEED);

if (Main.majorVersion <= 18) return;
ENCHANTMENTS.put("loyalty", Enchantment.LOYALTY);
}
}

0 comments on commit b2e6000

Please sign in to comment.