Search in sources :

Example 26 with User

use of com.Ben12345rocks.VotingPlugin.Objects.User in project VotingPlugin by Ben12345rocks.

the class PlayerGUIs method openVoteToday.

public void openVoteToday(Player player) {
    setSelectedPlayer(player, null);
    BInventory inv = new BInventory(Config.getInstance().getGUIVoteTodayName());
    for (User user : plugin.voteToday.keySet()) {
        for (VoteSite voteSite : plugin.voteToday.get(user).keySet()) {
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern(Config.getInstance().getFormatTimeFormat());
            String timeString = plugin.voteToday.get(user).get(voteSite).format(formatter);
            String msg = "&6" + user.getPlayerName() + " : " + voteSite.getDisplayName() + " : " + timeString;
            inv.addButton(inv.getNextSlot(), new BInventoryButton(user.getPlayerName(), new String[] { msg }, MiscUtils.getInstance().setSkullOwner(user.getOfflinePlayer())) {

                @Override
                public void onClick(ClickEvent clickEvent) {
                    User user = UserManager.getInstance().getVotingPluginUser(clickEvent.getClickedItem().getItemMeta().getDisplayName());
                    openVoteGUI(player, user);
                }
            });
        }
    }
    if (Config.getInstance().getGUIVoteTodayBackButton()) {
        inv.addButton(new BInventoryButton(getBackButton()) {

            @Override
            public void onClick(ClickEvent event) {
                openVoteGUI(event.getPlayer(), getSelectedPlayer(event.getPlayer()));
            }
        });
    }
    inv.openInventory(player);
}
Also used : VoteSite(com.Ben12345rocks.VotingPlugin.Objects.VoteSite) User(com.Ben12345rocks.VotingPlugin.Objects.User) BInventoryButton(com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventoryButton) ClickEvent(com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventory.ClickEvent) BInventory(com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventory) DateTimeFormatter(java.time.format.DateTimeFormatter)

Example 27 with User

use of com.Ben12345rocks.VotingPlugin.Objects.User in project VotingPlugin by Ben12345rocks.

the class Main method convertDataStorage.

public void convertDataStorage(UserStorage from, UserStorage to) {
    if (from == null || to == null) {
        throw new RuntimeException("Invalid Storage Method");
    }
    UserStorage cur = AdvancedCoreHook.getInstance().getStorageType();
    AdvancedCoreHook.getInstance().setStorageType(from);
    AdvancedCoreHook.getInstance().reload();
    HashMap<User, HashMap<String, String>> data = new HashMap<User, HashMap<String, String>>();
    for (String uuid : UserManager.getInstance().getAllUUIDs()) {
        try {
            User user = UserManager.getInstance().getVotingPluginUser(new UUID(uuid));
            HashMap<String, String> values = new HashMap<String, String>();
            for (String key : user.getData().getKeys()) {
                values.put(key, user.getData().getString(key));
            }
            data.put(user, values);
            debug("[Convert] Added " + uuid);
        } catch (Exception e) {
            AdvancedCoreHook.getInstance().debug(e);
            plugin.getLogger().warning("Exception occoured for '" + uuid + "': " + e.getMessage() + ", turn debug on to see full stack traces");
        }
    }
    plugin.getLogger().info("Finished getting data from " + from.toString());
    AdvancedCoreHook.getInstance().setStorageType(to);
    AdvancedCoreHook.getInstance().reload();
    for (Entry<User, HashMap<String, String>> entry : data.entrySet()) {
        try {
            for (Entry<String, String> values : entry.getValue().entrySet()) {
                entry.getKey().getData().setString(values.getKey(), values.getValue());
            }
        } catch (Exception e) {
            e.printStackTrace();
            plugin.getLogger().warning("Exception occoured for '" + entry.getKey().getUUID() + "': " + e.getMessage() + ", turn debug on to see full stack traces");
        }
    }
    AdvancedCoreHook.getInstance().setStorageType(cur);
    AdvancedCoreHook.getInstance().reload();
    plugin.getLogger().info("Finished convertting");
}
Also used : User(com.Ben12345rocks.VotingPlugin.Objects.User) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) UserStorage(com.Ben12345rocks.AdvancedCore.Objects.UserStorage) UUID(com.Ben12345rocks.AdvancedCore.Objects.UUID) IOException(java.io.IOException)

Example 28 with User

use of com.Ben12345rocks.VotingPlugin.Objects.User in project VotingPlugin by Ben12345rocks.

the class Main method update.

/**
 * Update.
 */
