54b7f21604c94e9ad2f53956 Flag for Poll DIsplay

This commit is contained in:
Shaun Bennett 2015-01-16 15:30:06 -05:00
parent ac709d09ce
commit b395508f0e
5 changed files with 55 additions and 7 deletions

View File

@ -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;
}
}
}

View File

@ -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)
{

View File

@ -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<PlayerPollData>
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<PlayerPollData>
}
}
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;
}

View File

@ -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);
}

View File

@ -100,6 +100,7 @@ public class PollCommand extends CommandBase<PollManager>
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("#.#");