This commit is contained in:
Jules 2020-07-30 09:47:11 +02:00
commit 9727bacb5c
3 changed files with 30 additions and 8 deletions

View File

@ -17,6 +17,8 @@ import net.mmogroup.mmolib.api.util.SmartGive;
public class CraftingRecipe extends Recipe {
private final ConfigMMOItem output;
private final ConfigurationSection config;
/*
* there can't be any crafting time for upgrading recipes since there is no
* way to save an MMOItem in the config file TODO save as ItemStack
@ -25,6 +27,7 @@ public class CraftingRecipe extends Recipe {
public CraftingRecipe(ConfigurationSection config) {
super(config);
this.config = config;
craftingTime = config.getDouble("crafting-time");
@ -42,6 +45,18 @@ 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 config.getBoolean("options.output-item", true);
}
public boolean isSilent() {
return config.getBoolean("options.silent-craft", false);
}
public ConfigMMOItem getOutput() {
return output;
}
@ -53,9 +68,11 @@ public class CraftingRecipe extends Recipe {
* directly add the ingredients to the player inventory
*/
if (isInstant()) {
new SmartGive(data.getPlayer()).give(getOutput().generate());
if (isItemRecipe())
new SmartGive(data.getPlayer()).give(getOutput().generate());
recipe.getRecipe().getTriggers().forEach(trigger -> trigger.whenCrafting(data));
if (!isSilent())
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 inventory data and reopen inventory!
@ -63,7 +80,8 @@ public class CraftingRecipe extends Recipe {
} else
data.getCrafting().getQueue(station).add(this);
data.getPlayer().playSound(data.getPlayer().getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 1);
if (!isInstant())
data.getPlayer().playSound(data.getPlayer().getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 1);
}
@Override

View File

@ -12,7 +12,7 @@ public class CommandTrigger extends Trigger {
super("command");
config.validate("format");
player = config.getBoolean("player");
player = config.getBoolean("player", false);
command = config.getString("format");
}

View File

@ -178,8 +178,6 @@ public class CraftingStationView extends PluginInventory {
if (!(tag = item.getString("queueId")).equals("")) {
UUID uuid = UUID.fromString(tag);
CraftingInfo craft = data.getCrafting().getQueue(station).getCraft(uuid);
data.getPlayer().playSound(data.getPlayer().getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 1);
data.getCrafting().getQueue(station).remove(craft);
if (craft.isReady()) {
@ -187,10 +185,16 @@ public class CraftingStationView extends PluginInventory {
recipe.getTriggers().forEach(trigger -> trigger.whenCrafting(data));
ItemStack craftedItem = recipe.getOutput().generate();
CustomSoundListener.stationCrafting(craftedItem, data.getPlayer());
new SmartGive(data.getPlayer()).give(craftedItem);
} else
if (!recipe.isSilent())
data.getPlayer().playSound(data.getPlayer().getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 1);
if (recipe.isItemRecipe())
new SmartGive(data.getPlayer()).give(craftedItem);
}
else {
data.getPlayer().playSound(data.getPlayer().getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 1);
for (Ingredient ingredient : craft.getRecipe().getIngredients())
new SmartGive(data.getPlayer()).give(ingredient.generateItemStack());
}
updateData();
open();