Merge branch 'master' of ssh://184.154.0.242:7999/min/mineplex
This commit is contained in:
commit
0557e10257
@ -49,7 +49,6 @@ public class SecondaryStatHandler implements ILoginProcessor
|
||||
DSLContext context = DSL.using(DBPool.ACCOUNT, SQLDialect.MYSQL);
|
||||
|
||||
final List<Insert> inserts = new ArrayList<>();
|
||||
final List<Delete> 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<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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
package mineplex.serverdata;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import mineplex.serverdata.servers.ConnectionData;
|
||||
import mineplex.serverdata.servers.ServerManager;
|
||||
import redis.clients.jedis.Jedis;
|
||||
@ -15,17 +17,20 @@ import com.google.gson.GsonBuilder;
|
||||
* @author Ty
|
||||
*
|
||||
*/
|
||||
public class Utility
|
||||
public class Utility
|
||||
{
|
||||
|
||||
// The Gson instance used to serialize/deserialize objects in JSON form.
|
||||
private static Gson _gson = new GsonBuilder().create();
|
||||
public static Gson getGson() { return _gson; }
|
||||
|
||||
|
||||
// map of all instantiated connection pools, distinguished by their ip:port combination
|
||||
private static final ConcurrentHashMap<String, JedisPool> _pools = new ConcurrentHashMap<String, JedisPool>();
|
||||
|
||||
// Public static jedis pool for interacting with central default jedis repo.
|
||||
private static JedisPool _masterPool;
|
||||
private static JedisPool _slavePool;
|
||||
|
||||
|
||||
/**
|
||||
* @param object - the (non-null) object to serialize
|
||||
* @return the serialized form of {@code object}.
|
||||
@ -34,7 +39,7 @@ public class Utility
|
||||
{
|
||||
return _gson.toJson(object);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param serializedData - the serialized data to be deserialized
|
||||
* @param type - the resulting class type of the object to be deserialized
|
||||
@ -44,7 +49,7 @@ public class Utility
|
||||
{
|
||||
return _gson.fromJson(serializedData, type);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param delimiter - the delimiter character used to separate the concatenated elements
|
||||
* @param elements - the set of string elements to be concatenated and returned.
|
||||
@ -54,15 +59,15 @@ public class Utility
|
||||
{
|
||||
int length = elements.length;
|
||||
String result = length > 0 ? elements[0] : new String();
|
||||
|
||||
|
||||
for (int i = 1; i < length; i++)
|
||||
{
|
||||
result += delimiter + elements[i];
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the current timestamp (in seconds) fetched from the central jedis repository
|
||||
* for synced timestamps.
|
||||
@ -72,7 +77,7 @@ public class Utility
|
||||
long currentTime = 0;
|
||||
JedisPool pool = getPool(false);
|
||||
Jedis jedis = pool.getResource();
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
currentTime = Long.parseLong(jedis.time().get(0));
|
||||
@ -90,10 +95,10 @@ public class Utility
|
||||
pool.returnResource(jedis);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return currentTime;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the current timestamp (in milliseconds) fetched from the central jedis repository
|
||||
* for synced timestamps.
|
||||
@ -121,22 +126,35 @@ public class Utility
|
||||
pool.returnResource(jedis);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return currentTime * 1000;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param connData - the connection data specifying the database to be connected to.
|
||||
* @return a newly instantiated {@link JedisPool} connected to the provided {@link ConnectionData} repository.
|
||||
*/
|
||||
public static JedisPool generatePool(ConnectionData connData)
|
||||
{
|
||||
JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
|
||||
jedisPoolConfig.setMaxWaitMillis(1000);
|
||||
jedisPoolConfig.setMinIdle(5);
|
||||
return new JedisPool(jedisPoolConfig, connData.getHost(), connData.getPort());
|
||||
String key = getConnKey(connData);
|
||||
JedisPool pool = _pools.get(key);
|
||||
if (pool == null)
|
||||
{
|
||||
JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
|
||||
jedisPoolConfig.setMaxWaitMillis(1000);
|
||||
jedisPoolConfig.setMinIdle(5);
|
||||
jedisPoolConfig.setTestOnBorrow(true);
|
||||
|
||||
jedisPoolConfig.setMaxTotal(20);
|
||||
jedisPoolConfig.setBlockWhenExhausted(true);
|
||||
|
||||
pool = new JedisPool(jedisPoolConfig, connData.getHost(), connData.getPort());
|
||||
_pools.put(key, pool);
|
||||
}
|
||||
|
||||
return pool;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param writeable - whether or not the Jedis connections returned should be writeable to.
|
||||
* @return a globally available {@link JedisPool}
|
||||
@ -149,7 +167,7 @@ public class Utility
|
||||
{
|
||||
_masterPool = generatePool(ServerManager.getMasterConnection());
|
||||
}
|
||||
|
||||
|
||||
return _masterPool;
|
||||
}
|
||||
else
|
||||
@ -157,11 +175,17 @@ public class Utility
|
||||
if (_slavePool == null)
|
||||
{
|
||||
ConnectionData slave = ServerManager.getSlaveConnection();
|
||||
|
||||
|
||||
_slavePool = generatePool(slave);
|
||||
}
|
||||
|
||||
|
||||
return _slavePool;
|
||||
}
|
||||
}
|
||||
|
||||
private static String getConnKey(ConnectionData connData)
|
||||
{
|
||||
return 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("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"));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user