Update Polls to use new MiniDbClientPlugin

This commit is contained in:
Shaun Bennett 2014-11-26 12:07:06 -06:00
parent 7c9226d6de
commit cded2c7d8f
3 changed files with 46 additions and 28 deletions

View File

@ -91,7 +91,7 @@ public class Hub extends JavaPlugin implements IRelation
Creature creature = new Creature(this); Creature creature = new Creature(this);
NpcManager npcManager = new NpcManager(this, creature); NpcManager npcManager = new NpcManager(this, creature);
PetManager petManager = new PetManager(this, clientManager, donationManager, creature, webServerAddress); PetManager petManager = new PetManager(this, clientManager, donationManager, creature, webServerAddress);
PollManager pollManager = new PollManager(this, donationManager); PollManager pollManager = new PollManager(this, clientManager, donationManager);
//Main Modules //Main Modules
ServerStatusManager serverStatusManager = new ServerStatusManager(this, new LagMeter(this, clientManager)); ServerStatusManager serverStatusManager = new ServerStatusManager(this, new LagMeter(this, clientManager));

View File

@ -1,5 +1,7 @@
package mineplex.hub.poll; package mineplex.hub.poll;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@ -14,6 +16,8 @@ import net.minecraft.server.v1_7_R4.PacketPlayOutChat;
import net.minecraft.util.com.google.gson.JsonObject; import net.minecraft.util.com.google.gson.JsonObject;
import mineplex.core.MiniClientPlugin; import mineplex.core.MiniClientPlugin;
import mineplex.core.MiniDbClientPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.common.util.Callback; import mineplex.core.common.util.Callback;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
@ -23,15 +27,15 @@ import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent; import mineplex.core.updater.event.UpdateEvent;
import mineplex.hub.poll.command.PollCommand; import mineplex.hub.poll.command.PollCommand;
public class PollManager extends MiniClientPlugin<PlayerPollData> public class PollManager extends MiniDbClientPlugin<PlayerPollData>
{ {
private PollRepository _repository; private PollRepository _repository;
private DonationManager _donationManager; private DonationManager _donationManager;
private List<Poll> _polls; private List<Poll> _polls;
public PollManager(JavaPlugin plugin, DonationManager donationManager) public PollManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager)
{ {
super("PollManager", plugin); super("PollManager", plugin, clientManager);
_repository = new PollRepository(plugin); _repository = new PollRepository(plugin);
@ -53,18 +57,6 @@ public class PollManager extends MiniClientPlugin<PlayerPollData>
return new PlayerPollData(); return new PlayerPollData();
} }
public void loadClientInformation(final PlayerJoinEvent event)
{
_plugin.getServer().getScheduler().runTaskAsynchronously(_plugin, new Runnable()
{
@Override
public void run()
{
Set(event.getPlayer().getName(), _repository.loadPollData(event.getPlayer().getUniqueId()));
}
});
}
@EventHandler @EventHandler
public void join(PlayerJoinEvent event) public void join(PlayerJoinEvent event)
{ {
@ -215,4 +207,16 @@ public class PollManager extends MiniClientPlugin<PlayerPollData>
{ {
addCommand(new PollCommand(this)); addCommand(new PollCommand(this));
} }
@Override
public void processLoginResultSet(String playerName, ResultSet resultSet) throws SQLException
{
Set(playerName, _repository.loadPollData(resultSet));
}
@Override
public String getQuery(String uuid, String name)
{
return "SELECT pollId, value FROM accountPolls INNER JOIN accounts ON accountPolls.accountId = accounts.id WHERE accounts.uuid = '" + uuid + "';";
}
} }

View File

@ -74,26 +74,40 @@ public class PollRepository extends RepositoryBase
return polls; return polls;
} }
public PlayerPollData loadPollData(UUID uuid) public PlayerPollData loadPollData(ResultSet resultSet) throws SQLException
{ {
final PlayerPollData pollData = new PlayerPollData(); PlayerPollData pollData = new PlayerPollData();
executeQuery(RETRIEVE_PLAYER_DATA, new ResultSetCallable()
{
public void processResultSet(ResultSet resultSet) throws SQLException
{
while (resultSet.next()) while (resultSet.next())
{ {
pollData.addAnswer(resultSet.getInt(1), resultSet.getInt(2)); pollData.addAnswer(resultSet.getInt(1), resultSet.getInt(2));
} }
}
}, new ColumnVarChar("uuid", 100, uuid.toString()));
pollData.Loaded = true; pollData.Loaded = true;
return pollData; return pollData;
} }
// public PlayerPollData loadPollData(UUID uuid)
// {
// final PlayerPollData pollData = new PlayerPollData();
//
// executeQuery(RETRIEVE_PLAYER_DATA, new ResultSetCallable()
// {
// public void processResultSet(ResultSet resultSet) throws SQLException
// {
// while (resultSet.next())
// {
// pollData.addAnswer(resultSet.getInt(1), resultSet.getInt(2));
// }
// }
// }, new ColumnVarChar("uuid", 100, uuid.toString()));
//
// pollData.Loaded = true;
//
// return pollData;
// }
public boolean addPollAnswer(UUID uuid, int pollId, int answer) public boolean addPollAnswer(UUID uuid, int pollId, int answer)
{ {
int update = executeUpdate(INSERT_POLL_ANSWER, new ColumnInt("pollId", pollId), new ColumnInt("answer", answer), new ColumnVarChar("uuid", 100, uuid.toString())); int update = executeUpdate(INSERT_POLL_ANSWER, new ColumnInt("pollId", pollId), new ColumnInt("answer", answer), new ColumnVarChar("uuid", 100, uuid.toString()));