Remove player from search map if they dont insert anything in search

This commit is contained in:
SeanOMik 2020-04-08 16:49:44 -05:00
parent 7a0b9d6bcc
commit d230970b8d
No known key found for this signature in database
GPG Key ID: FA4D55AC05268A88
1 changed files with 26 additions and 20 deletions

View File

@ -86,8 +86,6 @@ public class ESTerminalGUI implements InventoryHolder, Listener {
Map<ItemStack, Integer> items = openSystem.getAllItems();
if (openSearches.containsKey(player.getUniqueId())) {
items = openSearches.get(player.getUniqueId());
player.sendMessage("Contains search");
}
for (int i = 10; i < 44; i++) {
@ -246,6 +244,7 @@ public class ESTerminalGUI implements InventoryHolder, Listener {
} else if (slot == 49) { // Search
new AnvilGUI.Builder()
.onComplete((plr, text) -> {
if (text != null && !text.isEmpty()) {
Map<ItemStack, Integer> items = openSystem.getAllItems();
Map<ItemStack, Integer> search = new HashMap<>();
for (Map.Entry<ItemStack, Integer> entry : items.entrySet()) {
@ -255,7 +254,7 @@ public class ESTerminalGUI implements InventoryHolder, Listener {
text = text.toLowerCase();
List<String> lore = itemMeta.getLore();
if (Utils.listStringContainsString(lore, text) || itemMeta.getDisplayName().toLowerCase().contains(text) || item.getType().toString().toLowerCase().contains(text)) {
if (Utils.listStringContainsString(lore, text) || itemMeta.getDisplayName().toLowerCase().contains(text) || item.getType().toString().toLowerCase().contains(text) || item.getType().toString().toLowerCase().replace("_", " ").contains(text)) {
search.put(item, amount);
}
}
@ -263,12 +262,19 @@ public class ESTerminalGUI implements InventoryHolder, Listener {
openSearches.put(plr.getUniqueId(), search);
Bukkit.getScheduler().runTaskLater(EnergeticStorage.getPlugin(), () -> {
openInventory(player, openSystem);
//initializeItems(player, openSystem);
openInventory(plr, openSystem);
}, (long) 0.5);
} else {
openSearches.remove(plr.getUniqueId());
Bukkit.getScheduler().runTaskLater(EnergeticStorage.getPlugin(), () -> {
openInventory(plr, openSystem);
}, (long) 0.5);
}
return AnvilGUI.Response.close();
}).text("Enter Item name")
})
.text("Enter Item name")
.item(new ItemStack(Material.PLAYER_HEAD))
.title("Search Terminal.")
.plugin(EnergeticStorage.getPlugin())