Async db calls...
This commit is contained in:
parent
62d15eeee1
commit
844052c0c6
@ -9,6 +9,7 @@ import org.apache.commons.lang3.tuple.Triple;
|
||||
import mineplex.core.account.CoreClient;
|
||||
import mineplex.core.common.Pair;
|
||||
import mineplex.core.common.util.Callback;
|
||||
import mineplex.core.common.util.UtilServer;
|
||||
import mineplex.core.quests.Quest;
|
||||
import mineplex.serverdata.database.DBPool;
|
||||
import mineplex.serverdata.database.RepositoryBase;
|
||||
@ -42,56 +43,98 @@ public class QuestRepository extends RepositoryBase
|
||||
|
||||
public void createTable()
|
||||
{
|
||||
executeUpdate(CREATE_TABLE);
|
||||
UtilServer.runAsync(new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
executeUpdate(CREATE_TABLE);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void getQuests(CoreClient client, Callback<ArrayList<Pair<Integer, Triple<Integer, Long, Integer>>>> callback)
|
||||
{
|
||||
executeQuery(FETCH_QUESTS, new ResultSetCallable()
|
||||
{
|
||||
UtilServer.runAsync(new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void processResultSet(ResultSet resultSet) throws SQLException
|
||||
public void run()
|
||||
{
|
||||
ArrayList<Pair<Integer, Triple<Integer, Long, Integer>>> list = new ArrayList<>();
|
||||
while (resultSet.next())
|
||||
{
|
||||
list.add(Pair.create(resultSet.getInt(1), Triple.of(resultSet.getInt(2), resultSet.getLong(4), resultSet.getInt(3))));
|
||||
}
|
||||
callback.run(list);
|
||||
executeQuery(FETCH_QUESTS, new ResultSetCallable()
|
||||
{
|
||||
@Override
|
||||
public void processResultSet(ResultSet resultSet) throws SQLException
|
||||
{
|
||||
ArrayList<Pair<Integer, Triple<Integer, Long, Integer>>> list = new ArrayList<>();
|
||||
while (resultSet.next())
|
||||
{
|
||||
list.add(Pair.create(resultSet.getInt(1), Triple.of(resultSet.getInt(2), resultSet.getLong(4), resultSet.getInt(3))));
|
||||
}
|
||||
callback.run(list);
|
||||
}
|
||||
} ,new ColumnInt("accountId", client.getAccountId()));
|
||||
}
|
||||
} ,new ColumnInt("accountId", client.getAccountId()));
|
||||
});
|
||||
}
|
||||
|
||||
public void resetQuest(CoreClient client, Quest quest, boolean completed)
|
||||
{
|
||||
if (completed)
|
||||
UtilServer.runAsync(new Runnable()
|
||||
{
|
||||
executeUpdate(COMPLETE_QUEST, new ColumnLong("lastCompleted", System.currentTimeMillis()), new ColumnInt("accountId", client.getAccountId()), new ColumnInt("questId", quest.getID()));
|
||||
}
|
||||
else
|
||||
{
|
||||
executeUpdate(RESET_QUEST, new ColumnInt("accountId", client.getAccountId()), new ColumnInt("questId", quest.getID()));
|
||||
}
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (completed)
|
||||
{
|
||||
executeUpdate(COMPLETE_QUEST, new ColumnLong("lastCompleted", System.currentTimeMillis()), new ColumnInt("accountId", client.getAccountId()), new ColumnInt("questId", quest.getID()));
|
||||
}
|
||||
else
|
||||
{
|
||||
executeUpdate(RESET_QUEST, new ColumnInt("accountId", client.getAccountId()), new ColumnInt("questId", quest.getID()));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void addQuest(CoreClient client, Quest quest)
|
||||
{
|
||||
executeUpdate(START_QUEST, new ColumnInt("accountId", client.getAccountId()), new ColumnInt("questId", quest.getID()));
|
||||
UtilServer.runAsync(new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
executeUpdate(START_QUEST, new ColumnInt("accountId", client.getAccountId()), new ColumnInt("questId", quest.getID()));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void addNew(CoreClient client, Quest quest)
|
||||
{
|
||||
executeInsert(INSTERT_NEW_QUEST, null,
|
||||
new ColumnInt("accountId", client.getAccountId()),
|
||||
new ColumnInt("questId", quest.getID()),
|
||||
new ColumnInt("progress", 0),
|
||||
new ColumnInt("questCompletion", 0),
|
||||
new ColumnLong("lastCompleted", (long) 0));
|
||||
UtilServer.runAsync(new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
executeInsert(INSTERT_NEW_QUEST, null,
|
||||
new ColumnInt("accountId", client.getAccountId()),
|
||||
new ColumnInt("questId", quest.getID()),
|
||||
new ColumnInt("progress", 0),
|
||||
new ColumnInt("questCompletion", 0),
|
||||
new ColumnLong("lastCompleted", (long) 0));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void incrementQuest(CoreClient client, Quest quest, int value)
|
||||
{
|
||||
executeUpdate(INCREMENT_QUEST, new ColumnInt("progress", value), new ColumnInt("accountId", client.getAccountId()), new ColumnInt("questId", quest.getID()));
|
||||
UtilServer.runAsync(new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
executeUpdate(INCREMENT_QUEST, new ColumnInt("progress", value), new ColumnInt("accountId", client.getAccountId()), new ColumnInt("questId", quest.getID()));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user