modified: build.gradle

modified:   src/main/java/com/simolzimol/levelcraft/item/ItemUtil.java
	modified:   src/main/java/com/simolzimol/levelcraft/listener/CraftListener.java
	new file:   src/main/java/com/simolzimol/levelcraft/listener/LootListener.java
	new file:   src/main/java/com/simolzimol/levelcraft/listener/MobDropListener.java
This commit is contained in:
SimolZimol
2025-05-23 18:44:15 +02:00
parent a2c55f58bc
commit 717c026ade
5 changed files with 93 additions and 0 deletions

View File

@@ -22,3 +22,7 @@ java {
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
}
processResources {
from("plugin.yml")
}

View File

@@ -50,4 +50,8 @@ public class ItemUtil {
if (meta == null) return null;
return meta.getPersistentDataContainer().get(uuidKey, PersistentDataType.STRING);
}
public static NamespacedKey getRarityKey() {
return rarityKey;
}
}

View File

@@ -17,6 +17,9 @@ public class CraftListener implements Listener {
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;

View File

@@ -0,0 +1,50 @@
package com.simolzimol.levelcraft.listener;
import com.simolzimol.levelcraft.item.ItemUtil;
import com.simolzimol.levelcraft.item.Rarity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.Container;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
import java.util.Random;
public class LootListener implements Listener {
private final Random random = new Random();
@EventHandler
public void onChestOpen(PlayerInteractEvent event) {
Block block = event.getClickedBlock();
if (block == null) return;
BlockState state = block.getState();
if (!(state instanceof Container container)) return;
Inventory inv = container.getInventory();
for (ItemStack item : inv.getContents()) {
if (item == null) continue;
// Nur Items mit Haltbarkeit (Waffen, Rüstung, Werkzeuge, Angel, ...)
if (item.getType().getMaxDurability() <= 0) continue;
ItemMeta meta = item.getItemMeta();
if (meta == null) continue;
// Prüfe, ob das Item bereits eine Seltenheit hat
if (meta.getPersistentDataContainer().has(
ItemUtil.getRarityKey(), PersistentDataType.INTEGER)) continue;
// Rarity für Kisten-Loot: -1 bis 5
int rarityValue = random.nextInt(7) - 1; // -1 bis 5
if (rarityValue > 5) rarityValue = 5;
if (rarityValue < -1) rarityValue = -1;
Rarity rarity = Rarity.fromValue(rarityValue);
ItemUtil.setRarity(item, rarity);
ItemUtil.assignUniqueId(item);
}
}
}

View File

@@ -0,0 +1,32 @@
package com.simolzimol.levelcraft.listener;
import com.simolzimol.levelcraft.item.ItemUtil;
import com.simolzimol.levelcraft.item.Rarity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDropItemEvent;
import org.bukkit.inventory.ItemStack;
import java.util.Random;
public class MobDropListener implements Listener {
private final Random random = new Random();
@EventHandler
public void onMobDrop(EntityDropItemEvent event) {
ItemStack item = event.getItemDrop().getItemStack();
if (item == null) return;
// Nur Items mit Haltbarkeit (Waffen, Rüstung, Werkzeuge)
if (item.getType().getMaxDurability() <= 0) return;
// Rarity für Mobdrops: -1 bis 7
int rarityValue = random.nextInt(9) - 1; // -1 bis 7
if (rarityValue > 7) rarityValue = 7;
if (rarityValue < -1) rarityValue = -1;
Rarity rarity = Rarity.fromValue(rarityValue);
ItemUtil.setRarity(item, rarity);
ItemUtil.assignUniqueId(item);
event.getItemDrop().setItemStack(item);
}
}