Remove player from search map if they dont insert anything in search
This commit is contained in:
parent
7a0b9d6bcc
commit
d230970b8d
|
@ -86,8 +86,6 @@ public class ESTerminalGUI implements InventoryHolder, Listener {
|
||||||
Map<ItemStack, Integer> items = openSystem.getAllItems();
|
Map<ItemStack, Integer> items = openSystem.getAllItems();
|
||||||
if (openSearches.containsKey(player.getUniqueId())) {
|
if (openSearches.containsKey(player.getUniqueId())) {
|
||||||
items = openSearches.get(player.getUniqueId());
|
items = openSearches.get(player.getUniqueId());
|
||||||
|
|
||||||
player.sendMessage("Contains search");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 10; i < 44; i++) {
|
for (int i = 10; i < 44; i++) {
|
||||||
|
@ -246,29 +244,37 @@ public class ESTerminalGUI implements InventoryHolder, Listener {
|
||||||
} else if (slot == 49) { // Search
|
} else if (slot == 49) { // Search
|
||||||
new AnvilGUI.Builder()
|
new AnvilGUI.Builder()
|
||||||
.onComplete((plr, text) -> {
|
.onComplete((plr, text) -> {
|
||||||
Map<ItemStack, Integer> items = openSystem.getAllItems();
|
if (text != null && !text.isEmpty()) {
|
||||||
Map<ItemStack, Integer> search = new HashMap<>();
|
Map<ItemStack, Integer> items = openSystem.getAllItems();
|
||||||
for (Map.Entry<ItemStack, Integer> entry : items.entrySet()) {
|
Map<ItemStack, Integer> search = new HashMap<>();
|
||||||
ItemStack item = entry.getKey();
|
for (Map.Entry<ItemStack, Integer> entry : items.entrySet()) {
|
||||||
ItemMeta itemMeta = item.getItemMeta();
|
ItemStack item = entry.getKey();
|
||||||
int amount = entry.getValue();
|
ItemMeta itemMeta = item.getItemMeta();
|
||||||
|
int amount = entry.getValue();
|
||||||
|
|
||||||
text = text.toLowerCase();
|
text = text.toLowerCase();
|
||||||
List<String> lore = itemMeta.getLore();
|
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);
|
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();
|
return AnvilGUI.Response.close();
|
||||||
}).text("Enter Item name")
|
})
|
||||||
|
.text("Enter Item name")
|
||||||
.item(new ItemStack(Material.PLAYER_HEAD))
|
.item(new ItemStack(Material.PLAYER_HEAD))
|
||||||
.title("Search Terminal.")
|
.title("Search Terminal.")
|
||||||
.plugin(EnergeticStorage.getPlugin())
|
.plugin(EnergeticStorage.getPlugin())
|
||||||
|
|
Loading…
Reference in New Issue