diff --git a/Plugins/Mineplex.Core/src/mineplex/core/leaderboard/LeaderboardRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/leaderboard/LeaderboardRepository.java index 6ba12fbfb..28a706184 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/leaderboard/LeaderboardRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/leaderboard/LeaderboardRepository.java @@ -1,18 +1,25 @@ package mineplex.core.leaderboard; +import java.io.IOException; +import java.io.InputStream; +import java.net.HttpURLConnection; +import java.net.URL; +import java.net.URLConnection; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.Collection; +import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; import java.util.function.Consumer; -import org.bukkit.plugin.java.JavaPlugin; +import com.google.common.collect.ImmutableMap; import mineplex.core.common.util.UtilServer; +import mineplex.core.thread.ThreadPool; import mineplex.serverdata.database.DBPool; import mineplex.serverdata.database.RepositoryBase; @@ -45,6 +52,33 @@ public class LeaderboardRepository extends RepositoryBase public void insertStats(Map> stats) { + Map> copy = new HashMap<>(stats.size()); + stats.forEach((statId, map) -> copy.put(statId, ImmutableMap.copyOf(map))); + ThreadPool.ASYNC.execute(() -> + { + for (Integer accountId : stats.keySet()) + { + for (Integer statId : stats.get(accountId).keySet()) + { + try + { + URL url = new URL("http://184.154.154.86:30030/update/" + statId + "/" + accountId + "/" + stats.get(accountId).get(statId) + "?apiKey=3e265961-f554-4aa7-8d6e-51f2af536537"); + URLConnection con = url.openConnection(); + HttpURLConnection http = (HttpURLConnection)con; + http.setRequestMethod("POST"); // PUT is another valid option + http.connect(); + try (InputStream is = http.getInputStream()) + { + is.close(); + } + } + catch (IOException ex) + { + ex.printStackTrace(); + } + } + } + }); UtilServer.runAsync(() -> { try (