diff --git a/src/main/java/com/simolzimol/levelcraft/item/ItemUtil.java b/src/main/java/com/simolzimol/levelcraft/item/ItemUtil.java index 408452d..83f3047 100644 --- a/src/main/java/com/simolzimol/levelcraft/item/ItemUtil.java +++ b/src/main/java/com/simolzimol/levelcraft/item/ItemUtil.java @@ -21,9 +21,9 @@ public class ItemUtil { public static void setRarity(ItemStack item, Rarity rarity) { ItemMeta meta = item.getItemMeta(); meta.getPersistentDataContainer().set(rarityKey, PersistentDataType.INTEGER, rarity.getValue()); - // Optional: Lore aktualisieren - List lore = meta.hasLore() ? meta.getLore() : new java.util.ArrayList<>(); - lore.add("§7Seltenheit: §f" + rarity.getDisplayName()); + // Lore aktualisieren (alte Zeile ersetzen) + java.util.List lore = meta.hasLore() ? meta.getLore() : new java.util.ArrayList<>(); + lore.add(rarity.getDisplayName() + "§7 Seltenheit"); meta.setLore(lore); item.setItemMeta(meta); } diff --git a/src/main/java/com/simolzimol/levelcraft/item/Rarity.java b/src/main/java/com/simolzimol/levelcraft/item/Rarity.java index 7b946e6..ed7fbe8 100644 --- a/src/main/java/com/simolzimol/levelcraft/item/Rarity.java +++ b/src/main/java/com/simolzimol/levelcraft/item/Rarity.java @@ -1,22 +1,24 @@ package com.simolzimol.levelcraft.item; public enum Rarity { - CURSED(-1, "Verflucht"), - COMMON(0, "Gewöhnlich"), - UNCOMMON(1, "Ungewöhnlich"), - RARE(2, "Selten"), - EPIC(3, "Episch"), - LEGENDARY(4, "Legendär"), - MYTHIC(5, "Mythisch"), - ANCIENT(6, "Uralte"), - DIVINE(7, "Göttlich"); + CURSED(-1, "§8Verflucht", 0.02), // Sehr selten, negativ + COMMON(0, "§7Gewöhnlich", 0.50), // Am häufigsten (50%) + UNCOMMON(1, "§aUngewöhnlich", 0.20), // 20% + RARE(2, "§9Selten", 0.12), // 12% + EPIC(3, "§5Episch", 0.08), // 8% + LEGENDARY(4, "§6Legendär", 0.05), // 5% + MYTHIC(5, "§dMythisch", 0.025), // 2.5% + ANCIENT(6, "§eUralte", 0.012), // 1.2% + DIVINE(7, "§bGöttlich", 0.003); // 0.3% private final int value; private final String displayName; + private final double chance; - Rarity(int value, String displayName) { + Rarity(int value, String displayName, double chance) { this.value = value; this.displayName = displayName; + this.chance = chance; } public int getValue() { @@ -27,10 +29,27 @@ public enum Rarity { return displayName; } + public double getChance() { + return chance; + } + public static Rarity fromValue(int value) { for (Rarity r : values()) { if (r.value == value) return r; } return COMMON; } + + // Zufällige Rarity nach Gewichtung (ohne CURSED) + public static Rarity getRandomRarity(java.util.Random random, boolean allowCursed, int maxRarity) { + double roll = random.nextDouble(); + double cumulative = 0.0; + for (Rarity rarity : values()) { + if (rarity.value < (allowCursed ? -1 : 0)) continue; + if (rarity.value > maxRarity) continue; + cumulative += rarity.chance; + if (roll < cumulative) return rarity; + } + return COMMON; + } } diff --git a/src/main/java/com/simolzimol/levelcraft/listener/CraftListener.java b/src/main/java/com/simolzimol/levelcraft/listener/CraftListener.java index 4f0e8b2..d846bd9 100644 --- a/src/main/java/com/simolzimol/levelcraft/listener/CraftListener.java +++ b/src/main/java/com/simolzimol/levelcraft/listener/CraftListener.java @@ -16,16 +16,10 @@ public class CraftListener implements Listener { public void onCraft(CraftItemEvent event) { ItemStack result = event.getCurrentItem(); if (result == null) return; - - // Nur Items mit Haltbarkeit (Waffen, Rüstung, Werkzeuge) if (result.getType().getMaxDurability() <= 0) return; - // Rarity für gecraftete Items: -1 bis 3 - int rarityValue = random.nextInt(5) - 1; // -1,0,1,2,3 - if (rarityValue > 3) rarityValue = 3; - if (rarityValue < -1) rarityValue = -1; - - Rarity rarity = Rarity.fromValue(rarityValue); + // Gecraftete Items: -1 (selten) bis 3 (häufig) + Rarity rarity = Rarity.getRandomRarity(random, true, 3); ItemUtil.setRarity(result, rarity); ItemUtil.assignUniqueId(result); event.setCurrentItem(result);