Add search button & goto page

Dieser Commit ist enthalten in:
Silent 2020-12-20 16:03:31 +01:00
Ursprung afc19f4321
Commit b7f550546f
4 geänderte Dateien mit 68 neuen und 4 gelöschten Zeilen

11
pom.xml
Datei anzeigen

@ -28,6 +28,11 @@
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
<!-- CodeMC -->
<repository>
<id>codemc-snapshots</id>
<url>https://repo.codemc.io/repository/maven-snapshots/</url>
</repository>
</repositories>
<dependencies>
@ -57,6 +62,12 @@
<artifactId>simplixstorage</artifactId>
<version>3.2.0</version>
</dependency>
<!-- AnvilGUI -->
<dependency>
<groupId>net.wesjd</groupId>
<artifactId>anvilgui</artifactId>
<version>1.4.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>

Datei anzeigen

@ -143,6 +143,13 @@ public class InventoryUtils {
"&8Click to view your favorites")
);
inventory.setItem(40, buildButton(
XMaterial.DARK_OAK_SIGN.parseItem(),
"&9Search",
"",
"&8Click to open search menu"
));
inventory.setItem(41, buildButton(
XMaterial.COMPASS.parseItem(),
"&aLocal",
@ -155,7 +162,7 @@ public class InventoryUtils {
public static void fill(Inventory inv, ItemStack item) {
int size = inv.getSize();
int[] ignored = new int[]{20, 21, 22, 23, 24, 29, 30, 31, 32, 33, 39, 41};
int[] ignored = new int[]{20, 21, 22, 23, 24, 29, 30, 31, 32, 33, 39, 40, 41};
// Fill
for (int i = 0; i < size; i++) {

Datei anzeigen

@ -1,15 +1,18 @@
package tsp.headdb.inventory;
import net.wesjd.anvilgui.AnvilGUI;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import tsp.headdb.HeadDB;
import tsp.headdb.api.HeadAPI;
import tsp.headdb.util.Utils;
import tsp.headdb.util.XMaterial;
@ -245,9 +248,38 @@ public class PagedPane implements InventoryHolder {
"&3&lPage &a&l%d &7/ &c&l%d",
getCurrentPage(), getPageAmount()
);
String lore = "&7Click to go to the &cMain Menu";
ItemStack itemStack = setMeta(HeadAPI.getHeadByValue("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvY2Q5MWY1MTI2NmVkZGM2MjA3ZjEyYWU4ZDdhNDljNWRiMDQxNWFkYTA0ZGFiOTJiYjc2ODZhZmRiMTdmNGQ0ZSJ9fX0=").getItemStack(), name, lore);
controlMain = new Button(itemStack, event -> InventoryUtils.openDatabase((Player) event.getWhoClicked()));
ItemStack itemStack = setMeta(HeadAPI.getHeadByValue("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvY2Q5MWY1MTI2NmVkZGM2MjA3ZjEyYWU4ZDdhNDljNWRiMDQxNWFkYTA0ZGFiOTJiYjc2ODZhZmRiMTdmNGQ0ZSJ9fX0=").getItemStack(),
name,
"&7Left-Click to go to the &cMain Menu",
"&7Right-Click to go to a &6Specific Page");
controlMain = new Button(itemStack, event -> {
if (event.getClick() == ClickType.RIGHT) {
new AnvilGUI.Builder()
.onComplete((player, text) -> {
try {
int i = Integer.parseInt(text);
if (i > getPageAmount()) {
Utils.sendMessage(player, "&cPage number is out of bounds! Max: &e" + getPageAmount());
return AnvilGUI.Response.text("&cOut of bounds!");
}
Bukkit.getScheduler().runTaskLater(HeadDB.getInstance(), () -> {
open(player);
selectPage(i - 1);
}, 40L);
return AnvilGUI.Response.close();
} catch (NumberFormatException nfe) {
Utils.sendMessage(player, "&cValue must be a number!");
return AnvilGUI.Response.text(Utils.colorize("&cValue must be a number!"));
}
})
.title("Select Page")
.text("Page number...")
.plugin(HeadDB.getInstance())
.open((Player) event.getWhoClicked());
} else {
InventoryUtils.openDatabase((Player) event.getWhoClicked());
}
});
inventory.setItem(inventory.getSize() - 5, itemStack);
}
}

Datei anzeigen

@ -1,5 +1,6 @@
package tsp.headdb.listener;
import net.wesjd.anvilgui.AnvilGUI;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@ -8,6 +9,7 @@ import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import tsp.headdb.HeadDB;
import tsp.headdb.database.Category;
import tsp.headdb.inventory.InventoryUtils;
import tsp.headdb.util.Utils;
@ -53,6 +55,18 @@ public class MenuListener implements Listener {
InventoryUtils.openLocalMenu(player);
return;
}
if (name.equalsIgnoreCase("search")) {
new AnvilGUI.Builder()
.onComplete((p, text) -> {
InventoryUtils.openSearchDatabase(p, text);
return AnvilGUI.Response.text(Utils.colorize("Searching for &e" + text));
})
.title("Search Heads")
.text("Name...")
.plugin(HeadDB.getInstance())
.open(player);
return;
}
Category category = Category.getByName(name);