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:
@@ -21,4 +21,8 @@ java {
|
|||||||
|
|
||||||
tasks.withType(JavaCompile).configureEach {
|
tasks.withType(JavaCompile).configureEach {
|
||||||
options.encoding = 'UTF-8'
|
options.encoding = 'UTF-8'
|
||||||
|
}
|
||||||
|
|
||||||
|
processResources {
|
||||||
|
from("plugin.yml")
|
||||||
}
|
}
|
||||||
@@ -50,4 +50,8 @@ public class ItemUtil {
|
|||||||
if (meta == null) return null;
|
if (meta == null) return null;
|
||||||
return meta.getPersistentDataContainer().get(uuidKey, PersistentDataType.STRING);
|
return meta.getPersistentDataContainer().get(uuidKey, PersistentDataType.STRING);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static NamespacedKey getRarityKey() {
|
||||||
|
return rarityKey;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,9 @@ public class CraftListener implements Listener {
|
|||||||
ItemStack result = event.getCurrentItem();
|
ItemStack result = event.getCurrentItem();
|
||||||
if (result == null) return;
|
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
|
// Rarity für gecraftete Items: -1 bis 3
|
||||||
int rarityValue = random.nextInt(5) - 1; // -1,0,1,2,3
|
int rarityValue = random.nextInt(5) - 1; // -1,0,1,2,3
|
||||||
if (rarityValue > 3) rarityValue = 3;
|
if (rarityValue > 3) rarityValue = 3;
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user