diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/poll/DisplayType.java b/Plugins/Mineplex.Hub/src/mineplex/hub/poll/DisplayType.java new file mode 100644 index 000000000..3045f5277 --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/poll/DisplayType.java @@ -0,0 +1,23 @@ +package mineplex.hub.poll; + +import mineplex.core.common.Rank; + +public enum DisplayType +{ + ALL, + RANKED, + NOT_RANKED; + + public boolean shouldDisplay(Rank rank) + { + switch (this) + { + case RANKED: + return rank.Has(Rank.ULTRA); + case NOT_RANKED: + return !rank.Has(Rank.ULTRA); + default: + return true; + } + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/poll/Poll.java b/Plugins/Mineplex.Hub/src/mineplex/hub/poll/Poll.java index ebff218f9..1998173ff 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/poll/Poll.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/poll/Poll.java @@ -1,5 +1,7 @@ package mineplex.hub.poll; +import mineplex.core.common.Rank; + /** * Created by Shaun on 8/16/2014. */ @@ -10,8 +12,9 @@ public class Poll private int _coinReward; private String _question; private String[] _answers; + private DisplayType _displayType; - public Poll(int id, boolean enabled, int coinReward, String question, String answerA, String answerB, String answerC, String answerD) + public Poll(int id, boolean enabled, int coinReward, String question, String answerA, String answerB, String answerC, String answerD, DisplayType displayType) { _id = id; _enabled = enabled; @@ -22,6 +25,7 @@ public class Poll _answers[1] = answerB; _answers[2] = answerC; _answers[3] = answerD; + _displayType = displayType; } public int getId() @@ -54,6 +58,11 @@ public class Poll return _coinReward; } + public DisplayType getDisplayType() + { + return _displayType; + } + @Override public boolean equals(Object object) { diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/poll/PollManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/poll/PollManager.java index 64ea760de..81ec00634 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/poll/PollManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/poll/PollManager.java @@ -17,6 +17,7 @@ import net.minecraft.util.com.google.gson.JsonObject; import mineplex.core.MiniDbClientPlugin; import mineplex.core.account.CoreClientManager; +import mineplex.core.common.Rank; import mineplex.core.common.util.C; import mineplex.core.common.util.Callback; import mineplex.core.common.util.F; @@ -78,7 +79,8 @@ public class PollManager extends MiniDbClientPlugin if (pollData.shouldPoll()) { - Poll nextPoll = getNextPoll(pollData); + Rank playerRank = ClientManager.Get(player).GetRank(); + Poll nextPoll = getNextPoll(pollData, playerRank); if (nextPoll != null) displayPoll(player, nextPoll); @@ -88,11 +90,11 @@ public class PollManager extends MiniDbClientPlugin } } - public Poll getNextPoll(PlayerPollData pollData) + public Poll getNextPoll(PlayerPollData pollData, Rank playerRank) { for (Poll poll : _polls) { - if (poll.isEnabled() && !pollData.hasAnswered(poll)) + if (poll.isEnabled() && poll.getDisplayType().shouldDisplay(playerRank) && !pollData.hasAnswered(poll)) return poll; } diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/poll/PollRepository.java b/Plugins/Mineplex.Hub/src/mineplex/hub/poll/PollRepository.java index c6cb8cd4a..0015a87ea 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/poll/PollRepository.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/poll/PollRepository.java @@ -18,10 +18,10 @@ import mineplex.core.database.column.ColumnVarChar; */ public class PollRepository extends RepositoryBase { - private static String CREATE_POLL_TABLE = "CREATE TABLE IF NOT EXISTS polls (id INT NOT NULL AUTO_INCREMENT, enabled BIT(1), question VARCHAR(256) NOT NULL, answerA VARCHAR(256) NOT NULL, answerB VARCHAR(256), answerC VARCHAR(256), answerD VARCHAR(256), coinReward INT NOT NULL, PRIMARY KEY (id));"; + private static String CREATE_POLL_TABLE = "CREATE TABLE IF NOT EXISTS polls (id INT NOT NULL AUTO_INCREMENT, enabled BIT(1), question VARCHAR(256) NOT NULL, answerA VARCHAR(256) NOT NULL, answerB VARCHAR(256), answerC VARCHAR(256), answerD VARCHAR(256), coinReward INT NOT NULL, displayType INT DEFAULT 0 NOT NULL, PRIMARY KEY (id));"; private static String CREATE_RELATION_TABLE = "CREATE TABLE IF NOT EXISTS accountPolls (id INT NOT NULL AUTO_INCREMENT, accountId INT NOT NULL, pollId INT NOT NULL, value TINYINT(1) NOT NULL, PRIMARY KEY (id), FOREIGN KEY (accountId) REFERENCES accounts(id), FOREIGN KEY (pollId) REFERENCES polls(id), UNIQUE INDEX accountPollIndex (accountId, pollId));"; - private static String RETRIEVE_POLLS = "SELECT id, enabled, question, answerA, answerB, answerC, answerD, coinReward FROM polls ORDER BY coinReward DESC"; + private static String RETRIEVE_POLLS = "SELECT id, enabled, question, answerA, answerB, answerC, answerD, coinReward, displayType FROM polls ORDER BY coinReward DESC"; private static String RETRIEVE_PLAYER_DATA = "SELECT pollId, value FROM accountPolls INNER JOIN accounts ON accountPolls.accountId = accounts.id WHERE accounts.uuid = ?;"; private static String INSERT_POLL_ANSWER = "INSERT INTO accountPolls (accountId, pollId, value) SELECT accounts.id, ?, ? FROM accounts WHERE accounts.uuid = ?;"; private static String RETRIEVE_POLL_STATS = "SELECT value, COUNT(*) FROM accountPolls WHERE pollId=? GROUP BY value;"; @@ -63,8 +63,21 @@ public class PollRepository extends RepositoryBase String answerC = resultSet.getString(6); String answerD = resultSet.getString(7); int coinReward = resultSet.getInt(8); + DisplayType displayType; - Poll poll = new Poll(pollId, enabled, coinReward, question, answerA, answerB, answerC, answerD); + switch(resultSet.getInt(9)) + { + case 1: + displayType = DisplayType.RANKED; + break; + case 2: + displayType = DisplayType.NOT_RANKED; + break; + default: + displayType = DisplayType.ALL; + } + + Poll poll = new Poll(pollId, enabled, coinReward, question, answerA, answerB, answerC, answerD, displayType); polls.add(poll); } diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/poll/command/PollCommand.java b/Plugins/Mineplex.Hub/src/mineplex/hub/poll/command/PollCommand.java index 9d25b9c0f..bd75a6a06 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/poll/command/PollCommand.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/poll/command/PollCommand.java @@ -100,6 +100,7 @@ public class PollCommand extends CommandBase UtilPlayer.message(caller, "Enabled: " + C.cYellow + poll.isEnabled()); UtilPlayer.message(caller, "Poll Id: " + C.cYellow + poll.getId()); UtilPlayer.message(caller, "Reward: " + C.cYellow + poll.getCoinReward()); + UtilPlayer.message(caller, "Display Type: " + C.cYellow + poll.getDisplayType()); UtilPlayer.message(caller, ""); DecimalFormat decimalFormat = new DecimalFormat("#.#");