Skip to content

Commit

Permalink
Add go back button menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Over2Craft-mc committed Aug 18, 2021
1 parent ec47860 commit dc5b941
Show file tree
Hide file tree
Showing 8 changed files with 170 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import co.aikar.commands.BaseCommand;
import co.aikar.commands.annotation.*;
import fr.quentin.searchquickshop.Menu.SmartInv;
import fr.quentin.searchquickshop.Menu.InventoriesBuilder;
import fr.quentin.searchquickshop.SearchQuickShop;
import fr.quentin.searchquickshop.Shop.ShopFilters;
import org.bukkit.Bukkit;
Expand All @@ -17,7 +17,7 @@ public class ShopCommands extends BaseCommand {
@Syntax("/shop-search")
@CommandPermission("searchquickshop.command.default")
public static void listAll(Player player) {
SmartInv.getItemInventory(ShopFilters.allItems()).open(player);
InventoriesBuilder.getItemInventory(ShopFilters.allItems()).open(player);
}

@Subcommand("joueur")
Expand All @@ -39,7 +39,7 @@ public static void searchItemsForAPlayer(Player player, String[] args) {
return;
}

SmartInv.getItemInventory(ShopFilters.allItems().filterByPlayer(offlinePlayer.getUniqueId())).open(player);
InventoriesBuilder.getItemInventory(ShopFilters.allItems().filterByPlayer(offlinePlayer.getUniqueId())).open(player);
}

