mirror of
https://github.com/songoda/EpicHeads.git
synced 2024-11-26 04:25:16 +01:00
Added latest pack option and changed from tags to category.
This commit is contained in:
parent
622dfc62a0
commit
41b4fc0eb2
@ -1,9 +1,9 @@
|
||||
package com.songoda.epicheads;
|
||||
|
||||
import com.songoda.epicheads.command.CommandManager;
|
||||
import com.songoda.epicheads.head.Category;
|
||||
import com.songoda.epicheads.head.Head;
|
||||
import com.songoda.epicheads.head.HeadManager;
|
||||
import com.songoda.epicheads.head.Tag;
|
||||
import com.songoda.epicheads.listeners.ItemListeners;
|
||||
import com.songoda.epicheads.listeners.LoginListeners;
|
||||
import com.songoda.epicheads.players.EPlayer;
|
||||
@ -159,6 +159,7 @@ public class EpicHeads extends JavaPlugin {
|
||||
private boolean loadHeads() {
|
||||
try {
|
||||
this.headManager.clear();
|
||||
this.headManager.addCategory(new Category("Latest Pack", true));
|
||||
|
||||
JSONParser parser = new JSONParser();
|
||||
JSONArray jsonArray = (JSONArray) parser.parse(new FileReader(getDataFolder() + "/heads.json"));
|
||||
@ -166,22 +167,23 @@ public class EpicHeads extends JavaPlugin {
|
||||
for (Object o : jsonArray) {
|
||||
JSONObject jsonObject = (JSONObject) o;
|
||||
|
||||
String tags = (String) jsonObject.get("tags");
|
||||
Optional<Tag> tagOptional = headManager.getTags().stream().filter(t -> t.getName().equalsIgnoreCase(tags)).findFirst();
|
||||
String categoryStr = (String) jsonObject.get("tags");
|
||||
Optional<Category> tagOptional = headManager.getTags().stream().filter(t -> t.getName().equalsIgnoreCase(categoryStr)).findFirst();
|
||||
|
||||
Tag tag = tagOptional.orElseGet(() -> new Tag(tags));
|
||||
Category category = tagOptional.orElseGet(() -> new Category(categoryStr));
|
||||
|
||||
Head head = new Head(Integer.parseInt((String) jsonObject.get("id")),
|
||||
(String) jsonObject.get("name"),
|
||||
(String) jsonObject.get("url"),
|
||||
tag,
|
||||
category,
|
||||
(String) jsonObject.get("pack"),
|
||||
Byte.parseByte((String) jsonObject.get("staff_picked")));
|
||||
|
||||
if (head.getName() == null ||
|
||||
head.getName().equals("null")) continue;
|
||||
if (head.getName() == null || head.getName().equals("null")
|
||||
|| head.getPack() != null && head.getPack().equals("null")) continue;
|
||||
|
||||
if (!tagOptional.isPresent())
|
||||
headManager.addTag(tag);
|
||||
headManager.addCategory(category);
|
||||
headManager.addHead(head);
|
||||
}
|
||||
|
||||
@ -189,19 +191,20 @@ public class EpicHeads extends JavaPlugin {
|
||||
for (StorageRow row : storage.getRowsByGroup("local")) {
|
||||
String tagStr = row.get("category").asString();
|
||||
|
||||
Optional<Tag> tagOptional = headManager.getTags().stream()
|
||||
Optional<Category> tagOptional = headManager.getTags().stream()
|
||||
.filter(t -> t.getName().equalsIgnoreCase(tagStr)).findFirst();
|
||||
|
||||
Tag tag = tagOptional.orElseGet(() -> new Tag(tagStr));
|
||||
Category category = tagOptional.orElseGet(() -> new Category(tagStr));
|
||||
|
||||
Head head = new Head(row.get("id").asInt(),
|
||||
row.get("name").asString(),
|
||||
row.get("url").asString(),
|
||||
tag,
|
||||
category,
|
||||
null,
|
||||
(byte) 0);
|
||||
|
||||
if (!tagOptional.isPresent())
|
||||
headManager.addTag(tag);
|
||||
headManager.addCategory(category);
|
||||
headManager.addLocalHead(head);
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ package com.songoda.epicheads.gui;
|
||||
|
||||
import com.songoda.epicheads.EpicHeads;
|
||||
import com.songoda.epicheads.head.Head;
|
||||
import com.songoda.epicheads.head.Tag;
|
||||
import com.songoda.epicheads.head.Category;
|
||||
import com.songoda.epicheads.players.EPlayer;
|
||||
import com.songoda.epicheads.utils.AbstractChatConfirm;
|
||||
import com.songoda.epicheads.utils.SettingsManager;
|
||||
@ -52,10 +52,10 @@ public class GUIHeads extends AbstractGUI {
|
||||
player.sendMessage(plugin.getReferences().getPrefix() + plugin.getLocale().getMessage("general.search.nonefound"));
|
||||
return;
|
||||
}
|
||||
Tag tag = heads.get(0).getTag();
|
||||
Category category = heads.get(0).getCategory();
|
||||
|
||||
this.maxPage = (int) Math.floor(numHeads / 45.0);
|
||||
init((query != null ? plugin.getLocale().getMessage("general.word.query") + ": " + query : tag.getName())
|
||||
init((query != null ? plugin.getLocale().getMessage("general.word.query") + ": " + query : category.getName())
|
||||
+ " (" + numHeads + ") " + plugin.getLocale().getMessage("general.word.page") + " " + (page + 1) + "/" + (maxPage + 1), 54);
|
||||
constructGUI();
|
||||
}
|
||||
|
@ -1,7 +1,8 @@
|
||||
package com.songoda.epicheads.gui;
|
||||
|
||||
import com.songoda.epicheads.EpicHeads;
|
||||
import com.songoda.epicheads.head.Tag;
|
||||
import com.songoda.epicheads.head.Category;
|
||||
import com.songoda.epicheads.head.Head;
|
||||
import com.songoda.epicheads.utils.Methods;
|
||||
import com.songoda.epicheads.utils.ServerVersion;
|
||||
import com.songoda.epicheads.utils.SettingsManager;
|
||||
@ -57,23 +58,27 @@ public class GUIOverview extends AbstractGUI {
|
||||
inventory.setItem(38, Methods.getBackgroundGlass(false));
|
||||
inventory.setItem(42, Methods.getBackgroundGlass(false));
|
||||
|
||||
List<Tag> tags = plugin.getHeadManager().getTags();
|
||||
List<Category> tags = plugin.getHeadManager().getTags();
|
||||
int add = 0;
|
||||
for (int i = 0; i < tags.size(); i++) {
|
||||
if (i + add == 7 || i + add == 16) add = add + 2;
|
||||
|
||||
Tag tag = plugin.getHeadManager().getTags().get(i);
|
||||
Category category = plugin.getHeadManager().getTags().get(i);
|
||||
|
||||
if (!player.hasPermission("epicheads.category." + tag.getName().replace(" ", "_"))) continue;
|
||||
List<Head> heads = category.isLatestPack() ? plugin.getHeadManager().getLatestPack() : plugin.getHeadManager().getHeadsByTag(category);
|
||||
|
||||
Head firstHead = heads.get(0);
|
||||
|
||||
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),
|
||||
plugin.getHeadManager().getHeadsByTag(tag).get(0).getURL()),
|
||||
plugin.getLocale().getMessage("gui.overview.headname", Color.getRandomColor() + tag.getName()),
|
||||
plugin.getLocale().getMessage("gui.overview.headlore", String.format("%,d", tag.getCount())));
|
||||
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())));
|
||||
|
||||
registerClickable(i + 10 + add, ((player1, inventory1, cursor, slot, type) ->
|
||||
new GUIHeads(plugin, player, null, plugin.getHeadManager().getHeadsByTag(tag))));
|
||||
new GUIHeads(plugin, player, category.isLatestPack() ? category.getName() : null, heads)));
|
||||
}
|
||||
|
||||
createButton(SettingsManager.Setting.DISCORD.getBoolean() ? 39 : 40, Material.COMPASS, plugin.getLocale().getMessage("gui.overview.search"));
|
||||
@ -92,7 +97,6 @@ public class GUIOverview extends AbstractGUI {
|
||||
plugin.getLocale().getMessage("gui.overview.discord"),
|
||||
lore2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
31
src/main/java/com/songoda/epicheads/head/Category.java
Normal file
31
src/main/java/com/songoda/epicheads/head/Category.java
Normal file
@ -0,0 +1,31 @@
|
||||
package com.songoda.epicheads.head;
|
||||
|
||||
import com.songoda.epicheads.EpicHeads;
|
||||
|
||||
public class Category {
|
||||
|
||||
private final String name;
|
||||
private boolean latestPack = false;
|
||||
|
||||
public Category(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Category(String name, boolean latestPack) {
|
||||
this.name = name;
|
||||
this.latestPack = latestPack;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public boolean isLatestPack() {
|
||||
return latestPack;
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return Math.toIntExact(EpicHeads.getInstance().getHeadManager()
|
||||
.getHeads().stream().filter(head -> head.getCategory() == this).count());
|
||||
}
|
||||
}
|
@ -11,21 +11,24 @@ import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class Head {
|
||||
|
||||
private final int id;
|
||||
private final String name;
|
||||
private final String URL;
|
||||
private final String pack;
|
||||
private final byte staffPicked;
|
||||
|
||||
private final Tag tag;
|
||||
private final Category category;
|
||||
|
||||
public Head(int id, String name, String URL, Tag tag, byte staffPicked) {
|
||||
public Head(int id, String name, String URL, Category category, String pack, byte staffPicked) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.URL = URL;
|
||||
this.tag = tag;
|
||||
this.category = category;
|
||||
this.pack = pack;
|
||||
this.staffPicked = staffPicked;
|
||||
}
|
||||
|
||||
@ -37,12 +40,14 @@ public class Head {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getPack() { return pack; }
|
||||
|
||||
public String getURL() {
|
||||
return URL;
|
||||
}
|
||||
|
||||
public Tag getTag() {
|
||||
return tag;
|
||||
public Category getCategory() {
|
||||
return category;
|
||||
}
|
||||
|
||||
public byte getStaffPicked() {
|
||||
@ -81,7 +86,8 @@ public class Head {
|
||||
+ "Id:\"" + id + "\","
|
||||
+ "Name:\"" + name + "\","
|
||||
+ "URL:\"" + URL + "\","
|
||||
+ "Tags:\"" + tag.getName() + "\","
|
||||
+ "Category:\"" + category.getName() + "\","
|
||||
+ "Pack:\"" + pack + "\","
|
||||
+ "StaffPicked:\"" + staffPicked + "\""
|
||||
+ "}";
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ public class HeadManager {
|
||||
|
||||
private static final Set<Head> registeredHeads = new HashSet<>();
|
||||
private static final List<Head> localRegisteredHeads = new ArrayList<>();
|
||||
private static final List<Tag> registeredTags = new ArrayList<>();
|
||||
private static final List<Category> registeredTags = new ArrayList<>();
|
||||
|
||||
public Head addHead(Head head) {
|
||||
registeredHeads.add(head);
|
||||
@ -43,17 +43,17 @@ public class HeadManager {
|
||||
List<Head> result = getHeads().stream().filter(head -> head.getName().contains(query)).collect(Collectors.toList());
|
||||
|
||||
if (result.isEmpty()) {
|
||||
for (Tag tag : registeredTags) {
|
||||
for (Category tag : registeredTags) {
|
||||
if (!tag.getName().equalsIgnoreCase(query)) continue;
|
||||
return getHeads().stream().filter(head -> head.getTag() == tag).collect(Collectors.toList());
|
||||
return getHeads().stream().filter(head -> head.getCategory() == tag).collect(Collectors.toList());
|
||||
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<Head> getHeadsByTag(Tag tag) {
|
||||
return getHeads().stream().filter(head -> head.getTag() == tag).collect(Collectors.toList());
|
||||
public List<Head> getHeadsByTag(Category tag) {
|
||||
return getHeads().stream().filter(head -> head.getCategory() == tag).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public List<Head> getHeads() {
|
||||
@ -76,16 +76,30 @@ public class HeadManager {
|
||||
return new ArrayList<>(registeredHeads);
|
||||
}
|
||||
|
||||
public List<Head> getLatestPack() {
|
||||
List<Head> heads = getHeads().stream().sorted(Comparator.comparingInt(Head::getId)).filter(head -> head.getPack() != null).collect(Collectors.toList());
|
||||
|
||||
Collections.reverse(heads);
|
||||
|
||||
if (heads.isEmpty()) return new ArrayList<>();
|
||||
|
||||
String latestPack = heads.get(0).getPack();
|
||||
|
||||
heads = heads.stream().filter(head -> head.getPack().equals(latestPack)).collect(Collectors.toList());
|
||||
|
||||
return heads;
|
||||
}
|
||||
|
||||
public void removeLocalHead(Head head) {
|
||||
localRegisteredHeads.remove(head);
|
||||
}
|
||||
|
||||
public Tag addTag(Tag tag) {
|
||||
registeredTags.add(tag);
|
||||
return tag;
|
||||
public Category addCategory(Category category) {
|
||||
registeredTags.add(category);
|
||||
return category;
|
||||
}
|
||||
|
||||
public List<Tag> getTags() {
|
||||
public List<Category> getTags() {
|
||||
return Collections.unmodifiableList(registeredTags);
|
||||
}
|
||||
|
||||
|
@ -1,21 +0,0 @@
|
||||
package com.songoda.epicheads.head;
|
||||
|
||||
import com.songoda.epicheads.EpicHeads;
|
||||
|
||||
public class Tag {
|
||||
|
||||
private final String name;
|
||||
|
||||
public Tag(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return Math.toIntExact(EpicHeads.getInstance().getHeadManager()
|
||||
.getHeads().stream().filter(head -> head.getTag() == this).count());
|
||||
}
|
||||
}
|
@ -3,7 +3,7 @@ package com.songoda.epicheads.listeners;
|
||||
import com.songoda.epicheads.EpicHeads;
|
||||
import com.songoda.epicheads.head.Head;
|
||||
import com.songoda.epicheads.head.HeadManager;
|
||||
import com.songoda.epicheads.head.Tag;
|
||||
import com.songoda.epicheads.head.Category;
|
||||
import com.songoda.epicheads.utils.Methods;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -32,13 +32,13 @@ public class LoginListeners implements Listener {
|
||||
|
||||
String tagStr = "Player Heads";
|
||||
|
||||
Optional<Tag> tagOptional = headManager.getTags()
|
||||
Optional<Category> tagOptional = headManager.getTags()
|
||||
.stream().filter(t -> t.getName().equalsIgnoreCase(tagStr)).findFirst();
|
||||
|
||||
Tag tag = tagOptional.orElseGet(() -> new Tag(tagStr));
|
||||
Category tag = tagOptional.orElseGet(() -> new Category(tagStr));
|
||||
|
||||
if (!tagOptional.isPresent())
|
||||
headManager.addTag(tag);
|
||||
headManager.addCategory(tag);
|
||||
|
||||
Optional<Head> optional = headManager.getLocalHeads().stream()
|
||||
.filter(h -> h.getName().equalsIgnoreCase(event.getPlayer().getName())).findFirst();
|
||||
@ -51,7 +51,7 @@ public class LoginListeners implements Listener {
|
||||
headManager.removeLocalHead(head);
|
||||
}
|
||||
|
||||
headManager.addLocalHeads(new Head(id, player.getName(), url, tag, (byte) 0));
|
||||
headManager.addLocalHeads(new Head(id, player.getName(), url, tag, null, (byte) 0));
|
||||
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,7 @@ public abstract class Storage {
|
||||
prepareSaveItem("local", new StorageItem("url", head.getURL()),
|
||||
new StorageItem("name", head.getName()),
|
||||
new StorageItem("id", head.getId()),
|
||||
new StorageItem("category", head.getTag().getName()));
|
||||
new StorageItem("category", head.getCategory().getName()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,7 @@ gui.overview.title = "EpicHeads (%count% heads)"
|
||||
gui.overview.search = "&a&lSearch"
|
||||
gui.overview.headname = "&c&l%name%"
|
||||
gui.overview.headlore = "&e%count% heads"
|
||||
gui.overview.packlore = "&e%pack%"
|
||||
gui.overview.viewfavorites = "&6&lView Favorites"
|
||||
gui.overview.favoriteslore = "&8Shift click any head|&8to save as a favorite."
|
||||
gui.overview.discord = "&9&lDiscord"
|
||||
|
Loading…
Reference in New Issue
Block a user