Skip to content

Commit

Permalink
Add support for 1.20.4 again
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew121410 committed May 5, 2024
1 parent c5fe297 commit f8115d2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

Expand Down Expand Up @@ -37,7 +36,8 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
}

ItemStack item = InventoryUtils.createItem(Material.COMMAND_BLOCK, 1, "&cCommand Block&r", "New Fresh Command Block");
item.addUnsafeEnchantment(Enchantment.SHARPNESS, 1);
// item.addUnsafeEnchantment(Enchantment.SHARPNESS, 1);
api.TEMP_AddunsafeEnchantment_SHARPNESS(item);
p.getInventory().addItem(item);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.inventory.ItemStack;
Expand Down Expand Up @@ -69,7 +68,8 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String

if (args.length == 1 && args[0].equalsIgnoreCase("give")) {
ItemStack itemStack = new ItemStack(Material.OAK_SIGN, 1);
itemStack.addUnsafeEnchantment(Enchantment.SHARPNESS, 1);
// itemStack.addUnsafeEnchantment(Enchantment.SHARPNESS, 1);
api.TEMP_AddunsafeEnchantment_SHARPNESS(itemStack);
player.getInventory().addItem(itemStack);
return true;
} else if (args.length >= 1 && args[0].equalsIgnoreCase("edit")) {
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/com/andrew121410/mc/world16essentials/utils/API.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

import java.lang.reflect.Field;
import java.util.List;
import java.util.Map;
import java.util.UUID;
Expand Down Expand Up @@ -150,6 +153,26 @@ public Component parseMessage(Player player, String message) {
return this.getMessagesUtils().parseMessage(player, message);
}

// this is temp, and I'm sure there is a better way to do this, but I'm dumb,
// @TODO (remove method in a couple of months.)
public void TEMP_AddunsafeEnchantment_SHARPNESS(ItemStack item) {
Enchantment sharpness = null;
try {
Field sharpnessField = Enchantment.class.getDeclaredField("SHARPNESS");
sharpness = (Enchantment) sharpnessField.get(null);
} catch (NoSuchFieldException | IllegalAccessException e) {
try {
Field sharpnessField = Enchantment.class.getDeclaredField("DAMAGE_ALL");
sharpness = (Enchantment) sharpnessField.get(null);
} catch (NoSuchFieldException | IllegalAccessException e1) {
e1.printStackTrace();
}
}
if (sharpness == null) return;

item.addUnsafeEnchantment(sharpness, 1);
}

public ConfigUtils getConfigUtils() {
return configUtils;
}
Expand Down

0 comments on commit f8115d2

Please sign in to comment.