diff --git a/src/main/java/tsp/headdb/HeadDB.java b/src/main/java/tsp/headdb/HeadDB.java
index edab91c..0316dbc 100644
--- a/src/main/java/tsp/headdb/HeadDB.java
+++ b/src/main/java/tsp/headdb/HeadDB.java
@@ -15,7 +15,6 @@ import tsp.headdb.core.command.CommandTexture;
import tsp.headdb.core.command.CommandUpdate;
import tsp.headdb.core.economy.BasicEconomyProvider;
import tsp.headdb.core.economy.VaultProvider;
-import tsp.headdb.core.listener.PlayerJoinListener;
import tsp.headdb.core.storage.Storage;
import tsp.headdb.core.task.UpdateTask;
diff --git a/src/main/java/tsp/headdb/core/command/CommandMain.java b/src/main/java/tsp/headdb/core/command/CommandMain.java
index 0779911..ef07b94 100644
--- a/src/main/java/tsp/headdb/core/command/CommandMain.java
+++ b/src/main/java/tsp/headdb/core/command/CommandMain.java
@@ -5,7 +5,6 @@ import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
-import org.bukkit.command.PluginCommand;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@@ -68,7 +67,7 @@ public class CommandMain extends HeadDBCommand implements CommandExecutor, TabCo
.onComplete((p, text) -> {
try {
int page = Integer.parseInt(text);
- // to be replaced with own version of anvilgui
+ // to be replaced with own version of anvil-gui
List
heads = HeadAPI.getHeads(category);
PagedPane main = Utils.createPaged(player, Utils.translateTitle(getLocalization().getMessage(player.getUniqueId(), "menu.category.name").orElse(category.getName()), heads.size(), category.getName()));
Utils.addHeads(player, category, main, heads);
@@ -88,10 +87,11 @@ public class CommandMain extends HeadDBCommand implements CommandExecutor, TabCo
}
// Set meta buttons
+ // favorites
pane.setButton(getInstance().getConfig().getInt("gui.main.meta.favorites.slot"), new Button(Utils.getItemFromConfig("gui.main.meta.favorites.item", Material.BOOK), e -> {
e.setCancelled(true);
List heads = HeadAPI.getFavoriteHeads(player.getUniqueId());
- PagedPane main = Utils.createPaged(player, Utils.translateTitle(getLocalization().getMessage(player.getUniqueId(), "menu.main.favorites").orElse("Favorites"), heads.size(), "Favorites"));
+ PagedPane main = Utils.createPaged(player, Utils.translateTitle(getLocalization().getMessage(player.getUniqueId(), "menu.main.favorites.name").orElse("Favorites"), heads.size(), "Favorites"));
for (Head head : heads) {
main.addButton(new Button(head.getItem(player.getUniqueId()), fe -> {
if (fe.isLeftClick()) {
@@ -101,6 +101,8 @@ public class CommandMain extends HeadDBCommand implements CommandExecutor, TabCo
}
player.getInventory().addItem(favoriteItem);
+ } else if (fe.isRightClick()) {
+ HeadDB.getInstance().getStorage().getPlayerStorage().removeFavorite(player.getUniqueId(), head.getTexture());
}
}));
}
@@ -108,6 +110,7 @@ public class CommandMain extends HeadDBCommand implements CommandExecutor, TabCo
main.open(player);
}));
+ // search
pane.setButton(getInstance().getConfig().getInt("gui.main.meta.search.slot"), new Button(Utils.getItemFromConfig("gui.main.meta.search.item", Material.DARK_OAK_SIGN), e -> {
e.setCancelled(true);
new AnvilGUI.Builder()
@@ -143,6 +146,7 @@ public class CommandMain extends HeadDBCommand implements CommandExecutor, TabCo
.open(player);
}));
+ // local
pane.setButton(getInstance().getConfig().getInt("gui.main.meta.local.slot"), new Button(Utils.getItemFromConfig("gui.main.meta.local.item", Material.COMPASS), e -> {
Set localHeads = HeadAPI.getLocalHeads();
PagedPane localPane = Utils.createPaged(player, Utils.translateTitle(getLocalization().getMessage(player.getUniqueId(), "menu.main.local.name").orElse("Local Heads"), localHeads.size(), "Local"));
diff --git a/src/main/java/tsp/headdb/core/command/CommandSettings.java b/src/main/java/tsp/headdb/core/command/CommandSettings.java
index af3134e..5b36dc6 100644
--- a/src/main/java/tsp/headdb/core/command/CommandSettings.java
+++ b/src/main/java/tsp/headdb/core/command/CommandSettings.java
@@ -26,15 +26,15 @@ public class CommandSettings extends SubCommand {
return;
}
- Set langs = getLocalization().getData().keySet();
+ Set languages = getLocalization().getData().keySet();
Pane pane = new Pane(1, StringUtils.colorize(getLocalization().getMessage(player.getUniqueId(), "menu.settings.name").orElse("&cHeadDB - Settings")));
pane.addButton(new Button(new ItemBuilder(Material.BOOK)
.name(getLocalization().getMessage(player.getUniqueId(), "menu.settings.language.name").orElse("&cLanguage"))
- .setLore(getLocalization().getMessage(player.getUniqueId(), "menu.settings.language.available").orElse("&7Languages Available: &e%size%").replace("%size%", String.valueOf(langs.size())))
+ .setLore(getLocalization().getMessage(player.getUniqueId(), "menu.settings.language.available").orElse("&7Languages Available: &e%size%").replace("%size%", String.valueOf(languages.size())))
.build(), e -> {
e.setCancelled(true);
- PagedPane langPane = new PagedPane(4, 6, Utils.translateTitle(getLocalization().getMessage(player.getUniqueId(), "menu.settings.language.title").orElse("&cHeadDB &7- &eSelect Language").replace("%languages%", "%size%"), langs.size(), "Selector: Language"));
- for (String lang : langs) {
+ PagedPane langPane = new PagedPane(4, 6, Utils.translateTitle(getLocalization().getMessage(player.getUniqueId(), "menu.settings.language.title").orElse("&cHeadDB &7- &eSelect Language").replace("%languages%", "%size%"), languages.size(), "Selector: Language"));
+ for (String lang : languages) {
langPane.addButton(new Button(new ItemBuilder(Material.PAPER)
.name(getLocalization().getMessage(player.getUniqueId(), "menu.settings.language.format").orElse(ChatColor.YELLOW + lang).replace("%language%", lang))
.build(), langEvent -> {
diff --git a/src/main/java/tsp/headdb/core/storage/PlayerData.java b/src/main/java/tsp/headdb/core/storage/PlayerData.java
index 83953a5..5cdff12 100644
--- a/src/main/java/tsp/headdb/core/storage/PlayerData.java
+++ b/src/main/java/tsp/headdb/core/storage/PlayerData.java
@@ -4,4 +4,9 @@ import java.io.Serializable;
import java.util.Set;
import java.util.UUID;
+// Notice that there is no need to add any additional boilerplate in order to make this serializable.
+// Specifically, there is no need to add a serialVersionUID field,
+// since the serialVersionUID of a record class is 0L unless explicitly declared,
+// and the requirement for matching the serialVersionUID value is waived for record classes.
+// Source: https://docs.oracle.com/en/java/javase/15/serializable-records/index.html#:~:text=Specifically%2C%20there%20is%20no%20need,is%20waived%20for%20record%20classes.
public record PlayerData(UUID uniqueId, Set favorites) implements Serializable {}
\ No newline at end of file
diff --git a/src/main/java/tsp/headdb/core/storage/PlayerStorage.java b/src/main/java/tsp/headdb/core/storage/PlayerStorage.java
index 5004efd..3ad5ccc 100644
--- a/src/main/java/tsp/headdb/core/storage/PlayerStorage.java
+++ b/src/main/java/tsp/headdb/core/storage/PlayerStorage.java
@@ -9,6 +9,7 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Optional;
+import java.util.Set;
import java.util.UUID;
public class PlayerStorage extends SerializableFileDataManager> {
@@ -23,6 +24,22 @@ public class PlayerStorage extends SerializableFileDataManager getFavorites(UUID uuid) {
+ return players.containsKey(uuid) ? players.get(uuid).favorites() : new HashSet<>();
+ }
+
+ public void addFavorite(UUID uuid, String texture) {
+ Set fav = getFavorites(uuid);
+ fav.add(texture);
+ players.put(uuid, new PlayerData(uuid, new HashSet<>(fav)));
+ }
+
+ public void removeFavorite(UUID uuid, String texture) {
+ Set fav = getFavorites(uuid);
+ fav.remove(texture);
+ players.put(uuid, new PlayerData(uuid, new HashSet<>(fav)));
+ }
+
public Optional get(UUID uuid) {
return Optional.ofNullable(players.get(uuid));
}
diff --git a/src/main/java/tsp/headdb/core/util/Utils.java b/src/main/java/tsp/headdb/core/util/Utils.java
index 626431d..b65af22 100644
--- a/src/main/java/tsp/headdb/core/util/Utils.java
+++ b/src/main/java/tsp/headdb/core/util/Utils.java
@@ -15,14 +15,11 @@ import tsp.headdb.core.api.HeadAPI;
import tsp.headdb.core.api.event.HeadPurchaseEvent;
import tsp.headdb.core.economy.BasicEconomyProvider;
import tsp.headdb.core.hook.Hooks;
-import tsp.headdb.core.storage.PlayerData;
-import tsp.headdb.core.storage.PlayerStorage;
import tsp.headdb.implementation.category.Category;
import tsp.headdb.implementation.head.Head;
import tsp.smartplugin.inventory.Button;
import tsp.smartplugin.inventory.PagedPane;
import tsp.smartplugin.inventory.Pane;
-import tsp.smartplugin.utils.InventoryUtils;
import tsp.smartplugin.utils.StringUtils;
import tsp.smartplugin.utils.Validate;
@@ -31,11 +28,8 @@ import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import java.lang.reflect.Field;
import java.math.BigDecimal;
-import java.text.DecimalFormat;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collection;
-import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
@@ -95,6 +89,7 @@ public class Utils {
}
}
+ @SuppressWarnings("SpellCheckingInspection")
public static PagedPane createPaged(Player player, String title) {
PagedPane main = new PagedPane(4, 6, title);
HeadAPI.getHeadByTexture("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvODY1MmUyYjkzNmNhODAyNmJkMjg2NTFkN2M5ZjI4MTlkMmU5MjM2OTc3MzRkMThkZmRiMTM1NTBmOGZkYWQ1ZiJ9fX0=").ifPresent(head -> main.setBackItem(head.getItem(player.getUniqueId())));
@@ -124,7 +119,7 @@ public class Utils {
purchase(player, head, amount);
} else if (e.isRightClick()) {
- HeadDB.getInstance().getStorage().getPlayerStorage().get(player.getUniqueId()).orElse(new PlayerData(player.getUniqueId(), new HashSet<>())).favorites().add(head.getTexture());
+ HeadDB.getInstance().getStorage().getPlayerStorage().addFavorite(player.getUniqueId(), head.getTexture());
}
}));
}