Skip to content

Commit

Permalink
item stuff :)))
Browse files Browse the repository at this point in the history
  • Loading branch information
Oribuin committed Nov 26, 2024
1 parent b75c4b5 commit d2fcd77
Show file tree
Hide file tree
Showing 23 changed files with 374 additions and 34 deletions.
29 changes: 14 additions & 15 deletions src/main/java/xyz/oribuin/fishing/augment/Augment.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> description;
protected ItemConstruct displayItem;
protected String displayLine;
protected int maxLevel;
Expand All @@ -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();
Expand Down Expand Up @@ -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");
Expand All @@ -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"));
Expand All @@ -114,17 +115,15 @@ public void loadSettings(@NotNull CommentedConfigurationSection config) {
*/
private ItemConstruct defaultItem() {
return ItemConstruct.of(Material.FIREWORK_STAR)
.name("&f[&#4f73d6>&l%display_name%&f]")
.name("&f[&#4f73d6&l%display_name%&f]")
.lore("&7%description%",
"",
"&#4f73d6Information",
" &7| &fRequired Level: &#4f73d6%required_level%",
" &7| &fMax Level: &#4f73d6%max_level%",
" &7| &fCost: &#4f73d6%amount% &f%currency%",
" &#4f73d6- &7Required Level: &f%required_level%",
" &#4f73d6- &7Max Level: &f%max_level%",
""
)
.enchant(Enchantment.EFFICIENCY, 1)
.flags(ItemFlag.HIDE_ENCHANTS);
.glow(true);
}

/**
Expand Down Expand Up @@ -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)
Expand All @@ -170,7 +169,7 @@ public StringPlaceholders placeholders() {
*/
@Override
public List<String> comments() {
return this.description.isEmpty() ? List.of("No Description") : List.of(this.description);
return this.description.isEmpty() ? List.of("No Description") : this.description;
}

/**
Expand Down Expand Up @@ -199,7 +198,7 @@ public final String name() {
/**
* @return The description of the augment
*/
public final String description() {
public final List<String> description() {
return description;
}

Expand All @@ -208,7 +207,7 @@ public final String description() {
*
* @param description The description of the augment
*/
public void description(String description) {
public void description(List<String> description) {
this.description = description;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/xyz/oribuin/fishing/command/FishCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -20,7 +21,6 @@ protected CommandInfo createCommandInfo() {
return CommandInfo.builder("fish")
.aliases("fishing")
.arguments(this.createArguments())
.playerOnly(true)
.build();
}

Expand All @@ -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)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Fish> {

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<String> suggest(CommandContext context, Argument argument, String[] args) {
return FishingPlugin.get().getManager(TierManager.class).allFish().stream()
.map(Fish::name)
.toList();
}

}
Original file line number Diff line number Diff line change
@@ -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<Skill> {

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<String> suggest(CommandContext context, Argument argument, String[] args) {
return SkillRegistry.all().values().stream().map(Skill::name).toList();
}

}
Original file line number Diff line number Diff line change
@@ -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<Tier> {

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<String> suggest(CommandContext context, Argument argument, String[] args) {
return FishingPlugin.get().getManager(TierManager.class).getTiers().keySet().stream().toList();
}

}
Original file line number Diff line number Diff line change
@@ -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));
}

}
Loading

0 comments on commit d2fcd77

Please sign in to comment.