diff --git a/src/main/java/xyz/oribuin/fishing/augment/Augment.java b/src/main/java/xyz/oribuin/fishing/augment/Augment.java index c2ae484..a2c8e9e 100644 --- a/src/main/java/xyz/oribuin/fishing/augment/Augment.java +++ b/src/main/java/xyz/oribuin/fishing/augment/Augment.java @@ -15,13 +15,14 @@ import xyz.oribuin.fishing.util.ItemConstruct; import java.nio.file.Path; +import java.util.ArrayList; import java.util.List; public abstract class Augment extends FishEventHandler implements Listener, Configurable { protected final String name; protected boolean enabled; - protected String description; + protected List description; protected ItemConstruct displayItem; protected String displayLine; protected int maxLevel; @@ -34,10 +35,10 @@ public abstract class Augment extends FishEventHandler implements Listener, Conf * @param name The name of the augment * @param description The description of the augment */ - public Augment(String name, String description) { + public Augment(String name, String... description) { this.enabled = true; this.name = name; - this.description = description; + this.description = new ArrayList<>(List.of(description)); this.maxLevel = 5; this.requiredLevel = 1; this.displayItem = this.defaultItem(); @@ -76,7 +77,7 @@ public void saveSettings(@NotNull CommentedConfigurationSection config) { config.set("enabled", this.enabled); config.set("max-level", this.maxLevel); config.set("required-level", this.requiredLevel); - config.set("description", List.of(this.description.split("\n"))); + config.set("description", this.description); config.set("display-line", this.displayLine); CommentedConfigurationSection section = config.getConfigurationSection("display-item"); @@ -95,7 +96,7 @@ public void loadSettings(@NotNull CommentedConfigurationSection config) { this.enabled = config.getBoolean("enabled", true); this.maxLevel = config.getInt("max-level", 1); this.requiredLevel = config.getInt("required-level", 1); - this.description = String.join("\n", config.getStringList("description")); + this.description = config.getStringList("description"); this.displayLine = config.getString("display-line", "&c" + StringUtils.capitalize(this.name.replace("_", " ")) + " %level_roman%"); ItemConstruct construct = ItemConstruct.deserialize(config.getConfigurationSection("display-item")); @@ -114,17 +115,15 @@ public void loadSettings(@NotNull CommentedConfigurationSection config) { */ private ItemConstruct defaultItem() { return ItemConstruct.of(Material.FIREWORK_STAR) - .name("&f[f73d6>&l%display_name%&f]") + .name("&f[f73d6&l%display_name%&f]") .lore("&7%description%", "", "f73d6Information", - " &7| &fRequired Level: f73d6%required_level%", - " &7| &fMax Level: f73d6%max_level%", - " &7| &fCost: f73d6%amount% &f%currency%", + " f73d6- &7Required Level: &f%required_level%", + " f73d6- &7Max Level: &f%max_level%", "" ) - .enchant(Enchantment.EFFICIENCY, 1) - .flags(ItemFlag.HIDE_ENCHANTS); + .glow(true); } /** @@ -156,7 +155,7 @@ public StringPlaceholders placeholders() { .add("display_name", StringUtils.capitalize(this.name.replace("_", " "))) .add("max_level", this.maxLevel) .add("required_level", this.requiredLevel) - .add("description", this.description) + .add("description", String.join("\n", this.description)) .add("display_line", this.displayLine) .add("permission", this.permission) .add("enabled", this.enabled) @@ -170,7 +169,7 @@ public StringPlaceholders placeholders() { */ @Override public List comments() { - return this.description.isEmpty() ? List.of("No Description") : List.of(this.description); + return this.description.isEmpty() ? List.of("No Description") : this.description; } /** @@ -199,7 +198,7 @@ public final String name() { /** * @return The description of the augment */ - public final String description() { + public final List description() { return description; } @@ -208,7 +207,7 @@ public final String description() { * * @param description The description of the augment */ - public void description(String description) { + public void description(List description) { this.description = description; } diff --git a/src/main/java/xyz/oribuin/fishing/augment/impl/AugmentBiomeDisrupt.java b/src/main/java/xyz/oribuin/fishing/augment/impl/AugmentBiomeDisrupt.java index 9c55aa7..97423ba 100644 --- a/src/main/java/xyz/oribuin/fishing/augment/impl/AugmentBiomeDisrupt.java +++ b/src/main/java/xyz/oribuin/fishing/augment/impl/AugmentBiomeDisrupt.java @@ -18,7 +18,7 @@ public class AugmentBiomeDisrupt extends Augment { private String chanceFormula = "%level% * 0.20"; // 20% per level public AugmentBiomeDisrupt() { - super("biome_disruption", "When a player catches a fish, there is a chance to ignore the biome restrictions."); + super("biome_disruption", "&7When a player catches a fish, there is", "&7a chance to ignore the biome restrictions."); this.maxLevel = 3; } diff --git a/src/main/java/xyz/oribuin/fishing/augment/impl/AugmentCallOfTheSea.java b/src/main/java/xyz/oribuin/fishing/augment/impl/AugmentCallOfTheSea.java index b4a702f..825d790 100644 --- a/src/main/java/xyz/oribuin/fishing/augment/impl/AugmentCallOfTheSea.java +++ b/src/main/java/xyz/oribuin/fishing/augment/impl/AugmentCallOfTheSea.java @@ -18,7 +18,7 @@ public class AugmentCallOfTheSea extends Augment { private int maxFish = 3; public AugmentCallOfTheSea() { - super("call_of_the_sea", "Increases the amount of fish caught when the weather is raining"); + super("call_of_the_sea", "&7Increases the amount of fish", "&7caught when the weather is raining"); this.maxLevel = 15; } diff --git a/src/main/java/xyz/oribuin/fishing/augment/impl/AugmentHotspot.java b/src/main/java/xyz/oribuin/fishing/augment/impl/AugmentHotspot.java index 76624df..7b8ee06 100644 --- a/src/main/java/xyz/oribuin/fishing/augment/impl/AugmentHotspot.java +++ b/src/main/java/xyz/oribuin/fishing/augment/impl/AugmentHotspot.java @@ -18,7 +18,7 @@ public class AugmentHotspot extends Augment { private int maxFish = 3; public AugmentHotspot() { - super("hotspot", "Increases the amount of fish caught when the weather is clear"); + super("hotspot", "&7Increases the amount of fish", "&7caught when the weather is clear"); this.maxLevel = 15; } diff --git a/src/main/java/xyz/oribuin/fishing/augment/impl/AugmentIntellect.java b/src/main/java/xyz/oribuin/fishing/augment/impl/AugmentIntellect.java index 081fa00..783571b 100644 --- a/src/main/java/xyz/oribuin/fishing/augment/impl/AugmentIntellect.java +++ b/src/main/java/xyz/oribuin/fishing/augment/impl/AugmentIntellect.java @@ -17,7 +17,7 @@ public class AugmentIntellect extends Augment { * Create a new augment instance with a name and description */ public AugmentIntellect() { - super("intellect", "Increases the base minecraft xp earned from catching fish."); + super("intellect", "&7Increases the base minecraft xp", "&7earned from catching fish."); this.maxLevel = 3; } diff --git a/src/main/java/xyz/oribuin/fishing/augment/impl/AugmentPerception.java b/src/main/java/xyz/oribuin/fishing/augment/impl/AugmentPerception.java index ac14b1d..430f8fe 100644 --- a/src/main/java/xyz/oribuin/fishing/augment/impl/AugmentPerception.java +++ b/src/main/java/xyz/oribuin/fishing/augment/impl/AugmentPerception.java @@ -17,7 +17,7 @@ public class AugmentPerception extends Augment { * Create a new augment instance with a name and description */ public AugmentPerception() { - super("perception", "Increases the base entropy earned from catching fish."); + super("perception", "&7Increases the base entropy ", "&7earned from catching fish."); this.maxLevel = 5; } diff --git a/src/main/java/xyz/oribuin/fishing/augment/impl/AugmentPrecisionCutting.java b/src/main/java/xyz/oribuin/fishing/augment/impl/AugmentPrecisionCutting.java index 2e2a668..c32483b 100644 --- a/src/main/java/xyz/oribuin/fishing/augment/impl/AugmentPrecisionCutting.java +++ b/src/main/java/xyz/oribuin/fishing/augment/impl/AugmentPrecisionCutting.java @@ -17,7 +17,7 @@ public class AugmentPrecisionCutting extends Augment { * Create a new augment instance with a name and description */ public AugmentPrecisionCutting() { - super("precision_cutting", "Increases the entropy gained from gutting fish."); + super("precision_cutting", "&7Increases the entropy ", "&7gained from gutting fish."); } /** diff --git a/src/main/java/xyz/oribuin/fishing/augment/impl/AugmentSage.java b/src/main/java/xyz/oribuin/fishing/augment/impl/AugmentSage.java index 0889024..edc1bf3 100644 --- a/src/main/java/xyz/oribuin/fishing/augment/impl/AugmentSage.java +++ b/src/main/java/xyz/oribuin/fishing/augment/impl/AugmentSage.java @@ -17,7 +17,7 @@ public class AugmentSage extends Augment { * Create a new augment instance with a name and description */ public AugmentSage() { - super("sage", "Increases the base plugin xp earned from catching fish."); + super("sage", "&7Increases the base plugin xp", "&7earned from catching fish."); } /** diff --git a/src/main/java/xyz/oribuin/fishing/augment/impl/AugmentSaturate.java b/src/main/java/xyz/oribuin/fishing/augment/impl/AugmentSaturate.java index fbe82f8..28baad5 100644 --- a/src/main/java/xyz/oribuin/fishing/augment/impl/AugmentSaturate.java +++ b/src/main/java/xyz/oribuin/fishing/augment/impl/AugmentSaturate.java @@ -14,7 +14,7 @@ public class AugmentSaturate extends Augment { private String chanceFormula = "%level% * 0.15"; // 15% per level public AugmentSaturate() { - super("saturate", "Fully saturates the player when they catch a fish"); + super("saturate", "&7Fully saturates the player", "&7when they catch a fish"); } /** diff --git a/src/main/java/xyz/oribuin/fishing/command/FishCommand.java b/src/main/java/xyz/oribuin/fishing/command/FishCommand.java index cacb5cd..d8e7552 100644 --- a/src/main/java/xyz/oribuin/fishing/command/FishCommand.java +++ b/src/main/java/xyz/oribuin/fishing/command/FishCommand.java @@ -8,6 +8,7 @@ import dev.rosewood.rosegarden.command.framework.CommandInfo; import xyz.oribuin.fishing.command.impl.ApplyCommand; import xyz.oribuin.fishing.command.impl.MenuCommand; +import xyz.oribuin.fishing.command.impl.admin.GiveCommand; public class FishCommand extends BaseRoseCommand { @@ -20,7 +21,6 @@ protected CommandInfo createCommandInfo() { return CommandInfo.builder("fish") .aliases("fishing") .arguments(this.createArguments()) - .playerOnly(true) .build(); } @@ -30,7 +30,8 @@ private ArgumentsDefinition createArguments() { new HelpCommand(this.rosePlugin, this), new ReloadCommand(this.rosePlugin), new ApplyCommand(this.rosePlugin), - new MenuCommand(this.rosePlugin) + new MenuCommand(this.rosePlugin), + new GiveCommand(this.rosePlugin) ); } diff --git a/src/main/java/xyz/oribuin/fishing/command/argument/AugmentArgument.java b/src/main/java/xyz/oribuin/fishing/command/argument/AugmentArgument.java index c2f9b94..e7a7940 100644 --- a/src/main/java/xyz/oribuin/fishing/command/argument/AugmentArgument.java +++ b/src/main/java/xyz/oribuin/fishing/command/argument/AugmentArgument.java @@ -22,7 +22,7 @@ public Augment handle(CommandContext context, Argument argument, InputIterator i Augment augment = AugmentRegistry.all().get(input); if (augment != null) return augment; - throw new HandledArgumentException("argument-handler-augments", StringPlaceholders.of("augment", input)); + throw new HandledArgumentException("argument-handler-augments", StringPlaceholders.of("input", input)); } @Override diff --git a/src/main/java/xyz/oribuin/fishing/command/argument/FishArgument.java b/src/main/java/xyz/oribuin/fishing/command/argument/FishArgument.java new file mode 100644 index 0000000..c8656d8 --- /dev/null +++ b/src/main/java/xyz/oribuin/fishing/command/argument/FishArgument.java @@ -0,0 +1,36 @@ +package xyz.oribuin.fishing.command.argument; + +import dev.rosewood.rosegarden.command.framework.Argument; +import dev.rosewood.rosegarden.command.framework.ArgumentHandler; +import dev.rosewood.rosegarden.command.framework.CommandContext; +import dev.rosewood.rosegarden.command.framework.InputIterator; +import dev.rosewood.rosegarden.utils.StringPlaceholders; +import xyz.oribuin.fishing.FishingPlugin; +import xyz.oribuin.fishing.fish.Fish; +import xyz.oribuin.fishing.manager.TierManager; + +import java.util.List; + +public class FishArgument extends ArgumentHandler { + + public FishArgument() { + super(Fish.class); + } + + @Override + public Fish handle(CommandContext context, Argument argument, InputIterator inputIterator) throws HandledArgumentException { + String input = inputIterator.next(); + Fish fish = FishingPlugin.get().getManager(TierManager.class).getFish(input); + if (fish != null) return fish; + + throw new HandledArgumentException("argument-handler-fish", StringPlaceholders.of("input", input)); + } + + @Override + public List suggest(CommandContext context, Argument argument, String[] args) { + return FishingPlugin.get().getManager(TierManager.class).allFish().stream() + .map(Fish::name) + .toList(); + } + +} diff --git a/src/main/java/xyz/oribuin/fishing/command/argument/SkillArgument.java b/src/main/java/xyz/oribuin/fishing/command/argument/SkillArgument.java new file mode 100644 index 0000000..9b4d64d --- /dev/null +++ b/src/main/java/xyz/oribuin/fishing/command/argument/SkillArgument.java @@ -0,0 +1,33 @@ +package xyz.oribuin.fishing.command.argument; + +import dev.rosewood.rosegarden.command.framework.Argument; +import dev.rosewood.rosegarden.command.framework.ArgumentHandler; +import dev.rosewood.rosegarden.command.framework.CommandContext; +import dev.rosewood.rosegarden.command.framework.InputIterator; +import dev.rosewood.rosegarden.utils.StringPlaceholders; +import xyz.oribuin.fishing.skill.Skill; +import xyz.oribuin.fishing.skill.SkillRegistry; + +import java.util.List; + +public class SkillArgument extends ArgumentHandler { + + public SkillArgument() { + super(Skill.class); + } + + @Override + public Skill handle(CommandContext context, Argument argument, InputIterator inputIterator) throws HandledArgumentException { + String input = inputIterator.next(); + Skill skill = SkillRegistry.get(input); + if (skill != null) return skill; + + throw new HandledArgumentException("argument-handler-skill", StringPlaceholders.of("input", input)); + } + + @Override + public List suggest(CommandContext context, Argument argument, String[] args) { + return SkillRegistry.all().values().stream().map(Skill::name).toList(); + } + +} \ No newline at end of file diff --git a/src/main/java/xyz/oribuin/fishing/command/argument/TierArgument.java b/src/main/java/xyz/oribuin/fishing/command/argument/TierArgument.java new file mode 100644 index 0000000..a7d64b8 --- /dev/null +++ b/src/main/java/xyz/oribuin/fishing/command/argument/TierArgument.java @@ -0,0 +1,34 @@ +package xyz.oribuin.fishing.command.argument; + +import dev.rosewood.rosegarden.command.framework.Argument; +import dev.rosewood.rosegarden.command.framework.ArgumentHandler; +import dev.rosewood.rosegarden.command.framework.CommandContext; +import dev.rosewood.rosegarden.command.framework.InputIterator; +import dev.rosewood.rosegarden.utils.StringPlaceholders; +import xyz.oribuin.fishing.FishingPlugin; +import xyz.oribuin.fishing.fish.Tier; +import xyz.oribuin.fishing.manager.TierManager; + +import java.util.List; + +public class TierArgument extends ArgumentHandler { + + public TierArgument() { + super(Tier.class); + } + + @Override + public Tier handle(CommandContext context, Argument argument, InputIterator inputIterator) throws HandledArgumentException { + String input = inputIterator.next(); + Tier tier = FishingPlugin.get().getManager(TierManager.class).get(input); + if (tier != null) return tier; + + throw new HandledArgumentException("argument-handler-tier", StringPlaceholders.of("input", input)); + } + + @Override + public List suggest(CommandContext context, Argument argument, String[] args) { + return FishingPlugin.get().getManager(TierManager.class).getTiers().keySet().stream().toList(); + } + +} diff --git a/src/main/java/xyz/oribuin/fishing/command/impl/admin/GiveCommand.java b/src/main/java/xyz/oribuin/fishing/command/impl/admin/GiveCommand.java new file mode 100644 index 0000000..ff9a256 --- /dev/null +++ b/src/main/java/xyz/oribuin/fishing/command/impl/admin/GiveCommand.java @@ -0,0 +1,30 @@ +package xyz.oribuin.fishing.command.impl.admin; + +import dev.rosewood.rosegarden.RosePlugin; +import dev.rosewood.rosegarden.command.framework.ArgumentsDefinition; +import dev.rosewood.rosegarden.command.framework.BaseRoseCommand; +import dev.rosewood.rosegarden.command.framework.CommandInfo; +import xyz.oribuin.fishing.command.impl.admin.give.GiveAugmentCommand; +import xyz.oribuin.fishing.command.impl.admin.give.GiveFishCommand; + +public class GiveCommand extends BaseRoseCommand { + + public GiveCommand(RosePlugin rosePlugin) { + super(rosePlugin); + } + + @Override + protected CommandInfo createCommandInfo() { + return CommandInfo.builder("give") + .descriptionKey("command-give-description") + .permission("fishing.admin") + .arguments(this.createArguments()) + .build(); + } + + private ArgumentsDefinition createArguments() { + return ArgumentsDefinition.builder() + .requiredSub(new GiveAugmentCommand(this.rosePlugin), new GiveFishCommand(this.rosePlugin)); + } + +} diff --git a/src/main/java/xyz/oribuin/fishing/command/impl/admin/give/GiveAugmentCommand.java b/src/main/java/xyz/oribuin/fishing/command/impl/admin/give/GiveAugmentCommand.java new file mode 100644 index 0000000..89dccb4 --- /dev/null +++ b/src/main/java/xyz/oribuin/fishing/command/impl/admin/give/GiveAugmentCommand.java @@ -0,0 +1,55 @@ +package xyz.oribuin.fishing.command.impl.admin.give; + +import dev.rosewood.rosegarden.RosePlugin; +import dev.rosewood.rosegarden.command.argument.ArgumentHandlers; +import dev.rosewood.rosegarden.command.framework.ArgumentsDefinition; +import dev.rosewood.rosegarden.command.framework.BaseRoseCommand; +import dev.rosewood.rosegarden.command.framework.CommandContext; +import dev.rosewood.rosegarden.command.framework.CommandInfo; +import dev.rosewood.rosegarden.command.framework.annotation.RoseExecutable; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import xyz.oribuin.fishing.augment.Augment; +import xyz.oribuin.fishing.command.argument.AugmentArgument; + +public class GiveAugmentCommand extends BaseRoseCommand { + + public GiveAugmentCommand(RosePlugin rosePlugin) { + super(rosePlugin); + } + + @RoseExecutable + public void execute(CommandContext context, Player target, Augment augment, Integer amount) { + int fixedAmount = Math.max(1, Math.min(amount == null ? 1 : amount, 64)); + + CommandSender sender = context.getSender(); + ItemStack item = augment.displayItem().build(augment.placeholders()).asQuantity(fixedAmount); + + if (target.getInventory().firstEmpty() == -1) { + // TODO: Plugin Message + sender.sendMessage(target.getName() + "'s inventory is full."); + return; + } + + target.getInventory().addItem(item); + sender.sendMessage("You have given " + target.getName() + " " + fixedAmount + " " + augment.name() + " augment(s)."); + } + + @Override + protected CommandInfo createCommandInfo() { + return CommandInfo.builder("augment") + .descriptionKey("command-give-description") + .permission("fishing.admin") + .arguments(this.createArguments()) + .build(); + } + + private ArgumentsDefinition createArguments() { + return ArgumentsDefinition.builder() + .required("player", ArgumentHandlers.PLAYER) + .required("augment", new AugmentArgument()) + .optional("amount", ArgumentHandlers.INTEGER) + .build(); + } +} diff --git a/src/main/java/xyz/oribuin/fishing/command/impl/admin/give/GiveFishCommand.java b/src/main/java/xyz/oribuin/fishing/command/impl/admin/give/GiveFishCommand.java new file mode 100644 index 0000000..0470b27 --- /dev/null +++ b/src/main/java/xyz/oribuin/fishing/command/impl/admin/give/GiveFishCommand.java @@ -0,0 +1,55 @@ +package xyz.oribuin.fishing.command.impl.admin.give; + +import dev.rosewood.rosegarden.RosePlugin; +import dev.rosewood.rosegarden.command.argument.ArgumentHandlers; +import dev.rosewood.rosegarden.command.framework.ArgumentsDefinition; +import dev.rosewood.rosegarden.command.framework.BaseRoseCommand; +import dev.rosewood.rosegarden.command.framework.CommandContext; +import dev.rosewood.rosegarden.command.framework.CommandInfo; +import dev.rosewood.rosegarden.command.framework.annotation.RoseExecutable; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import xyz.oribuin.fishing.command.argument.FishArgument; +import xyz.oribuin.fishing.fish.Fish; + +public class GiveFishCommand extends BaseRoseCommand { + + public GiveFishCommand(RosePlugin rosePlugin) { + super(rosePlugin); + } + + @RoseExecutable + public void execute(CommandContext context, Player target, Fish fish, Integer amount) { + int fixedAmount = Math.max(1, Math.min(amount == null ? 1 : amount, 64)); + + CommandSender sender = context.getSender(); + ItemStack item = fish.createItemStack().asQuantity(fixedAmount); + + if (target.getInventory().firstEmpty() == -1) { + // TODO: Plugin Message + sender.sendMessage(target.getName() + "'s inventory is full."); + return; + } + + target.getInventory().addItem(item); + sender.sendMessage("You have given " + target.getName() + " " + fixedAmount + " " + fish.name() + " fish."); + } + + @Override + protected CommandInfo createCommandInfo() { + return CommandInfo.builder("fish") + .descriptionKey("command-give-description") + .permission("fishing.admin") + .arguments(this.createArguments()) + .build(); + } + + private ArgumentsDefinition createArguments() { + return ArgumentsDefinition.builder() + .required("player", ArgumentHandlers.PLAYER) + .required("fish", new FishArgument()) + .optional("amount", ArgumentHandlers.INTEGER) + .build(); + } +} diff --git a/src/main/java/xyz/oribuin/fishing/fish/Fish.java b/src/main/java/xyz/oribuin/fishing/fish/Fish.java index 19cdd31..3d0b010 100644 --- a/src/main/java/xyz/oribuin/fishing/fish/Fish.java +++ b/src/main/java/xyz/oribuin/fishing/fish/Fish.java @@ -148,12 +148,12 @@ private StringPlaceholders placeholders() { .add("name", this.displayName) .add("tier", this.tier) .add("description", String.join("\n", this.description)) - .add("biomes", this.condition.biomes().isEmpty() ? "All" : String.join(", ", this.condition.biomes())) - .add("weather", this.condition.weather() == null ? "All" : this.condition.weather().name()) - .add("time", this.condition.time() == null ? "All" : this.condition.time().name()) - .add("worlds", this.condition.worlds().isEmpty() ? "All" : String.join(", ", this.condition.worlds())) - .add("environment", this.condition.environment() == null ? "All" : this.condition.environment().name()) - .add("water-depth", this.condition.waterDepth() == null ? "All" : this.condition.waterDepth().toString()) + .add("biomes", this.condition.biomes().isEmpty() ? "Any Biome" : String.join(", ", this.condition.biomes())) + .add("weather", FishUtils.niceify(this.condition.weather(), "Any Weather")) + .add("time", FishUtils.niceify(this.condition.time(), "Any Time")) + .add("worlds", this.condition.worlds().isEmpty() ? "Any World" : String.join(", ", this.condition.worlds())) + .add("environment", FishUtils.niceify(this.condition.environment(), "Any Environment")) + .add("water-depth", this.condition.waterDepth() == null ? "Any Depth" : this.condition.waterDepth().toString()) .add("ice-fishing", this.condition.iceFishing() ? "Yes" : "No") .add("height", this.condition.height() == null ? "All" : this.condition.height().getLeft() + " - " + this.condition.height().getRight()) .add("light-level", this.condition.lightLevel() == null ? "All" : this.condition.lightLevel().toString()) diff --git a/src/main/java/xyz/oribuin/fishing/fish/Tier.java b/src/main/java/xyz/oribuin/fishing/fish/Tier.java index 43dcb7b..0fcac2b 100644 --- a/src/main/java/xyz/oribuin/fishing/fish/Tier.java +++ b/src/main/java/xyz/oribuin/fishing/fish/Tier.java @@ -125,6 +125,10 @@ public void saveSettings(@NotNull CommentedConfigurationSection config) { } } + public Fish getFish(String name) { + return this.fish.get(name); + } + public StringPlaceholders placeholders() { return StringPlaceholders.builder() .add("tier", this.name) diff --git a/src/main/java/xyz/oribuin/fishing/manager/TierManager.java b/src/main/java/xyz/oribuin/fishing/manager/TierManager.java index 40fe926..46040ba 100644 --- a/src/main/java/xyz/oribuin/fishing/manager/TierManager.java +++ b/src/main/java/xyz/oribuin/fishing/manager/TierManager.java @@ -4,6 +4,7 @@ import dev.rosewood.rosegarden.config.CommentedFileConfiguration; import dev.rosewood.rosegarden.manager.Manager; import org.jetbrains.annotations.Nullable; +import xyz.oribuin.fishing.fish.Fish; import xyz.oribuin.fishing.fish.Tier; import xyz.oribuin.fishing.util.FishUtils; @@ -76,10 +77,42 @@ public Tier selectTier(double chance) { .orElse(null); } + /** + * Get the tier based on the key + * + * @param key The key of the tier + * + * @return The tier + */ public Tier get(String key) { return this.tiers.get(key); } + /** + * Get the fish from the tier based on the key + * + * @param key The key of the fish + * + * @return The fish from the tier + */ + public Fish getFish(String key) { + return this.tiers.values().stream() + .map(x -> x.getFish(key)) + .findFirst() + .orElse(null); + } + + /** + * Get all the fish from all the tiers + * + * @return All the fish from all the tiers + */ + public List allFish() { + List fish = new ArrayList<>(); + this.tiers.values().forEach(x -> fish.addAll(x.fish().values())); + return fish; + } + @Override public void disable() { this.tiers.clear(); // Clear the cached list of tiers diff --git a/src/main/java/xyz/oribuin/fishing/skill/SkillRegistry.java b/src/main/java/xyz/oribuin/fishing/skill/SkillRegistry.java index 2b13bb4..521ed50 100644 --- a/src/main/java/xyz/oribuin/fishing/skill/SkillRegistry.java +++ b/src/main/java/xyz/oribuin/fishing/skill/SkillRegistry.java @@ -39,6 +39,20 @@ public static Skill get(Class clazz) { return skills.get(clazz); } + /** + * Get a skill from the registry + * + * @param name The name of the skill + * + * @return The skill + */ + public static Skill get(String name) { + return skills.values().stream() + .filter(skill -> skill.name().equalsIgnoreCase(name)) + .findFirst() + .orElse(null); + } + /** * Get all the skills from the registry * diff --git a/src/main/java/xyz/oribuin/fishing/util/FishUtils.java b/src/main/java/xyz/oribuin/fishing/util/FishUtils.java index 474999c..2ba86bc 100644 --- a/src/main/java/xyz/oribuin/fishing/util/FishUtils.java +++ b/src/main/java/xyz/oribuin/fishing/util/FishUtils.java @@ -5,6 +5,7 @@ import dev.rosewood.rosegarden.utils.HexUtils; import dev.rosewood.rosegarden.utils.StringPlaceholders; import net.objecthunter.exp4j.ExpressionBuilder; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.Pair; import org.bukkit.Color; import org.bukkit.entity.Player; @@ -280,6 +281,28 @@ public static > List getEnumList(Class enumClass, List The enum type + * + * @return The niceified string + */ + public static > String niceify(T enumValue) { + String noUnderscores = enumValue.name().toLowerCase().replace("_", " "); + return StringUtils.capitalize(noUnderscores); + } + + public static > String niceify(T enumValue, String def) { + if (enumValue == null) return def; + + String noUnderscores = enumValue.name().toLowerCase().replace("_", " "); + return StringUtils.capitalize(noUnderscores); + } + + + /** * Parse a list of strings from 1-1 to a stringlist * @@ -324,6 +347,7 @@ public static List getNumberRange(int start, int end) { /** * Generate the default fish names from the resources + * * @return The list of fish names */ public static List generateFishNames() { @@ -340,7 +364,7 @@ public static List generateFishNames() { while ((line = reader.readLine()) != null) { fishNames.add(line); } - } catch (Exception e){ + } catch (Exception e) { FishingPlugin.get().getLogger().severe("Failed to generate default fish: " + e.getMessage()); } diff --git a/src/main/java/xyz/oribuin/fishing/util/ItemConstruct.java b/src/main/java/xyz/oribuin/fishing/util/ItemConstruct.java index 872b67f..ad7be3c 100644 --- a/src/main/java/xyz/oribuin/fishing/util/ItemConstruct.java +++ b/src/main/java/xyz/oribuin/fishing/util/ItemConstruct.java @@ -42,6 +42,7 @@ public class ItemConstruct { private String texture; private List effects; private Color color; + private boolean glow; /** * Create a new Item Construct with a Material @@ -56,6 +57,7 @@ private ItemConstruct(Material type) { this.enchantment = new HashMap<>(); this.flags = new ArrayList<>(); this.effects = new ArrayList<>(); + this.glow = false; } /** @@ -79,16 +81,20 @@ public void serialize(CommentedConfigurationSection config) { config.set("type", this.type.name()); config.set("amount", this.amount); + if (this.name != null) config.set("name", this.name); if (this.lore != null && !this.lore.isEmpty()) config.set("lore", this.lore); if (this.model != 0) config.set("model", this.model); + + config.set("unbreakable", this.unbreakable); + config.set("glow", this.glow); + if (this.enchantment != null) { for (Map.Entry entry : this.enchantment.entrySet()) { config.set("enchantments." + entry.getKey().getKey().getKey(), entry.getValue()); } } - config.set("unbreakable", this.unbreakable); if (this.flags != null && !this.flags.isEmpty()) config.set("flags", this.flags.stream().map(ItemFlag::name).toList()); if (this.texture != null) config.set("texture", this.texture); if (this.color != null) config.set("color", this.color.asRGB()); @@ -100,6 +106,8 @@ public void serialize(CommentedConfigurationSection config) { config.set("effects." + i + ".amplifier", effect.amp); } } + + } /** @@ -124,6 +132,7 @@ public static ItemConstruct deserialize(CommentedConfigurationSection config) { construct.flagSerialize(config.getStringList("flags")); construct.texture(config.getString("texture")); construct.color(Color.fromRGB(config.getInt("color"))); + construct.glow(config.getBoolean("glow")); // Serialize the enchants CommentedConfigurationSection enchantments = config.getConfigurationSection("enchantments"); @@ -193,6 +202,7 @@ public ItemStack build(StringPlaceholders placeholders) { if (this.model != 0) meta.setCustomModelData(this.model); if (this.amount > 1) stack.setAmount(this.amount); if (this.unbreakable) meta.setUnbreakable(true); + if (this.glow) meta.setEnchantmentGlintOverride(true); if (this.flags != null && !this.flags.isEmpty()) this.flags.forEach(meta::addItemFlags); if (this.enchantment != null) { for (Map.Entry entry : this.enchantment.entrySet()) { @@ -409,6 +419,18 @@ public ItemConstruct color(String hex) { return this; } + /** + * Apply the itemstack glow + * + * @param glow If the itemstack should glow + * + * @return The itemstack constructor + */ + public ItemConstruct glow(boolean glow) { + this.glow = glow; + return this; + } + /** * Apply the itemstack effects *