!Code cleanup for station options.

This commit is contained in:
Ethan 2020-08-03 05:38:58 -04:00
parent 00c28dd750
commit 3ed33ac172
3 changed files with 15 additions and 25 deletions

View File

@ -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

View File

@ -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() {

View File

@ -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 {