public void update() {
    if (update && plugin != null && !updateStarted) {
        updateStarted = true;
        update = false;
        synchronized (plugin) {
            if (AdvancedCoreHook.getInstance().getStorageType().equals(UserStorage.MYSQL)) {
                if (AdvancedCoreHook.getInstance().getMysql() == null) {
                    plugin.debug("MySQL not loaded yet");
                    return;
                } else if (Config.getInstance().getClearCacheOnUpdate()) {
                    AdvancedCoreHook.getInstance().getMysql().clearCache();
                } else {
                    AdvancedCoreHook.getInstance().getMysql().clearCacheBasic();
                }
            }
            plugin.debug("Starting background task");
            long time = System.currentTimeMillis();
            try {
                ArrayList<String> uuids = UserManager.getInstance().getAllUUIDs();
                ArrayList<User> users = new ArrayList<User>();
                for (String uuid : uuids) {
                    if (uuid != null && !uuid.isEmpty()) {
                        User user = UserManager.getInstance().getVotingPluginUser(new UUID(uuid));
                        users.add(user);
                    // AdvancedCoreHook.getInstance().extraDebug("Loading " + uuid);
                    // java.lang.Thread.sleep(5000);
                    }
                }
                update = false;
                long time1 = ((System.currentTimeMillis() - time) / 1000);
                plugin.debug("Finished loading player data in " + time1 + " seconds, " + users.size() + " users");
                TopVoterHandler.getInstance().updateTopVoters(users);
                Commands.getInstance().updateVoteToday(users);
                ServerData.getInstance().updateValues();
                Signs.getInstance().updateSigns();
                for (Player player : Bukkit.getOnlinePlayers()) {
                    UserManager.getInstance().getVotingPluginUser(player).offVote();
                }
                time1 = ((System.currentTimeMillis() - time) / 1000);
                plugin.debug("Background task finished in " + time1 + " seconds");
            } catch (Exception ex) {
                ex.printStackTrace();
                plugin.getLogger().info("Looks like something went wrong.");
            }
        }
        updateStarted = false;
    }
}
Also used : Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) User(com.Ben12345rocks.VotingPlugin.Objects.User) ArrayList(java.util.ArrayList) UUID(com.Ben12345rocks.AdvancedCore.Objects.UUID) IOException(java.io.IOException)

Example 29 with User

use of com.Ben12345rocks.VotingPlugin.Objects.User in project VotingPlugin by Ben12345rocks.

the class TopVoterHandler method storeDailyTopVoters.

public void storeDailyTopVoters() {
    LocalDateTime time = LocalDateTime.now().minusHours(5);
    String month = time.getMonth().toString();
    int year = time.getYear();
    int day = time.getDayOfMonth();
    YMLFileHandler file = new YMLFileHandler(new File(plugin.getDataFolder(), "TopVoter" + File.separator + "Daily" + File.separator + year + "_" + month + "_" + day + ".yml"));
    file.setup();
    ArrayList<String> topVoters = new ArrayList<String>();
    int count = 1;
    for (Entry<User, Integer> entry : plugin.topVoterDaily.entrySet()) {
        topVoters.add(count + ": " + entry.getKey().getPlayerName() + ": " + entry.getValue());
        count++;
    }
    file.getData().set("Day", topVoters);
    file.saveData();
}
Also used : LocalDateTime(java.time.LocalDateTime) User(com.Ben12345rocks.VotingPlugin.Objects.User) YMLFileHandler(com.Ben12345rocks.AdvancedCore.YML.YMLFileHandler) ArrayList(java.util.ArrayList) File(java.io.File)

Example 30 with User

use of com.Ben12345rocks.VotingPlugin.Objects.User in project VotingPlugin by Ben12345rocks.

the class TopVoterHandler method storeMonthlyTopVoters.

public void storeMonthlyTopVoters() {
    LocalDateTime time = LocalDateTime.now().minusHours(10);
    String month = time.getMonth().toString();
    int year = time.getYear();
    YMLFileHandler file = new YMLFileHandler(new File(plugin.getDataFolder(), "TopVoter" + File.separator + "Monthly" + File.separator + month + "_" + year + ".yml"));
    file.setup();
    ArrayList<String> topVoters = new ArrayList<String>();
    int count = 1;
    for (Entry<User, Integer> entry : plugin.topVoterMonthly.entrySet()) {
        topVoters.add(count + ": " + entry.getKey().getPlayerName() + ": " + entry.getValue());
        count++;
    }
    file.getData().set("Month", topVoters);
    file.saveData();
}
Also used : LocalDateTime(java.time.LocalDateTime) User(com.Ben12345rocks.VotingPlugin.Objects.User) YMLFileHandler(com.Ben12345rocks.AdvancedCore.YML.YMLFileHandler) ArrayList(java.util.ArrayList) File(java.io.File)

Aggregations

User (com.Ben12345rocks.VotingPlugin.Objects.User)32 ArrayList (java.util.ArrayList)12 UUID (com.Ben12345rocks.AdvancedCore.Objects.UUID)9 VoteSite (com.Ben12345rocks.VotingPlugin.Objects.VoteSite)9 BInventory (com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventory)7 ClickEvent (com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventory.ClickEvent)7 BInventoryButton (com.Ben12345rocks.AdvancedCore.Util.Inventory.BInventoryButton)7 Player (org.bukkit.entity.Player)7 ItemBuilder (com.Ben12345rocks.AdvancedCore.Util.Item.ItemBuilder)6 HashMap (java.util.HashMap)6 OfflinePlayer (org.bukkit.OfflinePlayer)5 SimpleScoreboard (com.Ben12345rocks.AdvancedCore.Util.Scoreboards.SimpleScoreboard)4 File (java.io.File)4 LocalDateTime (java.time.LocalDateTime)4 YMLFileHandler (com.Ben12345rocks.AdvancedCore.YML.YMLFileHandler)3 Entry (java.util.Map.Entry)3 EventHandler (org.bukkit.event.EventHandler)3 CommandHandler (com.Ben12345rocks.AdvancedCore.Objects.CommandHandler)2 UserStorage (com.Ben12345rocks.AdvancedCore.Objects.UserStorage)2 IOException (java.io.IOException)2