3
0
Mirror von https://github.com/TheSilentPro/HeadDB.git synchronisiert 2024-12-27 11:20:05 +01:00
Dieser Commit ist enthalten in:
Silent 2022-11-13 14:57:55 +01:00
Ursprung 6f415e58ca
Commit 61c1c357eb
6 geänderte Dateien mit 35 neuen und 15 gelöschten Zeilen

Datei anzeigen

@ -15,7 +15,6 @@ import tsp.headdb.core.command.CommandTexture;
import tsp.headdb.core.command.CommandUpdate; import tsp.headdb.core.command.CommandUpdate;
import tsp.headdb.core.economy.BasicEconomyProvider; import tsp.headdb.core.economy.BasicEconomyProvider;
import tsp.headdb.core.economy.VaultProvider; import tsp.headdb.core.economy.VaultProvider;
import tsp.headdb.core.listener.PlayerJoinListener;
import tsp.headdb.core.storage.Storage; import tsp.headdb.core.storage.Storage;
import tsp.headdb.core.task.UpdateTask; import tsp.headdb.core.task.UpdateTask;

Datei anzeigen

@ -5,7 +5,6 @@ import org.bukkit.Material;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginCommand;
import org.bukkit.command.TabCompleter; import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -68,7 +67,7 @@ public class CommandMain extends HeadDBCommand implements CommandExecutor, TabCo
.onComplete((p, text) -> { .onComplete((p, text) -> {
try { try {
int page = Integer.parseInt(text); int page = Integer.parseInt(text);
// to be replaced with own version of anvilgui // to be replaced with own version of anvil-gui
List<Head> heads = HeadAPI.getHeads(category); List<Head> 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())); 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); Utils.addHeads(player, category, main, heads);
@ -88,10 +87,11 @@ public class CommandMain extends HeadDBCommand implements CommandExecutor, TabCo
} }
// Set meta buttons // 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 -> { 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); e.setCancelled(true);
List<Head> heads = HeadAPI.getFavoriteHeads(player.getUniqueId()); List<Head> 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) { for (Head head : heads) {
main.addButton(new Button(head.getItem(player.getUniqueId()), fe -> { main.addButton(new Button(head.getItem(player.getUniqueId()), fe -> {
if (fe.isLeftClick()) { if (fe.isLeftClick()) {
@ -101,6 +101,8 @@ public class CommandMain extends HeadDBCommand implements CommandExecutor, TabCo
} }
player.getInventory().addItem(favoriteItem); 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); 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 -> { 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); e.setCancelled(true);
new AnvilGUI.Builder() new AnvilGUI.Builder()
@ -143,6 +146,7 @@ public class CommandMain extends HeadDBCommand implements CommandExecutor, TabCo
.open(player); .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 -> { pane.setButton(getInstance().getConfig().getInt("gui.main.meta.local.slot"), new Button(Utils.getItemFromConfig("gui.main.meta.local.item", Material.COMPASS), e -> {
Set<LocalHead> localHeads = HeadAPI.getLocalHeads(); Set<LocalHead> localHeads = HeadAPI.getLocalHeads();
PagedPane localPane = Utils.createPaged(player, Utils.translateTitle(getLocalization().getMessage(player.getUniqueId(), "menu.main.local.name").orElse("Local Heads"), localHeads.size(), "Local")); PagedPane localPane = Utils.createPaged(player, Utils.translateTitle(getLocalization().getMessage(player.getUniqueId(), "menu.main.local.name").orElse("Local Heads"), localHeads.size(), "Local"));

Datei anzeigen

@ -26,15 +26,15 @@ public class CommandSettings extends SubCommand {
return; return;
} }
Set<String> langs = getLocalization().getData().keySet(); Set<String> languages = getLocalization().getData().keySet();
Pane pane = new Pane(1, StringUtils.colorize(getLocalization().getMessage(player.getUniqueId(), "menu.settings.name").orElse("&cHeadDB - Settings"))); 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) pane.addButton(new Button(new ItemBuilder(Material.BOOK)
.name(getLocalization().getMessage(player.getUniqueId(), "menu.settings.language.name").orElse("&cLanguage")) .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 -> { .build(), e -> {
e.setCancelled(true); 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")); 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 : langs) { for (String lang : languages) {
langPane.addButton(new Button(new ItemBuilder(Material.PAPER) langPane.addButton(new Button(new ItemBuilder(Material.PAPER)
.name(getLocalization().getMessage(player.getUniqueId(), "menu.settings.language.format").orElse(ChatColor.YELLOW + lang).replace("%language%", lang)) .name(getLocalization().getMessage(player.getUniqueId(), "menu.settings.language.format").orElse(ChatColor.YELLOW + lang).replace("%language%", lang))
.build(), langEvent -> { .build(), langEvent -> {

Datei anzeigen

@ -4,4 +4,9 @@ import java.io.Serializable;
import java.util.Set; import java.util.Set;
import java.util.UUID; 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<String> favorites) implements Serializable {} public record PlayerData(UUID uniqueId, Set<String> favorites) implements Serializable {}

Datei anzeigen

@ -9,6 +9,7 @@ import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.Set;
import java.util.UUID; import java.util.UUID;
public class PlayerStorage extends SerializableFileDataManager<HashSet<PlayerData>> { public class PlayerStorage extends SerializableFileDataManager<HashSet<PlayerData>> {
@ -23,6 +24,22 @@ public class PlayerStorage extends SerializableFileDataManager<HashSet<PlayerDat
this.players.put(data.uniqueId(), data); this.players.put(data.uniqueId(), data);
} }
public Set<String> getFavorites(UUID uuid) {
return players.containsKey(uuid) ? players.get(uuid).favorites() : new HashSet<>();
}
public void addFavorite(UUID uuid, String texture) {
Set<String> fav = getFavorites(uuid);
fav.add(texture);
players.put(uuid, new PlayerData(uuid, new HashSet<>(fav)));
}
public void removeFavorite(UUID uuid, String texture) {
Set<String> fav = getFavorites(uuid);
fav.remove(texture);
players.put(uuid, new PlayerData(uuid, new HashSet<>(fav)));
}
public Optional<PlayerData> get(UUID uuid) { public Optional<PlayerData> get(UUID uuid) {
return Optional.ofNullable(players.get(uuid)); return Optional.ofNullable(players.get(uuid));
} }

Datei anzeigen

@ -15,14 +15,11 @@ import tsp.headdb.core.api.HeadAPI;
import tsp.headdb.core.api.event.HeadPurchaseEvent; import tsp.headdb.core.api.event.HeadPurchaseEvent;
import tsp.headdb.core.economy.BasicEconomyProvider; import tsp.headdb.core.economy.BasicEconomyProvider;
import tsp.headdb.core.hook.Hooks; 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.category.Category;
import tsp.headdb.implementation.head.Head; import tsp.headdb.implementation.head.Head;
import tsp.smartplugin.inventory.Button; import tsp.smartplugin.inventory.Button;
import tsp.smartplugin.inventory.PagedPane; import tsp.smartplugin.inventory.PagedPane;
import tsp.smartplugin.inventory.Pane; import tsp.smartplugin.inventory.Pane;
import tsp.smartplugin.utils.InventoryUtils;
import tsp.smartplugin.utils.StringUtils; import tsp.smartplugin.utils.StringUtils;
import tsp.smartplugin.utils.Validate; import tsp.smartplugin.utils.Validate;
@ -31,11 +28,8 @@ import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault; import javax.annotation.ParametersAreNonnullByDefault;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Optional; import java.util.Optional;
@ -95,6 +89,7 @@ public class Utils {
} }
} }
@SuppressWarnings("SpellCheckingInspection")
public static PagedPane createPaged(Player player, String title) { public static PagedPane createPaged(Player player, String title) {
PagedPane main = new PagedPane(4, 6, title); PagedPane main = new PagedPane(4, 6, title);
HeadAPI.getHeadByTexture("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvODY1MmUyYjkzNmNhODAyNmJkMjg2NTFkN2M5ZjI4MTlkMmU5MjM2OTc3MzRkMThkZmRiMTM1NTBmOGZkYWQ1ZiJ9fX0=").ifPresent(head -> main.setBackItem(head.getItem(player.getUniqueId()))); HeadAPI.getHeadByTexture("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvODY1MmUyYjkzNmNhODAyNmJkMjg2NTFkN2M5ZjI4MTlkMmU5MjM2OTc3MzRkMThkZmRiMTM1NTBmOGZkYWQ1ZiJ9fX0=").ifPresent(head -> main.setBackItem(head.getItem(player.getUniqueId())));
@ -124,7 +119,7 @@ public class Utils {
purchase(player, head, amount); purchase(player, head, amount);
} else if (e.isRightClick()) { } 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());
} }
})); }));
} }