diff --git a/VotingPlugin/src/com/bencodez/votingplugin/commands/CommandLoader.java b/VotingPlugin/src/com/bencodez/votingplugin/commands/CommandLoader.java index 766d80233..48e190567 100644 --- a/VotingPlugin/src/com/bencodez/votingplugin/commands/CommandLoader.java +++ b/VotingPlugin/src/com/bencodez/votingplugin/commands/CommandLoader.java @@ -5,7 +5,9 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; +import java.util.LinkedList; import java.util.Map.Entry; +import java.util.Queue; import java.util.Set; import java.util.UUID; import java.util.concurrent.TimeUnit; @@ -35,6 +37,7 @@ import com.bencodez.advancedcore.api.misc.PlayerUtils; import com.bencodez.advancedcore.api.rewards.RewardOptions; import com.bencodez.advancedcore.api.updater.Updater; +import com.bencodez.advancedcore.api.user.UserStorage; import com.bencodez.advancedcore.api.user.userstorage.Column; import com.bencodez.advancedcore.api.user.userstorage.DataType; import com.bencodez.advancedcore.api.valuerequest.ValueRequest; @@ -1725,6 +1728,51 @@ public void execute(CommandSender sender, String[] args) { } }); + plugin.getAdminVoteCommand() + .add(new CommandHandler(plugin, new String[] { "MergeDataFrom", "(UserStorage)" }, + "VotingPlugin.Commands.AdminVote.MergeDataFrom|" + adminPerm, + "Merge player totals from other storage type", true, true) { + + @Override + public void execute(CommandSender sender, String[] args) { + plugin.loadUserAPI(UserStorage.value(args[1])); + + if (plugin.getMysql() != null) { + plugin.getMysql().clearCacheBasic(); + } + + HashMap> cols = plugin.getUserManager() + .getAllKeys(UserStorage.value(args[1])); + Queue>> players = new LinkedList>>( + cols.entrySet()); + ArrayList uuids = plugin.getUserManager().getAllUUIDs(); + + while (players.size() > 0) { + Entry> entry = players.poll(); + VotingPluginUser user = plugin.getVotingPluginUserManager() + .getVotingPluginUser(entry.getKey(), false); + user.dontCache(); + if (uuids.contains(entry.getKey().toString())) { + user.mergeData(user.getData().convert(entry.getValue())); + } else { + user.getData().setValues(plugin.getStorageType(), + user.getData().convert(entry.getValue())); + } + + sendMessage(sender, "Finished merge for " + user.getUUID() + ", " + players.size() + + " more left to go!"); + + if (players.size() % 50 == 0) { + sendMessage(sender, + "Working on converting data, about " + players.size() + " left to go!"); + } + } + plugin.getUserManager().getDataManager().clearCache(); + sendMessage(sender, "Merge finished"); + + } + }); + plugin.getAdminVoteCommand().add(new CommandHandler(plugin, new String[] {}, "VotingPlugin.Commands.AdminVote|" + adminPerm, "Base command") { diff --git a/VotingPlugin/src/com/bencodez/votingplugin/user/VotingPluginUser.java b/VotingPlugin/src/com/bencodez/votingplugin/user/VotingPluginUser.java index 1927880ce..1406ef04e 100644 --- a/VotingPlugin/src/com/bencodez/votingplugin/user/VotingPluginUser.java +++ b/VotingPlugin/src/com/bencodez/votingplugin/user/VotingPluginUser.java @@ -24,6 +24,8 @@ import com.bencodez.advancedcore.api.rewards.RewardBuilder; import com.bencodez.advancedcore.api.rewards.RewardOptions; import com.bencodez.advancedcore.api.user.AdvancedCoreUser; +import com.bencodez.advancedcore.api.user.usercache.value.DataValue; +import com.bencodez.advancedcore.api.user.usercache.value.DataValueInt; import com.bencodez.votingplugin.VotingPluginMain; import com.bencodez.votingplugin.bungee.BungeeMessageData; import com.bencodez.votingplugin.bungee.BungeeMethod; @@ -1409,4 +1411,20 @@ public long getLastVoteTimer(VoteSite voteSite) { } + public void mergeData(HashMap toAdd) { + HashMap currentData = getData().getValues(); + HashMap newData = new HashMap(); + + for (TopVoter top : TopVoter.values()) { + if (toAdd.containsKey(top.getColumnName()) && currentData.containsKey(top.getColumnName())) { + newData.put(top.getColumnName(), new DataValueInt( + currentData.get(top.getColumnName()).getInt() + toAdd.get(top.getColumnName()).getInt())); + } + } + + if (newData.size() > 0) { + getData().setValues(newData); + } + } + }