From cded2c7d8f34ea6f44a4d10260a8a53a54c95119 Mon Sep 17 00:00:00 2001 From: Shaun Bennett Date: Wed, 26 Nov 2014 12:07:06 -0600 Subject: [PATCH] Update Polls to use new MiniDbClientPlugin --- .../Mineplex.Hub/src/mineplex/hub/Hub.java | 2 +- .../src/mineplex/hub/poll/PollManager.java | 34 +++++++++-------- .../src/mineplex/hub/poll/PollRepository.java | 38 +++++++++++++------ 3 files changed, 46 insertions(+), 28 deletions(-) diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java index b3a27efe1..9af37cd09 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java @@ -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)); diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/poll/PollManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/poll/PollManager.java index 0d7b68656..25f4e305f 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/poll/PollManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/poll/PollManager.java @@ -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 +public class PollManager extends MiniDbClientPlugin { private PollRepository _repository; private DonationManager _donationManager; private List _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 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 { 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 + "';"; + } } diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/poll/PollRepository.java b/Plugins/Mineplex.Hub/src/mineplex/hub/poll/PollRepository.java index fa2a25e80..c6cb8cd4a 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/poll/PollRepository.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/poll/PollRepository.java @@ -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()));