fixed more deprecated methods

This commit is contained in:
Janik Heß
2025-03-08 23:15:30 +01:00
parent 9a858aef69
commit bc71ccee8f
2 changed files with 31 additions and 14 deletions

View File

@@ -4,10 +4,9 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeModifier;
import org.bukkit.attribute.AttributeModifier.Operation;
@@ -17,7 +16,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.inventory.PrepareAnvilEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.EquipmentSlotGroup;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.view.AnvilView;
@@ -32,12 +31,13 @@ public class ArmoredElytra implements Listener {
@EventHandler
public void tes(PlayerDeathEvent e) {
Location deathLoc = e.getPlayer().getLocation();
new BukkitRunnable() {
@Override
public void run() {
e.getPlayer().spigot().respawn();
e.getPlayer().sendMessage("Todes koordinaten: " + deathLoc.getBlockX() + " " + deathLoc.getBlockY() + " " + deathLoc.getBlockZ());
e.getPlayer().sendMessage("Todes koordinaten: " + deathLoc.getBlockX() + " " + deathLoc.getBlockY()
+ " " + deathLoc.getBlockZ());
}
}.runTaskLater(App.main, 1L); // Run next tick to prevent death screen
}
@@ -114,19 +114,27 @@ public class ArmoredElytra implements Listener {
}
}
}
NamespacedKey armor_modifierKey = new NamespacedKey("environmentex", "armor");
NamespacedKey armor_toughness_modifierKey = new NamespacedKey("environmentex",
"armor_toughness");
NamespacedKey armor_knockback_resistance_modifierKey = new NamespacedKey("environmentex",
"knockback_resistance");
if (armor != 0) {
AttributeModifier mod = new AttributeModifier(UUID.randomUUID(), "armor", armor,
Operation.ADD_NUMBER, EquipmentSlot.CHEST);
AttributeModifier mod = new AttributeModifier(armor_modifierKey, armor,
Operation.ADD_NUMBER, EquipmentSlotGroup.CHEST);
// Add the attribute modifier to the meta data for the item
meta.addAttributeModifier(Attribute.ARMOR, mod);
}
if (toughness != 0) {
AttributeModifier mod = new AttributeModifier(UUID.randomUUID(), "armor_toughness",
toughness, Operation.ADD_NUMBER, EquipmentSlot.CHEST);
AttributeModifier mod = new AttributeModifier(armor_toughness_modifierKey, toughness,
Operation.ADD_NUMBER, EquipmentSlotGroup.CHEST);
meta.addAttributeModifier(Attribute.ARMOR_TOUGHNESS, mod);
}
if (knockbackres != 0) {
AttributeModifier mod = new AttributeModifier(UUID.randomUUID(), "knockback_resistance",
knockbackres, Operation.ADD_NUMBER, EquipmentSlot.CHEST);
AttributeModifier mod = new AttributeModifier(armor_knockback_resistance_modifierKey,
knockbackres, Operation.ADD_NUMBER, EquipmentSlotGroup.CHEST);
meta.addAttributeModifier(Attribute.KNOCKBACK_RESISTANCE, mod);
}
for (Enchantment ench : item2.getEnchantments().keySet()) {
@@ -145,8 +153,11 @@ public class ArmoredElytra implements Listener {
combinedElytra.setItemMeta(meta);
for (Enchantment ench : enchants.keySet()) {
combinedElytra.addUnsafeEnchantment(Enchantment.getByKey(ench.getKey()),
enchants.get(ench));
if (ench != null) {
combinedElytra.addUnsafeEnchantment(ench, enchants.get(ench));
}
}
ItemMeta elytraMeta = combinedElytra.getItemMeta();
Style st = Style.style().color(NamedTextColor.DARK_PURPLE)

View File

@@ -10,7 +10,9 @@ import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.server.ServerLoadEvent;
import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.MenuType;
import org.bukkit.inventory.ShapedRecipe;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.components.CustomModelDataComponent;
@@ -59,7 +61,11 @@ public class WorkbenchToGo implements Listener {
return;
}
e.setCancelled(true);
e.getPlayer().openWorkbench(null, true);
MenuType.Typed<InventoryView, ?> craftingMenuType = MenuType.CRAFTING;
InventoryView craftingView = craftingMenuType.builder()
.title(Component.text("Custom Crafting"))
.build(e.getPlayer());
e.getPlayer().openInventory(craftingView);
}
}
}