Changed upgrading to require points and use tracks
This commit is contained in:
@@ -1,21 +1,35 @@
|
||||
package com.alttd.fishingevent.fish;
|
||||
|
||||
import com.alttd.fishingevent.FishingEvent;
|
||||
import com.alttd.fishingevent.config.Config;
|
||||
import com.alttd.fishingevent.config.Fishes;
|
||||
import com.alttd.fishingevent.objects.Rarity;
|
||||
import com.alttd.fishingevent.util.Logger;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public abstract class Fish {
|
||||
|
||||
protected final FishingEvent fishingEvent;
|
||||
protected final Logger logger;
|
||||
|
||||
Fish(FishingEvent fishingEvent, Logger logger) {
|
||||
this.fishingEvent = fishingEvent;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an the fish item for a specific player
|
||||
* @param player Player to get the item for
|
||||
@@ -42,7 +56,7 @@ public abstract class Fish {
|
||||
|
||||
public abstract Rarity getRarity();
|
||||
|
||||
public ItemStack createItem(Player player, double length) {
|
||||
public Optional<ItemStack> createItem(Player player, double length, int points) {
|
||||
ItemStack fishItem = getFishItem(player);
|
||||
ItemMeta itemMeta = fishItem.getItemMeta();
|
||||
TagResolver resolver = TagResolver.resolver(
|
||||
@@ -53,9 +67,21 @@ public abstract class Fish {
|
||||
|
||||
itemMeta.lore(fishLore(resolver));
|
||||
itemMeta.displayName(fishName());
|
||||
NamespacedKey namespacedKey;
|
||||
try {
|
||||
namespacedKey = NamespacedKey.fromString("points", fishingEvent);
|
||||
} catch (Exception e) {
|
||||
logger.warning("Unable to create namespaced key for fish");
|
||||
return Optional.empty();
|
||||
}
|
||||
if (namespacedKey == null) {
|
||||
logger.warning("Created null namespaced key for fish");
|
||||
return Optional.empty();
|
||||
}
|
||||
itemMeta.getPersistentDataContainer().set(namespacedKey, PersistentDataType.INTEGER, points);
|
||||
|
||||
fishItem.setItemMeta(itemMeta);
|
||||
return fishItem;
|
||||
return Optional.of(fishItem);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user