Implement temporary daily leaderboards microservice
This commit is contained in:
parent
81aea0cfae
commit
d14fcac6fb
@ -1,18 +1,25 @@
|
|||||||
package mineplex.core.leaderboard;
|
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.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.Consumer;
|
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.common.util.UtilServer;
|
||||||
|
import mineplex.core.thread.ThreadPool;
|
||||||
import mineplex.serverdata.database.DBPool;
|
import mineplex.serverdata.database.DBPool;
|
||||||
import mineplex.serverdata.database.RepositoryBase;
|
import mineplex.serverdata.database.RepositoryBase;
|
||||||
|
|
||||||
@ -45,6 +52,33 @@ public class LeaderboardRepository extends RepositoryBase
|
|||||||
|
|
||||||
public void insertStats(Map<Integer, Map<Integer, Long>> stats)
|
public void insertStats(Map<Integer, Map<Integer, Long>> stats)
|
||||||
{
|
{
|
||||||
|
Map<Integer, Map<Integer, Long>> 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(() ->
|
UtilServer.runAsync(() ->
|
||||||
{
|
{
|
||||||
try (
|
try (
|
||||||
|
Loading…
Reference in New Issue
Block a user