Update Polls to use new MiniDbClientPlugin
This commit is contained in:
parent
7c9226d6de
commit
cded2c7d8f
@ -91,7 +91,7 @@ public class Hub extends JavaPlugin implements IRelation
|
||||
Creature creature = new Creature(this);
|
||||
NpcManager npcManager = new NpcManager(this, creature);
|
||||
PetManager petManager = new PetManager(this, clientManager, donationManager, creature, webServerAddress);
|
||||
PollManager pollManager = new PollManager(this, donationManager);
|
||||
PollManager pollManager = new PollManager(this, clientManager, donationManager);
|
||||
|
||||
//Main Modules
|
||||
ServerStatusManager serverStatusManager = new ServerStatusManager(this, new LagMeter(this, clientManager));
|
||||
|
@ -1,5 +1,7 @@
|
||||
package mineplex.hub.poll;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
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 mineplex.core.MiniClientPlugin;
|
||||
import mineplex.core.MiniDbClientPlugin;
|
||||
import mineplex.core.account.CoreClientManager;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.Callback;
|
||||
import mineplex.core.common.util.F;
|
||||
@ -23,15 +27,15 @@ import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
import mineplex.hub.poll.command.PollCommand;
|
||||
|
||||
public class PollManager extends MiniClientPlugin<PlayerPollData>
|
||||
public class PollManager extends MiniDbClientPlugin<PlayerPollData>
|
||||
{
|
||||
private PollRepository _repository;
|
||||
private DonationManager _donationManager;
|
||||
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);
|
||||
|
||||
@ -53,18 +57,6 @@ public class PollManager extends MiniClientPlugin<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
|
||||
public void join(PlayerJoinEvent event)
|
||||
{
|
||||
@ -215,4 +207,16 @@ public class PollManager extends MiniClientPlugin<PlayerPollData>
|
||||
{
|
||||
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 + "';";
|
||||
}
|
||||
}
|
||||
|
@ -74,26 +74,40 @@ public class PollRepository extends RepositoryBase
|
||||
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()
|
||||
while (resultSet.next())
|
||||
{
|
||||
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.addAnswer(resultSet.getInt(1), resultSet.getInt(2));
|
||||
}
|
||||
|
||||
pollData.Loaded = true;
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
int update = executeUpdate(INSERT_POLL_ANSWER, new ColumnInt("pollId", pollId), new ColumnInt("answer", answer), new ColumnVarChar("uuid", 100, uuid.toString()));
|
||||
|
Loading…
Reference in New Issue
Block a user