Fix merge conflicts
This commit is contained in:
parent
fddfcda105
commit
d64d1eed4e
@ -71,14 +71,14 @@ public class Leaderboard
|
|||||||
return _type;
|
return _type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update(Map<String, Integer> names)
|
public void update(Map<String, Long> names)
|
||||||
{
|
{
|
||||||
deconstruct();
|
deconstruct();
|
||||||
LinkedList<String> display = new LinkedList<>();
|
LinkedList<String> display = new LinkedList<>();
|
||||||
display.add(C.cAqua + _display);
|
display.add(C.cAqua + _display);
|
||||||
display.add(C.cRed + " ");
|
display.add(C.cRed + " ");
|
||||||
int place = _start + 1;
|
int place = _start + 1;
|
||||||
for (Entry<String, Integer> entry : names.entrySet())
|
for (Entry<String, Long> entry : names.entrySet())
|
||||||
{
|
{
|
||||||
if (entry.getValue() == 1)
|
if (entry.getValue() == 1)
|
||||||
{
|
{
|
||||||
|
@ -127,11 +127,11 @@ public class LeaderboardRepository extends RepositoryBase
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadLeaderboard(Leaderboard board, Consumer<Map<String, Integer>> leaderboard)
|
public void loadLeaderboard(Leaderboard board, Consumer<Map<String, Long>> leaderboard)
|
||||||
{
|
{
|
||||||
UtilServer.runAsync(() ->
|
UtilServer.runAsync(() ->
|
||||||
{
|
{
|
||||||
Map<String, Integer> names = new LinkedHashMap<>();
|
Map<String, Long> names = new LinkedHashMap<>();
|
||||||
try (
|
try (
|
||||||
Connection c = getConnection();
|
Connection c = getConnection();
|
||||||
Statement s = c.createStatement();
|
Statement s = c.createStatement();
|
||||||
@ -144,7 +144,7 @@ public class LeaderboardRepository extends RepositoryBase
|
|||||||
{
|
{
|
||||||
while (rs.next())
|
while (rs.next())
|
||||||
{
|
{
|
||||||
names.merge(rs.getString("name"), rs.getInt("value"), Integer::sum);
|
names.merge(rs.getString("name"), rs.getLong("value"), Long::sum);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!s.getMoreResults())
|
if (!s.getMoreResults())
|
||||||
@ -166,11 +166,11 @@ public class LeaderboardRepository extends RepositoryBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void loadLeaderboards(Collection<Leaderboard> boards, Consumer<Map<String, Integer>[]> leaderboard)
|
public void loadLeaderboards(Collection<Leaderboard> boards, Consumer<Map<String, Long>[]> leaderboard)
|
||||||
{
|
{
|
||||||
UtilServer.runAsync(() ->
|
UtilServer.runAsync(() ->
|
||||||
{
|
{
|
||||||
Map<String, Integer>[] leaderboards = new Map[boards.size()];
|
Map<String, Long>[] leaderboards = new Map[boards.size()];
|
||||||
StringBuilder queryBuilder = new StringBuilder();
|
StringBuilder queryBuilder = new StringBuilder();
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
@ -199,7 +199,7 @@ public class LeaderboardRepository extends RepositoryBase
|
|||||||
{
|
{
|
||||||
while (rs.next())
|
while (rs.next())
|
||||||
{
|
{
|
||||||
leaderboards[index].merge(rs.getString("name"), rs.getInt("value"), Integer::sum);
|
leaderboards[index].merge(rs.getString("name"), rs.getLong("value"), Long::sum);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!s.getMoreResults())
|
if (!s.getMoreResults())
|
||||||
|
@ -5,6 +5,7 @@ import java.sql.SQLException;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
@ -21,12 +22,12 @@ import mineplex.core.account.CoreClient;
|
|||||||
import mineplex.core.account.CoreClientManager;
|
import mineplex.core.account.CoreClientManager;
|
||||||
import mineplex.core.account.permissions.Permission;
|
import mineplex.core.account.permissions.Permission;
|
||||||
import mineplex.core.account.permissions.PermissionGroup;
|
import mineplex.core.account.permissions.PermissionGroup;
|
||||||
|
import mineplex.core.common.util.F;
|
||||||
|
import mineplex.core.common.util.UtilPlayer;
|
||||||
import mineplex.core.common.util.UtilServer;
|
import mineplex.core.common.util.UtilServer;
|
||||||
import mineplex.core.common.util.UtilTasks;
|
import mineplex.core.common.util.UtilTasks;
|
||||||
import mineplex.core.leaderboard.LeaderboardManager;
|
import mineplex.core.leaderboard.LeaderboardManager;
|
||||||
import mineplex.core.stats.command.GiveStatCommand;
|
import mineplex.core.stats.command.GiveStatCommand;
|
||||||
import mineplex.core.stats.command.MasterBuilderUnban;
|
|
||||||
import mineplex.core.stats.command.SetLevelCommand;
|
|
||||||
import mineplex.core.stats.command.TimeCommand;
|
import mineplex.core.stats.command.TimeCommand;
|
||||||
import mineplex.core.stats.event.StatChangeEvent;
|
import mineplex.core.stats.event.StatChangeEvent;
|
||||||
import mineplex.core.thread.ThreadPool;
|
import mineplex.core.thread.ThreadPool;
|
||||||
@ -69,12 +70,12 @@ public class StatsManager extends MiniDbClientPlugin<PlayerStats>
|
|||||||
{
|
{
|
||||||
save(_statUploadQueue, map ->
|
save(_statUploadQueue, map ->
|
||||||
{
|
{
|
||||||
_repository.saveStats(map);
|
//_repository.saveStats(map);
|
||||||
_leaderboard.handleStatIncrease(map);
|
_leaderboard.handleStatIncrease(map);
|
||||||
}, "increment");
|
}, "increment");
|
||||||
save(_statUploadQueueOverRidable, map ->
|
save(_statUploadQueueOverRidable, map ->
|
||||||
{
|
{
|
||||||
_repository.saveStats(map, true);
|
//_repository.saveStats(map, true);
|
||||||
_leaderboard.handleStatIncrease(map);
|
_leaderboard.handleStatIncrease(map);
|
||||||
}, "override");
|
}, "override");
|
||||||
});
|
});
|
||||||
@ -89,7 +90,6 @@ public class StatsManager extends MiniDbClientPlugin<PlayerStats>
|
|||||||
|
|
||||||
private void generatePermissions()
|
private void generatePermissions()
|
||||||
{
|
{
|
||||||
|
|
||||||
PermissionGroup.ADMIN.setPermission(Perm.GIVE_STAT_COMMAND, true, true);
|
PermissionGroup.ADMIN.setPermission(Perm.GIVE_STAT_COMMAND, true, true);
|
||||||
PermissionGroup.MOD.setPermission(Perm.TIME_COMMAND, true, true);
|
PermissionGroup.MOD.setPermission(Perm.TIME_COMMAND, true, true);
|
||||||
PermissionGroup.ADMIN.setPermission(Perm.SET_LEVEL_COMMAND, true, true);
|
PermissionGroup.ADMIN.setPermission(Perm.SET_LEVEL_COMMAND, true, true);
|
||||||
@ -297,18 +297,22 @@ public class StatsManager extends MiniDbClientPlugin<PlayerStats>
|
|||||||
if (callback != null) callback.run();
|
if (callback != null) callback.run();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_repository.registerNewStat(statName);
|
|
||||||
|
|
||||||
_stats.clear();
|
|
||||||
|
|
||||||
for (Stat stat : _repository.retrieveStats())
|
|
||||||
{
|
|
||||||
_stats.put(stat.getName(), stat.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (callback != null) callback.run();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_repository.registerNewStat(statName, () ->
|
||||||
|
{
|
||||||
|
synchronized(STATS_LOCK)
|
||||||
|
{
|
||||||
|
_stats.clear();
|
||||||
|
|
||||||
|
for (Stat stat : _repository.retrieveStats())
|
||||||
|
{
|
||||||
|
_stats.put(stat.getName(), stat.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (callback != null) callback.run();
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -332,6 +336,43 @@ public class StatsManager extends MiniDbClientPlugin<PlayerStats>
|
|||||||
{
|
{
|
||||||
setStat(event.getPlayer(), stat, 0);
|
setStat(event.getPlayer(), stat, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
final UUID uuid = event.getPlayer().getUniqueId();
|
||||||
|
final int accountId = _coreClientManager.getAccountId(event.getPlayer());
|
||||||
|
UtilPlayer.message(event.getPlayer(), F.main(getName(), "We are currently converting to a different stat storage method, please wait a moment if your stats are not all present!"));
|
||||||
|
runAsync(() ->
|
||||||
|
{
|
||||||
|
_repository.loadStatsFromOld(accountId, statMap ->
|
||||||
|
{
|
||||||
|
if (Bukkit.getPlayer(uuid) == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
boolean conversionOccurred = false;
|
||||||
|
Map<String, Long> currentMap = Get(event.getPlayer()).getStats();
|
||||||
|
for (Entry<String, Long> oldEntry : statMap.entrySet())
|
||||||
|
{
|
||||||
|
if (currentMap.containsKey(oldEntry.getKey()))
|
||||||
|
{
|
||||||
|
if (currentMap.get(oldEntry.getKey()) < oldEntry.getValue())
|
||||||
|
{
|
||||||
|
conversionOccurred = true;
|
||||||
|
Long diff = oldEntry.getValue() - currentMap.get(oldEntry.getKey());
|
||||||
|
incrementStat(event.getPlayer(), oldEntry.getKey(), diff);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
conversionOccurred = true;
|
||||||
|
incrementStat(event.getPlayer(), oldEntry.getKey(), oldEntry.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (conversionOccurred)
|
||||||
|
{
|
||||||
|
UtilPlayer.message(event.getPlayer(), F.main(getName(), "Your old stats have been converted!"));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -339,8 +380,8 @@ public class StatsManager extends MiniDbClientPlugin<PlayerStats>
|
|||||||
{
|
{
|
||||||
addCommand(new TimeCommand(this));
|
addCommand(new TimeCommand(this));
|
||||||
addCommand(new GiveStatCommand(this));
|
addCommand(new GiveStatCommand(this));
|
||||||
addCommand(new SetLevelCommand(this));
|
//addCommand(new SetLevelCommand(this));
|
||||||
addCommand(new MasterBuilderUnban(this));
|
//addCommand(new MasterBuilderUnban(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -373,6 +414,6 @@ public class StatsManager extends MiniDbClientPlugin<PlayerStats>
|
|||||||
@Override
|
@Override
|
||||||
public String getQuery(int accountId, String uuid, String name)
|
public String getQuery(int accountId, String uuid, String name)
|
||||||
{
|
{
|
||||||
return "SELECT stats.name, value FROM accountStat INNER JOIN stats ON stats.id = accountStat.statId WHERE accountStat.accountId = '" + accountId + "';";
|
return "SELECT stats.name, value FROM accountStatsAllTime INNER JOIN stats ON stats.id = accountStatsAllTime.statId WHERE accountStatsAllTime.accountId = '" + accountId + "';";
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,10 +1,14 @@
|
|||||||
package mineplex.core.stats;
|
package mineplex.core.stats;
|
||||||
|
|
||||||
|
import java.sql.CallableStatement;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import org.jooq.DSLContext;
|
import org.jooq.DSLContext;
|
||||||
import org.jooq.Insert;
|
import org.jooq.Insert;
|
||||||
@ -15,10 +19,11 @@ import org.jooq.Update;
|
|||||||
import org.jooq.impl.DSL;
|
import org.jooq.impl.DSL;
|
||||||
import org.jooq.types.ULong;
|
import org.jooq.types.ULong;
|
||||||
|
|
||||||
import mineplex.core.database.MinecraftRepository;
|
import mineplex.core.common.util.UtilServer;
|
||||||
import mineplex.database.Tables;
|
import mineplex.database.Tables;
|
||||||
import mineplex.serverdata.database.DBPool;
|
import mineplex.serverdata.database.DBPool;
|
||||||
import mineplex.serverdata.database.RepositoryBase;
|
import mineplex.serverdata.database.RepositoryBase;
|
||||||
|
import mineplex.serverdata.database.column.ColumnInt;
|
||||||
import mineplex.serverdata.database.column.ColumnVarChar;
|
import mineplex.serverdata.database.column.ColumnVarChar;
|
||||||
|
|
||||||
public class StatsRepository extends RepositoryBase
|
public class StatsRepository extends RepositoryBase
|
||||||
@ -31,6 +36,20 @@ public class StatsRepository extends RepositoryBase
|
|||||||
super(DBPool.getAccount());
|
super(DBPool.getAccount());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void loadStatsFromOld(int accountId, Consumer<Map<String, Long>> callback)
|
||||||
|
{
|
||||||
|
executeQuery("SELECT stats.name, value FROM accountStat INNER JOIN stats ON stats.id = accountStat.statId WHERE accountStat.accountId=?;", rs ->
|
||||||
|
{
|
||||||
|
final Map<String, Long> statMap = new HashMap<>();
|
||||||
|
while (rs.next())
|
||||||
|
{
|
||||||
|
statMap.put(rs.getString(1), rs.getLong(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
UtilServer.runSync(() -> callback.accept(statMap));
|
||||||
|
}, new ColumnInt("accountId", accountId));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves all the remote registered stats
|
* Retrieves all the remote registered stats
|
||||||
*
|
*
|
||||||
@ -56,9 +75,28 @@ public class StatsRepository extends RepositoryBase
|
|||||||
*
|
*
|
||||||
* @param name The name of the stat
|
* @param name The name of the stat
|
||||||
*/
|
*/
|
||||||
public void registerNewStat(String name)
|
public void registerNewStat(String name, Runnable onComplete)
|
||||||
{
|
{
|
||||||
executeUpdate(INSERT_STAT, new ColumnVarChar("name", 100, name));
|
try (Connection c = getConnection())
|
||||||
|
{
|
||||||
|
executeInsert(c, "INSERT INTO stats (name) VALUES (?);", rs ->
|
||||||
|
{
|
||||||
|
if (rs.next())
|
||||||
|
{
|
||||||
|
final int id = rs.getInt(1);
|
||||||
|
try (CallableStatement cs = c.prepareCall("{call accountStatsCreateBucketData(?)}"))
|
||||||
|
{
|
||||||
|
cs.setInt("stat", id);
|
||||||
|
cs.execute();
|
||||||
|
onComplete.run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, () -> {}, new ColumnVarChar("name", 100, name));
|
||||||
|
}
|
||||||
|
catch (SQLException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
62
Tools/Stat Conversion/pom.xml
Normal file
62
Tools/Stat Conversion/pom.xml
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>StatConverter</groupId>
|
||||||
|
<artifactId>StatConverter</artifactId>
|
||||||
|
<version>1.0</version>
|
||||||
|
<build>
|
||||||
|
<sourceDirectory>src</sourceDirectory>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>src</directory>
|
||||||
|
<excludes>
|
||||||
|
<exclude>**/*.java</exclude>
|
||||||
|
</excludes>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.1</version>
|
||||||
|
<configuration>
|
||||||
|
<source>1.8</source>
|
||||||
|
<target>1.8</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>2.3</version>
|
||||||
|
<configuration>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>2.4.3</version>
|
||||||
|
<type>maven-plugin</type>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.commons</groupId>
|
||||||
|
<artifactId>commons-dbcp2</artifactId>
|
||||||
|
<version>2.0.1</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>mysql</groupId>
|
||||||
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
|
<version>5.1.14</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
168
Tools/Stat Conversion/src/com/mineplex/statconverter/Main.java
Normal file
168
Tools/Stat Conversion/src/com/mineplex/statconverter/Main.java
Normal file
@ -0,0 +1,168 @@
|
|||||||
|
package com.mineplex.statconverter;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Statement;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import com.google.common.io.Files;
|
||||||
|
import com.mineplex.statconverter.database.mysql.DBPool;
|
||||||
|
|
||||||
|
public class Main
|
||||||
|
{
|
||||||
|
public static void main(String[] args)
|
||||||
|
{
|
||||||
|
new Main();
|
||||||
|
}
|
||||||
|
|
||||||
|
private File _info;
|
||||||
|
|
||||||
|
public Main()
|
||||||
|
{
|
||||||
|
int start = 0;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_info = new File(new File(".").getCanonicalPath() + File.separator + "converterInfo.dat");
|
||||||
|
System.out.println(_info.getCanonicalPath());
|
||||||
|
if (_info.exists())
|
||||||
|
{
|
||||||
|
String startStr = Files.readFirstLine(_info, Charset.defaultCharset());
|
||||||
|
if (startStr != null && !startStr.isEmpty())
|
||||||
|
{
|
||||||
|
start = Integer.parseInt(startStr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_info.createNewFile();
|
||||||
|
Files.write("0".getBytes(), _info);
|
||||||
|
}
|
||||||
|
|
||||||
|
convertGroup(start);
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void convertGroup(int start)
|
||||||
|
{
|
||||||
|
System.out.println("[INFO] Starting " + start + " to " + (start + 9999));
|
||||||
|
List<Integer> accounts = new ArrayList<>();
|
||||||
|
try (Connection c = DBPool.getDataSource("ACCOUNT_PC").getConnection())
|
||||||
|
{
|
||||||
|
try (Statement s = c.createStatement();
|
||||||
|
ResultSet rs = s.executeQuery("SELECT DISTINCT accountId FROM accountStat LIMIT " + start + ",10000;")
|
||||||
|
)
|
||||||
|
{
|
||||||
|
while (rs.next())
|
||||||
|
{
|
||||||
|
accounts.add(rs.getInt("accountId"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!accounts.isEmpty())
|
||||||
|
{
|
||||||
|
for (Integer accountId : accounts)
|
||||||
|
{
|
||||||
|
Map<Integer, Long> oldStats = new HashMap<>();
|
||||||
|
Map<Integer, Long> newStats = new HashMap<>();
|
||||||
|
try (Statement s = c.createStatement();
|
||||||
|
ResultSet rs = s.executeQuery("SELECT statId, value FROM accountStat WHERE accountId=" + accountId + ";")
|
||||||
|
)
|
||||||
|
{
|
||||||
|
while (rs.next())
|
||||||
|
{
|
||||||
|
oldStats.put(rs.getInt("statId"), rs.getLong("value"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try (Statement s = c.createStatement();
|
||||||
|
ResultSet rs = s.executeQuery("SELECT statId, value FROM accountStatsAllTime WHERE accountId=" + accountId + ";")
|
||||||
|
)
|
||||||
|
{
|
||||||
|
while (rs.next())
|
||||||
|
{
|
||||||
|
newStats.put(rs.getInt("statId"), rs.getLong("value"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Entry<Integer, Long> oldEntry : oldStats.entrySet())
|
||||||
|
{
|
||||||
|
if (newStats.containsKey(oldEntry.getKey()))
|
||||||
|
{
|
||||||
|
if (newStats.get(oldEntry.getKey()) < oldEntry.getValue())
|
||||||
|
{
|
||||||
|
try (Statement s = c.createStatement())
|
||||||
|
{
|
||||||
|
Long diff = oldEntry.getValue() - newStats.get(oldEntry.getKey());
|
||||||
|
s.execute("UPDATE accountStatsAllTime SET value=value+" + diff + " WHERE accountId=" + accountId + " AND statId=" + oldEntry.getKey() + ";");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
try (Statement s = c.createStatement())
|
||||||
|
{
|
||||||
|
s.execute("INSERT INTO accountStatsAllTime (accountId, statId, value) VALUES (" + accountId + ", " + oldEntry.getKey() + ", " + oldEntry.getValue() + ");");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try (Statement s = c.createStatement())
|
||||||
|
{
|
||||||
|
s.execute("DELETE FROM accountStat WHERE accountId=" + accountId + ";");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
complete(start);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
System.out.println("[INFO] Conversion complete");
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Thread.sleep(3000);
|
||||||
|
}
|
||||||
|
catch (InterruptedException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (SQLException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void complete(int start)
|
||||||
|
{
|
||||||
|
int nextStart = start + 10000;
|
||||||
|
if (_info.delete())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_info.createNewFile();
|
||||||
|
Files.write((nextStart + "").getBytes(), _info);
|
||||||
|
System.out.println("[INFO] Completed " + start + " to " + (nextStart - 1));
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,90 @@
|
|||||||
|
package com.mineplex.statconverter.database.mysql;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
|
import org.apache.commons.dbcp2.BasicDataSource;
|
||||||
|
|
||||||
|
public final class DBPool
|
||||||
|
{
|
||||||
|
private static final Map<String, DataSource> _dataSources = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
public static DataSource getDataSource(String databaseId)
|
||||||
|
{
|
||||||
|
if (_dataSources == null || _dataSources.isEmpty())
|
||||||
|
{
|
||||||
|
loadDataSources();
|
||||||
|
}
|
||||||
|
return _dataSources.get(databaseId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static DataSource openDataSource(String url, String username, String password)
|
||||||
|
{
|
||||||
|
BasicDataSource source = new BasicDataSource();
|
||||||
|
source.addConnectionProperty("autoReconnect", "true");
|
||||||
|
source.addConnectionProperty("allowMultiQueries", "true");
|
||||||
|
source.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
|
||||||
|
source.setDriverClassName("com.mysql.jdbc.Driver");
|
||||||
|
source.setUrl(url);
|
||||||
|
source.setUsername(username);
|
||||||
|
source.setPassword(password);
|
||||||
|
source.setMaxTotal(3);
|
||||||
|
source.setMaxIdle(3);
|
||||||
|
source.setTimeBetweenEvictionRunsMillis(180 * 1000);
|
||||||
|
source.setSoftMinEvictableIdleTimeMillis(180 * 1000);
|
||||||
|
|
||||||
|
return source;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void loadDataSources()
|
||||||
|
{
|
||||||
|
Map<String, DataSource> dataSources = new HashMap<>();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File configFile = new File(new File(".").getCanonicalPath() + File.separator + "database-config.dat");
|
||||||
|
|
||||||
|
if (configFile.exists())
|
||||||
|
{
|
||||||
|
List<String> lines = Files.readAllLines(configFile.toPath(),
|
||||||
|
Charset.defaultCharset());
|
||||||
|
|
||||||
|
for (String line : lines)
|
||||||
|
{
|
||||||
|
String[] args = line.split(" ");
|
||||||
|
|
||||||
|
if (args.length == 4)
|
||||||
|
{
|
||||||
|
String dbId = args[0];
|
||||||
|
String dbHost = args[1];
|
||||||
|
String userName = args[2];
|
||||||
|
String password = args[3];
|
||||||
|
|
||||||
|
dataSources.put(dbId, openDataSource("jdbc:mysql://" + dbHost, userName, password));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
System.out.println("database-config.dat not found at "
|
||||||
|
+ configFile.toPath().toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
exception.printStackTrace();
|
||||||
|
System.out.println("---Unable To Parse DBPOOL Configuration File---");
|
||||||
|
}
|
||||||
|
|
||||||
|
_dataSources.replaceAll((database, source) -> dataSources.getOrDefault(database, source));
|
||||||
|
dataSources.forEach((database, source) -> _dataSources.putIfAbsent(database, source));
|
||||||
|
_dataSources.entrySet().removeIf(entry -> !dataSources.containsKey(entry.getKey()));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user