mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2024-12-22 04:37:42 +01:00
!Code cleanup for station options.
This commit is contained in:
parent
00c28dd750
commit
3ed33ac172
@ -16,7 +16,6 @@ import net.mmogroup.mmolib.api.util.SmartGive;
|
||||
|
||||
public class CraftingRecipe extends Recipe {
|
||||
private final ConfigMMOItem output;
|
||||
private final boolean itemRecipe, silent;
|
||||
|
||||
/*
|
||||
* there can't be any crafting time for upgrading recipes since there is no way
|
||||
@ -28,8 +27,6 @@ public class CraftingRecipe extends Recipe {
|
||||
super(config);
|
||||
|
||||
craftingTime = config.getDouble("crafting-time");
|
||||
itemRecipe = config.getBoolean("options.output-item", true);
|
||||
silent = config.getBoolean("options.silent-craft");
|
||||
|
||||
/*
|
||||
* load recipe output
|
||||
@ -45,18 +42,6 @@ public class CraftingRecipe extends Recipe {
|
||||
return craftingTime <= 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* this determines whether or not to give an item whenever an item is crafted
|
||||
* yaml format is 'output-item: false' under options
|
||||
*/
|
||||
public boolean isItemRecipe() {
|
||||
return itemRecipe;
|
||||
}
|
||||
|
||||
public boolean isSilent() {
|
||||
return silent;
|
||||
}
|
||||
|
||||
public ConfigMMOItem getOutput() {
|
||||
return output;
|
||||
}
|
||||
@ -68,10 +53,10 @@ public class CraftingRecipe extends Recipe {
|
||||
* directly add the ingredients to the player inventory
|
||||
*/
|
||||
if (isInstant()) {
|
||||
if (isItemRecipe())
|
||||
if (getOption(RecipeOption.OUTPUT_ITEM))
|
||||
new SmartGive(data.getPlayer()).give(getOutput().generate());
|
||||
recipe.getRecipe().getTriggers().forEach(trigger -> trigger.whenCrafting(data));
|
||||
if (!isSilent())
|
||||
if (!getOption(RecipeOption.SILENT_CRAFT))
|
||||
data.getPlayer().playSound(data.getPlayer().getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 1);
|
||||
/*
|
||||
* if recipe not instant, add item to crafting queue, either way RELOAD
|
||||
|
@ -145,16 +145,20 @@ public abstract class Recipe {
|
||||
public abstract ItemStack display(RecipeInfo recipe);
|
||||
|
||||
public enum RecipeOption {
|
||||
HIDE_WHEN_LOCKED;
|
||||
HIDE_WHEN_LOCKED,
|
||||
OUTPUT_ITEM,
|
||||
SILENT_CRAFT;
|
||||
|
||||
private final boolean def;
|
||||
|
||||
private RecipeOption() {
|
||||
this(false);
|
||||
}
|
||||
|
||||
private RecipeOption(boolean def) {
|
||||
this.def = def;
|
||||
// this stores the defaults of the enums
|
||||
HashMap<String, Boolean> defaultMap = new HashMap<String, Boolean>() {{
|
||||
put("HIDE_WHEN_LOCKED", false);
|
||||
put("OUTPUT_ITEM", true);
|
||||
put("SILENT_CRAFT", false);
|
||||
}};
|
||||
this.def = defaultMap.get(this.toString());
|
||||
}
|
||||
|
||||
public boolean getDefault() {
|
||||
|
@ -3,6 +3,7 @@ package net.Indyuce.mmoitems.gui;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import net.Indyuce.mmoitems.api.crafting.recipe.Recipe;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Sound;
|
||||
@ -185,9 +186,9 @@ public class CraftingStationView extends PluginInventory {
|
||||
recipe.getTriggers().forEach(trigger -> trigger.whenCrafting(data));
|
||||
ItemStack craftedItem = recipe.getOutput().generate();
|
||||
CustomSoundListener.stationCrafting(craftedItem, data.getPlayer());
|
||||
if (!recipe.isSilent())
|
||||
if (!recipe.getOption(Recipe.RecipeOption.SILENT_CRAFT))
|
||||
data.getPlayer().playSound(data.getPlayer().getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 1);
|
||||
if (recipe.isItemRecipe())
|
||||
if (recipe.getOption(Recipe.RecipeOption.OUTPUT_ITEM))
|
||||
new SmartGive(data.getPlayer()).give(craftedItem);
|
||||
}
|
||||
else {
|
||||
|
Loading…
Reference in New Issue
Block a user