Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
dan28000 committed May 26, 2024
1 parent dd5ce43 commit 50f489e
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 56 deletions.
2 changes: 1 addition & 1 deletion paper/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ dependencies {

api(projects.crazycratesCore)

compileOnly("cz.basicland:bLibs:2.0.0-WIP-b24")
compileOnly("cz.basicland:bLibs:2.0.0-WIP-b25")

compileOnly ("org.projectlombok:lombok:1.18.32")
annotationProcessor ("org.projectlombok:lombok:1.18.32")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public Prize(String prizeNumber, String crateName, Tier tier, ItemStack stack, b
if (updatedLore == null) updatedLore = new ArrayList<>();
updatedLore.addFirst("");
updatedLore.addFirst(type.name());
display.setDisplayLore(updatedLore);
display.setDisplayLore(updatedLore.stream().map(s -> s.replace("§", "&")).toList());

this.displayItem = display;
this.prizeItem = display;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public DatabaseManager(List<Crate> crateList) {
CrateSettings settings = crate.getCrateSettings();
if (settings == null) continue;
BannerPackage bannerPackage = settings.getBannerPackage();
if (bannerPackage.isBannerActive()) {
if (bannerPackage.isBannerActive() || !bannerPackage.enabled()) {
settings.loadItems(crate, crate.getPrizes(), this);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,25 @@
import com.badbones69.crazycrates.api.objects.gacha.util.HSLColor;
import com.badbones69.crazycrates.api.objects.gacha.util.Pair;
import cz.basicland.blibs.spigot.utils.item.NBT;
import io.papermc.paper.adventure.PaperAdventure;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.nbt.api.BinaryTagHolder;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.event.DataComponentValue;
import net.kyori.adventure.text.event.HoverEvent;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextColor;
import net.kyori.adventure.text.format.TextDecoration;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bukkit.NamespacedKey;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;

import java.text.SimpleDateFormat;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import static net.kyori.adventure.text.Component.text;

public class History {
private final DatabaseManager playerDataManager;
private final SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
Expand All @@ -46,15 +43,15 @@ public void sendHistory(Player player, String target, int pageNumber, CrateSetti
PlayerProfile profile = playerDataManager.getPlayerProfile(target, crateSettings, true);

if (profile == null) {
player.sendMessage(Component.text("Hráč " + target + " nemá žádnou historii otevření " + crateSettings.getCrateName() + " crate", NamedTextColor.RED));
player.sendMessage(text("Hráč " + target + " nemá žádnou historii otevření " + crateSettings.getCrateName() + " crate", NamedTextColor.RED));
return;
}

List<Result> historyList = profile.getHistory();
TextColor color = TextColor.fromHexString("#de7a00");

if (historyList.isEmpty()) {
player.sendMessage(Component.text("Nemáte žádnou historii otevření " + crateSettings.getCrateName() + " crate", NamedTextColor.RED));
player.sendMessage(text("Nemáte žádnou historii otevření " + crateSettings.getCrateName() + " crate", NamedTextColor.RED));
return;
}

Expand All @@ -68,11 +65,11 @@ public void sendHistory(Player player, String target, int pageNumber, CrateSetti
int endIndex = Math.min(startIndex + HISTORY_PER_PAGE, size);
int maxPage = (size / HISTORY_PER_PAGE) + (size % HISTORY_PER_PAGE == 0 ? 0 : 1);

Component header = Component.text()
Component header = text()
.appendNewline()
.append(Component.text("Historie otevření ", color))
.append(Component.text(crateSettings.getCrateName(), NamedTextColor.AQUA))
.append(Component.text(" crate", color))
.append(text("Historie otevření ", color))
.append(text(crateSettings.getCrateName(), NamedTextColor.AQUA))
.append(text(" crate", color))
.appendNewline()
.build();
player.sendMessage(header);
Expand All @@ -81,27 +78,27 @@ public void sendHistory(Player player, String target, int pageNumber, CrateSetti
Result history = historyList.get(size - i - 1);
Rarity rarity = history.getRarity();

Component component = Component.text()
.append(Component.text("» ", NamedTextColor.DARK_GRAY, TextDecoration.BOLD))
.append(LegacyComponentSerializer.legacy('&').deserialize(history.getItemName()).hoverEvent(showItem(getItem(history, rarity, crateSettings))))
.append(Component.text(" - ", NamedTextColor.GRAY)
.append(Component.text(rarity.name(), rarity.getColor()).hoverEvent(HoverEvent.showText(getHoverText(history, crateSettings)))))
Component component = text()
.append(text("» ", NamedTextColor.DARK_GRAY, TextDecoration.BOLD))
.append(LegacyComponentSerializer.legacy('&').deserialize(history.getItemName()).hoverEvent(getHover(history, rarity, crateSettings)))
.append(text(" - ", NamedTextColor.GRAY)
.append(text(rarity.name(), rarity.getColor()).hoverEvent(HoverEvent.showText(getHoverText(history, crateSettings)))))
.build();
player.sendMessage(component);
}

int pageMinus = pageNumber - 1;
int pagePlus = pageNumber + 1;

Component pages = Component.text()
Component pages = text()
.appendNewline()
.append(Component.text("<<<<", NamedTextColor.DARK_GRAY, TextDecoration.BOLD)
.append(text("<<<<", NamedTextColor.DARK_GRAY, TextDecoration.BOLD)
.clickEvent(ClickEvent.callback((clickEvent) -> sendHistory(player, target, pageMinus <= 0 ? maxPage : pageMinus, crateSettings)))
.hoverEvent(Component.text("Předchozí stránka", NamedTextColor.GRAY)))
.append(Component.text(" Strana " + pageNumber + "/" + maxPage + " ", color))
.append(Component.text(">>>>", NamedTextColor.DARK_GRAY, TextDecoration.BOLD)
.hoverEvent(text("Předchozí stránka", NamedTextColor.GRAY)))
.append(text(" Strana " + pageNumber + "/" + maxPage + " ", color))
.append(text(">>>>", NamedTextColor.DARK_GRAY, TextDecoration.BOLD)
.clickEvent(ClickEvent.callback((clickEvent) -> sendHistory(player, target, pagePlus > maxPage ? 1 : pagePlus, crateSettings)))
.hoverEvent(Component.text("Další stránka", NamedTextColor.GRAY)))
.hoverEvent(text("Další stránka", NamedTextColor.GRAY)))
.build();
player.sendMessage(pages);
}
Expand All @@ -110,15 +107,15 @@ public void sendPity(Player player, String target, CrateSettings crateSettings)
PlayerProfile profile = playerDataManager.getPlayerProfile(target, crateSettings, true);

if (profile == null) {
player.sendMessage(Component.text("Hráč " + target + " nemá žádnou historii otevření " + crateSettings.getCrateName() + " crate", NamedTextColor.RED));
player.sendMessage(text("Hráč " + target + " nemá žádnou historii otevření " + crateSettings.getCrateName() + " crate", NamedTextColor.RED));
return;
}

Component header = Component.text()
Component header = text()
.appendNewline()
.append(Component.text("Pity pro ", NamedTextColor.GRAY))
.append(Component.text(crateSettings.getCrateName(), NamedTextColor.AQUA))
.append(Component.text(" crate", NamedTextColor.GRAY))
.append(text("Pity pro ", NamedTextColor.GRAY))
.append(text(crateSettings.getCrateName(), NamedTextColor.AQUA))
.append(text(" crate", NamedTextColor.GRAY))
.appendNewline()
.build();
player.sendMessage(header);
Expand All @@ -129,18 +126,18 @@ public void sendPity(Player player, String target, CrateSettings crateSettings)
ResultType won5050 = pair.second();
int color = getColor(pity);

Component component = Component.text()
.append(Component.text(rarity.name(), rarity.getColor()))
.append(Component.text(" pity: ", NamedTextColor.GRAY))
.append(Component.text(pity, TextColor.color(color)))
.append(Component.text(" last 50/50: ", NamedTextColor.GRAY))
.append(Component.text(won5050.name(), won5050.getColor()))
Component component = text()
.append(text(rarity.name(), rarity.getColor()))
.append(text(" pity: ", NamedTextColor.GRAY))
.append(text(pity, TextColor.color(color)))
.append(text(" last 50/50: ", NamedTextColor.GRAY))
.append(text(won5050.name(), won5050.getColor()))
.build();
player.sendMessage(component);
});
}

private ItemStack getItem(Result history, Rarity rarity, CrateSettings crateSettings) {
private @NotNull HoverEvent<HoverEvent.ShowItem> getHover(Result history, Rarity rarity, CrateSettings crateSettings) {
Set<Prize> items = crateSettings.getGachaType().equals(GachaType.OVERRIDE) ? crateSettings.getBoth(rarity) : new HashSet<>(history.isWon5050() ? crateSettings.getLimited() : crateSettings.getStandard());
items.removeIf(item -> item.getRarity() != rarity || !item.getSectionName().equals(history.getRewardName()));

Expand All @@ -155,13 +152,9 @@ private ItemStack getItem(Result history, Rarity rarity, CrateSettings crateSett
}
}

return item;
}

private HoverEvent<HoverEvent.ShowItem> showItem(ItemStack itemStack) {
NamespacedKey key = itemStack.getType().getKey();
int itemCount = itemStack.getAmount();
return HoverEvent.showItem(HoverEvent.ShowItem.showItem(key, itemCount, PaperAdventure.asAdventure(CraftItemStack.asNMSCopy(itemStack).getComponentsPatch())));
NamespacedKey key = item.getType().getKey();
int itemCount = item.getAmount();
return HoverEvent.showItem(HoverEvent.ShowItem.showItem(key, itemCount, new NBT(item).getNBTToMap()));
}

private Component getHoverText(Result history, CrateSettings crateSettings) {
Expand All @@ -170,15 +163,15 @@ private Component getHoverText(Result history, CrateSettings crateSettings) {
int color = getColor(history.getPity());
ResultType won5050 = history.getWon5050();

return Component.text()
.append(Component.text("- čas: ", NamedTextColor.GRAY)
.append(Component.text(dateFormat.format(history.getTimestamp()), NamedTextColor.GOLD)))
return text()
.append(text("- čas: ", NamedTextColor.GRAY)
.append(text(dateFormat.format(history.getTimestamp()), NamedTextColor.GOLD)))
.appendNewline()
.append(Component.text("- pity: ", NamedTextColor.GRAY)
.append(Component.text(history.getPity(), TextColor.color(color))))
.append(text("- pity: ", NamedTextColor.GRAY)
.append(text(history.getPity(), TextColor.color(color))))
.append(raritySettings.is5050Enabled() ?
Component.newline().append(Component.text("- 50/50: ", NamedTextColor.GRAY))
.append(Component.text(won5050.name(), won5050.getColor())) :
Component.newline().append(text("- 50/50: ", NamedTextColor.GRAY))
.append(text(won5050.name(), won5050.getColor())) :
Component.empty())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import java.time.Duration;
import java.time.LocalDateTime;

public record BannerPackage(BannerData currentBanner, BannerData nextBanner) {
public record BannerPackage(BannerData currentBanner, BannerData nextBanner, boolean enabled) {

public BannerData getBanner() {
return currentBanner.isBannerActive() ? currentBanner : nextBanner.isBannerActive() ? nextBanner : null;
return enabled ? currentBanner.isBannerActive() ? currentBanner : nextBanner.isBannerActive() ? nextBanner : null : null;
}

public boolean isBannerActive() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public CrateSettings(FileConfiguration config, String crateName, Crate crate) {

CustomFile customFile = yamlManager.getCustomFile(bannerFile);
if (customFile == null) {
bannerPackage = null;
bannerPackage = new BannerPackage(null, null, false);
return;
}

Expand All @@ -95,7 +95,7 @@ public CrateSettings(FileConfiguration config, String crateName, Crate crate) {
BannerData currentBanner = getBanner(yamlFile, "currentBanner");
BannerData nextBanner = getBanner(yamlFile, "nextBanner");

bannerPackage = new BannerPackage(currentBanner, nextBanner);
bannerPackage = new BannerPackage(currentBanner, nextBanner, true);
updateItems();
}

Expand Down

0 comments on commit 50f489e

Please sign in to comment.