diff --git a/Plugins/Mineplex.Core/src/mineplex/core/stats/SecondaryStatHandler.java b/Plugins/Mineplex.Core/src/mineplex/core/stats/SecondaryStatHandler.java index 1aa39a19c..5901a17e1 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/stats/SecondaryStatHandler.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/stats/SecondaryStatHandler.java @@ -49,7 +49,6 @@ public class SecondaryStatHandler implements ILoginProcessor DSLContext context = DSL.using(DBPool.ACCOUNT, SQLDialect.MYSQL); final List inserts = new ArrayList<>(); - final List deletes = new ArrayList<>(); for (String statName : oldPlayerStats.getStatsNames()) { @@ -59,14 +58,9 @@ public class SecondaryStatHandler implements ILoginProcessor .insertInto(Tables.accountStat) .set(Tables.accountStat.accountId, accountId) .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); - - Delete delete = context.delete(Tables.accountStats) - .where(Tables.accountStats.accountId.equal(accountId)); - - deletes.add(delete); } context.transaction(new TransactionalRunnable() @@ -75,7 +69,6 @@ public class SecondaryStatHandler implements ILoginProcessor public void run(Configuration config) throws Exception { DSL.using(config).batch(inserts).execute(); - DSL.using(config).batch(deletes).execute(); } }); } @@ -87,6 +80,97 @@ public class SecondaryStatHandler implements ILoginProcessor else { _statsManager.replacePlayerHack(playerName, newPlayerStats); + + if (oldPlayerStats.getStatsNames().size() != 0) + { + try + { + final DSLContext context = DSL.using(DBPool.ACCOUNT, SQLDialect.MYSQL); + final List updates = new ArrayList<>(); + final List 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 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(); + } + } } } diff --git a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/Utility.java b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/Utility.java index 9e6dba353..790a2efa3 100644 --- a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/Utility.java +++ b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/Utility.java @@ -134,6 +134,7 @@ public class Utility JedisPoolConfig jedisPoolConfig = new JedisPoolConfig(); jedisPoolConfig.setMaxWaitMillis(1000); jedisPoolConfig.setMinIdle(5); + jedisPoolConfig.setTestOnBorrow(true); return new JedisPool(jedisPoolConfig, connData.getHost(), connData.getPort()); } diff --git a/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/StaffServer.java b/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/StaffServer.java index 37b54b75b..f349df29e 100644 --- a/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/StaffServer.java +++ b/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/StaffServer.java @@ -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("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("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("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("cf85f470-5248-4978-8208-435736fa136e"), "RustyRoo")); } }