modified: src/main/java/com/simolzimol/levelcraft/LevelCraft.java
new file: src/main/java/com/simolzimol/levelcraft/item/ItemUtil.java new file: src/main/java/com/simolzimol/levelcraft/item/Rarity.java
This commit is contained in:
@@ -6,6 +6,7 @@ public class LevelCraft extends JavaPlugin {
|
||||
@Override
|
||||
public void onEnable() {
|
||||
getLogger().info("LevelCraft aktiviert!");
|
||||
com.simolzimol.levelcraft.item.ItemUtil.init(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
24
src/main/java/com/simolzimol/levelcraft/item/ItemUtil.java
Normal file
24
src/main/java/com/simolzimol/levelcraft/item/ItemUtil.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package com.simolzimol.levelcraft.item;
|
||||
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class ItemUtil {
|
||||
private static NamespacedKey rarityKey;
|
||||
|
||||
public static void init(Plugin plugin) {
|
||||
rarityKey = new NamespacedKey(plugin, "rarity");
|
||||
}
|
||||
|
||||
public static void setRarity(ItemStack item, Rarity rarity) {
|
||||
item.getItemMeta().getPersistentDataContainer().set(rarityKey, PersistentDataType.INTEGER, rarity.getValue());
|
||||
// Optional: ItemMeta updaten (z.B. Lore, Name)
|
||||
}
|
||||
|
||||
public static Rarity getRarity(ItemStack item) {
|
||||
Integer value = item.getItemMeta().getPersistentDataContainer().get(rarityKey, PersistentDataType.INTEGER);
|
||||
return value == null ? Rarity.COMMON : Rarity.fromValue(value);
|
||||
}
|
||||
}
|
||||
36
src/main/java/com/simolzimol/levelcraft/item/Rarity.java
Normal file
36
src/main/java/com/simolzimol/levelcraft/item/Rarity.java
Normal file
@@ -0,0 +1,36 @@
|
||||
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");
|
||||
|
||||
private final int value;
|
||||
private final String displayName;
|
||||
|
||||
Rarity(int value, String displayName) {
|
||||
this.value = value;
|
||||
this.displayName = displayName;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
return displayName;
|
||||
}
|
||||
|
||||
public static Rarity fromValue(int value) {
|
||||
for (Rarity r : values()) {
|
||||
if (r.value == value) return r;
|
||||
}
|
||||
return COMMON;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user