generated from Rosewood-Development/RoseTemplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
236 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
76
src/main/java/xyz/oribuin/fishing/api/recipe/RecipeItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
63 changes: 63 additions & 0 deletions
63
src/main/java/xyz/oribuin/fishing/api/recipe/type/AugmentRecipeItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
src/main/java/xyz/oribuin/fishing/api/recipe/type/MaterialRecipeItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters