Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions src/main/java/fr/maxlego08/menu/ZInventoryManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public class ZInventoryManager extends ZUtils implements InventoryManager {

private final Map<UUID, Integer> playerPages = new HashMap<>();
private final Map<UUID, Integer> playerMaxPages = new HashMap<>();
private final Map<String, Inventory> inventoryByName = new HashMap<>();

private final List<InventoryLoadRequirement> inventoryLoadRequirements = new ArrayList<>();

Expand Down Expand Up @@ -210,6 +211,7 @@ public Inventory loadInventory(Plugin plugin, File file, Class<? extends Invento
List<Inventory> inventories = this.inventories.getOrDefault(plugin.getName(), new ArrayList<>());
inventories.add(inventory);
this.inventories.put(plugin.getName(), inventories);
this.inventoryByName.put(inventory.getFileName().toLowerCase(), inventory);

if (Configuration.enableInformationMessage) {
Logger.info(file.getPath() + " loaded successfully !", LogType.INFO);
Expand Down Expand Up @@ -240,12 +242,7 @@ public Optional<Inventory> getInventory(String name) {
if (name == null) {
return Optional.empty();
}
for (Inventory inventory : this.getInventories()) {
if (inventory.getFileName().equalsIgnoreCase(name)) {
return Optional.of(inventory);
}
}
return Optional.empty();
return Optional.ofNullable(this.inventoryByName.get(name.toLowerCase()));
}

@Override
Expand Down Expand Up @@ -287,6 +284,7 @@ public void deleteInventory(Inventory inventory) {
List<Inventory> inventories = this.inventories.getOrDefault(pluginName, new ArrayList<>());
inventories.remove(inventory);
this.inventories.put(pluginName, inventories);
this.inventoryByName.remove(inventory.getFileName().toLowerCase());
}

@Override
Expand All @@ -301,7 +299,10 @@ public boolean deleteInventory(String name) {

@Override
public void deleteInventories(Plugin plugin) {
this.inventories.remove(plugin.getName());
List<Inventory> removed = this.inventories.remove(plugin.getName());
if (removed != null) {
removed.forEach(inv -> this.inventoryByName.remove(inv.getFileName().toLowerCase()));
}
}

@Override
Expand Down Expand Up @@ -474,6 +475,7 @@ public void loadInventories() {

this.playerMaxPages.clear();
this.playerPages.clear();
this.inventoryByName.clear();

File folder = new File(this.plugin.getDataFolder(), "inventories");
if (!folder.exists()) {
Expand Down
Loading