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);
}
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");
}
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;
}
}
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();
}
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();
}
Aggregations