Made fish generator work for both fish types
Load lava fish Change from title messages to action bar messages
This commit is contained in:
parent
c971e11d9f
commit
4e2d82a0aa
|
|
@ -63,7 +63,7 @@ public final class FishingEvent extends JavaPlugin {
|
|||
}
|
||||
|
||||
private void registerEvents(@NotNull PluginManager pluginManager) {
|
||||
pluginManager.registerEvents(new CatchFish(this, logger, new FishGenerator(Fishes.FISH.RARITY_WATER_FISH_MAP, new RarityManager(Config.RARITY.RARITY_SET), logger), PointsManagement.getInstance()), this);
|
||||
pluginManager.registerEvents(new CatchFish(this, logger, new FishGenerator(new RarityManager(Config.RARITY.RARITY_SET), logger), PointsManagement.getInstance()), this);
|
||||
pluginManager.registerEvents(new GUIListener(), this);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package com.alttd.fishingevent.config;
|
|||
|
||||
import com.alttd.fishingevent.FishingEvent;
|
||||
import com.alttd.fishingevent.fish.Fish;
|
||||
import com.alttd.fishingevent.fish.WaterFish;
|
||||
import com.alttd.fishingevent.objects.FishType;
|
||||
import com.alttd.fishingevent.objects.Rarity;
|
||||
import com.alttd.fishingevent.util.FishConfigHelper;
|
||||
|
|
@ -94,21 +93,17 @@ public class Fishes extends AbstractConfig {
|
|||
Set<FishType> fishTypes = getFishTypes(fishSection);
|
||||
|
||||
for (FishType fishType : fishTypes) {
|
||||
Fish fish = new Fish(
|
||||
config.fishingEvent,
|
||||
config.logger,
|
||||
(float) fishSection.getDouble("min-length", 0),
|
||||
(float) fishSection.getDouble("max-length", 0),
|
||||
fishSection.getString("fish-name", "default name"),
|
||||
rarity.get(),
|
||||
optionalItemStack.get());
|
||||
switch (fishType) {
|
||||
case WATER -> {
|
||||
WATER_FISH.add(new WaterFish(
|
||||
config.fishingEvent,
|
||||
config.logger,
|
||||
(float) fishSection.getDouble("min-length", 0),
|
||||
(float) fishSection.getDouble("max-length", 0),
|
||||
fishSection.getString("fish-name", "default name"),
|
||||
rarity.get(),
|
||||
optionalItemStack.get())
|
||||
);
|
||||
}
|
||||
case LAVA -> {
|
||||
//TODO make lava fish and add it
|
||||
}
|
||||
case WATER -> WATER_FISH.add(fish);
|
||||
case LAVA -> LAVA_FISH.add(fish);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,38 +13,34 @@ 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.Random;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public abstract class Fish {
|
||||
public class Fish {
|
||||
|
||||
private final float minLength;
|
||||
private final float maxLength;
|
||||
private final String fishName;
|
||||
private final Rarity rarity;
|
||||
private final ItemStack itemStack;
|
||||
|
||||
protected final FishingEvent fishingEvent;
|
||||
protected final Logger logger;
|
||||
|
||||
Fish(FishingEvent fishingEvent, Logger logger) {
|
||||
public Fish(FishingEvent fishingEvent, Logger logger, float minLength, float maxLength, String fishName, Rarity rarity, ItemStack itemStack) {
|
||||
this.fishingEvent = fishingEvent;
|
||||
this.logger = logger;
|
||||
this.minLength = minLength;
|
||||
this.maxLength = maxLength;
|
||||
this.fishName = fishName;
|
||||
this.rarity = rarity;
|
||||
this.itemStack = itemStack;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an the fish item for a specific player
|
||||
* @param player Player to get the item for
|
||||
* @return ItemStack for that fish item if one exists
|
||||
*/
|
||||
protected abstract ItemStack getFishItem(Player player);
|
||||
|
||||
/**
|
||||
* Gives back a different result each call, it generates a length based on the min and max length values for a fish
|
||||
* @return a random length for this fish
|
||||
*/
|
||||
public abstract float generateLength();
|
||||
|
||||
public abstract Component fishName();
|
||||
|
||||
public abstract String normalFishName();
|
||||
|
||||
protected List<Component> fishLore(TagResolver tagResolver) {
|
||||
MiniMessage miniMessage = MiniMessage.miniMessage();
|
||||
return Fishes.FORMAT.LORE.stream()
|
||||
|
|
@ -52,8 +48,6 @@ public abstract class Fish {
|
|||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public abstract Rarity getRarity();
|
||||
|
||||
public Optional<ItemStack> createItem(Player player, double length, int points) {
|
||||
ItemStack fishItem = getFishItem(player);
|
||||
ItemMeta itemMeta = fishItem.getItemMeta();
|
||||
|
|
@ -82,4 +76,32 @@ public abstract class Fish {
|
|||
return Optional.of(fishItem);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an the fish item for a specific player
|
||||
* @param player Player to get the item for
|
||||
* @return ItemStack for that fish item if one exists
|
||||
*/
|
||||
public ItemStack getFishItem(Player player) {
|
||||
return itemStack.clone();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gives back a different result each call, it generates a length based on the min and max length values for a fish
|
||||
* @return a random length for this fish
|
||||
*/
|
||||
public float generateLength() {
|
||||
return new Random().nextFloat(minLength, maxLength);
|
||||
}
|
||||
|
||||
public net.kyori.adventure.text.@NotNull Component fishName() {
|
||||
return MiniMessage.miniMessage().deserialize(Fishes.FORMAT.DISPLAY_NAME, Placeholder.parsed("fish_name", fishName));
|
||||
}
|
||||
|
||||
public String normalFishName() {
|
||||
return fishName;
|
||||
}
|
||||
|
||||
public Rarity getRarity() {
|
||||
return rarity;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,64 +0,0 @@
|
|||
package com.alttd.fishingevent.fish;
|
||||
|
||||
|
||||
import com.alttd.fishingevent.FishingEvent;
|
||||
import com.alttd.fishingevent.objects.Rarity;
|
||||
import com.alttd.fishingevent.util.Logger;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Set;
|
||||
|
||||
public class LavaFish extends Fish {
|
||||
|
||||
public LavaFish(FishingEvent fishingEvent, Logger logger, float minLength, float maxLength, String fishName, Rarity rarity, ItemStack itemStack, ArrayList<Set<Particle>> particles) {
|
||||
super(fishingEvent, logger);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getFishItem(Player player) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float generateLength() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component fishName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String normalFishName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Rarity getRarity() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void spawnParticles(Location location) {
|
||||
//TODO run async function in here
|
||||
//TODO color particles based on rarity?
|
||||
}
|
||||
|
||||
public boolean validRod(ItemStack fishingRod) {
|
||||
//TODO check data to see if its a lava rod
|
||||
return false;
|
||||
}
|
||||
|
||||
public Instant getSpawnTime(ItemStack fishingRod) {
|
||||
//TODO calc based on rod enchant level and check if the rod is valid maybe?
|
||||
return Instant.now();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,55 +0,0 @@
|
|||
package com.alttd.fishingevent.fish;
|
||||
|
||||
import com.alttd.fishingevent.FishingEvent;
|
||||
import com.alttd.fishingevent.config.Fishes;
|
||||
import com.alttd.fishingevent.objects.Rarity;
|
||||
import com.alttd.fishingevent.util.Logger;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class WaterFish extends Fish {
|
||||
|
||||
private final float minLength;
|
||||
private final float maxLength;
|
||||
private final String fishName;
|
||||
private final Rarity rarity;
|
||||
private final ItemStack itemStack;
|
||||
|
||||
public WaterFish(FishingEvent fishingEvent, Logger logger, float minLength, float maxLength, String fishName, Rarity rarity, ItemStack itemStack) {
|
||||
super(fishingEvent, logger);
|
||||
this.minLength = minLength;
|
||||
this.maxLength = maxLength;
|
||||
this.fishName = fishName;
|
||||
this.rarity = rarity;
|
||||
this.itemStack = itemStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getFishItem(Player player) {
|
||||
return itemStack.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float generateLength() {
|
||||
return new Random().nextFloat(minLength, maxLength);
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.kyori.adventure.text.@NotNull Component fishName() {
|
||||
return MiniMessage.miniMessage().deserialize(Fishes.FORMAT.DISPLAY_NAME, Placeholder.parsed("fish_name", fishName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String normalFishName() {
|
||||
return fishName;
|
||||
}
|
||||
@Override
|
||||
public Rarity getRarity() {
|
||||
return rarity;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
package com.alttd.fishingevent.fish_generator;
|
||||
|
||||
import com.alttd.fishingevent.config.Fishes;
|
||||
import com.alttd.fishingevent.fish.Fish;
|
||||
import com.alttd.fishingevent.objects.*;
|
||||
import com.alttd.fishingevent.util.Logger;
|
||||
|
|
@ -7,19 +8,16 @@ import org.bukkit.Material;
|
|||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class FishGenerator {
|
||||
|
||||
private final HashMap<Rarity, List<Fish>> possibleFishMap;
|
||||
private final RandomListItem<Fish> randomListItem = new RandomListItem<>();
|
||||
private final RarityManager rarityManager;
|
||||
private final Logger logger;
|
||||
|
||||
public FishGenerator(HashMap<Rarity, List<Fish>> possibleFishMap, RarityManager rarityManager, Logger logger) {
|
||||
this.possibleFishMap = possibleFishMap;
|
||||
public FishGenerator(RarityManager rarityManager, Logger logger) {
|
||||
this.rarityManager = rarityManager;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
|
@ -35,7 +33,12 @@ public class FishGenerator {
|
|||
return Optional.empty();
|
||||
|
||||
Rarity rarity = optionalRarity.get();
|
||||
List<Fish> fish = possibleFishMap.get(rarity);
|
||||
List<Fish> fish = null;
|
||||
switch (fishType) {
|
||||
case WATER -> fish = Fishes.FISH.RARITY_WATER_FISH_MAP.get(rarity);
|
||||
case LAVA -> fish = Fishes.FISH.RARITY_LAVA_FISH_MAP.get(rarity);
|
||||
}
|
||||
|
||||
if (fish == null) {
|
||||
logger.warning("Empty fish map for rarity [%]", rarity.toString());
|
||||
return Optional.empty();
|
||||
|
|
|
|||
|
|
@ -10,11 +10,9 @@ import com.alttd.fishingevent.points.PointsManagement;
|
|||
import com.alttd.fishingevent.scoreboard.ScoreboardManager;
|
||||
import com.alttd.fishingevent.timer.EventManager;
|
||||
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 net.kyori.adventure.title.Title;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
|
|
@ -55,7 +53,7 @@ public class CatchFish implements Listener {
|
|||
}
|
||||
Player player = event.getPlayer();
|
||||
if (fishingRodBroken(player)) {
|
||||
player.showTitle(Title.title(Component.empty(), MiniMessage.miniMessage().deserialize("<red>Your rod is too damaged to fish</red>")));
|
||||
player.sendActionBar(MiniMessage.miniMessage().deserialize("<red>Your rod is too damaged to fish</red>"));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
|
@ -65,7 +63,7 @@ public class CatchFish implements Listener {
|
|||
@Override
|
||||
public void run() {
|
||||
if (event.getHook().getLocation().getBlock().getType().equals(Material.LAVA)) {
|
||||
player.showTitle(Title.title(Component.empty(), MiniMessage.miniMessage().deserialize("<gold>You are now fishing in lava...</gold>"))); //TODO move to config
|
||||
player.sendActionBar(MiniMessage.miniMessage().deserialize("<gold>You are now fishing in lava...</gold>")); //TODO move to config
|
||||
LavaFishing lavaFishing = new LavaFishing(1, 1, player, logger, event.getHook().getLocation());
|
||||
activeLavaFishers.put(player.getUniqueId(), lavaFishing);
|
||||
lavaFishing.runTaskTimerAsynchronously(fishingEvent, 1, 1);
|
||||
|
|
@ -143,12 +141,12 @@ public class CatchFish implements Listener {
|
|||
.forEach(item -> player.getWorld().dropItem(player.getLocation(), item).setOwner(player.getUniqueId()));
|
||||
player.updateInventory();
|
||||
ScoreboardManager.getInstance().updateScoreboard(player, caughtFishData.length(), caughtFishData.fish());
|
||||
player.showTitle(Title.title(Component.empty(), MiniMessage.miniMessage().deserialize("<green>You caught a <rarity> <name> fish <gold><length> cm</gold></green>", //TODO move to config
|
||||
player.sendActionBar(MiniMessage.miniMessage().deserialize("<green>You caught a <rarity> <name> fish <gold><length> cm</gold></green>", //TODO move to config
|
||||
TagResolver.resolver(
|
||||
Placeholder.component("rarity", caughtFishData.fish().getRarity().displayName()),
|
||||
Placeholder.component("name", caughtFishData.fish().fishName()),
|
||||
Placeholder.parsed("length", String.valueOf(caughtFishData.length()))
|
||||
))));
|
||||
Placeholder.parsed("length", String.format("%.2f", caughtFishData.length()))
|
||||
)));
|
||||
}
|
||||
|
||||
private void handleFishCaught(PlayerFishEvent event) {
|
||||
|
|
@ -172,12 +170,12 @@ public class CatchFish implements Listener {
|
|||
player.getName(), caughtFishData.fish().normalFishName(), String.format("%.2f", caughtFishData.length()),
|
||||
caughtFishData.fish().getRarity().displayNameString(), String.valueOf(caughtFishData.pointsValue()));
|
||||
ScoreboardManager.getInstance().updateScoreboard(player, caughtFishData.length(), caughtFishData.fish());
|
||||
player.showTitle(Title.title(Component.empty(), MiniMessage.miniMessage().deserialize("<green>You caught a <rarity> <name> fish <gold><length> cm</gold></green>", //TODO move to config
|
||||
player.sendActionBar(MiniMessage.miniMessage().deserialize("<green>You caught a <rarity> <name> fish <gold><length> cm</gold></green>", //TODO move to config
|
||||
TagResolver.resolver(
|
||||
Placeholder.component("rarity", caughtFishData.fish().getRarity().displayName()),
|
||||
Placeholder.component("name", caughtFishData.fish().fishName()),
|
||||
Placeholder.parsed("length", String.valueOf(caughtFishData.length()))
|
||||
))));
|
||||
Placeholder.parsed("length", String.format("%.2f", caughtFishData.length()))
|
||||
)));
|
||||
}
|
||||
|
||||
private Optional<CaughtFishData> getFishData(PlayerFishEvent event, Player player, FishType fishType) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user