Changed favorites and latest pack to not display as queries.

This commit is contained in:
Brianna 2019-05-08 14:46:50 -04:00
parent 41b4fc0eb2
commit 64a79573ac
3 changed files with 34 additions and 11 deletions

View File

@ -1,8 +1,8 @@
package com.songoda.epicheads.gui;
import com.songoda.epicheads.EpicHeads;
import com.songoda.epicheads.head.Head;
import com.songoda.epicheads.head.Category;
import com.songoda.epicheads.head.Head;
import com.songoda.epicheads.players.EPlayer;
import com.songoda.epicheads.utils.AbstractChatConfirm;
import com.songoda.epicheads.utils.SettingsManager;
@ -32,11 +32,13 @@ public class GUIHeads extends AbstractGUI {
private int maxPage;
private String query;
private final QueryTypes type;
public GUIHeads(EpicHeads plugin, Player player, String query, List<Head> heads) {
public GUIHeads(EpicHeads plugin, Player player, String query, QueryTypes type, List<Head> heads) {
super(player);
this.plugin = plugin;
this.query = query;
this.type = type;
List<Integer> favorites = plugin.getPlayerManager().getPlayer(player).getFavorites();
this.heads = heads.stream()
@ -54,9 +56,25 @@ public class GUIHeads extends AbstractGUI {
}
Category category = heads.get(0).getCategory();
String name = null;
switch (type) {
case SEARCH:
name = plugin.getLocale().getMessage("general.word.query") + ": " + query;
break;
case CATEGORY:
name = category.getName();
break;
case FAVORITES:
name = plugin.getLocale().getMessage("general.word.favorites");
break;
case PACK:
name = plugin.getLocale().getMessage("general.phrase.latestpack");
break;
}
this.maxPage = (int) Math.floor(numHeads / 45.0);
init((query != null ? plugin.getLocale().getMessage("general.word.query") + ": " + query : category.getName())
+ " (" + numHeads + ") " + plugin.getLocale().getMessage("general.word.page") + " " + (page + 1) + "/" + (maxPage + 1), 54);
init(name + " (" + numHeads + ") " + plugin.getLocale().getMessage("general.word.page") + " " + (page + 1) + "/" + (maxPage + 1), 54);
constructGUI();
}
@ -220,7 +238,11 @@ public class GUIHeads extends AbstractGUI {
.filter(head -> head.getName().toLowerCase().contains(event.getMessage().toLowerCase()))
.collect(Collectors.toList());
Bukkit.getScheduler().scheduleSyncDelayedTask(EpicHeads.getInstance(), () ->
new GUIHeads(EpicHeads.getInstance(), player, event.getMessage(), heads), 0L);
new GUIHeads(EpicHeads.getInstance(), player, event.getMessage(), QueryTypes.SEARCH, heads), 0L);
});
}
public enum QueryTypes {
SEARCH, CATEGORY, FAVORITES, PACK
}
}

View File

@ -72,20 +72,20 @@ public class GUIOverview extends AbstractGUI {
if (!player.hasPermission("epicheads.category." + category.getName().replace(" ", "_"))) continue;
createButton(i + 10 + add, Methods.addTexture(new ItemStack(plugin.isServerVersionAtLeast(ServerVersion.V1_13)
? Material.PLAYER_HEAD : Material.valueOf("SKULL_ITEM"), 1, (byte) 3),
firstHead.getURL()),
? Material.PLAYER_HEAD : Material.valueOf("SKULL_ITEM"), 1, (byte) 3), firstHead.getURL()),
plugin.getLocale().getMessage("gui.overview.headname", Color.getRandomColor() + category.getName()),
category.isLatestPack() ? plugin.getLocale().getMessage("gui.overview.packlore", firstHead.getPack()) : plugin.getLocale().getMessage("gui.overview.headlore", String.format("%,d", category.getCount())));
category.isLatestPack() ? plugin.getLocale().getMessage("gui.overview.packlore", firstHead.getPack())
: plugin.getLocale().getMessage("gui.overview.headlore", String.format("%,d", category.getCount())));
registerClickable(i + 10 + add, ((player1, inventory1, cursor, slot, type) ->
new GUIHeads(plugin, player, category.isLatestPack() ? category.getName() : null, heads)));
new GUIHeads(plugin, player, category.isLatestPack() ? category.getName() : null,
category.isLatestPack() ? GUIHeads.QueryTypes.PACK : GUIHeads.QueryTypes.CATEGORY, heads)));
}
createButton(SettingsManager.Setting.DISCORD.getBoolean() ? 39 : 40, Material.COMPASS, plugin.getLocale().getMessage("gui.overview.search"));
if (SettingsManager.Setting.DISCORD.getBoolean()) {
ArrayList<String> lore2 = new ArrayList<>();
String[] parts2 = plugin.getLocale().getMessage("gui.overview.discordlore").split("\\|");
for (String line : parts2)
@ -102,7 +102,7 @@ public class GUIOverview extends AbstractGUI {
@Override
protected void registerClickables() {
registerClickable(4, ((player1, inventory1, cursor, slot, type) ->
new GUIHeads(plugin, player, plugin.getLocale().getMessage("general.word.favorites"),
new GUIHeads(plugin, player, null, GUIHeads.QueryTypes.FAVORITES,
plugin.getPlayerManager().getPlayer(player).getFavoritesAsHeads())));
registerClickable(SettingsManager.Setting.DISCORD.getBoolean() ? 39 : 40, ((player1, inventory1, cursor, slot, type) ->

View File

@ -4,6 +4,7 @@ general.nametag.prefix = "&7[&6EpicHeads&7]"
general.word.page = "Page"
general.word.query = "Query"
general.word.favorites = "Favorites"
general.phrase.latestpack = "Latest Pack"
general.search.global = "&6Enter your search query."
general.search.refine = "&6Enter a search term to refine your search.")