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,29 +244,37 @@ public class ESTerminalGUI implements InventoryHolder, Listener {
} else if (slot == 49) { // Search
new AnvilGUI.Builder()
.onComplete((plr, text) -> {
Map<ItemStack, Integer> items = openSystem.getAllItems();
Map<ItemStack, Integer> search = new HashMap<>();
for (Map.Entry<ItemStack, Integer> entry : items.entrySet()) {
ItemStack item = entry.getKey();
ItemMeta itemMeta = item.getItemMeta();
int amount = entry.getValue();
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()) {
ItemStack item = entry.getKey();
ItemMeta itemMeta = item.getItemMeta();
int amount = entry.getValue();
text = text.toLowerCase();
List<String> lore = itemMeta.getLore();
if (Utils.listStringContainsString(lore, text) || itemMeta.getDisplayName().toLowerCase().contains(text) || item.getType().toString().toLowerCase().contains(text)) {
search.put(item, amount);
text = text.toLowerCase();
List<String> lore = itemMeta.getLore();
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);
}
}
openSearches.put(plr.getUniqueId(), search);
Bukkit.getScheduler().runTaskLater(EnergeticStorage.getPlugin(), () -> {
openInventory(plr, openSystem);
}, (long) 0.5);
} else {
openSearches.remove(plr.getUniqueId());
Bukkit.getScheduler().runTaskLater(EnergeticStorage.getPlugin(), () -> {
openInventory(plr, openSystem);
}, (long) 0.5);
}
openSearches.put(plr.getUniqueId(), search);
Bukkit.getScheduler().runTaskLater(EnergeticStorage.getPlugin(), ()-> {
openInventory(player, openSystem);
//initializeItems(player, 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())