<repo_name>Lacratus/MarketPlugin<file_sep>/src/main/java/be/lacratus/market/objects/DDGPlayer.java
package be.lacratus.market.objects;


import java.util.ArrayList;
import java.util.List;
import java.util.PriorityQueue;
import java.util.UUID;

public class DDGPlayer {

    private UUID uuid;
    private PriorityQueue<AuctionItem> personalItems;
    private boolean isBidding;
    private AuctionItem bidAuctionItem;
    private List<AuctionItem> biddenItems;

    public DDGPlayer(UUID uuid) {
        this.uuid = uuid;
        this.personalItems = new PriorityQueue<>();
        this.biddenItems = new ArrayList<>();
    }

    public UUID getUuid() {
        return uuid;
    }

    public PriorityQueue<AuctionItem> getPersonalItems() {
        return personalItems;
    }


    public boolean isBidding() {
        return isBidding;
    }

    public void setBidding(boolean bidding) {
        isBidding = bidding;
    }

    public AuctionItem getBidAuctionItem() {
        return bidAuctionItem;
    }

    public void setBidAuctionItem(AuctionItem bidAuctionItem) {
        this.bidAuctionItem = bidAuctionItem;
    }

    public List<AuctionItem> getBiddenItems() {
        return biddenItems;
    }


}
<file_sep>/src/main/java/be/lacratus/market/commands/MoneyCommand.java
package be.lacratus.market.commands;

