Fixes to redis
Fixes for stat handler.
This commit is contained in:
parent
d64d713a87
commit
26ed7ebb94
@ -49,7 +49,6 @@ public class SecondaryStatHandler implements ILoginProcessor
|
|||||||
DSLContext context = DSL.using(DBPool.ACCOUNT, SQLDialect.MYSQL);
|
DSLContext context = DSL.using(DBPool.ACCOUNT, SQLDialect.MYSQL);
|
||||||
|
|
||||||
final List<Insert> inserts = new ArrayList<>();
|
final List<Insert> inserts = new ArrayList<>();
|
||||||
final List<Delete> deletes = new ArrayList<>();
|
|
||||||
|
|
||||||
for (String statName : oldPlayerStats.getStatsNames())
|
for (String statName : oldPlayerStats.getStatsNames())
|
||||||
{
|
{
|
||||||
@ -59,14 +58,9 @@ public class SecondaryStatHandler implements ILoginProcessor
|
|||||||
.insertInto(Tables.accountStat)
|
.insertInto(Tables.accountStat)
|
||||||
.set(Tables.accountStat.accountId, accountId)
|
.set(Tables.accountStat.accountId, accountId)
|
||||||
.set(Tables.accountStat.statId, statId)
|
.set(Tables.accountStat.statId, statId)
|
||||||
.set(Tables.accountStat.value, oldPlayerStats.getStat(statName));
|
.set(Tables.accountStat.value, Math.max(oldPlayerStats.getStat(statName), 0L));
|
||||||
|
|
||||||
inserts.add(insert);
|
inserts.add(insert);
|
||||||
|
|
||||||
Delete delete = context.delete(Tables.accountStats)
|
|
||||||
.where(Tables.accountStats.accountId.equal(accountId));
|
|
||||||
|
|
||||||
deletes.add(delete);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
context.transaction(new TransactionalRunnable()
|
context.transaction(new TransactionalRunnable()
|
||||||
@ -75,7 +69,6 @@ public class SecondaryStatHandler implements ILoginProcessor
|
|||||||
public void run(Configuration config) throws Exception
|
public void run(Configuration config) throws Exception
|
||||||
{
|
{
|
||||||
DSL.using(config).batch(inserts).execute();
|
DSL.using(config).batch(inserts).execute();
|
||||||
DSL.using(config).batch(deletes).execute();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -87,6 +80,97 @@ public class SecondaryStatHandler implements ILoginProcessor
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
_statsManager.replacePlayerHack(playerName, newPlayerStats);
|
_statsManager.replacePlayerHack(playerName, newPlayerStats);
|
||||||
|
|
||||||
|
if (oldPlayerStats.getStatsNames().size() != 0)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
final DSLContext context = DSL.using(DBPool.ACCOUNT, SQLDialect.MYSQL);
|
||||||
|
final List<Update> updates = new ArrayList<>();
|
||||||
|
final List<Insert> inserts = new ArrayList<>();
|
||||||
|
boolean foundNegativeStat = false;
|
||||||
|
boolean foundLessThanStat = false;
|
||||||
|
|
||||||
|
for (String statName : oldPlayerStats.getStatsNames())
|
||||||
|
{
|
||||||
|
Integer statId = _statsManager.getStatId(statName);
|
||||||
|
|
||||||
|
Insert insert = context
|
||||||
|
.insertInto(Tables.accountStat)
|
||||||
|
.set(Tables.accountStat.accountId, accountId)
|
||||||
|
.set(Tables.accountStat.statId, statId)
|
||||||
|
.set(Tables.accountStat.value, Math.max(oldPlayerStats.getStat(statName), 0L));
|
||||||
|
|
||||||
|
inserts.add(insert);
|
||||||
|
|
||||||
|
Update update = context
|
||||||
|
.update(Tables.accountStat)
|
||||||
|
.set(Tables.accountStat.value, Math.max(oldPlayerStats.getStat(statName), 0L))
|
||||||
|
.where(Tables.accountStat.accountId.eq(accountId))
|
||||||
|
.and(Tables.accountStat.statId.eq(statId));
|
||||||
|
|
||||||
|
updates.add(update);
|
||||||
|
|
||||||
|
if (oldPlayerStats.getStat(statName) < 0)
|
||||||
|
{
|
||||||
|
foundNegativeStat = true;
|
||||||
|
}
|
||||||
|
else if (newPlayerStats.getStat(statName) < oldPlayerStats.getStat(statName))
|
||||||
|
{
|
||||||
|
foundLessThanStat = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (foundNegativeStat && foundLessThanStat)
|
||||||
|
{
|
||||||
|
context.transaction(new TransactionalRunnable()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run(Configuration config) throws Exception
|
||||||
|
{
|
||||||
|
int[] updateResult = context.batch(updates).execute();
|
||||||
|
|
||||||
|
for (int i = 0; i < updateResult.length; i++)
|
||||||
|
{
|
||||||
|
if (updateResult[i] > 0)
|
||||||
|
inserts.set(i, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
inserts.removeAll(Collections.singleton(null));
|
||||||
|
|
||||||
|
context.batch(inserts).execute();
|
||||||
|
|
||||||
|
System.out.println("Updating");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
final List<Delete> deletes = new ArrayList<>();
|
||||||
|
|
||||||
|
for (String statName : oldPlayerStats.getStatsNames())
|
||||||
|
{
|
||||||
|
Delete delete = context.delete(Tables.accountStats)
|
||||||
|
.where(Tables.accountStats.accountId.equal(accountId));
|
||||||
|
|
||||||
|
deletes.add(delete);
|
||||||
|
}
|
||||||
|
|
||||||
|
context.transaction(new TransactionalRunnable()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run(Configuration config) throws Exception
|
||||||
|
{
|
||||||
|
DSL.using(config).batch(deletes).execute();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,6 +134,7 @@ public class Utility
|
|||||||
JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
|
JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
|
||||||
jedisPoolConfig.setMaxWaitMillis(1000);
|
jedisPoolConfig.setMaxWaitMillis(1000);
|
||||||
jedisPoolConfig.setMinIdle(5);
|
jedisPoolConfig.setMinIdle(5);
|
||||||
|
jedisPoolConfig.setTestOnBorrow(true);
|
||||||
return new JedisPool(jedisPoolConfig, connData.getHost(), connData.getPort());
|
return new JedisPool(jedisPoolConfig, connData.getHost(), connData.getPort());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,11 +83,12 @@ public class StaffServer extends JavaPlugin
|
|||||||
((CraftServer)getServer()).getHandle().addWhitelist(new GameProfile(UUID.fromString("efaf9a17-2304-4f42-8433-421523c308dc"), "B2_mp"));
|
((CraftServer)getServer()).getHandle().addWhitelist(new GameProfile(UUID.fromString("efaf9a17-2304-4f42-8433-421523c308dc"), "B2_mp"));
|
||||||
((CraftServer)getServer()).getHandle().addWhitelist(new GameProfile(UUID.fromString("492ff708-fe76-4c5a-b9ed-a747b5fa20a0"), "Cherdy8s"));
|
((CraftServer)getServer()).getHandle().addWhitelist(new GameProfile(UUID.fromString("492ff708-fe76-4c5a-b9ed-a747b5fa20a0"), "Cherdy8s"));
|
||||||
((CraftServer)getServer()).getHandle().addWhitelist(new GameProfile(UUID.fromString("80f40f29-4d66-4355-a32f-01a65af2a14c"), "rl6"));
|
((CraftServer)getServer()).getHandle().addWhitelist(new GameProfile(UUID.fromString("80f40f29-4d66-4355-a32f-01a65af2a14c"), "rl6"));
|
||||||
|
((CraftServer)getServer()).getHandle().addWhitelist(new GameProfile(UUID.fromString("cf85f470-5248-4978-8208-435736fa136e"), "RustyRoo"));
|
||||||
|
|
||||||
|
|
||||||
((CraftServer)getServer()).getHandle().addOp(new GameProfile(UUID.fromString("377bdea3-badc-448d-81c1-65db43b17ea4"), "Strutt20"));
|
((CraftServer)getServer()).getHandle().addOp(new GameProfile(UUID.fromString("377bdea3-badc-448d-81c1-65db43b17ea4"), "Strutt20"));
|
||||||
((CraftServer)getServer()).getHandle().addOp(new GameProfile(UUID.fromString("efaf9a17-2304-4f42-8433-421523c308dc"), "B2_mp"));
|
((CraftServer)getServer()).getHandle().addOp(new GameProfile(UUID.fromString("efaf9a17-2304-4f42-8433-421523c308dc"), "B2_mp"));
|
||||||
((CraftServer)getServer()).getHandle().addOp(new GameProfile(UUID.fromString("2d5fd31b-0aa5-41db-a62d-a4611a24349a"), "ishh"));
|
((CraftServer)getServer()).getHandle().addOp(new GameProfile(UUID.fromString("2d5fd31b-0aa5-41db-a62d-a4611a24349a"), "ishh"));
|
||||||
|
((CraftServer)getServer()).getHandle().addOp(new GameProfile(UUID.fromString("cf85f470-5248-4978-8208-435736fa136e"), "RustyRoo"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user