diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandcondense.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandcondense.java index 26f75d27d84..2d57bca12e5 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandcondense.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandcondense.java @@ -89,17 +89,27 @@ private boolean condenseStack(final User user, final ItemStack stack, final bool amount += contents.getAmount(); } } + + final int crafts = amount / input.getAmount(); + final int output = crafts * result.getAmount(); - final int output = (amount / input.getAmount()) * result.getAmount(); amount -= amount % input.getAmount(); if (amount > 0) { input.setAmount(amount); result.setAmount(output); + final Trade remove = new Trade(input, ess); final Trade add = new Trade(result, ess); + remove.charge(user); add.pay(user, OverflowType.DROP); + + for (final ItemStack remainingItem : condenseType.getRemainingItems()) { + remainingItem.setAmount(remainingItem.getAmount() * crafts); + new Trade(remainingItem, ess).pay(user, OverflowType.DROP); + } + return true; } } @@ -120,7 +130,8 @@ private SimpleRecipe getCondenseType(final ItemStack stack) { if (recipeItems != null && (recipeItems.size() == 4 || recipeItems.size() == 9) && (recipeItems.size() > recipe.getResult().getAmount())) { final ItemStack input = stack.clone(); input.setAmount(recipeItems.size()); - final SimpleRecipe newRecipe = new SimpleRecipe(recipe.getResult(), input); + final List remainingItems = getRemainingItems(stack, recipeItems.size()); + final SimpleRecipe newRecipe = new SimpleRecipe(recipe.getResult(), input, remainingItems); bestRecipes.add(newRecipe); } } @@ -187,10 +198,12 @@ protected List getTabCompleteOptions(final Server server, final User use private static final class SimpleRecipe implements Recipe { private final ItemStack result; private final ItemStack input; + private final List remainingItems; - private SimpleRecipe(final ItemStack result, final ItemStack input) { + private SimpleRecipe(final ItemStack result, final ItemStack input, final List remainingItems) { this.result = result; this.input = input; + this.remainingItems = remainingItems; } @Override @@ -201,6 +214,24 @@ public ItemStack getResult() { public ItemStack getInput() { return input.clone(); } + + public List getRemainingItems() { + final List clonedItems = new ArrayList<>(); + + for (final ItemStack item : remainingItems) { + clonedItems.add(item.clone()); + } + + return clonedItems; + } + } + + private List getRemainingItems(final ItemStack input, final int inputAmount) { + if (input.getType() == Material.HONEY_BOTTLE) { + return Collections.singletonList(new ItemStack(Material.GLASS_BOTTLE, inputAmount)); + } + + return Collections.emptyList(); } private static class SimpleRecipeComparator implements Comparator {