-
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.
Add Custom craft and its config GUI. (#5)
- Loading branch information
Showing
24 changed files
with
1,582 additions
and
389 deletions.
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
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
2 changes: 1 addition & 1 deletion
2
.../gui/config/AbstractEnchantConfigGui.java → ...nfig/global/AbstractEnchantConfigGui.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
94 changes: 94 additions & 0 deletions
94
src/main/java/xyz/alexcrea/cuanvil/gui/config/global/CustomRecipeConfigGui.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,94 @@ | ||
package xyz.alexcrea.cuanvil.gui.config.global; | ||
|
||
import com.github.stefvanschie.inventoryframework.gui.GuiItem; | ||
import org.bukkit.Material; | ||
import org.bukkit.inventory.ItemFlag; | ||
import org.bukkit.inventory.ItemStack; | ||
import org.bukkit.inventory.meta.ItemMeta; | ||
import xyz.alexcrea.cuanvil.config.ConfigHolder; | ||
import xyz.alexcrea.cuanvil.gui.config.settings.subsetting.CustomRecipeSubSettingGui; | ||
import xyz.alexcrea.cuanvil.recipe.AnvilCustomRecipe; | ||
import xyz.alexcrea.cuanvil.util.CasedStringUtil; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public class CustomRecipeConfigGui extends MappedElementListConfigGui<AnvilCustomRecipe, CustomRecipeSubSettingGui> { | ||
|
||
|
||
public final static CustomRecipeConfigGui INSTANCE = new CustomRecipeConfigGui(); | ||
|
||
static { | ||
INSTANCE.init(); | ||
} | ||
|
||
private CustomRecipeConfigGui() { | ||
super("Custom Recipe Config"); | ||
|
||
} | ||
|
||
@Override | ||
protected ItemStack createItemForGeneric(AnvilCustomRecipe recipe) { | ||
// Get base item to display | ||
ItemStack craftResultItem = recipe.getResultItem(); | ||
ItemStack displaydItem; | ||
if(craftResultItem == null){ | ||
displaydItem = new ItemStack(Material.BARRIER); | ||
}else{ | ||
displaydItem = craftResultItem.clone(); | ||
} | ||
|
||
// edit displayed item | ||
ItemMeta meta = displaydItem.getItemMeta(); | ||
|
||
meta.setDisplayName("\u00A7e" + CasedStringUtil.snakeToUpperSpacedCase(recipe.getName()) + " \u00A7fCustom recipe"); | ||
meta.addItemFlags(ItemFlag.values()); | ||
|
||
boolean shouldWork = recipe.validate(); | ||
|
||
meta.setLore(Arrays.asList( | ||
"\u00A77Should work: \u00A7"+(shouldWork ? "aYes" : "cNo"), | ||
"\u00A77Exact count: \u00A7"+(recipe.getExactCount() ? "aYes" : "cNo"), | ||
"\u00A77Recipe Xp Cost: \u00A7e"+recipe.getXpCostPerCraft() | ||
|
||
)); | ||
|
||
displaydItem.setItemMeta(meta); | ||
return displaydItem; | ||
} | ||
|
||
@Override | ||
protected CustomRecipeSubSettingGui newInstanceOfGui(AnvilCustomRecipe generic, GuiItem item) { | ||
return new CustomRecipeSubSettingGui(this, generic, item); | ||
} | ||
|
||
@Override | ||
protected String genericDisplayedName() { | ||
return "custom recipe"; | ||
} | ||
|
||
@Override | ||
protected AnvilCustomRecipe createAndSaveNewEmptyGeneric(String name) { | ||
// Create new empty conflict and display it to the admin | ||
AnvilCustomRecipe recipe = new AnvilCustomRecipe( | ||
name, | ||
AnvilCustomRecipe.Companion.getDEFAULT_EXACT_COUNT_CONFIG(), | ||
AnvilCustomRecipe.Companion.getDEFAULT_XP_COST_CONFIG(), | ||
AnvilCustomRecipe.Companion.getDEFAULT_LEFT_ITEM_CONFIG(), | ||
AnvilCustomRecipe.Companion.getDEFAULT_RIGHT_ITEM_CONFIG(), | ||
AnvilCustomRecipe.Companion.getDEFAULT_RESULT_ITEM_CONFIG()); | ||
|
||
ConfigHolder.CUSTOM_RECIPE_HOLDER.getRecipeManager().cleanAddNew(recipe); | ||
|
||
// Save recipe to file | ||
recipe.saveToFile(); | ||
|
||
return recipe; | ||
} | ||
|
||
|
||
@Override | ||
protected List<AnvilCustomRecipe> getEveryDisplayableInstanceOfGeneric() { | ||
return ConfigHolder.CUSTOM_RECIPE_HOLDER.getRecipeManager().getRecipeList(); | ||
} | ||
} |
Oops, something went wrong.