Initial commit

This commit is contained in:
Scifi9902
2026-10-12 13:57:05 -03:00
commit 4bde3b176a
2576 changed files with 212659 additions and 0 deletions
@@ -0,0 +1,126 @@
package net.crankedpvp.lootboxes.struct;
import de.tr7zw.nbtapi.NBTItem;
import lombok.AllArgsConstructor;
import lombok.Getter;
import net.crankedpvp.crankedutils.utils.Arrow;
import net.crankedpvp.crankedutils.utils.RandomUtils;
import net.crankedpvp.crankedutils.utils.items.ItemBuilder;
import net.crankedpvp.crankedutils.utils.items.SkullUtils;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import java.util.*;
@Getter @AllArgsConstructor
public class Lootbox {
private final String id;
private final String displayName;
private final List<String> header;
private final List<String> footer;
private final String rewardTitle;
private final String rewardLine;
private final String jackpotTitle;
private final String jackpotLine;
private final Material material;
private final boolean glowing;
private final boolean viewRewards;
private final boolean broadcastRewards;
private final int amountOfRewards;
private final RewardType rewardType;
private final String skullValue;
private final List<Reward> rewards;
public List<String> getLore() {
List<String> lore = new ArrayList<>();
if(!header.isEmpty()) lore.addAll(header);
if(viewRewards) {
if(rewards.stream().anyMatch(rewardObject -> !rewardObject.isJackpot())) {
lore.add(rewardTitle.replace("%rewards%", String.valueOf(amountOfRewards)));
for(Reward reward : rewards) {
if(!reward.isJackpot()) {
if(reward.getSpecialName() == null || reward.getSpecialName().equals("null")) {
lore.add(rewardLine.replace("%amount%", String.valueOf(reward.getItemStack().getAmount())).replace("%name%", reward.getItemStack().getItemMeta().getDisplayName()));
} else {
lore.add(reward.getSpecialName());
}
}
}
}
if(rewards.stream().anyMatch(Reward::isJackpot)) {
if(rewards.stream().anyMatch(rewardObject -> !rewardObject.isJackpot())) lore.add("");
lore.add(jackpotTitle);
for(Reward reward : rewards) {
if(reward.isJackpot()) {
if(reward.getSpecialName() == null || reward.getSpecialName().equals("null")) {
lore.add(jackpotLine.replace("%amount%", String.valueOf(reward.getItemStack().getAmount())).replace("%name%", reward.getItemStack().getItemMeta().getDisplayName()));
} else {
lore.add(reward.getSpecialName());
}
}
}
}
}
lore.addAll(footer);
return lore;
}
public ItemStack createLootbox(int amount) {
ItemBuilder itemBuilder = this.skullValue.equals("???") ? new ItemBuilder(material) : new ItemBuilder(SkullUtils.getSkullFromSkin(this.skullValue));
itemBuilder.setAmount(amount);
itemBuilder.setName(this.displayName);
itemBuilder.setLore(this.getLore()).colorize();
if (glowing) itemBuilder.setGlowing();
NBTItem nbtItem = new NBTItem(itemBuilder.build());
nbtItem.setBoolean("broadcast", this.broadcastRewards);
nbtItem.getOrCreateCompound("cosmicData").setString("customItem", "lootbox");
nbtItem.getCompound("cosmicData").setString("lootboxID", id);
ItemStack itemStack = nbtItem.getItem();
if(!this.skullValue.equals("???")) {
return SkullUtils.getSkull(itemStack, this.skullValue);
}
return nbtItem.getItem();
}
public ItemStack buildHalf(String side) {
String string = side.equals("left") ? "&b&lLeft Half (" + this.getDisplayName() + "&b&l)" : "&d&lRight Half (" + this.getDisplayName() + "&d&l)";
String opposite = side.equals("left") ? "right" : "left";
ItemBuilder itemBuilder = new ItemBuilder(Material.PRISMARINE_CRYSTALS, string, "&7Combine with the " + opposite + " half to",
"&7create a full " + this.getDisplayName());
NBTItem nbtItem = new NBTItem(itemBuilder.colorize().setGlowing().build());
nbtItem.setString("halfLootbox", this.getId());
nbtItem.setString("side", side);
return nbtItem.getItem();
}
public ItemStack buildLeftOrRightHalf() {
ItemBuilder itemBuilder = new ItemBuilder(Material.PAPER, "&b&lLEFT &f&l&nOR&r &d&lRIGHT &f&lHalf " + Arrow.arrow() + " " + this.getDisplayName(),
"&7Right-Click this lootbox to receive",
"&7either the &bleft &7or &dright&7 half",
"&7of the " + this.getDisplayName() + "&r &7lootbox",
"",
"&4&l(!) &7Obtained from &cbuy.crankedpvp.org &7(/buy)",
"",
"&f&lRandom Loot &7(1 Item)",
"&f&l* 1x &b&lLeft Half (" + this.getDisplayName() + "&b&l)",
"&f&l* 1x &d&lRight Half (" + this.getDisplayName() + "&d&l)"
);
NBTItem nbtItem = new NBTItem(itemBuilder.colorize().setGlowing().build());
nbtItem.setString("leftOrRightHalf", this.getId());
return nbtItem.getItem();
}
public ItemStack pickRandomReward() {
final Map<ItemStack, Double> rewards = new HashMap<>();
this.getRewards().stream()
.filter(Objects::nonNull)
.forEach(reward -> rewards.put(reward.getItemStack(), reward.getChance()));
return RandomUtils.getRandomItem(rewards);
}
public boolean doesBroadcast() {
return this.broadcastRewards;
}
}