@Subcommand("item")
Expand All @@ -50,7 +50,7 @@ public static void searchItemsForAPlayer(Player player, String[] args) {
public static void searchItem(Player player, String[] args) {

if (args.length == 1) {
SmartInv.getItemInventory(ShopFilters.allItems().filterLikeItem(args[0])).open(player);
InventoriesBuilder.getItemInventory(ShopFilters.allItems().filterLikeItem(args[0])).open(player);
return;
}
listAll(player);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package fr.quentin.searchquickshop.Menu;

import fr.minuskube.inv.ClickableItem;
import fr.minuskube.inv.content.InventoryProvider;
import fr.quentin.searchquickshop.Menu.utils.ItemStackUtils;
import org.bukkit.Material;
import org.bukkit.entity.Player;

public abstract class AbstractPreviousInventory implements InventoryProvider, InventoryBuilderProviderInterface {

private final InventoryProvider previousInventory;

public AbstractPreviousInventory(InventoryProvider previousInventory) {
this.previousInventory = previousInventory;
}

public InventoryProvider getPreviousInventory() {
return previousInventory;
}

public boolean hasPreviousInventory() {
return previousInventory != null;
}

public ClickableItem getItemPreviousInventory() {

if (!hasPreviousInventory()) {
throw new NullPointerException("Can't an item to go back to previous Inventory if there is no previous inventory.");
}

return ItemStackUtils.clickableItemWithItem(
e -> ((InventoryBuilderProviderInterface) getPreviousInventory()).getBuilder(previousInventory).open((Player) e.getWhoClicked()),
Material.ARROW,
"Retour"
);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package fr.quentin.searchquickshop.Menu.Inventories;

import fr.minuskube.inv.SmartInventory;
import fr.minuskube.inv.content.InventoryContents;
import fr.minuskube.inv.content.InventoryProvider;
import fr.quentin.searchquickshop.Configuration.Config;
import fr.quentin.searchquickshop.Menu.AbstractPreviousInventory;
import fr.quentin.searchquickshop.Menu.InventoriesBuilder;
import fr.quentin.searchquickshop.Menu.InventoryBuilderProviderInterface;
import fr.quentin.searchquickshop.Menu.utils.ItemStackUtils;
import fr.quentin.searchquickshop.Shop.ShopFilters;
import org.bukkit.entity.Player;


public class CategoriesInventoryAbstract extends AbstractPreviousInventory implements InventoryProvider, InventoryBuilderProviderInterface {

private final Config config;

public CategoriesInventoryAbstract(Config config) {
super(null);
this.config = config;
}

public CategoriesInventoryAbstract(Config config, InventoryProvider previousInventory) {
super(previousInventory);
this.config = config;
}

@Override
public void init(Player player, InventoryContents contents) {

config.getCategories().forEach(category -> contents.set(
category.getPositionRow(), category.getPositionColumn(),
ItemStackUtils.clickableItemWithItem(
e -> InventoriesBuilder.getItemInventory(ShopFilters.allItems().filterCategory(category.getName()), this).open(player),
category.getIcon(),
category.getName(),
category.getLore()
)));

if (this.hasPreviousInventory()) {
contents.set(5, 0, this.getItemPreviousInventory());
}
}

@Override
public void update(Player player, InventoryContents contents) {

}

@Override
public SmartInventory getBuilder(InventoryProvider inventoryProvider) {
return SmartInventory.builder()
.provider(inventoryProvider)
.size(6, 9)
.title("Shops")
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package fr.quentin.searchquickshop.Menu;
package fr.quentin.searchquickshop.Menu.Inventories;

import fr.minuskube.inv.ClickableItem;
import fr.minuskube.inv.SmartInventory;
import fr.minuskube.inv.content.InventoryContents;
import fr.minuskube.inv.content.InventoryProvider;
import fr.minuskube.inv.content.Pagination;
import fr.minuskube.inv.content.SlotIterator;
import fr.quentin.searchquickshop.Configuration.Config;
import fr.quentin.searchquickshop.Menu.AbstractPreviousInventory;
import fr.quentin.searchquickshop.Menu.InventoriesBuilder;
import fr.quentin.searchquickshop.Menu.InventoryBuilderProviderInterface;
import fr.quentin.searchquickshop.Menu.utils.ItemStackUtils;
import fr.quentin.searchquickshop.SearchQuickShop;
import fr.quentin.searchquickshop.Shop.ShopFilters;
Expand All @@ -19,13 +23,20 @@
import java.util.ArrayList;
import java.util.List;

public class ShopsInventory implements InventoryProvider {
public class ShopsInventoryAbstract extends AbstractPreviousInventory implements InventoryProvider, InventoryBuilderProviderInterface {

private final ShopFilters filters;

private final Config config;

public ShopsInventory(ShopFilters filters) {
public ShopsInventoryAbstract(ShopFilters filters) {
super(null);
this.filters = filters;
this.config = SearchQuickShop.getPluginConfig();
}

public ShopsInventoryAbstract(ShopFilters filters, InventoryProvider previousInventory) {
super(previousInventory);
this.filters = filters;
this.config = SearchQuickShop.getPluginConfig();
}
Expand Down Expand Up @@ -64,19 +75,29 @@ public void init(Player player, InventoryContents contents) {
pagination.addToIterator(contents.newIterator(SlotIterator.Type.HORIZONTAL, 0, 0));

contents.set(5, 3, ClickableItem.of(ItemStackUtils.createItem(Material.ARROW, "Page précédente"),
e -> SmartInv.getItemInventory(filters).open(player, pagination.previous().getPage())));
e -> InventoriesBuilder.getItemInventory(filters).open(player, pagination.previous().getPage())));

contents.set(5, 4, ClickableItem.of(ItemStackUtils.createItem(Material.PAPER, "Voir les catégorie"),
e -> SmartInv.getCategoryInventory(config).open(player)));
e -> InventoriesBuilder.getCategoryInventory(config, this).open(player)));

contents.set(5, 5, ClickableItem.of(ItemStackUtils.createItem(Material.ARROW, "Page suivante"),
e -> SmartInv.getItemInventory(filters).open(player, pagination.next().getPage())));
e -> InventoriesBuilder.getItemInventory(filters).open(player, pagination.next().getPage())));

if (this.hasPreviousInventory()) {
contents.set(5, 0, this.getItemPreviousInventory());
}

}

@Override
public void update(Player player, InventoryContents contents) {}



@Override
public SmartInventory getBuilder(InventoryProvider inventoryProvider) {
return SmartInventory.builder()
.provider(inventoryProvider)
.size(6, 9)
.title("Shops")
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package fr.quentin.searchquickshop.Menu;

import fr.minuskube.inv.SmartInventory;
import fr.minuskube.inv.content.InventoryProvider;
import fr.quentin.searchquickshop.Configuration.Config;
import fr.quentin.searchquickshop.Menu.Inventories.CategoriesInventoryAbstract;
import fr.quentin.searchquickshop.Menu.Inventories.ShopsInventoryAbstract;
import fr.quentin.searchquickshop.Shop.ShopFilters;

public class InventoriesBuilder {

public static SmartInventory getItemInventory(ShopFilters shopFilters, InventoryProvider previousInventory) {
InventoryBuilderProviderInterface inventoryProvider = new ShopsInventoryAbstract(shopFilters, previousInventory);
return inventoryProvider.getBuilder((InventoryProvider) inventoryProvider);
}

public static SmartInventory getItemInventory(ShopFilters shopFilters) {
return getItemInventory(shopFilters, null);
}

public static SmartInventory getCategoryInventory(Config config, InventoryProvider previousInventory) {
InventoryBuilderProviderInterface inventoryProvider = new CategoriesInventoryAbstract(config, previousInventory);
return inventoryProvider.getBuilder((InventoryProvider) inventoryProvider);
}

public static SmartInventory getCategoryInventory(Config config) {
return getCategoryInventory(config, null);
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package fr.quentin.searchquickshop.Menu;

import fr.minuskube.inv.SmartInventory;
import fr.minuskube.inv.content.InventoryProvider;

public interface InventoryBuilderProviderInterface {

SmartInventory getBuilder(InventoryProvider inventoryProvider);

}
26 changes: 0 additions & 26 deletions src/main/java/fr/quentin/searchquickshop/Menu/SmartInv.java

This file was deleted.

0 comments on commit dc5b941

Please sign in to comment.