import be.lacratus.market.Market;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class MoneyCommand implements CommandExecutor {

    Market main;

    public MoneyCommand(Market market) {
        this.main = market;
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {

        if (!(sender instanceof Player)) {
            sender.sendMessage("You have to be a player");
            return false;
        }

        if (args.length == 0) {
            OfflinePlayer player = (OfflinePlayer) sender;
            sender.sendMessage(main.getEconomyImplementer().getBalance(player) + "");
            return true;
        }
        if (args.length == 1) {
            try {
                Player player = Bukkit.getPlayer(args[0]);
                double balance = main.getEconomyImplementer().getBalance(player);
                sender.sendMessage(balance + "");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return false;
    }
}
<file_sep>/src/main/java/be/lacratus/market/listeners/OnJoinListener.java
package be.lacratus.market.listeners;

import be.lacratus.market.Market;
import be.lacratus.market.data.StoredDataHandler;
import be.lacratus.market.objects.DDGPlayer;
import be.lacratus.market.objects.AuctionItem;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

public class OnJoinListener implements Listener {

    private Market main;
    private StoredDataHandler storedDataHandler;

    public OnJoinListener(Market main) {
        this.main = main;
        this.storedDataHandler = main.getStoredDataHandler();
    }

    @EventHandler
    public void onJoin(PlayerJoinEvent event) {
        Player player = event.getPlayer();
        UUID uuid = player.getUniqueId();
        if (main.getEconomyImplementer().createPlayerAccount(player)) {
            System.out.println("Account created");
        } else {
            System.out.println("Account already existed");
        }

        //Fill onlinePlayers

        //Check if player gets item back
        DDGPlayer ddgPlayer;
        List<AuctionItem> auctionItems;
        if (main.getPlayersWithItems().containsKey(uuid)) {
            ddgPlayer = main.getPlayersWithItems().get(uuid);
            auctionItems = new ArrayList<>(main.getPlayersWithItems().get(uuid).getBiddenItems());
            for (AuctionItem item : auctionItems) {
                long timeLeft = item.getTimeOfDeletion() - (System.currentTimeMillis() / 1000);
                if (timeLeft < 0) {
                    player.getInventory().setItem(player.getInventory().firstEmpty(), item.getItemStack());
                    main.getPlayersWithBiddings().get(uuid).getBiddenItems().remove(item);
                    main.getItemsRemoveDatabase().add(item);
                }
            }
            main.getOnlinePlayers().put(uuid, ddgPlayer);
            main.updateLists(ddgPlayer);

        } else if (main.getPlayersWithBiddings().containsKey(uuid)) {
            ddgPlayer = main.getPlayersWithBiddings().get(uuid);
            auctionItems = new ArrayList<>(main.getPlayersWithBiddings().get(uuid).getBiddenItems());
            for (AuctionItem item : auctionItems) {
                long timeLeft = item.getTimeOfDeletion() - (System.currentTimeMillis() / 1000);
                if (timeLeft < 0) {
                    player.sendMessage("You are getting a item from the auction, get some inventory space");
                    main.giveItemWhenInventoryFull(item, ddgPlayer, 30);
                    main.getPlayersWithBiddings().get(uuid).getBiddenItems().remove(item);
                }
            }
            main.getOnlinePlayers().put(uuid, ddgPlayer);
            main.updateLists(ddgPlayer);
        } else {
            storedDataHandler.loadData(uuid).thenAccept(DDGspeler ->
                    main.getOnlinePlayers().put(uuid, DDGspeler)).exceptionally(throwable -> {
                throwable.printStackTrace();
                return null;
            });
        }
    }
}
<file_sep>/src/main/java/be/lacratus/market/util/ItemStackSerializer.java
package be.lacratus.market.util;

import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
import org.bukkit.inventory.meta.ItemMeta;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

public class ItemStackSerializer {
    @SuppressWarnings("deprecation")
    public static String ItemStackToString(ItemStack itemStack) {
        String serialization = null;

        if (itemStack != null) {
            StringBuilder serializedItemStack = new StringBuilder();

            String itemStackType = String.valueOf(itemStack.getType().getId());
            serializedItemStack.append("Item@").append(itemStackType);

            if (itemStack.getDurability() != 0) {
                String itemStackDurability = String.valueOf(itemStack.getDurability());
                serializedItemStack.append(":d@").append(itemStackDurability);
            }

            if (itemStack.getAmount() != 1) {
                String itemStackAmount = String.valueOf(itemStack.getAmount());
                serializedItemStack.append(":a@").append(itemStackAmount);
            }

            if (itemStack.getItemMeta().getDisplayName() != null) {
                String itemStackName = itemStack.getItemMeta().getDisplayName();
                serializedItemStack.append(":n@").append(itemStackName);
            }

            Map<Enchantment, Integer> itemStackEnch = itemStack.getEnchantments();
            if (itemStackEnch.size() > 0) {
                for (Entry<Enchantment, Integer> ench : itemStackEnch.entrySet()) {
                    serializedItemStack.append(":e@").append(ench.getKey().getId()).append("@").append(ench.getValue());
                }
            }

            List<String> lores = itemStack.getItemMeta().getLore();
            if (lores != null && lores.size() > 0) {
                for (String lore : lores) {
                    serializedItemStack.append(":l@").append(lore);
                }
            }


            if (itemStack.getType() == Material.ENCHANTED_BOOK) {
                EnchantmentStorageMeta bookmeta = (EnchantmentStorageMeta) itemStack.getItemMeta();
                Map<Enchantment, Integer> enchantments = bookmeta.getStoredEnchants();
                if (enchantments.size() > 0) {
                    for (Entry<Enchantment, Integer> bookenchants : enchantments.entrySet()) {
                        serializedItemStack.append(":m@").append(bookenchants.getKey().getId()).append("@").append(bookenchants.getValue());
                    }
                }
            }

            serialization = serializedItemStack.toString();
        }
        return serialization;
    }

    @SuppressWarnings("deprecation")
    public static ItemStack StringToItemStack(String serializedItem) {
        ItemStack itemStack = null;
        boolean createdItemStack = false;
        String[] serializedItemStack = serializedItem.split(":");
        for (String itemInfo : serializedItemStack) {
            String[] itemAttribute = itemInfo.split("@");
            if (itemAttribute[0].equals("Item")) {
                itemStack = new ItemStack(Material.getMaterial(Integer.parseInt(itemAttribute[1])));
                createdItemStack = true;
            } else if (itemAttribute[0].equals("d") && createdItemStack) {
                itemStack.setDurability(Short.parseShort(itemAttribute[1]));
            } else if (itemAttribute[0].equals("a") && createdItemStack) {
                itemStack.setAmount(Integer.parseInt(itemAttribute[1]));
            } else if (itemAttribute[0].equals("e") && createdItemStack) {
                itemStack.addEnchantment(Enchantment.getById(Integer.parseInt(itemAttribute[1])), Integer.parseInt(itemAttribute[2]));
            } else if (itemAttribute[0].equals("n") && createdItemStack) {
                ItemMeta itemMeta = itemStack.getItemMeta();
                itemMeta.setDisplayName(itemAttribute[1]);
                itemStack.setItemMeta(itemMeta);
            } else if (itemAttribute[0].equals("l") && createdItemStack) {
                ItemMeta itemMeta = itemStack.getItemMeta();
                List<String> lores = new ArrayList<>();
                lores.add(itemAttribute[1]);
                itemMeta.setLore(lores);
                itemStack.setItemMeta(itemMeta);

            } else if (itemAttribute[0].equals("m") && createdItemStack) {
                EnchantmentStorageMeta itemStackMeta = (EnchantmentStorageMeta) itemStack.getItemMeta();
                itemStackMeta.addStoredEnchant(Enchantment.getById(Integer.parseInt(itemAttribute[1])), Integer.parseInt(itemAttribute[2]), true);
                itemStack.setItemMeta(itemStackMeta);
            }
        }
        return itemStack;
    }
}<file_sep>/src/main/java/be/lacratus/market/util/AuctionHouse.java
package be.lacratus.market.util;

import be.lacratus.market.objects.AuctionItem;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

import java.util.ArrayList;
import java.util.List;
import java.util.PriorityQueue;

import java.util.concurrent.TimeUnit;

public class AuctionHouse {


    public AuctionHouse() {

    }

    public static void openAuctionHouse(Player player, PriorityQueue<AuctionItem> allItems, int page, String title) {
        ArrayList<AuctionItem> items = new ArrayList<>(allItems);
        if (title.equals("AuctionHouse")) {
            items.sort(new SortByIndexAscending());
        } else if (title.equals("Personal")) {
            items.sort(new SortByIndexDescending());
        }
        Inventory auctionHouse = Bukkit.createInventory(null, 54, title);

        //Get to previous page if possible
        ItemStack previousPage;
        ItemMeta previousMeta;
        if (PageUtil.isPageValid(allItems, page - 1, 45)) {
            previousPage = new ItemStack(Material.STAINED_GLASS, 1, (short) 5);
        } else {
            previousPage = new ItemStack(Material.STAINED_GLASS, 1, (short) 14);
        }
        previousMeta = previousPage.getItemMeta();
        previousMeta.setDisplayName(ChatColor.GREEN + "PREVIOUS PAGE");
        previousMeta.setLocalizedName(page + "");
        previousPage.setItemMeta(previousMeta);

        auctionHouse.setItem(45, previousPage);
        //Get to next page if possible
        ItemStack nextPage;
        ItemMeta nextMeta;
        if (PageUtil.isPageValid(allItems, page + 1, 45)) {
            nextPage = new ItemStack(Material.STAINED_GLASS, 1, (short) 5);
        } else {
            nextPage = new ItemStack(Material.STAINED_GLASS, 1, (short) 14);
        }
        nextMeta = nextPage.getItemMeta();
        nextMeta.setDisplayName(ChatColor.GREEN + "NEXT PAGE");
        nextPage.setItemMeta(nextMeta);

        auctionHouse.setItem(53, nextPage);
        // Fill up AuctionHouse and add lores
        for (AuctionItem item : PageUtil.getPageItems(items, page, 45)) {
            //Get Itemstack
            ItemStack itemstack = item.getItemStack();
            ItemMeta itemMeta = itemstack.getItemMeta();
            //Create lore
            List<String> lores = itemMeta.getLore();
            lores.add("Bid: " + item.getHighestOffer() + "€");
            long timeLeft = item.getTimeOfDeletion() - System.currentTimeMillis() / 1000;
            long[] timeList = onlineTimeToLong(timeLeft);
            lores.add("Hours: " + timeList[0] + ", Minutes: " + timeList[1] + ", Seconds: " + timeList[2]);
            itemMeta.setLore(lores);
            itemstack.setItemMeta(itemMeta);
            //Set Item
            auctionHouse.setItem(auctionHouse.firstEmpty(), item.getItemStack());
        }
        player.openInventory(auctionHouse);

        // Remove lores
        for (AuctionItem item : PageUtil.getPageItems(items, page, 45)) {
            // Get Itemstack
            ItemStack itemstack = item.getItemStack();
            ItemMeta itemMeta = itemstack.getItemMeta();
            // Remove Auction lore
            List<String> lores = itemMeta.getLore();
            lores.remove(lores.size() - 1);
            lores.remove(lores.size() - 1);
            itemMeta.setLore(lores);
            itemstack.setItemMeta(itemMeta);
        }
    }

    public static long[] onlineTimeToLong(long timeInSeconds) {
        long hours = TimeUnit.SECONDS.toHours(timeInSeconds);
        timeInSeconds -= TimeUnit.HOURS.toSeconds(hours);
        long minutes = TimeUnit.SECONDS.toMinutes(timeInSeconds);
        timeInSeconds -= TimeUnit.MINUTES.toSeconds(minutes);
        long seconds = TimeUnit.SECONDS.toSeconds(timeInSeconds);
        return new long[]{hours, minutes, seconds};
    }
}



