mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2025-02-25 15:11:20 +01:00
Fixed a severe dupe bug with c. stations
This commit is contained in:
parent
6df659d04c
commit
bea250c612
@ -4,37 +4,34 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import net.Indyuce.mmoitems.MMOUtils;
|
||||
import net.Indyuce.mmoitems.api.crafting.CraftingStation;
|
||||
import net.Indyuce.mmoitems.api.crafting.ingredient.Ingredient.CheckedIngredient;
|
||||
import net.Indyuce.mmoitems.api.crafting.recipe.CraftingRecipe;
|
||||
import net.Indyuce.mmoitems.api.crafting.recipe.RecipeInfo;
|
||||
import net.Indyuce.mmoitems.api.crafting.recipe.UpgradingRecipe;
|
||||
import net.Indyuce.mmoitems.api.item.plugin.ConfigItem;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
|
||||
public class CraftingStationPreview extends PluginInventory {
|
||||
private final int previousPage;
|
||||
private final CraftingStation station;
|
||||
private final CraftingStationView previous;
|
||||
private final RecipeInfo recipe;
|
||||
|
||||
private List<CheckedIngredient> ingredients = new ArrayList<>();
|
||||
private final List<CheckedIngredient> ingredients = new ArrayList<>();
|
||||
|
||||
private static final int[] slots = { 12, 13, 14, 21, 22, 23, 30, 31, 32 }, fill = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 15, 17, 18, 19, 25, 26, 27, 29, 33, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44 };
|
||||
private static final int[] slots = { 12, 13, 14, 21, 22, 23, 30, 31, 32 },
|
||||
fill = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 15, 17, 18, 19, 25, 26, 27, 29, 33, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44 };
|
||||
|
||||
public CraftingStationPreview(Player player, CraftingStation station, RecipeInfo recipe, int previousPage) {
|
||||
super(player);
|
||||
public CraftingStationPreview(CraftingStationView previous, RecipeInfo recipe) {
|
||||
super(previous.getPlayer());
|
||||
|
||||
this.previousPage = previousPage;
|
||||
this.station = station;
|
||||
this.previous = previous;
|
||||
this.recipe = recipe;
|
||||
}
|
||||
|
||||
@ -47,7 +44,7 @@ public class CraftingStationPreview extends PluginInventory {
|
||||
int min = (page - 1) * slots.length, max = page * slots.length;
|
||||
for (int j = min; j < max; j++) {
|
||||
if (j >= ingredients.size()) {
|
||||
if (station.getItemOptions().hasNoRecipe())
|
||||
if (previous.getStation().getItemOptions().hasNoRecipe())
|
||||
inv.setItem(slots[j - min], null);
|
||||
continue;
|
||||
}
|
||||
@ -99,9 +96,8 @@ public class CraftingStationPreview extends PluginInventory {
|
||||
return;
|
||||
|
||||
if (MMOUtils.areSimilar(event.getCurrentItem(), ConfigItem.CONFIRM.getItem())) {
|
||||
CraftingStationView csv = new CraftingStationView(player, station, previousPage);
|
||||
csv.processRecipe(recipe);
|
||||
csv.open();
|
||||
previous.processRecipe(recipe);
|
||||
previous.open();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -117,9 +113,7 @@ public class CraftingStationPreview extends PluginInventory {
|
||||
return;
|
||||
}
|
||||
|
||||
if (MMOUtils.areSimilar(event.getCurrentItem(), ConfigItem.BACK.getItem())) {
|
||||
new CraftingStationView(player, station, previousPage).open();
|
||||
return;
|
||||
}
|
||||
if (MMOUtils.areSimilar(event.getCurrentItem(), ConfigItem.BACK.getItem()))
|
||||
previous.open();
|
||||
}
|
||||
}
|
||||
|
@ -39,7 +39,8 @@ public class CraftingStationView extends PluginInventory {
|
||||
private int queueOffset;
|
||||
|
||||
private static final int[] slots = { 10, 11, 12, 13, 14, 15, 16, 19, 20, 21, 22, 23, 24, 25 }, queueSlots = { 38, 39, 40, 41, 42 };
|
||||
private static final int[] fill = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 17, 18, 26, 27, 35, 36, 37, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 28, 29, 30, 31, 32, 33, 34 };
|
||||
private static final int[] fill = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 17, 18, 26, 27, 35, 36, 37, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 28, 29,
|
||||
30, 31, 32, 33, 34 };
|
||||
|
||||
public CraftingStationView(Player player, CraftingStation station) {
|
||||
this(player, station, 1);
|
||||
@ -55,7 +56,11 @@ public class CraftingStationView extends PluginInventory {
|
||||
updateData();
|
||||
}
|
||||
|
||||
private void updateData() {
|
||||
public CraftingStation getStation() {
|
||||
return station;
|
||||
}
|
||||
|
||||
void updateData() {
|
||||
ingredients = new IngredientInventory(player);
|
||||
recipes = station.getAvailableRecipes(data, ingredients);
|
||||
}
|
||||
@ -114,7 +119,8 @@ public class CraftingStationView extends PluginInventory {
|
||||
|
||||
for (int j = queueOffset; j < queueOffset + queueSlots.length; j++)
|
||||
if (j >= queue.getCrafts().size())
|
||||
inv.setItem(queueSlots[j - queueOffset], station.getItemOptions().hasNoQueueItem() ? station.getItemOptions().getNoQueueItem() : null);
|
||||
inv.setItem(queueSlots[j - queueOffset],
|
||||
station.getItemOptions().hasNoQueueItem() ? station.getItemOptions().getNoQueueItem() : null);
|
||||
else
|
||||
inv.setItem(queueSlots[j - queueOffset], ConfigItem.QUEUE_ITEM_DISPLAY.newBuilder(queue.getCrafts().get(j), j + 1).build());
|
||||
}
|
||||
@ -160,13 +166,11 @@ public class CraftingStationView extends PluginInventory {
|
||||
if (!tag.equals("")) {
|
||||
RecipeInfo recipe = getRecipe(tag);
|
||||
if (event.isRightClick()) {
|
||||
new CraftingStationPreview(player, station, recipe, page).open();
|
||||
new CraftingStationPreview(this, recipe).open();
|
||||
return;
|
||||
}
|
||||
|
||||
processRecipe(recipe);
|
||||
|
||||
updateData();
|
||||
open();
|
||||
}
|
||||
|
||||
@ -192,7 +196,6 @@ public class CraftingStationView extends PluginInventory {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void processRecipe(RecipeInfo recipe) {
|
||||
if (!recipe.areConditionsMet()) {
|
||||
Message.CONDITIONS_NOT_MET.format(ChatColor.RED).send(player);
|
||||
@ -217,6 +220,8 @@ public class CraftingStationView extends PluginInventory {
|
||||
recipe.getRecipe().whenUsed(data, ingredients, recipe, station);
|
||||
recipe.getIngredients().forEach(ingredient -> ingredient.getPlayerIngredient().reduceItem(ingredient.getIngredient().getAmount()));
|
||||
recipe.getConditions().forEach(condition -> condition.getCondition().whenCrafting(data));
|
||||
|
||||
updateData();
|
||||
}
|
||||
|
||||
private RecipeInfo getRecipe(String id) {
|
||||
|
@ -11,8 +11,9 @@ import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.api.Type;
|
||||
|
||||
public abstract class PluginInventory implements InventoryHolder {
|
||||
protected final Player player;
|
||||
|
||||
protected int page = 1;
|
||||
protected Player player;
|
||||
|
||||
public PluginInventory(Player player) {
|
||||
this(player, null, null, null);
|
||||
|
Loading…
Reference in New Issue
Block a user