Skip to content

Commit

Permalink
start recipes
Browse files Browse the repository at this point in the history
  • Loading branch information
Oribuin committed Nov 25, 2024
1 parent 1ab7ae8 commit 605cc5c
Show file tree
Hide file tree
Showing 7 changed files with 236 additions and 1 deletion.
30 changes: 30 additions & 0 deletions src/main/java/xyz/oribuin/fishing/api/recipe/Recipe.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package xyz.oribuin.fishing.api.recipe;

import xyz.oribuin.fishing.api.economy.Cost;

import java.util.List;

public interface Recipe<T> {

/**
* The result of the recipe
*
* @return The result of the recipe
*/
T result();

/**
* The list of ingredients for the recipe to be crafted
*
* @return The list of ingredients
*/
List<RecipeItem<?>> ingredients();

/**
* The cost of the recipe
*
* @return The cost of the recipe
*/
Cost cost();

}
76 changes: 76 additions & 0 deletions src/main/java/xyz/oribuin/fishing/api/recipe/RecipeItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package xyz.oribuin.fishing.api.recipe;

import dev.rosewood.rosegarden.config.CommentedConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import xyz.oribuin.fishing.api.config.Configurable;


private final Class<T> type; // This is the type of the ite;
protected T item;
protected int amount;

public RecipeItem(Class<T> type) {
this.type = type;
}

/**
* Check if the item is the same as the recipe item
*
* @param item The item to check
*
* @return If the item is the same as the recipe item
*/
public abstract boolean check(ItemStack item);

/**
* Load the settings from the configuration file
* I would recommend always super calling this method to save any settings that could be implemented
*
* @param config The configuration file to load
*/
@Override
public void loadSettings(@NotNull CommentedConfigurationSection config) {
this.amount = config.getInt("amount", 1);
}

/**
* Save the configuration file for the configurable class
* I would recommend always super calling this method to save any settings that could be implemented
*
* @param config The configuration file to save
*/
@Override
public void saveSettings(@NotNull CommentedConfigurationSection config) {
config.set("amount", this.amount);
}

/**
* Get the item of the recipe item
*
* @return The item of the recipe item
*/
public final T item() {
return this.item;
}

/**
* Get the amount of the recipe item
*
* @return The amount of the recipe item
*/
public final Class<T> type() {
return this.type;
}

/**
* Get the amount of the recipe item
*
* @return The amount of the recipe item
*/
public final int amount() {
return this.amount;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package xyz.oribuin.fishing.api.recipe.type;

import dev.rosewood.rosegarden.config.CommentedConfigurationSection;
import org.bukkit.inventory.ItemStack;
import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType;
import org.jetbrains.annotations.NotNull;
import xyz.oribuin.fishing.api.recipe.RecipeItem;
import xyz.oribuin.fishing.augment.Augment;
import xyz.oribuin.fishing.augment.AugmentRegistry;
import xyz.oribuin.fishing.storage.util.PersistKeys;

public class AugmentRecipeItem extends RecipeItem<Augment> {

public AugmentRecipeItem() {
super(Augment.class);
}

/**
* Check if the item is the same as the recipe item
*
* @param item The item to check
*
* @return If the item is the same as the recipe item
*/
@Override
public boolean check(ItemStack item) {
if (item == null) return false;

PersistentDataContainer container = item.getItemMeta().getPersistentDataContainer();
String augmentType = container.get(PersistKeys.AUGMENT_TYPE, PersistentDataType.STRING);

return augmentType != null && augmentType.equalsIgnoreCase(this.item.name());
}


/**
* Load the settings from the configuration file
* I would recommend always super calling this method to save any settings that could be implemented
*
* @param config The configuration file to load
*/
@Override
public void loadSettings(@NotNull CommentedConfigurationSection config) {
super.loadSettings(config);

this.item = AugmentRegistry.from(config.getString("item"));
}

/**
* Save the configuration file for the configurable class
* I would recommend always super calling this method to save any settings that could be implemented
*
* @param config The configuration file to save
*/
@Override
public void saveSettings(@NotNull CommentedConfigurationSection config) {
super.saveSettings(config);

config.set("item", this.item.name());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package xyz.oribuin.fishing.api.recipe.type;

import dev.rosewood.rosegarden.config.CommentedConfigurationSection;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import xyz.oribuin.fishing.api.recipe.RecipeItem;
import xyz.oribuin.fishing.util.FishUtils;

public class MaterialRecipeItem extends RecipeItem<Material> {

public MaterialRecipeItem() {
super(Material.class);
}

/**
* Check if the item is the same as the recipe item
*
* @param item The item to check
*
* @return If the item is the same as the recipe item
*/
@Override
public boolean check(ItemStack item) {
return item != null && item.getType() == this.item();
}

/**
* Load the settings from the configuration file
* I would recommend always super calling this method to save any settings that could be implemented
*
* @param config The configuration file to load
*/
@Override
public void loadSettings(@NotNull CommentedConfigurationSection config) {
super.loadSettings(config);

this.item = FishUtils.getEnum(this.type(), config.getString("item"), Material.BEDROCK);
}
/**
* Save the configuration file for the configurable class
* I would recommend always super calling this method to save any settings that could be implemented
*
* @param config The configuration file to save
*/
@Override
public void saveSettings(@NotNull CommentedConfigurationSection config) {
super.saveSettings(config);

config.set("item", this.item().name());
}

}
1 change: 0 additions & 1 deletion src/main/java/xyz/oribuin/fishing/augment/Augment.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public abstract class Augment extends FishEventHandler implements Listener, Conf
protected int requiredLevel;
protected String permission;


/**
* Create a new augment instance with a name and description
*
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/xyz/oribuin/fishing/augment/AugmentRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@ public static Map<Augment, Integer> from(ItemStack itemStack) {
return result;
}

/**
* Get an augment from the registry by its name
*
* @param name The name of the augment
*
* @return The augment
*/
public static Augment from(String name) {
return augments.get(name);
}

/**
* Save the augments to the itemstack meta
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ public class PersistKeys {
public static NamespacedKey FISH_TYPE = new NamespacedKey(PLUGIN, "fish_type");
public static NamespacedKey FISH_TIER = new NamespacedKey(PLUGIN, "fish_tier");

// Augment Namespaces
public static final NamespacedKey AUGMENT_TYPE = new NamespacedKey(PLUGIN, "augment_type");

// Totem Namespaces
public static final NamespacedKey TOTEM_OWNER = new NamespacedKey(PLUGIN, "totem_owner");
public static final NamespacedKey TOTEM_OWNERNAME = new NamespacedKey(PLUGIN, "totem_ownername");
Expand Down

0 comments on commit 605cc5c

Please sign in to comment.